nfs4xdr.c 157 KB

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