nfs4xdr.c 184 KB

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