nfs4xdr.c 154 KB

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