nfs4xdr.c 154 KB

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