nfs4xdr.c 167 KB

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