nfs4xdr.c 201 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721
  1. /*
  2. * fs/nfs/nfs4xdr.c
  3. *
  4. * Client-side XDR for NFSv4.
  5. *
  6. * Copyright (c) 2002 The Regents of the University of Michigan.
  7. * All rights reserved.
  8. *
  9. * Kendrick Smith <kmsmith@umich.edu>
  10. * Andy Adamson <andros@umich.edu>
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. *
  16. * 1. Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. * 2. Redistributions in binary form must reproduce the above copyright
  19. * notice, this list of conditions and the following disclaimer in the
  20. * documentation and/or other materials provided with the distribution.
  21. * 3. Neither the name of the University nor the names of its
  22. * contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  26. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  27. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  28. * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  29. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  30. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  31. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  32. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  33. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  35. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. */
  37. #include <linux/param.h>
  38. #include <linux/time.h>
  39. #include <linux/mm.h>
  40. #include <linux/errno.h>
  41. #include <linux/string.h>
  42. #include <linux/in.h>
  43. #include <linux/pagemap.h>
  44. #include <linux/proc_fs.h>
  45. #include <linux/kdev_t.h>
  46. #include <linux/module.h>
  47. #include <linux/utsname.h>
  48. #include <linux/sunrpc/clnt.h>
  49. #include <linux/sunrpc/msg_prot.h>
  50. #include <linux/sunrpc/gss_api.h>
  51. #include <linux/nfs.h>
  52. #include <linux/nfs4.h>
  53. #include <linux/nfs_fs.h>
  54. #include <linux/nfs_common.h>
  55. #include "nfs4_fs.h"
  56. #include "nfs4trace.h"
  57. #include "internal.h"
  58. #include "nfs4idmap.h"
  59. #include "nfs4session.h"
  60. #include "pnfs.h"
  61. #include "netns.h"
  62. #define NFSDBG_FACILITY NFSDBG_XDR
  63. struct compound_hdr;
  64. static void encode_layoutget(struct xdr_stream *xdr,
  65. const struct nfs4_layoutget_args *args,
  66. struct compound_hdr *hdr);
  67. static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
  68. struct nfs4_layoutget_res *res);
  69. /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
  70. #ifdef DEBUG
  71. #define NFS4_MAXTAGLEN 20
  72. #else
  73. #define NFS4_MAXTAGLEN 0
  74. #endif
  75. /* lock,open owner id:
  76. * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
  77. */
  78. #define pagepad_maxsz (1)
  79. #define open_owner_id_maxsz (2 + 1 + 2 + 2)
  80. #define lock_owner_id_maxsz (2 + 1 + 2)
  81. #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
  82. #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
  83. #define op_encode_hdr_maxsz (1)
  84. #define op_decode_hdr_maxsz (2)
  85. #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
  86. #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
  87. #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
  88. #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
  89. #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
  90. (NFS4_FHSIZE >> 2))
  91. #define decode_putfh_maxsz (op_decode_hdr_maxsz)
  92. #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
  93. #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
  94. #define encode_getfh_maxsz (op_encode_hdr_maxsz)
  95. #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
  96. ((3+NFS4_FHSIZE) >> 2))
  97. #define nfs4_fattr_bitmap_maxsz 4
  98. #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
  99. #define nfstime4_maxsz (3)
  100. #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
  101. #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
  102. #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
  103. #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
  104. #ifdef CONFIG_NFS_V4_SECURITY_LABEL
  105. /* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
  106. #define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
  107. #else
  108. #define nfs4_label_maxsz 0
  109. #endif
  110. /* We support only one layout type per file system */
  111. #define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
  112. /* This is based on getfattr, which uses the most attributes: */
  113. #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
  114. 3*nfstime4_maxsz + \
  115. nfs4_owner_maxsz + \
  116. nfs4_group_maxsz + nfs4_label_maxsz + \
  117. decode_mdsthreshold_maxsz))
  118. #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
  119. nfs4_fattr_value_maxsz)
  120. #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
  121. #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
  122. 1 + 2 + 1 + \
  123. nfs4_owner_maxsz + \
  124. nfs4_group_maxsz + \
  125. nfs4_label_maxsz + \
  126. 1 + nfstime4_maxsz + \
  127. 1 + nfstime4_maxsz)
  128. #define encode_savefh_maxsz (op_encode_hdr_maxsz)
  129. #define decode_savefh_maxsz (op_decode_hdr_maxsz)
  130. #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
  131. #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
  132. #define encode_fsinfo_maxsz (encode_getattr_maxsz)
  133. /* The 5 accounts for the PNFS attributes, and assumes that at most three
  134. * layout types will be returned.
  135. */
  136. #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
  137. nfs4_fattr_bitmap_maxsz + 1 + \
  138. 1 /* lease time */ + \
  139. 2 /* max filesize */ + \
  140. 2 /* max read */ + \
  141. 2 /* max write */ + \
  142. nfstime4_maxsz /* time delta */ + \
  143. 5 /* fs layout types */ + \
  144. 1 /* layout blksize */ + \
  145. 1 /* clone blksize */ + \
  146. 1 /* change attr type */ + \
  147. 1 /* xattr support */)
  148. #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
  149. #define decode_renew_maxsz (op_decode_hdr_maxsz)
  150. #define encode_setclientid_maxsz \
  151. (op_encode_hdr_maxsz + \
  152. XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
  153. /* client name */ \
  154. 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
  155. 1 /* sc_prog */ + \
  156. 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
  157. 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
  158. 1) /* sc_cb_ident */
  159. #define decode_setclientid_maxsz \
  160. (op_decode_hdr_maxsz + \
  161. 2 /* clientid */ + \
  162. XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
  163. 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
  164. 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
  165. #define encode_setclientid_confirm_maxsz \
  166. (op_encode_hdr_maxsz + \
  167. 3 + (NFS4_VERIFIER_SIZE >> 2))
  168. #define decode_setclientid_confirm_maxsz \
  169. (op_decode_hdr_maxsz)
  170. #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
  171. #define decode_lookup_maxsz (op_decode_hdr_maxsz)
  172. #define encode_lookupp_maxsz (op_encode_hdr_maxsz)
  173. #define decode_lookupp_maxsz (op_decode_hdr_maxsz)
  174. #define encode_share_access_maxsz \
  175. (2)
  176. #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
  177. #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
  178. #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
  179. #define encode_open_maxsz (op_encode_hdr_maxsz + \
  180. 2 + encode_share_access_maxsz + 2 + \
  181. 1 + open_owner_id_maxsz + \
  182. encode_opentype_maxsz + \
  183. encode_claim_null_maxsz)
  184. #define decode_space_limit_maxsz (3)
  185. #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
  186. #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
  187. decode_space_limit_maxsz + \
  188. decode_ace_maxsz)
  189. #define decode_change_info_maxsz (5)
  190. #define decode_open_maxsz (op_decode_hdr_maxsz + \
  191. decode_stateid_maxsz + \
  192. decode_change_info_maxsz + 1 + \
  193. nfs4_fattr_bitmap_maxsz + \
  194. decode_delegation_maxsz)
  195. #define encode_open_confirm_maxsz \
  196. (op_encode_hdr_maxsz + \
  197. encode_stateid_maxsz + 1)
  198. #define decode_open_confirm_maxsz \
  199. (op_decode_hdr_maxsz + \
  200. decode_stateid_maxsz)
  201. #define encode_open_downgrade_maxsz \
  202. (op_encode_hdr_maxsz + \
  203. encode_stateid_maxsz + 1 + \
  204. encode_share_access_maxsz)
  205. #define decode_open_downgrade_maxsz \
  206. (op_decode_hdr_maxsz + \
  207. decode_stateid_maxsz)
  208. #define encode_close_maxsz (op_encode_hdr_maxsz + \
  209. 1 + encode_stateid_maxsz)
  210. #define decode_close_maxsz (op_decode_hdr_maxsz + \
  211. decode_stateid_maxsz)
  212. #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
  213. encode_stateid_maxsz + \
  214. encode_attrs_maxsz)
  215. #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
  216. nfs4_fattr_bitmap_maxsz)
  217. #define encode_delegattr_maxsz (op_encode_hdr_maxsz + \
  218. encode_stateid_maxsz + \
  219. nfs4_fattr_bitmap_maxsz + \
  220. 2*nfstime4_maxsz)
  221. #define decode_delegattr_maxsz (decode_setattr_maxsz)
  222. #define encode_read_maxsz (op_encode_hdr_maxsz + \
  223. encode_stateid_maxsz + 3)
  224. #define decode_read_maxsz (op_decode_hdr_maxsz + 2 + pagepad_maxsz)
  225. #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
  226. 2 + encode_verifier_maxsz + 5 + \
  227. nfs4_label_maxsz)
  228. #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
  229. decode_verifier_maxsz + pagepad_maxsz)
  230. #define encode_readlink_maxsz (op_encode_hdr_maxsz)
  231. #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1 + pagepad_maxsz)
  232. #define encode_write_maxsz (op_encode_hdr_maxsz + \
  233. encode_stateid_maxsz + 4)
  234. #define decode_write_maxsz (op_decode_hdr_maxsz + \
  235. 2 + decode_verifier_maxsz)
  236. #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
  237. #define decode_commit_maxsz (op_decode_hdr_maxsz + \
  238. decode_verifier_maxsz)
  239. #define encode_remove_maxsz (op_encode_hdr_maxsz + \
  240. nfs4_name_maxsz)
  241. #define decode_remove_maxsz (op_decode_hdr_maxsz + \
  242. decode_change_info_maxsz)
  243. #define encode_rename_maxsz (op_encode_hdr_maxsz + \
  244. 2 * nfs4_name_maxsz)
  245. #define decode_rename_maxsz (op_decode_hdr_maxsz + \
  246. decode_change_info_maxsz + \
  247. decode_change_info_maxsz)
  248. #define encode_link_maxsz (op_encode_hdr_maxsz + \
  249. nfs4_name_maxsz)
  250. #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
  251. #define encode_lockowner_maxsz (2 + 1 + lock_owner_id_maxsz)
  252. #define encode_lock_maxsz (op_encode_hdr_maxsz + \
  253. 7 + \
  254. 1 + encode_stateid_maxsz + 1 + \
  255. encode_lockowner_maxsz)
  256. #define decode_lock_denied_maxsz \
  257. (2 + 2 + 1 + 2 + 1 + lock_owner_id_maxsz)
  258. #define decode_lock_maxsz (op_decode_hdr_maxsz + \
  259. decode_lock_denied_maxsz)
  260. #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
  261. encode_lockowner_maxsz)
  262. #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
  263. decode_lock_denied_maxsz)
  264. #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
  265. encode_stateid_maxsz + \
  266. 4)
  267. #define decode_locku_maxsz (op_decode_hdr_maxsz + \
  268. decode_stateid_maxsz)
  269. #define encode_release_lockowner_maxsz \
  270. (op_encode_hdr_maxsz + \
  271. encode_lockowner_maxsz)
  272. #define decode_release_lockowner_maxsz \
  273. (op_decode_hdr_maxsz)
  274. #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
  275. #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
  276. #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
  277. 1 + nfs4_name_maxsz + \
  278. 1 + \
  279. nfs4_fattr_maxsz)
  280. #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
  281. #define encode_create_maxsz (op_encode_hdr_maxsz + \
  282. 1 + 2 + nfs4_name_maxsz + \
  283. encode_attrs_maxsz)
  284. #define decode_create_maxsz (op_decode_hdr_maxsz + \
  285. decode_change_info_maxsz + \
  286. nfs4_fattr_bitmap_maxsz)
  287. #define encode_statfs_maxsz (encode_getattr_maxsz)
  288. #define decode_statfs_maxsz (decode_getattr_maxsz)
  289. #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
  290. #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
  291. #define encode_getacl_maxsz (encode_getattr_maxsz)
  292. #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
  293. nfs4_fattr_bitmap_maxsz + 1 + pagepad_maxsz)
  294. #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
  295. encode_stateid_maxsz + 3)
  296. #define decode_setacl_maxsz (decode_setattr_maxsz)
  297. #define encode_fs_locations_maxsz \
  298. (encode_getattr_maxsz)
  299. #define decode_fs_locations_maxsz \
  300. (pagepad_maxsz)
  301. #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
  302. #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
  303. #if defined(CONFIG_NFS_V4_1)
  304. #define NFS4_MAX_MACHINE_NAME_LEN (64)
  305. #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
  306. sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
  307. #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
  308. encode_verifier_maxsz + \
  309. 1 /* co_ownerid.len */ + \
  310. /* eia_clientowner */ \
  311. 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
  312. 1 /* flags */ + \
  313. 1 /* spa_how */ + \
  314. /* max is SP4_MACH_CRED (for now) */ + \
  315. 1 + NFS4_OP_MAP_NUM_WORDS + \
  316. 1 + NFS4_OP_MAP_NUM_WORDS + \
  317. 1 /* implementation id array of size 1 */ + \
  318. 1 /* nii_domain */ + \
  319. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
  320. 1 /* nii_name */ + \
  321. XDR_QUADLEN(IMPL_NAME_LIMIT) + \
  322. 3 /* nii_date */)
  323. #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
  324. 2 /* eir_clientid */ + \
  325. 1 /* eir_sequenceid */ + \
  326. 1 /* eir_flags */ + \
  327. 1 /* spr_how */ + \
  328. /* max is SP4_MACH_CRED (for now) */ + \
  329. 1 + NFS4_OP_MAP_NUM_WORDS + \
  330. 1 + NFS4_OP_MAP_NUM_WORDS + \
  331. 2 /* eir_server_owner.so_minor_id */ + \
  332. /* eir_server_owner.so_major_id<> */ \
  333. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
  334. /* eir_server_scope<> */ \
  335. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
  336. 1 /* eir_server_impl_id array length */ + \
  337. 1 /* nii_domain */ + \
  338. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
  339. 1 /* nii_name */ + \
  340. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
  341. 3 /* nii_date */)
  342. #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
  343. #define decode_channel_attrs_maxsz (6 + \
  344. 1 /* ca_rdma_ird.len */ + \
  345. 1 /* ca_rdma_ird */)
  346. #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
  347. 2 /* csa_clientid */ + \
  348. 1 /* csa_sequence */ + \
  349. 1 /* csa_flags */ + \
  350. encode_channel_attrs_maxsz + \
  351. encode_channel_attrs_maxsz + \
  352. 1 /* csa_cb_program */ + \
  353. 1 /* csa_sec_parms.len (1) */ + \
  354. 1 /* cb_secflavor (AUTH_SYS) */ + \
  355. 1 /* stamp */ + \
  356. 1 /* machinename.len */ + \
  357. XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
  358. 1 /* uid */ + \
  359. 1 /* gid */ + \
  360. 1 /* gids.len (0) */)
  361. #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
  362. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
  363. 1 /* csr_sequence */ + \
  364. 1 /* csr_flags */ + \
  365. decode_channel_attrs_maxsz + \
  366. decode_channel_attrs_maxsz)
  367. #define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
  368. /* bctsa_sessid */ \
  369. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
  370. 1 /* bctsa_dir */ + \
  371. 1 /* bctsa_use_conn_in_rdma_mode */)
  372. #define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
  373. /* bctsr_sessid */ \
  374. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
  375. 1 /* bctsr_dir */ + \
  376. 1 /* bctsr_use_conn_in_rdma_mode */)
  377. #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
  378. #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
  379. #define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
  380. #define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
  381. #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
  382. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
  383. #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
  384. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
  385. #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
  386. #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
  387. #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
  388. XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
  389. 1 /* layout type */ + \
  390. 1 /* maxcount */ + \
  391. 1 /* bitmap size */ + \
  392. 1 /* notification bitmap length */ + \
  393. 1 /* notification bitmap, word 0 */)
  394. #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
  395. 1 /* layout type */ + \
  396. 1 /* opaque devaddr4 length */ + \
  397. /* devaddr4 payload is read into page */ \
  398. 1 /* notification bitmap length */ + \
  399. 1 /* notification bitmap, word 0 */ + \
  400. pagepad_maxsz /* possible XDR padding */)
  401. #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
  402. encode_stateid_maxsz)
  403. #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
  404. decode_stateid_maxsz + \
  405. XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE) + \
  406. pagepad_maxsz)
  407. #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
  408. 2 /* offset */ + \
  409. 2 /* length */ + \
  410. 1 /* reclaim */ + \
  411. encode_stateid_maxsz + \
  412. 1 /* new offset (true) */ + \
  413. 2 /* last byte written */ + \
  414. 1 /* nt_timechanged (false) */ + \
  415. 1 /* layoutupdate4 layout type */ + \
  416. 1 /* layoutupdate4 opaqueue len */)
  417. /* the actual content of layoutupdate4 should
  418. be allocated by drivers and spliced in
  419. using xdr_write_pages */
  420. #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
  421. #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
  422. encode_stateid_maxsz + \
  423. 1 + \
  424. XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
  425. #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
  426. 1 + decode_stateid_maxsz)
  427. #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
  428. #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
  429. #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
  430. XDR_QUADLEN(NFS4_STATEID_SIZE))
  431. #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
  432. #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
  433. XDR_QUADLEN(NFS4_STATEID_SIZE))
  434. #define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
  435. #else /* CONFIG_NFS_V4_1 */
  436. #define encode_sequence_maxsz 0
  437. #define decode_sequence_maxsz 0
  438. #define encode_layoutreturn_maxsz 0
  439. #define decode_layoutreturn_maxsz 0
  440. #define encode_layoutget_maxsz 0
  441. #define decode_layoutget_maxsz 0
  442. #endif /* CONFIG_NFS_V4_1 */
  443. #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
  444. #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
  445. #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
  446. encode_sequence_maxsz + \
  447. encode_putfh_maxsz + \
  448. encode_read_maxsz)
  449. #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
  450. decode_sequence_maxsz + \
  451. decode_putfh_maxsz + \
  452. decode_read_maxsz)
  453. #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
  454. encode_sequence_maxsz + \
  455. encode_putfh_maxsz + \
  456. encode_readlink_maxsz)
  457. #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
  458. decode_sequence_maxsz + \
  459. decode_putfh_maxsz + \
  460. decode_readlink_maxsz)
  461. #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
  462. encode_sequence_maxsz + \
  463. encode_putfh_maxsz + \
  464. encode_readdir_maxsz)
  465. #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
  466. decode_sequence_maxsz + \
  467. decode_putfh_maxsz + \
  468. decode_readdir_maxsz)
  469. #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
  470. encode_sequence_maxsz + \
  471. encode_putfh_maxsz + \
  472. encode_write_maxsz + \
  473. encode_getattr_maxsz)
  474. #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
  475. decode_sequence_maxsz + \
  476. decode_putfh_maxsz + \
  477. decode_write_maxsz + \
  478. decode_getattr_maxsz)
  479. #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
  480. encode_sequence_maxsz + \
  481. encode_putfh_maxsz + \
  482. encode_commit_maxsz)
  483. #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
  484. decode_sequence_maxsz + \
  485. decode_putfh_maxsz + \
  486. decode_commit_maxsz)
  487. #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
  488. encode_sequence_maxsz + \
  489. encode_putfh_maxsz + \
  490. encode_open_maxsz + \
  491. encode_access_maxsz + \
  492. encode_getfh_maxsz + \
  493. encode_getattr_maxsz + \
  494. encode_layoutget_maxsz)
  495. #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
  496. decode_sequence_maxsz + \
  497. decode_putfh_maxsz + \
  498. decode_open_maxsz + \
  499. decode_access_maxsz + \
  500. decode_getfh_maxsz + \
  501. decode_getattr_maxsz + \
  502. decode_layoutget_maxsz)
  503. #define NFS4_enc_open_confirm_sz \
  504. (compound_encode_hdr_maxsz + \
  505. encode_putfh_maxsz + \
  506. encode_open_confirm_maxsz)
  507. #define NFS4_dec_open_confirm_sz \
  508. (compound_decode_hdr_maxsz + \
  509. decode_putfh_maxsz + \
  510. decode_open_confirm_maxsz)
  511. #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
  512. encode_sequence_maxsz + \
  513. encode_putfh_maxsz + \
  514. encode_open_maxsz + \
  515. encode_access_maxsz + \
  516. encode_getattr_maxsz + \
  517. encode_layoutget_maxsz)
  518. #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
  519. decode_sequence_maxsz + \
  520. decode_putfh_maxsz + \
  521. decode_open_maxsz + \
  522. decode_access_maxsz + \
  523. decode_getattr_maxsz + \
  524. decode_layoutget_maxsz)
  525. #define NFS4_enc_open_downgrade_sz \
  526. (compound_encode_hdr_maxsz + \
  527. encode_sequence_maxsz + \
  528. encode_putfh_maxsz + \
  529. encode_layoutreturn_maxsz + \
  530. encode_open_downgrade_maxsz)
  531. #define NFS4_dec_open_downgrade_sz \
  532. (compound_decode_hdr_maxsz + \
  533. decode_sequence_maxsz + \
  534. decode_putfh_maxsz + \
  535. decode_layoutreturn_maxsz + \
  536. decode_open_downgrade_maxsz)
  537. #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
  538. encode_sequence_maxsz + \
  539. encode_putfh_maxsz + \
  540. encode_layoutreturn_maxsz + \
  541. encode_close_maxsz + \
  542. encode_getattr_maxsz)
  543. #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
  544. decode_sequence_maxsz + \
  545. decode_putfh_maxsz + \
  546. decode_layoutreturn_maxsz + \
  547. decode_close_maxsz + \
  548. decode_getattr_maxsz)
  549. #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
  550. encode_sequence_maxsz + \
  551. encode_putfh_maxsz + \
  552. encode_setattr_maxsz + \
  553. encode_getattr_maxsz)
  554. #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
  555. decode_sequence_maxsz + \
  556. decode_putfh_maxsz + \
  557. decode_setattr_maxsz + \
  558. decode_getattr_maxsz)
  559. #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
  560. encode_sequence_maxsz + \
  561. encode_putfh_maxsz + \
  562. encode_fsinfo_maxsz)
  563. #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
  564. decode_sequence_maxsz + \
  565. decode_putfh_maxsz + \
  566. decode_fsinfo_maxsz)
  567. #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
  568. encode_renew_maxsz)
  569. #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
  570. decode_renew_maxsz)
  571. #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
  572. encode_setclientid_maxsz)
  573. #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
  574. decode_setclientid_maxsz)
  575. #define NFS4_enc_setclientid_confirm_sz \
  576. (compound_encode_hdr_maxsz + \
  577. encode_setclientid_confirm_maxsz)
  578. #define NFS4_dec_setclientid_confirm_sz \
  579. (compound_decode_hdr_maxsz + \
  580. decode_setclientid_confirm_maxsz)
  581. #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
  582. encode_sequence_maxsz + \
  583. encode_putfh_maxsz + \
  584. encode_lock_maxsz)
  585. #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
  586. decode_sequence_maxsz + \
  587. decode_putfh_maxsz + \
  588. decode_lock_maxsz)
  589. #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
  590. encode_sequence_maxsz + \
  591. encode_putfh_maxsz + \
  592. encode_lockt_maxsz)
  593. #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
  594. decode_sequence_maxsz + \
  595. decode_putfh_maxsz + \
  596. decode_lockt_maxsz)
  597. #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
  598. encode_sequence_maxsz + \
  599. encode_putfh_maxsz + \
  600. encode_locku_maxsz)
  601. #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
  602. decode_sequence_maxsz + \
  603. decode_putfh_maxsz + \
  604. decode_locku_maxsz)
  605. #define NFS4_enc_release_lockowner_sz \
  606. (compound_encode_hdr_maxsz + \
  607. encode_lockowner_maxsz)
  608. #define NFS4_dec_release_lockowner_sz \
  609. (compound_decode_hdr_maxsz + \
  610. decode_release_lockowner_maxsz)
  611. #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
  612. encode_sequence_maxsz + \
  613. encode_putfh_maxsz + \
  614. encode_access_maxsz + \
  615. encode_getattr_maxsz)
  616. #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
  617. decode_sequence_maxsz + \
  618. decode_putfh_maxsz + \
  619. decode_access_maxsz + \
  620. decode_getattr_maxsz)
  621. #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
  622. encode_sequence_maxsz + \
  623. encode_putfh_maxsz + \
  624. encode_getattr_maxsz + \
  625. encode_renew_maxsz)
  626. #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
  627. decode_sequence_maxsz + \
  628. decode_putfh_maxsz + \
  629. decode_getattr_maxsz + \
  630. decode_renew_maxsz)
  631. #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
  632. encode_sequence_maxsz + \
  633. encode_putfh_maxsz + \
  634. encode_lookup_maxsz + \
  635. encode_getattr_maxsz + \
  636. encode_getfh_maxsz)
  637. #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
  638. decode_sequence_maxsz + \
  639. decode_putfh_maxsz + \
  640. decode_lookup_maxsz + \
  641. decode_getattr_maxsz + \
  642. decode_getfh_maxsz)
  643. #define NFS4_enc_lookupp_sz (compound_encode_hdr_maxsz + \
  644. encode_sequence_maxsz + \
  645. encode_putfh_maxsz + \
  646. encode_lookupp_maxsz + \
  647. encode_getattr_maxsz + \
  648. encode_getfh_maxsz)
  649. #define NFS4_dec_lookupp_sz (compound_decode_hdr_maxsz + \
  650. decode_sequence_maxsz + \
  651. decode_putfh_maxsz + \
  652. decode_lookupp_maxsz + \
  653. decode_getattr_maxsz + \
  654. decode_getfh_maxsz)
  655. #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
  656. encode_sequence_maxsz + \
  657. encode_putrootfh_maxsz + \
  658. encode_getattr_maxsz + \
  659. encode_getfh_maxsz)
  660. #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
  661. decode_sequence_maxsz + \
  662. decode_putrootfh_maxsz + \
  663. decode_getattr_maxsz + \
  664. decode_getfh_maxsz)
  665. #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
  666. encode_sequence_maxsz + \
  667. encode_putfh_maxsz + \
  668. encode_remove_maxsz)
  669. #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
  670. decode_sequence_maxsz + \
  671. decode_putfh_maxsz + \
  672. decode_remove_maxsz)
  673. #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
  674. encode_sequence_maxsz + \
  675. encode_putfh_maxsz + \
  676. encode_savefh_maxsz + \
  677. encode_putfh_maxsz + \
  678. encode_rename_maxsz)
  679. #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
  680. decode_sequence_maxsz + \
  681. decode_putfh_maxsz + \
  682. decode_savefh_maxsz + \
  683. decode_putfh_maxsz + \
  684. decode_rename_maxsz)
  685. #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
  686. encode_sequence_maxsz + \
  687. encode_putfh_maxsz + \
  688. encode_savefh_maxsz + \
  689. encode_putfh_maxsz + \
  690. encode_link_maxsz + \
  691. encode_restorefh_maxsz + \
  692. encode_getattr_maxsz)
  693. #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
  694. decode_sequence_maxsz + \
  695. decode_putfh_maxsz + \
  696. decode_savefh_maxsz + \
  697. decode_putfh_maxsz + \
  698. decode_link_maxsz + \
  699. decode_restorefh_maxsz + \
  700. decode_getattr_maxsz)
  701. #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
  702. encode_sequence_maxsz + \
  703. encode_putfh_maxsz + \
  704. encode_symlink_maxsz + \
  705. encode_getattr_maxsz + \
  706. encode_getfh_maxsz)
  707. #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
  708. decode_sequence_maxsz + \
  709. decode_putfh_maxsz + \
  710. decode_symlink_maxsz + \
  711. decode_getattr_maxsz + \
  712. decode_getfh_maxsz)
  713. #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
  714. encode_sequence_maxsz + \
  715. encode_putfh_maxsz + \
  716. encode_create_maxsz + \
  717. encode_getfh_maxsz + \
  718. encode_getattr_maxsz)
  719. #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
  720. decode_sequence_maxsz + \
  721. decode_putfh_maxsz + \
  722. decode_create_maxsz + \
  723. decode_getfh_maxsz + \
  724. decode_getattr_maxsz)
  725. #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
  726. encode_sequence_maxsz + \
  727. encode_putfh_maxsz + \
  728. encode_getattr_maxsz)
  729. #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
  730. decode_sequence_maxsz + \
  731. decode_putfh_maxsz + \
  732. decode_getattr_maxsz)
  733. #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
  734. encode_sequence_maxsz + \
  735. encode_putfh_maxsz + \
  736. encode_statfs_maxsz)
  737. #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
  738. decode_sequence_maxsz + \
  739. decode_putfh_maxsz + \
  740. decode_statfs_maxsz)
  741. #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
  742. encode_sequence_maxsz + \
  743. encode_putfh_maxsz + \
  744. encode_getattr_maxsz)
  745. #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
  746. decode_sequence_maxsz + \
  747. decode_putfh_maxsz + \
  748. decode_getattr_maxsz)
  749. #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
  750. encode_sequence_maxsz + \
  751. encode_putfh_maxsz + \
  752. encode_layoutreturn_maxsz + \
  753. encode_delegattr_maxsz + \
  754. encode_delegreturn_maxsz + \
  755. encode_getattr_maxsz)
  756. #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
  757. decode_sequence_maxsz + \
  758. decode_putfh_maxsz + \
  759. decode_layoutreturn_maxsz + \
  760. decode_delegattr_maxsz + \
  761. decode_delegreturn_maxsz + \
  762. decode_getattr_maxsz)
  763. #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
  764. encode_sequence_maxsz + \
  765. encode_putfh_maxsz + \
  766. encode_getacl_maxsz)
  767. #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
  768. decode_sequence_maxsz + \
  769. decode_putfh_maxsz + \
  770. decode_getacl_maxsz)
  771. #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
  772. encode_sequence_maxsz + \
  773. encode_putfh_maxsz + \
  774. encode_setacl_maxsz)
  775. #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
  776. decode_sequence_maxsz + \
  777. decode_putfh_maxsz + \
  778. decode_setacl_maxsz)
  779. #define NFS4_enc_fs_locations_sz \
  780. (compound_encode_hdr_maxsz + \
  781. encode_sequence_maxsz + \
  782. encode_putfh_maxsz + \
  783. encode_lookup_maxsz + \
  784. encode_fs_locations_maxsz + \
  785. encode_renew_maxsz)
  786. #define NFS4_dec_fs_locations_sz \
  787. (compound_decode_hdr_maxsz + \
  788. decode_sequence_maxsz + \
  789. decode_putfh_maxsz + \
  790. decode_lookup_maxsz + \
  791. decode_fs_locations_maxsz + \
  792. decode_renew_maxsz)
  793. #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
  794. encode_sequence_maxsz + \
  795. encode_putfh_maxsz + \
  796. encode_secinfo_maxsz)
  797. #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
  798. decode_sequence_maxsz + \
  799. decode_putfh_maxsz + \
  800. decode_secinfo_maxsz)
  801. #define NFS4_enc_fsid_present_sz \
  802. (compound_encode_hdr_maxsz + \
  803. encode_sequence_maxsz + \
  804. encode_putfh_maxsz + \
  805. encode_getfh_maxsz + \
  806. encode_renew_maxsz)
  807. #define NFS4_dec_fsid_present_sz \
  808. (compound_decode_hdr_maxsz + \
  809. decode_sequence_maxsz + \
  810. decode_putfh_maxsz + \
  811. decode_getfh_maxsz + \
  812. decode_renew_maxsz)
  813. #if defined(CONFIG_NFS_V4_1)
  814. #define NFS4_enc_bind_conn_to_session_sz \
  815. (compound_encode_hdr_maxsz + \
  816. encode_bind_conn_to_session_maxsz)
  817. #define NFS4_dec_bind_conn_to_session_sz \
  818. (compound_decode_hdr_maxsz + \
  819. decode_bind_conn_to_session_maxsz)
  820. #define NFS4_enc_exchange_id_sz \
  821. (compound_encode_hdr_maxsz + \
  822. encode_exchange_id_maxsz)
  823. #define NFS4_dec_exchange_id_sz \
  824. (compound_decode_hdr_maxsz + \
  825. decode_exchange_id_maxsz)
  826. #define NFS4_enc_create_session_sz \
  827. (compound_encode_hdr_maxsz + \
  828. encode_create_session_maxsz)
  829. #define NFS4_dec_create_session_sz \
  830. (compound_decode_hdr_maxsz + \
  831. decode_create_session_maxsz)
  832. #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
  833. encode_destroy_session_maxsz)
  834. #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
  835. decode_destroy_session_maxsz)
  836. #define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
  837. encode_destroy_clientid_maxsz)
  838. #define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
  839. decode_destroy_clientid_maxsz)
  840. #define NFS4_enc_sequence_sz \
  841. (compound_decode_hdr_maxsz + \
  842. encode_sequence_maxsz)
  843. #define NFS4_dec_sequence_sz \
  844. (compound_decode_hdr_maxsz + \
  845. decode_sequence_maxsz)
  846. #endif
  847. #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
  848. encode_sequence_maxsz + \
  849. encode_putrootfh_maxsz + \
  850. encode_fsinfo_maxsz)
  851. #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
  852. decode_sequence_maxsz + \
  853. decode_putrootfh_maxsz + \
  854. decode_fsinfo_maxsz)
  855. #if defined(CONFIG_NFS_V4_1)
  856. #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
  857. encode_sequence_maxsz + \
  858. encode_reclaim_complete_maxsz)
  859. #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
  860. decode_sequence_maxsz + \
  861. decode_reclaim_complete_maxsz)
  862. #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
  863. encode_sequence_maxsz +\
  864. encode_getdeviceinfo_maxsz)
  865. #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
  866. decode_sequence_maxsz + \
  867. decode_getdeviceinfo_maxsz)
  868. #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
  869. encode_sequence_maxsz + \
  870. encode_putfh_maxsz + \
  871. encode_layoutget_maxsz)
  872. #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
  873. decode_sequence_maxsz + \
  874. decode_putfh_maxsz + \
  875. decode_layoutget_maxsz)
  876. #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
  877. encode_sequence_maxsz +\
  878. encode_putfh_maxsz + \
  879. encode_layoutcommit_maxsz + \
  880. encode_getattr_maxsz)
  881. #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
  882. decode_sequence_maxsz + \
  883. decode_putfh_maxsz + \
  884. decode_layoutcommit_maxsz + \
  885. decode_getattr_maxsz)
  886. #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
  887. encode_sequence_maxsz + \
  888. encode_putfh_maxsz + \
  889. encode_layoutreturn_maxsz)
  890. #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
  891. decode_sequence_maxsz + \
  892. decode_putfh_maxsz + \
  893. decode_layoutreturn_maxsz)
  894. #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
  895. encode_sequence_maxsz + \
  896. encode_putrootfh_maxsz +\
  897. encode_secinfo_no_name_maxsz)
  898. #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
  899. decode_sequence_maxsz + \
  900. decode_putrootfh_maxsz + \
  901. decode_secinfo_no_name_maxsz)
  902. #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
  903. encode_sequence_maxsz + \
  904. encode_test_stateid_maxsz)
  905. #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
  906. decode_sequence_maxsz + \
  907. decode_test_stateid_maxsz)
  908. #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
  909. encode_sequence_maxsz + \
  910. encode_free_stateid_maxsz)
  911. #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
  912. decode_sequence_maxsz + \
  913. decode_free_stateid_maxsz)
  914. const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
  915. compound_encode_hdr_maxsz +
  916. encode_sequence_maxsz +
  917. encode_putfh_maxsz +
  918. encode_getattr_maxsz) *
  919. XDR_UNIT);
  920. const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
  921. compound_decode_hdr_maxsz +
  922. decode_sequence_maxsz +
  923. decode_putfh_maxsz) *
  924. XDR_UNIT);
  925. const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
  926. compound_decode_hdr_maxsz +
  927. decode_sequence_maxsz) *
  928. XDR_UNIT);
  929. EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
  930. #endif /* CONFIG_NFS_V4_1 */
  931. static const umode_t nfs_type2fmt[] = {
  932. [NF4BAD] = 0,
  933. [NF4REG] = S_IFREG,
  934. [NF4DIR] = S_IFDIR,
  935. [NF4BLK] = S_IFBLK,
  936. [NF4CHR] = S_IFCHR,
  937. [NF4LNK] = S_IFLNK,
  938. [NF4SOCK] = S_IFSOCK,
  939. [NF4FIFO] = S_IFIFO,
  940. [NF4ATTRDIR] = 0,
  941. [NF4NAMEDATTR] = 0,
  942. };
  943. struct compound_hdr {
  944. int32_t status;
  945. uint32_t nops;
  946. __be32 * nops_p;
  947. uint32_t taglen;
  948. char * tag;
  949. uint32_t replen; /* expected reply words */
  950. u32 minorversion;
  951. };
  952. static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
  953. {
  954. __be32 *p = xdr_reserve_space(xdr, nbytes);
  955. BUG_ON(!p);
  956. return p;
  957. }
  958. static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
  959. {
  960. WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0);
  961. }
  962. static void encode_uint32(struct xdr_stream *xdr, u32 n)
  963. {
  964. WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0);
  965. }
  966. static void encode_uint64(struct xdr_stream *xdr, u64 n)
  967. {
  968. WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0);
  969. }
  970. static ssize_t xdr_encode_bitmap4(struct xdr_stream *xdr,
  971. const __u32 *bitmap, size_t len)
  972. {
  973. ssize_t ret;
  974. /* Trim empty words */
  975. while (len > 0 && bitmap[len-1] == 0)
  976. len--;
  977. ret = xdr_stream_encode_uint32_array(xdr, bitmap, len);
  978. if (WARN_ON_ONCE(ret < 0))
  979. return ret;
  980. return len;
  981. }
  982. static size_t mask_bitmap4(const __u32 *bitmap, const __u32 *mask,
  983. __u32 *res, size_t len)
  984. {
  985. size_t i;
  986. __u32 tmp;
  987. while (len > 0 && (bitmap[len-1] == 0 || mask[len-1] == 0))
  988. len--;
  989. for (i = len; i-- > 0;) {
  990. tmp = bitmap[i] & mask[i];
  991. res[i] = tmp;
  992. }
  993. return len;
  994. }
  995. static void encode_nfs4_seqid(struct xdr_stream *xdr,
  996. const struct nfs_seqid *seqid)
  997. {
  998. if (seqid != NULL)
  999. encode_uint32(xdr, seqid->sequence->counter);
  1000. else
  1001. encode_uint32(xdr, 0);
  1002. }
  1003. static void encode_compound_hdr(struct xdr_stream *xdr,
  1004. struct rpc_rqst *req,
  1005. struct compound_hdr *hdr)
  1006. {
  1007. __be32 *p;
  1008. /* initialize running count of expected bytes in reply.
  1009. * NOTE: the replied tag SHOULD be the same is the one sent,
  1010. * but this is not required as a MUST for the server to do so. */
  1011. hdr->replen = 3 + hdr->taglen;
  1012. WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
  1013. encode_string(xdr, hdr->taglen, hdr->tag);
  1014. p = reserve_space(xdr, 8);
  1015. *p++ = cpu_to_be32(hdr->minorversion);
  1016. hdr->nops_p = p;
  1017. *p = cpu_to_be32(hdr->nops);
  1018. }
  1019. static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
  1020. uint32_t replen,
  1021. struct compound_hdr *hdr)
  1022. {
  1023. encode_uint32(xdr, op);
  1024. hdr->nops++;
  1025. hdr->replen += replen;
  1026. }
  1027. static void encode_nops(struct compound_hdr *hdr)
  1028. {
  1029. WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
  1030. *hdr->nops_p = htonl(hdr->nops);
  1031. }
  1032. static void encode_nfs4_stateid(struct xdr_stream *xdr,
  1033. const nfs4_stateid *stateid)
  1034. {
  1035. encode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
  1036. }
  1037. static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
  1038. {
  1039. encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
  1040. }
  1041. static __be32 *
  1042. xdr_encode_nfstime4(__be32 *p, const struct timespec64 *t)
  1043. {
  1044. p = xdr_encode_hyper(p, t->tv_sec);
  1045. *p++ = cpu_to_be32(t->tv_nsec);
  1046. return p;
  1047. }
  1048. static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
  1049. const struct nfs4_label *label,
  1050. const umode_t *umask,
  1051. const struct nfs_server *server,
  1052. const uint32_t attrmask[])
  1053. {
  1054. char owner_name[IDMAP_NAMESZ];
  1055. char owner_group[IDMAP_NAMESZ];
  1056. int owner_namelen = 0;
  1057. int owner_grouplen = 0;
  1058. __be32 *p;
  1059. uint32_t len = 0;
  1060. uint32_t bmval[3] = { 0 };
  1061. /*
  1062. * We reserve enough space to write the entire attribute buffer at once.
  1063. */
  1064. if ((iap->ia_valid & ATTR_SIZE) && (attrmask[0] & FATTR4_WORD0_SIZE)) {
  1065. bmval[0] |= FATTR4_WORD0_SIZE;
  1066. len += 8;
  1067. }
  1068. if (iap->ia_valid & ATTR_MODE) {
  1069. if (umask && (attrmask[2] & FATTR4_WORD2_MODE_UMASK)) {
  1070. bmval[2] |= FATTR4_WORD2_MODE_UMASK;
  1071. len += 8;
  1072. } else if (attrmask[1] & FATTR4_WORD1_MODE) {
  1073. bmval[1] |= FATTR4_WORD1_MODE;
  1074. len += 4;
  1075. }
  1076. }
  1077. if ((iap->ia_valid & ATTR_UID) && (attrmask[1] & FATTR4_WORD1_OWNER)) {
  1078. owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
  1079. if (owner_namelen < 0) {
  1080. dprintk("nfs: couldn't resolve uid %d to string\n",
  1081. from_kuid(&init_user_ns, iap->ia_uid));
  1082. /* XXX */
  1083. strcpy(owner_name, "nobody");
  1084. owner_namelen = sizeof("nobody") - 1;
  1085. /* goto out; */
  1086. }
  1087. bmval[1] |= FATTR4_WORD1_OWNER;
  1088. len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
  1089. }
  1090. if ((iap->ia_valid & ATTR_GID) &&
  1091. (attrmask[1] & FATTR4_WORD1_OWNER_GROUP)) {
  1092. owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
  1093. if (owner_grouplen < 0) {
  1094. dprintk("nfs: couldn't resolve gid %d to string\n",
  1095. from_kgid(&init_user_ns, iap->ia_gid));
  1096. strcpy(owner_group, "nobody");
  1097. owner_grouplen = sizeof("nobody") - 1;
  1098. /* goto out; */
  1099. }
  1100. bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
  1101. len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
  1102. }
  1103. if (attrmask[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
  1104. if (iap->ia_valid & ATTR_ATIME_SET) {
  1105. bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
  1106. len += 4 + (nfstime4_maxsz << 2);
  1107. } else if (iap->ia_valid & ATTR_ATIME) {
  1108. bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
  1109. len += 4;
  1110. }
  1111. }
  1112. if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
  1113. if (iap->ia_valid & ATTR_MTIME_SET) {
  1114. bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
  1115. len += 4 + (nfstime4_maxsz << 2);
  1116. } else if (iap->ia_valid & ATTR_MTIME) {
  1117. bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
  1118. len += 4;
  1119. }
  1120. }
  1121. if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) {
  1122. len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
  1123. bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
  1124. }
  1125. xdr_encode_bitmap4(xdr, bmval, ARRAY_SIZE(bmval));
  1126. xdr_stream_encode_opaque_inline(xdr, (void **)&p, len);
  1127. if (bmval[0] & FATTR4_WORD0_SIZE)
  1128. p = xdr_encode_hyper(p, iap->ia_size);
  1129. if (bmval[1] & FATTR4_WORD1_MODE)
  1130. *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
  1131. if (bmval[1] & FATTR4_WORD1_OWNER)
  1132. p = xdr_encode_opaque(p, owner_name, owner_namelen);
  1133. if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
  1134. p = xdr_encode_opaque(p, owner_group, owner_grouplen);
  1135. if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
  1136. if (iap->ia_valid & ATTR_ATIME_SET) {
  1137. *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
  1138. p = xdr_encode_nfstime4(p, &iap->ia_atime);
  1139. } else
  1140. *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
  1141. }
  1142. if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
  1143. if (iap->ia_valid & ATTR_MTIME_SET) {
  1144. *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
  1145. p = xdr_encode_nfstime4(p, &iap->ia_mtime);
  1146. } else
  1147. *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
  1148. }
  1149. if (label && (bmval[2] & FATTR4_WORD2_SECURITY_LABEL)) {
  1150. *p++ = cpu_to_be32(label->lfs);
  1151. *p++ = cpu_to_be32(label->pi);
  1152. *p++ = cpu_to_be32(label->len);
  1153. p = xdr_encode_opaque_fixed(p, label->label, label->len);
  1154. }
  1155. if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
  1156. *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
  1157. *p++ = cpu_to_be32(*umask);
  1158. }
  1159. /* out: */
  1160. }
  1161. static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
  1162. {
  1163. encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
  1164. encode_uint32(xdr, access);
  1165. }
  1166. static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
  1167. {
  1168. encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
  1169. encode_nfs4_seqid(xdr, arg->seqid);
  1170. encode_nfs4_stateid(xdr, &arg->stateid);
  1171. }
  1172. static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
  1173. {
  1174. __be32 *p;
  1175. encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
  1176. p = reserve_space(xdr, 12);
  1177. p = xdr_encode_hyper(p, args->offset);
  1178. *p = cpu_to_be32(args->count);
  1179. }
  1180. static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
  1181. {
  1182. __be32 *p;
  1183. encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
  1184. encode_uint32(xdr, create->ftype);
  1185. switch (create->ftype) {
  1186. case NF4LNK:
  1187. p = reserve_space(xdr, 4);
  1188. *p = cpu_to_be32(create->u.symlink.len);
  1189. xdr_write_pages(xdr, create->u.symlink.pages, 0,
  1190. create->u.symlink.len);
  1191. xdr->buf->flags |= XDRBUF_WRITE;
  1192. break;
  1193. case NF4BLK: case NF4CHR:
  1194. p = reserve_space(xdr, 8);
  1195. *p++ = cpu_to_be32(create->u.device.specdata1);
  1196. *p = cpu_to_be32(create->u.device.specdata2);
  1197. break;
  1198. default:
  1199. break;
  1200. }
  1201. encode_string(xdr, create->name->len, create->name->name);
  1202. encode_attrs(xdr, create->attrs, create->label, &create->umask,
  1203. create->server, create->server->attr_bitmask);
  1204. }
  1205. static void encode_getattr(struct xdr_stream *xdr,
  1206. const __u32 *bitmap, const __u32 *mask, size_t len,
  1207. struct compound_hdr *hdr)
  1208. {
  1209. __u32 masked_bitmap[nfs4_fattr_bitmap_maxsz];
  1210. encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
  1211. if (mask) {
  1212. if (WARN_ON_ONCE(len > ARRAY_SIZE(masked_bitmap)))
  1213. len = ARRAY_SIZE(masked_bitmap);
  1214. len = mask_bitmap4(bitmap, mask, masked_bitmap, len);
  1215. bitmap = masked_bitmap;
  1216. }
  1217. xdr_encode_bitmap4(xdr, bitmap, len);
  1218. }
  1219. static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
  1220. {
  1221. encode_getattr(xdr, nfs4_fattr_bitmap, bitmask,
  1222. ARRAY_SIZE(nfs4_fattr_bitmap), hdr);
  1223. }
  1224. static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
  1225. const u32 *open_bitmap,
  1226. struct compound_hdr *hdr)
  1227. {
  1228. encode_getattr(xdr, open_bitmap, bitmask, 3, hdr);
  1229. }
  1230. static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
  1231. {
  1232. encode_getattr(xdr, nfs4_fsinfo_bitmap, bitmask,
  1233. ARRAY_SIZE(nfs4_fsinfo_bitmap), hdr);
  1234. }
  1235. static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
  1236. {
  1237. encode_getattr(xdr, nfs4_fs_locations_bitmap, bitmask,
  1238. ARRAY_SIZE(nfs4_fs_locations_bitmap), hdr);
  1239. }
  1240. static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
  1241. {
  1242. encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
  1243. }
  1244. static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
  1245. {
  1246. encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
  1247. encode_string(xdr, name->len, name->name);
  1248. }
  1249. static inline int nfs4_lock_type(struct file_lock *fl, int block)
  1250. {
  1251. if (lock_is_read(fl))
  1252. return block ? NFS4_READW_LT : NFS4_READ_LT;
  1253. return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
  1254. }
  1255. static inline uint64_t nfs4_lock_length(struct file_lock *fl)
  1256. {
  1257. if (fl->fl_end == OFFSET_MAX)
  1258. return ~(uint64_t)0;
  1259. return fl->fl_end - fl->fl_start + 1;
  1260. }
  1261. static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
  1262. {
  1263. __be32 *p;
  1264. p = reserve_space(xdr, 32);
  1265. p = xdr_encode_hyper(p, lowner->clientid);
  1266. *p++ = cpu_to_be32(20);
  1267. p = xdr_encode_opaque_fixed(p, "lock id:", 8);
  1268. *p++ = cpu_to_be32(lowner->s_dev);
  1269. xdr_encode_hyper(p, lowner->id);
  1270. }
  1271. /*
  1272. * opcode,type,reclaim,offset,length,new_lock_owner = 32
  1273. * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
  1274. */
  1275. static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
  1276. {
  1277. __be32 *p;
  1278. encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
  1279. p = reserve_space(xdr, 28);
  1280. *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
  1281. *p++ = cpu_to_be32(args->reclaim);
  1282. p = xdr_encode_hyper(p, args->fl->fl_start);
  1283. p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
  1284. *p = cpu_to_be32(args->new_lock_owner);
  1285. if (args->new_lock_owner){
  1286. encode_nfs4_seqid(xdr, args->open_seqid);
  1287. encode_nfs4_stateid(xdr, &args->open_stateid);
  1288. encode_nfs4_seqid(xdr, args->lock_seqid);
  1289. encode_lockowner(xdr, &args->lock_owner);
  1290. }
  1291. else {
  1292. encode_nfs4_stateid(xdr, &args->lock_stateid);
  1293. encode_nfs4_seqid(xdr, args->lock_seqid);
  1294. }
  1295. }
  1296. static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
  1297. {
  1298. __be32 *p;
  1299. encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
  1300. p = reserve_space(xdr, 20);
  1301. *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
  1302. p = xdr_encode_hyper(p, args->fl->fl_start);
  1303. p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
  1304. encode_lockowner(xdr, &args->lock_owner);
  1305. }
  1306. static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
  1307. {
  1308. __be32 *p;
  1309. encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
  1310. encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
  1311. encode_nfs4_seqid(xdr, args->seqid);
  1312. encode_nfs4_stateid(xdr, &args->stateid);
  1313. p = reserve_space(xdr, 16);
  1314. p = xdr_encode_hyper(p, args->fl->fl_start);
  1315. xdr_encode_hyper(p, nfs4_lock_length(args->fl));
  1316. }
  1317. static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
  1318. {
  1319. encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
  1320. encode_lockowner(xdr, lowner);
  1321. }
  1322. static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
  1323. {
  1324. encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
  1325. encode_string(xdr, name->len, name->name);
  1326. }
  1327. static void encode_lookupp(struct xdr_stream *xdr, struct compound_hdr *hdr)
  1328. {
  1329. encode_op_hdr(xdr, OP_LOOKUPP, decode_lookupp_maxsz, hdr);
  1330. }
  1331. static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
  1332. {
  1333. __be32 *p;
  1334. p = reserve_space(xdr, 8);
  1335. *p++ = cpu_to_be32(share_access);
  1336. *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
  1337. }
  1338. static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
  1339. {
  1340. __be32 *p;
  1341. /*
  1342. * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
  1343. * owner 28
  1344. */
  1345. encode_nfs4_seqid(xdr, arg->seqid);
  1346. encode_share_access(xdr, arg->share_access);
  1347. p = reserve_space(xdr, 40);
  1348. p = xdr_encode_hyper(p, arg->clientid);
  1349. *p++ = cpu_to_be32(28);
  1350. p = xdr_encode_opaque_fixed(p, "open id:", 8);
  1351. *p++ = cpu_to_be32(arg->server->s_dev);
  1352. p = xdr_encode_hyper(p, arg->id.uniquifier);
  1353. xdr_encode_hyper(p, arg->id.create_time);
  1354. }
  1355. static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
  1356. {
  1357. __be32 *p;
  1358. p = reserve_space(xdr, 4);
  1359. switch(arg->createmode) {
  1360. case NFS4_CREATE_UNCHECKED:
  1361. *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
  1362. encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
  1363. arg->server, arg->server->attr_bitmask);
  1364. break;
  1365. case NFS4_CREATE_GUARDED:
  1366. *p = cpu_to_be32(NFS4_CREATE_GUARDED);
  1367. encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
  1368. arg->server, arg->server->attr_bitmask);
  1369. break;
  1370. case NFS4_CREATE_EXCLUSIVE:
  1371. *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
  1372. encode_nfs4_verifier(xdr, &arg->u.verifier);
  1373. break;
  1374. case NFS4_CREATE_EXCLUSIVE4_1:
  1375. *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
  1376. encode_nfs4_verifier(xdr, &arg->u.verifier);
  1377. encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
  1378. arg->server, arg->server->exclcreat_bitmask);
  1379. }
  1380. }
  1381. static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
  1382. {
  1383. __be32 *p;
  1384. p = reserve_space(xdr, 4);
  1385. switch (arg->open_flags & O_CREAT) {
  1386. case 0:
  1387. *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
  1388. break;
  1389. default:
  1390. *p = cpu_to_be32(NFS4_OPEN_CREATE);
  1391. encode_createmode(xdr, arg);
  1392. }
  1393. }
  1394. static inline void encode_delegation_type(struct xdr_stream *xdr, u32 delegation_type)
  1395. {
  1396. __be32 *p;
  1397. p = reserve_space(xdr, 4);
  1398. switch (delegation_type) {
  1399. case NFS4_OPEN_DELEGATE_NONE:
  1400. case NFS4_OPEN_DELEGATE_READ:
  1401. case NFS4_OPEN_DELEGATE_WRITE:
  1402. case NFS4_OPEN_DELEGATE_READ_ATTRS_DELEG:
  1403. case NFS4_OPEN_DELEGATE_WRITE_ATTRS_DELEG:
  1404. *p = cpu_to_be32(delegation_type);
  1405. break;
  1406. default:
  1407. BUG();
  1408. }
  1409. }
  1410. static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
  1411. {
  1412. __be32 *p;
  1413. p = reserve_space(xdr, 4);
  1414. *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
  1415. encode_string(xdr, name->len, name->name);
  1416. }
  1417. static inline void encode_claim_previous(struct xdr_stream *xdr, u32 type)
  1418. {
  1419. __be32 *p;
  1420. p = reserve_space(xdr, 4);
  1421. *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
  1422. encode_delegation_type(xdr, type);
  1423. }
  1424. static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
  1425. {
  1426. __be32 *p;
  1427. p = reserve_space(xdr, 4);
  1428. *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
  1429. encode_nfs4_stateid(xdr, stateid);
  1430. encode_string(xdr, name->len, name->name);
  1431. }
  1432. static inline void encode_claim_fh(struct xdr_stream *xdr)
  1433. {
  1434. __be32 *p;
  1435. p = reserve_space(xdr, 4);
  1436. *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
  1437. }
  1438. static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
  1439. {
  1440. __be32 *p;
  1441. p = reserve_space(xdr, 4);
  1442. *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
  1443. encode_nfs4_stateid(xdr, stateid);
  1444. }
  1445. static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
  1446. {
  1447. encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
  1448. encode_openhdr(xdr, arg);
  1449. encode_opentype(xdr, arg);
  1450. switch (arg->claim) {
  1451. case NFS4_OPEN_CLAIM_NULL:
  1452. encode_claim_null(xdr, arg->name);
  1453. break;
  1454. case NFS4_OPEN_CLAIM_PREVIOUS:
  1455. encode_claim_previous(xdr, arg->u.delegation_type);
  1456. break;
  1457. case NFS4_OPEN_CLAIM_DELEGATE_CUR:
  1458. encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
  1459. break;
  1460. case NFS4_OPEN_CLAIM_FH:
  1461. encode_claim_fh(xdr);
  1462. break;
  1463. case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
  1464. encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
  1465. break;
  1466. default:
  1467. BUG();
  1468. }
  1469. }
  1470. static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
  1471. {
  1472. encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
  1473. encode_nfs4_stateid(xdr, arg->stateid);
  1474. encode_nfs4_seqid(xdr, arg->seqid);
  1475. }
  1476. static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
  1477. {
  1478. encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
  1479. encode_nfs4_stateid(xdr, &arg->stateid);
  1480. encode_nfs4_seqid(xdr, arg->seqid);
  1481. encode_share_access(xdr, arg->share_access);
  1482. }
  1483. static void
  1484. encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
  1485. {
  1486. encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
  1487. encode_string(xdr, fh->size, fh->data);
  1488. }
  1489. static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
  1490. {
  1491. encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
  1492. }
  1493. static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
  1494. struct compound_hdr *hdr)
  1495. {
  1496. __be32 *p;
  1497. encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
  1498. encode_nfs4_stateid(xdr, &args->stateid);
  1499. p = reserve_space(xdr, 12);
  1500. p = xdr_encode_hyper(p, args->offset);
  1501. *p = cpu_to_be32(args->count);
  1502. }
  1503. static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
  1504. {
  1505. uint32_t attrs[3] = {
  1506. FATTR4_WORD0_TYPE
  1507. | FATTR4_WORD0_RDATTR_ERROR,
  1508. FATTR4_WORD1_MOUNTED_ON_FILEID,
  1509. };
  1510. uint32_t dircount = readdir->count;
  1511. uint32_t maxcount = readdir->count;
  1512. __be32 *p, verf[2];
  1513. uint32_t attrlen = 0;
  1514. unsigned int i;
  1515. if (readdir->plus) {
  1516. attrs[0] |= FATTR4_WORD0_CHANGE
  1517. | FATTR4_WORD0_SIZE
  1518. | FATTR4_WORD0_FSID
  1519. | FATTR4_WORD0_FILEHANDLE
  1520. | FATTR4_WORD0_FILEID;
  1521. attrs[1] |= FATTR4_WORD1_MODE
  1522. | FATTR4_WORD1_NUMLINKS
  1523. | FATTR4_WORD1_OWNER
  1524. | FATTR4_WORD1_OWNER_GROUP
  1525. | FATTR4_WORD1_RAWDEV
  1526. | FATTR4_WORD1_SPACE_USED
  1527. | FATTR4_WORD1_TIME_ACCESS
  1528. | FATTR4_WORD1_TIME_METADATA
  1529. | FATTR4_WORD1_TIME_MODIFY;
  1530. attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
  1531. }
  1532. /* Use mounted_on_fileid only if the server supports it */
  1533. if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
  1534. attrs[0] |= FATTR4_WORD0_FILEID;
  1535. for (i = 0; i < ARRAY_SIZE(attrs); i++) {
  1536. attrs[i] &= readdir->bitmask[i];
  1537. if (attrs[i] != 0)
  1538. attrlen = i+1;
  1539. }
  1540. encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
  1541. encode_uint64(xdr, readdir->cookie);
  1542. encode_nfs4_verifier(xdr, &readdir->verifier);
  1543. p = reserve_space(xdr, 12 + (attrlen << 2));
  1544. *p++ = cpu_to_be32(dircount);
  1545. *p++ = cpu_to_be32(maxcount);
  1546. *p++ = cpu_to_be32(attrlen);
  1547. for (i = 0; i < attrlen; i++)
  1548. *p++ = cpu_to_be32(attrs[i]);
  1549. memcpy(verf, readdir->verifier.data, sizeof(verf));
  1550. dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
  1551. __func__,
  1552. (unsigned long long)readdir->cookie,
  1553. verf[0], verf[1],
  1554. attrs[0] & readdir->bitmask[0],
  1555. attrs[1] & readdir->bitmask[1],
  1556. attrs[2] & readdir->bitmask[2]);
  1557. }
  1558. static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
  1559. {
  1560. encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
  1561. }
  1562. static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
  1563. {
  1564. encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
  1565. encode_string(xdr, name->len, name->name);
  1566. }
  1567. static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
  1568. {
  1569. encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
  1570. encode_string(xdr, oldname->len, oldname->name);
  1571. encode_string(xdr, newname->len, newname->name);
  1572. }
  1573. static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
  1574. struct compound_hdr *hdr)
  1575. {
  1576. encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
  1577. encode_uint64(xdr, clid);
  1578. }
  1579. static void
  1580. encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
  1581. {
  1582. encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
  1583. }
  1584. static void nfs4_acltype_to_bitmap(enum nfs4_acl_type type, __u32 bitmap[2])
  1585. {
  1586. switch (type) {
  1587. default:
  1588. bitmap[0] = FATTR4_WORD0_ACL;
  1589. bitmap[1] = 0;
  1590. break;
  1591. case NFS4ACL_DACL:
  1592. bitmap[0] = 0;
  1593. bitmap[1] = FATTR4_WORD1_DACL;
  1594. break;
  1595. case NFS4ACL_SACL:
  1596. bitmap[0] = 0;
  1597. bitmap[1] = FATTR4_WORD1_SACL;
  1598. }
  1599. }
  1600. static void encode_setacl(struct xdr_stream *xdr,
  1601. const struct nfs_setaclargs *arg,
  1602. struct compound_hdr *hdr)
  1603. {
  1604. __u32 bitmap[2];
  1605. nfs4_acltype_to_bitmap(arg->acl_type, bitmap);
  1606. encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
  1607. encode_nfs4_stateid(xdr, &zero_stateid);
  1608. xdr_encode_bitmap4(xdr, bitmap, ARRAY_SIZE(bitmap));
  1609. encode_uint32(xdr, arg->acl_len);
  1610. xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
  1611. }
  1612. static void
  1613. encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
  1614. {
  1615. encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
  1616. }
  1617. static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
  1618. {
  1619. encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
  1620. encode_nfs4_stateid(xdr, &arg->stateid);
  1621. encode_attrs(xdr, arg->iap, arg->label, NULL, server,
  1622. server->attr_bitmask);
  1623. }
  1624. static void encode_delegattr(struct xdr_stream *xdr,
  1625. const nfs4_stateid *stateid,
  1626. const struct nfs4_delegattr *attr,
  1627. struct compound_hdr *hdr)
  1628. {
  1629. uint32_t bitmap[3] = { 0 };
  1630. uint32_t len = 0;
  1631. __be32 *p;
  1632. encode_op_hdr(xdr, OP_SETATTR, encode_delegattr_maxsz, hdr);
  1633. encode_nfs4_stateid(xdr, stateid);
  1634. if (attr->atime_set) {
  1635. bitmap[2] |= FATTR4_WORD2_TIME_DELEG_ACCESS;
  1636. len += (nfstime4_maxsz << 2);
  1637. }
  1638. if (attr->mtime_set) {
  1639. bitmap[2] |= FATTR4_WORD2_TIME_DELEG_MODIFY;
  1640. len += (nfstime4_maxsz << 2);
  1641. }
  1642. xdr_encode_bitmap4(xdr, bitmap, ARRAY_SIZE(bitmap));
  1643. xdr_stream_encode_opaque_inline(xdr, (void **)&p, len);
  1644. if (bitmap[2] & FATTR4_WORD2_TIME_DELEG_ACCESS)
  1645. p = xdr_encode_nfstime4(p, &attr->atime);
  1646. if (bitmap[2] & FATTR4_WORD2_TIME_DELEG_MODIFY)
  1647. p = xdr_encode_nfstime4(p, &attr->mtime);
  1648. }
  1649. static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
  1650. {
  1651. __be32 *p;
  1652. encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
  1653. encode_nfs4_verifier(xdr, setclientid->sc_verifier);
  1654. encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
  1655. setclientid->sc_clnt->cl_owner_id);
  1656. p = reserve_space(xdr, 4);
  1657. *p = cpu_to_be32(setclientid->sc_prog);
  1658. encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
  1659. encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
  1660. p = reserve_space(xdr, 4);
  1661. *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
  1662. }
  1663. static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
  1664. {
  1665. encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
  1666. decode_setclientid_confirm_maxsz, hdr);
  1667. encode_uint64(xdr, arg->clientid);
  1668. encode_nfs4_verifier(xdr, &arg->confirm);
  1669. }
  1670. static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
  1671. struct compound_hdr *hdr)
  1672. {
  1673. __be32 *p;
  1674. encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
  1675. encode_nfs4_stateid(xdr, &args->stateid);
  1676. p = reserve_space(xdr, 16);
  1677. p = xdr_encode_hyper(p, args->offset);
  1678. *p++ = cpu_to_be32(args->stable);
  1679. *p = cpu_to_be32(args->count);
  1680. xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
  1681. }
  1682. static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
  1683. {
  1684. encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
  1685. encode_nfs4_stateid(xdr, stateid);
  1686. }
  1687. static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
  1688. {
  1689. encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
  1690. encode_string(xdr, name->len, name->name);
  1691. }
  1692. #if defined(CONFIG_NFS_V4_1)
  1693. /* NFSv4.1 operations */
  1694. static void encode_bind_conn_to_session(struct xdr_stream *xdr,
  1695. const struct nfs41_bind_conn_to_session_args *args,
  1696. struct compound_hdr *hdr)
  1697. {
  1698. __be32 *p;
  1699. encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
  1700. decode_bind_conn_to_session_maxsz, hdr);
  1701. encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
  1702. p = xdr_reserve_space(xdr, 8);
  1703. *p++ = cpu_to_be32(args->dir);
  1704. *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
  1705. }
  1706. static void encode_op_map(struct xdr_stream *xdr, const struct nfs4_op_map *op_map)
  1707. {
  1708. unsigned int i;
  1709. encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
  1710. for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
  1711. encode_uint32(xdr, op_map->u.words[i]);
  1712. }
  1713. static void encode_exchange_id(struct xdr_stream *xdr,
  1714. const struct nfs41_exchange_id_args *args,
  1715. struct compound_hdr *hdr)
  1716. {
  1717. __be32 *p;
  1718. char impl_name[IMPL_NAME_LIMIT];
  1719. int len = 0;
  1720. encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
  1721. encode_nfs4_verifier(xdr, &args->verifier);
  1722. encode_string(xdr, strlen(args->client->cl_owner_id),
  1723. args->client->cl_owner_id);
  1724. encode_uint32(xdr, args->flags);
  1725. encode_uint32(xdr, args->state_protect.how);
  1726. switch (args->state_protect.how) {
  1727. case SP4_NONE:
  1728. break;
  1729. case SP4_MACH_CRED:
  1730. encode_op_map(xdr, &args->state_protect.enforce);
  1731. encode_op_map(xdr, &args->state_protect.allow);
  1732. break;
  1733. default:
  1734. WARN_ON_ONCE(1);
  1735. break;
  1736. }
  1737. if (send_implementation_id &&
  1738. sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
  1739. sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
  1740. <= sizeof(impl_name) + 1)
  1741. len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
  1742. utsname()->sysname, utsname()->release,
  1743. utsname()->version, utsname()->machine);
  1744. if (len > 0) {
  1745. encode_uint32(xdr, 1); /* implementation id array length=1 */
  1746. encode_string(xdr,
  1747. sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
  1748. CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
  1749. encode_string(xdr, len, impl_name);
  1750. /* just send zeros for nii_date - the date is in nii_name */
  1751. p = reserve_space(xdr, 12);
  1752. p = xdr_encode_hyper(p, 0);
  1753. *p = cpu_to_be32(0);
  1754. } else
  1755. encode_uint32(xdr, 0); /* implementation id array length=0 */
  1756. }
  1757. static void encode_create_session(struct xdr_stream *xdr,
  1758. const struct nfs41_create_session_args *args,
  1759. struct compound_hdr *hdr)
  1760. {
  1761. __be32 *p;
  1762. struct nfs_client *clp = args->client;
  1763. struct rpc_clnt *clnt = clp->cl_rpcclient;
  1764. struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
  1765. u32 max_resp_sz_cached;
  1766. /*
  1767. * Assumes OPEN is the biggest non-idempotent compound.
  1768. * 2 is the verifier.
  1769. */
  1770. max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 2)
  1771. * XDR_UNIT + RPC_MAX_AUTH_SIZE;
  1772. encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
  1773. p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
  1774. p = xdr_encode_hyper(p, args->clientid);
  1775. *p++ = cpu_to_be32(args->seqid); /*Sequence id */
  1776. *p++ = cpu_to_be32(args->flags); /*flags */
  1777. /* Fore Channel */
  1778. *p++ = cpu_to_be32(0); /* header padding size */
  1779. *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
  1780. *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
  1781. *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
  1782. *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
  1783. *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
  1784. *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
  1785. /* Back Channel */
  1786. *p++ = cpu_to_be32(0); /* header padding size */
  1787. *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
  1788. *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
  1789. *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
  1790. *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
  1791. *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
  1792. *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
  1793. *p++ = cpu_to_be32(args->cb_program); /* cb_program */
  1794. *p++ = cpu_to_be32(1);
  1795. *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
  1796. /* authsys_parms rfc1831 */
  1797. *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */
  1798. p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
  1799. *p++ = cpu_to_be32(0); /* UID */
  1800. *p++ = cpu_to_be32(0); /* GID */
  1801. *p = cpu_to_be32(0); /* No more gids */
  1802. }
  1803. static void encode_destroy_session(struct xdr_stream *xdr,
  1804. const struct nfs4_session *session,
  1805. struct compound_hdr *hdr)
  1806. {
  1807. encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
  1808. encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
  1809. }
  1810. static void encode_destroy_clientid(struct xdr_stream *xdr,
  1811. uint64_t clientid,
  1812. struct compound_hdr *hdr)
  1813. {
  1814. encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
  1815. encode_uint64(xdr, clientid);
  1816. }
  1817. static void encode_reclaim_complete(struct xdr_stream *xdr,
  1818. const struct nfs41_reclaim_complete_args *args,
  1819. struct compound_hdr *hdr)
  1820. {
  1821. encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
  1822. encode_uint32(xdr, args->one_fs);
  1823. }
  1824. #endif /* CONFIG_NFS_V4_1 */
  1825. static void encode_sequence(struct xdr_stream *xdr,
  1826. const struct nfs4_sequence_args *args,
  1827. struct compound_hdr *hdr)
  1828. {
  1829. #if defined(CONFIG_NFS_V4_1)
  1830. struct nfs4_session *session;
  1831. struct nfs4_slot_table *tp;
  1832. struct nfs4_slot *slot = args->sa_slot;
  1833. __be32 *p;
  1834. tp = slot->table;
  1835. session = tp->session;
  1836. if (!session)
  1837. return;
  1838. encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
  1839. /*
  1840. * Sessionid + seqid + slotid + max slotid + cache_this
  1841. */
  1842. dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
  1843. "max_slotid=%d cache_this=%d\n",
  1844. __func__,
  1845. ((u32 *)session->sess_id.data)[0],
  1846. ((u32 *)session->sess_id.data)[1],
  1847. ((u32 *)session->sess_id.data)[2],
  1848. ((u32 *)session->sess_id.data)[3],
  1849. slot->seq_nr, slot->slot_nr,
  1850. tp->highest_used_slotid, args->sa_cache_this);
  1851. p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
  1852. p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
  1853. *p++ = cpu_to_be32(slot->seq_nr);
  1854. *p++ = cpu_to_be32(slot->slot_nr);
  1855. *p++ = cpu_to_be32(tp->highest_used_slotid);
  1856. *p = cpu_to_be32(args->sa_cache_this);
  1857. #endif /* CONFIG_NFS_V4_1 */
  1858. }
  1859. #ifdef CONFIG_NFS_V4_1
  1860. static void
  1861. encode_getdeviceinfo(struct xdr_stream *xdr,
  1862. const struct nfs4_getdeviceinfo_args *args,
  1863. struct compound_hdr *hdr)
  1864. {
  1865. __be32 *p;
  1866. encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
  1867. p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
  1868. p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
  1869. NFS4_DEVICEID4_SIZE);
  1870. *p++ = cpu_to_be32(args->pdev->layout_type);
  1871. *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
  1872. p = reserve_space(xdr, 4 + 4);
  1873. *p++ = cpu_to_be32(1); /* bitmap length */
  1874. *p++ = cpu_to_be32(args->notify_types);
  1875. }
  1876. static void
  1877. encode_layoutget(struct xdr_stream *xdr,
  1878. const struct nfs4_layoutget_args *args,
  1879. struct compound_hdr *hdr)
  1880. {
  1881. __be32 *p;
  1882. encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
  1883. p = reserve_space(xdr, 36);
  1884. *p++ = cpu_to_be32(0); /* Signal layout available */
  1885. *p++ = cpu_to_be32(args->type);
  1886. *p++ = cpu_to_be32(args->range.iomode);
  1887. p = xdr_encode_hyper(p, args->range.offset);
  1888. p = xdr_encode_hyper(p, args->range.length);
  1889. p = xdr_encode_hyper(p, args->minlength);
  1890. encode_nfs4_stateid(xdr, &args->stateid);
  1891. encode_uint32(xdr, args->maxcount);
  1892. dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
  1893. __func__,
  1894. args->type,
  1895. args->range.iomode,
  1896. (unsigned long)args->range.offset,
  1897. (unsigned long)args->range.length,
  1898. args->maxcount);
  1899. }
  1900. static int
  1901. encode_layoutcommit(struct xdr_stream *xdr,
  1902. struct inode *inode,
  1903. const struct nfs4_layoutcommit_args *args,
  1904. struct compound_hdr *hdr)
  1905. {
  1906. __be32 *p;
  1907. dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
  1908. NFS_SERVER(args->inode)->pnfs_curr_ld->id);
  1909. encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
  1910. p = reserve_space(xdr, 20);
  1911. /* Only whole file layouts */
  1912. p = xdr_encode_hyper(p, 0); /* offset */
  1913. p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
  1914. *p = cpu_to_be32(0); /* reclaim */
  1915. encode_nfs4_stateid(xdr, &args->stateid);
  1916. if (args->lastbytewritten != U64_MAX) {
  1917. p = reserve_space(xdr, 20);
  1918. *p++ = cpu_to_be32(1); /* newoffset = TRUE */
  1919. p = xdr_encode_hyper(p, args->lastbytewritten);
  1920. } else {
  1921. p = reserve_space(xdr, 12);
  1922. *p++ = cpu_to_be32(0); /* newoffset = FALSE */
  1923. }
  1924. *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
  1925. *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
  1926. encode_uint32(xdr, args->layoutupdate_len);
  1927. if (args->layoutupdate_pages)
  1928. xdr_write_pages(xdr, args->layoutupdate_pages, 0,
  1929. args->layoutupdate_len);
  1930. return 0;
  1931. }
  1932. static void
  1933. encode_layoutreturn(struct xdr_stream *xdr,
  1934. const struct nfs4_layoutreturn_args *args,
  1935. struct compound_hdr *hdr)
  1936. {
  1937. __be32 *p;
  1938. encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
  1939. p = reserve_space(xdr, 16);
  1940. *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
  1941. *p++ = cpu_to_be32(args->layout_type);
  1942. *p++ = cpu_to_be32(args->range.iomode);
  1943. *p = cpu_to_be32(RETURN_FILE);
  1944. p = reserve_space(xdr, 16);
  1945. p = xdr_encode_hyper(p, args->range.offset);
  1946. p = xdr_encode_hyper(p, args->range.length);
  1947. spin_lock(&args->inode->i_lock);
  1948. encode_nfs4_stateid(xdr, &args->stateid);
  1949. spin_unlock(&args->inode->i_lock);
  1950. if (args->ld_private->ops && args->ld_private->ops->encode)
  1951. args->ld_private->ops->encode(xdr, args, args->ld_private);
  1952. else
  1953. encode_uint32(xdr, 0);
  1954. }
  1955. static int
  1956. encode_secinfo_no_name(struct xdr_stream *xdr,
  1957. const struct nfs41_secinfo_no_name_args *args,
  1958. struct compound_hdr *hdr)
  1959. {
  1960. encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
  1961. encode_uint32(xdr, args->style);
  1962. return 0;
  1963. }
  1964. static void encode_test_stateid(struct xdr_stream *xdr,
  1965. const struct nfs41_test_stateid_args *args,
  1966. struct compound_hdr *hdr)
  1967. {
  1968. encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
  1969. encode_uint32(xdr, 1);
  1970. encode_nfs4_stateid(xdr, &args->stateid);
  1971. }
  1972. static void encode_free_stateid(struct xdr_stream *xdr,
  1973. const struct nfs41_free_stateid_args *args,
  1974. struct compound_hdr *hdr)
  1975. {
  1976. encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
  1977. encode_nfs4_stateid(xdr, &args->stateid);
  1978. }
  1979. #else
  1980. static inline void
  1981. encode_layoutreturn(struct xdr_stream *xdr,
  1982. const struct nfs4_layoutreturn_args *args,
  1983. struct compound_hdr *hdr)
  1984. {
  1985. }
  1986. static void
  1987. encode_layoutget(struct xdr_stream *xdr,
  1988. const struct nfs4_layoutget_args *args,
  1989. struct compound_hdr *hdr)
  1990. {
  1991. }
  1992. #endif /* CONFIG_NFS_V4_1 */
  1993. /*
  1994. * END OF "GENERIC" ENCODE ROUTINES.
  1995. */
  1996. static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
  1997. {
  1998. #if defined(CONFIG_NFS_V4_1)
  1999. struct nfs4_session *session = args->sa_slot->table->session;
  2000. if (session)
  2001. return session->clp->cl_mvops->minor_version;
  2002. #endif /* CONFIG_NFS_V4_1 */
  2003. return 0;
  2004. }
  2005. /*
  2006. * Encode an ACCESS request
  2007. */
  2008. static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
  2009. const void *data)
  2010. {
  2011. const struct nfs4_accessargs *args = data;
  2012. struct compound_hdr hdr = {
  2013. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2014. };
  2015. encode_compound_hdr(xdr, req, &hdr);
  2016. encode_sequence(xdr, &args->seq_args, &hdr);
  2017. encode_putfh(xdr, args->fh, &hdr);
  2018. encode_access(xdr, args->access, &hdr);
  2019. if (args->bitmask)
  2020. encode_getfattr(xdr, args->bitmask, &hdr);
  2021. encode_nops(&hdr);
  2022. }
  2023. /*
  2024. * Encode LOOKUP request
  2025. */
  2026. static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
  2027. const void *data)
  2028. {
  2029. const struct nfs4_lookup_arg *args = data;
  2030. struct compound_hdr hdr = {
  2031. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2032. };
  2033. encode_compound_hdr(xdr, req, &hdr);
  2034. encode_sequence(xdr, &args->seq_args, &hdr);
  2035. encode_putfh(xdr, args->dir_fh, &hdr);
  2036. encode_lookup(xdr, args->name, &hdr);
  2037. encode_getfh(xdr, &hdr);
  2038. encode_getfattr(xdr, args->bitmask, &hdr);
  2039. encode_nops(&hdr);
  2040. }
  2041. /*
  2042. * Encode LOOKUPP request
  2043. */
  2044. static void nfs4_xdr_enc_lookupp(struct rpc_rqst *req, struct xdr_stream *xdr,
  2045. const void *data)
  2046. {
  2047. const struct nfs4_lookupp_arg *args = data;
  2048. struct compound_hdr hdr = {
  2049. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2050. };
  2051. encode_compound_hdr(xdr, req, &hdr);
  2052. encode_sequence(xdr, &args->seq_args, &hdr);
  2053. encode_putfh(xdr, args->fh, &hdr);
  2054. encode_lookupp(xdr, &hdr);
  2055. encode_getfh(xdr, &hdr);
  2056. encode_getfattr(xdr, args->bitmask, &hdr);
  2057. encode_nops(&hdr);
  2058. }
  2059. /*
  2060. * Encode LOOKUP_ROOT request
  2061. */
  2062. static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
  2063. struct xdr_stream *xdr,
  2064. const void *data)
  2065. {
  2066. const struct nfs4_lookup_root_arg *args = data;
  2067. struct compound_hdr hdr = {
  2068. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2069. };
  2070. encode_compound_hdr(xdr, req, &hdr);
  2071. encode_sequence(xdr, &args->seq_args, &hdr);
  2072. encode_putrootfh(xdr, &hdr);
  2073. encode_getfh(xdr, &hdr);
  2074. encode_getfattr(xdr, args->bitmask, &hdr);
  2075. encode_nops(&hdr);
  2076. }
  2077. /*
  2078. * Encode REMOVE request
  2079. */
  2080. static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
  2081. const void *data)
  2082. {
  2083. const struct nfs_removeargs *args = data;
  2084. struct compound_hdr hdr = {
  2085. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2086. };
  2087. encode_compound_hdr(xdr, req, &hdr);
  2088. encode_sequence(xdr, &args->seq_args, &hdr);
  2089. encode_putfh(xdr, args->fh, &hdr);
  2090. encode_remove(xdr, &args->name, &hdr);
  2091. encode_nops(&hdr);
  2092. }
  2093. /*
  2094. * Encode RENAME request
  2095. */
  2096. static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
  2097. const void *data)
  2098. {
  2099. const struct nfs_renameargs *args = data;
  2100. struct compound_hdr hdr = {
  2101. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2102. };
  2103. encode_compound_hdr(xdr, req, &hdr);
  2104. encode_sequence(xdr, &args->seq_args, &hdr);
  2105. encode_putfh(xdr, args->old_dir, &hdr);
  2106. encode_savefh(xdr, &hdr);
  2107. encode_putfh(xdr, args->new_dir, &hdr);
  2108. encode_rename(xdr, args->old_name, args->new_name, &hdr);
  2109. encode_nops(&hdr);
  2110. }
  2111. /*
  2112. * Encode LINK request
  2113. */
  2114. static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
  2115. const void *data)
  2116. {
  2117. const struct nfs4_link_arg *args = data;
  2118. struct compound_hdr hdr = {
  2119. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2120. };
  2121. encode_compound_hdr(xdr, req, &hdr);
  2122. encode_sequence(xdr, &args->seq_args, &hdr);
  2123. encode_putfh(xdr, args->fh, &hdr);
  2124. encode_savefh(xdr, &hdr);
  2125. encode_putfh(xdr, args->dir_fh, &hdr);
  2126. encode_link(xdr, args->name, &hdr);
  2127. encode_restorefh(xdr, &hdr);
  2128. encode_getfattr(xdr, args->bitmask, &hdr);
  2129. encode_nops(&hdr);
  2130. }
  2131. /*
  2132. * Encode CREATE request
  2133. */
  2134. static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
  2135. const void *data)
  2136. {
  2137. const struct nfs4_create_arg *args = data;
  2138. struct compound_hdr hdr = {
  2139. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2140. };
  2141. encode_compound_hdr(xdr, req, &hdr);
  2142. encode_sequence(xdr, &args->seq_args, &hdr);
  2143. encode_putfh(xdr, args->dir_fh, &hdr);
  2144. encode_create(xdr, args, &hdr);
  2145. encode_getfh(xdr, &hdr);
  2146. encode_getfattr(xdr, args->bitmask, &hdr);
  2147. encode_nops(&hdr);
  2148. }
  2149. /*
  2150. * Encode SYMLINK request
  2151. */
  2152. static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
  2153. const void *data)
  2154. {
  2155. const struct nfs4_create_arg *args = data;
  2156. nfs4_xdr_enc_create(req, xdr, args);
  2157. }
  2158. /*
  2159. * Encode GETATTR request
  2160. */
  2161. static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
  2162. const void *data)
  2163. {
  2164. const struct nfs4_getattr_arg *args = data;
  2165. struct compound_hdr hdr = {
  2166. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2167. };
  2168. encode_compound_hdr(xdr, req, &hdr);
  2169. encode_sequence(xdr, &args->seq_args, &hdr);
  2170. encode_putfh(xdr, args->fh, &hdr);
  2171. encode_getfattr(xdr, args->bitmask, &hdr);
  2172. encode_nops(&hdr);
  2173. }
  2174. /*
  2175. * Encode a CLOSE request
  2176. */
  2177. static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
  2178. const void *data)
  2179. {
  2180. const struct nfs_closeargs *args = data;
  2181. struct compound_hdr hdr = {
  2182. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2183. };
  2184. encode_compound_hdr(xdr, req, &hdr);
  2185. encode_sequence(xdr, &args->seq_args, &hdr);
  2186. encode_putfh(xdr, args->fh, &hdr);
  2187. if (args->lr_args)
  2188. encode_layoutreturn(xdr, args->lr_args, &hdr);
  2189. if (args->bitmask != NULL)
  2190. encode_getfattr(xdr, args->bitmask, &hdr);
  2191. encode_close(xdr, args, &hdr);
  2192. encode_nops(&hdr);
  2193. }
  2194. /*
  2195. * Encode an OPEN request
  2196. */
  2197. static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
  2198. const void *data)
  2199. {
  2200. const struct nfs_openargs *args = data;
  2201. struct compound_hdr hdr = {
  2202. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2203. };
  2204. encode_compound_hdr(xdr, req, &hdr);
  2205. encode_sequence(xdr, &args->seq_args, &hdr);
  2206. encode_putfh(xdr, args->fh, &hdr);
  2207. encode_open(xdr, args, &hdr);
  2208. encode_getfh(xdr, &hdr);
  2209. if (args->access)
  2210. encode_access(xdr, args->access, &hdr);
  2211. encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
  2212. if (args->lg_args) {
  2213. encode_layoutget(xdr, args->lg_args, &hdr);
  2214. rpc_prepare_reply_pages(req, args->lg_args->layout.pages, 0,
  2215. args->lg_args->layout.pglen,
  2216. hdr.replen - pagepad_maxsz);
  2217. }
  2218. encode_nops(&hdr);
  2219. }
  2220. /*
  2221. * Encode an OPEN_CONFIRM request
  2222. */
  2223. static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
  2224. struct xdr_stream *xdr,
  2225. const void *data)
  2226. {
  2227. const struct nfs_open_confirmargs *args = data;
  2228. struct compound_hdr hdr = {
  2229. .nops = 0,
  2230. };
  2231. encode_compound_hdr(xdr, req, &hdr);
  2232. encode_putfh(xdr, args->fh, &hdr);
  2233. encode_open_confirm(xdr, args, &hdr);
  2234. encode_nops(&hdr);
  2235. }
  2236. /*
  2237. * Encode an OPEN request with no attributes.
  2238. */
  2239. static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
  2240. struct xdr_stream *xdr,
  2241. const void *data)
  2242. {
  2243. const struct nfs_openargs *args = data;
  2244. struct compound_hdr hdr = {
  2245. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2246. };
  2247. encode_compound_hdr(xdr, req, &hdr);
  2248. encode_sequence(xdr, &args->seq_args, &hdr);
  2249. encode_putfh(xdr, args->fh, &hdr);
  2250. encode_open(xdr, args, &hdr);
  2251. if (args->access)
  2252. encode_access(xdr, args->access, &hdr);
  2253. encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
  2254. if (args->lg_args) {
  2255. encode_layoutget(xdr, args->lg_args, &hdr);
  2256. rpc_prepare_reply_pages(req, args->lg_args->layout.pages, 0,
  2257. args->lg_args->layout.pglen,
  2258. hdr.replen - pagepad_maxsz);
  2259. }
  2260. encode_nops(&hdr);
  2261. }
  2262. /*
  2263. * Encode an OPEN_DOWNGRADE request
  2264. */
  2265. static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
  2266. struct xdr_stream *xdr,
  2267. const void *data)
  2268. {
  2269. const struct nfs_closeargs *args = data;
  2270. struct compound_hdr hdr = {
  2271. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2272. };
  2273. encode_compound_hdr(xdr, req, &hdr);
  2274. encode_sequence(xdr, &args->seq_args, &hdr);
  2275. encode_putfh(xdr, args->fh, &hdr);
  2276. if (args->lr_args)
  2277. encode_layoutreturn(xdr, args->lr_args, &hdr);
  2278. encode_open_downgrade(xdr, args, &hdr);
  2279. encode_nops(&hdr);
  2280. }
  2281. /*
  2282. * Encode a LOCK request
  2283. */
  2284. static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
  2285. const void *data)
  2286. {
  2287. const struct nfs_lock_args *args = data;
  2288. struct compound_hdr hdr = {
  2289. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2290. };
  2291. encode_compound_hdr(xdr, req, &hdr);
  2292. encode_sequence(xdr, &args->seq_args, &hdr);
  2293. encode_putfh(xdr, args->fh, &hdr);
  2294. encode_lock(xdr, args, &hdr);
  2295. encode_nops(&hdr);
  2296. }
  2297. /*
  2298. * Encode a LOCKT request
  2299. */
  2300. static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
  2301. const void *data)
  2302. {
  2303. const struct nfs_lockt_args *args = data;
  2304. struct compound_hdr hdr = {
  2305. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2306. };
  2307. encode_compound_hdr(xdr, req, &hdr);
  2308. encode_sequence(xdr, &args->seq_args, &hdr);
  2309. encode_putfh(xdr, args->fh, &hdr);
  2310. encode_lockt(xdr, args, &hdr);
  2311. encode_nops(&hdr);
  2312. }
  2313. /*
  2314. * Encode a LOCKU request
  2315. */
  2316. static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
  2317. const void *data)
  2318. {
  2319. const struct nfs_locku_args *args = data;
  2320. struct compound_hdr hdr = {
  2321. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2322. };
  2323. encode_compound_hdr(xdr, req, &hdr);
  2324. encode_sequence(xdr, &args->seq_args, &hdr);
  2325. encode_putfh(xdr, args->fh, &hdr);
  2326. encode_locku(xdr, args, &hdr);
  2327. encode_nops(&hdr);
  2328. }
  2329. static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
  2330. struct xdr_stream *xdr,
  2331. const void *data)
  2332. {
  2333. const struct nfs_release_lockowner_args *args = data;
  2334. struct compound_hdr hdr = {
  2335. .minorversion = 0,
  2336. };
  2337. encode_compound_hdr(xdr, req, &hdr);
  2338. encode_release_lockowner(xdr, &args->lock_owner, &hdr);
  2339. encode_nops(&hdr);
  2340. }
  2341. /*
  2342. * Encode a READLINK request
  2343. */
  2344. static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
  2345. const void *data)
  2346. {
  2347. const struct nfs4_readlink *args = data;
  2348. struct compound_hdr hdr = {
  2349. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2350. };
  2351. encode_compound_hdr(xdr, req, &hdr);
  2352. encode_sequence(xdr, &args->seq_args, &hdr);
  2353. encode_putfh(xdr, args->fh, &hdr);
  2354. encode_readlink(xdr, args, req, &hdr);
  2355. rpc_prepare_reply_pages(req, args->pages, args->pgbase,
  2356. args->pglen, hdr.replen - pagepad_maxsz);
  2357. encode_nops(&hdr);
  2358. }
  2359. /*
  2360. * Encode a READDIR request
  2361. */
  2362. static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
  2363. const void *data)
  2364. {
  2365. const struct nfs4_readdir_arg *args = data;
  2366. struct compound_hdr hdr = {
  2367. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2368. };
  2369. encode_compound_hdr(xdr, req, &hdr);
  2370. encode_sequence(xdr, &args->seq_args, &hdr);
  2371. encode_putfh(xdr, args->fh, &hdr);
  2372. encode_readdir(xdr, args, req, &hdr);
  2373. rpc_prepare_reply_pages(req, args->pages, args->pgbase,
  2374. args->count, hdr.replen - pagepad_maxsz);
  2375. encode_nops(&hdr);
  2376. }
  2377. /*
  2378. * Encode a READ request
  2379. */
  2380. static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
  2381. const void *data)
  2382. {
  2383. const struct nfs_pgio_args *args = data;
  2384. struct compound_hdr hdr = {
  2385. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2386. };
  2387. encode_compound_hdr(xdr, req, &hdr);
  2388. encode_sequence(xdr, &args->seq_args, &hdr);
  2389. encode_putfh(xdr, args->fh, &hdr);
  2390. encode_read(xdr, args, &hdr);
  2391. rpc_prepare_reply_pages(req, args->pages, args->pgbase,
  2392. args->count, hdr.replen - pagepad_maxsz);
  2393. req->rq_rcv_buf.flags |= XDRBUF_READ;
  2394. encode_nops(&hdr);
  2395. }
  2396. /*
  2397. * Encode an SETATTR request
  2398. */
  2399. static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
  2400. const void *data)
  2401. {
  2402. const struct nfs_setattrargs *args = data;
  2403. struct compound_hdr hdr = {
  2404. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2405. };
  2406. encode_compound_hdr(xdr, req, &hdr);
  2407. encode_sequence(xdr, &args->seq_args, &hdr);
  2408. encode_putfh(xdr, args->fh, &hdr);
  2409. encode_setattr(xdr, args, args->server, &hdr);
  2410. encode_getfattr(xdr, args->bitmask, &hdr);
  2411. encode_nops(&hdr);
  2412. }
  2413. /*
  2414. * Encode a GETACL request
  2415. */
  2416. static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
  2417. const void *data)
  2418. {
  2419. const struct nfs_getaclargs *args = data;
  2420. struct compound_hdr hdr = {
  2421. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2422. };
  2423. __u32 nfs4_acl_bitmap[2];
  2424. uint32_t replen;
  2425. nfs4_acltype_to_bitmap(args->acl_type, nfs4_acl_bitmap);
  2426. encode_compound_hdr(xdr, req, &hdr);
  2427. encode_sequence(xdr, &args->seq_args, &hdr);
  2428. encode_putfh(xdr, args->fh, &hdr);
  2429. replen = hdr.replen + op_decode_hdr_maxsz;
  2430. encode_getattr(xdr, nfs4_acl_bitmap, NULL,
  2431. ARRAY_SIZE(nfs4_acl_bitmap), &hdr);
  2432. rpc_prepare_reply_pages(req, args->acl_pages, 0,
  2433. args->acl_len, replen);
  2434. encode_nops(&hdr);
  2435. }
  2436. /*
  2437. * Encode a WRITE request
  2438. */
  2439. static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
  2440. const void *data)
  2441. {
  2442. const struct nfs_pgio_args *args = data;
  2443. struct compound_hdr hdr = {
  2444. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2445. };
  2446. encode_compound_hdr(xdr, req, &hdr);
  2447. encode_sequence(xdr, &args->seq_args, &hdr);
  2448. encode_putfh(xdr, args->fh, &hdr);
  2449. encode_write(xdr, args, &hdr);
  2450. req->rq_snd_buf.flags |= XDRBUF_WRITE;
  2451. if (args->bitmask)
  2452. encode_getfattr(xdr, args->bitmask, &hdr);
  2453. encode_nops(&hdr);
  2454. }
  2455. /*
  2456. * a COMMIT request
  2457. */
  2458. static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
  2459. const void *data)
  2460. {
  2461. const struct nfs_commitargs *args = data;
  2462. struct compound_hdr hdr = {
  2463. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2464. };
  2465. encode_compound_hdr(xdr, req, &hdr);
  2466. encode_sequence(xdr, &args->seq_args, &hdr);
  2467. encode_putfh(xdr, args->fh, &hdr);
  2468. encode_commit(xdr, args, &hdr);
  2469. encode_nops(&hdr);
  2470. }
  2471. /*
  2472. * FSINFO request
  2473. */
  2474. static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
  2475. const void *data)
  2476. {
  2477. const struct nfs4_fsinfo_arg *args = data;
  2478. struct compound_hdr hdr = {
  2479. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2480. };
  2481. encode_compound_hdr(xdr, req, &hdr);
  2482. encode_sequence(xdr, &args->seq_args, &hdr);
  2483. encode_putfh(xdr, args->fh, &hdr);
  2484. encode_fsinfo(xdr, args->bitmask, &hdr);
  2485. encode_nops(&hdr);
  2486. }
  2487. /*
  2488. * a PATHCONF request
  2489. */
  2490. static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
  2491. const void *data)
  2492. {
  2493. const struct nfs4_pathconf_arg *args = data;
  2494. struct compound_hdr hdr = {
  2495. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2496. };
  2497. encode_compound_hdr(xdr, req, &hdr);
  2498. encode_sequence(xdr, &args->seq_args, &hdr);
  2499. encode_putfh(xdr, args->fh, &hdr);
  2500. encode_getattr(xdr, nfs4_pathconf_bitmap, args->bitmask,
  2501. ARRAY_SIZE(nfs4_pathconf_bitmap), &hdr);
  2502. encode_nops(&hdr);
  2503. }
  2504. /*
  2505. * a STATFS request
  2506. */
  2507. static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
  2508. const void *data)
  2509. {
  2510. const struct nfs4_statfs_arg *args = data;
  2511. struct compound_hdr hdr = {
  2512. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2513. };
  2514. encode_compound_hdr(xdr, req, &hdr);
  2515. encode_sequence(xdr, &args->seq_args, &hdr);
  2516. encode_putfh(xdr, args->fh, &hdr);
  2517. encode_getattr(xdr, nfs4_statfs_bitmap, args->bitmask,
  2518. ARRAY_SIZE(nfs4_statfs_bitmap), &hdr);
  2519. encode_nops(&hdr);
  2520. }
  2521. /*
  2522. * GETATTR_BITMAP request
  2523. */
  2524. static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
  2525. struct xdr_stream *xdr,
  2526. const void *data)
  2527. {
  2528. const struct nfs4_server_caps_arg *args = data;
  2529. const u32 *bitmask = args->bitmask;
  2530. struct compound_hdr hdr = {
  2531. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2532. };
  2533. encode_compound_hdr(xdr, req, &hdr);
  2534. encode_sequence(xdr, &args->seq_args, &hdr);
  2535. encode_putfh(xdr, args->fhandle, &hdr);
  2536. encode_getattr(xdr, bitmask, NULL, 3, &hdr);
  2537. encode_nops(&hdr);
  2538. }
  2539. /*
  2540. * a RENEW request
  2541. */
  2542. static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
  2543. const void *data)
  2544. {
  2545. const struct nfs_client *clp = data;
  2546. struct compound_hdr hdr = {
  2547. .nops = 0,
  2548. };
  2549. encode_compound_hdr(xdr, req, &hdr);
  2550. encode_renew(xdr, clp->cl_clientid, &hdr);
  2551. encode_nops(&hdr);
  2552. }
  2553. /*
  2554. * a SETCLIENTID request
  2555. */
  2556. static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
  2557. struct xdr_stream *xdr,
  2558. const void *data)
  2559. {
  2560. const struct nfs4_setclientid *sc = data;
  2561. struct compound_hdr hdr = {
  2562. .nops = 0,
  2563. };
  2564. encode_compound_hdr(xdr, req, &hdr);
  2565. encode_setclientid(xdr, sc, &hdr);
  2566. encode_nops(&hdr);
  2567. }
  2568. /*
  2569. * a SETCLIENTID_CONFIRM request
  2570. */
  2571. static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
  2572. struct xdr_stream *xdr,
  2573. const void *data)
  2574. {
  2575. const struct nfs4_setclientid_res *arg = data;
  2576. struct compound_hdr hdr = {
  2577. .nops = 0,
  2578. };
  2579. encode_compound_hdr(xdr, req, &hdr);
  2580. encode_setclientid_confirm(xdr, arg, &hdr);
  2581. encode_nops(&hdr);
  2582. }
  2583. /*
  2584. * DELEGRETURN request
  2585. */
  2586. static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
  2587. struct xdr_stream *xdr,
  2588. const void *data)
  2589. {
  2590. const struct nfs4_delegreturnargs *args = data;
  2591. struct compound_hdr hdr = {
  2592. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2593. };
  2594. encode_compound_hdr(xdr, req, &hdr);
  2595. encode_sequence(xdr, &args->seq_args, &hdr);
  2596. encode_putfh(xdr, args->fhandle, &hdr);
  2597. if (args->lr_args)
  2598. encode_layoutreturn(xdr, args->lr_args, &hdr);
  2599. if (args->sattr_args)
  2600. encode_delegattr(xdr, args->stateid, args->sattr_args, &hdr);
  2601. if (args->bitmask)
  2602. encode_getfattr(xdr, args->bitmask, &hdr);
  2603. encode_delegreturn(xdr, args->stateid, &hdr);
  2604. encode_nops(&hdr);
  2605. }
  2606. /*
  2607. * Encode FS_LOCATIONS request
  2608. */
  2609. static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
  2610. struct xdr_stream *xdr,
  2611. const void *data)
  2612. {
  2613. const struct nfs4_fs_locations_arg *args = data;
  2614. struct compound_hdr hdr = {
  2615. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2616. };
  2617. uint32_t replen;
  2618. encode_compound_hdr(xdr, req, &hdr);
  2619. encode_sequence(xdr, &args->seq_args, &hdr);
  2620. if (args->migration) {
  2621. encode_putfh(xdr, args->fh, &hdr);
  2622. replen = hdr.replen;
  2623. encode_fs_locations(xdr, args->bitmask, &hdr);
  2624. if (args->renew)
  2625. encode_renew(xdr, args->clientid, &hdr);
  2626. } else {
  2627. encode_putfh(xdr, args->dir_fh, &hdr);
  2628. encode_lookup(xdr, args->name, &hdr);
  2629. replen = hdr.replen;
  2630. encode_fs_locations(xdr, args->bitmask, &hdr);
  2631. }
  2632. rpc_prepare_reply_pages(req, (struct page **)&args->page, 0,
  2633. PAGE_SIZE, replen);
  2634. encode_nops(&hdr);
  2635. }
  2636. /*
  2637. * Encode SECINFO request
  2638. */
  2639. static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
  2640. struct xdr_stream *xdr,
  2641. const void *data)
  2642. {
  2643. const struct nfs4_secinfo_arg *args = data;
  2644. struct compound_hdr hdr = {
  2645. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2646. };
  2647. encode_compound_hdr(xdr, req, &hdr);
  2648. encode_sequence(xdr, &args->seq_args, &hdr);
  2649. encode_putfh(xdr, args->dir_fh, &hdr);
  2650. encode_secinfo(xdr, args->name, &hdr);
  2651. encode_nops(&hdr);
  2652. }
  2653. /*
  2654. * Encode FSID_PRESENT request
  2655. */
  2656. static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
  2657. struct xdr_stream *xdr,
  2658. const void *data)
  2659. {
  2660. const struct nfs4_fsid_present_arg *args = data;
  2661. struct compound_hdr hdr = {
  2662. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2663. };
  2664. encode_compound_hdr(xdr, req, &hdr);
  2665. encode_sequence(xdr, &args->seq_args, &hdr);
  2666. encode_putfh(xdr, args->fh, &hdr);
  2667. encode_getfh(xdr, &hdr);
  2668. if (args->renew)
  2669. encode_renew(xdr, args->clientid, &hdr);
  2670. encode_nops(&hdr);
  2671. }
  2672. #if defined(CONFIG_NFS_V4_1)
  2673. /*
  2674. * BIND_CONN_TO_SESSION request
  2675. */
  2676. static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
  2677. struct xdr_stream *xdr,
  2678. const void *data)
  2679. {
  2680. const struct nfs41_bind_conn_to_session_args *args = data;
  2681. struct compound_hdr hdr = {
  2682. .minorversion = args->client->cl_mvops->minor_version,
  2683. };
  2684. encode_compound_hdr(xdr, req, &hdr);
  2685. encode_bind_conn_to_session(xdr, args, &hdr);
  2686. encode_nops(&hdr);
  2687. }
  2688. /*
  2689. * EXCHANGE_ID request
  2690. */
  2691. static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
  2692. struct xdr_stream *xdr,
  2693. const void *data)
  2694. {
  2695. const struct nfs41_exchange_id_args *args = data;
  2696. struct compound_hdr hdr = {
  2697. .minorversion = args->client->cl_mvops->minor_version,
  2698. };
  2699. encode_compound_hdr(xdr, req, &hdr);
  2700. encode_exchange_id(xdr, args, &hdr);
  2701. encode_nops(&hdr);
  2702. }
  2703. /*
  2704. * a CREATE_SESSION request
  2705. */
  2706. static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
  2707. struct xdr_stream *xdr,
  2708. const void *data)
  2709. {
  2710. const struct nfs41_create_session_args *args = data;
  2711. struct compound_hdr hdr = {
  2712. .minorversion = args->client->cl_mvops->minor_version,
  2713. };
  2714. encode_compound_hdr(xdr, req, &hdr);
  2715. encode_create_session(xdr, args, &hdr);
  2716. encode_nops(&hdr);
  2717. }
  2718. /*
  2719. * a DESTROY_SESSION request
  2720. */
  2721. static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
  2722. struct xdr_stream *xdr,
  2723. const void *data)
  2724. {
  2725. const struct nfs4_session *session = data;
  2726. struct compound_hdr hdr = {
  2727. .minorversion = session->clp->cl_mvops->minor_version,
  2728. };
  2729. encode_compound_hdr(xdr, req, &hdr);
  2730. encode_destroy_session(xdr, session, &hdr);
  2731. encode_nops(&hdr);
  2732. }
  2733. /*
  2734. * a DESTROY_CLIENTID request
  2735. */
  2736. static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
  2737. struct xdr_stream *xdr,
  2738. const void *data)
  2739. {
  2740. const struct nfs_client *clp = data;
  2741. struct compound_hdr hdr = {
  2742. .minorversion = clp->cl_mvops->minor_version,
  2743. };
  2744. encode_compound_hdr(xdr, req, &hdr);
  2745. encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
  2746. encode_nops(&hdr);
  2747. }
  2748. /*
  2749. * a SEQUENCE request
  2750. */
  2751. static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
  2752. const void *data)
  2753. {
  2754. const struct nfs4_sequence_args *args = data;
  2755. struct compound_hdr hdr = {
  2756. .minorversion = nfs4_xdr_minorversion(args),
  2757. };
  2758. encode_compound_hdr(xdr, req, &hdr);
  2759. encode_sequence(xdr, args, &hdr);
  2760. encode_nops(&hdr);
  2761. }
  2762. #endif
  2763. /*
  2764. * a GET_LEASE_TIME request
  2765. */
  2766. static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
  2767. struct xdr_stream *xdr,
  2768. const void *data)
  2769. {
  2770. const struct nfs4_get_lease_time_args *args = data;
  2771. struct compound_hdr hdr = {
  2772. .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
  2773. };
  2774. const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
  2775. encode_compound_hdr(xdr, req, &hdr);
  2776. encode_sequence(xdr, &args->la_seq_args, &hdr);
  2777. encode_putrootfh(xdr, &hdr);
  2778. encode_fsinfo(xdr, lease_bitmap, &hdr);
  2779. encode_nops(&hdr);
  2780. }
  2781. #ifdef CONFIG_NFS_V4_1
  2782. /*
  2783. * a RECLAIM_COMPLETE request
  2784. */
  2785. static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
  2786. struct xdr_stream *xdr,
  2787. const void *data)
  2788. {
  2789. const struct nfs41_reclaim_complete_args *args = data;
  2790. struct compound_hdr hdr = {
  2791. .minorversion = nfs4_xdr_minorversion(&args->seq_args)
  2792. };
  2793. encode_compound_hdr(xdr, req, &hdr);
  2794. encode_sequence(xdr, &args->seq_args, &hdr);
  2795. encode_reclaim_complete(xdr, args, &hdr);
  2796. encode_nops(&hdr);
  2797. }
  2798. /*
  2799. * Encode GETDEVICEINFO request
  2800. */
  2801. static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
  2802. struct xdr_stream *xdr,
  2803. const void *data)
  2804. {
  2805. const struct nfs4_getdeviceinfo_args *args = data;
  2806. struct compound_hdr hdr = {
  2807. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2808. };
  2809. uint32_t replen;
  2810. encode_compound_hdr(xdr, req, &hdr);
  2811. encode_sequence(xdr, &args->seq_args, &hdr);
  2812. replen = hdr.replen + op_decode_hdr_maxsz + 2;
  2813. encode_getdeviceinfo(xdr, args, &hdr);
  2814. /* set up reply kvec. device_addr4 opaque data is read into the
  2815. * pages */
  2816. rpc_prepare_reply_pages(req, args->pdev->pages, args->pdev->pgbase,
  2817. args->pdev->pglen, replen);
  2818. encode_nops(&hdr);
  2819. }
  2820. /*
  2821. * Encode LAYOUTGET request
  2822. */
  2823. static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
  2824. struct xdr_stream *xdr,
  2825. const void *data)
  2826. {
  2827. const struct nfs4_layoutget_args *args = data;
  2828. struct compound_hdr hdr = {
  2829. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2830. };
  2831. encode_compound_hdr(xdr, req, &hdr);
  2832. encode_sequence(xdr, &args->seq_args, &hdr);
  2833. encode_putfh(xdr, NFS_FH(args->inode), &hdr);
  2834. encode_layoutget(xdr, args, &hdr);
  2835. rpc_prepare_reply_pages(req, args->layout.pages, 0,
  2836. args->layout.pglen, hdr.replen - pagepad_maxsz);
  2837. encode_nops(&hdr);
  2838. }
  2839. /*
  2840. * Encode LAYOUTCOMMIT request
  2841. */
  2842. static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
  2843. struct xdr_stream *xdr,
  2844. const void *priv)
  2845. {
  2846. const struct nfs4_layoutcommit_args *args = priv;
  2847. struct nfs4_layoutcommit_data *data =
  2848. container_of(args, struct nfs4_layoutcommit_data, args);
  2849. struct compound_hdr hdr = {
  2850. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2851. };
  2852. encode_compound_hdr(xdr, req, &hdr);
  2853. encode_sequence(xdr, &args->seq_args, &hdr);
  2854. encode_putfh(xdr, NFS_FH(args->inode), &hdr);
  2855. encode_layoutcommit(xdr, data->args.inode, args, &hdr);
  2856. encode_getfattr(xdr, args->bitmask, &hdr);
  2857. encode_nops(&hdr);
  2858. }
  2859. /*
  2860. * Encode LAYOUTRETURN request
  2861. */
  2862. static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
  2863. struct xdr_stream *xdr,
  2864. const void *data)
  2865. {
  2866. const struct nfs4_layoutreturn_args *args = data;
  2867. struct compound_hdr hdr = {
  2868. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2869. };
  2870. encode_compound_hdr(xdr, req, &hdr);
  2871. encode_sequence(xdr, &args->seq_args, &hdr);
  2872. encode_putfh(xdr, NFS_FH(args->inode), &hdr);
  2873. encode_layoutreturn(xdr, args, &hdr);
  2874. encode_nops(&hdr);
  2875. }
  2876. /*
  2877. * Encode SECINFO_NO_NAME request
  2878. */
  2879. static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
  2880. struct xdr_stream *xdr,
  2881. const void *data)
  2882. {
  2883. const struct nfs41_secinfo_no_name_args *args = data;
  2884. struct compound_hdr hdr = {
  2885. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2886. };
  2887. encode_compound_hdr(xdr, req, &hdr);
  2888. encode_sequence(xdr, &args->seq_args, &hdr);
  2889. encode_putrootfh(xdr, &hdr);
  2890. encode_secinfo_no_name(xdr, args, &hdr);
  2891. encode_nops(&hdr);
  2892. }
  2893. /*
  2894. * Encode TEST_STATEID request
  2895. */
  2896. static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
  2897. struct xdr_stream *xdr,
  2898. const void *data)
  2899. {
  2900. const struct nfs41_test_stateid_args *args = data;
  2901. struct compound_hdr hdr = {
  2902. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2903. };
  2904. encode_compound_hdr(xdr, req, &hdr);
  2905. encode_sequence(xdr, &args->seq_args, &hdr);
  2906. encode_test_stateid(xdr, args, &hdr);
  2907. encode_nops(&hdr);
  2908. }
  2909. /*
  2910. * Encode FREE_STATEID request
  2911. */
  2912. static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
  2913. struct xdr_stream *xdr,
  2914. const void *data)
  2915. {
  2916. const struct nfs41_free_stateid_args *args = data;
  2917. struct compound_hdr hdr = {
  2918. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2919. };
  2920. encode_compound_hdr(xdr, req, &hdr);
  2921. encode_sequence(xdr, &args->seq_args, &hdr);
  2922. encode_free_stateid(xdr, args, &hdr);
  2923. encode_nops(&hdr);
  2924. }
  2925. #endif /* CONFIG_NFS_V4_1 */
  2926. static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
  2927. {
  2928. ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string,
  2929. NFS4_OPAQUE_LIMIT);
  2930. if (unlikely(ret < 0))
  2931. return -EIO;
  2932. *len = ret;
  2933. return 0;
  2934. }
  2935. static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
  2936. {
  2937. ssize_t ret;
  2938. void *ptr;
  2939. u32 tmp;
  2940. if (xdr_stream_decode_u32(xdr, &tmp) < 0)
  2941. return -EIO;
  2942. hdr->status = tmp;
  2943. ret = xdr_stream_decode_opaque_inline(xdr, &ptr, NFS4_OPAQUE_LIMIT);
  2944. if (ret < 0)
  2945. return -EIO;
  2946. hdr->taglen = ret;
  2947. hdr->tag = ptr;
  2948. if (xdr_stream_decode_u32(xdr, &tmp) < 0)
  2949. return -EIO;
  2950. hdr->nops = tmp;
  2951. if (unlikely(hdr->nops < 1))
  2952. return nfs4_stat_to_errno(hdr->status);
  2953. return 0;
  2954. }
  2955. static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
  2956. int *nfs_retval)
  2957. {
  2958. __be32 *p;
  2959. uint32_t opnum;
  2960. int32_t nfserr;
  2961. p = xdr_inline_decode(xdr, 8);
  2962. if (unlikely(!p))
  2963. goto out_overflow;
  2964. opnum = be32_to_cpup(p++);
  2965. if (unlikely(opnum != expected))
  2966. goto out_bad_operation;
  2967. if (unlikely(*p != cpu_to_be32(NFS_OK)))
  2968. goto out_status;
  2969. *nfs_retval = 0;
  2970. return true;
  2971. out_status:
  2972. nfserr = be32_to_cpup(p);
  2973. trace_nfs4_xdr_status(xdr, opnum, nfserr);
  2974. *nfs_retval = nfs4_stat_to_errno(nfserr);
  2975. return true;
  2976. out_bad_operation:
  2977. trace_nfs4_xdr_bad_operation(xdr, opnum, expected);
  2978. *nfs_retval = -EREMOTEIO;
  2979. return false;
  2980. out_overflow:
  2981. *nfs_retval = -EIO;
  2982. return false;
  2983. }
  2984. static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
  2985. {
  2986. int retval;
  2987. __decode_op_hdr(xdr, expected, &retval);
  2988. return retval;
  2989. }
  2990. /* Dummy routine */
  2991. static int decode_ace(struct xdr_stream *xdr, void *ace)
  2992. {
  2993. __be32 *p;
  2994. unsigned int strlen;
  2995. char *str;
  2996. p = xdr_inline_decode(xdr, 12);
  2997. if (unlikely(!p))
  2998. return -EIO;
  2999. return decode_opaque_inline(xdr, &strlen, &str);
  3000. }
  3001. static ssize_t
  3002. decode_bitmap4(struct xdr_stream *xdr, uint32_t *bitmap, size_t sz)
  3003. {
  3004. ssize_t ret;
  3005. ret = xdr_stream_decode_uint32_array(xdr, bitmap, sz);
  3006. if (likely(ret >= 0))
  3007. return ret;
  3008. if (ret != -EMSGSIZE)
  3009. return -EIO;
  3010. return sz;
  3011. }
  3012. static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
  3013. {
  3014. ssize_t ret;
  3015. ret = decode_bitmap4(xdr, bitmap, 3);
  3016. return ret < 0 ? ret : 0;
  3017. }
  3018. static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
  3019. {
  3020. __be32 *p;
  3021. p = xdr_inline_decode(xdr, 4);
  3022. if (unlikely(!p))
  3023. return -EIO;
  3024. *attrlen = be32_to_cpup(p);
  3025. *savep = xdr_stream_pos(xdr);
  3026. return 0;
  3027. }
  3028. static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
  3029. {
  3030. if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
  3031. int ret;
  3032. ret = decode_attr_bitmap(xdr, bitmask);
  3033. if (unlikely(ret < 0))
  3034. return ret;
  3035. bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
  3036. } else
  3037. bitmask[0] = bitmask[1] = bitmask[2] = 0;
  3038. dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
  3039. bitmask[0], bitmask[1], bitmask[2]);
  3040. return 0;
  3041. }
  3042. static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
  3043. {
  3044. __be32 *p;
  3045. int ret = 0;
  3046. *type = 0;
  3047. if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
  3048. return -EIO;
  3049. if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
  3050. p = xdr_inline_decode(xdr, 4);
  3051. if (unlikely(!p))
  3052. return -EIO;
  3053. *type = be32_to_cpup(p);
  3054. if (*type < NF4REG || *type > NF4NAMEDATTR) {
  3055. dprintk("%s: bad type %d\n", __func__, *type);
  3056. return -EIO;
  3057. }
  3058. bitmap[0] &= ~FATTR4_WORD0_TYPE;
  3059. ret = NFS_ATTR_FATTR_TYPE;
  3060. }
  3061. dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
  3062. return ret;
  3063. }
  3064. static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
  3065. uint32_t *bitmap, uint32_t *type)
  3066. {
  3067. __be32 *p;
  3068. *type = 0;
  3069. if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
  3070. return -EIO;
  3071. if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
  3072. p = xdr_inline_decode(xdr, 4);
  3073. if (unlikely(!p))
  3074. return -EIO;
  3075. *type = be32_to_cpup(p);
  3076. bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
  3077. }
  3078. dprintk("%s: expire type=0x%x\n", __func__, *type);
  3079. return 0;
  3080. }
  3081. static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
  3082. {
  3083. __be32 *p;
  3084. int ret = 0;
  3085. *change = 0;
  3086. if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
  3087. return -EIO;
  3088. if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
  3089. p = xdr_inline_decode(xdr, 8);
  3090. if (unlikely(!p))
  3091. return -EIO;
  3092. xdr_decode_hyper(p, change);
  3093. bitmap[0] &= ~FATTR4_WORD0_CHANGE;
  3094. ret = NFS_ATTR_FATTR_CHANGE;
  3095. }
  3096. dprintk("%s: change attribute=%Lu\n", __func__,
  3097. (unsigned long long)*change);
  3098. return ret;
  3099. }
  3100. static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
  3101. {
  3102. __be32 *p;
  3103. int ret = 0;
  3104. *size = 0;
  3105. if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
  3106. return -EIO;
  3107. if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
  3108. p = xdr_inline_decode(xdr, 8);
  3109. if (unlikely(!p))
  3110. return -EIO;
  3111. xdr_decode_hyper(p, size);
  3112. bitmap[0] &= ~FATTR4_WORD0_SIZE;
  3113. ret = NFS_ATTR_FATTR_SIZE;
  3114. }
  3115. dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
  3116. return ret;
  3117. }
  3118. static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3119. {
  3120. __be32 *p;
  3121. *res = 0;
  3122. if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
  3123. return -EIO;
  3124. if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
  3125. p = xdr_inline_decode(xdr, 4);
  3126. if (unlikely(!p))
  3127. return -EIO;
  3128. *res = be32_to_cpup(p);
  3129. bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
  3130. }
  3131. dprintk("%s: link support=%s\n", __func__, str_false_true(*res == 0));
  3132. return 0;
  3133. }
  3134. static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3135. {
  3136. __be32 *p;
  3137. *res = 0;
  3138. if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
  3139. return -EIO;
  3140. if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
  3141. p = xdr_inline_decode(xdr, 4);
  3142. if (unlikely(!p))
  3143. return -EIO;
  3144. *res = be32_to_cpup(p);
  3145. bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
  3146. }
  3147. dprintk("%s: symlink support=%s\n", __func__, str_false_true(*res == 0));
  3148. return 0;
  3149. }
  3150. static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
  3151. {
  3152. __be32 *p;
  3153. int ret = 0;
  3154. fsid->major = 0;
  3155. fsid->minor = 0;
  3156. if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
  3157. return -EIO;
  3158. if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
  3159. p = xdr_inline_decode(xdr, 16);
  3160. if (unlikely(!p))
  3161. return -EIO;
  3162. p = xdr_decode_hyper(p, &fsid->major);
  3163. xdr_decode_hyper(p, &fsid->minor);
  3164. bitmap[0] &= ~FATTR4_WORD0_FSID;
  3165. ret = NFS_ATTR_FATTR_FSID;
  3166. }
  3167. dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
  3168. (unsigned long long)fsid->major,
  3169. (unsigned long long)fsid->minor);
  3170. return ret;
  3171. }
  3172. static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3173. {
  3174. __be32 *p;
  3175. *res = 60;
  3176. if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
  3177. return -EIO;
  3178. if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
  3179. p = xdr_inline_decode(xdr, 4);
  3180. if (unlikely(!p))
  3181. return -EIO;
  3182. *res = be32_to_cpup(p);
  3183. bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
  3184. }
  3185. dprintk("%s: lease time=%u\n", __func__, (unsigned int)*res);
  3186. return 0;
  3187. }
  3188. static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
  3189. {
  3190. __be32 *p;
  3191. if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
  3192. return -EIO;
  3193. if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
  3194. p = xdr_inline_decode(xdr, 4);
  3195. if (unlikely(!p))
  3196. return -EIO;
  3197. bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
  3198. *res = -be32_to_cpup(p);
  3199. }
  3200. return 0;
  3201. }
  3202. static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
  3203. uint32_t *bitmap, uint32_t *bitmask)
  3204. {
  3205. if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
  3206. int ret;
  3207. ret = decode_attr_bitmap(xdr, bitmask);
  3208. if (unlikely(ret < 0))
  3209. return ret;
  3210. bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
  3211. } else
  3212. bitmask[0] = bitmask[1] = bitmask[2] = 0;
  3213. dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
  3214. bitmask[0], bitmask[1], bitmask[2]);
  3215. return 0;
  3216. }
  3217. static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
  3218. {
  3219. __be32 *p;
  3220. u32 len;
  3221. if (fh != NULL)
  3222. memset(fh, 0, sizeof(*fh));
  3223. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
  3224. return -EIO;
  3225. if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
  3226. p = xdr_inline_decode(xdr, 4);
  3227. if (unlikely(!p))
  3228. return -EIO;
  3229. len = be32_to_cpup(p);
  3230. if (len > NFS4_FHSIZE || len == 0) {
  3231. trace_nfs4_xdr_bad_filehandle(xdr, OP_READDIR,
  3232. NFS4ERR_BADHANDLE);
  3233. return -EREMOTEIO;
  3234. }
  3235. p = xdr_inline_decode(xdr, len);
  3236. if (unlikely(!p))
  3237. return -EIO;
  3238. if (fh != NULL) {
  3239. memcpy(fh->data, p, len);
  3240. fh->size = len;
  3241. }
  3242. bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
  3243. }
  3244. return 0;
  3245. }
  3246. static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3247. {
  3248. __be32 *p;
  3249. *res = 0;
  3250. if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
  3251. return -EIO;
  3252. if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
  3253. p = xdr_inline_decode(xdr, 4);
  3254. if (unlikely(!p))
  3255. return -EIO;
  3256. *res = be32_to_cpup(p);
  3257. bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
  3258. }
  3259. dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
  3260. return 0;
  3261. }
  3262. static int decode_attr_case_insensitive(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3263. {
  3264. __be32 *p;
  3265. *res = 0;
  3266. if (unlikely(bitmap[0] & (FATTR4_WORD0_CASE_INSENSITIVE - 1U)))
  3267. return -EIO;
  3268. if (likely(bitmap[0] & FATTR4_WORD0_CASE_INSENSITIVE)) {
  3269. p = xdr_inline_decode(xdr, 4);
  3270. if (unlikely(!p))
  3271. return -EIO;
  3272. *res = be32_to_cpup(p);
  3273. bitmap[0] &= ~FATTR4_WORD0_CASE_INSENSITIVE;
  3274. }
  3275. dprintk("%s: case_insensitive=%s\n", __func__, str_false_true(*res == 0));
  3276. return 0;
  3277. }
  3278. static int decode_attr_case_preserving(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3279. {
  3280. __be32 *p;
  3281. *res = 0;
  3282. if (unlikely(bitmap[0] & (FATTR4_WORD0_CASE_PRESERVING - 1U)))
  3283. return -EIO;
  3284. if (likely(bitmap[0] & FATTR4_WORD0_CASE_PRESERVING)) {
  3285. p = xdr_inline_decode(xdr, 4);
  3286. if (unlikely(!p))
  3287. return -EIO;
  3288. *res = be32_to_cpup(p);
  3289. bitmap[0] &= ~FATTR4_WORD0_CASE_PRESERVING;
  3290. }
  3291. dprintk("%s: case_preserving=%s\n", __func__, str_false_true(*res == 0));
  3292. return 0;
  3293. }
  3294. static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
  3295. {
  3296. __be32 *p;
  3297. int ret = 0;
  3298. *fileid = 0;
  3299. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
  3300. return -EIO;
  3301. if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
  3302. p = xdr_inline_decode(xdr, 8);
  3303. if (unlikely(!p))
  3304. return -EIO;
  3305. xdr_decode_hyper(p, fileid);
  3306. bitmap[0] &= ~FATTR4_WORD0_FILEID;
  3307. ret = NFS_ATTR_FATTR_FILEID;
  3308. }
  3309. dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
  3310. return ret;
  3311. }
  3312. static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
  3313. {
  3314. __be32 *p;
  3315. int ret = 0;
  3316. *fileid = 0;
  3317. if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
  3318. return -EIO;
  3319. if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
  3320. p = xdr_inline_decode(xdr, 8);
  3321. if (unlikely(!p))
  3322. return -EIO;
  3323. xdr_decode_hyper(p, fileid);
  3324. bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
  3325. ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
  3326. }
  3327. dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
  3328. return ret;
  3329. }
  3330. static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3331. {
  3332. __be32 *p;
  3333. int status = 0;
  3334. *res = 0;
  3335. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
  3336. return -EIO;
  3337. if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
  3338. p = xdr_inline_decode(xdr, 8);
  3339. if (unlikely(!p))
  3340. return -EIO;
  3341. xdr_decode_hyper(p, res);
  3342. bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
  3343. }
  3344. dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
  3345. return status;
  3346. }
  3347. static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3348. {
  3349. __be32 *p;
  3350. int status = 0;
  3351. *res = 0;
  3352. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
  3353. return -EIO;
  3354. if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
  3355. p = xdr_inline_decode(xdr, 8);
  3356. if (unlikely(!p))
  3357. return -EIO;
  3358. xdr_decode_hyper(p, res);
  3359. bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
  3360. }
  3361. dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
  3362. return status;
  3363. }
  3364. static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3365. {
  3366. __be32 *p;
  3367. int status = 0;
  3368. *res = 0;
  3369. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
  3370. return -EIO;
  3371. if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
  3372. p = xdr_inline_decode(xdr, 8);
  3373. if (unlikely(!p))
  3374. return -EIO;
  3375. xdr_decode_hyper(p, res);
  3376. bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
  3377. }
  3378. dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
  3379. return status;
  3380. }
  3381. static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
  3382. {
  3383. u32 n;
  3384. __be32 *p;
  3385. int status = 0;
  3386. p = xdr_inline_decode(xdr, 4);
  3387. if (unlikely(!p))
  3388. return -EIO;
  3389. n = be32_to_cpup(p);
  3390. if (n == 0)
  3391. goto root_path;
  3392. dprintk("pathname4: ");
  3393. if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
  3394. dprintk("cannot parse %d components in path\n", n);
  3395. goto out_eio;
  3396. }
  3397. for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
  3398. struct nfs4_string *component = &path->components[path->ncomponents];
  3399. status = decode_opaque_inline(xdr, &component->len, &component->data);
  3400. if (unlikely(status != 0))
  3401. goto out_eio;
  3402. ifdebug (XDR)
  3403. pr_cont("%s%.*s ",
  3404. (path->ncomponents != n ? "/ " : ""),
  3405. component->len, component->data);
  3406. }
  3407. out:
  3408. return status;
  3409. root_path:
  3410. /* a root pathname is sent as a zero component4 */
  3411. path->ncomponents = 1;
  3412. path->components[0].len=0;
  3413. path->components[0].data=NULL;
  3414. dprintk("pathname4: /\n");
  3415. goto out;
  3416. out_eio:
  3417. dprintk(" status %d", status);
  3418. status = -EIO;
  3419. goto out;
  3420. }
  3421. static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
  3422. {
  3423. int n;
  3424. __be32 *p;
  3425. int status = -EIO;
  3426. if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
  3427. goto out;
  3428. status = 0;
  3429. if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
  3430. goto out;
  3431. bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
  3432. status = -EIO;
  3433. /* Ignore borken servers that return unrequested attrs */
  3434. if (unlikely(res == NULL))
  3435. goto out;
  3436. dprintk("%s: fsroot:\n", __func__);
  3437. status = decode_pathname(xdr, &res->fs_path);
  3438. if (unlikely(status != 0))
  3439. goto out;
  3440. p = xdr_inline_decode(xdr, 4);
  3441. if (unlikely(!p))
  3442. goto out_eio;
  3443. n = be32_to_cpup(p);
  3444. for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
  3445. u32 m;
  3446. struct nfs4_fs_location *loc;
  3447. if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
  3448. break;
  3449. loc = &res->locations[res->nlocations];
  3450. p = xdr_inline_decode(xdr, 4);
  3451. if (unlikely(!p))
  3452. goto out_eio;
  3453. m = be32_to_cpup(p);
  3454. dprintk("%s: servers:\n", __func__);
  3455. for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
  3456. struct nfs4_string *server;
  3457. if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
  3458. unsigned int i;
  3459. dprintk("%s: using first %u of %u servers "
  3460. "returned for location %u\n",
  3461. __func__,
  3462. NFS4_FS_LOCATION_MAXSERVERS,
  3463. m, res->nlocations);
  3464. for (i = loc->nservers; i < m; i++) {
  3465. unsigned int len;
  3466. char *data;
  3467. status = decode_opaque_inline(xdr, &len, &data);
  3468. if (unlikely(status != 0))
  3469. goto out_eio;
  3470. }
  3471. break;
  3472. }
  3473. server = &loc->servers[loc->nservers];
  3474. status = decode_opaque_inline(xdr, &server->len, &server->data);
  3475. if (unlikely(status != 0))
  3476. goto out_eio;
  3477. dprintk("%s ", server->data);
  3478. }
  3479. status = decode_pathname(xdr, &loc->rootpath);
  3480. if (unlikely(status != 0))
  3481. goto out_eio;
  3482. }
  3483. if (res->nlocations != 0)
  3484. status = NFS_ATTR_FATTR_V4_LOCATIONS;
  3485. out:
  3486. dprintk("%s: fs_locations done, error = %d\n", __func__, status);
  3487. return status;
  3488. out_eio:
  3489. status = -EIO;
  3490. goto out;
  3491. }
  3492. static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3493. {
  3494. __be32 *p;
  3495. int status = 0;
  3496. *res = 0;
  3497. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
  3498. return -EIO;
  3499. if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
  3500. p = xdr_inline_decode(xdr, 8);
  3501. if (unlikely(!p))
  3502. return -EIO;
  3503. xdr_decode_hyper(p, res);
  3504. bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
  3505. }
  3506. dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
  3507. return status;
  3508. }
  3509. static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
  3510. {
  3511. __be32 *p;
  3512. int status = 0;
  3513. *maxlink = 1;
  3514. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
  3515. return -EIO;
  3516. if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
  3517. p = xdr_inline_decode(xdr, 4);
  3518. if (unlikely(!p))
  3519. return -EIO;
  3520. *maxlink = be32_to_cpup(p);
  3521. bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
  3522. }
  3523. dprintk("%s: maxlink=%u\n", __func__, *maxlink);
  3524. return status;
  3525. }
  3526. static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
  3527. {
  3528. __be32 *p;
  3529. int status = 0;
  3530. *maxname = 1024;
  3531. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
  3532. return -EIO;
  3533. if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
  3534. p = xdr_inline_decode(xdr, 4);
  3535. if (unlikely(!p))
  3536. return -EIO;
  3537. *maxname = be32_to_cpup(p);
  3538. bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
  3539. }
  3540. dprintk("%s: maxname=%u\n", __func__, *maxname);
  3541. return status;
  3542. }
  3543. static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3544. {
  3545. __be32 *p;
  3546. int status = 0;
  3547. *res = 1024;
  3548. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
  3549. return -EIO;
  3550. if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
  3551. uint64_t maxread;
  3552. p = xdr_inline_decode(xdr, 8);
  3553. if (unlikely(!p))
  3554. return -EIO;
  3555. xdr_decode_hyper(p, &maxread);
  3556. if (maxread > 0x7FFFFFFF)
  3557. maxread = 0x7FFFFFFF;
  3558. *res = (uint32_t)maxread;
  3559. bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
  3560. }
  3561. dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
  3562. return status;
  3563. }
  3564. static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3565. {
  3566. __be32 *p;
  3567. int status = 0;
  3568. *res = 1024;
  3569. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
  3570. return -EIO;
  3571. if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
  3572. uint64_t maxwrite;
  3573. p = xdr_inline_decode(xdr, 8);
  3574. if (unlikely(!p))
  3575. return -EIO;
  3576. xdr_decode_hyper(p, &maxwrite);
  3577. if (maxwrite > 0x7FFFFFFF)
  3578. maxwrite = 0x7FFFFFFF;
  3579. *res = (uint32_t)maxwrite;
  3580. bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
  3581. }
  3582. dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
  3583. return status;
  3584. }
  3585. static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
  3586. {
  3587. uint32_t tmp;
  3588. __be32 *p;
  3589. int ret = 0;
  3590. *mode = 0;
  3591. if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
  3592. return -EIO;
  3593. if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
  3594. p = xdr_inline_decode(xdr, 4);
  3595. if (unlikely(!p))
  3596. return -EIO;
  3597. tmp = be32_to_cpup(p);
  3598. *mode = tmp & ~S_IFMT;
  3599. bitmap[1] &= ~FATTR4_WORD1_MODE;
  3600. ret = NFS_ATTR_FATTR_MODE;
  3601. }
  3602. dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
  3603. return ret;
  3604. }
  3605. static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
  3606. {
  3607. __be32 *p;
  3608. int ret = 0;
  3609. *nlink = 1;
  3610. if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
  3611. return -EIO;
  3612. if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
  3613. p = xdr_inline_decode(xdr, 4);
  3614. if (unlikely(!p))
  3615. return -EIO;
  3616. *nlink = be32_to_cpup(p);
  3617. bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
  3618. ret = NFS_ATTR_FATTR_NLINK;
  3619. }
  3620. dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
  3621. return ret;
  3622. }
  3623. static ssize_t decode_nfs4_string(struct xdr_stream *xdr,
  3624. struct nfs4_string *name, gfp_t gfp_flags)
  3625. {
  3626. ssize_t ret;
  3627. ret = xdr_stream_decode_string_dup(xdr, &name->data,
  3628. XDR_MAX_NETOBJ, gfp_flags);
  3629. name->len = 0;
  3630. if (ret > 0)
  3631. name->len = ret;
  3632. return ret;
  3633. }
  3634. static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
  3635. const struct nfs_server *server, kuid_t *uid,
  3636. struct nfs4_string *owner_name)
  3637. {
  3638. ssize_t len;
  3639. char *p;
  3640. *uid = make_kuid(&init_user_ns, -2);
  3641. if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
  3642. return -EIO;
  3643. if (!(bitmap[1] & FATTR4_WORD1_OWNER))
  3644. return 0;
  3645. bitmap[1] &= ~FATTR4_WORD1_OWNER;
  3646. if (owner_name != NULL) {
  3647. len = decode_nfs4_string(xdr, owner_name, GFP_NOIO);
  3648. if (len <= 0)
  3649. goto out;
  3650. dprintk("%s: name=%s\n", __func__, owner_name->data);
  3651. return NFS_ATTR_FATTR_OWNER_NAME;
  3652. } else {
  3653. len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
  3654. XDR_MAX_NETOBJ);
  3655. if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0)
  3656. goto out;
  3657. dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
  3658. return NFS_ATTR_FATTR_OWNER;
  3659. }
  3660. out:
  3661. if (len == -EBADMSG)
  3662. return -EIO;
  3663. return 0;
  3664. }
  3665. static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
  3666. const struct nfs_server *server, kgid_t *gid,
  3667. struct nfs4_string *group_name)
  3668. {
  3669. ssize_t len;
  3670. char *p;
  3671. *gid = make_kgid(&init_user_ns, -2);
  3672. if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
  3673. return -EIO;
  3674. if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP))
  3675. return 0;
  3676. bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
  3677. if (group_name != NULL) {
  3678. len = decode_nfs4_string(xdr, group_name, GFP_NOIO);
  3679. if (len <= 0)
  3680. goto out;
  3681. dprintk("%s: name=%s\n", __func__, group_name->data);
  3682. return NFS_ATTR_FATTR_GROUP_NAME;
  3683. } else {
  3684. len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
  3685. XDR_MAX_NETOBJ);
  3686. if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0)
  3687. goto out;
  3688. dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
  3689. return NFS_ATTR_FATTR_GROUP;
  3690. }
  3691. out:
  3692. if (len == -EBADMSG)
  3693. return -EIO;
  3694. return 0;
  3695. }
  3696. static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
  3697. {
  3698. uint32_t major = 0, minor = 0;
  3699. __be32 *p;
  3700. int ret = 0;
  3701. *rdev = MKDEV(0,0);
  3702. if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
  3703. return -EIO;
  3704. if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
  3705. dev_t tmp;
  3706. p = xdr_inline_decode(xdr, 8);
  3707. if (unlikely(!p))
  3708. return -EIO;
  3709. major = be32_to_cpup(p++);
  3710. minor = be32_to_cpup(p);
  3711. tmp = MKDEV(major, minor);
  3712. if (MAJOR(tmp) == major && MINOR(tmp) == minor)
  3713. *rdev = tmp;
  3714. bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
  3715. ret = NFS_ATTR_FATTR_RDEV;
  3716. }
  3717. dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
  3718. return ret;
  3719. }
  3720. static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3721. {
  3722. __be32 *p;
  3723. int status = 0;
  3724. *res = 0;
  3725. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
  3726. return -EIO;
  3727. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
  3728. p = xdr_inline_decode(xdr, 8);
  3729. if (unlikely(!p))
  3730. return -EIO;
  3731. xdr_decode_hyper(p, res);
  3732. bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
  3733. }
  3734. dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
  3735. return status;
  3736. }
  3737. static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3738. {
  3739. __be32 *p;
  3740. int status = 0;
  3741. *res = 0;
  3742. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
  3743. return -EIO;
  3744. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
  3745. p = xdr_inline_decode(xdr, 8);
  3746. if (unlikely(!p))
  3747. return -EIO;
  3748. xdr_decode_hyper(p, res);
  3749. bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
  3750. }
  3751. dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
  3752. return status;
  3753. }
  3754. static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3755. {
  3756. __be32 *p;
  3757. int status = 0;
  3758. *res = 0;
  3759. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
  3760. return -EIO;
  3761. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
  3762. p = xdr_inline_decode(xdr, 8);
  3763. if (unlikely(!p))
  3764. return -EIO;
  3765. xdr_decode_hyper(p, res);
  3766. bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
  3767. }
  3768. dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
  3769. return status;
  3770. }
  3771. static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
  3772. {
  3773. __be32 *p;
  3774. int ret = 0;
  3775. *used = 0;
  3776. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
  3777. return -EIO;
  3778. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
  3779. p = xdr_inline_decode(xdr, 8);
  3780. if (unlikely(!p))
  3781. return -EIO;
  3782. xdr_decode_hyper(p, used);
  3783. bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
  3784. ret = NFS_ATTR_FATTR_SPACE_USED;
  3785. }
  3786. dprintk("%s: space used=%Lu\n", __func__,
  3787. (unsigned long long)*used);
  3788. return ret;
  3789. }
  3790. static __be32 *
  3791. xdr_decode_nfstime4(__be32 *p, struct timespec64 *t)
  3792. {
  3793. __u64 sec;
  3794. p = xdr_decode_hyper(p, &sec);
  3795. t-> tv_sec = sec;
  3796. t->tv_nsec = be32_to_cpup(p++);
  3797. return p;
  3798. }
  3799. static int decode_attr_time(struct xdr_stream *xdr, struct timespec64 *time)
  3800. {
  3801. __be32 *p;
  3802. p = xdr_inline_decode(xdr, nfstime4_maxsz << 2);
  3803. if (unlikely(!p))
  3804. return -EIO;
  3805. xdr_decode_nfstime4(p, time);
  3806. return 0;
  3807. }
  3808. static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
  3809. {
  3810. int status = 0;
  3811. time->tv_sec = 0;
  3812. time->tv_nsec = 0;
  3813. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
  3814. return -EIO;
  3815. if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
  3816. status = decode_attr_time(xdr, time);
  3817. if (status == 0)
  3818. status = NFS_ATTR_FATTR_ATIME;
  3819. bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
  3820. }
  3821. dprintk("%s: atime=%lld\n", __func__, time->tv_sec);
  3822. return status;
  3823. }
  3824. static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
  3825. {
  3826. int status = 0;
  3827. time->tv_sec = 0;
  3828. time->tv_nsec = 0;
  3829. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
  3830. return -EIO;
  3831. if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
  3832. status = decode_attr_time(xdr, time);
  3833. if (status == 0)
  3834. status = NFS_ATTR_FATTR_CTIME;
  3835. bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
  3836. }
  3837. dprintk("%s: ctime=%lld\n", __func__, time->tv_sec);
  3838. return status;
  3839. }
  3840. static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
  3841. struct timespec64 *time)
  3842. {
  3843. int status = 0;
  3844. time->tv_sec = 0;
  3845. time->tv_nsec = 0;
  3846. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
  3847. return -EIO;
  3848. if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
  3849. status = decode_attr_time(xdr, time);
  3850. bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
  3851. }
  3852. dprintk("%s: time_delta=%lld %ld\n", __func__, time->tv_sec,
  3853. time->tv_nsec);
  3854. return status;
  3855. }
  3856. static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
  3857. struct nfs4_label *label)
  3858. {
  3859. uint32_t pi = 0;
  3860. uint32_t lfs = 0;
  3861. __u32 len;
  3862. __be32 *p;
  3863. int status = 0;
  3864. if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
  3865. return -EIO;
  3866. if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
  3867. p = xdr_inline_decode(xdr, 4);
  3868. if (unlikely(!p))
  3869. return -EIO;
  3870. lfs = be32_to_cpup(p++);
  3871. p = xdr_inline_decode(xdr, 4);
  3872. if (unlikely(!p))
  3873. return -EIO;
  3874. pi = be32_to_cpup(p++);
  3875. p = xdr_inline_decode(xdr, 4);
  3876. if (unlikely(!p))
  3877. return -EIO;
  3878. len = be32_to_cpup(p++);
  3879. p = xdr_inline_decode(xdr, len);
  3880. if (unlikely(!p))
  3881. return -EIO;
  3882. bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
  3883. if (len < NFS4_MAXLABELLEN) {
  3884. if (label && label->len) {
  3885. if (label->len < len)
  3886. return -ERANGE;
  3887. memcpy(label->label, p, len);
  3888. label->len = len;
  3889. label->pi = pi;
  3890. label->lfs = lfs;
  3891. status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
  3892. }
  3893. } else
  3894. printk(KERN_WARNING "%s: label too long (%u)!\n",
  3895. __func__, len);
  3896. if (label && label->label)
  3897. dprintk("%s: label=%.*s, len=%d, PI=%d, LFS=%d\n",
  3898. __func__, label->len, (char *)label->label,
  3899. label->len, label->pi, label->lfs);
  3900. }
  3901. return status;
  3902. }
  3903. static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
  3904. {
  3905. int status = 0;
  3906. time->tv_sec = 0;
  3907. time->tv_nsec = 0;
  3908. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
  3909. return -EIO;
  3910. if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
  3911. status = decode_attr_time(xdr, time);
  3912. if (status == 0)
  3913. status = NFS_ATTR_FATTR_MTIME;
  3914. bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
  3915. }
  3916. dprintk("%s: mtime=%lld\n", __func__, time->tv_sec);
  3917. return status;
  3918. }
  3919. static int decode_attr_xattrsupport(struct xdr_stream *xdr, uint32_t *bitmap,
  3920. uint32_t *res)
  3921. {
  3922. __be32 *p;
  3923. *res = 0;
  3924. if (unlikely(bitmap[2] & (FATTR4_WORD2_XATTR_SUPPORT - 1U)))
  3925. return -EIO;
  3926. if (likely(bitmap[2] & FATTR4_WORD2_XATTR_SUPPORT)) {
  3927. p = xdr_inline_decode(xdr, 4);
  3928. if (unlikely(!p))
  3929. return -EIO;
  3930. *res = be32_to_cpup(p);
  3931. bitmap[2] &= ~FATTR4_WORD2_XATTR_SUPPORT;
  3932. }
  3933. dprintk("%s: XATTR support=%s\n", __func__, str_false_true(*res == 0));
  3934. return 0;
  3935. }
  3936. static int decode_attr_open_arguments(struct xdr_stream *xdr, uint32_t *bitmap,
  3937. struct nfs4_open_caps *res)
  3938. {
  3939. memset(res, 0, sizeof(*res));
  3940. if (unlikely(bitmap[2] & (FATTR4_WORD2_OPEN_ARGUMENTS - 1U)))
  3941. return -EIO;
  3942. if (likely(bitmap[2] & FATTR4_WORD2_OPEN_ARGUMENTS)) {
  3943. if (decode_bitmap4(xdr, res->oa_share_access, ARRAY_SIZE(res->oa_share_access)) < 0)
  3944. return -EIO;
  3945. if (decode_bitmap4(xdr, res->oa_share_deny, ARRAY_SIZE(res->oa_share_deny)) < 0)
  3946. return -EIO;
  3947. if (decode_bitmap4(xdr, res->oa_share_access_want, ARRAY_SIZE(res->oa_share_access_want)) < 0)
  3948. return -EIO;
  3949. if (decode_bitmap4(xdr, res->oa_open_claim, ARRAY_SIZE(res->oa_open_claim)) < 0)
  3950. return -EIO;
  3951. if (decode_bitmap4(xdr, res->oa_createmode, ARRAY_SIZE(res->oa_createmode)) < 0)
  3952. return -EIO;
  3953. bitmap[2] &= ~FATTR4_WORD2_OPEN_ARGUMENTS;
  3954. }
  3955. return 0;
  3956. }
  3957. static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
  3958. {
  3959. unsigned int attrwords = XDR_QUADLEN(attrlen);
  3960. unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
  3961. if (unlikely(attrwords != nwords)) {
  3962. dprintk("%s: server returned incorrect attribute length: "
  3963. "%u %c %u\n",
  3964. __func__,
  3965. attrwords << 2,
  3966. (attrwords < nwords) ? '<' : '>',
  3967. nwords << 2);
  3968. return -EIO;
  3969. }
  3970. return 0;
  3971. }
  3972. static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  3973. {
  3974. __be32 *p;
  3975. p = xdr_inline_decode(xdr, 20);
  3976. if (unlikely(!p))
  3977. return -EIO;
  3978. cinfo->atomic = be32_to_cpup(p++);
  3979. p = xdr_decode_hyper(p, &cinfo->before);
  3980. xdr_decode_hyper(p, &cinfo->after);
  3981. return 0;
  3982. }
  3983. static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
  3984. {
  3985. __be32 *p;
  3986. uint32_t supp, acc;
  3987. int status;
  3988. status = decode_op_hdr(xdr, OP_ACCESS);
  3989. if (status)
  3990. return status;
  3991. p = xdr_inline_decode(xdr, 8);
  3992. if (unlikely(!p))
  3993. return -EIO;
  3994. supp = be32_to_cpup(p++);
  3995. acc = be32_to_cpup(p);
  3996. *supported = supp;
  3997. *access = acc;
  3998. return 0;
  3999. }
  4000. static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  4001. {
  4002. return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
  4003. }
  4004. static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  4005. {
  4006. stateid->type = NFS4_OPEN_STATEID_TYPE;
  4007. return decode_stateid(xdr, stateid);
  4008. }
  4009. static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  4010. {
  4011. stateid->type = NFS4_LOCK_STATEID_TYPE;
  4012. return decode_stateid(xdr, stateid);
  4013. }
  4014. static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  4015. {
  4016. stateid->type = NFS4_DELEGATION_STATEID_TYPE;
  4017. return decode_stateid(xdr, stateid);
  4018. }
  4019. static int decode_invalid_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  4020. {
  4021. nfs4_stateid dummy;
  4022. nfs4_stateid_copy(stateid, &invalid_stateid);
  4023. return decode_stateid(xdr, &dummy);
  4024. }
  4025. static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
  4026. {
  4027. int status;
  4028. status = decode_op_hdr(xdr, OP_CLOSE);
  4029. if (status != -EIO)
  4030. nfs_increment_open_seqid(status, res->seqid);
  4031. if (!status)
  4032. status = decode_invalid_stateid(xdr, &res->stateid);
  4033. return status;
  4034. }
  4035. static int decode_verifier(struct xdr_stream *xdr, void *verifier)
  4036. {
  4037. return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
  4038. }
  4039. static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
  4040. {
  4041. return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
  4042. }
  4043. static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
  4044. {
  4045. struct nfs_writeverf *verf = res->verf;
  4046. int status;
  4047. status = decode_op_hdr(xdr, OP_COMMIT);
  4048. if (!status)
  4049. status = decode_write_verifier(xdr, &verf->verifier);
  4050. if (!status)
  4051. verf->committed = NFS_FILE_SYNC;
  4052. return status;
  4053. }
  4054. static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  4055. {
  4056. __be32 *p;
  4057. uint32_t bmlen;
  4058. int status;
  4059. status = decode_op_hdr(xdr, OP_CREATE);
  4060. if (status)
  4061. return status;
  4062. if ((status = decode_change_info(xdr, cinfo)))
  4063. return status;
  4064. p = xdr_inline_decode(xdr, 4);
  4065. if (unlikely(!p))
  4066. return -EIO;
  4067. bmlen = be32_to_cpup(p);
  4068. p = xdr_inline_decode(xdr, bmlen << 2);
  4069. if (likely(p))
  4070. return 0;
  4071. return -EIO;
  4072. }
  4073. static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
  4074. {
  4075. unsigned int savep;
  4076. uint32_t attrlen, bitmap[3] = {0};
  4077. int status;
  4078. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  4079. goto xdr_error;
  4080. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  4081. goto xdr_error;
  4082. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  4083. goto xdr_error;
  4084. if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
  4085. goto xdr_error;
  4086. if ((status = decode_attr_fh_expire_type(xdr, bitmap,
  4087. &res->fh_expire_type)) != 0)
  4088. goto xdr_error;
  4089. if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
  4090. goto xdr_error;
  4091. if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
  4092. goto xdr_error;
  4093. if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
  4094. goto xdr_error;
  4095. if ((status = decode_attr_case_insensitive(xdr, bitmap, &res->case_insensitive)) != 0)
  4096. goto xdr_error;
  4097. if ((status = decode_attr_case_preserving(xdr, bitmap, &res->case_preserving)) != 0)
  4098. goto xdr_error;
  4099. if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
  4100. res->exclcreat_bitmask)) != 0)
  4101. goto xdr_error;
  4102. if ((status = decode_attr_open_arguments(xdr, bitmap, &res->open_caps)) != 0)
  4103. goto xdr_error;
  4104. status = verify_attr_len(xdr, savep, attrlen);
  4105. xdr_error:
  4106. dprintk("%s: xdr returned %d!\n", __func__, -status);
  4107. return status;
  4108. }
  4109. static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
  4110. {
  4111. unsigned int savep;
  4112. uint32_t attrlen, bitmap[3] = {0};
  4113. int status;
  4114. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  4115. goto xdr_error;
  4116. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  4117. goto xdr_error;
  4118. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  4119. goto xdr_error;
  4120. if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
  4121. goto xdr_error;
  4122. if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
  4123. goto xdr_error;
  4124. if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
  4125. goto xdr_error;
  4126. status = -EIO;
  4127. if (unlikely(bitmap[0]))
  4128. goto xdr_error;
  4129. if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
  4130. goto xdr_error;
  4131. if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
  4132. goto xdr_error;
  4133. if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
  4134. goto xdr_error;
  4135. status = verify_attr_len(xdr, savep, attrlen);
  4136. xdr_error:
  4137. dprintk("%s: xdr returned %d!\n", __func__, -status);
  4138. return status;
  4139. }
  4140. static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
  4141. {
  4142. unsigned int savep;
  4143. uint32_t attrlen, bitmap[3] = {0};
  4144. int status;
  4145. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  4146. goto xdr_error;
  4147. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  4148. goto xdr_error;
  4149. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  4150. goto xdr_error;
  4151. if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
  4152. goto xdr_error;
  4153. if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
  4154. goto xdr_error;
  4155. status = verify_attr_len(xdr, savep, attrlen);
  4156. xdr_error:
  4157. dprintk("%s: xdr returned %d!\n", __func__, -status);
  4158. return status;
  4159. }
  4160. static int decode_threshold_hint(struct xdr_stream *xdr,
  4161. uint32_t *bitmap,
  4162. uint64_t *res,
  4163. uint32_t hint_bit)
  4164. {
  4165. __be32 *p;
  4166. *res = 0;
  4167. if (likely(bitmap[0] & hint_bit)) {
  4168. p = xdr_inline_decode(xdr, 8);
  4169. if (unlikely(!p))
  4170. return -EIO;
  4171. xdr_decode_hyper(p, res);
  4172. }
  4173. return 0;
  4174. }
  4175. static int decode_first_threshold_item4(struct xdr_stream *xdr,
  4176. struct nfs4_threshold *res)
  4177. {
  4178. __be32 *p;
  4179. unsigned int savep;
  4180. uint32_t bitmap[3] = {0,}, attrlen;
  4181. int status;
  4182. /* layout type */
  4183. p = xdr_inline_decode(xdr, 4);
  4184. if (unlikely(!p))
  4185. return -EIO;
  4186. res->l_type = be32_to_cpup(p);
  4187. /* thi_hintset bitmap */
  4188. status = decode_attr_bitmap(xdr, bitmap);
  4189. if (status < 0)
  4190. goto xdr_error;
  4191. /* thi_hintlist length */
  4192. status = decode_attr_length(xdr, &attrlen, &savep);
  4193. if (status < 0)
  4194. goto xdr_error;
  4195. /* thi_hintlist */
  4196. status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
  4197. if (status < 0)
  4198. goto xdr_error;
  4199. status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
  4200. if (status < 0)
  4201. goto xdr_error;
  4202. status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
  4203. THRESHOLD_RD_IO);
  4204. if (status < 0)
  4205. goto xdr_error;
  4206. status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
  4207. THRESHOLD_WR_IO);
  4208. if (status < 0)
  4209. goto xdr_error;
  4210. status = verify_attr_len(xdr, savep, attrlen);
  4211. res->bm = bitmap[0];
  4212. dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
  4213. __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
  4214. res->wr_io_sz);
  4215. xdr_error:
  4216. dprintk("%s ret=%d!\n", __func__, status);
  4217. return status;
  4218. }
  4219. /*
  4220. * Thresholds on pNFS direct I/O vrs MDS I/O
  4221. */
  4222. static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
  4223. uint32_t *bitmap,
  4224. struct nfs4_threshold *res)
  4225. {
  4226. __be32 *p;
  4227. int status = 0;
  4228. uint32_t num;
  4229. if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
  4230. return -EIO;
  4231. if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
  4232. /* Did the server return an unrequested attribute? */
  4233. if (unlikely(res == NULL))
  4234. return -EREMOTEIO;
  4235. p = xdr_inline_decode(xdr, 4);
  4236. if (unlikely(!p))
  4237. return -EIO;
  4238. num = be32_to_cpup(p);
  4239. if (num == 0)
  4240. return 0;
  4241. if (num > 1)
  4242. printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
  4243. "drivers per filesystem not supported\n",
  4244. __func__);
  4245. status = decode_first_threshold_item4(xdr, res);
  4246. bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
  4247. }
  4248. return status;
  4249. }
  4250. static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
  4251. struct nfs_fattr *fattr, struct nfs_fh *fh,
  4252. struct nfs4_fs_locations *fs_loc, const struct nfs_server *server)
  4253. {
  4254. int status;
  4255. umode_t fmode = 0;
  4256. uint32_t type;
  4257. int32_t err;
  4258. status = decode_attr_type(xdr, bitmap, &type);
  4259. if (status < 0)
  4260. goto xdr_error;
  4261. fattr->mode = 0;
  4262. if (status != 0) {
  4263. fattr->mode |= nfs_type2fmt[type];
  4264. fattr->valid |= status;
  4265. }
  4266. status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
  4267. if (status < 0)
  4268. goto xdr_error;
  4269. fattr->valid |= status;
  4270. status = decode_attr_size(xdr, bitmap, &fattr->size);
  4271. if (status < 0)
  4272. goto xdr_error;
  4273. fattr->valid |= status;
  4274. status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
  4275. if (status < 0)
  4276. goto xdr_error;
  4277. fattr->valid |= status;
  4278. err = 0;
  4279. status = decode_attr_error(xdr, bitmap, &err);
  4280. if (status < 0)
  4281. goto xdr_error;
  4282. status = decode_attr_filehandle(xdr, bitmap, fh);
  4283. if (status < 0)
  4284. goto xdr_error;
  4285. status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
  4286. if (status < 0)
  4287. goto xdr_error;
  4288. fattr->valid |= status;
  4289. status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
  4290. if (status < 0)
  4291. goto xdr_error;
  4292. fattr->valid |= status;
  4293. status = -EIO;
  4294. if (unlikely(bitmap[0]))
  4295. goto xdr_error;
  4296. status = decode_attr_mode(xdr, bitmap, &fmode);
  4297. if (status < 0)
  4298. goto xdr_error;
  4299. if (status != 0) {
  4300. fattr->mode |= fmode;
  4301. fattr->valid |= status;
  4302. }
  4303. status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
  4304. if (status < 0)
  4305. goto xdr_error;
  4306. fattr->valid |= status;
  4307. status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
  4308. if (status < 0)
  4309. goto xdr_error;
  4310. fattr->valid |= status;
  4311. status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
  4312. if (status < 0)
  4313. goto xdr_error;
  4314. fattr->valid |= status;
  4315. status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
  4316. if (status < 0)
  4317. goto xdr_error;
  4318. fattr->valid |= status;
  4319. status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
  4320. if (status < 0)
  4321. goto xdr_error;
  4322. fattr->valid |= status;
  4323. status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
  4324. if (status < 0)
  4325. goto xdr_error;
  4326. fattr->valid |= status;
  4327. status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
  4328. if (status < 0)
  4329. goto xdr_error;
  4330. fattr->valid |= status;
  4331. status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
  4332. if (status < 0)
  4333. goto xdr_error;
  4334. fattr->valid |= status;
  4335. status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
  4336. if (status < 0)
  4337. goto xdr_error;
  4338. fattr->valid |= status;
  4339. status = -EIO;
  4340. if (unlikely(bitmap[1]))
  4341. goto xdr_error;
  4342. status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
  4343. if (status < 0)
  4344. goto xdr_error;
  4345. status = decode_attr_security_label(xdr, bitmap, fattr->label);
  4346. if (status < 0)
  4347. goto xdr_error;
  4348. fattr->valid |= status;
  4349. xdr_error:
  4350. dprintk("%s: xdr returned %d\n", __func__, -status);
  4351. return status;
  4352. }
  4353. static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
  4354. struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
  4355. const struct nfs_server *server)
  4356. {
  4357. unsigned int savep;
  4358. uint32_t attrlen,
  4359. bitmap[3] = {0};
  4360. int status;
  4361. status = decode_op_hdr(xdr, OP_GETATTR);
  4362. if (status < 0)
  4363. goto xdr_error;
  4364. status = decode_attr_bitmap(xdr, bitmap);
  4365. if (status < 0)
  4366. goto xdr_error;
  4367. status = decode_attr_length(xdr, &attrlen, &savep);
  4368. if (status < 0)
  4369. goto xdr_error;
  4370. status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
  4371. if (status < 0)
  4372. goto xdr_error;
  4373. status = verify_attr_len(xdr, savep, attrlen);
  4374. xdr_error:
  4375. dprintk("%s: xdr returned %d\n", __func__, -status);
  4376. return status;
  4377. }
  4378. static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
  4379. const struct nfs_server *server)
  4380. {
  4381. return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
  4382. }
  4383. /*
  4384. * Decode potentially multiple layout types.
  4385. */
  4386. static int decode_pnfs_layout_types(struct xdr_stream *xdr,
  4387. struct nfs_fsinfo *fsinfo)
  4388. {
  4389. __be32 *p;
  4390. uint32_t i;
  4391. p = xdr_inline_decode(xdr, 4);
  4392. if (unlikely(!p))
  4393. return -EIO;
  4394. fsinfo->nlayouttypes = be32_to_cpup(p);
  4395. /* pNFS is not supported by the underlying file system */
  4396. if (fsinfo->nlayouttypes == 0)
  4397. return 0;
  4398. /* Decode and set first layout type, move xdr->p past unused types */
  4399. p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
  4400. if (unlikely(!p))
  4401. return -EIO;
  4402. /* If we get too many, then just cap it at the max */
  4403. if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
  4404. printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
  4405. __func__, fsinfo->nlayouttypes);
  4406. fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
  4407. }
  4408. for(i = 0; i < fsinfo->nlayouttypes; ++i)
  4409. fsinfo->layouttype[i] = be32_to_cpup(p++);
  4410. return 0;
  4411. }
  4412. /*
  4413. * The type of file system exported.
  4414. * Note we must ensure that layouttype is set in any non-error case.
  4415. */
  4416. static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
  4417. struct nfs_fsinfo *fsinfo)
  4418. {
  4419. int status = 0;
  4420. dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
  4421. if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
  4422. return -EIO;
  4423. if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
  4424. status = decode_pnfs_layout_types(xdr, fsinfo);
  4425. bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
  4426. }
  4427. return status;
  4428. }
  4429. /*
  4430. * The prefered block size for layout directed io
  4431. */
  4432. static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
  4433. uint32_t *res)
  4434. {
  4435. __be32 *p;
  4436. dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
  4437. *res = 0;
  4438. if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
  4439. p = xdr_inline_decode(xdr, 4);
  4440. if (unlikely(!p))
  4441. return -EIO;
  4442. *res = be32_to_cpup(p);
  4443. bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
  4444. }
  4445. return 0;
  4446. }
  4447. /*
  4448. * The granularity of a CLONE operation.
  4449. */
  4450. static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
  4451. uint32_t *res)
  4452. {
  4453. __be32 *p;
  4454. dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
  4455. *res = 0;
  4456. if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
  4457. p = xdr_inline_decode(xdr, 4);
  4458. if (unlikely(!p))
  4459. return -EIO;
  4460. *res = be32_to_cpup(p);
  4461. bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
  4462. }
  4463. return 0;
  4464. }
  4465. static int decode_attr_change_attr_type(struct xdr_stream *xdr,
  4466. uint32_t *bitmap,
  4467. enum nfs4_change_attr_type *res)
  4468. {
  4469. u32 tmp = NFS4_CHANGE_TYPE_IS_UNDEFINED;
  4470. dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
  4471. if (bitmap[2] & FATTR4_WORD2_CHANGE_ATTR_TYPE) {
  4472. if (xdr_stream_decode_u32(xdr, &tmp))
  4473. return -EIO;
  4474. bitmap[2] &= ~FATTR4_WORD2_CHANGE_ATTR_TYPE;
  4475. }
  4476. switch(tmp) {
  4477. case NFS4_CHANGE_TYPE_IS_MONOTONIC_INCR:
  4478. case NFS4_CHANGE_TYPE_IS_VERSION_COUNTER:
  4479. case NFS4_CHANGE_TYPE_IS_VERSION_COUNTER_NOPNFS:
  4480. case NFS4_CHANGE_TYPE_IS_TIME_METADATA:
  4481. *res = tmp;
  4482. break;
  4483. default:
  4484. *res = NFS4_CHANGE_TYPE_IS_UNDEFINED;
  4485. }
  4486. return 0;
  4487. }
  4488. static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
  4489. {
  4490. unsigned int savep;
  4491. uint32_t attrlen, bitmap[3];
  4492. int status;
  4493. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  4494. goto xdr_error;
  4495. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  4496. goto xdr_error;
  4497. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  4498. goto xdr_error;
  4499. fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
  4500. if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
  4501. goto xdr_error;
  4502. if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
  4503. goto xdr_error;
  4504. if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
  4505. goto xdr_error;
  4506. fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
  4507. if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
  4508. goto xdr_error;
  4509. fsinfo->wtpref = fsinfo->wtmax;
  4510. status = -EIO;
  4511. if (unlikely(bitmap[0]))
  4512. goto xdr_error;
  4513. status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
  4514. if (status != 0)
  4515. goto xdr_error;
  4516. status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
  4517. if (status != 0)
  4518. goto xdr_error;
  4519. status = -EIO;
  4520. if (unlikely(bitmap[1]))
  4521. goto xdr_error;
  4522. status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
  4523. if (status)
  4524. goto xdr_error;
  4525. status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
  4526. if (status)
  4527. goto xdr_error;
  4528. status = decode_attr_change_attr_type(xdr, bitmap,
  4529. &fsinfo->change_attr_type);
  4530. if (status)
  4531. goto xdr_error;
  4532. status = decode_attr_xattrsupport(xdr, bitmap,
  4533. &fsinfo->xattr_support);
  4534. if (status)
  4535. goto xdr_error;
  4536. status = verify_attr_len(xdr, savep, attrlen);
  4537. xdr_error:
  4538. dprintk("%s: xdr returned %d!\n", __func__, -status);
  4539. return status;
  4540. }
  4541. static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
  4542. {
  4543. __be32 *p;
  4544. uint32_t len;
  4545. int status;
  4546. /* Zero handle first to allow comparisons */
  4547. memset(fh, 0, sizeof(*fh));
  4548. status = decode_op_hdr(xdr, OP_GETFH);
  4549. if (status)
  4550. return status;
  4551. p = xdr_inline_decode(xdr, 4);
  4552. if (unlikely(!p))
  4553. return -EIO;
  4554. len = be32_to_cpup(p);
  4555. if (len > NFS4_FHSIZE || len == 0) {
  4556. trace_nfs4_xdr_bad_filehandle(xdr, OP_GETFH, NFS4ERR_BADHANDLE);
  4557. return -EREMOTEIO;
  4558. }
  4559. fh->size = len;
  4560. p = xdr_inline_decode(xdr, len);
  4561. if (unlikely(!p))
  4562. return -EIO;
  4563. memcpy(fh->data, p, len);
  4564. return 0;
  4565. }
  4566. static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  4567. {
  4568. int status;
  4569. status = decode_op_hdr(xdr, OP_LINK);
  4570. if (status)
  4571. return status;
  4572. return decode_change_info(xdr, cinfo);
  4573. }
  4574. /*
  4575. * We create the owner, so we know a proper owner.id length is 4.
  4576. */
  4577. static int decode_lock_denied(struct xdr_stream *xdr, struct file_lock *fl)
  4578. {
  4579. uint64_t offset, length, clientid;
  4580. __be32 *p;
  4581. uint32_t namelen, type;
  4582. p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
  4583. if (unlikely(!p))
  4584. return -EIO;
  4585. p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
  4586. p = xdr_decode_hyper(p, &length);
  4587. type = be32_to_cpup(p++); /* 4 byte read */
  4588. if (fl != NULL) { /* manipulate file lock */
  4589. fl->fl_start = (loff_t)offset;
  4590. fl->fl_end = fl->fl_start + (loff_t)length - 1;
  4591. if (length == ~(uint64_t)0)
  4592. fl->fl_end = OFFSET_MAX;
  4593. fl->c.flc_type = F_WRLCK;
  4594. if (type & 1)
  4595. fl->c.flc_type = F_RDLCK;
  4596. fl->c.flc_pid = 0;
  4597. }
  4598. p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
  4599. namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
  4600. p = xdr_inline_decode(xdr, namelen); /* variable size field */
  4601. if (likely(!p))
  4602. return -EIO;
  4603. return -NFS4ERR_DENIED;
  4604. }
  4605. static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
  4606. {
  4607. int status;
  4608. status = decode_op_hdr(xdr, OP_LOCK);
  4609. if (status == -EIO)
  4610. goto out;
  4611. if (status == 0) {
  4612. status = decode_lock_stateid(xdr, &res->stateid);
  4613. if (unlikely(status))
  4614. goto out;
  4615. } else if (status == -NFS4ERR_DENIED)
  4616. status = decode_lock_denied(xdr, NULL);
  4617. if (res->open_seqid != NULL)
  4618. nfs_increment_open_seqid(status, res->open_seqid);
  4619. nfs_increment_lock_seqid(status, res->lock_seqid);
  4620. out:
  4621. return status;
  4622. }
  4623. static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
  4624. {
  4625. int status;
  4626. status = decode_op_hdr(xdr, OP_LOCKT);
  4627. if (status == -NFS4ERR_DENIED)
  4628. return decode_lock_denied(xdr, res->denied);
  4629. return status;
  4630. }
  4631. static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
  4632. {
  4633. int status;
  4634. status = decode_op_hdr(xdr, OP_LOCKU);
  4635. if (status != -EIO)
  4636. nfs_increment_lock_seqid(status, res->seqid);
  4637. if (status == 0)
  4638. status = decode_lock_stateid(xdr, &res->stateid);
  4639. return status;
  4640. }
  4641. static int decode_release_lockowner(struct xdr_stream *xdr)
  4642. {
  4643. return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
  4644. }
  4645. static int decode_lookup(struct xdr_stream *xdr)
  4646. {
  4647. return decode_op_hdr(xdr, OP_LOOKUP);
  4648. }
  4649. static int decode_lookupp(struct xdr_stream *xdr)
  4650. {
  4651. return decode_op_hdr(xdr, OP_LOOKUPP);
  4652. }
  4653. /* This is too sick! */
  4654. static int decode_space_limit(struct xdr_stream *xdr,
  4655. unsigned long *pagemod_limit)
  4656. {
  4657. __be32 *p;
  4658. uint32_t limit_type, nblocks, blocksize;
  4659. u64 maxsize = 0;
  4660. p = xdr_inline_decode(xdr, 12);
  4661. if (unlikely(!p))
  4662. return -EIO;
  4663. limit_type = be32_to_cpup(p++);
  4664. switch (limit_type) {
  4665. case NFS4_LIMIT_SIZE:
  4666. xdr_decode_hyper(p, &maxsize);
  4667. break;
  4668. case NFS4_LIMIT_BLOCKS:
  4669. nblocks = be32_to_cpup(p++);
  4670. blocksize = be32_to_cpup(p);
  4671. maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
  4672. }
  4673. maxsize >>= PAGE_SHIFT;
  4674. *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
  4675. return 0;
  4676. }
  4677. static int decode_rw_delegation(struct xdr_stream *xdr,
  4678. struct nfs4_open_delegation *res)
  4679. {
  4680. __be32 *p;
  4681. int status;
  4682. status = decode_delegation_stateid(xdr, &res->stateid);
  4683. if (unlikely(status))
  4684. return status;
  4685. p = xdr_inline_decode(xdr, 4);
  4686. if (unlikely(!p))
  4687. return -EIO;
  4688. res->do_recall = be32_to_cpup(p);
  4689. switch (res->open_delegation_type) {
  4690. case NFS4_OPEN_DELEGATE_READ:
  4691. case NFS4_OPEN_DELEGATE_READ_ATTRS_DELEG:
  4692. res->type = FMODE_READ;
  4693. break;
  4694. case NFS4_OPEN_DELEGATE_WRITE:
  4695. case NFS4_OPEN_DELEGATE_WRITE_ATTRS_DELEG:
  4696. res->type = FMODE_WRITE|FMODE_READ;
  4697. if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
  4698. return -EIO;
  4699. }
  4700. return decode_ace(xdr, NULL);
  4701. }
  4702. static int decode_no_delegation(struct xdr_stream *xdr,
  4703. struct nfs4_open_delegation *res)
  4704. {
  4705. __be32 *p;
  4706. p = xdr_inline_decode(xdr, 4);
  4707. if (unlikely(!p))
  4708. return -EIO;
  4709. res->why_no_delegation = be32_to_cpup(p);
  4710. switch (res->why_no_delegation) {
  4711. case WND4_CONTENTION:
  4712. case WND4_RESOURCE:
  4713. p = xdr_inline_decode(xdr, 4);
  4714. if (unlikely(!p))
  4715. return -EIO;
  4716. res->will_notify = be32_to_cpup(p);
  4717. }
  4718. return 0;
  4719. }
  4720. static int decode_delegation(struct xdr_stream *xdr,
  4721. struct nfs4_open_delegation *res)
  4722. {
  4723. __be32 *p;
  4724. p = xdr_inline_decode(xdr, 4);
  4725. if (unlikely(!p))
  4726. return -EIO;
  4727. res->open_delegation_type = be32_to_cpup(p);
  4728. switch (res->open_delegation_type) {
  4729. case NFS4_OPEN_DELEGATE_NONE:
  4730. return 0;
  4731. case NFS4_OPEN_DELEGATE_READ:
  4732. case NFS4_OPEN_DELEGATE_WRITE:
  4733. case NFS4_OPEN_DELEGATE_READ_ATTRS_DELEG:
  4734. case NFS4_OPEN_DELEGATE_WRITE_ATTRS_DELEG:
  4735. return decode_rw_delegation(xdr, res);
  4736. case NFS4_OPEN_DELEGATE_NONE_EXT:
  4737. return decode_no_delegation(xdr, res);
  4738. }
  4739. return -EIO;
  4740. }
  4741. static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
  4742. {
  4743. __be32 *p;
  4744. uint32_t savewords, bmlen, i;
  4745. int status;
  4746. if (!__decode_op_hdr(xdr, OP_OPEN, &status))
  4747. return status;
  4748. nfs_increment_open_seqid(status, res->seqid);
  4749. if (status)
  4750. return status;
  4751. status = decode_open_stateid(xdr, &res->stateid);
  4752. if (unlikely(status))
  4753. return status;
  4754. decode_change_info(xdr, &res->cinfo);
  4755. p = xdr_inline_decode(xdr, 8);
  4756. if (unlikely(!p))
  4757. return -EIO;
  4758. res->rflags = be32_to_cpup(p++);
  4759. bmlen = be32_to_cpup(p);
  4760. if (bmlen > 10)
  4761. goto xdr_error;
  4762. p = xdr_inline_decode(xdr, bmlen << 2);
  4763. if (unlikely(!p))
  4764. return -EIO;
  4765. savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
  4766. for (i = 0; i < savewords; ++i)
  4767. res->attrset[i] = be32_to_cpup(p++);
  4768. for (; i < NFS4_BITMAP_SIZE; i++)
  4769. res->attrset[i] = 0;
  4770. return decode_delegation(xdr, &res->delegation);
  4771. xdr_error:
  4772. dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
  4773. return -EIO;
  4774. }
  4775. static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
  4776. {
  4777. int status;
  4778. status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
  4779. if (status != -EIO)
  4780. nfs_increment_open_seqid(status, res->seqid);
  4781. if (!status)
  4782. status = decode_open_stateid(xdr, &res->stateid);
  4783. return status;
  4784. }
  4785. static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
  4786. {
  4787. int status;
  4788. status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
  4789. if (status != -EIO)
  4790. nfs_increment_open_seqid(status, res->seqid);
  4791. if (!status)
  4792. status = decode_open_stateid(xdr, &res->stateid);
  4793. return status;
  4794. }
  4795. static int decode_putfh(struct xdr_stream *xdr)
  4796. {
  4797. return decode_op_hdr(xdr, OP_PUTFH);
  4798. }
  4799. static int decode_putrootfh(struct xdr_stream *xdr)
  4800. {
  4801. return decode_op_hdr(xdr, OP_PUTROOTFH);
  4802. }
  4803. static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
  4804. struct nfs_pgio_res *res)
  4805. {
  4806. __be32 *p;
  4807. uint32_t count, eof, recvd;
  4808. int status;
  4809. status = decode_op_hdr(xdr, OP_READ);
  4810. if (status)
  4811. return status;
  4812. p = xdr_inline_decode(xdr, 8);
  4813. if (unlikely(!p))
  4814. return -EIO;
  4815. eof = be32_to_cpup(p++);
  4816. count = be32_to_cpup(p);
  4817. recvd = xdr_read_pages(xdr, count);
  4818. if (count > recvd) {
  4819. dprintk("NFS: server cheating in read reply: "
  4820. "count %u > recvd %u\n", count, recvd);
  4821. count = recvd;
  4822. eof = 0;
  4823. }
  4824. res->eof = eof;
  4825. res->count = count;
  4826. return 0;
  4827. }
  4828. static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
  4829. {
  4830. int status;
  4831. __be32 verf[2];
  4832. status = decode_op_hdr(xdr, OP_READDIR);
  4833. if (!status)
  4834. status = decode_verifier(xdr, readdir->verifier.data);
  4835. if (unlikely(status))
  4836. return status;
  4837. memcpy(verf, readdir->verifier.data, sizeof(verf));
  4838. dprintk("%s: verifier = %08x:%08x\n",
  4839. __func__, verf[0], verf[1]);
  4840. return xdr_read_pages(xdr, xdr->buf->page_len);
  4841. }
  4842. static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
  4843. {
  4844. struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
  4845. u32 len, recvd;
  4846. __be32 *p;
  4847. int status;
  4848. status = decode_op_hdr(xdr, OP_READLINK);
  4849. if (status)
  4850. return status;
  4851. /* Convert length of symlink */
  4852. p = xdr_inline_decode(xdr, 4);
  4853. if (unlikely(!p))
  4854. return -EIO;
  4855. len = be32_to_cpup(p);
  4856. if (len >= rcvbuf->page_len || len <= 0) {
  4857. dprintk("nfs: server returned giant symlink!\n");
  4858. return -ENAMETOOLONG;
  4859. }
  4860. recvd = xdr_read_pages(xdr, len);
  4861. if (recvd < len) {
  4862. dprintk("NFS: server cheating in readlink reply: "
  4863. "count %u > recvd %u\n", len, recvd);
  4864. return -EIO;
  4865. }
  4866. /*
  4867. * The XDR encode routine has set things up so that
  4868. * the link text will be copied directly into the
  4869. * buffer. We just have to do overflow-checking,
  4870. * and null-terminate the text (the VFS expects
  4871. * null-termination).
  4872. */
  4873. xdr_terminate_string(rcvbuf, len);
  4874. return 0;
  4875. }
  4876. static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  4877. {
  4878. int status;
  4879. status = decode_op_hdr(xdr, OP_REMOVE);
  4880. if (status)
  4881. goto out;
  4882. status = decode_change_info(xdr, cinfo);
  4883. out:
  4884. return status;
  4885. }
  4886. static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
  4887. struct nfs4_change_info *new_cinfo)
  4888. {
  4889. int status;
  4890. status = decode_op_hdr(xdr, OP_RENAME);
  4891. if (status)
  4892. goto out;
  4893. if ((status = decode_change_info(xdr, old_cinfo)))
  4894. goto out;
  4895. status = decode_change_info(xdr, new_cinfo);
  4896. out:
  4897. return status;
  4898. }
  4899. static int decode_renew(struct xdr_stream *xdr)
  4900. {
  4901. return decode_op_hdr(xdr, OP_RENEW);
  4902. }
  4903. static int
  4904. decode_restorefh(struct xdr_stream *xdr)
  4905. {
  4906. return decode_op_hdr(xdr, OP_RESTOREFH);
  4907. }
  4908. static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
  4909. struct nfs_getaclres *res, enum nfs4_acl_type type)
  4910. {
  4911. unsigned int savep;
  4912. uint32_t attrlen,
  4913. bitmap[3] = {0};
  4914. int status;
  4915. res->acl_len = 0;
  4916. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  4917. goto out;
  4918. xdr_enter_page(xdr, xdr->buf->page_len);
  4919. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  4920. goto out;
  4921. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  4922. goto out;
  4923. switch (type) {
  4924. default:
  4925. if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
  4926. return -EIO;
  4927. if (!(bitmap[0] & FATTR4_WORD0_ACL))
  4928. return -EOPNOTSUPP;
  4929. break;
  4930. case NFS4ACL_DACL:
  4931. if (unlikely(bitmap[0] || bitmap[1] & (FATTR4_WORD1_DACL - 1U)))
  4932. return -EIO;
  4933. if (!(bitmap[1] & FATTR4_WORD1_DACL))
  4934. return -EOPNOTSUPP;
  4935. break;
  4936. case NFS4ACL_SACL:
  4937. if (unlikely(bitmap[0] || bitmap[1] & (FATTR4_WORD1_SACL - 1U)))
  4938. return -EIO;
  4939. if (!(bitmap[1] & FATTR4_WORD1_SACL))
  4940. return -EOPNOTSUPP;
  4941. }
  4942. /* The bitmap (xdr len + bitmaps) and the attr xdr len words
  4943. * are stored with the acl data to handle the problem of
  4944. * variable length bitmaps.*/
  4945. res->acl_data_offset = xdr_page_pos(xdr);
  4946. res->acl_len = attrlen;
  4947. /* Check for receive buffer overflow */
  4948. if (res->acl_len > xdr_stream_remaining(xdr) ||
  4949. res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
  4950. res->acl_flags |= NFS4_ACL_TRUNC;
  4951. dprintk("NFS: acl reply: attrlen %u > page_len %zu\n",
  4952. attrlen, xdr_stream_remaining(xdr));
  4953. }
  4954. out:
  4955. return status;
  4956. }
  4957. static int
  4958. decode_savefh(struct xdr_stream *xdr)
  4959. {
  4960. return decode_op_hdr(xdr, OP_SAVEFH);
  4961. }
  4962. static int decode_setattr(struct xdr_stream *xdr)
  4963. {
  4964. int status;
  4965. status = decode_op_hdr(xdr, OP_SETATTR);
  4966. if (status)
  4967. return status;
  4968. if (decode_bitmap4(xdr, NULL, 0) >= 0)
  4969. return 0;
  4970. return -EIO;
  4971. }
  4972. static int decode_delegattr(struct xdr_stream *xdr)
  4973. {
  4974. return decode_setattr(xdr);
  4975. }
  4976. static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
  4977. {
  4978. __be32 *p;
  4979. uint32_t opnum;
  4980. int32_t nfserr;
  4981. p = xdr_inline_decode(xdr, 8);
  4982. if (unlikely(!p))
  4983. return -EIO;
  4984. opnum = be32_to_cpup(p++);
  4985. if (opnum != OP_SETCLIENTID) {
  4986. dprintk("nfs: decode_setclientid: Server returned operation"
  4987. " %d\n", opnum);
  4988. return -EIO;
  4989. }
  4990. nfserr = be32_to_cpup(p);
  4991. if (nfserr == NFS_OK) {
  4992. p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
  4993. if (unlikely(!p))
  4994. return -EIO;
  4995. p = xdr_decode_hyper(p, &res->clientid);
  4996. memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
  4997. } else if (nfserr == NFSERR_CLID_INUSE) {
  4998. uint32_t len;
  4999. /* skip netid string */
  5000. p = xdr_inline_decode(xdr, 4);
  5001. if (unlikely(!p))
  5002. return -EIO;
  5003. len = be32_to_cpup(p);
  5004. p = xdr_inline_decode(xdr, len);
  5005. if (unlikely(!p))
  5006. return -EIO;
  5007. /* skip uaddr string */
  5008. p = xdr_inline_decode(xdr, 4);
  5009. if (unlikely(!p))
  5010. return -EIO;
  5011. len = be32_to_cpup(p);
  5012. p = xdr_inline_decode(xdr, len);
  5013. if (unlikely(!p))
  5014. return -EIO;
  5015. return -NFSERR_CLID_INUSE;
  5016. } else
  5017. return nfs4_stat_to_errno(nfserr);
  5018. return 0;
  5019. }
  5020. static int decode_setclientid_confirm(struct xdr_stream *xdr)
  5021. {
  5022. return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
  5023. }
  5024. static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
  5025. {
  5026. __be32 *p;
  5027. int status;
  5028. status = decode_op_hdr(xdr, OP_WRITE);
  5029. if (status)
  5030. return status;
  5031. p = xdr_inline_decode(xdr, 8);
  5032. if (unlikely(!p))
  5033. return -EIO;
  5034. res->count = be32_to_cpup(p++);
  5035. res->verf->committed = be32_to_cpup(p++);
  5036. return decode_write_verifier(xdr, &res->verf->verifier);
  5037. }
  5038. static int decode_delegreturn(struct xdr_stream *xdr)
  5039. {
  5040. return decode_op_hdr(xdr, OP_DELEGRETURN);
  5041. }
  5042. static int decode_secinfo_gss(struct xdr_stream *xdr,
  5043. struct nfs4_secinfo4 *flavor)
  5044. {
  5045. u32 oid_len;
  5046. __be32 *p;
  5047. p = xdr_inline_decode(xdr, 4);
  5048. if (unlikely(!p))
  5049. return -EIO;
  5050. oid_len = be32_to_cpup(p);
  5051. if (oid_len > GSS_OID_MAX_LEN)
  5052. return -EINVAL;
  5053. p = xdr_inline_decode(xdr, oid_len);
  5054. if (unlikely(!p))
  5055. return -EIO;
  5056. memcpy(flavor->flavor_info.oid.data, p, oid_len);
  5057. flavor->flavor_info.oid.len = oid_len;
  5058. p = xdr_inline_decode(xdr, 8);
  5059. if (unlikely(!p))
  5060. return -EIO;
  5061. flavor->flavor_info.qop = be32_to_cpup(p++);
  5062. flavor->flavor_info.service = be32_to_cpup(p);
  5063. return 0;
  5064. }
  5065. static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
  5066. {
  5067. struct nfs4_secinfo4 *sec_flavor;
  5068. unsigned int i, num_flavors;
  5069. int status;
  5070. __be32 *p;
  5071. p = xdr_inline_decode(xdr, 4);
  5072. if (unlikely(!p))
  5073. return -EIO;
  5074. res->flavors->num_flavors = 0;
  5075. num_flavors = be32_to_cpup(p);
  5076. for (i = 0; i < num_flavors; i++) {
  5077. sec_flavor = &res->flavors->flavors[i];
  5078. if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
  5079. break;
  5080. p = xdr_inline_decode(xdr, 4);
  5081. if (unlikely(!p))
  5082. return -EIO;
  5083. sec_flavor->flavor = be32_to_cpup(p);
  5084. if (sec_flavor->flavor == RPC_AUTH_GSS) {
  5085. status = decode_secinfo_gss(xdr, sec_flavor);
  5086. if (status)
  5087. goto out;
  5088. }
  5089. res->flavors->num_flavors++;
  5090. }
  5091. status = 0;
  5092. out:
  5093. return status;
  5094. }
  5095. static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
  5096. {
  5097. int status = decode_op_hdr(xdr, OP_SECINFO);
  5098. if (status)
  5099. return status;
  5100. return decode_secinfo_common(xdr, res);
  5101. }
  5102. #if defined(CONFIG_NFS_V4_1)
  5103. static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
  5104. {
  5105. int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
  5106. if (status)
  5107. return status;
  5108. return decode_secinfo_common(xdr, res);
  5109. }
  5110. static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
  5111. {
  5112. if (xdr_stream_decode_uint32_array(xdr, op_map->u.words,
  5113. ARRAY_SIZE(op_map->u.words)) < 0)
  5114. return -EIO;
  5115. return 0;
  5116. }
  5117. static int decode_exchange_id(struct xdr_stream *xdr,
  5118. struct nfs41_exchange_id_res *res)
  5119. {
  5120. __be32 *p;
  5121. uint32_t dummy;
  5122. char *dummy_str;
  5123. int status;
  5124. uint32_t impl_id_count;
  5125. status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
  5126. if (status)
  5127. return status;
  5128. p = xdr_inline_decode(xdr, 8);
  5129. if (unlikely(!p))
  5130. return -EIO;
  5131. xdr_decode_hyper(p, &res->clientid);
  5132. p = xdr_inline_decode(xdr, 12);
  5133. if (unlikely(!p))
  5134. return -EIO;
  5135. res->seqid = be32_to_cpup(p++);
  5136. res->flags = be32_to_cpup(p++);
  5137. res->state_protect.how = be32_to_cpup(p);
  5138. switch (res->state_protect.how) {
  5139. case SP4_NONE:
  5140. break;
  5141. case SP4_MACH_CRED:
  5142. status = decode_op_map(xdr, &res->state_protect.enforce);
  5143. if (status)
  5144. return status;
  5145. status = decode_op_map(xdr, &res->state_protect.allow);
  5146. if (status)
  5147. return status;
  5148. break;
  5149. default:
  5150. WARN_ON_ONCE(1);
  5151. return -EIO;
  5152. }
  5153. /* server_owner4.so_minor_id */
  5154. p = xdr_inline_decode(xdr, 8);
  5155. if (unlikely(!p))
  5156. return -EIO;
  5157. p = xdr_decode_hyper(p, &res->server_owner->minor_id);
  5158. /* server_owner4.so_major_id */
  5159. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  5160. if (unlikely(status))
  5161. return status;
  5162. memcpy(res->server_owner->major_id, dummy_str, dummy);
  5163. res->server_owner->major_id_sz = dummy;
  5164. /* server_scope4 */
  5165. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  5166. if (unlikely(status))
  5167. return status;
  5168. memcpy(res->server_scope->server_scope, dummy_str, dummy);
  5169. res->server_scope->server_scope_sz = dummy;
  5170. /* Implementation Id */
  5171. p = xdr_inline_decode(xdr, 4);
  5172. if (unlikely(!p))
  5173. return -EIO;
  5174. impl_id_count = be32_to_cpup(p++);
  5175. if (impl_id_count) {
  5176. /* nii_domain */
  5177. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  5178. if (unlikely(status))
  5179. return status;
  5180. memcpy(res->impl_id->domain, dummy_str, dummy);
  5181. /* nii_name */
  5182. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  5183. if (unlikely(status))
  5184. return status;
  5185. memcpy(res->impl_id->name, dummy_str, dummy);
  5186. /* nii_date */
  5187. p = xdr_inline_decode(xdr, 12);
  5188. if (unlikely(!p))
  5189. return -EIO;
  5190. p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
  5191. res->impl_id->date.nseconds = be32_to_cpup(p);
  5192. /* if there's more than one entry, ignore the rest */
  5193. }
  5194. return 0;
  5195. }
  5196. static int decode_chan_attrs(struct xdr_stream *xdr,
  5197. struct nfs4_channel_attrs *attrs)
  5198. {
  5199. __be32 *p;
  5200. u32 nr_attrs, val;
  5201. p = xdr_inline_decode(xdr, 28);
  5202. if (unlikely(!p))
  5203. return -EIO;
  5204. val = be32_to_cpup(p++); /* headerpadsz */
  5205. if (val)
  5206. return -EINVAL; /* no support for header padding yet */
  5207. attrs->max_rqst_sz = be32_to_cpup(p++);
  5208. attrs->max_resp_sz = be32_to_cpup(p++);
  5209. attrs->max_resp_sz_cached = be32_to_cpup(p++);
  5210. attrs->max_ops = be32_to_cpup(p++);
  5211. attrs->max_reqs = be32_to_cpup(p++);
  5212. nr_attrs = be32_to_cpup(p);
  5213. if (unlikely(nr_attrs > 1)) {
  5214. printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
  5215. "count %u\n", __func__, nr_attrs);
  5216. return -EINVAL;
  5217. }
  5218. if (nr_attrs == 1) {
  5219. p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
  5220. if (unlikely(!p))
  5221. return -EIO;
  5222. }
  5223. return 0;
  5224. }
  5225. static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
  5226. {
  5227. return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
  5228. }
  5229. static int decode_bind_conn_to_session(struct xdr_stream *xdr,
  5230. struct nfs41_bind_conn_to_session_res *res)
  5231. {
  5232. __be32 *p;
  5233. int status;
  5234. status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
  5235. if (!status)
  5236. status = decode_sessionid(xdr, &res->sessionid);
  5237. if (unlikely(status))
  5238. return status;
  5239. /* dir flags, rdma mode bool */
  5240. p = xdr_inline_decode(xdr, 8);
  5241. if (unlikely(!p))
  5242. return -EIO;
  5243. res->dir = be32_to_cpup(p++);
  5244. if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
  5245. return -EIO;
  5246. if (be32_to_cpup(p) == 0)
  5247. res->use_conn_in_rdma_mode = false;
  5248. else
  5249. res->use_conn_in_rdma_mode = true;
  5250. return 0;
  5251. }
  5252. static int decode_create_session(struct xdr_stream *xdr,
  5253. struct nfs41_create_session_res *res)
  5254. {
  5255. __be32 *p;
  5256. int status;
  5257. status = decode_op_hdr(xdr, OP_CREATE_SESSION);
  5258. if (!status)
  5259. status = decode_sessionid(xdr, &res->sessionid);
  5260. if (unlikely(status))
  5261. return status;
  5262. /* seqid, flags */
  5263. p = xdr_inline_decode(xdr, 8);
  5264. if (unlikely(!p))
  5265. return -EIO;
  5266. res->seqid = be32_to_cpup(p++);
  5267. res->flags = be32_to_cpup(p);
  5268. /* Channel attributes */
  5269. status = decode_chan_attrs(xdr, &res->fc_attrs);
  5270. if (!status)
  5271. status = decode_chan_attrs(xdr, &res->bc_attrs);
  5272. return status;
  5273. }
  5274. static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
  5275. {
  5276. return decode_op_hdr(xdr, OP_DESTROY_SESSION);
  5277. }
  5278. static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
  5279. {
  5280. return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
  5281. }
  5282. static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
  5283. {
  5284. return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
  5285. }
  5286. #endif /* CONFIG_NFS_V4_1 */
  5287. static int decode_sequence(struct xdr_stream *xdr,
  5288. struct nfs4_sequence_res *res,
  5289. struct rpc_rqst *rqstp)
  5290. {
  5291. #if defined(CONFIG_NFS_V4_1)
  5292. struct nfs4_session *session;
  5293. struct nfs4_sessionid id;
  5294. u32 dummy;
  5295. int status;
  5296. __be32 *p;
  5297. if (res->sr_slot == NULL)
  5298. return 0;
  5299. if (!res->sr_slot->table->session)
  5300. return 0;
  5301. status = decode_op_hdr(xdr, OP_SEQUENCE);
  5302. if (!status)
  5303. status = decode_sessionid(xdr, &id);
  5304. if (unlikely(status))
  5305. goto out_err;
  5306. /*
  5307. * If the server returns different values for sessionID, slotID or
  5308. * sequence number, the server is looney tunes.
  5309. */
  5310. status = -EREMOTEIO;
  5311. session = res->sr_slot->table->session;
  5312. if (memcmp(id.data, session->sess_id.data,
  5313. NFS4_MAX_SESSIONID_LEN)) {
  5314. dprintk("%s Invalid session id\n", __func__);
  5315. goto out_err;
  5316. }
  5317. p = xdr_inline_decode(xdr, 20);
  5318. if (unlikely(!p))
  5319. goto out_overflow;
  5320. /* seqid */
  5321. dummy = be32_to_cpup(p++);
  5322. if (dummy != res->sr_slot->seq_nr) {
  5323. dprintk("%s Invalid sequence number\n", __func__);
  5324. goto out_err;
  5325. }
  5326. /* slot id */
  5327. dummy = be32_to_cpup(p++);
  5328. if (dummy != res->sr_slot->slot_nr) {
  5329. dprintk("%s Invalid slot id\n", __func__);
  5330. goto out_err;
  5331. }
  5332. /* highest slot id */
  5333. res->sr_highest_slotid = be32_to_cpup(p++);
  5334. /* target highest slot id */
  5335. res->sr_target_highest_slotid = be32_to_cpup(p++);
  5336. /* result flags */
  5337. res->sr_status_flags = be32_to_cpup(p);
  5338. status = 0;
  5339. out_err:
  5340. res->sr_status = status;
  5341. return status;
  5342. out_overflow:
  5343. status = -EIO;
  5344. goto out_err;
  5345. #else /* CONFIG_NFS_V4_1 */
  5346. return 0;
  5347. #endif /* CONFIG_NFS_V4_1 */
  5348. }
  5349. #if defined(CONFIG_NFS_V4_1)
  5350. static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  5351. {
  5352. stateid->type = NFS4_LAYOUT_STATEID_TYPE;
  5353. return decode_stateid(xdr, stateid);
  5354. }
  5355. static int decode_getdeviceinfo(struct xdr_stream *xdr,
  5356. struct nfs4_getdeviceinfo_res *res)
  5357. {
  5358. struct pnfs_device *pdev = res->pdev;
  5359. __be32 *p;
  5360. uint32_t len, type;
  5361. int status;
  5362. status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
  5363. if (status) {
  5364. if (status == -ETOOSMALL) {
  5365. p = xdr_inline_decode(xdr, 4);
  5366. if (unlikely(!p))
  5367. return -EIO;
  5368. pdev->mincount = be32_to_cpup(p);
  5369. dprintk("%s: Min count too small. mincnt = %u\n",
  5370. __func__, pdev->mincount);
  5371. }
  5372. return status;
  5373. }
  5374. p = xdr_inline_decode(xdr, 8);
  5375. if (unlikely(!p))
  5376. return -EIO;
  5377. type = be32_to_cpup(p++);
  5378. if (type != pdev->layout_type) {
  5379. dprintk("%s: layout mismatch req: %u pdev: %u\n",
  5380. __func__, pdev->layout_type, type);
  5381. return -EINVAL;
  5382. }
  5383. /*
  5384. * Get the length of the opaque device_addr4. xdr_read_pages places
  5385. * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
  5386. * and places the remaining xdr data in xdr_buf->tail
  5387. */
  5388. pdev->mincount = be32_to_cpup(p);
  5389. if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
  5390. return -EIO;
  5391. /* Parse notification bitmap, verifying that it is zero. */
  5392. p = xdr_inline_decode(xdr, 4);
  5393. if (unlikely(!p))
  5394. return -EIO;
  5395. len = be32_to_cpup(p);
  5396. if (len) {
  5397. uint32_t i;
  5398. p = xdr_inline_decode(xdr, 4 * len);
  5399. if (unlikely(!p))
  5400. return -EIO;
  5401. res->notification = be32_to_cpup(p++);
  5402. for (i = 1; i < len; i++) {
  5403. if (be32_to_cpup(p++)) {
  5404. dprintk("%s: unsupported notification\n",
  5405. __func__);
  5406. return -EIO;
  5407. }
  5408. }
  5409. }
  5410. return 0;
  5411. }
  5412. static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
  5413. struct nfs4_layoutget_res *res)
  5414. {
  5415. __be32 *p;
  5416. int status;
  5417. u32 layout_count;
  5418. u32 recvd;
  5419. status = decode_op_hdr(xdr, OP_LAYOUTGET);
  5420. if (status)
  5421. goto out;
  5422. p = xdr_inline_decode(xdr, 4);
  5423. if (unlikely(!p))
  5424. goto out_overflow;
  5425. res->return_on_close = be32_to_cpup(p);
  5426. decode_layout_stateid(xdr, &res->stateid);
  5427. p = xdr_inline_decode(xdr, 4);
  5428. if (unlikely(!p))
  5429. goto out_overflow;
  5430. layout_count = be32_to_cpup(p);
  5431. if (!layout_count) {
  5432. dprintk("%s: server responded with empty layout array\n",
  5433. __func__);
  5434. status = -EINVAL;
  5435. goto out;
  5436. }
  5437. p = xdr_inline_decode(xdr, 28);
  5438. if (unlikely(!p))
  5439. goto out_overflow;
  5440. p = xdr_decode_hyper(p, &res->range.offset);
  5441. p = xdr_decode_hyper(p, &res->range.length);
  5442. res->range.iomode = be32_to_cpup(p++);
  5443. res->type = be32_to_cpup(p++);
  5444. res->layoutp->len = be32_to_cpup(p);
  5445. dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
  5446. __func__,
  5447. (unsigned long)res->range.offset,
  5448. (unsigned long)res->range.length,
  5449. res->range.iomode,
  5450. res->type,
  5451. res->layoutp->len);
  5452. recvd = xdr_read_pages(xdr, res->layoutp->len);
  5453. if (res->layoutp->len > recvd) {
  5454. dprintk("NFS: server cheating in layoutget reply: "
  5455. "layout len %u > recvd %u\n",
  5456. res->layoutp->len, recvd);
  5457. status = -EINVAL;
  5458. goto out;
  5459. }
  5460. if (layout_count > 1) {
  5461. /* We only handle a length one array at the moment. Any
  5462. * further entries are just ignored. Note that this means
  5463. * the client may see a response that is less than the
  5464. * minimum it requested.
  5465. */
  5466. dprintk("%s: server responded with %d layouts, dropping tail\n",
  5467. __func__, layout_count);
  5468. }
  5469. out:
  5470. res->status = status;
  5471. return status;
  5472. out_overflow:
  5473. status = -EIO;
  5474. goto out;
  5475. }
  5476. static int decode_layoutreturn(struct xdr_stream *xdr,
  5477. struct nfs4_layoutreturn_res *res)
  5478. {
  5479. __be32 *p;
  5480. int status;
  5481. status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
  5482. if (status)
  5483. return status;
  5484. p = xdr_inline_decode(xdr, 4);
  5485. if (unlikely(!p))
  5486. return -EIO;
  5487. res->lrs_present = be32_to_cpup(p);
  5488. if (res->lrs_present)
  5489. status = decode_layout_stateid(xdr, &res->stateid);
  5490. else
  5491. nfs4_stateid_copy(&res->stateid, &invalid_stateid);
  5492. return status;
  5493. }
  5494. static int decode_layoutcommit(struct xdr_stream *xdr,
  5495. struct rpc_rqst *req,
  5496. struct nfs4_layoutcommit_res *res)
  5497. {
  5498. __be32 *p;
  5499. __u32 sizechanged;
  5500. int status;
  5501. status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
  5502. res->status = status;
  5503. if (status)
  5504. return status;
  5505. p = xdr_inline_decode(xdr, 4);
  5506. if (unlikely(!p))
  5507. return -EIO;
  5508. sizechanged = be32_to_cpup(p);
  5509. if (sizechanged) {
  5510. /* throw away new size */
  5511. p = xdr_inline_decode(xdr, 8);
  5512. if (unlikely(!p))
  5513. return -EIO;
  5514. }
  5515. return 0;
  5516. }
  5517. static int decode_test_stateid(struct xdr_stream *xdr,
  5518. struct nfs41_test_stateid_res *res)
  5519. {
  5520. __be32 *p;
  5521. int status;
  5522. int num_res;
  5523. status = decode_op_hdr(xdr, OP_TEST_STATEID);
  5524. if (status)
  5525. return status;
  5526. p = xdr_inline_decode(xdr, 4);
  5527. if (unlikely(!p))
  5528. return -EIO;
  5529. num_res = be32_to_cpup(p++);
  5530. if (num_res != 1)
  5531. return -EIO;
  5532. p = xdr_inline_decode(xdr, 4);
  5533. if (unlikely(!p))
  5534. return -EIO;
  5535. res->status = be32_to_cpup(p++);
  5536. return status;
  5537. }
  5538. static int decode_free_stateid(struct xdr_stream *xdr,
  5539. struct nfs41_free_stateid_res *res)
  5540. {
  5541. res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
  5542. return res->status;
  5543. }
  5544. #else
  5545. static inline
  5546. int decode_layoutreturn(struct xdr_stream *xdr,
  5547. struct nfs4_layoutreturn_res *res)
  5548. {
  5549. return 0;
  5550. }
  5551. static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
  5552. struct nfs4_layoutget_res *res)
  5553. {
  5554. return 0;
  5555. }
  5556. #endif /* CONFIG_NFS_V4_1 */
  5557. /*
  5558. * END OF "GENERIC" DECODE ROUTINES.
  5559. */
  5560. /*
  5561. * Decode OPEN_DOWNGRADE response
  5562. */
  5563. static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
  5564. struct xdr_stream *xdr,
  5565. void *data)
  5566. {
  5567. struct nfs_closeres *res = data;
  5568. struct compound_hdr hdr;
  5569. int status;
  5570. status = decode_compound_hdr(xdr, &hdr);
  5571. if (status)
  5572. goto out;
  5573. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5574. if (status)
  5575. goto out;
  5576. status = decode_putfh(xdr);
  5577. if (status)
  5578. goto out;
  5579. if (res->lr_res) {
  5580. status = decode_layoutreturn(xdr, res->lr_res);
  5581. res->lr_ret = status;
  5582. if (status)
  5583. goto out;
  5584. }
  5585. status = decode_open_downgrade(xdr, res);
  5586. out:
  5587. return status;
  5588. }
  5589. /*
  5590. * Decode ACCESS response
  5591. */
  5592. static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5593. void *data)
  5594. {
  5595. struct nfs4_accessres *res = data;
  5596. struct compound_hdr hdr;
  5597. int status;
  5598. status = decode_compound_hdr(xdr, &hdr);
  5599. if (status)
  5600. goto out;
  5601. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5602. if (status)
  5603. goto out;
  5604. status = decode_putfh(xdr);
  5605. if (status != 0)
  5606. goto out;
  5607. status = decode_access(xdr, &res->supported, &res->access);
  5608. if (status != 0)
  5609. goto out;
  5610. if (res->fattr)
  5611. decode_getfattr(xdr, res->fattr, res->server);
  5612. out:
  5613. return status;
  5614. }
  5615. /*
  5616. * Decode LOOKUP response
  5617. */
  5618. static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5619. void *data)
  5620. {
  5621. struct nfs4_lookup_res *res = data;
  5622. struct compound_hdr hdr;
  5623. int status;
  5624. status = decode_compound_hdr(xdr, &hdr);
  5625. if (status)
  5626. goto out;
  5627. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5628. if (status)
  5629. goto out;
  5630. status = decode_putfh(xdr);
  5631. if (status)
  5632. goto out;
  5633. status = decode_lookup(xdr);
  5634. if (status)
  5635. goto out;
  5636. status = decode_getfh(xdr, res->fh);
  5637. if (status)
  5638. goto out;
  5639. status = decode_getfattr(xdr, res->fattr, res->server);
  5640. out:
  5641. return status;
  5642. }
  5643. /*
  5644. * Decode LOOKUPP response
  5645. */
  5646. static int nfs4_xdr_dec_lookupp(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5647. void *data)
  5648. {
  5649. struct nfs4_lookupp_res *res = data;
  5650. struct compound_hdr hdr;
  5651. int status;
  5652. status = decode_compound_hdr(xdr, &hdr);
  5653. if (status)
  5654. goto out;
  5655. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5656. if (status)
  5657. goto out;
  5658. status = decode_putfh(xdr);
  5659. if (status)
  5660. goto out;
  5661. status = decode_lookupp(xdr);
  5662. if (status)
  5663. goto out;
  5664. status = decode_getfh(xdr, res->fh);
  5665. if (status)
  5666. goto out;
  5667. status = decode_getfattr(xdr, res->fattr, res->server);
  5668. out:
  5669. return status;
  5670. }
  5671. /*
  5672. * Decode LOOKUP_ROOT response
  5673. */
  5674. static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
  5675. struct xdr_stream *xdr,
  5676. void *data)
  5677. {
  5678. struct nfs4_lookup_res *res = data;
  5679. struct compound_hdr hdr;
  5680. int status;
  5681. status = decode_compound_hdr(xdr, &hdr);
  5682. if (status)
  5683. goto out;
  5684. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5685. if (status)
  5686. goto out;
  5687. status = decode_putrootfh(xdr);
  5688. if (status)
  5689. goto out;
  5690. status = decode_getfh(xdr, res->fh);
  5691. if (status == 0)
  5692. status = decode_getfattr(xdr, res->fattr, res->server);
  5693. out:
  5694. return status;
  5695. }
  5696. /*
  5697. * Decode REMOVE response
  5698. */
  5699. static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5700. void *data)
  5701. {
  5702. struct nfs_removeres *res = data;
  5703. struct compound_hdr hdr;
  5704. int status;
  5705. status = decode_compound_hdr(xdr, &hdr);
  5706. if (status)
  5707. goto out;
  5708. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5709. if (status)
  5710. goto out;
  5711. status = decode_putfh(xdr);
  5712. if (status)
  5713. goto out;
  5714. status = decode_remove(xdr, &res->cinfo);
  5715. out:
  5716. return status;
  5717. }
  5718. /*
  5719. * Decode RENAME response
  5720. */
  5721. static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5722. void *data)
  5723. {
  5724. struct nfs_renameres *res = data;
  5725. struct compound_hdr hdr;
  5726. int status;
  5727. status = decode_compound_hdr(xdr, &hdr);
  5728. if (status)
  5729. goto out;
  5730. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5731. if (status)
  5732. goto out;
  5733. status = decode_putfh(xdr);
  5734. if (status)
  5735. goto out;
  5736. status = decode_savefh(xdr);
  5737. if (status)
  5738. goto out;
  5739. status = decode_putfh(xdr);
  5740. if (status)
  5741. goto out;
  5742. status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
  5743. out:
  5744. return status;
  5745. }
  5746. /*
  5747. * Decode LINK response
  5748. */
  5749. static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5750. void *data)
  5751. {
  5752. struct nfs4_link_res *res = data;
  5753. struct compound_hdr hdr;
  5754. int status;
  5755. status = decode_compound_hdr(xdr, &hdr);
  5756. if (status)
  5757. goto out;
  5758. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5759. if (status)
  5760. goto out;
  5761. status = decode_putfh(xdr);
  5762. if (status)
  5763. goto out;
  5764. status = decode_savefh(xdr);
  5765. if (status)
  5766. goto out;
  5767. status = decode_putfh(xdr);
  5768. if (status)
  5769. goto out;
  5770. status = decode_link(xdr, &res->cinfo);
  5771. if (status)
  5772. goto out;
  5773. /*
  5774. * Note order: OP_LINK leaves the directory as the current
  5775. * filehandle.
  5776. */
  5777. status = decode_restorefh(xdr);
  5778. if (status)
  5779. goto out;
  5780. decode_getfattr(xdr, res->fattr, res->server);
  5781. out:
  5782. return status;
  5783. }
  5784. /*
  5785. * Decode CREATE response
  5786. */
  5787. static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5788. void *data)
  5789. {
  5790. struct nfs4_create_res *res = data;
  5791. struct compound_hdr hdr;
  5792. int status;
  5793. status = decode_compound_hdr(xdr, &hdr);
  5794. if (status)
  5795. goto out;
  5796. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5797. if (status)
  5798. goto out;
  5799. status = decode_putfh(xdr);
  5800. if (status)
  5801. goto out;
  5802. status = decode_create(xdr, &res->dir_cinfo);
  5803. if (status)
  5804. goto out;
  5805. status = decode_getfh(xdr, res->fh);
  5806. if (status)
  5807. goto out;
  5808. decode_getfattr(xdr, res->fattr, res->server);
  5809. out:
  5810. return status;
  5811. }
  5812. /*
  5813. * Decode SYMLINK response
  5814. */
  5815. static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5816. void *res)
  5817. {
  5818. return nfs4_xdr_dec_create(rqstp, xdr, res);
  5819. }
  5820. /*
  5821. * Decode GETATTR response
  5822. */
  5823. static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5824. void *data)
  5825. {
  5826. struct nfs4_getattr_res *res = data;
  5827. struct compound_hdr hdr;
  5828. int status;
  5829. status = decode_compound_hdr(xdr, &hdr);
  5830. if (status)
  5831. goto out;
  5832. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5833. if (status)
  5834. goto out;
  5835. status = decode_putfh(xdr);
  5836. if (status)
  5837. goto out;
  5838. status = decode_getfattr(xdr, res->fattr, res->server);
  5839. out:
  5840. return status;
  5841. }
  5842. /*
  5843. * Encode an SETACL request
  5844. */
  5845. static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
  5846. const void *data)
  5847. {
  5848. const struct nfs_setaclargs *args = data;
  5849. struct compound_hdr hdr = {
  5850. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  5851. };
  5852. encode_compound_hdr(xdr, req, &hdr);
  5853. encode_sequence(xdr, &args->seq_args, &hdr);
  5854. encode_putfh(xdr, args->fh, &hdr);
  5855. encode_setacl(xdr, args, &hdr);
  5856. encode_nops(&hdr);
  5857. }
  5858. /*
  5859. * Decode SETACL response
  5860. */
  5861. static int
  5862. nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5863. void *data)
  5864. {
  5865. struct nfs_setaclres *res = data;
  5866. struct compound_hdr hdr;
  5867. int status;
  5868. status = decode_compound_hdr(xdr, &hdr);
  5869. if (status)
  5870. goto out;
  5871. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5872. if (status)
  5873. goto out;
  5874. status = decode_putfh(xdr);
  5875. if (status)
  5876. goto out;
  5877. status = decode_setattr(xdr);
  5878. out:
  5879. return status;
  5880. }
  5881. /*
  5882. * Decode GETACL response
  5883. */
  5884. static int
  5885. nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5886. void *data)
  5887. {
  5888. struct nfs_getaclres *res = data;
  5889. struct compound_hdr hdr;
  5890. int status;
  5891. if (res->acl_scratch != NULL)
  5892. xdr_set_scratch_page(xdr, res->acl_scratch);
  5893. status = decode_compound_hdr(xdr, &hdr);
  5894. if (status)
  5895. goto out;
  5896. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5897. if (status)
  5898. goto out;
  5899. status = decode_putfh(xdr);
  5900. if (status)
  5901. goto out;
  5902. status = decode_getacl(xdr, rqstp, res, res->acl_type);
  5903. out:
  5904. return status;
  5905. }
  5906. /*
  5907. * Decode CLOSE response
  5908. */
  5909. static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5910. void *data)
  5911. {
  5912. struct nfs_closeres *res = data;
  5913. struct compound_hdr hdr;
  5914. int status;
  5915. status = decode_compound_hdr(xdr, &hdr);
  5916. if (status)
  5917. goto out;
  5918. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5919. if (status)
  5920. goto out;
  5921. status = decode_putfh(xdr);
  5922. if (status)
  5923. goto out;
  5924. if (res->lr_res) {
  5925. status = decode_layoutreturn(xdr, res->lr_res);
  5926. res->lr_ret = status;
  5927. if (status)
  5928. goto out;
  5929. }
  5930. if (res->fattr != NULL) {
  5931. status = decode_getfattr(xdr, res->fattr, res->server);
  5932. if (status != 0)
  5933. goto out;
  5934. }
  5935. status = decode_close(xdr, res);
  5936. out:
  5937. return status;
  5938. }
  5939. /*
  5940. * Decode OPEN response
  5941. */
  5942. static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5943. void *data)
  5944. {
  5945. struct nfs_openres *res = data;
  5946. struct compound_hdr hdr;
  5947. int status;
  5948. status = decode_compound_hdr(xdr, &hdr);
  5949. if (status)
  5950. goto out;
  5951. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5952. if (status)
  5953. goto out;
  5954. status = decode_putfh(xdr);
  5955. if (status)
  5956. goto out;
  5957. status = decode_open(xdr, res);
  5958. if (status)
  5959. goto out;
  5960. status = decode_getfh(xdr, &res->fh);
  5961. if (status)
  5962. goto out;
  5963. if (res->access_request)
  5964. decode_access(xdr, &res->access_supported, &res->access_result);
  5965. decode_getfattr(xdr, res->f_attr, res->server);
  5966. if (res->lg_res)
  5967. decode_layoutget(xdr, rqstp, res->lg_res);
  5968. out:
  5969. return status;
  5970. }
  5971. /*
  5972. * Decode OPEN_CONFIRM response
  5973. */
  5974. static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
  5975. struct xdr_stream *xdr,
  5976. void *data)
  5977. {
  5978. struct nfs_open_confirmres *res = data;
  5979. struct compound_hdr hdr;
  5980. int status;
  5981. status = decode_compound_hdr(xdr, &hdr);
  5982. if (status)
  5983. goto out;
  5984. status = decode_putfh(xdr);
  5985. if (status)
  5986. goto out;
  5987. status = decode_open_confirm(xdr, res);
  5988. out:
  5989. return status;
  5990. }
  5991. /*
  5992. * Decode OPEN response
  5993. */
  5994. static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
  5995. struct xdr_stream *xdr,
  5996. void *data)
  5997. {
  5998. struct nfs_openres *res = data;
  5999. struct compound_hdr hdr;
  6000. int status;
  6001. status = decode_compound_hdr(xdr, &hdr);
  6002. if (status)
  6003. goto out;
  6004. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6005. if (status)
  6006. goto out;
  6007. status = decode_putfh(xdr);
  6008. if (status)
  6009. goto out;
  6010. status = decode_open(xdr, res);
  6011. if (status)
  6012. goto out;
  6013. if (res->access_request)
  6014. decode_access(xdr, &res->access_supported, &res->access_result);
  6015. decode_getfattr(xdr, res->f_attr, res->server);
  6016. if (res->lg_res)
  6017. decode_layoutget(xdr, rqstp, res->lg_res);
  6018. out:
  6019. return status;
  6020. }
  6021. /*
  6022. * Decode SETATTR response
  6023. */
  6024. static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
  6025. struct xdr_stream *xdr,
  6026. void *data)
  6027. {
  6028. struct nfs_setattrres *res = data;
  6029. struct compound_hdr hdr;
  6030. int status;
  6031. status = decode_compound_hdr(xdr, &hdr);
  6032. if (status)
  6033. goto out;
  6034. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6035. if (status)
  6036. goto out;
  6037. status = decode_putfh(xdr);
  6038. if (status)
  6039. goto out;
  6040. status = decode_setattr(xdr);
  6041. if (status)
  6042. goto out;
  6043. decode_getfattr(xdr, res->fattr, res->server);
  6044. out:
  6045. return status;
  6046. }
  6047. /*
  6048. * Decode LOCK response
  6049. */
  6050. static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6051. void *data)
  6052. {
  6053. struct nfs_lock_res *res = data;
  6054. struct compound_hdr hdr;
  6055. int status;
  6056. status = decode_compound_hdr(xdr, &hdr);
  6057. if (status)
  6058. goto out;
  6059. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6060. if (status)
  6061. goto out;
  6062. status = decode_putfh(xdr);
  6063. if (status)
  6064. goto out;
  6065. status = decode_lock(xdr, res);
  6066. out:
  6067. return status;
  6068. }
  6069. /*
  6070. * Decode LOCKT response
  6071. */
  6072. static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6073. void *data)
  6074. {
  6075. struct nfs_lockt_res *res = data;
  6076. struct compound_hdr hdr;
  6077. int status;
  6078. status = decode_compound_hdr(xdr, &hdr);
  6079. if (status)
  6080. goto out;
  6081. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6082. if (status)
  6083. goto out;
  6084. status = decode_putfh(xdr);
  6085. if (status)
  6086. goto out;
  6087. status = decode_lockt(xdr, res);
  6088. out:
  6089. return status;
  6090. }
  6091. /*
  6092. * Decode LOCKU response
  6093. */
  6094. static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6095. void *data)
  6096. {
  6097. struct nfs_locku_res *res = data;
  6098. struct compound_hdr hdr;
  6099. int status;
  6100. status = decode_compound_hdr(xdr, &hdr);
  6101. if (status)
  6102. goto out;
  6103. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6104. if (status)
  6105. goto out;
  6106. status = decode_putfh(xdr);
  6107. if (status)
  6108. goto out;
  6109. status = decode_locku(xdr, res);
  6110. out:
  6111. return status;
  6112. }
  6113. static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
  6114. struct xdr_stream *xdr, void *dummy)
  6115. {
  6116. struct compound_hdr hdr;
  6117. int status;
  6118. status = decode_compound_hdr(xdr, &hdr);
  6119. if (!status)
  6120. status = decode_release_lockowner(xdr);
  6121. return status;
  6122. }
  6123. /*
  6124. * Decode READLINK response
  6125. */
  6126. static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
  6127. struct xdr_stream *xdr,
  6128. void *data)
  6129. {
  6130. struct nfs4_readlink_res *res = data;
  6131. struct compound_hdr hdr;
  6132. int status;
  6133. status = decode_compound_hdr(xdr, &hdr);
  6134. if (status)
  6135. goto out;
  6136. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6137. if (status)
  6138. goto out;
  6139. status = decode_putfh(xdr);
  6140. if (status)
  6141. goto out;
  6142. status = decode_readlink(xdr, rqstp);
  6143. out:
  6144. return status;
  6145. }
  6146. /*
  6147. * Decode READDIR response
  6148. */
  6149. static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6150. void *data)
  6151. {
  6152. struct nfs4_readdir_res *res = data;
  6153. struct compound_hdr hdr;
  6154. int status;
  6155. status = decode_compound_hdr(xdr, &hdr);
  6156. if (status)
  6157. goto out;
  6158. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6159. if (status)
  6160. goto out;
  6161. status = decode_putfh(xdr);
  6162. if (status)
  6163. goto out;
  6164. status = decode_readdir(xdr, rqstp, res);
  6165. out:
  6166. return status;
  6167. }
  6168. /*
  6169. * Decode Read response
  6170. */
  6171. static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6172. void *data)
  6173. {
  6174. struct nfs_pgio_res *res = data;
  6175. struct compound_hdr hdr;
  6176. int status;
  6177. status = decode_compound_hdr(xdr, &hdr);
  6178. res->op_status = hdr.status;
  6179. if (status)
  6180. goto out;
  6181. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6182. if (status)
  6183. goto out;
  6184. status = decode_putfh(xdr);
  6185. if (status)
  6186. goto out;
  6187. status = decode_read(xdr, rqstp, res);
  6188. if (!status)
  6189. status = res->count;
  6190. out:
  6191. return status;
  6192. }
  6193. /*
  6194. * Decode WRITE response
  6195. */
  6196. static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6197. void *data)
  6198. {
  6199. struct nfs_pgio_res *res = data;
  6200. struct compound_hdr hdr;
  6201. int status;
  6202. status = decode_compound_hdr(xdr, &hdr);
  6203. res->op_status = hdr.status;
  6204. if (status)
  6205. goto out;
  6206. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6207. if (status)
  6208. goto out;
  6209. status = decode_putfh(xdr);
  6210. if (status)
  6211. goto out;
  6212. status = decode_write(xdr, res);
  6213. if (status)
  6214. goto out;
  6215. if (res->fattr)
  6216. decode_getfattr(xdr, res->fattr, res->server);
  6217. if (!status)
  6218. status = res->count;
  6219. out:
  6220. return status;
  6221. }
  6222. /*
  6223. * Decode COMMIT response
  6224. */
  6225. static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6226. void *data)
  6227. {
  6228. struct nfs_commitres *res = data;
  6229. struct compound_hdr hdr;
  6230. int status;
  6231. status = decode_compound_hdr(xdr, &hdr);
  6232. res->op_status = hdr.status;
  6233. if (status)
  6234. goto out;
  6235. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6236. if (status)
  6237. goto out;
  6238. status = decode_putfh(xdr);
  6239. if (status)
  6240. goto out;
  6241. status = decode_commit(xdr, res);
  6242. out:
  6243. return status;
  6244. }
  6245. /*
  6246. * Decode FSINFO response
  6247. */
  6248. static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
  6249. void *data)
  6250. {
  6251. struct nfs4_fsinfo_res *res = data;
  6252. struct compound_hdr hdr;
  6253. int status;
  6254. status = decode_compound_hdr(xdr, &hdr);
  6255. if (!status)
  6256. status = decode_sequence(xdr, &res->seq_res, req);
  6257. if (!status)
  6258. status = decode_putfh(xdr);
  6259. if (!status)
  6260. status = decode_fsinfo(xdr, res->fsinfo);
  6261. return status;
  6262. }
  6263. /*
  6264. * Decode PATHCONF response
  6265. */
  6266. static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
  6267. void *data)
  6268. {
  6269. struct nfs4_pathconf_res *res = data;
  6270. struct compound_hdr hdr;
  6271. int status;
  6272. status = decode_compound_hdr(xdr, &hdr);
  6273. if (!status)
  6274. status = decode_sequence(xdr, &res->seq_res, req);
  6275. if (!status)
  6276. status = decode_putfh(xdr);
  6277. if (!status)
  6278. status = decode_pathconf(xdr, res->pathconf);
  6279. return status;
  6280. }
  6281. /*
  6282. * Decode STATFS response
  6283. */
  6284. static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
  6285. void *data)
  6286. {
  6287. struct nfs4_statfs_res *res = data;
  6288. struct compound_hdr hdr;
  6289. int status;
  6290. status = decode_compound_hdr(xdr, &hdr);
  6291. if (!status)
  6292. status = decode_sequence(xdr, &res->seq_res, req);
  6293. if (!status)
  6294. status = decode_putfh(xdr);
  6295. if (!status)
  6296. status = decode_statfs(xdr, res->fsstat);
  6297. return status;
  6298. }
  6299. /*
  6300. * Decode GETATTR_BITMAP response
  6301. */
  6302. static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
  6303. struct xdr_stream *xdr,
  6304. void *data)
  6305. {
  6306. struct nfs4_server_caps_res *res = data;
  6307. struct compound_hdr hdr;
  6308. int status;
  6309. status = decode_compound_hdr(xdr, &hdr);
  6310. if (status)
  6311. goto out;
  6312. status = decode_sequence(xdr, &res->seq_res, req);
  6313. if (status)
  6314. goto out;
  6315. status = decode_putfh(xdr);
  6316. if (status)
  6317. goto out;
  6318. status = decode_server_caps(xdr, res);
  6319. out:
  6320. return status;
  6321. }
  6322. /*
  6323. * Decode RENEW response
  6324. */
  6325. static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6326. void *__unused)
  6327. {
  6328. struct compound_hdr hdr;
  6329. int status;
  6330. status = decode_compound_hdr(xdr, &hdr);
  6331. if (!status)
  6332. status = decode_renew(xdr);
  6333. return status;
  6334. }
  6335. /*
  6336. * Decode SETCLIENTID response
  6337. */
  6338. static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
  6339. struct xdr_stream *xdr,
  6340. void *data)
  6341. {
  6342. struct nfs4_setclientid_res *res = data;
  6343. struct compound_hdr hdr;
  6344. int status;
  6345. status = decode_compound_hdr(xdr, &hdr);
  6346. if (!status)
  6347. status = decode_setclientid(xdr, res);
  6348. return status;
  6349. }
  6350. /*
  6351. * Decode SETCLIENTID_CONFIRM response
  6352. */
  6353. static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
  6354. struct xdr_stream *xdr,
  6355. void *data)
  6356. {
  6357. struct compound_hdr hdr;
  6358. int status;
  6359. status = decode_compound_hdr(xdr, &hdr);
  6360. if (!status)
  6361. status = decode_setclientid_confirm(xdr);
  6362. return status;
  6363. }
  6364. /*
  6365. * Decode DELEGRETURN response
  6366. */
  6367. static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
  6368. struct xdr_stream *xdr,
  6369. void *data)
  6370. {
  6371. struct nfs4_delegreturnres *res = data;
  6372. struct compound_hdr hdr;
  6373. int status;
  6374. status = decode_compound_hdr(xdr, &hdr);
  6375. if (status)
  6376. goto out;
  6377. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6378. if (status)
  6379. goto out;
  6380. status = decode_putfh(xdr);
  6381. if (status != 0)
  6382. goto out;
  6383. if (res->lr_res) {
  6384. status = decode_layoutreturn(xdr, res->lr_res);
  6385. res->lr_ret = status;
  6386. if (status)
  6387. goto out;
  6388. }
  6389. if (res->sattr_res) {
  6390. status = decode_delegattr(xdr);
  6391. res->sattr_ret = status;
  6392. if (status)
  6393. goto out;
  6394. }
  6395. if (res->fattr) {
  6396. status = decode_getfattr(xdr, res->fattr, res->server);
  6397. if (status != 0)
  6398. goto out;
  6399. }
  6400. status = decode_delegreturn(xdr);
  6401. out:
  6402. return status;
  6403. }
  6404. /*
  6405. * Decode FS_LOCATIONS response
  6406. */
  6407. static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
  6408. struct xdr_stream *xdr,
  6409. void *data)
  6410. {
  6411. struct nfs4_fs_locations_res *res = data;
  6412. struct compound_hdr hdr;
  6413. int status;
  6414. status = decode_compound_hdr(xdr, &hdr);
  6415. if (status)
  6416. goto out;
  6417. status = decode_sequence(xdr, &res->seq_res, req);
  6418. if (status)
  6419. goto out;
  6420. status = decode_putfh(xdr);
  6421. if (status)
  6422. goto out;
  6423. if (res->migration) {
  6424. xdr_enter_page(xdr, PAGE_SIZE);
  6425. status = decode_getfattr_generic(xdr,
  6426. res->fs_locations->fattr,
  6427. NULL, res->fs_locations,
  6428. res->fs_locations->server);
  6429. if (status)
  6430. goto out;
  6431. if (res->renew)
  6432. status = decode_renew(xdr);
  6433. } else {
  6434. status = decode_lookup(xdr);
  6435. if (status)
  6436. goto out;
  6437. xdr_enter_page(xdr, PAGE_SIZE);
  6438. status = decode_getfattr_generic(xdr,
  6439. res->fs_locations->fattr,
  6440. NULL, res->fs_locations,
  6441. res->fs_locations->server);
  6442. }
  6443. out:
  6444. return status;
  6445. }
  6446. /*
  6447. * Decode SECINFO response
  6448. */
  6449. static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
  6450. struct xdr_stream *xdr,
  6451. void *data)
  6452. {
  6453. struct nfs4_secinfo_res *res = data;
  6454. struct compound_hdr hdr;
  6455. int status;
  6456. status = decode_compound_hdr(xdr, &hdr);
  6457. if (status)
  6458. goto out;
  6459. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6460. if (status)
  6461. goto out;
  6462. status = decode_putfh(xdr);
  6463. if (status)
  6464. goto out;
  6465. status = decode_secinfo(xdr, res);
  6466. out:
  6467. return status;
  6468. }
  6469. /*
  6470. * Decode FSID_PRESENT response
  6471. */
  6472. static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
  6473. struct xdr_stream *xdr,
  6474. void *data)
  6475. {
  6476. struct nfs4_fsid_present_res *res = data;
  6477. struct compound_hdr hdr;
  6478. int status;
  6479. status = decode_compound_hdr(xdr, &hdr);
  6480. if (status)
  6481. goto out;
  6482. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6483. if (status)
  6484. goto out;
  6485. status = decode_putfh(xdr);
  6486. if (status)
  6487. goto out;
  6488. status = decode_getfh(xdr, res->fh);
  6489. if (status)
  6490. goto out;
  6491. if (res->renew)
  6492. status = decode_renew(xdr);
  6493. out:
  6494. return status;
  6495. }
  6496. #if defined(CONFIG_NFS_V4_1)
  6497. /*
  6498. * Decode BIND_CONN_TO_SESSION response
  6499. */
  6500. static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
  6501. struct xdr_stream *xdr,
  6502. void *res)
  6503. {
  6504. struct compound_hdr hdr;
  6505. int status;
  6506. status = decode_compound_hdr(xdr, &hdr);
  6507. if (!status)
  6508. status = decode_bind_conn_to_session(xdr, res);
  6509. return status;
  6510. }
  6511. /*
  6512. * Decode EXCHANGE_ID response
  6513. */
  6514. static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
  6515. struct xdr_stream *xdr,
  6516. void *res)
  6517. {
  6518. struct compound_hdr hdr;
  6519. int status;
  6520. status = decode_compound_hdr(xdr, &hdr);
  6521. if (!status)
  6522. status = decode_exchange_id(xdr, res);
  6523. return status;
  6524. }
  6525. /*
  6526. * Decode CREATE_SESSION response
  6527. */
  6528. static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
  6529. struct xdr_stream *xdr,
  6530. void *res)
  6531. {
  6532. struct compound_hdr hdr;
  6533. int status;
  6534. status = decode_compound_hdr(xdr, &hdr);
  6535. if (!status)
  6536. status = decode_create_session(xdr, res);
  6537. return status;
  6538. }
  6539. /*
  6540. * Decode DESTROY_SESSION response
  6541. */
  6542. static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
  6543. struct xdr_stream *xdr,
  6544. void *res)
  6545. {
  6546. struct compound_hdr hdr;
  6547. int status;
  6548. status = decode_compound_hdr(xdr, &hdr);
  6549. if (!status)
  6550. status = decode_destroy_session(xdr, res);
  6551. return status;
  6552. }
  6553. /*
  6554. * Decode DESTROY_CLIENTID response
  6555. */
  6556. static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
  6557. struct xdr_stream *xdr,
  6558. void *res)
  6559. {
  6560. struct compound_hdr hdr;
  6561. int status;
  6562. status = decode_compound_hdr(xdr, &hdr);
  6563. if (!status)
  6564. status = decode_destroy_clientid(xdr, res);
  6565. return status;
  6566. }
  6567. /*
  6568. * Decode SEQUENCE response
  6569. */
  6570. static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
  6571. struct xdr_stream *xdr,
  6572. void *res)
  6573. {
  6574. struct compound_hdr hdr;
  6575. int status;
  6576. status = decode_compound_hdr(xdr, &hdr);
  6577. if (!status)
  6578. status = decode_sequence(xdr, res, rqstp);
  6579. return status;
  6580. }
  6581. #endif
  6582. /*
  6583. * Decode GET_LEASE_TIME response
  6584. */
  6585. static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
  6586. struct xdr_stream *xdr,
  6587. void *data)
  6588. {
  6589. struct nfs4_get_lease_time_res *res = data;
  6590. struct compound_hdr hdr;
  6591. int status;
  6592. status = decode_compound_hdr(xdr, &hdr);
  6593. if (!status)
  6594. status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
  6595. if (!status)
  6596. status = decode_putrootfh(xdr);
  6597. if (!status)
  6598. status = decode_fsinfo(xdr, res->lr_fsinfo);
  6599. return status;
  6600. }
  6601. #ifdef CONFIG_NFS_V4_1
  6602. /*
  6603. * Decode RECLAIM_COMPLETE response
  6604. */
  6605. static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
  6606. struct xdr_stream *xdr,
  6607. void *data)
  6608. {
  6609. struct nfs41_reclaim_complete_res *res = data;
  6610. struct compound_hdr hdr;
  6611. int status;
  6612. status = decode_compound_hdr(xdr, &hdr);
  6613. if (!status)
  6614. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6615. if (!status)
  6616. status = decode_reclaim_complete(xdr, NULL);
  6617. return status;
  6618. }
  6619. /*
  6620. * Decode GETDEVINFO response
  6621. */
  6622. static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
  6623. struct xdr_stream *xdr,
  6624. void *data)
  6625. {
  6626. struct nfs4_getdeviceinfo_res *res = data;
  6627. struct compound_hdr hdr;
  6628. int status;
  6629. status = decode_compound_hdr(xdr, &hdr);
  6630. if (status != 0)
  6631. goto out;
  6632. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6633. if (status != 0)
  6634. goto out;
  6635. status = decode_getdeviceinfo(xdr, res);
  6636. out:
  6637. return status;
  6638. }
  6639. /*
  6640. * Decode LAYOUTGET response
  6641. */
  6642. static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
  6643. struct xdr_stream *xdr,
  6644. void *data)
  6645. {
  6646. struct nfs4_layoutget_res *res = data;
  6647. struct compound_hdr hdr;
  6648. int status;
  6649. status = decode_compound_hdr(xdr, &hdr);
  6650. if (status)
  6651. goto out;
  6652. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6653. if (status)
  6654. goto out;
  6655. status = decode_putfh(xdr);
  6656. if (status)
  6657. goto out;
  6658. status = decode_layoutget(xdr, rqstp, res);
  6659. out:
  6660. return status;
  6661. }
  6662. /*
  6663. * Decode LAYOUTRETURN response
  6664. */
  6665. static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
  6666. struct xdr_stream *xdr,
  6667. void *data)
  6668. {
  6669. struct nfs4_layoutreturn_res *res = data;
  6670. struct compound_hdr hdr;
  6671. int status;
  6672. status = decode_compound_hdr(xdr, &hdr);
  6673. if (status)
  6674. goto out;
  6675. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6676. if (status)
  6677. goto out;
  6678. status = decode_putfh(xdr);
  6679. if (status)
  6680. goto out;
  6681. status = decode_layoutreturn(xdr, res);
  6682. out:
  6683. return status;
  6684. }
  6685. /*
  6686. * Decode LAYOUTCOMMIT response
  6687. */
  6688. static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
  6689. struct xdr_stream *xdr,
  6690. void *data)
  6691. {
  6692. struct nfs4_layoutcommit_res *res = data;
  6693. struct compound_hdr hdr;
  6694. int status;
  6695. status = decode_compound_hdr(xdr, &hdr);
  6696. if (status)
  6697. goto out;
  6698. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6699. if (status)
  6700. goto out;
  6701. status = decode_putfh(xdr);
  6702. if (status)
  6703. goto out;
  6704. status = decode_layoutcommit(xdr, rqstp, res);
  6705. if (status)
  6706. goto out;
  6707. decode_getfattr(xdr, res->fattr, res->server);
  6708. out:
  6709. return status;
  6710. }
  6711. /*
  6712. * Decode SECINFO_NO_NAME response
  6713. */
  6714. static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
  6715. struct xdr_stream *xdr,
  6716. void *data)
  6717. {
  6718. struct nfs4_secinfo_res *res = data;
  6719. struct compound_hdr hdr;
  6720. int status;
  6721. status = decode_compound_hdr(xdr, &hdr);
  6722. if (status)
  6723. goto out;
  6724. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6725. if (status)
  6726. goto out;
  6727. status = decode_putrootfh(xdr);
  6728. if (status)
  6729. goto out;
  6730. status = decode_secinfo_no_name(xdr, res);
  6731. out:
  6732. return status;
  6733. }
  6734. /*
  6735. * Decode TEST_STATEID response
  6736. */
  6737. static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
  6738. struct xdr_stream *xdr,
  6739. void *data)
  6740. {
  6741. struct nfs41_test_stateid_res *res = data;
  6742. struct compound_hdr hdr;
  6743. int status;
  6744. status = decode_compound_hdr(xdr, &hdr);
  6745. if (status)
  6746. goto out;
  6747. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6748. if (status)
  6749. goto out;
  6750. status = decode_test_stateid(xdr, res);
  6751. out:
  6752. return status;
  6753. }
  6754. /*
  6755. * Decode FREE_STATEID response
  6756. */
  6757. static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
  6758. struct xdr_stream *xdr,
  6759. void *data)
  6760. {
  6761. struct nfs41_free_stateid_res *res = data;
  6762. struct compound_hdr hdr;
  6763. int status;
  6764. status = decode_compound_hdr(xdr, &hdr);
  6765. if (status)
  6766. goto out;
  6767. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6768. if (status)
  6769. goto out;
  6770. status = decode_free_stateid(xdr, res);
  6771. out:
  6772. return status;
  6773. }
  6774. #endif /* CONFIG_NFS_V4_1 */
  6775. /**
  6776. * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
  6777. * the local page cache.
  6778. * @xdr: XDR stream where entry resides
  6779. * @entry: buffer to fill in with entry data
  6780. * @plus: boolean indicating whether this should be a readdirplus entry
  6781. *
  6782. * Returns zero if successful, otherwise a negative errno value is
  6783. * returned.
  6784. *
  6785. * This function is not invoked during READDIR reply decoding, but
  6786. * rather whenever an application invokes the getdents(2) system call
  6787. * on a directory already in our cache.
  6788. */
  6789. int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
  6790. bool plus)
  6791. {
  6792. unsigned int savep;
  6793. uint32_t bitmap[3] = {0};
  6794. uint32_t len;
  6795. uint64_t new_cookie;
  6796. __be32 *p = xdr_inline_decode(xdr, 4);
  6797. if (unlikely(!p))
  6798. return -EAGAIN;
  6799. if (*p == xdr_zero) {
  6800. p = xdr_inline_decode(xdr, 4);
  6801. if (unlikely(!p))
  6802. return -EAGAIN;
  6803. if (*p == xdr_zero)
  6804. return -EAGAIN;
  6805. entry->eof = 1;
  6806. return -EBADCOOKIE;
  6807. }
  6808. p = xdr_inline_decode(xdr, 12);
  6809. if (unlikely(!p))
  6810. return -EAGAIN;
  6811. p = xdr_decode_hyper(p, &new_cookie);
  6812. entry->len = be32_to_cpup(p);
  6813. p = xdr_inline_decode(xdr, entry->len);
  6814. if (unlikely(!p))
  6815. return -EAGAIN;
  6816. entry->name = (const char *) p;
  6817. /*
  6818. * In case the server doesn't return an inode number,
  6819. * we fake one here. (We don't use inode number 0,
  6820. * since glibc seems to choke on it...)
  6821. */
  6822. entry->ino = 1;
  6823. entry->fattr->valid = 0;
  6824. if (decode_attr_bitmap(xdr, bitmap) < 0)
  6825. return -EAGAIN;
  6826. if (decode_attr_length(xdr, &len, &savep) < 0)
  6827. return -EAGAIN;
  6828. if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
  6829. NULL, entry->server) < 0)
  6830. return -EAGAIN;
  6831. if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
  6832. entry->ino = entry->fattr->mounted_on_fileid;
  6833. else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
  6834. entry->ino = entry->fattr->fileid;
  6835. entry->d_type = DT_UNKNOWN;
  6836. if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
  6837. entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
  6838. entry->cookie = new_cookie;
  6839. return 0;
  6840. }
  6841. #ifdef CONFIG_NFS_V4_2
  6842. #include "nfs42xdr.c"
  6843. #endif /* CONFIG_NFS_V4_2 */
  6844. #define PROC(proc, argtype, restype) \
  6845. [NFSPROC4_CLNT_##proc] = { \
  6846. .p_proc = NFSPROC4_COMPOUND, \
  6847. .p_encode = nfs4_xdr_##argtype, \
  6848. .p_decode = nfs4_xdr_##restype, \
  6849. .p_arglen = NFS4_##argtype##_sz, \
  6850. .p_replen = NFS4_##restype##_sz, \
  6851. .p_statidx = NFSPROC4_CLNT_##proc, \
  6852. .p_name = #proc, \
  6853. }
  6854. #define STUB(proc) \
  6855. [NFSPROC4_CLNT_##proc] = { \
  6856. .p_name = #proc, \
  6857. }
  6858. #if defined(CONFIG_NFS_V4_1)
  6859. #define PROC41(proc, argtype, restype) \
  6860. PROC(proc, argtype, restype)
  6861. #else
  6862. #define PROC41(proc, argtype, restype) \
  6863. STUB(proc)
  6864. #endif
  6865. #if defined(CONFIG_NFS_V4_2)
  6866. #define PROC42(proc, argtype, restype) \
  6867. PROC(proc, argtype, restype)
  6868. #else
  6869. #define PROC42(proc, argtype, restype) \
  6870. STUB(proc)
  6871. #endif
  6872. const struct rpc_procinfo nfs4_procedures[] = {
  6873. PROC(READ, enc_read, dec_read),
  6874. PROC(WRITE, enc_write, dec_write),
  6875. PROC(COMMIT, enc_commit, dec_commit),
  6876. PROC(OPEN, enc_open, dec_open),
  6877. PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
  6878. PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
  6879. PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
  6880. PROC(CLOSE, enc_close, dec_close),
  6881. PROC(SETATTR, enc_setattr, dec_setattr),
  6882. PROC(FSINFO, enc_fsinfo, dec_fsinfo),
  6883. PROC(RENEW, enc_renew, dec_renew),
  6884. PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
  6885. PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
  6886. PROC(LOCK, enc_lock, dec_lock),
  6887. PROC(LOCKT, enc_lockt, dec_lockt),
  6888. PROC(LOCKU, enc_locku, dec_locku),
  6889. PROC(ACCESS, enc_access, dec_access),
  6890. PROC(GETATTR, enc_getattr, dec_getattr),
  6891. PROC(LOOKUP, enc_lookup, dec_lookup),
  6892. PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
  6893. PROC(REMOVE, enc_remove, dec_remove),
  6894. PROC(RENAME, enc_rename, dec_rename),
  6895. PROC(LINK, enc_link, dec_link),
  6896. PROC(SYMLINK, enc_symlink, dec_symlink),
  6897. PROC(CREATE, enc_create, dec_create),
  6898. PROC(PATHCONF, enc_pathconf, dec_pathconf),
  6899. PROC(STATFS, enc_statfs, dec_statfs),
  6900. PROC(READLINK, enc_readlink, dec_readlink),
  6901. PROC(READDIR, enc_readdir, dec_readdir),
  6902. PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
  6903. PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
  6904. PROC(GETACL, enc_getacl, dec_getacl),
  6905. PROC(SETACL, enc_setacl, dec_setacl),
  6906. PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
  6907. PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
  6908. PROC(SECINFO, enc_secinfo, dec_secinfo),
  6909. PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
  6910. PROC41(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
  6911. PROC41(CREATE_SESSION, enc_create_session, dec_create_session),
  6912. PROC41(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
  6913. PROC41(SEQUENCE, enc_sequence, dec_sequence),
  6914. PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
  6915. PROC41(RECLAIM_COMPLETE,enc_reclaim_complete, dec_reclaim_complete),
  6916. PROC41(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
  6917. PROC41(LAYOUTGET, enc_layoutget, dec_layoutget),
  6918. PROC41(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
  6919. PROC41(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
  6920. PROC41(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
  6921. PROC41(TEST_STATEID, enc_test_stateid, dec_test_stateid),
  6922. PROC41(FREE_STATEID, enc_free_stateid, dec_free_stateid),
  6923. STUB(GETDEVICELIST),
  6924. PROC41(BIND_CONN_TO_SESSION,
  6925. enc_bind_conn_to_session, dec_bind_conn_to_session),
  6926. PROC41(DESTROY_CLIENTID,enc_destroy_clientid, dec_destroy_clientid),
  6927. PROC42(SEEK, enc_seek, dec_seek),
  6928. PROC42(ALLOCATE, enc_allocate, dec_allocate),
  6929. PROC42(DEALLOCATE, enc_deallocate, dec_deallocate),
  6930. PROC42(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
  6931. PROC42(CLONE, enc_clone, dec_clone),
  6932. PROC42(COPY, enc_copy, dec_copy),
  6933. PROC42(OFFLOAD_CANCEL, enc_offload_cancel, dec_offload_cancel),
  6934. PROC42(COPY_NOTIFY, enc_copy_notify, dec_copy_notify),
  6935. PROC(LOOKUPP, enc_lookupp, dec_lookupp),
  6936. PROC42(LAYOUTERROR, enc_layouterror, dec_layouterror),
  6937. PROC42(GETXATTR, enc_getxattr, dec_getxattr),
  6938. PROC42(SETXATTR, enc_setxattr, dec_setxattr),
  6939. PROC42(LISTXATTRS, enc_listxattrs, dec_listxattrs),
  6940. PROC42(REMOVEXATTR, enc_removexattr, dec_removexattr),
  6941. PROC42(READ_PLUS, enc_read_plus, dec_read_plus),
  6942. };
  6943. static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)];
  6944. const struct rpc_version nfs_version4 = {
  6945. .number = 4,
  6946. .nrprocs = ARRAY_SIZE(nfs4_procedures),
  6947. .procs = nfs4_procedures,
  6948. .counts = nfs_version4_counts,
  6949. };