nfs4xdr.c 152 KB

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