nfs4xdr.c 202 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761
  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/module.h>
  47. #include <linux/utsname.h>
  48. #include <linux/sunrpc/clnt.h>
  49. #include <linux/sunrpc/msg_prot.h>
  50. #include <linux/sunrpc/gss_api.h>
  51. #include <linux/nfs.h>
  52. #include <linux/nfs4.h>
  53. #include <linux/nfs_fs.h>
  54. #include <linux/fs_struct.h>
  55. #include "nfs4_fs.h"
  56. #include "internal.h"
  57. #include "nfs4idmap.h"
  58. #include "nfs4session.h"
  59. #include "pnfs.h"
  60. #include "netns.h"
  61. #define NFSDBG_FACILITY NFSDBG_XDR
  62. /* Mapping from NFS error code to "errno" error code. */
  63. #define errno_NFSERR_IO EIO
  64. static int nfs4_stat_to_errno(int);
  65. /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
  66. #ifdef DEBUG
  67. #define NFS4_MAXTAGLEN 20
  68. #else
  69. #define NFS4_MAXTAGLEN 0
  70. #endif
  71. /* lock,open owner id:
  72. * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
  73. */
  74. #define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
  75. #define lock_owner_id_maxsz (1 + 1 + 4)
  76. #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
  77. #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
  78. #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
  79. #define op_encode_hdr_maxsz (1)
  80. #define op_decode_hdr_maxsz (2)
  81. #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
  82. #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
  83. #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
  84. #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
  85. #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
  86. (NFS4_FHSIZE >> 2))
  87. #define decode_putfh_maxsz (op_decode_hdr_maxsz)
  88. #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
  89. #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
  90. #define encode_getfh_maxsz (op_encode_hdr_maxsz)
  91. #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
  92. ((3+NFS4_FHSIZE) >> 2))
  93. #define nfs4_fattr_bitmap_maxsz 4
  94. #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
  95. #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
  96. #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
  97. #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
  98. #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
  99. #ifdef CONFIG_NFS_V4_SECURITY_LABEL
  100. /* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
  101. #define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
  102. #else
  103. #define nfs4_label_maxsz 0
  104. #endif
  105. /* We support only one layout type per file system */
  106. #define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
  107. /* This is based on getfattr, which uses the most attributes: */
  108. #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
  109. 3 + 3 + 3 + nfs4_owner_maxsz + \
  110. nfs4_group_maxsz + nfs4_label_maxsz + \
  111. decode_mdsthreshold_maxsz))
  112. #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
  113. nfs4_fattr_value_maxsz)
  114. #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
  115. #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
  116. 1 + 2 + 1 + \
  117. nfs4_owner_maxsz + \
  118. nfs4_group_maxsz + \
  119. nfs4_label_maxsz + \
  120. 4 + 4)
  121. #define encode_savefh_maxsz (op_encode_hdr_maxsz)
  122. #define decode_savefh_maxsz (op_decode_hdr_maxsz)
  123. #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
  124. #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
  125. #define encode_fsinfo_maxsz (encode_getattr_maxsz)
  126. /* The 5 accounts for the PNFS attributes, and assumes that at most three
  127. * layout types will be returned.
  128. */
  129. #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
  130. nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
  131. #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
  132. #define decode_renew_maxsz (op_decode_hdr_maxsz)
  133. #define encode_setclientid_maxsz \
  134. (op_encode_hdr_maxsz + \
  135. XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
  136. /* client name */ \
  137. 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
  138. 1 /* sc_prog */ + \
  139. 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
  140. 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
  141. 1) /* sc_cb_ident */
  142. #define decode_setclientid_maxsz \
  143. (op_decode_hdr_maxsz + \
  144. 2 /* clientid */ + \
  145. XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
  146. 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
  147. 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
  148. #define encode_setclientid_confirm_maxsz \
  149. (op_encode_hdr_maxsz + \
  150. 3 + (NFS4_VERIFIER_SIZE >> 2))
  151. #define decode_setclientid_confirm_maxsz \
  152. (op_decode_hdr_maxsz)
  153. #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
  154. #define decode_lookup_maxsz (op_decode_hdr_maxsz)
  155. #define encode_lookupp_maxsz (op_encode_hdr_maxsz)
  156. #define decode_lookupp_maxsz (op_decode_hdr_maxsz)
  157. #define encode_share_access_maxsz \
  158. (2)
  159. #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
  160. #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
  161. #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
  162. #define encode_open_maxsz (op_encode_hdr_maxsz + \
  163. 2 + encode_share_access_maxsz + 2 + \
  164. open_owner_id_maxsz + \
  165. encode_opentype_maxsz + \
  166. encode_claim_null_maxsz)
  167. #define decode_space_limit_maxsz (3)
  168. #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
  169. #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
  170. decode_space_limit_maxsz + \
  171. decode_ace_maxsz)
  172. #define decode_change_info_maxsz (5)
  173. #define decode_open_maxsz (op_decode_hdr_maxsz + \
  174. decode_stateid_maxsz + \
  175. decode_change_info_maxsz + 1 + \
  176. nfs4_fattr_bitmap_maxsz + \
  177. decode_delegation_maxsz)
  178. #define encode_open_confirm_maxsz \
  179. (op_encode_hdr_maxsz + \
  180. encode_stateid_maxsz + 1)
  181. #define decode_open_confirm_maxsz \
  182. (op_decode_hdr_maxsz + \
  183. decode_stateid_maxsz)
  184. #define encode_open_downgrade_maxsz \
  185. (op_encode_hdr_maxsz + \
  186. encode_stateid_maxsz + 1 + \
  187. encode_share_access_maxsz)
  188. #define decode_open_downgrade_maxsz \
  189. (op_decode_hdr_maxsz + \
  190. decode_stateid_maxsz)
  191. #define encode_close_maxsz (op_encode_hdr_maxsz + \
  192. 1 + encode_stateid_maxsz)
  193. #define decode_close_maxsz (op_decode_hdr_maxsz + \
  194. decode_stateid_maxsz)
  195. #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
  196. encode_stateid_maxsz + \
  197. encode_attrs_maxsz)
  198. #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
  199. nfs4_fattr_bitmap_maxsz)
  200. #define encode_read_maxsz (op_encode_hdr_maxsz + \
  201. encode_stateid_maxsz + 3)
  202. #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
  203. #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
  204. 2 + encode_verifier_maxsz + 5 + \
  205. nfs4_label_maxsz)
  206. #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
  207. decode_verifier_maxsz)
  208. #define encode_readlink_maxsz (op_encode_hdr_maxsz)
  209. #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
  210. #define encode_write_maxsz (op_encode_hdr_maxsz + \
  211. encode_stateid_maxsz + 4)
  212. #define decode_write_maxsz (op_decode_hdr_maxsz + \
  213. 2 + decode_verifier_maxsz)
  214. #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
  215. #define decode_commit_maxsz (op_decode_hdr_maxsz + \
  216. decode_verifier_maxsz)
  217. #define encode_remove_maxsz (op_encode_hdr_maxsz + \
  218. nfs4_name_maxsz)
  219. #define decode_remove_maxsz (op_decode_hdr_maxsz + \
  220. decode_change_info_maxsz)
  221. #define encode_rename_maxsz (op_encode_hdr_maxsz + \
  222. 2 * nfs4_name_maxsz)
  223. #define decode_rename_maxsz (op_decode_hdr_maxsz + \
  224. decode_change_info_maxsz + \
  225. decode_change_info_maxsz)
  226. #define encode_link_maxsz (op_encode_hdr_maxsz + \
  227. nfs4_name_maxsz)
  228. #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
  229. #define encode_lockowner_maxsz (7)
  230. #define encode_lock_maxsz (op_encode_hdr_maxsz + \
  231. 7 + \
  232. 1 + encode_stateid_maxsz + 1 + \
  233. encode_lockowner_maxsz)
  234. #define decode_lock_denied_maxsz \
  235. (8 + decode_lockowner_maxsz)
  236. #define decode_lock_maxsz (op_decode_hdr_maxsz + \
  237. decode_lock_denied_maxsz)
  238. #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
  239. encode_lockowner_maxsz)
  240. #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
  241. decode_lock_denied_maxsz)
  242. #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
  243. encode_stateid_maxsz + \
  244. 4)
  245. #define decode_locku_maxsz (op_decode_hdr_maxsz + \
  246. decode_stateid_maxsz)
  247. #define encode_release_lockowner_maxsz \
  248. (op_encode_hdr_maxsz + \
  249. encode_lockowner_maxsz)
  250. #define decode_release_lockowner_maxsz \
  251. (op_decode_hdr_maxsz)
  252. #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
  253. #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
  254. #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
  255. 1 + nfs4_name_maxsz + \
  256. 1 + \
  257. nfs4_fattr_maxsz)
  258. #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
  259. #define encode_create_maxsz (op_encode_hdr_maxsz + \
  260. 1 + 2 + nfs4_name_maxsz + \
  261. encode_attrs_maxsz)
  262. #define decode_create_maxsz (op_decode_hdr_maxsz + \
  263. decode_change_info_maxsz + \
  264. nfs4_fattr_bitmap_maxsz)
  265. #define encode_statfs_maxsz (encode_getattr_maxsz)
  266. #define decode_statfs_maxsz (decode_getattr_maxsz)
  267. #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
  268. #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
  269. #define encode_getacl_maxsz (encode_getattr_maxsz)
  270. #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
  271. nfs4_fattr_bitmap_maxsz + 1)
  272. #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
  273. encode_stateid_maxsz + 3)
  274. #define decode_setacl_maxsz (decode_setattr_maxsz)
  275. #define encode_fs_locations_maxsz \
  276. (encode_getattr_maxsz)
  277. #define decode_fs_locations_maxsz \
  278. (0)
  279. #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
  280. #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
  281. #if defined(CONFIG_NFS_V4_1)
  282. #define NFS4_MAX_MACHINE_NAME_LEN (64)
  283. #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
  284. sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
  285. #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
  286. encode_verifier_maxsz + \
  287. 1 /* co_ownerid.len */ + \
  288. /* eia_clientowner */ \
  289. 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
  290. 1 /* flags */ + \
  291. 1 /* spa_how */ + \
  292. /* max is SP4_MACH_CRED (for now) */ + \
  293. 1 + NFS4_OP_MAP_NUM_WORDS + \
  294. 1 + NFS4_OP_MAP_NUM_WORDS + \
  295. 1 /* implementation id array of size 1 */ + \
  296. 1 /* nii_domain */ + \
  297. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
  298. 1 /* nii_name */ + \
  299. XDR_QUADLEN(IMPL_NAME_LIMIT) + \
  300. 3 /* nii_date */)
  301. #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
  302. 2 /* eir_clientid */ + \
  303. 1 /* eir_sequenceid */ + \
  304. 1 /* eir_flags */ + \
  305. 1 /* spr_how */ + \
  306. /* max is SP4_MACH_CRED (for now) */ + \
  307. 1 + NFS4_OP_MAP_NUM_WORDS + \
  308. 1 + NFS4_OP_MAP_NUM_WORDS + \
  309. 2 /* eir_server_owner.so_minor_id */ + \
  310. /* eir_server_owner.so_major_id<> */ \
  311. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
  312. /* eir_server_scope<> */ \
  313. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
  314. 1 /* eir_server_impl_id array length */ + \
  315. 1 /* nii_domain */ + \
  316. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
  317. 1 /* nii_name */ + \
  318. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
  319. 3 /* nii_date */)
  320. #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
  321. #define decode_channel_attrs_maxsz (6 + \
  322. 1 /* ca_rdma_ird.len */ + \
  323. 1 /* ca_rdma_ird */)
  324. #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
  325. 2 /* csa_clientid */ + \
  326. 1 /* csa_sequence */ + \
  327. 1 /* csa_flags */ + \
  328. encode_channel_attrs_maxsz + \
  329. encode_channel_attrs_maxsz + \
  330. 1 /* csa_cb_program */ + \
  331. 1 /* csa_sec_parms.len (1) */ + \
  332. 1 /* cb_secflavor (AUTH_SYS) */ + \
  333. 1 /* stamp */ + \
  334. 1 /* machinename.len */ + \
  335. XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
  336. 1 /* uid */ + \
  337. 1 /* gid */ + \
  338. 1 /* gids.len (0) */)
  339. #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
  340. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
  341. 1 /* csr_sequence */ + \
  342. 1 /* csr_flags */ + \
  343. decode_channel_attrs_maxsz + \
  344. decode_channel_attrs_maxsz)
  345. #define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
  346. /* bctsa_sessid */ \
  347. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
  348. 1 /* bctsa_dir */ + \
  349. 1 /* bctsa_use_conn_in_rdma_mode */)
  350. #define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
  351. /* bctsr_sessid */ \
  352. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
  353. 1 /* bctsr_dir */ + \
  354. 1 /* bctsr_use_conn_in_rdma_mode */)
  355. #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
  356. #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
  357. #define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
  358. #define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
  359. #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
  360. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
  361. #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
  362. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
  363. #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
  364. #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
  365. #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
  366. XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
  367. 1 /* layout type */ + \
  368. 1 /* maxcount */ + \
  369. 1 /* bitmap size */ + \
  370. 1 /* notification bitmap length */ + \
  371. 1 /* notification bitmap, word 0 */)
  372. #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
  373. 1 /* layout type */ + \
  374. 1 /* opaque devaddr4 length */ + \
  375. /* devaddr4 payload is read into page */ \
  376. 1 /* notification bitmap length */ + \
  377. 1 /* notification bitmap, word 0 */)
  378. #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
  379. encode_stateid_maxsz)
  380. #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
  381. decode_stateid_maxsz + \
  382. XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
  383. #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
  384. 2 /* offset */ + \
  385. 2 /* length */ + \
  386. 1 /* reclaim */ + \
  387. encode_stateid_maxsz + \
  388. 1 /* new offset (true) */ + \
  389. 2 /* last byte written */ + \
  390. 1 /* nt_timechanged (false) */ + \
  391. 1 /* layoutupdate4 layout type */ + \
  392. 1 /* layoutupdate4 opaqueue len */)
  393. /* the actual content of layoutupdate4 should
  394. be allocated by drivers and spliced in
  395. using xdr_write_pages */
  396. #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
  397. #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
  398. encode_stateid_maxsz + \
  399. 1 + \
  400. XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
  401. #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
  402. 1 + decode_stateid_maxsz)
  403. #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
  404. #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
  405. #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
  406. XDR_QUADLEN(NFS4_STATEID_SIZE))
  407. #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
  408. #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
  409. XDR_QUADLEN(NFS4_STATEID_SIZE))
  410. #define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
  411. #else /* CONFIG_NFS_V4_1 */
  412. #define encode_sequence_maxsz 0
  413. #define decode_sequence_maxsz 0
  414. #define encode_layoutreturn_maxsz 0
  415. #define decode_layoutreturn_maxsz 0
  416. #endif /* CONFIG_NFS_V4_1 */
  417. #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
  418. #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
  419. #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
  420. encode_sequence_maxsz + \
  421. encode_putfh_maxsz + \
  422. encode_read_maxsz)
  423. #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
  424. decode_sequence_maxsz + \
  425. decode_putfh_maxsz + \
  426. decode_read_maxsz)
  427. #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
  428. encode_sequence_maxsz + \
  429. encode_putfh_maxsz + \
  430. encode_readlink_maxsz)
  431. #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
  432. decode_sequence_maxsz + \
  433. decode_putfh_maxsz + \
  434. decode_readlink_maxsz)
  435. #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
  436. encode_sequence_maxsz + \
  437. encode_putfh_maxsz + \
  438. encode_readdir_maxsz)
  439. #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
  440. decode_sequence_maxsz + \
  441. decode_putfh_maxsz + \
  442. decode_readdir_maxsz)
  443. #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
  444. encode_sequence_maxsz + \
  445. encode_putfh_maxsz + \
  446. encode_write_maxsz + \
  447. encode_getattr_maxsz)
  448. #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
  449. decode_sequence_maxsz + \
  450. decode_putfh_maxsz + \
  451. decode_write_maxsz + \
  452. decode_getattr_maxsz)
  453. #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
  454. encode_sequence_maxsz + \
  455. encode_putfh_maxsz + \
  456. encode_commit_maxsz)
  457. #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
  458. decode_sequence_maxsz + \
  459. decode_putfh_maxsz + \
  460. decode_commit_maxsz)
  461. #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
  462. encode_sequence_maxsz + \
  463. encode_putfh_maxsz + \
  464. encode_open_maxsz + \
  465. encode_access_maxsz + \
  466. encode_getfh_maxsz + \
  467. encode_getattr_maxsz)
  468. #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
  469. decode_sequence_maxsz + \
  470. decode_putfh_maxsz + \
  471. decode_open_maxsz + \
  472. decode_access_maxsz + \
  473. decode_getfh_maxsz + \
  474. decode_getattr_maxsz)
  475. #define NFS4_enc_open_confirm_sz \
  476. (compound_encode_hdr_maxsz + \
  477. encode_putfh_maxsz + \
  478. encode_open_confirm_maxsz)
  479. #define NFS4_dec_open_confirm_sz \
  480. (compound_decode_hdr_maxsz + \
  481. decode_putfh_maxsz + \
  482. decode_open_confirm_maxsz)
  483. #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
  484. encode_sequence_maxsz + \
  485. encode_putfh_maxsz + \
  486. encode_open_maxsz + \
  487. encode_access_maxsz + \
  488. encode_getattr_maxsz)
  489. #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
  490. decode_sequence_maxsz + \
  491. decode_putfh_maxsz + \
  492. decode_open_maxsz + \
  493. decode_access_maxsz + \
  494. decode_getattr_maxsz)
  495. #define NFS4_enc_open_downgrade_sz \
  496. (compound_encode_hdr_maxsz + \
  497. encode_sequence_maxsz + \
  498. encode_putfh_maxsz + \
  499. encode_layoutreturn_maxsz + \
  500. encode_open_downgrade_maxsz)
  501. #define NFS4_dec_open_downgrade_sz \
  502. (compound_decode_hdr_maxsz + \
  503. decode_sequence_maxsz + \
  504. decode_putfh_maxsz + \
  505. decode_layoutreturn_maxsz + \
  506. decode_open_downgrade_maxsz)
  507. #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
  508. encode_sequence_maxsz + \
  509. encode_putfh_maxsz + \
  510. encode_layoutreturn_maxsz + \
  511. encode_close_maxsz + \
  512. encode_getattr_maxsz)
  513. #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
  514. decode_sequence_maxsz + \
  515. decode_putfh_maxsz + \
  516. decode_layoutreturn_maxsz + \
  517. decode_close_maxsz + \
  518. decode_getattr_maxsz)
  519. #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
  520. encode_sequence_maxsz + \
  521. encode_putfh_maxsz + \
  522. encode_setattr_maxsz + \
  523. encode_getattr_maxsz)
  524. #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
  525. decode_sequence_maxsz + \
  526. decode_putfh_maxsz + \
  527. decode_setattr_maxsz + \
  528. decode_getattr_maxsz)
  529. #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
  530. encode_sequence_maxsz + \
  531. encode_putfh_maxsz + \
  532. encode_fsinfo_maxsz)
  533. #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
  534. decode_sequence_maxsz + \
  535. decode_putfh_maxsz + \
  536. decode_fsinfo_maxsz)
  537. #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
  538. encode_renew_maxsz)
  539. #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
  540. decode_renew_maxsz)
  541. #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
  542. encode_setclientid_maxsz)
  543. #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
  544. decode_setclientid_maxsz)
  545. #define NFS4_enc_setclientid_confirm_sz \
  546. (compound_encode_hdr_maxsz + \
  547. encode_setclientid_confirm_maxsz)
  548. #define NFS4_dec_setclientid_confirm_sz \
  549. (compound_decode_hdr_maxsz + \
  550. decode_setclientid_confirm_maxsz)
  551. #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
  552. encode_sequence_maxsz + \
  553. encode_putfh_maxsz + \
  554. encode_lock_maxsz)
  555. #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
  556. decode_sequence_maxsz + \
  557. decode_putfh_maxsz + \
  558. decode_lock_maxsz)
  559. #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
  560. encode_sequence_maxsz + \
  561. encode_putfh_maxsz + \
  562. encode_lockt_maxsz)
  563. #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
  564. decode_sequence_maxsz + \
  565. decode_putfh_maxsz + \
  566. decode_lockt_maxsz)
  567. #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
  568. encode_sequence_maxsz + \
  569. encode_putfh_maxsz + \
  570. encode_locku_maxsz)
  571. #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
  572. decode_sequence_maxsz + \
  573. decode_putfh_maxsz + \
  574. decode_locku_maxsz)
  575. #define NFS4_enc_release_lockowner_sz \
  576. (compound_encode_hdr_maxsz + \
  577. encode_lockowner_maxsz)
  578. #define NFS4_dec_release_lockowner_sz \
  579. (compound_decode_hdr_maxsz + \
  580. decode_lockowner_maxsz)
  581. #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
  582. encode_sequence_maxsz + \
  583. encode_putfh_maxsz + \
  584. encode_access_maxsz + \
  585. encode_getattr_maxsz)
  586. #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
  587. decode_sequence_maxsz + \
  588. decode_putfh_maxsz + \
  589. decode_access_maxsz + \
  590. decode_getattr_maxsz)
  591. #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
  592. encode_sequence_maxsz + \
  593. encode_putfh_maxsz + \
  594. encode_getattr_maxsz + \
  595. encode_renew_maxsz)
  596. #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
  597. decode_sequence_maxsz + \
  598. decode_putfh_maxsz + \
  599. decode_getattr_maxsz + \
  600. decode_renew_maxsz)
  601. #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
  602. encode_sequence_maxsz + \
  603. encode_putfh_maxsz + \
  604. encode_lookup_maxsz + \
  605. encode_getattr_maxsz + \
  606. encode_getfh_maxsz)
  607. #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
  608. decode_sequence_maxsz + \
  609. decode_putfh_maxsz + \
  610. decode_lookup_maxsz + \
  611. decode_getattr_maxsz + \
  612. decode_getfh_maxsz)
  613. #define NFS4_enc_lookupp_sz (compound_encode_hdr_maxsz + \
  614. encode_sequence_maxsz + \
  615. encode_putfh_maxsz + \
  616. encode_lookupp_maxsz + \
  617. encode_getattr_maxsz + \
  618. encode_getfh_maxsz)
  619. #define NFS4_dec_lookupp_sz (compound_decode_hdr_maxsz + \
  620. decode_sequence_maxsz + \
  621. decode_putfh_maxsz + \
  622. decode_lookupp_maxsz + \
  623. decode_getattr_maxsz + \
  624. decode_getfh_maxsz)
  625. #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
  626. encode_sequence_maxsz + \
  627. encode_putrootfh_maxsz + \
  628. encode_getattr_maxsz + \
  629. encode_getfh_maxsz)
  630. #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
  631. decode_sequence_maxsz + \
  632. decode_putrootfh_maxsz + \
  633. decode_getattr_maxsz + \
  634. decode_getfh_maxsz)
  635. #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
  636. encode_sequence_maxsz + \
  637. encode_putfh_maxsz + \
  638. encode_remove_maxsz)
  639. #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
  640. decode_sequence_maxsz + \
  641. decode_putfh_maxsz + \
  642. decode_remove_maxsz)
  643. #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
  644. encode_sequence_maxsz + \
  645. encode_putfh_maxsz + \
  646. encode_savefh_maxsz + \
  647. encode_putfh_maxsz + \
  648. encode_rename_maxsz)
  649. #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
  650. decode_sequence_maxsz + \
  651. decode_putfh_maxsz + \
  652. decode_savefh_maxsz + \
  653. decode_putfh_maxsz + \
  654. decode_rename_maxsz)
  655. #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
  656. encode_sequence_maxsz + \
  657. encode_putfh_maxsz + \
  658. encode_savefh_maxsz + \
  659. encode_putfh_maxsz + \
  660. encode_link_maxsz + \
  661. encode_restorefh_maxsz + \
  662. encode_getattr_maxsz)
  663. #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
  664. decode_sequence_maxsz + \
  665. decode_putfh_maxsz + \
  666. decode_savefh_maxsz + \
  667. decode_putfh_maxsz + \
  668. decode_link_maxsz + \
  669. decode_restorefh_maxsz + \
  670. decode_getattr_maxsz)
  671. #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
  672. encode_sequence_maxsz + \
  673. encode_putfh_maxsz + \
  674. encode_symlink_maxsz + \
  675. encode_getattr_maxsz + \
  676. encode_getfh_maxsz)
  677. #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
  678. decode_sequence_maxsz + \
  679. decode_putfh_maxsz + \
  680. decode_symlink_maxsz + \
  681. decode_getattr_maxsz + \
  682. decode_getfh_maxsz)
  683. #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
  684. encode_sequence_maxsz + \
  685. encode_putfh_maxsz + \
  686. encode_create_maxsz + \
  687. encode_getfh_maxsz + \
  688. encode_getattr_maxsz)
  689. #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
  690. decode_sequence_maxsz + \
  691. decode_putfh_maxsz + \
  692. decode_create_maxsz + \
  693. decode_getfh_maxsz + \
  694. decode_getattr_maxsz)
  695. #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
  696. encode_sequence_maxsz + \
  697. encode_putfh_maxsz + \
  698. encode_getattr_maxsz)
  699. #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
  700. decode_sequence_maxsz + \
  701. decode_putfh_maxsz + \
  702. decode_getattr_maxsz)
  703. #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
  704. encode_sequence_maxsz + \
  705. encode_putfh_maxsz + \
  706. encode_statfs_maxsz)
  707. #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
  708. decode_sequence_maxsz + \
  709. decode_putfh_maxsz + \
  710. decode_statfs_maxsz)
  711. #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
  712. encode_sequence_maxsz + \
  713. encode_putfh_maxsz + \
  714. encode_getattr_maxsz)
  715. #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
  716. decode_sequence_maxsz + \
  717. decode_putfh_maxsz + \
  718. decode_getattr_maxsz)
  719. #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
  720. encode_sequence_maxsz + \
  721. encode_putfh_maxsz + \
  722. encode_layoutreturn_maxsz + \
  723. encode_delegreturn_maxsz + \
  724. encode_getattr_maxsz)
  725. #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
  726. decode_sequence_maxsz + \
  727. decode_putfh_maxsz + \
  728. decode_layoutreturn_maxsz + \
  729. decode_delegreturn_maxsz + \
  730. decode_getattr_maxsz)
  731. #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
  732. encode_sequence_maxsz + \
  733. encode_putfh_maxsz + \
  734. encode_getacl_maxsz)
  735. #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
  736. decode_sequence_maxsz + \
  737. decode_putfh_maxsz + \
  738. decode_getacl_maxsz)
  739. #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
  740. encode_sequence_maxsz + \
  741. encode_putfh_maxsz + \
  742. encode_setacl_maxsz)
  743. #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
  744. decode_sequence_maxsz + \
  745. decode_putfh_maxsz + \
  746. decode_setacl_maxsz)
  747. #define NFS4_enc_fs_locations_sz \
  748. (compound_encode_hdr_maxsz + \
  749. encode_sequence_maxsz + \
  750. encode_putfh_maxsz + \
  751. encode_lookup_maxsz + \
  752. encode_fs_locations_maxsz + \
  753. encode_renew_maxsz)
  754. #define NFS4_dec_fs_locations_sz \
  755. (compound_decode_hdr_maxsz + \
  756. decode_sequence_maxsz + \
  757. decode_putfh_maxsz + \
  758. decode_lookup_maxsz + \
  759. decode_fs_locations_maxsz + \
  760. decode_renew_maxsz)
  761. #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
  762. encode_sequence_maxsz + \
  763. encode_putfh_maxsz + \
  764. encode_secinfo_maxsz)
  765. #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
  766. decode_sequence_maxsz + \
  767. decode_putfh_maxsz + \
  768. decode_secinfo_maxsz)
  769. #define NFS4_enc_fsid_present_sz \
  770. (compound_encode_hdr_maxsz + \
  771. encode_sequence_maxsz + \
  772. encode_putfh_maxsz + \
  773. encode_getfh_maxsz + \
  774. encode_renew_maxsz)
  775. #define NFS4_dec_fsid_present_sz \
  776. (compound_decode_hdr_maxsz + \
  777. decode_sequence_maxsz + \
  778. decode_putfh_maxsz + \
  779. decode_getfh_maxsz + \
  780. decode_renew_maxsz)
  781. #if defined(CONFIG_NFS_V4_1)
  782. #define NFS4_enc_bind_conn_to_session_sz \
  783. (compound_encode_hdr_maxsz + \
  784. encode_bind_conn_to_session_maxsz)
  785. #define NFS4_dec_bind_conn_to_session_sz \
  786. (compound_decode_hdr_maxsz + \
  787. decode_bind_conn_to_session_maxsz)
  788. #define NFS4_enc_exchange_id_sz \
  789. (compound_encode_hdr_maxsz + \
  790. encode_exchange_id_maxsz)
  791. #define NFS4_dec_exchange_id_sz \
  792. (compound_decode_hdr_maxsz + \
  793. decode_exchange_id_maxsz)
  794. #define NFS4_enc_create_session_sz \
  795. (compound_encode_hdr_maxsz + \
  796. encode_create_session_maxsz)
  797. #define NFS4_dec_create_session_sz \
  798. (compound_decode_hdr_maxsz + \
  799. decode_create_session_maxsz)
  800. #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
  801. encode_destroy_session_maxsz)
  802. #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
  803. decode_destroy_session_maxsz)
  804. #define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
  805. encode_destroy_clientid_maxsz)
  806. #define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
  807. decode_destroy_clientid_maxsz)
  808. #define NFS4_enc_sequence_sz \
  809. (compound_decode_hdr_maxsz + \
  810. encode_sequence_maxsz)
  811. #define NFS4_dec_sequence_sz \
  812. (compound_decode_hdr_maxsz + \
  813. decode_sequence_maxsz)
  814. #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
  815. encode_sequence_maxsz + \
  816. encode_putrootfh_maxsz + \
  817. encode_fsinfo_maxsz)
  818. #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
  819. decode_sequence_maxsz + \
  820. decode_putrootfh_maxsz + \
  821. decode_fsinfo_maxsz)
  822. #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
  823. encode_sequence_maxsz + \
  824. encode_reclaim_complete_maxsz)
  825. #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
  826. decode_sequence_maxsz + \
  827. decode_reclaim_complete_maxsz)
  828. #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
  829. encode_sequence_maxsz +\
  830. encode_getdeviceinfo_maxsz)
  831. #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
  832. decode_sequence_maxsz + \
  833. decode_getdeviceinfo_maxsz)
  834. #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
  835. encode_sequence_maxsz + \
  836. encode_putfh_maxsz + \
  837. encode_layoutget_maxsz)
  838. #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
  839. decode_sequence_maxsz + \
  840. decode_putfh_maxsz + \
  841. decode_layoutget_maxsz)
  842. #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
  843. encode_sequence_maxsz +\
  844. encode_putfh_maxsz + \
  845. encode_layoutcommit_maxsz + \
  846. encode_getattr_maxsz)
  847. #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
  848. decode_sequence_maxsz + \
  849. decode_putfh_maxsz + \
  850. decode_layoutcommit_maxsz + \
  851. decode_getattr_maxsz)
  852. #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
  853. encode_sequence_maxsz + \
  854. encode_putfh_maxsz + \
  855. encode_layoutreturn_maxsz)
  856. #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
  857. decode_sequence_maxsz + \
  858. decode_putfh_maxsz + \
  859. decode_layoutreturn_maxsz)
  860. #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
  861. encode_sequence_maxsz + \
  862. encode_putrootfh_maxsz +\
  863. encode_secinfo_no_name_maxsz)
  864. #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
  865. decode_sequence_maxsz + \
  866. decode_putrootfh_maxsz + \
  867. decode_secinfo_no_name_maxsz)
  868. #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
  869. encode_sequence_maxsz + \
  870. encode_test_stateid_maxsz)
  871. #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
  872. decode_sequence_maxsz + \
  873. decode_test_stateid_maxsz)
  874. #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
  875. encode_sequence_maxsz + \
  876. encode_free_stateid_maxsz)
  877. #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
  878. decode_sequence_maxsz + \
  879. decode_free_stateid_maxsz)
  880. const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
  881. compound_encode_hdr_maxsz +
  882. encode_sequence_maxsz +
  883. encode_putfh_maxsz +
  884. encode_getattr_maxsz) *
  885. XDR_UNIT);
  886. const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
  887. compound_decode_hdr_maxsz +
  888. decode_sequence_maxsz +
  889. decode_putfh_maxsz) *
  890. XDR_UNIT);
  891. const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
  892. compound_decode_hdr_maxsz +
  893. decode_sequence_maxsz) *
  894. XDR_UNIT);
  895. EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
  896. #endif /* CONFIG_NFS_V4_1 */
  897. static const umode_t nfs_type2fmt[] = {
  898. [NF4BAD] = 0,
  899. [NF4REG] = S_IFREG,
  900. [NF4DIR] = S_IFDIR,
  901. [NF4BLK] = S_IFBLK,
  902. [NF4CHR] = S_IFCHR,
  903. [NF4LNK] = S_IFLNK,
  904. [NF4SOCK] = S_IFSOCK,
  905. [NF4FIFO] = S_IFIFO,
  906. [NF4ATTRDIR] = 0,
  907. [NF4NAMEDATTR] = 0,
  908. };
  909. struct compound_hdr {
  910. int32_t status;
  911. uint32_t nops;
  912. __be32 * nops_p;
  913. uint32_t taglen;
  914. char * tag;
  915. uint32_t replen; /* expected reply words */
  916. u32 minorversion;
  917. };
  918. static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
  919. {
  920. __be32 *p = xdr_reserve_space(xdr, nbytes);
  921. BUG_ON(!p);
  922. return p;
  923. }
  924. static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
  925. {
  926. WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0);
  927. }
  928. static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
  929. {
  930. WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0);
  931. }
  932. static void encode_uint32(struct xdr_stream *xdr, u32 n)
  933. {
  934. WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0);
  935. }
  936. static void encode_uint64(struct xdr_stream *xdr, u64 n)
  937. {
  938. WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0);
  939. }
  940. static void encode_nfs4_seqid(struct xdr_stream *xdr,
  941. const struct nfs_seqid *seqid)
  942. {
  943. if (seqid != NULL)
  944. encode_uint32(xdr, seqid->sequence->counter);
  945. else
  946. encode_uint32(xdr, 0);
  947. }
  948. static void encode_compound_hdr(struct xdr_stream *xdr,
  949. struct rpc_rqst *req,
  950. struct compound_hdr *hdr)
  951. {
  952. __be32 *p;
  953. struct rpc_auth *auth = req->rq_cred->cr_auth;
  954. /* initialize running count of expected bytes in reply.
  955. * NOTE: the replied tag SHOULD be the same is the one sent,
  956. * but this is not required as a MUST for the server to do so. */
  957. hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
  958. WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
  959. encode_string(xdr, hdr->taglen, hdr->tag);
  960. p = reserve_space(xdr, 8);
  961. *p++ = cpu_to_be32(hdr->minorversion);
  962. hdr->nops_p = p;
  963. *p = cpu_to_be32(hdr->nops);
  964. }
  965. static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
  966. uint32_t replen,
  967. struct compound_hdr *hdr)
  968. {
  969. encode_uint32(xdr, op);
  970. hdr->nops++;
  971. hdr->replen += replen;
  972. }
  973. static void encode_nops(struct compound_hdr *hdr)
  974. {
  975. WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
  976. *hdr->nops_p = htonl(hdr->nops);
  977. }
  978. static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
  979. {
  980. encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
  981. }
  982. static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
  983. {
  984. encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
  985. }
  986. static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
  987. const struct nfs4_label *label,
  988. const umode_t *umask,
  989. const struct nfs_server *server,
  990. const uint32_t attrmask[])
  991. {
  992. char owner_name[IDMAP_NAMESZ];
  993. char owner_group[IDMAP_NAMESZ];
  994. int owner_namelen = 0;
  995. int owner_grouplen = 0;
  996. __be32 *p;
  997. unsigned i;
  998. uint32_t len = 0;
  999. uint32_t bmval_len;
  1000. uint32_t bmval[3] = { 0 };
  1001. /*
  1002. * We reserve enough space to write the entire attribute buffer at once.
  1003. */
  1004. if ((iap->ia_valid & ATTR_SIZE) && (attrmask[0] & FATTR4_WORD0_SIZE)) {
  1005. bmval[0] |= FATTR4_WORD0_SIZE;
  1006. len += 8;
  1007. }
  1008. if (iap->ia_valid & ATTR_MODE) {
  1009. if (umask && (attrmask[2] & FATTR4_WORD2_MODE_UMASK)) {
  1010. bmval[2] |= FATTR4_WORD2_MODE_UMASK;
  1011. len += 8;
  1012. } else if (attrmask[1] & FATTR4_WORD1_MODE) {
  1013. bmval[1] |= FATTR4_WORD1_MODE;
  1014. len += 4;
  1015. }
  1016. }
  1017. if ((iap->ia_valid & ATTR_UID) && (attrmask[1] & FATTR4_WORD1_OWNER)) {
  1018. owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
  1019. if (owner_namelen < 0) {
  1020. dprintk("nfs: couldn't resolve uid %d to string\n",
  1021. from_kuid(&init_user_ns, iap->ia_uid));
  1022. /* XXX */
  1023. strcpy(owner_name, "nobody");
  1024. owner_namelen = sizeof("nobody") - 1;
  1025. /* goto out; */
  1026. }
  1027. bmval[1] |= FATTR4_WORD1_OWNER;
  1028. len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
  1029. }
  1030. if ((iap->ia_valid & ATTR_GID) &&
  1031. (attrmask[1] & FATTR4_WORD1_OWNER_GROUP)) {
  1032. owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
  1033. if (owner_grouplen < 0) {
  1034. dprintk("nfs: couldn't resolve gid %d to string\n",
  1035. from_kgid(&init_user_ns, iap->ia_gid));
  1036. strcpy(owner_group, "nobody");
  1037. owner_grouplen = sizeof("nobody") - 1;
  1038. /* goto out; */
  1039. }
  1040. bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
  1041. len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
  1042. }
  1043. if (attrmask[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
  1044. if (iap->ia_valid & ATTR_ATIME_SET) {
  1045. bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
  1046. len += 16;
  1047. } else if (iap->ia_valid & ATTR_ATIME) {
  1048. bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
  1049. len += 4;
  1050. }
  1051. }
  1052. if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
  1053. if (iap->ia_valid & ATTR_MTIME_SET) {
  1054. bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
  1055. len += 16;
  1056. } else if (iap->ia_valid & ATTR_MTIME) {
  1057. bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
  1058. len += 4;
  1059. }
  1060. }
  1061. if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) {
  1062. len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
  1063. bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
  1064. }
  1065. if (bmval[2] != 0)
  1066. bmval_len = 3;
  1067. else if (bmval[1] != 0)
  1068. bmval_len = 2;
  1069. else
  1070. bmval_len = 1;
  1071. p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
  1072. *p++ = cpu_to_be32(bmval_len);
  1073. for (i = 0; i < bmval_len; i++)
  1074. *p++ = cpu_to_be32(bmval[i]);
  1075. *p++ = cpu_to_be32(len);
  1076. if (bmval[0] & FATTR4_WORD0_SIZE)
  1077. p = xdr_encode_hyper(p, iap->ia_size);
  1078. if (bmval[1] & FATTR4_WORD1_MODE)
  1079. *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
  1080. if (bmval[1] & FATTR4_WORD1_OWNER)
  1081. p = xdr_encode_opaque(p, owner_name, owner_namelen);
  1082. if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
  1083. p = xdr_encode_opaque(p, owner_group, owner_grouplen);
  1084. if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
  1085. if (iap->ia_valid & ATTR_ATIME_SET) {
  1086. *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
  1087. p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
  1088. *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
  1089. } else
  1090. *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
  1091. }
  1092. if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
  1093. if (iap->ia_valid & ATTR_MTIME_SET) {
  1094. *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
  1095. p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
  1096. *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
  1097. } else
  1098. *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
  1099. }
  1100. if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
  1101. *p++ = cpu_to_be32(label->lfs);
  1102. *p++ = cpu_to_be32(label->pi);
  1103. *p++ = cpu_to_be32(label->len);
  1104. p = xdr_encode_opaque_fixed(p, label->label, label->len);
  1105. }
  1106. if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
  1107. *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
  1108. *p++ = cpu_to_be32(*umask);
  1109. }
  1110. /* out: */
  1111. }
  1112. static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
  1113. {
  1114. encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
  1115. encode_uint32(xdr, access);
  1116. }
  1117. static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
  1118. {
  1119. encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
  1120. encode_nfs4_seqid(xdr, arg->seqid);
  1121. encode_nfs4_stateid(xdr, &arg->stateid);
  1122. }
  1123. static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
  1124. {
  1125. __be32 *p;
  1126. encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
  1127. p = reserve_space(xdr, 12);
  1128. p = xdr_encode_hyper(p, args->offset);
  1129. *p = cpu_to_be32(args->count);
  1130. }
  1131. static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
  1132. {
  1133. __be32 *p;
  1134. encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
  1135. encode_uint32(xdr, create->ftype);
  1136. switch (create->ftype) {
  1137. case NF4LNK:
  1138. p = reserve_space(xdr, 4);
  1139. *p = cpu_to_be32(create->u.symlink.len);
  1140. xdr_write_pages(xdr, create->u.symlink.pages, 0,
  1141. create->u.symlink.len);
  1142. xdr->buf->flags |= XDRBUF_WRITE;
  1143. break;
  1144. case NF4BLK: case NF4CHR:
  1145. p = reserve_space(xdr, 8);
  1146. *p++ = cpu_to_be32(create->u.device.specdata1);
  1147. *p = cpu_to_be32(create->u.device.specdata2);
  1148. break;
  1149. default:
  1150. break;
  1151. }
  1152. encode_string(xdr, create->name->len, create->name->name);
  1153. encode_attrs(xdr, create->attrs, create->label, &create->umask,
  1154. create->server, create->server->attr_bitmask);
  1155. }
  1156. static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
  1157. {
  1158. __be32 *p;
  1159. encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
  1160. p = reserve_space(xdr, 8);
  1161. *p++ = cpu_to_be32(1);
  1162. *p = cpu_to_be32(bitmap);
  1163. }
  1164. static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
  1165. {
  1166. __be32 *p;
  1167. encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
  1168. p = reserve_space(xdr, 12);
  1169. *p++ = cpu_to_be32(2);
  1170. *p++ = cpu_to_be32(bm0);
  1171. *p = cpu_to_be32(bm1);
  1172. }
  1173. static void
  1174. encode_getattr_three(struct xdr_stream *xdr,
  1175. uint32_t bm0, uint32_t bm1, uint32_t bm2,
  1176. struct compound_hdr *hdr)
  1177. {
  1178. __be32 *p;
  1179. encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
  1180. if (bm2) {
  1181. p = reserve_space(xdr, 16);
  1182. *p++ = cpu_to_be32(3);
  1183. *p++ = cpu_to_be32(bm0);
  1184. *p++ = cpu_to_be32(bm1);
  1185. *p = cpu_to_be32(bm2);
  1186. } else if (bm1) {
  1187. p = reserve_space(xdr, 12);
  1188. *p++ = cpu_to_be32(2);
  1189. *p++ = cpu_to_be32(bm0);
  1190. *p = cpu_to_be32(bm1);
  1191. } else {
  1192. p = reserve_space(xdr, 8);
  1193. *p++ = cpu_to_be32(1);
  1194. *p = cpu_to_be32(bm0);
  1195. }
  1196. }
  1197. static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
  1198. {
  1199. encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
  1200. bitmask[1] & nfs4_fattr_bitmap[1],
  1201. bitmask[2] & nfs4_fattr_bitmap[2],
  1202. hdr);
  1203. }
  1204. static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
  1205. const u32 *open_bitmap,
  1206. struct compound_hdr *hdr)
  1207. {
  1208. encode_getattr_three(xdr,
  1209. bitmask[0] & open_bitmap[0],
  1210. bitmask[1] & open_bitmap[1],
  1211. bitmask[2] & open_bitmap[2],
  1212. hdr);
  1213. }
  1214. static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
  1215. {
  1216. encode_getattr_three(xdr,
  1217. bitmask[0] & nfs4_fsinfo_bitmap[0],
  1218. bitmask[1] & nfs4_fsinfo_bitmap[1],
  1219. bitmask[2] & nfs4_fsinfo_bitmap[2],
  1220. hdr);
  1221. }
  1222. static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
  1223. {
  1224. encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
  1225. bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
  1226. }
  1227. static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
  1228. {
  1229. encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
  1230. }
  1231. static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
  1232. {
  1233. encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
  1234. encode_string(xdr, name->len, name->name);
  1235. }
  1236. static inline int nfs4_lock_type(struct file_lock *fl, int block)
  1237. {
  1238. if (fl->fl_type == F_RDLCK)
  1239. return block ? NFS4_READW_LT : NFS4_READ_LT;
  1240. return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
  1241. }
  1242. static inline uint64_t nfs4_lock_length(struct file_lock *fl)
  1243. {
  1244. if (fl->fl_end == OFFSET_MAX)
  1245. return ~(uint64_t)0;
  1246. return fl->fl_end - fl->fl_start + 1;
  1247. }
  1248. static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
  1249. {
  1250. __be32 *p;
  1251. p = reserve_space(xdr, 32);
  1252. p = xdr_encode_hyper(p, lowner->clientid);
  1253. *p++ = cpu_to_be32(20);
  1254. p = xdr_encode_opaque_fixed(p, "lock id:", 8);
  1255. *p++ = cpu_to_be32(lowner->s_dev);
  1256. xdr_encode_hyper(p, lowner->id);
  1257. }
  1258. /*
  1259. * opcode,type,reclaim,offset,length,new_lock_owner = 32
  1260. * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
  1261. */
  1262. static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
  1263. {
  1264. __be32 *p;
  1265. encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
  1266. p = reserve_space(xdr, 28);
  1267. *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
  1268. *p++ = cpu_to_be32(args->reclaim);
  1269. p = xdr_encode_hyper(p, args->fl->fl_start);
  1270. p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
  1271. *p = cpu_to_be32(args->new_lock_owner);
  1272. if (args->new_lock_owner){
  1273. encode_nfs4_seqid(xdr, args->open_seqid);
  1274. encode_nfs4_stateid(xdr, &args->open_stateid);
  1275. encode_nfs4_seqid(xdr, args->lock_seqid);
  1276. encode_lockowner(xdr, &args->lock_owner);
  1277. }
  1278. else {
  1279. encode_nfs4_stateid(xdr, &args->lock_stateid);
  1280. encode_nfs4_seqid(xdr, args->lock_seqid);
  1281. }
  1282. }
  1283. static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
  1284. {
  1285. __be32 *p;
  1286. encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
  1287. p = reserve_space(xdr, 20);
  1288. *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
  1289. p = xdr_encode_hyper(p, args->fl->fl_start);
  1290. p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
  1291. encode_lockowner(xdr, &args->lock_owner);
  1292. }
  1293. static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
  1294. {
  1295. __be32 *p;
  1296. encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
  1297. encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
  1298. encode_nfs4_seqid(xdr, args->seqid);
  1299. encode_nfs4_stateid(xdr, &args->stateid);
  1300. p = reserve_space(xdr, 16);
  1301. p = xdr_encode_hyper(p, args->fl->fl_start);
  1302. xdr_encode_hyper(p, nfs4_lock_length(args->fl));
  1303. }
  1304. static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
  1305. {
  1306. encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
  1307. encode_lockowner(xdr, lowner);
  1308. }
  1309. static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
  1310. {
  1311. encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
  1312. encode_string(xdr, name->len, name->name);
  1313. }
  1314. static void encode_lookupp(struct xdr_stream *xdr, struct compound_hdr *hdr)
  1315. {
  1316. encode_op_hdr(xdr, OP_LOOKUPP, decode_lookupp_maxsz, hdr);
  1317. }
  1318. static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
  1319. {
  1320. __be32 *p;
  1321. p = reserve_space(xdr, 8);
  1322. *p++ = cpu_to_be32(share_access);
  1323. *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
  1324. }
  1325. static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
  1326. {
  1327. __be32 *p;
  1328. /*
  1329. * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
  1330. * owner 4 = 32
  1331. */
  1332. encode_nfs4_seqid(xdr, arg->seqid);
  1333. encode_share_access(xdr, arg->share_access);
  1334. p = reserve_space(xdr, 36);
  1335. p = xdr_encode_hyper(p, arg->clientid);
  1336. *p++ = cpu_to_be32(24);
  1337. p = xdr_encode_opaque_fixed(p, "open id:", 8);
  1338. *p++ = cpu_to_be32(arg->server->s_dev);
  1339. *p++ = cpu_to_be32(arg->id.uniquifier);
  1340. xdr_encode_hyper(p, arg->id.create_time);
  1341. }
  1342. static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
  1343. {
  1344. __be32 *p;
  1345. p = reserve_space(xdr, 4);
  1346. switch(arg->createmode) {
  1347. case NFS4_CREATE_UNCHECKED:
  1348. *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
  1349. encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
  1350. arg->server, arg->server->attr_bitmask);
  1351. break;
  1352. case NFS4_CREATE_GUARDED:
  1353. *p = cpu_to_be32(NFS4_CREATE_GUARDED);
  1354. encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
  1355. arg->server, arg->server->attr_bitmask);
  1356. break;
  1357. case NFS4_CREATE_EXCLUSIVE:
  1358. *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
  1359. encode_nfs4_verifier(xdr, &arg->u.verifier);
  1360. break;
  1361. case NFS4_CREATE_EXCLUSIVE4_1:
  1362. *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
  1363. encode_nfs4_verifier(xdr, &arg->u.verifier);
  1364. encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
  1365. arg->server, arg->server->exclcreat_bitmask);
  1366. }
  1367. }
  1368. static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
  1369. {
  1370. __be32 *p;
  1371. p = reserve_space(xdr, 4);
  1372. switch (arg->open_flags & O_CREAT) {
  1373. case 0:
  1374. *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
  1375. break;
  1376. default:
  1377. *p = cpu_to_be32(NFS4_OPEN_CREATE);
  1378. encode_createmode(xdr, arg);
  1379. }
  1380. }
  1381. static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
  1382. {
  1383. __be32 *p;
  1384. p = reserve_space(xdr, 4);
  1385. switch (delegation_type) {
  1386. case 0:
  1387. *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
  1388. break;
  1389. case FMODE_READ:
  1390. *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
  1391. break;
  1392. case FMODE_WRITE|FMODE_READ:
  1393. *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
  1394. break;
  1395. default:
  1396. BUG();
  1397. }
  1398. }
  1399. static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
  1400. {
  1401. __be32 *p;
  1402. p = reserve_space(xdr, 4);
  1403. *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
  1404. encode_string(xdr, name->len, name->name);
  1405. }
  1406. static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
  1407. {
  1408. __be32 *p;
  1409. p = reserve_space(xdr, 4);
  1410. *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
  1411. encode_delegation_type(xdr, type);
  1412. }
  1413. static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
  1414. {
  1415. __be32 *p;
  1416. p = reserve_space(xdr, 4);
  1417. *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
  1418. encode_nfs4_stateid(xdr, stateid);
  1419. encode_string(xdr, name->len, name->name);
  1420. }
  1421. static inline void encode_claim_fh(struct xdr_stream *xdr)
  1422. {
  1423. __be32 *p;
  1424. p = reserve_space(xdr, 4);
  1425. *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
  1426. }
  1427. static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
  1428. {
  1429. __be32 *p;
  1430. p = reserve_space(xdr, 4);
  1431. *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
  1432. encode_nfs4_stateid(xdr, stateid);
  1433. }
  1434. static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
  1435. {
  1436. encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
  1437. encode_openhdr(xdr, arg);
  1438. encode_opentype(xdr, arg);
  1439. switch (arg->claim) {
  1440. case NFS4_OPEN_CLAIM_NULL:
  1441. encode_claim_null(xdr, arg->name);
  1442. break;
  1443. case NFS4_OPEN_CLAIM_PREVIOUS:
  1444. encode_claim_previous(xdr, arg->u.delegation_type);
  1445. break;
  1446. case NFS4_OPEN_CLAIM_DELEGATE_CUR:
  1447. encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
  1448. break;
  1449. case NFS4_OPEN_CLAIM_FH:
  1450. encode_claim_fh(xdr);
  1451. break;
  1452. case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
  1453. encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
  1454. break;
  1455. default:
  1456. BUG();
  1457. }
  1458. }
  1459. static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
  1460. {
  1461. encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
  1462. encode_nfs4_stateid(xdr, arg->stateid);
  1463. encode_nfs4_seqid(xdr, arg->seqid);
  1464. }
  1465. static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
  1466. {
  1467. encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
  1468. encode_nfs4_stateid(xdr, &arg->stateid);
  1469. encode_nfs4_seqid(xdr, arg->seqid);
  1470. encode_share_access(xdr, arg->share_access);
  1471. }
  1472. static void
  1473. encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
  1474. {
  1475. encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
  1476. encode_string(xdr, fh->size, fh->data);
  1477. }
  1478. static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
  1479. {
  1480. encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
  1481. }
  1482. static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
  1483. struct compound_hdr *hdr)
  1484. {
  1485. __be32 *p;
  1486. encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
  1487. encode_nfs4_stateid(xdr, &args->stateid);
  1488. p = reserve_space(xdr, 12);
  1489. p = xdr_encode_hyper(p, args->offset);
  1490. *p = cpu_to_be32(args->count);
  1491. }
  1492. static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
  1493. {
  1494. uint32_t attrs[3] = {
  1495. FATTR4_WORD0_RDATTR_ERROR,
  1496. FATTR4_WORD1_MOUNTED_ON_FILEID,
  1497. };
  1498. uint32_t dircount = readdir->count >> 1;
  1499. __be32 *p, verf[2];
  1500. uint32_t attrlen = 0;
  1501. unsigned int i;
  1502. if (readdir->plus) {
  1503. attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
  1504. FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
  1505. attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
  1506. FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
  1507. FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
  1508. FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
  1509. attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
  1510. dircount >>= 1;
  1511. }
  1512. /* Use mounted_on_fileid only if the server supports it */
  1513. if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
  1514. attrs[0] |= FATTR4_WORD0_FILEID;
  1515. for (i = 0; i < ARRAY_SIZE(attrs); i++) {
  1516. attrs[i] &= readdir->bitmask[i];
  1517. if (attrs[i] != 0)
  1518. attrlen = i+1;
  1519. }
  1520. encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
  1521. encode_uint64(xdr, readdir->cookie);
  1522. encode_nfs4_verifier(xdr, &readdir->verifier);
  1523. p = reserve_space(xdr, 12 + (attrlen << 2));
  1524. *p++ = cpu_to_be32(dircount);
  1525. *p++ = cpu_to_be32(readdir->count);
  1526. *p++ = cpu_to_be32(attrlen);
  1527. for (i = 0; i < attrlen; i++)
  1528. *p++ = cpu_to_be32(attrs[i]);
  1529. memcpy(verf, readdir->verifier.data, sizeof(verf));
  1530. dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
  1531. __func__,
  1532. (unsigned long long)readdir->cookie,
  1533. verf[0], verf[1],
  1534. attrs[0] & readdir->bitmask[0],
  1535. attrs[1] & readdir->bitmask[1],
  1536. attrs[2] & readdir->bitmask[2]);
  1537. }
  1538. static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
  1539. {
  1540. encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
  1541. }
  1542. static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
  1543. {
  1544. encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
  1545. encode_string(xdr, name->len, name->name);
  1546. }
  1547. static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
  1548. {
  1549. encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
  1550. encode_string(xdr, oldname->len, oldname->name);
  1551. encode_string(xdr, newname->len, newname->name);
  1552. }
  1553. static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
  1554. struct compound_hdr *hdr)
  1555. {
  1556. encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
  1557. encode_uint64(xdr, clid);
  1558. }
  1559. static void
  1560. encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
  1561. {
  1562. encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
  1563. }
  1564. static void
  1565. encode_setacl(struct xdr_stream *xdr, const struct nfs_setaclargs *arg,
  1566. struct compound_hdr *hdr)
  1567. {
  1568. __be32 *p;
  1569. encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
  1570. encode_nfs4_stateid(xdr, &zero_stateid);
  1571. p = reserve_space(xdr, 2*4);
  1572. *p++ = cpu_to_be32(1);
  1573. *p = cpu_to_be32(FATTR4_WORD0_ACL);
  1574. p = reserve_space(xdr, 4);
  1575. *p = cpu_to_be32(arg->acl_len);
  1576. xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
  1577. }
  1578. static void
  1579. encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
  1580. {
  1581. encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
  1582. }
  1583. static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
  1584. {
  1585. encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
  1586. encode_nfs4_stateid(xdr, &arg->stateid);
  1587. encode_attrs(xdr, arg->iap, arg->label, NULL, server,
  1588. server->attr_bitmask);
  1589. }
  1590. static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
  1591. {
  1592. __be32 *p;
  1593. encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
  1594. encode_nfs4_verifier(xdr, setclientid->sc_verifier);
  1595. encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
  1596. setclientid->sc_clnt->cl_owner_id);
  1597. p = reserve_space(xdr, 4);
  1598. *p = cpu_to_be32(setclientid->sc_prog);
  1599. encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
  1600. encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
  1601. p = reserve_space(xdr, 4);
  1602. *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
  1603. }
  1604. static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
  1605. {
  1606. encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
  1607. decode_setclientid_confirm_maxsz, hdr);
  1608. encode_uint64(xdr, arg->clientid);
  1609. encode_nfs4_verifier(xdr, &arg->confirm);
  1610. }
  1611. static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
  1612. struct compound_hdr *hdr)
  1613. {
  1614. __be32 *p;
  1615. encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
  1616. encode_nfs4_stateid(xdr, &args->stateid);
  1617. p = reserve_space(xdr, 16);
  1618. p = xdr_encode_hyper(p, args->offset);
  1619. *p++ = cpu_to_be32(args->stable);
  1620. *p = cpu_to_be32(args->count);
  1621. xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
  1622. }
  1623. static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
  1624. {
  1625. encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
  1626. encode_nfs4_stateid(xdr, stateid);
  1627. }
  1628. static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
  1629. {
  1630. encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
  1631. encode_string(xdr, name->len, name->name);
  1632. }
  1633. #if defined(CONFIG_NFS_V4_1)
  1634. /* NFSv4.1 operations */
  1635. static void encode_bind_conn_to_session(struct xdr_stream *xdr,
  1636. const struct nfs41_bind_conn_to_session_args *args,
  1637. struct compound_hdr *hdr)
  1638. {
  1639. __be32 *p;
  1640. encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
  1641. decode_bind_conn_to_session_maxsz, hdr);
  1642. encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
  1643. p = xdr_reserve_space(xdr, 8);
  1644. *p++ = cpu_to_be32(args->dir);
  1645. *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
  1646. }
  1647. static void encode_op_map(struct xdr_stream *xdr, const struct nfs4_op_map *op_map)
  1648. {
  1649. unsigned int i;
  1650. encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
  1651. for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
  1652. encode_uint32(xdr, op_map->u.words[i]);
  1653. }
  1654. static void encode_exchange_id(struct xdr_stream *xdr,
  1655. const struct nfs41_exchange_id_args *args,
  1656. struct compound_hdr *hdr)
  1657. {
  1658. __be32 *p;
  1659. char impl_name[IMPL_NAME_LIMIT];
  1660. int len = 0;
  1661. encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
  1662. encode_nfs4_verifier(xdr, &args->verifier);
  1663. encode_string(xdr, strlen(args->client->cl_owner_id),
  1664. args->client->cl_owner_id);
  1665. encode_uint32(xdr, args->flags);
  1666. encode_uint32(xdr, args->state_protect.how);
  1667. switch (args->state_protect.how) {
  1668. case SP4_NONE:
  1669. break;
  1670. case SP4_MACH_CRED:
  1671. encode_op_map(xdr, &args->state_protect.enforce);
  1672. encode_op_map(xdr, &args->state_protect.allow);
  1673. break;
  1674. default:
  1675. WARN_ON_ONCE(1);
  1676. break;
  1677. }
  1678. if (send_implementation_id &&
  1679. sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
  1680. sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
  1681. <= sizeof(impl_name) + 1)
  1682. len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
  1683. utsname()->sysname, utsname()->release,
  1684. utsname()->version, utsname()->machine);
  1685. if (len > 0) {
  1686. encode_uint32(xdr, 1); /* implementation id array length=1 */
  1687. encode_string(xdr,
  1688. sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
  1689. CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
  1690. encode_string(xdr, len, impl_name);
  1691. /* just send zeros for nii_date - the date is in nii_name */
  1692. p = reserve_space(xdr, 12);
  1693. p = xdr_encode_hyper(p, 0);
  1694. *p = cpu_to_be32(0);
  1695. } else
  1696. encode_uint32(xdr, 0); /* implementation id array length=0 */
  1697. }
  1698. static void encode_create_session(struct xdr_stream *xdr,
  1699. const struct nfs41_create_session_args *args,
  1700. struct compound_hdr *hdr)
  1701. {
  1702. __be32 *p;
  1703. struct nfs_client *clp = args->client;
  1704. struct rpc_clnt *clnt = clp->cl_rpcclient;
  1705. struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
  1706. u32 max_resp_sz_cached;
  1707. /*
  1708. * Assumes OPEN is the biggest non-idempotent compound.
  1709. * 2 is the verifier.
  1710. */
  1711. max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 2)
  1712. * XDR_UNIT + RPC_MAX_AUTH_SIZE;
  1713. encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
  1714. p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
  1715. p = xdr_encode_hyper(p, args->clientid);
  1716. *p++ = cpu_to_be32(args->seqid); /*Sequence id */
  1717. *p++ = cpu_to_be32(args->flags); /*flags */
  1718. /* Fore Channel */
  1719. *p++ = cpu_to_be32(0); /* header padding size */
  1720. *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
  1721. *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
  1722. *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
  1723. *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
  1724. *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
  1725. *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
  1726. /* Back Channel */
  1727. *p++ = cpu_to_be32(0); /* header padding size */
  1728. *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
  1729. *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
  1730. *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
  1731. *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
  1732. *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
  1733. *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
  1734. *p++ = cpu_to_be32(args->cb_program); /* cb_program */
  1735. *p++ = cpu_to_be32(1);
  1736. *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
  1737. /* authsys_parms rfc1831 */
  1738. *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */
  1739. p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
  1740. *p++ = cpu_to_be32(0); /* UID */
  1741. *p++ = cpu_to_be32(0); /* GID */
  1742. *p = cpu_to_be32(0); /* No more gids */
  1743. }
  1744. static void encode_destroy_session(struct xdr_stream *xdr,
  1745. const struct nfs4_session *session,
  1746. struct compound_hdr *hdr)
  1747. {
  1748. encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
  1749. encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
  1750. }
  1751. static void encode_destroy_clientid(struct xdr_stream *xdr,
  1752. uint64_t clientid,
  1753. struct compound_hdr *hdr)
  1754. {
  1755. encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
  1756. encode_uint64(xdr, clientid);
  1757. }
  1758. static void encode_reclaim_complete(struct xdr_stream *xdr,
  1759. const struct nfs41_reclaim_complete_args *args,
  1760. struct compound_hdr *hdr)
  1761. {
  1762. encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
  1763. encode_uint32(xdr, args->one_fs);
  1764. }
  1765. #endif /* CONFIG_NFS_V4_1 */
  1766. static void encode_sequence(struct xdr_stream *xdr,
  1767. const struct nfs4_sequence_args *args,
  1768. struct compound_hdr *hdr)
  1769. {
  1770. #if defined(CONFIG_NFS_V4_1)
  1771. struct nfs4_session *session;
  1772. struct nfs4_slot_table *tp;
  1773. struct nfs4_slot *slot = args->sa_slot;
  1774. __be32 *p;
  1775. tp = slot->table;
  1776. session = tp->session;
  1777. if (!session)
  1778. return;
  1779. encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
  1780. /*
  1781. * Sessionid + seqid + slotid + max slotid + cache_this
  1782. */
  1783. dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
  1784. "max_slotid=%d cache_this=%d\n",
  1785. __func__,
  1786. ((u32 *)session->sess_id.data)[0],
  1787. ((u32 *)session->sess_id.data)[1],
  1788. ((u32 *)session->sess_id.data)[2],
  1789. ((u32 *)session->sess_id.data)[3],
  1790. slot->seq_nr, slot->slot_nr,
  1791. tp->highest_used_slotid, args->sa_cache_this);
  1792. p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
  1793. p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
  1794. *p++ = cpu_to_be32(slot->seq_nr);
  1795. *p++ = cpu_to_be32(slot->slot_nr);
  1796. *p++ = cpu_to_be32(tp->highest_used_slotid);
  1797. *p = cpu_to_be32(args->sa_cache_this);
  1798. #endif /* CONFIG_NFS_V4_1 */
  1799. }
  1800. #ifdef CONFIG_NFS_V4_1
  1801. static void
  1802. encode_getdeviceinfo(struct xdr_stream *xdr,
  1803. const struct nfs4_getdeviceinfo_args *args,
  1804. struct compound_hdr *hdr)
  1805. {
  1806. __be32 *p;
  1807. encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
  1808. p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
  1809. p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
  1810. NFS4_DEVICEID4_SIZE);
  1811. *p++ = cpu_to_be32(args->pdev->layout_type);
  1812. *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
  1813. p = reserve_space(xdr, 4 + 4);
  1814. *p++ = cpu_to_be32(1); /* bitmap length */
  1815. *p++ = cpu_to_be32(args->notify_types);
  1816. }
  1817. static void
  1818. encode_layoutget(struct xdr_stream *xdr,
  1819. const struct nfs4_layoutget_args *args,
  1820. struct compound_hdr *hdr)
  1821. {
  1822. __be32 *p;
  1823. encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
  1824. p = reserve_space(xdr, 36);
  1825. *p++ = cpu_to_be32(0); /* Signal layout available */
  1826. *p++ = cpu_to_be32(args->type);
  1827. *p++ = cpu_to_be32(args->range.iomode);
  1828. p = xdr_encode_hyper(p, args->range.offset);
  1829. p = xdr_encode_hyper(p, args->range.length);
  1830. p = xdr_encode_hyper(p, args->minlength);
  1831. encode_nfs4_stateid(xdr, &args->stateid);
  1832. encode_uint32(xdr, args->maxcount);
  1833. dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
  1834. __func__,
  1835. args->type,
  1836. args->range.iomode,
  1837. (unsigned long)args->range.offset,
  1838. (unsigned long)args->range.length,
  1839. args->maxcount);
  1840. }
  1841. static int
  1842. encode_layoutcommit(struct xdr_stream *xdr,
  1843. struct inode *inode,
  1844. const struct nfs4_layoutcommit_args *args,
  1845. struct compound_hdr *hdr)
  1846. {
  1847. __be32 *p;
  1848. dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
  1849. NFS_SERVER(args->inode)->pnfs_curr_ld->id);
  1850. encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
  1851. p = reserve_space(xdr, 20);
  1852. /* Only whole file layouts */
  1853. p = xdr_encode_hyper(p, 0); /* offset */
  1854. p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
  1855. *p = cpu_to_be32(0); /* reclaim */
  1856. encode_nfs4_stateid(xdr, &args->stateid);
  1857. if (args->lastbytewritten != U64_MAX) {
  1858. p = reserve_space(xdr, 20);
  1859. *p++ = cpu_to_be32(1); /* newoffset = TRUE */
  1860. p = xdr_encode_hyper(p, args->lastbytewritten);
  1861. } else {
  1862. p = reserve_space(xdr, 12);
  1863. *p++ = cpu_to_be32(0); /* newoffset = FALSE */
  1864. }
  1865. *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
  1866. *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
  1867. encode_uint32(xdr, args->layoutupdate_len);
  1868. if (args->layoutupdate_pages)
  1869. xdr_write_pages(xdr, args->layoutupdate_pages, 0,
  1870. args->layoutupdate_len);
  1871. return 0;
  1872. }
  1873. static void
  1874. encode_layoutreturn(struct xdr_stream *xdr,
  1875. const struct nfs4_layoutreturn_args *args,
  1876. struct compound_hdr *hdr)
  1877. {
  1878. __be32 *p;
  1879. encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
  1880. p = reserve_space(xdr, 16);
  1881. *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
  1882. *p++ = cpu_to_be32(args->layout_type);
  1883. *p++ = cpu_to_be32(args->range.iomode);
  1884. *p = cpu_to_be32(RETURN_FILE);
  1885. p = reserve_space(xdr, 16);
  1886. p = xdr_encode_hyper(p, args->range.offset);
  1887. p = xdr_encode_hyper(p, args->range.length);
  1888. spin_lock(&args->inode->i_lock);
  1889. encode_nfs4_stateid(xdr, &args->stateid);
  1890. spin_unlock(&args->inode->i_lock);
  1891. if (args->ld_private->ops && args->ld_private->ops->encode)
  1892. args->ld_private->ops->encode(xdr, args, args->ld_private);
  1893. else
  1894. encode_uint32(xdr, 0);
  1895. }
  1896. static int
  1897. encode_secinfo_no_name(struct xdr_stream *xdr,
  1898. const struct nfs41_secinfo_no_name_args *args,
  1899. struct compound_hdr *hdr)
  1900. {
  1901. encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
  1902. encode_uint32(xdr, args->style);
  1903. return 0;
  1904. }
  1905. static void encode_test_stateid(struct xdr_stream *xdr,
  1906. const struct nfs41_test_stateid_args *args,
  1907. struct compound_hdr *hdr)
  1908. {
  1909. encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
  1910. encode_uint32(xdr, 1);
  1911. encode_nfs4_stateid(xdr, args->stateid);
  1912. }
  1913. static void encode_free_stateid(struct xdr_stream *xdr,
  1914. const struct nfs41_free_stateid_args *args,
  1915. struct compound_hdr *hdr)
  1916. {
  1917. encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
  1918. encode_nfs4_stateid(xdr, &args->stateid);
  1919. }
  1920. #else
  1921. static inline void
  1922. encode_layoutreturn(struct xdr_stream *xdr,
  1923. const struct nfs4_layoutreturn_args *args,
  1924. struct compound_hdr *hdr)
  1925. {
  1926. }
  1927. #endif /* CONFIG_NFS_V4_1 */
  1928. /*
  1929. * END OF "GENERIC" ENCODE ROUTINES.
  1930. */
  1931. static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
  1932. {
  1933. #if defined(CONFIG_NFS_V4_1)
  1934. struct nfs4_session *session = args->sa_slot->table->session;
  1935. if (session)
  1936. return session->clp->cl_mvops->minor_version;
  1937. #endif /* CONFIG_NFS_V4_1 */
  1938. return 0;
  1939. }
  1940. /*
  1941. * Encode an ACCESS request
  1942. */
  1943. static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
  1944. const void *data)
  1945. {
  1946. const struct nfs4_accessargs *args = data;
  1947. struct compound_hdr hdr = {
  1948. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1949. };
  1950. encode_compound_hdr(xdr, req, &hdr);
  1951. encode_sequence(xdr, &args->seq_args, &hdr);
  1952. encode_putfh(xdr, args->fh, &hdr);
  1953. encode_access(xdr, args->access, &hdr);
  1954. encode_getfattr(xdr, args->bitmask, &hdr);
  1955. encode_nops(&hdr);
  1956. }
  1957. /*
  1958. * Encode LOOKUP request
  1959. */
  1960. static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
  1961. const void *data)
  1962. {
  1963. const struct nfs4_lookup_arg *args = data;
  1964. struct compound_hdr hdr = {
  1965. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1966. };
  1967. encode_compound_hdr(xdr, req, &hdr);
  1968. encode_sequence(xdr, &args->seq_args, &hdr);
  1969. encode_putfh(xdr, args->dir_fh, &hdr);
  1970. encode_lookup(xdr, args->name, &hdr);
  1971. encode_getfh(xdr, &hdr);
  1972. encode_getfattr(xdr, args->bitmask, &hdr);
  1973. encode_nops(&hdr);
  1974. }
  1975. /*
  1976. * Encode LOOKUPP request
  1977. */
  1978. static void nfs4_xdr_enc_lookupp(struct rpc_rqst *req, struct xdr_stream *xdr,
  1979. const void *data)
  1980. {
  1981. const struct nfs4_lookupp_arg *args = data;
  1982. struct compound_hdr hdr = {
  1983. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1984. };
  1985. encode_compound_hdr(xdr, req, &hdr);
  1986. encode_sequence(xdr, &args->seq_args, &hdr);
  1987. encode_putfh(xdr, args->fh, &hdr);
  1988. encode_lookupp(xdr, &hdr);
  1989. encode_getfh(xdr, &hdr);
  1990. encode_getfattr(xdr, args->bitmask, &hdr);
  1991. encode_nops(&hdr);
  1992. }
  1993. /*
  1994. * Encode LOOKUP_ROOT request
  1995. */
  1996. static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
  1997. struct xdr_stream *xdr,
  1998. const void *data)
  1999. {
  2000. const struct nfs4_lookup_root_arg *args = data;
  2001. struct compound_hdr hdr = {
  2002. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2003. };
  2004. encode_compound_hdr(xdr, req, &hdr);
  2005. encode_sequence(xdr, &args->seq_args, &hdr);
  2006. encode_putrootfh(xdr, &hdr);
  2007. encode_getfh(xdr, &hdr);
  2008. encode_getfattr(xdr, args->bitmask, &hdr);
  2009. encode_nops(&hdr);
  2010. }
  2011. /*
  2012. * Encode REMOVE request
  2013. */
  2014. static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
  2015. const void *data)
  2016. {
  2017. const struct nfs_removeargs *args = data;
  2018. struct compound_hdr hdr = {
  2019. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2020. };
  2021. encode_compound_hdr(xdr, req, &hdr);
  2022. encode_sequence(xdr, &args->seq_args, &hdr);
  2023. encode_putfh(xdr, args->fh, &hdr);
  2024. encode_remove(xdr, &args->name, &hdr);
  2025. encode_nops(&hdr);
  2026. }
  2027. /*
  2028. * Encode RENAME request
  2029. */
  2030. static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
  2031. const void *data)
  2032. {
  2033. const struct nfs_renameargs *args = data;
  2034. struct compound_hdr hdr = {
  2035. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2036. };
  2037. encode_compound_hdr(xdr, req, &hdr);
  2038. encode_sequence(xdr, &args->seq_args, &hdr);
  2039. encode_putfh(xdr, args->old_dir, &hdr);
  2040. encode_savefh(xdr, &hdr);
  2041. encode_putfh(xdr, args->new_dir, &hdr);
  2042. encode_rename(xdr, args->old_name, args->new_name, &hdr);
  2043. encode_nops(&hdr);
  2044. }
  2045. /*
  2046. * Encode LINK request
  2047. */
  2048. static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
  2049. const void *data)
  2050. {
  2051. const struct nfs4_link_arg *args = data;
  2052. struct compound_hdr hdr = {
  2053. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2054. };
  2055. encode_compound_hdr(xdr, req, &hdr);
  2056. encode_sequence(xdr, &args->seq_args, &hdr);
  2057. encode_putfh(xdr, args->fh, &hdr);
  2058. encode_savefh(xdr, &hdr);
  2059. encode_putfh(xdr, args->dir_fh, &hdr);
  2060. encode_link(xdr, args->name, &hdr);
  2061. encode_restorefh(xdr, &hdr);
  2062. encode_getfattr(xdr, args->bitmask, &hdr);
  2063. encode_nops(&hdr);
  2064. }
  2065. /*
  2066. * Encode CREATE request
  2067. */
  2068. static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
  2069. const void *data)
  2070. {
  2071. const struct nfs4_create_arg *args = data;
  2072. struct compound_hdr hdr = {
  2073. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2074. };
  2075. encode_compound_hdr(xdr, req, &hdr);
  2076. encode_sequence(xdr, &args->seq_args, &hdr);
  2077. encode_putfh(xdr, args->dir_fh, &hdr);
  2078. encode_create(xdr, args, &hdr);
  2079. encode_getfh(xdr, &hdr);
  2080. encode_getfattr(xdr, args->bitmask, &hdr);
  2081. encode_nops(&hdr);
  2082. }
  2083. /*
  2084. * Encode SYMLINK request
  2085. */
  2086. static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
  2087. const void *data)
  2088. {
  2089. const struct nfs4_create_arg *args = data;
  2090. nfs4_xdr_enc_create(req, xdr, args);
  2091. }
  2092. /*
  2093. * Encode GETATTR request
  2094. */
  2095. static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
  2096. const void *data)
  2097. {
  2098. const struct nfs4_getattr_arg *args = data;
  2099. struct compound_hdr hdr = {
  2100. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2101. };
  2102. encode_compound_hdr(xdr, req, &hdr);
  2103. encode_sequence(xdr, &args->seq_args, &hdr);
  2104. encode_putfh(xdr, args->fh, &hdr);
  2105. encode_getfattr(xdr, args->bitmask, &hdr);
  2106. encode_nops(&hdr);
  2107. }
  2108. /*
  2109. * Encode a CLOSE request
  2110. */
  2111. static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
  2112. const void *data)
  2113. {
  2114. const struct nfs_closeargs *args = data;
  2115. struct compound_hdr hdr = {
  2116. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2117. };
  2118. encode_compound_hdr(xdr, req, &hdr);
  2119. encode_sequence(xdr, &args->seq_args, &hdr);
  2120. encode_putfh(xdr, args->fh, &hdr);
  2121. if (args->lr_args)
  2122. encode_layoutreturn(xdr, args->lr_args, &hdr);
  2123. if (args->bitmask != NULL)
  2124. encode_getfattr(xdr, args->bitmask, &hdr);
  2125. encode_close(xdr, args, &hdr);
  2126. encode_nops(&hdr);
  2127. }
  2128. /*
  2129. * Encode an OPEN request
  2130. */
  2131. static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
  2132. const void *data)
  2133. {
  2134. const struct nfs_openargs *args = data;
  2135. struct compound_hdr hdr = {
  2136. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2137. };
  2138. encode_compound_hdr(xdr, req, &hdr);
  2139. encode_sequence(xdr, &args->seq_args, &hdr);
  2140. encode_putfh(xdr, args->fh, &hdr);
  2141. encode_open(xdr, args, &hdr);
  2142. encode_getfh(xdr, &hdr);
  2143. if (args->access)
  2144. encode_access(xdr, args->access, &hdr);
  2145. encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
  2146. encode_nops(&hdr);
  2147. }
  2148. /*
  2149. * Encode an OPEN_CONFIRM request
  2150. */
  2151. static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
  2152. struct xdr_stream *xdr,
  2153. const void *data)
  2154. {
  2155. const struct nfs_open_confirmargs *args = data;
  2156. struct compound_hdr hdr = {
  2157. .nops = 0,
  2158. };
  2159. encode_compound_hdr(xdr, req, &hdr);
  2160. encode_putfh(xdr, args->fh, &hdr);
  2161. encode_open_confirm(xdr, args, &hdr);
  2162. encode_nops(&hdr);
  2163. }
  2164. /*
  2165. * Encode an OPEN request with no attributes.
  2166. */
  2167. static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
  2168. struct xdr_stream *xdr,
  2169. const void *data)
  2170. {
  2171. const struct nfs_openargs *args = data;
  2172. struct compound_hdr hdr = {
  2173. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2174. };
  2175. encode_compound_hdr(xdr, req, &hdr);
  2176. encode_sequence(xdr, &args->seq_args, &hdr);
  2177. encode_putfh(xdr, args->fh, &hdr);
  2178. encode_open(xdr, args, &hdr);
  2179. if (args->access)
  2180. encode_access(xdr, args->access, &hdr);
  2181. encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
  2182. encode_nops(&hdr);
  2183. }
  2184. /*
  2185. * Encode an OPEN_DOWNGRADE request
  2186. */
  2187. static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
  2188. struct xdr_stream *xdr,
  2189. const void *data)
  2190. {
  2191. const struct nfs_closeargs *args = data;
  2192. struct compound_hdr hdr = {
  2193. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2194. };
  2195. encode_compound_hdr(xdr, req, &hdr);
  2196. encode_sequence(xdr, &args->seq_args, &hdr);
  2197. encode_putfh(xdr, args->fh, &hdr);
  2198. if (args->lr_args)
  2199. encode_layoutreturn(xdr, args->lr_args, &hdr);
  2200. encode_open_downgrade(xdr, args, &hdr);
  2201. encode_nops(&hdr);
  2202. }
  2203. /*
  2204. * Encode a LOCK request
  2205. */
  2206. static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
  2207. const void *data)
  2208. {
  2209. const struct nfs_lock_args *args = data;
  2210. struct compound_hdr hdr = {
  2211. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2212. };
  2213. encode_compound_hdr(xdr, req, &hdr);
  2214. encode_sequence(xdr, &args->seq_args, &hdr);
  2215. encode_putfh(xdr, args->fh, &hdr);
  2216. encode_lock(xdr, args, &hdr);
  2217. encode_nops(&hdr);
  2218. }
  2219. /*
  2220. * Encode a LOCKT request
  2221. */
  2222. static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
  2223. const void *data)
  2224. {
  2225. const struct nfs_lockt_args *args = data;
  2226. struct compound_hdr hdr = {
  2227. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2228. };
  2229. encode_compound_hdr(xdr, req, &hdr);
  2230. encode_sequence(xdr, &args->seq_args, &hdr);
  2231. encode_putfh(xdr, args->fh, &hdr);
  2232. encode_lockt(xdr, args, &hdr);
  2233. encode_nops(&hdr);
  2234. }
  2235. /*
  2236. * Encode a LOCKU request
  2237. */
  2238. static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
  2239. const void *data)
  2240. {
  2241. const struct nfs_locku_args *args = data;
  2242. struct compound_hdr hdr = {
  2243. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2244. };
  2245. encode_compound_hdr(xdr, req, &hdr);
  2246. encode_sequence(xdr, &args->seq_args, &hdr);
  2247. encode_putfh(xdr, args->fh, &hdr);
  2248. encode_locku(xdr, args, &hdr);
  2249. encode_nops(&hdr);
  2250. }
  2251. static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
  2252. struct xdr_stream *xdr,
  2253. const void *data)
  2254. {
  2255. const struct nfs_release_lockowner_args *args = data;
  2256. struct compound_hdr hdr = {
  2257. .minorversion = 0,
  2258. };
  2259. encode_compound_hdr(xdr, req, &hdr);
  2260. encode_release_lockowner(xdr, &args->lock_owner, &hdr);
  2261. encode_nops(&hdr);
  2262. }
  2263. /*
  2264. * Encode a READLINK request
  2265. */
  2266. static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
  2267. const void *data)
  2268. {
  2269. const struct nfs4_readlink *args = data;
  2270. struct compound_hdr hdr = {
  2271. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2272. };
  2273. encode_compound_hdr(xdr, req, &hdr);
  2274. encode_sequence(xdr, &args->seq_args, &hdr);
  2275. encode_putfh(xdr, args->fh, &hdr);
  2276. encode_readlink(xdr, args, req, &hdr);
  2277. xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
  2278. args->pgbase, args->pglen);
  2279. encode_nops(&hdr);
  2280. }
  2281. /*
  2282. * Encode a READDIR request
  2283. */
  2284. static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
  2285. const void *data)
  2286. {
  2287. const struct nfs4_readdir_arg *args = data;
  2288. struct compound_hdr hdr = {
  2289. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2290. };
  2291. encode_compound_hdr(xdr, req, &hdr);
  2292. encode_sequence(xdr, &args->seq_args, &hdr);
  2293. encode_putfh(xdr, args->fh, &hdr);
  2294. encode_readdir(xdr, args, req, &hdr);
  2295. xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
  2296. args->pgbase, args->count);
  2297. dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
  2298. __func__, hdr.replen << 2, args->pages,
  2299. args->pgbase, args->count);
  2300. encode_nops(&hdr);
  2301. }
  2302. /*
  2303. * Encode a READ request
  2304. */
  2305. static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
  2306. const void *data)
  2307. {
  2308. const struct nfs_pgio_args *args = data;
  2309. struct compound_hdr hdr = {
  2310. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2311. };
  2312. encode_compound_hdr(xdr, req, &hdr);
  2313. encode_sequence(xdr, &args->seq_args, &hdr);
  2314. encode_putfh(xdr, args->fh, &hdr);
  2315. encode_read(xdr, args, &hdr);
  2316. xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
  2317. args->pages, args->pgbase, args->count);
  2318. req->rq_rcv_buf.flags |= XDRBUF_READ;
  2319. encode_nops(&hdr);
  2320. }
  2321. /*
  2322. * Encode an SETATTR request
  2323. */
  2324. static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
  2325. const void *data)
  2326. {
  2327. const struct nfs_setattrargs *args = data;
  2328. struct compound_hdr hdr = {
  2329. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2330. };
  2331. encode_compound_hdr(xdr, req, &hdr);
  2332. encode_sequence(xdr, &args->seq_args, &hdr);
  2333. encode_putfh(xdr, args->fh, &hdr);
  2334. encode_setattr(xdr, args, args->server, &hdr);
  2335. encode_getfattr(xdr, args->bitmask, &hdr);
  2336. encode_nops(&hdr);
  2337. }
  2338. /*
  2339. * Encode a GETACL request
  2340. */
  2341. static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
  2342. const void *data)
  2343. {
  2344. const struct nfs_getaclargs *args = data;
  2345. struct compound_hdr hdr = {
  2346. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2347. };
  2348. uint32_t replen;
  2349. encode_compound_hdr(xdr, req, &hdr);
  2350. encode_sequence(xdr, &args->seq_args, &hdr);
  2351. encode_putfh(xdr, args->fh, &hdr);
  2352. replen = hdr.replen + op_decode_hdr_maxsz;
  2353. encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
  2354. xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
  2355. args->acl_pages, 0, args->acl_len);
  2356. encode_nops(&hdr);
  2357. }
  2358. /*
  2359. * Encode a WRITE request
  2360. */
  2361. static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
  2362. const void *data)
  2363. {
  2364. const struct nfs_pgio_args *args = data;
  2365. struct compound_hdr hdr = {
  2366. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2367. };
  2368. encode_compound_hdr(xdr, req, &hdr);
  2369. encode_sequence(xdr, &args->seq_args, &hdr);
  2370. encode_putfh(xdr, args->fh, &hdr);
  2371. encode_write(xdr, args, &hdr);
  2372. req->rq_snd_buf.flags |= XDRBUF_WRITE;
  2373. if (args->bitmask)
  2374. encode_getfattr(xdr, args->bitmask, &hdr);
  2375. encode_nops(&hdr);
  2376. }
  2377. /*
  2378. * a COMMIT request
  2379. */
  2380. static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
  2381. const void *data)
  2382. {
  2383. const struct nfs_commitargs *args = data;
  2384. struct compound_hdr hdr = {
  2385. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2386. };
  2387. encode_compound_hdr(xdr, req, &hdr);
  2388. encode_sequence(xdr, &args->seq_args, &hdr);
  2389. encode_putfh(xdr, args->fh, &hdr);
  2390. encode_commit(xdr, args, &hdr);
  2391. encode_nops(&hdr);
  2392. }
  2393. /*
  2394. * FSINFO request
  2395. */
  2396. static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
  2397. const void *data)
  2398. {
  2399. const struct nfs4_fsinfo_arg *args = data;
  2400. struct compound_hdr hdr = {
  2401. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2402. };
  2403. encode_compound_hdr(xdr, req, &hdr);
  2404. encode_sequence(xdr, &args->seq_args, &hdr);
  2405. encode_putfh(xdr, args->fh, &hdr);
  2406. encode_fsinfo(xdr, args->bitmask, &hdr);
  2407. encode_nops(&hdr);
  2408. }
  2409. /*
  2410. * a PATHCONF request
  2411. */
  2412. static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
  2413. const void *data)
  2414. {
  2415. const struct nfs4_pathconf_arg *args = data;
  2416. struct compound_hdr hdr = {
  2417. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2418. };
  2419. encode_compound_hdr(xdr, req, &hdr);
  2420. encode_sequence(xdr, &args->seq_args, &hdr);
  2421. encode_putfh(xdr, args->fh, &hdr);
  2422. encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
  2423. &hdr);
  2424. encode_nops(&hdr);
  2425. }
  2426. /*
  2427. * a STATFS request
  2428. */
  2429. static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
  2430. const void *data)
  2431. {
  2432. const struct nfs4_statfs_arg *args = data;
  2433. struct compound_hdr hdr = {
  2434. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2435. };
  2436. encode_compound_hdr(xdr, req, &hdr);
  2437. encode_sequence(xdr, &args->seq_args, &hdr);
  2438. encode_putfh(xdr, args->fh, &hdr);
  2439. encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
  2440. args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
  2441. encode_nops(&hdr);
  2442. }
  2443. /*
  2444. * GETATTR_BITMAP request
  2445. */
  2446. static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
  2447. struct xdr_stream *xdr,
  2448. const void *data)
  2449. {
  2450. const struct nfs4_server_caps_arg *args = data;
  2451. const u32 *bitmask = args->bitmask;
  2452. struct compound_hdr hdr = {
  2453. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2454. };
  2455. encode_compound_hdr(xdr, req, &hdr);
  2456. encode_sequence(xdr, &args->seq_args, &hdr);
  2457. encode_putfh(xdr, args->fhandle, &hdr);
  2458. encode_getattr_three(xdr, bitmask[0], bitmask[1], bitmask[2], &hdr);
  2459. encode_nops(&hdr);
  2460. }
  2461. /*
  2462. * a RENEW request
  2463. */
  2464. static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
  2465. const void *data)
  2466. {
  2467. const struct nfs_client *clp = data;
  2468. struct compound_hdr hdr = {
  2469. .nops = 0,
  2470. };
  2471. encode_compound_hdr(xdr, req, &hdr);
  2472. encode_renew(xdr, clp->cl_clientid, &hdr);
  2473. encode_nops(&hdr);
  2474. }
  2475. /*
  2476. * a SETCLIENTID request
  2477. */
  2478. static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
  2479. struct xdr_stream *xdr,
  2480. const void *data)
  2481. {
  2482. const struct nfs4_setclientid *sc = data;
  2483. struct compound_hdr hdr = {
  2484. .nops = 0,
  2485. };
  2486. encode_compound_hdr(xdr, req, &hdr);
  2487. encode_setclientid(xdr, sc, &hdr);
  2488. encode_nops(&hdr);
  2489. }
  2490. /*
  2491. * a SETCLIENTID_CONFIRM request
  2492. */
  2493. static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
  2494. struct xdr_stream *xdr,
  2495. const void *data)
  2496. {
  2497. const struct nfs4_setclientid_res *arg = data;
  2498. struct compound_hdr hdr = {
  2499. .nops = 0,
  2500. };
  2501. encode_compound_hdr(xdr, req, &hdr);
  2502. encode_setclientid_confirm(xdr, arg, &hdr);
  2503. encode_nops(&hdr);
  2504. }
  2505. /*
  2506. * DELEGRETURN request
  2507. */
  2508. static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
  2509. struct xdr_stream *xdr,
  2510. const void *data)
  2511. {
  2512. const struct nfs4_delegreturnargs *args = data;
  2513. struct compound_hdr hdr = {
  2514. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2515. };
  2516. encode_compound_hdr(xdr, req, &hdr);
  2517. encode_sequence(xdr, &args->seq_args, &hdr);
  2518. encode_putfh(xdr, args->fhandle, &hdr);
  2519. if (args->lr_args)
  2520. encode_layoutreturn(xdr, args->lr_args, &hdr);
  2521. if (args->bitmask)
  2522. encode_getfattr(xdr, args->bitmask, &hdr);
  2523. encode_delegreturn(xdr, args->stateid, &hdr);
  2524. encode_nops(&hdr);
  2525. }
  2526. /*
  2527. * Encode FS_LOCATIONS request
  2528. */
  2529. static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
  2530. struct xdr_stream *xdr,
  2531. const void *data)
  2532. {
  2533. const struct nfs4_fs_locations_arg *args = data;
  2534. struct compound_hdr hdr = {
  2535. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2536. };
  2537. uint32_t replen;
  2538. encode_compound_hdr(xdr, req, &hdr);
  2539. encode_sequence(xdr, &args->seq_args, &hdr);
  2540. if (args->migration) {
  2541. encode_putfh(xdr, args->fh, &hdr);
  2542. replen = hdr.replen;
  2543. encode_fs_locations(xdr, args->bitmask, &hdr);
  2544. if (args->renew)
  2545. encode_renew(xdr, args->clientid, &hdr);
  2546. } else {
  2547. encode_putfh(xdr, args->dir_fh, &hdr);
  2548. encode_lookup(xdr, args->name, &hdr);
  2549. replen = hdr.replen;
  2550. encode_fs_locations(xdr, args->bitmask, &hdr);
  2551. }
  2552. /* Set up reply kvec to capture returned fs_locations array. */
  2553. xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
  2554. (struct page **)&args->page, 0, PAGE_SIZE);
  2555. encode_nops(&hdr);
  2556. }
  2557. /*
  2558. * Encode SECINFO request
  2559. */
  2560. static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
  2561. struct xdr_stream *xdr,
  2562. const void *data)
  2563. {
  2564. const struct nfs4_secinfo_arg *args = data;
  2565. struct compound_hdr hdr = {
  2566. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2567. };
  2568. encode_compound_hdr(xdr, req, &hdr);
  2569. encode_sequence(xdr, &args->seq_args, &hdr);
  2570. encode_putfh(xdr, args->dir_fh, &hdr);
  2571. encode_secinfo(xdr, args->name, &hdr);
  2572. encode_nops(&hdr);
  2573. }
  2574. /*
  2575. * Encode FSID_PRESENT request
  2576. */
  2577. static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
  2578. struct xdr_stream *xdr,
  2579. const void *data)
  2580. {
  2581. const struct nfs4_fsid_present_arg *args = data;
  2582. struct compound_hdr hdr = {
  2583. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2584. };
  2585. encode_compound_hdr(xdr, req, &hdr);
  2586. encode_sequence(xdr, &args->seq_args, &hdr);
  2587. encode_putfh(xdr, args->fh, &hdr);
  2588. encode_getfh(xdr, &hdr);
  2589. if (args->renew)
  2590. encode_renew(xdr, args->clientid, &hdr);
  2591. encode_nops(&hdr);
  2592. }
  2593. #if defined(CONFIG_NFS_V4_1)
  2594. /*
  2595. * BIND_CONN_TO_SESSION request
  2596. */
  2597. static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
  2598. struct xdr_stream *xdr,
  2599. const void *data)
  2600. {
  2601. const struct nfs41_bind_conn_to_session_args *args = data;
  2602. struct compound_hdr hdr = {
  2603. .minorversion = args->client->cl_mvops->minor_version,
  2604. };
  2605. encode_compound_hdr(xdr, req, &hdr);
  2606. encode_bind_conn_to_session(xdr, args, &hdr);
  2607. encode_nops(&hdr);
  2608. }
  2609. /*
  2610. * EXCHANGE_ID request
  2611. */
  2612. static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
  2613. struct xdr_stream *xdr,
  2614. const void *data)
  2615. {
  2616. const struct nfs41_exchange_id_args *args = data;
  2617. struct compound_hdr hdr = {
  2618. .minorversion = args->client->cl_mvops->minor_version,
  2619. };
  2620. encode_compound_hdr(xdr, req, &hdr);
  2621. encode_exchange_id(xdr, args, &hdr);
  2622. encode_nops(&hdr);
  2623. }
  2624. /*
  2625. * a CREATE_SESSION request
  2626. */
  2627. static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
  2628. struct xdr_stream *xdr,
  2629. const void *data)
  2630. {
  2631. const struct nfs41_create_session_args *args = data;
  2632. struct compound_hdr hdr = {
  2633. .minorversion = args->client->cl_mvops->minor_version,
  2634. };
  2635. encode_compound_hdr(xdr, req, &hdr);
  2636. encode_create_session(xdr, args, &hdr);
  2637. encode_nops(&hdr);
  2638. }
  2639. /*
  2640. * a DESTROY_SESSION request
  2641. */
  2642. static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
  2643. struct xdr_stream *xdr,
  2644. const void *data)
  2645. {
  2646. const struct nfs4_session *session = data;
  2647. struct compound_hdr hdr = {
  2648. .minorversion = session->clp->cl_mvops->minor_version,
  2649. };
  2650. encode_compound_hdr(xdr, req, &hdr);
  2651. encode_destroy_session(xdr, session, &hdr);
  2652. encode_nops(&hdr);
  2653. }
  2654. /*
  2655. * a DESTROY_CLIENTID request
  2656. */
  2657. static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
  2658. struct xdr_stream *xdr,
  2659. const void *data)
  2660. {
  2661. const struct nfs_client *clp = data;
  2662. struct compound_hdr hdr = {
  2663. .minorversion = clp->cl_mvops->minor_version,
  2664. };
  2665. encode_compound_hdr(xdr, req, &hdr);
  2666. encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
  2667. encode_nops(&hdr);
  2668. }
  2669. /*
  2670. * a SEQUENCE request
  2671. */
  2672. static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
  2673. const void *data)
  2674. {
  2675. const struct nfs4_sequence_args *args = data;
  2676. struct compound_hdr hdr = {
  2677. .minorversion = nfs4_xdr_minorversion(args),
  2678. };
  2679. encode_compound_hdr(xdr, req, &hdr);
  2680. encode_sequence(xdr, args, &hdr);
  2681. encode_nops(&hdr);
  2682. }
  2683. /*
  2684. * a GET_LEASE_TIME request
  2685. */
  2686. static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
  2687. struct xdr_stream *xdr,
  2688. const void *data)
  2689. {
  2690. const struct nfs4_get_lease_time_args *args = data;
  2691. struct compound_hdr hdr = {
  2692. .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
  2693. };
  2694. const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
  2695. encode_compound_hdr(xdr, req, &hdr);
  2696. encode_sequence(xdr, &args->la_seq_args, &hdr);
  2697. encode_putrootfh(xdr, &hdr);
  2698. encode_fsinfo(xdr, lease_bitmap, &hdr);
  2699. encode_nops(&hdr);
  2700. }
  2701. /*
  2702. * a RECLAIM_COMPLETE request
  2703. */
  2704. static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
  2705. struct xdr_stream *xdr,
  2706. const void *data)
  2707. {
  2708. const struct nfs41_reclaim_complete_args *args = data;
  2709. struct compound_hdr hdr = {
  2710. .minorversion = nfs4_xdr_minorversion(&args->seq_args)
  2711. };
  2712. encode_compound_hdr(xdr, req, &hdr);
  2713. encode_sequence(xdr, &args->seq_args, &hdr);
  2714. encode_reclaim_complete(xdr, args, &hdr);
  2715. encode_nops(&hdr);
  2716. }
  2717. /*
  2718. * Encode GETDEVICEINFO request
  2719. */
  2720. static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
  2721. struct xdr_stream *xdr,
  2722. const void *data)
  2723. {
  2724. const struct nfs4_getdeviceinfo_args *args = data;
  2725. struct compound_hdr hdr = {
  2726. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2727. };
  2728. encode_compound_hdr(xdr, req, &hdr);
  2729. encode_sequence(xdr, &args->seq_args, &hdr);
  2730. encode_getdeviceinfo(xdr, args, &hdr);
  2731. /* set up reply kvec. Subtract notification bitmap max size (2)
  2732. * so that notification bitmap is put in xdr_buf tail */
  2733. xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
  2734. args->pdev->pages, args->pdev->pgbase,
  2735. args->pdev->pglen);
  2736. encode_nops(&hdr);
  2737. }
  2738. /*
  2739. * Encode LAYOUTGET request
  2740. */
  2741. static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
  2742. struct xdr_stream *xdr,
  2743. const void *data)
  2744. {
  2745. const struct nfs4_layoutget_args *args = data;
  2746. struct compound_hdr hdr = {
  2747. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2748. };
  2749. encode_compound_hdr(xdr, req, &hdr);
  2750. encode_sequence(xdr, &args->seq_args, &hdr);
  2751. encode_putfh(xdr, NFS_FH(args->inode), &hdr);
  2752. encode_layoutget(xdr, args, &hdr);
  2753. xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
  2754. args->layout.pages, 0, args->layout.pglen);
  2755. encode_nops(&hdr);
  2756. }
  2757. /*
  2758. * Encode LAYOUTCOMMIT request
  2759. */
  2760. static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
  2761. struct xdr_stream *xdr,
  2762. const void *priv)
  2763. {
  2764. const struct nfs4_layoutcommit_args *args = priv;
  2765. struct nfs4_layoutcommit_data *data =
  2766. container_of(args, struct nfs4_layoutcommit_data, args);
  2767. struct compound_hdr hdr = {
  2768. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2769. };
  2770. encode_compound_hdr(xdr, req, &hdr);
  2771. encode_sequence(xdr, &args->seq_args, &hdr);
  2772. encode_putfh(xdr, NFS_FH(args->inode), &hdr);
  2773. encode_layoutcommit(xdr, data->args.inode, args, &hdr);
  2774. encode_getfattr(xdr, args->bitmask, &hdr);
  2775. encode_nops(&hdr);
  2776. }
  2777. /*
  2778. * Encode LAYOUTRETURN request
  2779. */
  2780. static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
  2781. struct xdr_stream *xdr,
  2782. const void *data)
  2783. {
  2784. const struct nfs4_layoutreturn_args *args = data;
  2785. struct compound_hdr hdr = {
  2786. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2787. };
  2788. encode_compound_hdr(xdr, req, &hdr);
  2789. encode_sequence(xdr, &args->seq_args, &hdr);
  2790. encode_putfh(xdr, NFS_FH(args->inode), &hdr);
  2791. encode_layoutreturn(xdr, args, &hdr);
  2792. encode_nops(&hdr);
  2793. }
  2794. /*
  2795. * Encode SECINFO_NO_NAME request
  2796. */
  2797. static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
  2798. struct xdr_stream *xdr,
  2799. const void *data)
  2800. {
  2801. const struct nfs41_secinfo_no_name_args *args = data;
  2802. struct compound_hdr hdr = {
  2803. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2804. };
  2805. encode_compound_hdr(xdr, req, &hdr);
  2806. encode_sequence(xdr, &args->seq_args, &hdr);
  2807. encode_putrootfh(xdr, &hdr);
  2808. encode_secinfo_no_name(xdr, args, &hdr);
  2809. encode_nops(&hdr);
  2810. }
  2811. /*
  2812. * Encode TEST_STATEID request
  2813. */
  2814. static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
  2815. struct xdr_stream *xdr,
  2816. const void *data)
  2817. {
  2818. const struct nfs41_test_stateid_args *args = data;
  2819. struct compound_hdr hdr = {
  2820. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2821. };
  2822. encode_compound_hdr(xdr, req, &hdr);
  2823. encode_sequence(xdr, &args->seq_args, &hdr);
  2824. encode_test_stateid(xdr, args, &hdr);
  2825. encode_nops(&hdr);
  2826. }
  2827. /*
  2828. * Encode FREE_STATEID request
  2829. */
  2830. static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
  2831. struct xdr_stream *xdr,
  2832. const void *data)
  2833. {
  2834. const struct nfs41_free_stateid_args *args = data;
  2835. struct compound_hdr hdr = {
  2836. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2837. };
  2838. encode_compound_hdr(xdr, req, &hdr);
  2839. encode_sequence(xdr, &args->seq_args, &hdr);
  2840. encode_free_stateid(xdr, args, &hdr);
  2841. encode_nops(&hdr);
  2842. }
  2843. #endif /* CONFIG_NFS_V4_1 */
  2844. static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
  2845. {
  2846. dprintk("nfs: %s: prematurely hit end of receive buffer. "
  2847. "Remaining buffer length is %tu words.\n",
  2848. func, xdr->end - xdr->p);
  2849. }
  2850. static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
  2851. {
  2852. ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string,
  2853. NFS4_OPAQUE_LIMIT);
  2854. if (unlikely(ret < 0)) {
  2855. if (ret == -EBADMSG)
  2856. print_overflow_msg(__func__, xdr);
  2857. return -EIO;
  2858. }
  2859. *len = ret;
  2860. return 0;
  2861. }
  2862. static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
  2863. {
  2864. __be32 *p;
  2865. p = xdr_inline_decode(xdr, 8);
  2866. if (unlikely(!p))
  2867. goto out_overflow;
  2868. hdr->status = be32_to_cpup(p++);
  2869. hdr->taglen = be32_to_cpup(p);
  2870. p = xdr_inline_decode(xdr, hdr->taglen + 4);
  2871. if (unlikely(!p))
  2872. goto out_overflow;
  2873. hdr->tag = (char *)p;
  2874. p += XDR_QUADLEN(hdr->taglen);
  2875. hdr->nops = be32_to_cpup(p);
  2876. if (unlikely(hdr->nops < 1))
  2877. return nfs4_stat_to_errno(hdr->status);
  2878. return 0;
  2879. out_overflow:
  2880. print_overflow_msg(__func__, xdr);
  2881. return -EIO;
  2882. }
  2883. static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
  2884. int *nfs_retval)
  2885. {
  2886. __be32 *p;
  2887. uint32_t opnum;
  2888. int32_t nfserr;
  2889. p = xdr_inline_decode(xdr, 8);
  2890. if (unlikely(!p))
  2891. goto out_overflow;
  2892. opnum = be32_to_cpup(p++);
  2893. if (unlikely(opnum != expected))
  2894. goto out_bad_operation;
  2895. nfserr = be32_to_cpup(p);
  2896. if (nfserr == NFS_OK)
  2897. *nfs_retval = 0;
  2898. else
  2899. *nfs_retval = nfs4_stat_to_errno(nfserr);
  2900. return true;
  2901. out_bad_operation:
  2902. dprintk("nfs: Server returned operation"
  2903. " %d but we issued a request for %d\n",
  2904. opnum, expected);
  2905. *nfs_retval = -EREMOTEIO;
  2906. return false;
  2907. out_overflow:
  2908. print_overflow_msg(__func__, xdr);
  2909. *nfs_retval = -EIO;
  2910. return false;
  2911. }
  2912. static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
  2913. {
  2914. int retval;
  2915. __decode_op_hdr(xdr, expected, &retval);
  2916. return retval;
  2917. }
  2918. /* Dummy routine */
  2919. static int decode_ace(struct xdr_stream *xdr, void *ace)
  2920. {
  2921. __be32 *p;
  2922. unsigned int strlen;
  2923. char *str;
  2924. p = xdr_inline_decode(xdr, 12);
  2925. if (likely(p))
  2926. return decode_opaque_inline(xdr, &strlen, &str);
  2927. print_overflow_msg(__func__, xdr);
  2928. return -EIO;
  2929. }
  2930. static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
  2931. {
  2932. uint32_t bmlen;
  2933. __be32 *p;
  2934. p = xdr_inline_decode(xdr, 4);
  2935. if (unlikely(!p))
  2936. goto out_overflow;
  2937. bmlen = be32_to_cpup(p);
  2938. bitmap[0] = bitmap[1] = bitmap[2] = 0;
  2939. p = xdr_inline_decode(xdr, (bmlen << 2));
  2940. if (unlikely(!p))
  2941. goto out_overflow;
  2942. if (bmlen > 0) {
  2943. bitmap[0] = be32_to_cpup(p++);
  2944. if (bmlen > 1) {
  2945. bitmap[1] = be32_to_cpup(p++);
  2946. if (bmlen > 2)
  2947. bitmap[2] = be32_to_cpup(p);
  2948. }
  2949. }
  2950. return 0;
  2951. out_overflow:
  2952. print_overflow_msg(__func__, xdr);
  2953. return -EIO;
  2954. }
  2955. static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
  2956. {
  2957. __be32 *p;
  2958. p = xdr_inline_decode(xdr, 4);
  2959. if (unlikely(!p))
  2960. goto out_overflow;
  2961. *attrlen = be32_to_cpup(p);
  2962. *savep = xdr_stream_pos(xdr);
  2963. return 0;
  2964. out_overflow:
  2965. print_overflow_msg(__func__, xdr);
  2966. return -EIO;
  2967. }
  2968. static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
  2969. {
  2970. if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
  2971. int ret;
  2972. ret = decode_attr_bitmap(xdr, bitmask);
  2973. if (unlikely(ret < 0))
  2974. return ret;
  2975. bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
  2976. } else
  2977. bitmask[0] = bitmask[1] = bitmask[2] = 0;
  2978. dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
  2979. bitmask[0], bitmask[1], bitmask[2]);
  2980. return 0;
  2981. }
  2982. static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
  2983. {
  2984. __be32 *p;
  2985. int ret = 0;
  2986. *type = 0;
  2987. if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
  2988. return -EIO;
  2989. if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
  2990. p = xdr_inline_decode(xdr, 4);
  2991. if (unlikely(!p))
  2992. goto out_overflow;
  2993. *type = be32_to_cpup(p);
  2994. if (*type < NF4REG || *type > NF4NAMEDATTR) {
  2995. dprintk("%s: bad type %d\n", __func__, *type);
  2996. return -EIO;
  2997. }
  2998. bitmap[0] &= ~FATTR4_WORD0_TYPE;
  2999. ret = NFS_ATTR_FATTR_TYPE;
  3000. }
  3001. dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
  3002. return ret;
  3003. out_overflow:
  3004. print_overflow_msg(__func__, xdr);
  3005. return -EIO;
  3006. }
  3007. static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
  3008. uint32_t *bitmap, uint32_t *type)
  3009. {
  3010. __be32 *p;
  3011. *type = 0;
  3012. if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
  3013. return -EIO;
  3014. if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
  3015. p = xdr_inline_decode(xdr, 4);
  3016. if (unlikely(!p))
  3017. goto out_overflow;
  3018. *type = be32_to_cpup(p);
  3019. bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
  3020. }
  3021. dprintk("%s: expire type=0x%x\n", __func__, *type);
  3022. return 0;
  3023. out_overflow:
  3024. print_overflow_msg(__func__, xdr);
  3025. return -EIO;
  3026. }
  3027. static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
  3028. {
  3029. __be32 *p;
  3030. int ret = 0;
  3031. *change = 0;
  3032. if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
  3033. return -EIO;
  3034. if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
  3035. p = xdr_inline_decode(xdr, 8);
  3036. if (unlikely(!p))
  3037. goto out_overflow;
  3038. xdr_decode_hyper(p, change);
  3039. bitmap[0] &= ~FATTR4_WORD0_CHANGE;
  3040. ret = NFS_ATTR_FATTR_CHANGE;
  3041. }
  3042. dprintk("%s: change attribute=%Lu\n", __func__,
  3043. (unsigned long long)*change);
  3044. return ret;
  3045. out_overflow:
  3046. print_overflow_msg(__func__, xdr);
  3047. return -EIO;
  3048. }
  3049. static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
  3050. {
  3051. __be32 *p;
  3052. int ret = 0;
  3053. *size = 0;
  3054. if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
  3055. return -EIO;
  3056. if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
  3057. p = xdr_inline_decode(xdr, 8);
  3058. if (unlikely(!p))
  3059. goto out_overflow;
  3060. xdr_decode_hyper(p, size);
  3061. bitmap[0] &= ~FATTR4_WORD0_SIZE;
  3062. ret = NFS_ATTR_FATTR_SIZE;
  3063. }
  3064. dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
  3065. return ret;
  3066. out_overflow:
  3067. print_overflow_msg(__func__, xdr);
  3068. return -EIO;
  3069. }
  3070. static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3071. {
  3072. __be32 *p;
  3073. *res = 0;
  3074. if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
  3075. return -EIO;
  3076. if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
  3077. p = xdr_inline_decode(xdr, 4);
  3078. if (unlikely(!p))
  3079. goto out_overflow;
  3080. *res = be32_to_cpup(p);
  3081. bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
  3082. }
  3083. dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
  3084. return 0;
  3085. out_overflow:
  3086. print_overflow_msg(__func__, xdr);
  3087. return -EIO;
  3088. }
  3089. static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3090. {
  3091. __be32 *p;
  3092. *res = 0;
  3093. if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
  3094. return -EIO;
  3095. if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
  3096. p = xdr_inline_decode(xdr, 4);
  3097. if (unlikely(!p))
  3098. goto out_overflow;
  3099. *res = be32_to_cpup(p);
  3100. bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
  3101. }
  3102. dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
  3103. return 0;
  3104. out_overflow:
  3105. print_overflow_msg(__func__, xdr);
  3106. return -EIO;
  3107. }
  3108. static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
  3109. {
  3110. __be32 *p;
  3111. int ret = 0;
  3112. fsid->major = 0;
  3113. fsid->minor = 0;
  3114. if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
  3115. return -EIO;
  3116. if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
  3117. p = xdr_inline_decode(xdr, 16);
  3118. if (unlikely(!p))
  3119. goto out_overflow;
  3120. p = xdr_decode_hyper(p, &fsid->major);
  3121. xdr_decode_hyper(p, &fsid->minor);
  3122. bitmap[0] &= ~FATTR4_WORD0_FSID;
  3123. ret = NFS_ATTR_FATTR_FSID;
  3124. }
  3125. dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
  3126. (unsigned long long)fsid->major,
  3127. (unsigned long long)fsid->minor);
  3128. return ret;
  3129. out_overflow:
  3130. print_overflow_msg(__func__, xdr);
  3131. return -EIO;
  3132. }
  3133. static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3134. {
  3135. __be32 *p;
  3136. *res = 60;
  3137. if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
  3138. return -EIO;
  3139. if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
  3140. p = xdr_inline_decode(xdr, 4);
  3141. if (unlikely(!p))
  3142. goto out_overflow;
  3143. *res = be32_to_cpup(p);
  3144. bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
  3145. }
  3146. dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
  3147. return 0;
  3148. out_overflow:
  3149. print_overflow_msg(__func__, xdr);
  3150. return -EIO;
  3151. }
  3152. static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
  3153. {
  3154. __be32 *p;
  3155. if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
  3156. return -EIO;
  3157. if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
  3158. p = xdr_inline_decode(xdr, 4);
  3159. if (unlikely(!p))
  3160. goto out_overflow;
  3161. bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
  3162. *res = -be32_to_cpup(p);
  3163. }
  3164. return 0;
  3165. out_overflow:
  3166. print_overflow_msg(__func__, xdr);
  3167. return -EIO;
  3168. }
  3169. static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
  3170. uint32_t *bitmap, uint32_t *bitmask)
  3171. {
  3172. if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
  3173. int ret;
  3174. ret = decode_attr_bitmap(xdr, bitmask);
  3175. if (unlikely(ret < 0))
  3176. return ret;
  3177. bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
  3178. } else
  3179. bitmask[0] = bitmask[1] = bitmask[2] = 0;
  3180. dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
  3181. bitmask[0], bitmask[1], bitmask[2]);
  3182. return 0;
  3183. }
  3184. static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
  3185. {
  3186. __be32 *p;
  3187. int len;
  3188. if (fh != NULL)
  3189. memset(fh, 0, sizeof(*fh));
  3190. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
  3191. return -EIO;
  3192. if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
  3193. p = xdr_inline_decode(xdr, 4);
  3194. if (unlikely(!p))
  3195. goto out_overflow;
  3196. len = be32_to_cpup(p);
  3197. if (len > NFS4_FHSIZE)
  3198. return -EIO;
  3199. p = xdr_inline_decode(xdr, len);
  3200. if (unlikely(!p))
  3201. goto out_overflow;
  3202. if (fh != NULL) {
  3203. memcpy(fh->data, p, len);
  3204. fh->size = len;
  3205. }
  3206. bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
  3207. }
  3208. return 0;
  3209. out_overflow:
  3210. print_overflow_msg(__func__, xdr);
  3211. return -EIO;
  3212. }
  3213. static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3214. {
  3215. __be32 *p;
  3216. *res = 0;
  3217. if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
  3218. return -EIO;
  3219. if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
  3220. p = xdr_inline_decode(xdr, 4);
  3221. if (unlikely(!p))
  3222. goto out_overflow;
  3223. *res = be32_to_cpup(p);
  3224. bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
  3225. }
  3226. dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
  3227. return 0;
  3228. out_overflow:
  3229. print_overflow_msg(__func__, xdr);
  3230. return -EIO;
  3231. }
  3232. static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
  3233. {
  3234. __be32 *p;
  3235. int ret = 0;
  3236. *fileid = 0;
  3237. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
  3238. return -EIO;
  3239. if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
  3240. p = xdr_inline_decode(xdr, 8);
  3241. if (unlikely(!p))
  3242. goto out_overflow;
  3243. xdr_decode_hyper(p, fileid);
  3244. bitmap[0] &= ~FATTR4_WORD0_FILEID;
  3245. ret = NFS_ATTR_FATTR_FILEID;
  3246. }
  3247. dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
  3248. return ret;
  3249. out_overflow:
  3250. print_overflow_msg(__func__, xdr);
  3251. return -EIO;
  3252. }
  3253. static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
  3254. {
  3255. __be32 *p;
  3256. int ret = 0;
  3257. *fileid = 0;
  3258. if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
  3259. return -EIO;
  3260. if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
  3261. p = xdr_inline_decode(xdr, 8);
  3262. if (unlikely(!p))
  3263. goto out_overflow;
  3264. xdr_decode_hyper(p, fileid);
  3265. bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
  3266. ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
  3267. }
  3268. dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
  3269. return ret;
  3270. out_overflow:
  3271. print_overflow_msg(__func__, xdr);
  3272. return -EIO;
  3273. }
  3274. static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3275. {
  3276. __be32 *p;
  3277. int status = 0;
  3278. *res = 0;
  3279. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
  3280. return -EIO;
  3281. if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
  3282. p = xdr_inline_decode(xdr, 8);
  3283. if (unlikely(!p))
  3284. goto out_overflow;
  3285. xdr_decode_hyper(p, res);
  3286. bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
  3287. }
  3288. dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
  3289. return status;
  3290. out_overflow:
  3291. print_overflow_msg(__func__, xdr);
  3292. return -EIO;
  3293. }
  3294. static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3295. {
  3296. __be32 *p;
  3297. int status = 0;
  3298. *res = 0;
  3299. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
  3300. return -EIO;
  3301. if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
  3302. p = xdr_inline_decode(xdr, 8);
  3303. if (unlikely(!p))
  3304. goto out_overflow;
  3305. xdr_decode_hyper(p, res);
  3306. bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
  3307. }
  3308. dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
  3309. return status;
  3310. out_overflow:
  3311. print_overflow_msg(__func__, xdr);
  3312. return -EIO;
  3313. }
  3314. static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3315. {
  3316. __be32 *p;
  3317. int status = 0;
  3318. *res = 0;
  3319. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
  3320. return -EIO;
  3321. if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
  3322. p = xdr_inline_decode(xdr, 8);
  3323. if (unlikely(!p))
  3324. goto out_overflow;
  3325. xdr_decode_hyper(p, res);
  3326. bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
  3327. }
  3328. dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
  3329. return status;
  3330. out_overflow:
  3331. print_overflow_msg(__func__, xdr);
  3332. return -EIO;
  3333. }
  3334. static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
  3335. {
  3336. u32 n;
  3337. __be32 *p;
  3338. int status = 0;
  3339. p = xdr_inline_decode(xdr, 4);
  3340. if (unlikely(!p))
  3341. goto out_overflow;
  3342. n = be32_to_cpup(p);
  3343. if (n == 0)
  3344. goto root_path;
  3345. dprintk("pathname4: ");
  3346. if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
  3347. dprintk("cannot parse %d components in path\n", n);
  3348. goto out_eio;
  3349. }
  3350. for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
  3351. struct nfs4_string *component = &path->components[path->ncomponents];
  3352. status = decode_opaque_inline(xdr, &component->len, &component->data);
  3353. if (unlikely(status != 0))
  3354. goto out_eio;
  3355. ifdebug (XDR)
  3356. pr_cont("%s%.*s ",
  3357. (path->ncomponents != n ? "/ " : ""),
  3358. component->len, component->data);
  3359. }
  3360. out:
  3361. return status;
  3362. root_path:
  3363. /* a root pathname is sent as a zero component4 */
  3364. path->ncomponents = 1;
  3365. path->components[0].len=0;
  3366. path->components[0].data=NULL;
  3367. dprintk("pathname4: /\n");
  3368. goto out;
  3369. out_eio:
  3370. dprintk(" status %d", status);
  3371. status = -EIO;
  3372. goto out;
  3373. out_overflow:
  3374. print_overflow_msg(__func__, xdr);
  3375. return -EIO;
  3376. }
  3377. static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
  3378. {
  3379. int n;
  3380. __be32 *p;
  3381. int status = -EIO;
  3382. if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
  3383. goto out;
  3384. status = 0;
  3385. if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
  3386. goto out;
  3387. bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
  3388. status = -EIO;
  3389. /* Ignore borken servers that return unrequested attrs */
  3390. if (unlikely(res == NULL))
  3391. goto out;
  3392. dprintk("%s: fsroot:\n", __func__);
  3393. status = decode_pathname(xdr, &res->fs_path);
  3394. if (unlikely(status != 0))
  3395. goto out;
  3396. p = xdr_inline_decode(xdr, 4);
  3397. if (unlikely(!p))
  3398. goto out_overflow;
  3399. n = be32_to_cpup(p);
  3400. if (n <= 0)
  3401. goto out_eio;
  3402. for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
  3403. u32 m;
  3404. struct nfs4_fs_location *loc;
  3405. if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
  3406. break;
  3407. loc = &res->locations[res->nlocations];
  3408. p = xdr_inline_decode(xdr, 4);
  3409. if (unlikely(!p))
  3410. goto out_overflow;
  3411. m = be32_to_cpup(p);
  3412. dprintk("%s: servers:\n", __func__);
  3413. for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
  3414. struct nfs4_string *server;
  3415. if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
  3416. unsigned int i;
  3417. dprintk("%s: using first %u of %u servers "
  3418. "returned for location %u\n",
  3419. __func__,
  3420. NFS4_FS_LOCATION_MAXSERVERS,
  3421. m, res->nlocations);
  3422. for (i = loc->nservers; i < m; i++) {
  3423. unsigned int len;
  3424. char *data;
  3425. status = decode_opaque_inline(xdr, &len, &data);
  3426. if (unlikely(status != 0))
  3427. goto out_eio;
  3428. }
  3429. break;
  3430. }
  3431. server = &loc->servers[loc->nservers];
  3432. status = decode_opaque_inline(xdr, &server->len, &server->data);
  3433. if (unlikely(status != 0))
  3434. goto out_eio;
  3435. dprintk("%s ", server->data);
  3436. }
  3437. status = decode_pathname(xdr, &loc->rootpath);
  3438. if (unlikely(status != 0))
  3439. goto out_eio;
  3440. }
  3441. if (res->nlocations != 0)
  3442. status = NFS_ATTR_FATTR_V4_LOCATIONS;
  3443. out:
  3444. dprintk("%s: fs_locations done, error = %d\n", __func__, status);
  3445. return status;
  3446. out_overflow:
  3447. print_overflow_msg(__func__, xdr);
  3448. out_eio:
  3449. status = -EIO;
  3450. goto out;
  3451. }
  3452. static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3453. {
  3454. __be32 *p;
  3455. int status = 0;
  3456. *res = 0;
  3457. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
  3458. return -EIO;
  3459. if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
  3460. p = xdr_inline_decode(xdr, 8);
  3461. if (unlikely(!p))
  3462. goto out_overflow;
  3463. xdr_decode_hyper(p, res);
  3464. bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
  3465. }
  3466. dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
  3467. return status;
  3468. out_overflow:
  3469. print_overflow_msg(__func__, xdr);
  3470. return -EIO;
  3471. }
  3472. static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
  3473. {
  3474. __be32 *p;
  3475. int status = 0;
  3476. *maxlink = 1;
  3477. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
  3478. return -EIO;
  3479. if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
  3480. p = xdr_inline_decode(xdr, 4);
  3481. if (unlikely(!p))
  3482. goto out_overflow;
  3483. *maxlink = be32_to_cpup(p);
  3484. bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
  3485. }
  3486. dprintk("%s: maxlink=%u\n", __func__, *maxlink);
  3487. return status;
  3488. out_overflow:
  3489. print_overflow_msg(__func__, xdr);
  3490. return -EIO;
  3491. }
  3492. static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
  3493. {
  3494. __be32 *p;
  3495. int status = 0;
  3496. *maxname = 1024;
  3497. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
  3498. return -EIO;
  3499. if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
  3500. p = xdr_inline_decode(xdr, 4);
  3501. if (unlikely(!p))
  3502. goto out_overflow;
  3503. *maxname = be32_to_cpup(p);
  3504. bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
  3505. }
  3506. dprintk("%s: maxname=%u\n", __func__, *maxname);
  3507. return status;
  3508. out_overflow:
  3509. print_overflow_msg(__func__, xdr);
  3510. return -EIO;
  3511. }
  3512. static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3513. {
  3514. __be32 *p;
  3515. int status = 0;
  3516. *res = 1024;
  3517. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
  3518. return -EIO;
  3519. if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
  3520. uint64_t maxread;
  3521. p = xdr_inline_decode(xdr, 8);
  3522. if (unlikely(!p))
  3523. goto out_overflow;
  3524. xdr_decode_hyper(p, &maxread);
  3525. if (maxread > 0x7FFFFFFF)
  3526. maxread = 0x7FFFFFFF;
  3527. *res = (uint32_t)maxread;
  3528. bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
  3529. }
  3530. dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
  3531. return status;
  3532. out_overflow:
  3533. print_overflow_msg(__func__, xdr);
  3534. return -EIO;
  3535. }
  3536. static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3537. {
  3538. __be32 *p;
  3539. int status = 0;
  3540. *res = 1024;
  3541. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
  3542. return -EIO;
  3543. if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
  3544. uint64_t maxwrite;
  3545. p = xdr_inline_decode(xdr, 8);
  3546. if (unlikely(!p))
  3547. goto out_overflow;
  3548. xdr_decode_hyper(p, &maxwrite);
  3549. if (maxwrite > 0x7FFFFFFF)
  3550. maxwrite = 0x7FFFFFFF;
  3551. *res = (uint32_t)maxwrite;
  3552. bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
  3553. }
  3554. dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
  3555. return status;
  3556. out_overflow:
  3557. print_overflow_msg(__func__, xdr);
  3558. return -EIO;
  3559. }
  3560. static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
  3561. {
  3562. uint32_t tmp;
  3563. __be32 *p;
  3564. int ret = 0;
  3565. *mode = 0;
  3566. if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
  3567. return -EIO;
  3568. if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
  3569. p = xdr_inline_decode(xdr, 4);
  3570. if (unlikely(!p))
  3571. goto out_overflow;
  3572. tmp = be32_to_cpup(p);
  3573. *mode = tmp & ~S_IFMT;
  3574. bitmap[1] &= ~FATTR4_WORD1_MODE;
  3575. ret = NFS_ATTR_FATTR_MODE;
  3576. }
  3577. dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
  3578. return ret;
  3579. out_overflow:
  3580. print_overflow_msg(__func__, xdr);
  3581. return -EIO;
  3582. }
  3583. static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
  3584. {
  3585. __be32 *p;
  3586. int ret = 0;
  3587. *nlink = 1;
  3588. if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
  3589. return -EIO;
  3590. if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
  3591. p = xdr_inline_decode(xdr, 4);
  3592. if (unlikely(!p))
  3593. goto out_overflow;
  3594. *nlink = be32_to_cpup(p);
  3595. bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
  3596. ret = NFS_ATTR_FATTR_NLINK;
  3597. }
  3598. dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
  3599. return ret;
  3600. out_overflow:
  3601. print_overflow_msg(__func__, xdr);
  3602. return -EIO;
  3603. }
  3604. static ssize_t decode_nfs4_string(struct xdr_stream *xdr,
  3605. struct nfs4_string *name, gfp_t gfp_flags)
  3606. {
  3607. ssize_t ret;
  3608. ret = xdr_stream_decode_string_dup(xdr, &name->data,
  3609. XDR_MAX_NETOBJ, gfp_flags);
  3610. name->len = 0;
  3611. if (ret > 0)
  3612. name->len = ret;
  3613. return ret;
  3614. }
  3615. static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
  3616. const struct nfs_server *server, kuid_t *uid,
  3617. struct nfs4_string *owner_name)
  3618. {
  3619. ssize_t len;
  3620. char *p;
  3621. *uid = make_kuid(&init_user_ns, -2);
  3622. if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
  3623. return -EIO;
  3624. if (!(bitmap[1] & FATTR4_WORD1_OWNER))
  3625. return 0;
  3626. bitmap[1] &= ~FATTR4_WORD1_OWNER;
  3627. if (owner_name != NULL) {
  3628. len = decode_nfs4_string(xdr, owner_name, GFP_NOWAIT);
  3629. if (len <= 0)
  3630. goto out;
  3631. dprintk("%s: name=%s\n", __func__, owner_name->data);
  3632. return NFS_ATTR_FATTR_OWNER_NAME;
  3633. } else {
  3634. len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
  3635. XDR_MAX_NETOBJ);
  3636. if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0)
  3637. goto out;
  3638. dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
  3639. return NFS_ATTR_FATTR_OWNER;
  3640. }
  3641. out:
  3642. if (len != -EBADMSG)
  3643. return 0;
  3644. print_overflow_msg(__func__, xdr);
  3645. return -EIO;
  3646. }
  3647. static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
  3648. const struct nfs_server *server, kgid_t *gid,
  3649. struct nfs4_string *group_name)
  3650. {
  3651. ssize_t len;
  3652. char *p;
  3653. *gid = make_kgid(&init_user_ns, -2);
  3654. if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
  3655. return -EIO;
  3656. if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP))
  3657. return 0;
  3658. bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
  3659. if (group_name != NULL) {
  3660. len = decode_nfs4_string(xdr, group_name, GFP_NOWAIT);
  3661. if (len <= 0)
  3662. goto out;
  3663. dprintk("%s: name=%s\n", __func__, group_name->data);
  3664. return NFS_ATTR_FATTR_GROUP_NAME;
  3665. } else {
  3666. len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
  3667. XDR_MAX_NETOBJ);
  3668. if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0)
  3669. goto out;
  3670. dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
  3671. return NFS_ATTR_FATTR_GROUP;
  3672. }
  3673. out:
  3674. if (len != -EBADMSG)
  3675. return 0;
  3676. print_overflow_msg(__func__, xdr);
  3677. return -EIO;
  3678. }
  3679. static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
  3680. {
  3681. uint32_t major = 0, minor = 0;
  3682. __be32 *p;
  3683. int ret = 0;
  3684. *rdev = MKDEV(0,0);
  3685. if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
  3686. return -EIO;
  3687. if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
  3688. dev_t tmp;
  3689. p = xdr_inline_decode(xdr, 8);
  3690. if (unlikely(!p))
  3691. goto out_overflow;
  3692. major = be32_to_cpup(p++);
  3693. minor = be32_to_cpup(p);
  3694. tmp = MKDEV(major, minor);
  3695. if (MAJOR(tmp) == major && MINOR(tmp) == minor)
  3696. *rdev = tmp;
  3697. bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
  3698. ret = NFS_ATTR_FATTR_RDEV;
  3699. }
  3700. dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
  3701. return ret;
  3702. out_overflow:
  3703. print_overflow_msg(__func__, xdr);
  3704. return -EIO;
  3705. }
  3706. static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3707. {
  3708. __be32 *p;
  3709. int status = 0;
  3710. *res = 0;
  3711. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
  3712. return -EIO;
  3713. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
  3714. p = xdr_inline_decode(xdr, 8);
  3715. if (unlikely(!p))
  3716. goto out_overflow;
  3717. xdr_decode_hyper(p, res);
  3718. bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
  3719. }
  3720. dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
  3721. return status;
  3722. out_overflow:
  3723. print_overflow_msg(__func__, xdr);
  3724. return -EIO;
  3725. }
  3726. static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3727. {
  3728. __be32 *p;
  3729. int status = 0;
  3730. *res = 0;
  3731. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
  3732. return -EIO;
  3733. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
  3734. p = xdr_inline_decode(xdr, 8);
  3735. if (unlikely(!p))
  3736. goto out_overflow;
  3737. xdr_decode_hyper(p, res);
  3738. bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
  3739. }
  3740. dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
  3741. return status;
  3742. out_overflow:
  3743. print_overflow_msg(__func__, xdr);
  3744. return -EIO;
  3745. }
  3746. static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3747. {
  3748. __be32 *p;
  3749. int status = 0;
  3750. *res = 0;
  3751. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
  3752. return -EIO;
  3753. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
  3754. p = xdr_inline_decode(xdr, 8);
  3755. if (unlikely(!p))
  3756. goto out_overflow;
  3757. xdr_decode_hyper(p, res);
  3758. bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
  3759. }
  3760. dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
  3761. return status;
  3762. out_overflow:
  3763. print_overflow_msg(__func__, xdr);
  3764. return -EIO;
  3765. }
  3766. static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
  3767. {
  3768. __be32 *p;
  3769. int ret = 0;
  3770. *used = 0;
  3771. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
  3772. return -EIO;
  3773. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
  3774. p = xdr_inline_decode(xdr, 8);
  3775. if (unlikely(!p))
  3776. goto out_overflow;
  3777. xdr_decode_hyper(p, used);
  3778. bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
  3779. ret = NFS_ATTR_FATTR_SPACE_USED;
  3780. }
  3781. dprintk("%s: space used=%Lu\n", __func__,
  3782. (unsigned long long)*used);
  3783. return ret;
  3784. out_overflow:
  3785. print_overflow_msg(__func__, xdr);
  3786. return -EIO;
  3787. }
  3788. static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
  3789. {
  3790. __be32 *p;
  3791. uint64_t sec;
  3792. uint32_t nsec;
  3793. p = xdr_inline_decode(xdr, 12);
  3794. if (unlikely(!p))
  3795. goto out_overflow;
  3796. p = xdr_decode_hyper(p, &sec);
  3797. nsec = be32_to_cpup(p);
  3798. time->tv_sec = (time_t)sec;
  3799. time->tv_nsec = (long)nsec;
  3800. return 0;
  3801. out_overflow:
  3802. print_overflow_msg(__func__, xdr);
  3803. return -EIO;
  3804. }
  3805. static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
  3806. {
  3807. int status = 0;
  3808. time->tv_sec = 0;
  3809. time->tv_nsec = 0;
  3810. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
  3811. return -EIO;
  3812. if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
  3813. status = decode_attr_time(xdr, time);
  3814. if (status == 0)
  3815. status = NFS_ATTR_FATTR_ATIME;
  3816. bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
  3817. }
  3818. dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
  3819. return status;
  3820. }
  3821. static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
  3822. {
  3823. int status = 0;
  3824. time->tv_sec = 0;
  3825. time->tv_nsec = 0;
  3826. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
  3827. return -EIO;
  3828. if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
  3829. status = decode_attr_time(xdr, time);
  3830. if (status == 0)
  3831. status = NFS_ATTR_FATTR_CTIME;
  3832. bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
  3833. }
  3834. dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
  3835. return status;
  3836. }
  3837. static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
  3838. struct timespec *time)
  3839. {
  3840. int status = 0;
  3841. time->tv_sec = 0;
  3842. time->tv_nsec = 0;
  3843. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
  3844. return -EIO;
  3845. if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
  3846. status = decode_attr_time(xdr, time);
  3847. bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
  3848. }
  3849. dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
  3850. (long)time->tv_nsec);
  3851. return status;
  3852. }
  3853. static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
  3854. struct nfs4_label *label)
  3855. {
  3856. uint32_t pi = 0;
  3857. uint32_t lfs = 0;
  3858. __u32 len;
  3859. __be32 *p;
  3860. int status = 0;
  3861. if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
  3862. return -EIO;
  3863. if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
  3864. p = xdr_inline_decode(xdr, 4);
  3865. if (unlikely(!p))
  3866. goto out_overflow;
  3867. lfs = be32_to_cpup(p++);
  3868. p = xdr_inline_decode(xdr, 4);
  3869. if (unlikely(!p))
  3870. goto out_overflow;
  3871. pi = be32_to_cpup(p++);
  3872. p = xdr_inline_decode(xdr, 4);
  3873. if (unlikely(!p))
  3874. goto out_overflow;
  3875. len = be32_to_cpup(p++);
  3876. p = xdr_inline_decode(xdr, len);
  3877. if (unlikely(!p))
  3878. goto out_overflow;
  3879. if (len < NFS4_MAXLABELLEN) {
  3880. if (label) {
  3881. memcpy(label->label, p, len);
  3882. label->len = len;
  3883. label->pi = pi;
  3884. label->lfs = lfs;
  3885. status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
  3886. }
  3887. bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
  3888. } else
  3889. printk(KERN_WARNING "%s: label too long (%u)!\n",
  3890. __func__, len);
  3891. }
  3892. if (label && label->label)
  3893. dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
  3894. (char *)label->label, label->len, label->pi, label->lfs);
  3895. return status;
  3896. out_overflow:
  3897. print_overflow_msg(__func__, xdr);
  3898. return -EIO;
  3899. }
  3900. static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
  3901. {
  3902. int status = 0;
  3903. time->tv_sec = 0;
  3904. time->tv_nsec = 0;
  3905. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
  3906. return -EIO;
  3907. if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
  3908. status = decode_attr_time(xdr, time);
  3909. if (status == 0)
  3910. status = NFS_ATTR_FATTR_MTIME;
  3911. bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
  3912. }
  3913. dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
  3914. return status;
  3915. }
  3916. static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
  3917. {
  3918. unsigned int attrwords = XDR_QUADLEN(attrlen);
  3919. unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
  3920. if (unlikely(attrwords != nwords)) {
  3921. dprintk("%s: server returned incorrect attribute length: "
  3922. "%u %c %u\n",
  3923. __func__,
  3924. attrwords << 2,
  3925. (attrwords < nwords) ? '<' : '>',
  3926. nwords << 2);
  3927. return -EIO;
  3928. }
  3929. return 0;
  3930. }
  3931. static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  3932. {
  3933. __be32 *p;
  3934. p = xdr_inline_decode(xdr, 20);
  3935. if (unlikely(!p))
  3936. goto out_overflow;
  3937. cinfo->atomic = be32_to_cpup(p++);
  3938. p = xdr_decode_hyper(p, &cinfo->before);
  3939. xdr_decode_hyper(p, &cinfo->after);
  3940. return 0;
  3941. out_overflow:
  3942. print_overflow_msg(__func__, xdr);
  3943. return -EIO;
  3944. }
  3945. static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
  3946. {
  3947. __be32 *p;
  3948. uint32_t supp, acc;
  3949. int status;
  3950. status = decode_op_hdr(xdr, OP_ACCESS);
  3951. if (status)
  3952. return status;
  3953. p = xdr_inline_decode(xdr, 8);
  3954. if (unlikely(!p))
  3955. goto out_overflow;
  3956. supp = be32_to_cpup(p++);
  3957. acc = be32_to_cpup(p);
  3958. *supported = supp;
  3959. *access = acc;
  3960. return 0;
  3961. out_overflow:
  3962. print_overflow_msg(__func__, xdr);
  3963. return -EIO;
  3964. }
  3965. static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
  3966. {
  3967. ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
  3968. if (unlikely(ret < 0)) {
  3969. print_overflow_msg(__func__, xdr);
  3970. return -EIO;
  3971. }
  3972. return 0;
  3973. }
  3974. static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  3975. {
  3976. return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
  3977. }
  3978. static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  3979. {
  3980. stateid->type = NFS4_OPEN_STATEID_TYPE;
  3981. return decode_stateid(xdr, stateid);
  3982. }
  3983. static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  3984. {
  3985. stateid->type = NFS4_LOCK_STATEID_TYPE;
  3986. return decode_stateid(xdr, stateid);
  3987. }
  3988. static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  3989. {
  3990. stateid->type = NFS4_DELEGATION_STATEID_TYPE;
  3991. return decode_stateid(xdr, stateid);
  3992. }
  3993. static int decode_invalid_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  3994. {
  3995. nfs4_stateid dummy;
  3996. nfs4_stateid_copy(stateid, &invalid_stateid);
  3997. return decode_stateid(xdr, &dummy);
  3998. }
  3999. static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
  4000. {
  4001. int status;
  4002. status = decode_op_hdr(xdr, OP_CLOSE);
  4003. if (status != -EIO)
  4004. nfs_increment_open_seqid(status, res->seqid);
  4005. if (!status)
  4006. status = decode_invalid_stateid(xdr, &res->stateid);
  4007. return status;
  4008. }
  4009. static int decode_verifier(struct xdr_stream *xdr, void *verifier)
  4010. {
  4011. return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
  4012. }
  4013. static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
  4014. {
  4015. return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
  4016. }
  4017. static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
  4018. {
  4019. int status;
  4020. status = decode_op_hdr(xdr, OP_COMMIT);
  4021. if (!status)
  4022. status = decode_write_verifier(xdr, &res->verf->verifier);
  4023. return status;
  4024. }
  4025. static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  4026. {
  4027. __be32 *p;
  4028. uint32_t bmlen;
  4029. int status;
  4030. status = decode_op_hdr(xdr, OP_CREATE);
  4031. if (status)
  4032. return status;
  4033. if ((status = decode_change_info(xdr, cinfo)))
  4034. return status;
  4035. p = xdr_inline_decode(xdr, 4);
  4036. if (unlikely(!p))
  4037. goto out_overflow;
  4038. bmlen = be32_to_cpup(p);
  4039. p = xdr_inline_decode(xdr, bmlen << 2);
  4040. if (likely(p))
  4041. return 0;
  4042. out_overflow:
  4043. print_overflow_msg(__func__, xdr);
  4044. return -EIO;
  4045. }
  4046. static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
  4047. {
  4048. unsigned int savep;
  4049. uint32_t attrlen, bitmap[3] = {0};
  4050. int status;
  4051. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  4052. goto xdr_error;
  4053. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  4054. goto xdr_error;
  4055. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  4056. goto xdr_error;
  4057. if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
  4058. goto xdr_error;
  4059. if ((status = decode_attr_fh_expire_type(xdr, bitmap,
  4060. &res->fh_expire_type)) != 0)
  4061. goto xdr_error;
  4062. if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
  4063. goto xdr_error;
  4064. if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
  4065. goto xdr_error;
  4066. if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
  4067. goto xdr_error;
  4068. if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
  4069. res->exclcreat_bitmask)) != 0)
  4070. goto xdr_error;
  4071. status = verify_attr_len(xdr, savep, attrlen);
  4072. xdr_error:
  4073. dprintk("%s: xdr returned %d!\n", __func__, -status);
  4074. return status;
  4075. }
  4076. static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
  4077. {
  4078. unsigned int savep;
  4079. uint32_t attrlen, bitmap[3] = {0};
  4080. int status;
  4081. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  4082. goto xdr_error;
  4083. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  4084. goto xdr_error;
  4085. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  4086. goto xdr_error;
  4087. if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
  4088. goto xdr_error;
  4089. if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
  4090. goto xdr_error;
  4091. if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
  4092. goto xdr_error;
  4093. status = -EIO;
  4094. if (unlikely(bitmap[0]))
  4095. goto xdr_error;
  4096. if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
  4097. goto xdr_error;
  4098. if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
  4099. goto xdr_error;
  4100. if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
  4101. goto xdr_error;
  4102. status = verify_attr_len(xdr, savep, attrlen);
  4103. xdr_error:
  4104. dprintk("%s: xdr returned %d!\n", __func__, -status);
  4105. return status;
  4106. }
  4107. static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
  4108. {
  4109. unsigned int savep;
  4110. uint32_t attrlen, bitmap[3] = {0};
  4111. int status;
  4112. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  4113. goto xdr_error;
  4114. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  4115. goto xdr_error;
  4116. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  4117. goto xdr_error;
  4118. if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
  4119. goto xdr_error;
  4120. if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
  4121. goto xdr_error;
  4122. status = verify_attr_len(xdr, savep, attrlen);
  4123. xdr_error:
  4124. dprintk("%s: xdr returned %d!\n", __func__, -status);
  4125. return status;
  4126. }
  4127. static int decode_threshold_hint(struct xdr_stream *xdr,
  4128. uint32_t *bitmap,
  4129. uint64_t *res,
  4130. uint32_t hint_bit)
  4131. {
  4132. __be32 *p;
  4133. *res = 0;
  4134. if (likely(bitmap[0] & hint_bit)) {
  4135. p = xdr_inline_decode(xdr, 8);
  4136. if (unlikely(!p))
  4137. goto out_overflow;
  4138. xdr_decode_hyper(p, res);
  4139. }
  4140. return 0;
  4141. out_overflow:
  4142. print_overflow_msg(__func__, xdr);
  4143. return -EIO;
  4144. }
  4145. static int decode_first_threshold_item4(struct xdr_stream *xdr,
  4146. struct nfs4_threshold *res)
  4147. {
  4148. __be32 *p;
  4149. unsigned int savep;
  4150. uint32_t bitmap[3] = {0,}, attrlen;
  4151. int status;
  4152. /* layout type */
  4153. p = xdr_inline_decode(xdr, 4);
  4154. if (unlikely(!p)) {
  4155. print_overflow_msg(__func__, xdr);
  4156. return -EIO;
  4157. }
  4158. res->l_type = be32_to_cpup(p);
  4159. /* thi_hintset bitmap */
  4160. status = decode_attr_bitmap(xdr, bitmap);
  4161. if (status < 0)
  4162. goto xdr_error;
  4163. /* thi_hintlist length */
  4164. status = decode_attr_length(xdr, &attrlen, &savep);
  4165. if (status < 0)
  4166. goto xdr_error;
  4167. /* thi_hintlist */
  4168. status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
  4169. if (status < 0)
  4170. goto xdr_error;
  4171. status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
  4172. if (status < 0)
  4173. goto xdr_error;
  4174. status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
  4175. THRESHOLD_RD_IO);
  4176. if (status < 0)
  4177. goto xdr_error;
  4178. status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
  4179. THRESHOLD_WR_IO);
  4180. if (status < 0)
  4181. goto xdr_error;
  4182. status = verify_attr_len(xdr, savep, attrlen);
  4183. res->bm = bitmap[0];
  4184. dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
  4185. __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
  4186. res->wr_io_sz);
  4187. xdr_error:
  4188. dprintk("%s ret=%d!\n", __func__, status);
  4189. return status;
  4190. }
  4191. /*
  4192. * Thresholds on pNFS direct I/O vrs MDS I/O
  4193. */
  4194. static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
  4195. uint32_t *bitmap,
  4196. struct nfs4_threshold *res)
  4197. {
  4198. __be32 *p;
  4199. int status = 0;
  4200. uint32_t num;
  4201. if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
  4202. return -EIO;
  4203. if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
  4204. /* Did the server return an unrequested attribute? */
  4205. if (unlikely(res == NULL))
  4206. return -EREMOTEIO;
  4207. p = xdr_inline_decode(xdr, 4);
  4208. if (unlikely(!p))
  4209. goto out_overflow;
  4210. num = be32_to_cpup(p);
  4211. if (num == 0)
  4212. return 0;
  4213. if (num > 1)
  4214. printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
  4215. "drivers per filesystem not supported\n",
  4216. __func__);
  4217. status = decode_first_threshold_item4(xdr, res);
  4218. bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
  4219. }
  4220. return status;
  4221. out_overflow:
  4222. print_overflow_msg(__func__, xdr);
  4223. return -EIO;
  4224. }
  4225. static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
  4226. struct nfs_fattr *fattr, struct nfs_fh *fh,
  4227. struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
  4228. const struct nfs_server *server)
  4229. {
  4230. int status;
  4231. umode_t fmode = 0;
  4232. uint32_t type;
  4233. int32_t err;
  4234. status = decode_attr_type(xdr, bitmap, &type);
  4235. if (status < 0)
  4236. goto xdr_error;
  4237. fattr->mode = 0;
  4238. if (status != 0) {
  4239. fattr->mode |= nfs_type2fmt[type];
  4240. fattr->valid |= status;
  4241. }
  4242. status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
  4243. if (status < 0)
  4244. goto xdr_error;
  4245. fattr->valid |= status;
  4246. status = decode_attr_size(xdr, bitmap, &fattr->size);
  4247. if (status < 0)
  4248. goto xdr_error;
  4249. fattr->valid |= status;
  4250. status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
  4251. if (status < 0)
  4252. goto xdr_error;
  4253. fattr->valid |= status;
  4254. err = 0;
  4255. status = decode_attr_error(xdr, bitmap, &err);
  4256. if (status < 0)
  4257. goto xdr_error;
  4258. status = decode_attr_filehandle(xdr, bitmap, fh);
  4259. if (status < 0)
  4260. goto xdr_error;
  4261. status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
  4262. if (status < 0)
  4263. goto xdr_error;
  4264. fattr->valid |= status;
  4265. status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
  4266. if (status < 0)
  4267. goto xdr_error;
  4268. fattr->valid |= status;
  4269. status = -EIO;
  4270. if (unlikely(bitmap[0]))
  4271. goto xdr_error;
  4272. status = decode_attr_mode(xdr, bitmap, &fmode);
  4273. if (status < 0)
  4274. goto xdr_error;
  4275. if (status != 0) {
  4276. fattr->mode |= fmode;
  4277. fattr->valid |= status;
  4278. }
  4279. status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
  4280. if (status < 0)
  4281. goto xdr_error;
  4282. fattr->valid |= status;
  4283. status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
  4284. if (status < 0)
  4285. goto xdr_error;
  4286. fattr->valid |= status;
  4287. status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
  4288. if (status < 0)
  4289. goto xdr_error;
  4290. fattr->valid |= status;
  4291. status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
  4292. if (status < 0)
  4293. goto xdr_error;
  4294. fattr->valid |= status;
  4295. status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
  4296. if (status < 0)
  4297. goto xdr_error;
  4298. fattr->valid |= status;
  4299. status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
  4300. if (status < 0)
  4301. goto xdr_error;
  4302. fattr->valid |= status;
  4303. status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
  4304. if (status < 0)
  4305. goto xdr_error;
  4306. fattr->valid |= status;
  4307. status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
  4308. if (status < 0)
  4309. goto xdr_error;
  4310. fattr->valid |= status;
  4311. status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
  4312. if (status < 0)
  4313. goto xdr_error;
  4314. fattr->valid |= status;
  4315. status = -EIO;
  4316. if (unlikely(bitmap[1]))
  4317. goto xdr_error;
  4318. status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
  4319. if (status < 0)
  4320. goto xdr_error;
  4321. if (label) {
  4322. status = decode_attr_security_label(xdr, bitmap, label);
  4323. if (status < 0)
  4324. goto xdr_error;
  4325. fattr->valid |= status;
  4326. }
  4327. xdr_error:
  4328. dprintk("%s: xdr returned %d\n", __func__, -status);
  4329. return status;
  4330. }
  4331. static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
  4332. struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
  4333. struct nfs4_label *label, const struct nfs_server *server)
  4334. {
  4335. unsigned int savep;
  4336. uint32_t attrlen,
  4337. bitmap[3] = {0};
  4338. int status;
  4339. status = decode_op_hdr(xdr, OP_GETATTR);
  4340. if (status < 0)
  4341. goto xdr_error;
  4342. status = decode_attr_bitmap(xdr, bitmap);
  4343. if (status < 0)
  4344. goto xdr_error;
  4345. status = decode_attr_length(xdr, &attrlen, &savep);
  4346. if (status < 0)
  4347. goto xdr_error;
  4348. status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
  4349. label, server);
  4350. if (status < 0)
  4351. goto xdr_error;
  4352. status = verify_attr_len(xdr, savep, attrlen);
  4353. xdr_error:
  4354. dprintk("%s: xdr returned %d\n", __func__, -status);
  4355. return status;
  4356. }
  4357. static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
  4358. struct nfs4_label *label, const struct nfs_server *server)
  4359. {
  4360. return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
  4361. }
  4362. static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
  4363. const struct nfs_server *server)
  4364. {
  4365. return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
  4366. }
  4367. /*
  4368. * Decode potentially multiple layout types.
  4369. */
  4370. static int decode_pnfs_layout_types(struct xdr_stream *xdr,
  4371. struct nfs_fsinfo *fsinfo)
  4372. {
  4373. __be32 *p;
  4374. uint32_t i;
  4375. p = xdr_inline_decode(xdr, 4);
  4376. if (unlikely(!p))
  4377. goto out_overflow;
  4378. fsinfo->nlayouttypes = be32_to_cpup(p);
  4379. /* pNFS is not supported by the underlying file system */
  4380. if (fsinfo->nlayouttypes == 0)
  4381. return 0;
  4382. /* Decode and set first layout type, move xdr->p past unused types */
  4383. p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
  4384. if (unlikely(!p))
  4385. goto out_overflow;
  4386. /* If we get too many, then just cap it at the max */
  4387. if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
  4388. printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
  4389. __func__, fsinfo->nlayouttypes);
  4390. fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
  4391. }
  4392. for(i = 0; i < fsinfo->nlayouttypes; ++i)
  4393. fsinfo->layouttype[i] = be32_to_cpup(p++);
  4394. return 0;
  4395. out_overflow:
  4396. print_overflow_msg(__func__, xdr);
  4397. return -EIO;
  4398. }
  4399. /*
  4400. * The type of file system exported.
  4401. * Note we must ensure that layouttype is set in any non-error case.
  4402. */
  4403. static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
  4404. struct nfs_fsinfo *fsinfo)
  4405. {
  4406. int status = 0;
  4407. dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
  4408. if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
  4409. return -EIO;
  4410. if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
  4411. status = decode_pnfs_layout_types(xdr, fsinfo);
  4412. bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
  4413. }
  4414. return status;
  4415. }
  4416. /*
  4417. * The prefered block size for layout directed io
  4418. */
  4419. static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
  4420. uint32_t *res)
  4421. {
  4422. __be32 *p;
  4423. dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
  4424. *res = 0;
  4425. if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
  4426. p = xdr_inline_decode(xdr, 4);
  4427. if (unlikely(!p)) {
  4428. print_overflow_msg(__func__, xdr);
  4429. return -EIO;
  4430. }
  4431. *res = be32_to_cpup(p);
  4432. bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
  4433. }
  4434. return 0;
  4435. }
  4436. /*
  4437. * The granularity of a CLONE operation.
  4438. */
  4439. static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
  4440. uint32_t *res)
  4441. {
  4442. __be32 *p;
  4443. dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
  4444. *res = 0;
  4445. if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
  4446. p = xdr_inline_decode(xdr, 4);
  4447. if (unlikely(!p)) {
  4448. print_overflow_msg(__func__, xdr);
  4449. return -EIO;
  4450. }
  4451. *res = be32_to_cpup(p);
  4452. bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
  4453. }
  4454. return 0;
  4455. }
  4456. static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
  4457. {
  4458. unsigned int savep;
  4459. uint32_t attrlen, bitmap[3];
  4460. int status;
  4461. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  4462. goto xdr_error;
  4463. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  4464. goto xdr_error;
  4465. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  4466. goto xdr_error;
  4467. fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
  4468. if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
  4469. goto xdr_error;
  4470. if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
  4471. goto xdr_error;
  4472. if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
  4473. goto xdr_error;
  4474. fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
  4475. if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
  4476. goto xdr_error;
  4477. fsinfo->wtpref = fsinfo->wtmax;
  4478. status = -EIO;
  4479. if (unlikely(bitmap[0]))
  4480. goto xdr_error;
  4481. status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
  4482. if (status != 0)
  4483. goto xdr_error;
  4484. status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
  4485. if (status != 0)
  4486. goto xdr_error;
  4487. status = -EIO;
  4488. if (unlikely(bitmap[1]))
  4489. goto xdr_error;
  4490. status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
  4491. if (status)
  4492. goto xdr_error;
  4493. status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
  4494. if (status)
  4495. goto xdr_error;
  4496. status = verify_attr_len(xdr, savep, attrlen);
  4497. xdr_error:
  4498. dprintk("%s: xdr returned %d!\n", __func__, -status);
  4499. return status;
  4500. }
  4501. static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
  4502. {
  4503. __be32 *p;
  4504. uint32_t len;
  4505. int status;
  4506. /* Zero handle first to allow comparisons */
  4507. memset(fh, 0, sizeof(*fh));
  4508. status = decode_op_hdr(xdr, OP_GETFH);
  4509. if (status)
  4510. return status;
  4511. p = xdr_inline_decode(xdr, 4);
  4512. if (unlikely(!p))
  4513. goto out_overflow;
  4514. len = be32_to_cpup(p);
  4515. if (len > NFS4_FHSIZE)
  4516. return -EIO;
  4517. fh->size = len;
  4518. p = xdr_inline_decode(xdr, len);
  4519. if (unlikely(!p))
  4520. goto out_overflow;
  4521. memcpy(fh->data, p, len);
  4522. return 0;
  4523. out_overflow:
  4524. print_overflow_msg(__func__, xdr);
  4525. return -EIO;
  4526. }
  4527. static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  4528. {
  4529. int status;
  4530. status = decode_op_hdr(xdr, OP_LINK);
  4531. if (status)
  4532. return status;
  4533. return decode_change_info(xdr, cinfo);
  4534. }
  4535. /*
  4536. * We create the owner, so we know a proper owner.id length is 4.
  4537. */
  4538. static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
  4539. {
  4540. uint64_t offset, length, clientid;
  4541. __be32 *p;
  4542. uint32_t namelen, type;
  4543. p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
  4544. if (unlikely(!p))
  4545. goto out_overflow;
  4546. p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
  4547. p = xdr_decode_hyper(p, &length);
  4548. type = be32_to_cpup(p++); /* 4 byte read */
  4549. if (fl != NULL) { /* manipulate file lock */
  4550. fl->fl_start = (loff_t)offset;
  4551. fl->fl_end = fl->fl_start + (loff_t)length - 1;
  4552. if (length == ~(uint64_t)0)
  4553. fl->fl_end = OFFSET_MAX;
  4554. fl->fl_type = F_WRLCK;
  4555. if (type & 1)
  4556. fl->fl_type = F_RDLCK;
  4557. fl->fl_pid = 0;
  4558. }
  4559. p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
  4560. namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
  4561. p = xdr_inline_decode(xdr, namelen); /* variable size field */
  4562. if (likely(p))
  4563. return -NFS4ERR_DENIED;
  4564. out_overflow:
  4565. print_overflow_msg(__func__, xdr);
  4566. return -EIO;
  4567. }
  4568. static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
  4569. {
  4570. int status;
  4571. status = decode_op_hdr(xdr, OP_LOCK);
  4572. if (status == -EIO)
  4573. goto out;
  4574. if (status == 0) {
  4575. status = decode_lock_stateid(xdr, &res->stateid);
  4576. if (unlikely(status))
  4577. goto out;
  4578. } else if (status == -NFS4ERR_DENIED)
  4579. status = decode_lock_denied(xdr, NULL);
  4580. if (res->open_seqid != NULL)
  4581. nfs_increment_open_seqid(status, res->open_seqid);
  4582. nfs_increment_lock_seqid(status, res->lock_seqid);
  4583. out:
  4584. return status;
  4585. }
  4586. static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
  4587. {
  4588. int status;
  4589. status = decode_op_hdr(xdr, OP_LOCKT);
  4590. if (status == -NFS4ERR_DENIED)
  4591. return decode_lock_denied(xdr, res->denied);
  4592. return status;
  4593. }
  4594. static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
  4595. {
  4596. int status;
  4597. status = decode_op_hdr(xdr, OP_LOCKU);
  4598. if (status != -EIO)
  4599. nfs_increment_lock_seqid(status, res->seqid);
  4600. if (status == 0)
  4601. status = decode_lock_stateid(xdr, &res->stateid);
  4602. return status;
  4603. }
  4604. static int decode_release_lockowner(struct xdr_stream *xdr)
  4605. {
  4606. return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
  4607. }
  4608. static int decode_lookup(struct xdr_stream *xdr)
  4609. {
  4610. return decode_op_hdr(xdr, OP_LOOKUP);
  4611. }
  4612. static int decode_lookupp(struct xdr_stream *xdr)
  4613. {
  4614. return decode_op_hdr(xdr, OP_LOOKUPP);
  4615. }
  4616. /* This is too sick! */
  4617. static int decode_space_limit(struct xdr_stream *xdr,
  4618. unsigned long *pagemod_limit)
  4619. {
  4620. __be32 *p;
  4621. uint32_t limit_type, nblocks, blocksize;
  4622. u64 maxsize = 0;
  4623. p = xdr_inline_decode(xdr, 12);
  4624. if (unlikely(!p))
  4625. goto out_overflow;
  4626. limit_type = be32_to_cpup(p++);
  4627. switch (limit_type) {
  4628. case NFS4_LIMIT_SIZE:
  4629. xdr_decode_hyper(p, &maxsize);
  4630. break;
  4631. case NFS4_LIMIT_BLOCKS:
  4632. nblocks = be32_to_cpup(p++);
  4633. blocksize = be32_to_cpup(p);
  4634. maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
  4635. }
  4636. maxsize >>= PAGE_SHIFT;
  4637. *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
  4638. return 0;
  4639. out_overflow:
  4640. print_overflow_msg(__func__, xdr);
  4641. return -EIO;
  4642. }
  4643. static int decode_rw_delegation(struct xdr_stream *xdr,
  4644. uint32_t delegation_type,
  4645. struct nfs_openres *res)
  4646. {
  4647. __be32 *p;
  4648. int status;
  4649. status = decode_delegation_stateid(xdr, &res->delegation);
  4650. if (unlikely(status))
  4651. return status;
  4652. p = xdr_inline_decode(xdr, 4);
  4653. if (unlikely(!p))
  4654. goto out_overflow;
  4655. res->do_recall = be32_to_cpup(p);
  4656. switch (delegation_type) {
  4657. case NFS4_OPEN_DELEGATE_READ:
  4658. res->delegation_type = FMODE_READ;
  4659. break;
  4660. case NFS4_OPEN_DELEGATE_WRITE:
  4661. res->delegation_type = FMODE_WRITE|FMODE_READ;
  4662. if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
  4663. return -EIO;
  4664. }
  4665. return decode_ace(xdr, NULL);
  4666. out_overflow:
  4667. print_overflow_msg(__func__, xdr);
  4668. return -EIO;
  4669. }
  4670. static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
  4671. {
  4672. __be32 *p;
  4673. uint32_t why_no_delegation;
  4674. p = xdr_inline_decode(xdr, 4);
  4675. if (unlikely(!p))
  4676. goto out_overflow;
  4677. why_no_delegation = be32_to_cpup(p);
  4678. switch (why_no_delegation) {
  4679. case WND4_CONTENTION:
  4680. case WND4_RESOURCE:
  4681. xdr_inline_decode(xdr, 4);
  4682. /* Ignore for now */
  4683. }
  4684. return 0;
  4685. out_overflow:
  4686. print_overflow_msg(__func__, xdr);
  4687. return -EIO;
  4688. }
  4689. static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
  4690. {
  4691. __be32 *p;
  4692. uint32_t delegation_type;
  4693. p = xdr_inline_decode(xdr, 4);
  4694. if (unlikely(!p))
  4695. goto out_overflow;
  4696. delegation_type = be32_to_cpup(p);
  4697. res->delegation_type = 0;
  4698. switch (delegation_type) {
  4699. case NFS4_OPEN_DELEGATE_NONE:
  4700. return 0;
  4701. case NFS4_OPEN_DELEGATE_READ:
  4702. case NFS4_OPEN_DELEGATE_WRITE:
  4703. return decode_rw_delegation(xdr, delegation_type, res);
  4704. case NFS4_OPEN_DELEGATE_NONE_EXT:
  4705. return decode_no_delegation(xdr, res);
  4706. }
  4707. return -EIO;
  4708. out_overflow:
  4709. print_overflow_msg(__func__, xdr);
  4710. return -EIO;
  4711. }
  4712. static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
  4713. {
  4714. __be32 *p;
  4715. uint32_t savewords, bmlen, i;
  4716. int status;
  4717. if (!__decode_op_hdr(xdr, OP_OPEN, &status))
  4718. return status;
  4719. nfs_increment_open_seqid(status, res->seqid);
  4720. if (status)
  4721. return status;
  4722. status = decode_open_stateid(xdr, &res->stateid);
  4723. if (unlikely(status))
  4724. return status;
  4725. decode_change_info(xdr, &res->cinfo);
  4726. p = xdr_inline_decode(xdr, 8);
  4727. if (unlikely(!p))
  4728. goto out_overflow;
  4729. res->rflags = be32_to_cpup(p++);
  4730. bmlen = be32_to_cpup(p);
  4731. if (bmlen > 10)
  4732. goto xdr_error;
  4733. p = xdr_inline_decode(xdr, bmlen << 2);
  4734. if (unlikely(!p))
  4735. goto out_overflow;
  4736. savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
  4737. for (i = 0; i < savewords; ++i)
  4738. res->attrset[i] = be32_to_cpup(p++);
  4739. for (; i < NFS4_BITMAP_SIZE; i++)
  4740. res->attrset[i] = 0;
  4741. return decode_delegation(xdr, res);
  4742. xdr_error:
  4743. dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
  4744. return -EIO;
  4745. out_overflow:
  4746. print_overflow_msg(__func__, xdr);
  4747. return -EIO;
  4748. }
  4749. static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
  4750. {
  4751. int status;
  4752. status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
  4753. if (status != -EIO)
  4754. nfs_increment_open_seqid(status, res->seqid);
  4755. if (!status)
  4756. status = decode_open_stateid(xdr, &res->stateid);
  4757. return status;
  4758. }
  4759. static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
  4760. {
  4761. int status;
  4762. status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
  4763. if (status != -EIO)
  4764. nfs_increment_open_seqid(status, res->seqid);
  4765. if (!status)
  4766. status = decode_open_stateid(xdr, &res->stateid);
  4767. return status;
  4768. }
  4769. static int decode_putfh(struct xdr_stream *xdr)
  4770. {
  4771. return decode_op_hdr(xdr, OP_PUTFH);
  4772. }
  4773. static int decode_putrootfh(struct xdr_stream *xdr)
  4774. {
  4775. return decode_op_hdr(xdr, OP_PUTROOTFH);
  4776. }
  4777. static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
  4778. struct nfs_pgio_res *res)
  4779. {
  4780. __be32 *p;
  4781. uint32_t count, eof, recvd;
  4782. int status;
  4783. status = decode_op_hdr(xdr, OP_READ);
  4784. if (status)
  4785. return status;
  4786. p = xdr_inline_decode(xdr, 8);
  4787. if (unlikely(!p))
  4788. goto out_overflow;
  4789. eof = be32_to_cpup(p++);
  4790. count = be32_to_cpup(p);
  4791. recvd = xdr_read_pages(xdr, count);
  4792. if (count > recvd) {
  4793. dprintk("NFS: server cheating in read reply: "
  4794. "count %u > recvd %u\n", count, recvd);
  4795. count = recvd;
  4796. eof = 0;
  4797. }
  4798. res->eof = eof;
  4799. res->count = count;
  4800. return 0;
  4801. out_overflow:
  4802. print_overflow_msg(__func__, xdr);
  4803. return -EIO;
  4804. }
  4805. static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
  4806. {
  4807. int status;
  4808. __be32 verf[2];
  4809. status = decode_op_hdr(xdr, OP_READDIR);
  4810. if (!status)
  4811. status = decode_verifier(xdr, readdir->verifier.data);
  4812. if (unlikely(status))
  4813. return status;
  4814. memcpy(verf, readdir->verifier.data, sizeof(verf));
  4815. dprintk("%s: verifier = %08x:%08x\n",
  4816. __func__, verf[0], verf[1]);
  4817. return xdr_read_pages(xdr, xdr->buf->page_len);
  4818. }
  4819. static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
  4820. {
  4821. struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
  4822. u32 len, recvd;
  4823. __be32 *p;
  4824. int status;
  4825. status = decode_op_hdr(xdr, OP_READLINK);
  4826. if (status)
  4827. return status;
  4828. /* Convert length of symlink */
  4829. p = xdr_inline_decode(xdr, 4);
  4830. if (unlikely(!p))
  4831. goto out_overflow;
  4832. len = be32_to_cpup(p);
  4833. if (len >= rcvbuf->page_len || len <= 0) {
  4834. dprintk("nfs: server returned giant symlink!\n");
  4835. return -ENAMETOOLONG;
  4836. }
  4837. recvd = xdr_read_pages(xdr, len);
  4838. if (recvd < len) {
  4839. dprintk("NFS: server cheating in readlink reply: "
  4840. "count %u > recvd %u\n", len, recvd);
  4841. return -EIO;
  4842. }
  4843. /*
  4844. * The XDR encode routine has set things up so that
  4845. * the link text will be copied directly into the
  4846. * buffer. We just have to do overflow-checking,
  4847. * and and null-terminate the text (the VFS expects
  4848. * null-termination).
  4849. */
  4850. xdr_terminate_string(rcvbuf, len);
  4851. return 0;
  4852. out_overflow:
  4853. print_overflow_msg(__func__, xdr);
  4854. return -EIO;
  4855. }
  4856. static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  4857. {
  4858. int status;
  4859. status = decode_op_hdr(xdr, OP_REMOVE);
  4860. if (status)
  4861. goto out;
  4862. status = decode_change_info(xdr, cinfo);
  4863. out:
  4864. return status;
  4865. }
  4866. static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
  4867. struct nfs4_change_info *new_cinfo)
  4868. {
  4869. int status;
  4870. status = decode_op_hdr(xdr, OP_RENAME);
  4871. if (status)
  4872. goto out;
  4873. if ((status = decode_change_info(xdr, old_cinfo)))
  4874. goto out;
  4875. status = decode_change_info(xdr, new_cinfo);
  4876. out:
  4877. return status;
  4878. }
  4879. static int decode_renew(struct xdr_stream *xdr)
  4880. {
  4881. return decode_op_hdr(xdr, OP_RENEW);
  4882. }
  4883. static int
  4884. decode_restorefh(struct xdr_stream *xdr)
  4885. {
  4886. return decode_op_hdr(xdr, OP_RESTOREFH);
  4887. }
  4888. static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
  4889. struct nfs_getaclres *res)
  4890. {
  4891. unsigned int savep;
  4892. uint32_t attrlen,
  4893. bitmap[3] = {0};
  4894. int status;
  4895. unsigned int pg_offset;
  4896. res->acl_len = 0;
  4897. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  4898. goto out;
  4899. xdr_enter_page(xdr, xdr->buf->page_len);
  4900. /* Calculate the offset of the page data */
  4901. pg_offset = xdr->buf->head[0].iov_len;
  4902. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  4903. goto out;
  4904. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  4905. goto out;
  4906. if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
  4907. return -EIO;
  4908. if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
  4909. /* The bitmap (xdr len + bitmaps) and the attr xdr len words
  4910. * are stored with the acl data to handle the problem of
  4911. * variable length bitmaps.*/
  4912. res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
  4913. res->acl_len = attrlen;
  4914. /* Check for receive buffer overflow */
  4915. if (res->acl_len > (xdr->nwords << 2) ||
  4916. res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
  4917. res->acl_flags |= NFS4_ACL_TRUNC;
  4918. dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
  4919. attrlen, xdr->nwords << 2);
  4920. }
  4921. } else
  4922. status = -EOPNOTSUPP;
  4923. out:
  4924. return status;
  4925. }
  4926. static int
  4927. decode_savefh(struct xdr_stream *xdr)
  4928. {
  4929. return decode_op_hdr(xdr, OP_SAVEFH);
  4930. }
  4931. static int decode_setattr(struct xdr_stream *xdr)
  4932. {
  4933. __be32 *p;
  4934. uint32_t bmlen;
  4935. int status;
  4936. status = decode_op_hdr(xdr, OP_SETATTR);
  4937. if (status)
  4938. return status;
  4939. p = xdr_inline_decode(xdr, 4);
  4940. if (unlikely(!p))
  4941. goto out_overflow;
  4942. bmlen = be32_to_cpup(p);
  4943. p = xdr_inline_decode(xdr, bmlen << 2);
  4944. if (likely(p))
  4945. return 0;
  4946. out_overflow:
  4947. print_overflow_msg(__func__, xdr);
  4948. return -EIO;
  4949. }
  4950. static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
  4951. {
  4952. __be32 *p;
  4953. uint32_t opnum;
  4954. int32_t nfserr;
  4955. p = xdr_inline_decode(xdr, 8);
  4956. if (unlikely(!p))
  4957. goto out_overflow;
  4958. opnum = be32_to_cpup(p++);
  4959. if (opnum != OP_SETCLIENTID) {
  4960. dprintk("nfs: decode_setclientid: Server returned operation"
  4961. " %d\n", opnum);
  4962. return -EIO;
  4963. }
  4964. nfserr = be32_to_cpup(p);
  4965. if (nfserr == NFS_OK) {
  4966. p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
  4967. if (unlikely(!p))
  4968. goto out_overflow;
  4969. p = xdr_decode_hyper(p, &res->clientid);
  4970. memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
  4971. } else if (nfserr == NFSERR_CLID_INUSE) {
  4972. uint32_t len;
  4973. /* skip netid string */
  4974. p = xdr_inline_decode(xdr, 4);
  4975. if (unlikely(!p))
  4976. goto out_overflow;
  4977. len = be32_to_cpup(p);
  4978. p = xdr_inline_decode(xdr, len);
  4979. if (unlikely(!p))
  4980. goto out_overflow;
  4981. /* skip uaddr string */
  4982. p = xdr_inline_decode(xdr, 4);
  4983. if (unlikely(!p))
  4984. goto out_overflow;
  4985. len = be32_to_cpup(p);
  4986. p = xdr_inline_decode(xdr, len);
  4987. if (unlikely(!p))
  4988. goto out_overflow;
  4989. return -NFSERR_CLID_INUSE;
  4990. } else
  4991. return nfs4_stat_to_errno(nfserr);
  4992. return 0;
  4993. out_overflow:
  4994. print_overflow_msg(__func__, xdr);
  4995. return -EIO;
  4996. }
  4997. static int decode_setclientid_confirm(struct xdr_stream *xdr)
  4998. {
  4999. return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
  5000. }
  5001. static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
  5002. {
  5003. __be32 *p;
  5004. int status;
  5005. status = decode_op_hdr(xdr, OP_WRITE);
  5006. if (status)
  5007. return status;
  5008. p = xdr_inline_decode(xdr, 8);
  5009. if (unlikely(!p))
  5010. goto out_overflow;
  5011. res->count = be32_to_cpup(p++);
  5012. res->verf->committed = be32_to_cpup(p++);
  5013. return decode_write_verifier(xdr, &res->verf->verifier);
  5014. out_overflow:
  5015. print_overflow_msg(__func__, xdr);
  5016. return -EIO;
  5017. }
  5018. static int decode_delegreturn(struct xdr_stream *xdr)
  5019. {
  5020. return decode_op_hdr(xdr, OP_DELEGRETURN);
  5021. }
  5022. static int decode_secinfo_gss(struct xdr_stream *xdr,
  5023. struct nfs4_secinfo4 *flavor)
  5024. {
  5025. u32 oid_len;
  5026. __be32 *p;
  5027. p = xdr_inline_decode(xdr, 4);
  5028. if (unlikely(!p))
  5029. goto out_overflow;
  5030. oid_len = be32_to_cpup(p);
  5031. if (oid_len > GSS_OID_MAX_LEN)
  5032. goto out_err;
  5033. p = xdr_inline_decode(xdr, oid_len);
  5034. if (unlikely(!p))
  5035. goto out_overflow;
  5036. memcpy(flavor->flavor_info.oid.data, p, oid_len);
  5037. flavor->flavor_info.oid.len = oid_len;
  5038. p = xdr_inline_decode(xdr, 8);
  5039. if (unlikely(!p))
  5040. goto out_overflow;
  5041. flavor->flavor_info.qop = be32_to_cpup(p++);
  5042. flavor->flavor_info.service = be32_to_cpup(p);
  5043. return 0;
  5044. out_overflow:
  5045. print_overflow_msg(__func__, xdr);
  5046. return -EIO;
  5047. out_err:
  5048. return -EINVAL;
  5049. }
  5050. static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
  5051. {
  5052. struct nfs4_secinfo4 *sec_flavor;
  5053. unsigned int i, num_flavors;
  5054. int status;
  5055. __be32 *p;
  5056. p = xdr_inline_decode(xdr, 4);
  5057. if (unlikely(!p))
  5058. goto out_overflow;
  5059. res->flavors->num_flavors = 0;
  5060. num_flavors = be32_to_cpup(p);
  5061. for (i = 0; i < num_flavors; i++) {
  5062. sec_flavor = &res->flavors->flavors[i];
  5063. if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
  5064. break;
  5065. p = xdr_inline_decode(xdr, 4);
  5066. if (unlikely(!p))
  5067. goto out_overflow;
  5068. sec_flavor->flavor = be32_to_cpup(p);
  5069. if (sec_flavor->flavor == RPC_AUTH_GSS) {
  5070. status = decode_secinfo_gss(xdr, sec_flavor);
  5071. if (status)
  5072. goto out;
  5073. }
  5074. res->flavors->num_flavors++;
  5075. }
  5076. status = 0;
  5077. out:
  5078. return status;
  5079. out_overflow:
  5080. print_overflow_msg(__func__, xdr);
  5081. return -EIO;
  5082. }
  5083. static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
  5084. {
  5085. int status = decode_op_hdr(xdr, OP_SECINFO);
  5086. if (status)
  5087. return status;
  5088. return decode_secinfo_common(xdr, res);
  5089. }
  5090. #if defined(CONFIG_NFS_V4_1)
  5091. static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
  5092. {
  5093. int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
  5094. if (status)
  5095. return status;
  5096. return decode_secinfo_common(xdr, res);
  5097. }
  5098. static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
  5099. {
  5100. __be32 *p;
  5101. uint32_t bitmap_words;
  5102. unsigned int i;
  5103. p = xdr_inline_decode(xdr, 4);
  5104. if (!p)
  5105. return -EIO;
  5106. bitmap_words = be32_to_cpup(p++);
  5107. if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
  5108. return -EIO;
  5109. p = xdr_inline_decode(xdr, 4 * bitmap_words);
  5110. for (i = 0; i < bitmap_words; i++)
  5111. op_map->u.words[i] = be32_to_cpup(p++);
  5112. return 0;
  5113. }
  5114. static int decode_exchange_id(struct xdr_stream *xdr,
  5115. struct nfs41_exchange_id_res *res)
  5116. {
  5117. __be32 *p;
  5118. uint32_t dummy;
  5119. char *dummy_str;
  5120. int status;
  5121. uint32_t impl_id_count;
  5122. status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
  5123. if (status)
  5124. return status;
  5125. p = xdr_inline_decode(xdr, 8);
  5126. if (unlikely(!p))
  5127. goto out_overflow;
  5128. xdr_decode_hyper(p, &res->clientid);
  5129. p = xdr_inline_decode(xdr, 12);
  5130. if (unlikely(!p))
  5131. goto out_overflow;
  5132. res->seqid = be32_to_cpup(p++);
  5133. res->flags = be32_to_cpup(p++);
  5134. res->state_protect.how = be32_to_cpup(p);
  5135. switch (res->state_protect.how) {
  5136. case SP4_NONE:
  5137. break;
  5138. case SP4_MACH_CRED:
  5139. status = decode_op_map(xdr, &res->state_protect.enforce);
  5140. if (status)
  5141. return status;
  5142. status = decode_op_map(xdr, &res->state_protect.allow);
  5143. if (status)
  5144. return status;
  5145. break;
  5146. default:
  5147. WARN_ON_ONCE(1);
  5148. return -EIO;
  5149. }
  5150. /* server_owner4.so_minor_id */
  5151. p = xdr_inline_decode(xdr, 8);
  5152. if (unlikely(!p))
  5153. goto out_overflow;
  5154. p = xdr_decode_hyper(p, &res->server_owner->minor_id);
  5155. /* server_owner4.so_major_id */
  5156. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  5157. if (unlikely(status))
  5158. return status;
  5159. memcpy(res->server_owner->major_id, dummy_str, dummy);
  5160. res->server_owner->major_id_sz = dummy;
  5161. /* server_scope4 */
  5162. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  5163. if (unlikely(status))
  5164. return status;
  5165. memcpy(res->server_scope->server_scope, dummy_str, dummy);
  5166. res->server_scope->server_scope_sz = dummy;
  5167. /* Implementation Id */
  5168. p = xdr_inline_decode(xdr, 4);
  5169. if (unlikely(!p))
  5170. goto out_overflow;
  5171. impl_id_count = be32_to_cpup(p++);
  5172. if (impl_id_count) {
  5173. /* nii_domain */
  5174. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  5175. if (unlikely(status))
  5176. return status;
  5177. memcpy(res->impl_id->domain, dummy_str, dummy);
  5178. /* nii_name */
  5179. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  5180. if (unlikely(status))
  5181. return status;
  5182. memcpy(res->impl_id->name, dummy_str, dummy);
  5183. /* nii_date */
  5184. p = xdr_inline_decode(xdr, 12);
  5185. if (unlikely(!p))
  5186. goto out_overflow;
  5187. p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
  5188. res->impl_id->date.nseconds = be32_to_cpup(p);
  5189. /* if there's more than one entry, ignore the rest */
  5190. }
  5191. return 0;
  5192. out_overflow:
  5193. print_overflow_msg(__func__, xdr);
  5194. return -EIO;
  5195. }
  5196. static int decode_chan_attrs(struct xdr_stream *xdr,
  5197. struct nfs4_channel_attrs *attrs)
  5198. {
  5199. __be32 *p;
  5200. u32 nr_attrs, val;
  5201. p = xdr_inline_decode(xdr, 28);
  5202. if (unlikely(!p))
  5203. goto out_overflow;
  5204. val = be32_to_cpup(p++); /* headerpadsz */
  5205. if (val)
  5206. return -EINVAL; /* no support for header padding yet */
  5207. attrs->max_rqst_sz = be32_to_cpup(p++);
  5208. attrs->max_resp_sz = be32_to_cpup(p++);
  5209. attrs->max_resp_sz_cached = be32_to_cpup(p++);
  5210. attrs->max_ops = be32_to_cpup(p++);
  5211. attrs->max_reqs = be32_to_cpup(p++);
  5212. nr_attrs = be32_to_cpup(p);
  5213. if (unlikely(nr_attrs > 1)) {
  5214. printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
  5215. "count %u\n", __func__, nr_attrs);
  5216. return -EINVAL;
  5217. }
  5218. if (nr_attrs == 1) {
  5219. p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
  5220. if (unlikely(!p))
  5221. goto out_overflow;
  5222. }
  5223. return 0;
  5224. out_overflow:
  5225. print_overflow_msg(__func__, xdr);
  5226. return -EIO;
  5227. }
  5228. static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
  5229. {
  5230. return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
  5231. }
  5232. static int decode_bind_conn_to_session(struct xdr_stream *xdr,
  5233. struct nfs41_bind_conn_to_session_res *res)
  5234. {
  5235. __be32 *p;
  5236. int status;
  5237. status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
  5238. if (!status)
  5239. status = decode_sessionid(xdr, &res->sessionid);
  5240. if (unlikely(status))
  5241. return status;
  5242. /* dir flags, rdma mode bool */
  5243. p = xdr_inline_decode(xdr, 8);
  5244. if (unlikely(!p))
  5245. goto out_overflow;
  5246. res->dir = be32_to_cpup(p++);
  5247. if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
  5248. return -EIO;
  5249. if (be32_to_cpup(p) == 0)
  5250. res->use_conn_in_rdma_mode = false;
  5251. else
  5252. res->use_conn_in_rdma_mode = true;
  5253. return 0;
  5254. out_overflow:
  5255. print_overflow_msg(__func__, xdr);
  5256. return -EIO;
  5257. }
  5258. static int decode_create_session(struct xdr_stream *xdr,
  5259. struct nfs41_create_session_res *res)
  5260. {
  5261. __be32 *p;
  5262. int status;
  5263. status = decode_op_hdr(xdr, OP_CREATE_SESSION);
  5264. if (!status)
  5265. status = decode_sessionid(xdr, &res->sessionid);
  5266. if (unlikely(status))
  5267. return status;
  5268. /* seqid, flags */
  5269. p = xdr_inline_decode(xdr, 8);
  5270. if (unlikely(!p))
  5271. goto out_overflow;
  5272. res->seqid = be32_to_cpup(p++);
  5273. res->flags = be32_to_cpup(p);
  5274. /* Channel attributes */
  5275. status = decode_chan_attrs(xdr, &res->fc_attrs);
  5276. if (!status)
  5277. status = decode_chan_attrs(xdr, &res->bc_attrs);
  5278. return status;
  5279. out_overflow:
  5280. print_overflow_msg(__func__, xdr);
  5281. return -EIO;
  5282. }
  5283. static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
  5284. {
  5285. return decode_op_hdr(xdr, OP_DESTROY_SESSION);
  5286. }
  5287. static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
  5288. {
  5289. return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
  5290. }
  5291. static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
  5292. {
  5293. return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
  5294. }
  5295. #endif /* CONFIG_NFS_V4_1 */
  5296. static int decode_sequence(struct xdr_stream *xdr,
  5297. struct nfs4_sequence_res *res,
  5298. struct rpc_rqst *rqstp)
  5299. {
  5300. #if defined(CONFIG_NFS_V4_1)
  5301. struct nfs4_session *session;
  5302. struct nfs4_sessionid id;
  5303. u32 dummy;
  5304. int status;
  5305. __be32 *p;
  5306. if (res->sr_slot == NULL)
  5307. return 0;
  5308. if (!res->sr_slot->table->session)
  5309. return 0;
  5310. status = decode_op_hdr(xdr, OP_SEQUENCE);
  5311. if (!status)
  5312. status = decode_sessionid(xdr, &id);
  5313. if (unlikely(status))
  5314. goto out_err;
  5315. /*
  5316. * If the server returns different values for sessionID, slotID or
  5317. * sequence number, the server is looney tunes.
  5318. */
  5319. status = -EREMOTEIO;
  5320. session = res->sr_slot->table->session;
  5321. if (memcmp(id.data, session->sess_id.data,
  5322. NFS4_MAX_SESSIONID_LEN)) {
  5323. dprintk("%s Invalid session id\n", __func__);
  5324. goto out_err;
  5325. }
  5326. p = xdr_inline_decode(xdr, 20);
  5327. if (unlikely(!p))
  5328. goto out_overflow;
  5329. /* seqid */
  5330. dummy = be32_to_cpup(p++);
  5331. if (dummy != res->sr_slot->seq_nr) {
  5332. dprintk("%s Invalid sequence number\n", __func__);
  5333. goto out_err;
  5334. }
  5335. /* slot id */
  5336. dummy = be32_to_cpup(p++);
  5337. if (dummy != res->sr_slot->slot_nr) {
  5338. dprintk("%s Invalid slot id\n", __func__);
  5339. goto out_err;
  5340. }
  5341. /* highest slot id */
  5342. res->sr_highest_slotid = be32_to_cpup(p++);
  5343. /* target highest slot id */
  5344. res->sr_target_highest_slotid = be32_to_cpup(p++);
  5345. /* result flags */
  5346. res->sr_status_flags = be32_to_cpup(p);
  5347. status = 0;
  5348. out_err:
  5349. res->sr_status = status;
  5350. return status;
  5351. out_overflow:
  5352. print_overflow_msg(__func__, xdr);
  5353. status = -EIO;
  5354. goto out_err;
  5355. #else /* CONFIG_NFS_V4_1 */
  5356. return 0;
  5357. #endif /* CONFIG_NFS_V4_1 */
  5358. }
  5359. #if defined(CONFIG_NFS_V4_1)
  5360. static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  5361. {
  5362. stateid->type = NFS4_LAYOUT_STATEID_TYPE;
  5363. return decode_stateid(xdr, stateid);
  5364. }
  5365. static int decode_getdeviceinfo(struct xdr_stream *xdr,
  5366. struct nfs4_getdeviceinfo_res *res)
  5367. {
  5368. struct pnfs_device *pdev = res->pdev;
  5369. __be32 *p;
  5370. uint32_t len, type;
  5371. int status;
  5372. status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
  5373. if (status) {
  5374. if (status == -ETOOSMALL) {
  5375. p = xdr_inline_decode(xdr, 4);
  5376. if (unlikely(!p))
  5377. goto out_overflow;
  5378. pdev->mincount = be32_to_cpup(p);
  5379. dprintk("%s: Min count too small. mincnt = %u\n",
  5380. __func__, pdev->mincount);
  5381. }
  5382. return status;
  5383. }
  5384. p = xdr_inline_decode(xdr, 8);
  5385. if (unlikely(!p))
  5386. goto out_overflow;
  5387. type = be32_to_cpup(p++);
  5388. if (type != pdev->layout_type) {
  5389. dprintk("%s: layout mismatch req: %u pdev: %u\n",
  5390. __func__, pdev->layout_type, type);
  5391. return -EINVAL;
  5392. }
  5393. /*
  5394. * Get the length of the opaque device_addr4. xdr_read_pages places
  5395. * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
  5396. * and places the remaining xdr data in xdr_buf->tail
  5397. */
  5398. pdev->mincount = be32_to_cpup(p);
  5399. if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
  5400. goto out_overflow;
  5401. /* Parse notification bitmap, verifying that it is zero. */
  5402. p = xdr_inline_decode(xdr, 4);
  5403. if (unlikely(!p))
  5404. goto out_overflow;
  5405. len = be32_to_cpup(p);
  5406. if (len) {
  5407. uint32_t i;
  5408. p = xdr_inline_decode(xdr, 4 * len);
  5409. if (unlikely(!p))
  5410. goto out_overflow;
  5411. res->notification = be32_to_cpup(p++);
  5412. for (i = 1; i < len; i++) {
  5413. if (be32_to_cpup(p++)) {
  5414. dprintk("%s: unsupported notification\n",
  5415. __func__);
  5416. return -EIO;
  5417. }
  5418. }
  5419. }
  5420. return 0;
  5421. out_overflow:
  5422. print_overflow_msg(__func__, xdr);
  5423. return -EIO;
  5424. }
  5425. static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
  5426. struct nfs4_layoutget_res *res)
  5427. {
  5428. __be32 *p;
  5429. int status;
  5430. u32 layout_count;
  5431. u32 recvd;
  5432. status = decode_op_hdr(xdr, OP_LAYOUTGET);
  5433. if (status)
  5434. return status;
  5435. p = xdr_inline_decode(xdr, 4);
  5436. if (unlikely(!p))
  5437. goto out_overflow;
  5438. res->return_on_close = be32_to_cpup(p);
  5439. decode_layout_stateid(xdr, &res->stateid);
  5440. p = xdr_inline_decode(xdr, 4);
  5441. if (unlikely(!p))
  5442. goto out_overflow;
  5443. layout_count = be32_to_cpup(p);
  5444. if (!layout_count) {
  5445. dprintk("%s: server responded with empty layout array\n",
  5446. __func__);
  5447. return -EINVAL;
  5448. }
  5449. p = xdr_inline_decode(xdr, 28);
  5450. if (unlikely(!p))
  5451. goto out_overflow;
  5452. p = xdr_decode_hyper(p, &res->range.offset);
  5453. p = xdr_decode_hyper(p, &res->range.length);
  5454. res->range.iomode = be32_to_cpup(p++);
  5455. res->type = be32_to_cpup(p++);
  5456. res->layoutp->len = be32_to_cpup(p);
  5457. dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
  5458. __func__,
  5459. (unsigned long)res->range.offset,
  5460. (unsigned long)res->range.length,
  5461. res->range.iomode,
  5462. res->type,
  5463. res->layoutp->len);
  5464. recvd = xdr_read_pages(xdr, res->layoutp->len);
  5465. if (res->layoutp->len > recvd) {
  5466. dprintk("NFS: server cheating in layoutget reply: "
  5467. "layout len %u > recvd %u\n",
  5468. res->layoutp->len, recvd);
  5469. return -EINVAL;
  5470. }
  5471. if (layout_count > 1) {
  5472. /* We only handle a length one array at the moment. Any
  5473. * further entries are just ignored. Note that this means
  5474. * the client may see a response that is less than the
  5475. * minimum it requested.
  5476. */
  5477. dprintk("%s: server responded with %d layouts, dropping tail\n",
  5478. __func__, layout_count);
  5479. }
  5480. return 0;
  5481. out_overflow:
  5482. print_overflow_msg(__func__, xdr);
  5483. return -EIO;
  5484. }
  5485. static int decode_layoutreturn(struct xdr_stream *xdr,
  5486. struct nfs4_layoutreturn_res *res)
  5487. {
  5488. __be32 *p;
  5489. int status;
  5490. status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
  5491. if (status)
  5492. return status;
  5493. p = xdr_inline_decode(xdr, 4);
  5494. if (unlikely(!p))
  5495. goto out_overflow;
  5496. res->lrs_present = be32_to_cpup(p);
  5497. if (res->lrs_present)
  5498. status = decode_layout_stateid(xdr, &res->stateid);
  5499. else
  5500. nfs4_stateid_copy(&res->stateid, &invalid_stateid);
  5501. return status;
  5502. out_overflow:
  5503. print_overflow_msg(__func__, xdr);
  5504. return -EIO;
  5505. }
  5506. static int decode_layoutcommit(struct xdr_stream *xdr,
  5507. struct rpc_rqst *req,
  5508. struct nfs4_layoutcommit_res *res)
  5509. {
  5510. __be32 *p;
  5511. __u32 sizechanged;
  5512. int status;
  5513. status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
  5514. res->status = status;
  5515. if (status)
  5516. return status;
  5517. p = xdr_inline_decode(xdr, 4);
  5518. if (unlikely(!p))
  5519. goto out_overflow;
  5520. sizechanged = be32_to_cpup(p);
  5521. if (sizechanged) {
  5522. /* throw away new size */
  5523. p = xdr_inline_decode(xdr, 8);
  5524. if (unlikely(!p))
  5525. goto out_overflow;
  5526. }
  5527. return 0;
  5528. out_overflow:
  5529. print_overflow_msg(__func__, xdr);
  5530. return -EIO;
  5531. }
  5532. static int decode_test_stateid(struct xdr_stream *xdr,
  5533. struct nfs41_test_stateid_res *res)
  5534. {
  5535. __be32 *p;
  5536. int status;
  5537. int num_res;
  5538. status = decode_op_hdr(xdr, OP_TEST_STATEID);
  5539. if (status)
  5540. return status;
  5541. p = xdr_inline_decode(xdr, 4);
  5542. if (unlikely(!p))
  5543. goto out_overflow;
  5544. num_res = be32_to_cpup(p++);
  5545. if (num_res != 1)
  5546. goto out;
  5547. p = xdr_inline_decode(xdr, 4);
  5548. if (unlikely(!p))
  5549. goto out_overflow;
  5550. res->status = be32_to_cpup(p++);
  5551. return status;
  5552. out_overflow:
  5553. print_overflow_msg(__func__, xdr);
  5554. out:
  5555. return -EIO;
  5556. }
  5557. static int decode_free_stateid(struct xdr_stream *xdr,
  5558. struct nfs41_free_stateid_res *res)
  5559. {
  5560. res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
  5561. return res->status;
  5562. }
  5563. #else
  5564. static inline
  5565. int decode_layoutreturn(struct xdr_stream *xdr,
  5566. struct nfs4_layoutreturn_res *res)
  5567. {
  5568. return 0;
  5569. }
  5570. #endif /* CONFIG_NFS_V4_1 */
  5571. /*
  5572. * END OF "GENERIC" DECODE ROUTINES.
  5573. */
  5574. /*
  5575. * Decode OPEN_DOWNGRADE response
  5576. */
  5577. static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
  5578. struct xdr_stream *xdr,
  5579. void *data)
  5580. {
  5581. struct nfs_closeres *res = data;
  5582. struct compound_hdr hdr;
  5583. int status;
  5584. status = decode_compound_hdr(xdr, &hdr);
  5585. if (status)
  5586. goto out;
  5587. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5588. if (status)
  5589. goto out;
  5590. status = decode_putfh(xdr);
  5591. if (status)
  5592. goto out;
  5593. if (res->lr_res) {
  5594. status = decode_layoutreturn(xdr, res->lr_res);
  5595. res->lr_ret = status;
  5596. if (status)
  5597. goto out;
  5598. }
  5599. status = decode_open_downgrade(xdr, res);
  5600. out:
  5601. return status;
  5602. }
  5603. /*
  5604. * Decode ACCESS response
  5605. */
  5606. static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5607. void *data)
  5608. {
  5609. struct nfs4_accessres *res = data;
  5610. struct compound_hdr hdr;
  5611. int status;
  5612. status = decode_compound_hdr(xdr, &hdr);
  5613. if (status)
  5614. goto out;
  5615. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5616. if (status)
  5617. goto out;
  5618. status = decode_putfh(xdr);
  5619. if (status != 0)
  5620. goto out;
  5621. status = decode_access(xdr, &res->supported, &res->access);
  5622. if (status != 0)
  5623. goto out;
  5624. decode_getfattr(xdr, res->fattr, res->server);
  5625. out:
  5626. return status;
  5627. }
  5628. /*
  5629. * Decode LOOKUP response
  5630. */
  5631. static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5632. void *data)
  5633. {
  5634. struct nfs4_lookup_res *res = data;
  5635. struct compound_hdr hdr;
  5636. int status;
  5637. status = decode_compound_hdr(xdr, &hdr);
  5638. if (status)
  5639. goto out;
  5640. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5641. if (status)
  5642. goto out;
  5643. status = decode_putfh(xdr);
  5644. if (status)
  5645. goto out;
  5646. status = decode_lookup(xdr);
  5647. if (status)
  5648. goto out;
  5649. status = decode_getfh(xdr, res->fh);
  5650. if (status)
  5651. goto out;
  5652. status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
  5653. out:
  5654. return status;
  5655. }
  5656. /*
  5657. * Decode LOOKUPP response
  5658. */
  5659. static int nfs4_xdr_dec_lookupp(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5660. void *data)
  5661. {
  5662. struct nfs4_lookupp_res *res = data;
  5663. struct compound_hdr hdr;
  5664. int status;
  5665. status = decode_compound_hdr(xdr, &hdr);
  5666. if (status)
  5667. goto out;
  5668. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5669. if (status)
  5670. goto out;
  5671. status = decode_putfh(xdr);
  5672. if (status)
  5673. goto out;
  5674. status = decode_lookupp(xdr);
  5675. if (status)
  5676. goto out;
  5677. status = decode_getfh(xdr, res->fh);
  5678. if (status)
  5679. goto out;
  5680. status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
  5681. out:
  5682. return status;
  5683. }
  5684. /*
  5685. * Decode LOOKUP_ROOT response
  5686. */
  5687. static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
  5688. struct xdr_stream *xdr,
  5689. void *data)
  5690. {
  5691. struct nfs4_lookup_res *res = data;
  5692. struct compound_hdr hdr;
  5693. int status;
  5694. status = decode_compound_hdr(xdr, &hdr);
  5695. if (status)
  5696. goto out;
  5697. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5698. if (status)
  5699. goto out;
  5700. status = decode_putrootfh(xdr);
  5701. if (status)
  5702. goto out;
  5703. status = decode_getfh(xdr, res->fh);
  5704. if (status == 0)
  5705. status = decode_getfattr_label(xdr, res->fattr,
  5706. res->label, res->server);
  5707. out:
  5708. return status;
  5709. }
  5710. /*
  5711. * Decode REMOVE response
  5712. */
  5713. static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5714. void *data)
  5715. {
  5716. struct nfs_removeres *res = data;
  5717. struct compound_hdr hdr;
  5718. int status;
  5719. status = decode_compound_hdr(xdr, &hdr);
  5720. if (status)
  5721. goto out;
  5722. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5723. if (status)
  5724. goto out;
  5725. status = decode_putfh(xdr);
  5726. if (status)
  5727. goto out;
  5728. status = decode_remove(xdr, &res->cinfo);
  5729. out:
  5730. return status;
  5731. }
  5732. /*
  5733. * Decode RENAME response
  5734. */
  5735. static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5736. void *data)
  5737. {
  5738. struct nfs_renameres *res = data;
  5739. struct compound_hdr hdr;
  5740. int status;
  5741. status = decode_compound_hdr(xdr, &hdr);
  5742. if (status)
  5743. goto out;
  5744. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5745. if (status)
  5746. goto out;
  5747. status = decode_putfh(xdr);
  5748. if (status)
  5749. goto out;
  5750. status = decode_savefh(xdr);
  5751. if (status)
  5752. goto out;
  5753. status = decode_putfh(xdr);
  5754. if (status)
  5755. goto out;
  5756. status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
  5757. out:
  5758. return status;
  5759. }
  5760. /*
  5761. * Decode LINK response
  5762. */
  5763. static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5764. void *data)
  5765. {
  5766. struct nfs4_link_res *res = data;
  5767. struct compound_hdr hdr;
  5768. int status;
  5769. status = decode_compound_hdr(xdr, &hdr);
  5770. if (status)
  5771. goto out;
  5772. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5773. if (status)
  5774. goto out;
  5775. status = decode_putfh(xdr);
  5776. if (status)
  5777. goto out;
  5778. status = decode_savefh(xdr);
  5779. if (status)
  5780. goto out;
  5781. status = decode_putfh(xdr);
  5782. if (status)
  5783. goto out;
  5784. status = decode_link(xdr, &res->cinfo);
  5785. if (status)
  5786. goto out;
  5787. /*
  5788. * Note order: OP_LINK leaves the directory as the current
  5789. * filehandle.
  5790. */
  5791. status = decode_restorefh(xdr);
  5792. if (status)
  5793. goto out;
  5794. decode_getfattr_label(xdr, res->fattr, res->label, res->server);
  5795. out:
  5796. return status;
  5797. }
  5798. /*
  5799. * Decode CREATE response
  5800. */
  5801. static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5802. void *data)
  5803. {
  5804. struct nfs4_create_res *res = data;
  5805. struct compound_hdr hdr;
  5806. int status;
  5807. status = decode_compound_hdr(xdr, &hdr);
  5808. if (status)
  5809. goto out;
  5810. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5811. if (status)
  5812. goto out;
  5813. status = decode_putfh(xdr);
  5814. if (status)
  5815. goto out;
  5816. status = decode_create(xdr, &res->dir_cinfo);
  5817. if (status)
  5818. goto out;
  5819. status = decode_getfh(xdr, res->fh);
  5820. if (status)
  5821. goto out;
  5822. decode_getfattr_label(xdr, res->fattr, res->label, res->server);
  5823. out:
  5824. return status;
  5825. }
  5826. /*
  5827. * Decode SYMLINK response
  5828. */
  5829. static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5830. void *res)
  5831. {
  5832. return nfs4_xdr_dec_create(rqstp, xdr, res);
  5833. }
  5834. /*
  5835. * Decode GETATTR response
  5836. */
  5837. static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5838. void *data)
  5839. {
  5840. struct nfs4_getattr_res *res = data;
  5841. struct compound_hdr hdr;
  5842. int status;
  5843. status = decode_compound_hdr(xdr, &hdr);
  5844. if (status)
  5845. goto out;
  5846. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5847. if (status)
  5848. goto out;
  5849. status = decode_putfh(xdr);
  5850. if (status)
  5851. goto out;
  5852. status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
  5853. out:
  5854. return status;
  5855. }
  5856. /*
  5857. * Encode an SETACL request
  5858. */
  5859. static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
  5860. const void *data)
  5861. {
  5862. const struct nfs_setaclargs *args = data;
  5863. struct compound_hdr hdr = {
  5864. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  5865. };
  5866. encode_compound_hdr(xdr, req, &hdr);
  5867. encode_sequence(xdr, &args->seq_args, &hdr);
  5868. encode_putfh(xdr, args->fh, &hdr);
  5869. encode_setacl(xdr, args, &hdr);
  5870. encode_nops(&hdr);
  5871. }
  5872. /*
  5873. * Decode SETACL response
  5874. */
  5875. static int
  5876. nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5877. void *data)
  5878. {
  5879. struct nfs_setaclres *res = data;
  5880. struct compound_hdr hdr;
  5881. int status;
  5882. status = decode_compound_hdr(xdr, &hdr);
  5883. if (status)
  5884. goto out;
  5885. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5886. if (status)
  5887. goto out;
  5888. status = decode_putfh(xdr);
  5889. if (status)
  5890. goto out;
  5891. status = decode_setattr(xdr);
  5892. out:
  5893. return status;
  5894. }
  5895. /*
  5896. * Decode GETACL response
  5897. */
  5898. static int
  5899. nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5900. void *data)
  5901. {
  5902. struct nfs_getaclres *res = data;
  5903. struct compound_hdr hdr;
  5904. int status;
  5905. if (res->acl_scratch != NULL) {
  5906. void *p = page_address(res->acl_scratch);
  5907. xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
  5908. }
  5909. status = decode_compound_hdr(xdr, &hdr);
  5910. if (status)
  5911. goto out;
  5912. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5913. if (status)
  5914. goto out;
  5915. status = decode_putfh(xdr);
  5916. if (status)
  5917. goto out;
  5918. status = decode_getacl(xdr, rqstp, res);
  5919. out:
  5920. return status;
  5921. }
  5922. /*
  5923. * Decode CLOSE response
  5924. */
  5925. static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5926. void *data)
  5927. {
  5928. struct nfs_closeres *res = data;
  5929. struct compound_hdr hdr;
  5930. int status;
  5931. status = decode_compound_hdr(xdr, &hdr);
  5932. if (status)
  5933. goto out;
  5934. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5935. if (status)
  5936. goto out;
  5937. status = decode_putfh(xdr);
  5938. if (status)
  5939. goto out;
  5940. if (res->lr_res) {
  5941. status = decode_layoutreturn(xdr, res->lr_res);
  5942. res->lr_ret = status;
  5943. if (status)
  5944. goto out;
  5945. }
  5946. if (res->fattr != NULL) {
  5947. status = decode_getfattr(xdr, res->fattr, res->server);
  5948. if (status != 0)
  5949. goto out;
  5950. }
  5951. status = decode_close(xdr, res);
  5952. out:
  5953. return status;
  5954. }
  5955. /*
  5956. * Decode OPEN response
  5957. */
  5958. static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5959. void *data)
  5960. {
  5961. struct nfs_openres *res = data;
  5962. struct compound_hdr hdr;
  5963. int status;
  5964. status = decode_compound_hdr(xdr, &hdr);
  5965. if (status)
  5966. goto out;
  5967. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5968. if (status)
  5969. goto out;
  5970. status = decode_putfh(xdr);
  5971. if (status)
  5972. goto out;
  5973. status = decode_open(xdr, res);
  5974. if (status)
  5975. goto out;
  5976. status = decode_getfh(xdr, &res->fh);
  5977. if (status)
  5978. goto out;
  5979. if (res->access_request)
  5980. decode_access(xdr, &res->access_supported, &res->access_result);
  5981. decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
  5982. out:
  5983. return status;
  5984. }
  5985. /*
  5986. * Decode OPEN_CONFIRM response
  5987. */
  5988. static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
  5989. struct xdr_stream *xdr,
  5990. void *data)
  5991. {
  5992. struct nfs_open_confirmres *res = data;
  5993. struct compound_hdr hdr;
  5994. int status;
  5995. status = decode_compound_hdr(xdr, &hdr);
  5996. if (status)
  5997. goto out;
  5998. status = decode_putfh(xdr);
  5999. if (status)
  6000. goto out;
  6001. status = decode_open_confirm(xdr, res);
  6002. out:
  6003. return status;
  6004. }
  6005. /*
  6006. * Decode OPEN response
  6007. */
  6008. static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
  6009. struct xdr_stream *xdr,
  6010. void *data)
  6011. {
  6012. struct nfs_openres *res = data;
  6013. struct compound_hdr hdr;
  6014. int status;
  6015. status = decode_compound_hdr(xdr, &hdr);
  6016. if (status)
  6017. goto out;
  6018. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6019. if (status)
  6020. goto out;
  6021. status = decode_putfh(xdr);
  6022. if (status)
  6023. goto out;
  6024. status = decode_open(xdr, res);
  6025. if (status)
  6026. goto out;
  6027. if (res->access_request)
  6028. decode_access(xdr, &res->access_supported, &res->access_result);
  6029. decode_getfattr(xdr, res->f_attr, res->server);
  6030. out:
  6031. return status;
  6032. }
  6033. /*
  6034. * Decode SETATTR response
  6035. */
  6036. static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
  6037. struct xdr_stream *xdr,
  6038. void *data)
  6039. {
  6040. struct nfs_setattrres *res = data;
  6041. struct compound_hdr hdr;
  6042. int status;
  6043. status = decode_compound_hdr(xdr, &hdr);
  6044. if (status)
  6045. goto out;
  6046. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6047. if (status)
  6048. goto out;
  6049. status = decode_putfh(xdr);
  6050. if (status)
  6051. goto out;
  6052. status = decode_setattr(xdr);
  6053. if (status)
  6054. goto out;
  6055. decode_getfattr_label(xdr, res->fattr, res->label, res->server);
  6056. out:
  6057. return status;
  6058. }
  6059. /*
  6060. * Decode LOCK response
  6061. */
  6062. static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6063. void *data)
  6064. {
  6065. struct nfs_lock_res *res = data;
  6066. struct compound_hdr hdr;
  6067. int status;
  6068. status = decode_compound_hdr(xdr, &hdr);
  6069. if (status)
  6070. goto out;
  6071. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6072. if (status)
  6073. goto out;
  6074. status = decode_putfh(xdr);
  6075. if (status)
  6076. goto out;
  6077. status = decode_lock(xdr, res);
  6078. out:
  6079. return status;
  6080. }
  6081. /*
  6082. * Decode LOCKT response
  6083. */
  6084. static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6085. void *data)
  6086. {
  6087. struct nfs_lockt_res *res = data;
  6088. struct compound_hdr hdr;
  6089. int status;
  6090. status = decode_compound_hdr(xdr, &hdr);
  6091. if (status)
  6092. goto out;
  6093. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6094. if (status)
  6095. goto out;
  6096. status = decode_putfh(xdr);
  6097. if (status)
  6098. goto out;
  6099. status = decode_lockt(xdr, res);
  6100. out:
  6101. return status;
  6102. }
  6103. /*
  6104. * Decode LOCKU response
  6105. */
  6106. static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6107. void *data)
  6108. {
  6109. struct nfs_locku_res *res = data;
  6110. struct compound_hdr hdr;
  6111. int status;
  6112. status = decode_compound_hdr(xdr, &hdr);
  6113. if (status)
  6114. goto out;
  6115. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6116. if (status)
  6117. goto out;
  6118. status = decode_putfh(xdr);
  6119. if (status)
  6120. goto out;
  6121. status = decode_locku(xdr, res);
  6122. out:
  6123. return status;
  6124. }
  6125. static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
  6126. struct xdr_stream *xdr, void *dummy)
  6127. {
  6128. struct compound_hdr hdr;
  6129. int status;
  6130. status = decode_compound_hdr(xdr, &hdr);
  6131. if (!status)
  6132. status = decode_release_lockowner(xdr);
  6133. return status;
  6134. }
  6135. /*
  6136. * Decode READLINK response
  6137. */
  6138. static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
  6139. struct xdr_stream *xdr,
  6140. void *data)
  6141. {
  6142. struct nfs4_readlink_res *res = data;
  6143. struct compound_hdr hdr;
  6144. int status;
  6145. status = decode_compound_hdr(xdr, &hdr);
  6146. if (status)
  6147. goto out;
  6148. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6149. if (status)
  6150. goto out;
  6151. status = decode_putfh(xdr);
  6152. if (status)
  6153. goto out;
  6154. status = decode_readlink(xdr, rqstp);
  6155. out:
  6156. return status;
  6157. }
  6158. /*
  6159. * Decode READDIR response
  6160. */
  6161. static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6162. void *data)
  6163. {
  6164. struct nfs4_readdir_res *res = data;
  6165. struct compound_hdr hdr;
  6166. int status;
  6167. status = decode_compound_hdr(xdr, &hdr);
  6168. if (status)
  6169. goto out;
  6170. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6171. if (status)
  6172. goto out;
  6173. status = decode_putfh(xdr);
  6174. if (status)
  6175. goto out;
  6176. status = decode_readdir(xdr, rqstp, res);
  6177. out:
  6178. return status;
  6179. }
  6180. /*
  6181. * Decode Read response
  6182. */
  6183. static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6184. void *data)
  6185. {
  6186. struct nfs_pgio_res *res = data;
  6187. struct compound_hdr hdr;
  6188. int status;
  6189. status = decode_compound_hdr(xdr, &hdr);
  6190. res->op_status = hdr.status;
  6191. if (status)
  6192. goto out;
  6193. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6194. if (status)
  6195. goto out;
  6196. status = decode_putfh(xdr);
  6197. if (status)
  6198. goto out;
  6199. status = decode_read(xdr, rqstp, res);
  6200. if (!status)
  6201. status = res->count;
  6202. out:
  6203. return status;
  6204. }
  6205. /*
  6206. * Decode WRITE response
  6207. */
  6208. static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6209. void *data)
  6210. {
  6211. struct nfs_pgio_res *res = data;
  6212. struct compound_hdr hdr;
  6213. int status;
  6214. status = decode_compound_hdr(xdr, &hdr);
  6215. res->op_status = hdr.status;
  6216. if (status)
  6217. goto out;
  6218. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6219. if (status)
  6220. goto out;
  6221. status = decode_putfh(xdr);
  6222. if (status)
  6223. goto out;
  6224. status = decode_write(xdr, res);
  6225. if (status)
  6226. goto out;
  6227. if (res->fattr)
  6228. decode_getfattr(xdr, res->fattr, res->server);
  6229. if (!status)
  6230. status = res->count;
  6231. out:
  6232. return status;
  6233. }
  6234. /*
  6235. * Decode COMMIT response
  6236. */
  6237. static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6238. void *data)
  6239. {
  6240. struct nfs_commitres *res = data;
  6241. struct compound_hdr hdr;
  6242. int status;
  6243. status = decode_compound_hdr(xdr, &hdr);
  6244. res->op_status = hdr.status;
  6245. if (status)
  6246. goto out;
  6247. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6248. if (status)
  6249. goto out;
  6250. status = decode_putfh(xdr);
  6251. if (status)
  6252. goto out;
  6253. status = decode_commit(xdr, res);
  6254. out:
  6255. return status;
  6256. }
  6257. /*
  6258. * Decode FSINFO response
  6259. */
  6260. static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
  6261. void *data)
  6262. {
  6263. struct nfs4_fsinfo_res *res = data;
  6264. struct compound_hdr hdr;
  6265. int status;
  6266. status = decode_compound_hdr(xdr, &hdr);
  6267. if (!status)
  6268. status = decode_sequence(xdr, &res->seq_res, req);
  6269. if (!status)
  6270. status = decode_putfh(xdr);
  6271. if (!status)
  6272. status = decode_fsinfo(xdr, res->fsinfo);
  6273. return status;
  6274. }
  6275. /*
  6276. * Decode PATHCONF response
  6277. */
  6278. static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
  6279. void *data)
  6280. {
  6281. struct nfs4_pathconf_res *res = data;
  6282. struct compound_hdr hdr;
  6283. int status;
  6284. status = decode_compound_hdr(xdr, &hdr);
  6285. if (!status)
  6286. status = decode_sequence(xdr, &res->seq_res, req);
  6287. if (!status)
  6288. status = decode_putfh(xdr);
  6289. if (!status)
  6290. status = decode_pathconf(xdr, res->pathconf);
  6291. return status;
  6292. }
  6293. /*
  6294. * Decode STATFS response
  6295. */
  6296. static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
  6297. void *data)
  6298. {
  6299. struct nfs4_statfs_res *res = data;
  6300. struct compound_hdr hdr;
  6301. int status;
  6302. status = decode_compound_hdr(xdr, &hdr);
  6303. if (!status)
  6304. status = decode_sequence(xdr, &res->seq_res, req);
  6305. if (!status)
  6306. status = decode_putfh(xdr);
  6307. if (!status)
  6308. status = decode_statfs(xdr, res->fsstat);
  6309. return status;
  6310. }
  6311. /*
  6312. * Decode GETATTR_BITMAP response
  6313. */
  6314. static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
  6315. struct xdr_stream *xdr,
  6316. void *data)
  6317. {
  6318. struct nfs4_server_caps_res *res = data;
  6319. struct compound_hdr hdr;
  6320. int status;
  6321. status = decode_compound_hdr(xdr, &hdr);
  6322. if (status)
  6323. goto out;
  6324. status = decode_sequence(xdr, &res->seq_res, req);
  6325. if (status)
  6326. goto out;
  6327. status = decode_putfh(xdr);
  6328. if (status)
  6329. goto out;
  6330. status = decode_server_caps(xdr, res);
  6331. out:
  6332. return status;
  6333. }
  6334. /*
  6335. * Decode RENEW response
  6336. */
  6337. static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6338. void *__unused)
  6339. {
  6340. struct compound_hdr hdr;
  6341. int status;
  6342. status = decode_compound_hdr(xdr, &hdr);
  6343. if (!status)
  6344. status = decode_renew(xdr);
  6345. return status;
  6346. }
  6347. /*
  6348. * Decode SETCLIENTID response
  6349. */
  6350. static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
  6351. struct xdr_stream *xdr,
  6352. void *data)
  6353. {
  6354. struct nfs4_setclientid_res *res = data;
  6355. struct compound_hdr hdr;
  6356. int status;
  6357. status = decode_compound_hdr(xdr, &hdr);
  6358. if (!status)
  6359. status = decode_setclientid(xdr, res);
  6360. return status;
  6361. }
  6362. /*
  6363. * Decode SETCLIENTID_CONFIRM response
  6364. */
  6365. static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
  6366. struct xdr_stream *xdr,
  6367. void *data)
  6368. {
  6369. struct compound_hdr hdr;
  6370. int status;
  6371. status = decode_compound_hdr(xdr, &hdr);
  6372. if (!status)
  6373. status = decode_setclientid_confirm(xdr);
  6374. return status;
  6375. }
  6376. /*
  6377. * Decode DELEGRETURN response
  6378. */
  6379. static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
  6380. struct xdr_stream *xdr,
  6381. void *data)
  6382. {
  6383. struct nfs4_delegreturnres *res = data;
  6384. struct compound_hdr hdr;
  6385. int status;
  6386. status = decode_compound_hdr(xdr, &hdr);
  6387. if (status)
  6388. goto out;
  6389. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6390. if (status)
  6391. goto out;
  6392. status = decode_putfh(xdr);
  6393. if (status != 0)
  6394. goto out;
  6395. if (res->lr_res) {
  6396. status = decode_layoutreturn(xdr, res->lr_res);
  6397. res->lr_ret = status;
  6398. if (status)
  6399. goto out;
  6400. }
  6401. if (res->fattr) {
  6402. status = decode_getfattr(xdr, res->fattr, res->server);
  6403. if (status != 0)
  6404. goto out;
  6405. }
  6406. status = decode_delegreturn(xdr);
  6407. out:
  6408. return status;
  6409. }
  6410. /*
  6411. * Decode FS_LOCATIONS response
  6412. */
  6413. static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
  6414. struct xdr_stream *xdr,
  6415. void *data)
  6416. {
  6417. struct nfs4_fs_locations_res *res = data;
  6418. struct compound_hdr hdr;
  6419. int status;
  6420. status = decode_compound_hdr(xdr, &hdr);
  6421. if (status)
  6422. goto out;
  6423. status = decode_sequence(xdr, &res->seq_res, req);
  6424. if (status)
  6425. goto out;
  6426. status = decode_putfh(xdr);
  6427. if (status)
  6428. goto out;
  6429. if (res->migration) {
  6430. xdr_enter_page(xdr, PAGE_SIZE);
  6431. status = decode_getfattr_generic(xdr,
  6432. &res->fs_locations->fattr,
  6433. NULL, res->fs_locations,
  6434. NULL, res->fs_locations->server);
  6435. if (status)
  6436. goto out;
  6437. if (res->renew)
  6438. status = decode_renew(xdr);
  6439. } else {
  6440. status = decode_lookup(xdr);
  6441. if (status)
  6442. goto out;
  6443. xdr_enter_page(xdr, PAGE_SIZE);
  6444. status = decode_getfattr_generic(xdr,
  6445. &res->fs_locations->fattr,
  6446. NULL, res->fs_locations,
  6447. NULL, res->fs_locations->server);
  6448. }
  6449. out:
  6450. return status;
  6451. }
  6452. /*
  6453. * Decode SECINFO response
  6454. */
  6455. static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
  6456. struct xdr_stream *xdr,
  6457. void *data)
  6458. {
  6459. struct nfs4_secinfo_res *res = data;
  6460. struct compound_hdr hdr;
  6461. int status;
  6462. status = decode_compound_hdr(xdr, &hdr);
  6463. if (status)
  6464. goto out;
  6465. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6466. if (status)
  6467. goto out;
  6468. status = decode_putfh(xdr);
  6469. if (status)
  6470. goto out;
  6471. status = decode_secinfo(xdr, res);
  6472. out:
  6473. return status;
  6474. }
  6475. /*
  6476. * Decode FSID_PRESENT response
  6477. */
  6478. static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
  6479. struct xdr_stream *xdr,
  6480. void *data)
  6481. {
  6482. struct nfs4_fsid_present_res *res = data;
  6483. struct compound_hdr hdr;
  6484. int status;
  6485. status = decode_compound_hdr(xdr, &hdr);
  6486. if (status)
  6487. goto out;
  6488. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6489. if (status)
  6490. goto out;
  6491. status = decode_putfh(xdr);
  6492. if (status)
  6493. goto out;
  6494. status = decode_getfh(xdr, res->fh);
  6495. if (status)
  6496. goto out;
  6497. if (res->renew)
  6498. status = decode_renew(xdr);
  6499. out:
  6500. return status;
  6501. }
  6502. #if defined(CONFIG_NFS_V4_1)
  6503. /*
  6504. * Decode BIND_CONN_TO_SESSION response
  6505. */
  6506. static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
  6507. struct xdr_stream *xdr,
  6508. void *res)
  6509. {
  6510. struct compound_hdr hdr;
  6511. int status;
  6512. status = decode_compound_hdr(xdr, &hdr);
  6513. if (!status)
  6514. status = decode_bind_conn_to_session(xdr, res);
  6515. return status;
  6516. }
  6517. /*
  6518. * Decode EXCHANGE_ID response
  6519. */
  6520. static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
  6521. struct xdr_stream *xdr,
  6522. void *res)
  6523. {
  6524. struct compound_hdr hdr;
  6525. int status;
  6526. status = decode_compound_hdr(xdr, &hdr);
  6527. if (!status)
  6528. status = decode_exchange_id(xdr, res);
  6529. return status;
  6530. }
  6531. /*
  6532. * Decode CREATE_SESSION response
  6533. */
  6534. static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
  6535. struct xdr_stream *xdr,
  6536. void *res)
  6537. {
  6538. struct compound_hdr hdr;
  6539. int status;
  6540. status = decode_compound_hdr(xdr, &hdr);
  6541. if (!status)
  6542. status = decode_create_session(xdr, res);
  6543. return status;
  6544. }
  6545. /*
  6546. * Decode DESTROY_SESSION response
  6547. */
  6548. static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
  6549. struct xdr_stream *xdr,
  6550. void *res)
  6551. {
  6552. struct compound_hdr hdr;
  6553. int status;
  6554. status = decode_compound_hdr(xdr, &hdr);
  6555. if (!status)
  6556. status = decode_destroy_session(xdr, res);
  6557. return status;
  6558. }
  6559. /*
  6560. * Decode DESTROY_CLIENTID response
  6561. */
  6562. static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
  6563. struct xdr_stream *xdr,
  6564. void *res)
  6565. {
  6566. struct compound_hdr hdr;
  6567. int status;
  6568. status = decode_compound_hdr(xdr, &hdr);
  6569. if (!status)
  6570. status = decode_destroy_clientid(xdr, res);
  6571. return status;
  6572. }
  6573. /*
  6574. * Decode SEQUENCE response
  6575. */
  6576. static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
  6577. struct xdr_stream *xdr,
  6578. void *res)
  6579. {
  6580. struct compound_hdr hdr;
  6581. int status;
  6582. status = decode_compound_hdr(xdr, &hdr);
  6583. if (!status)
  6584. status = decode_sequence(xdr, res, rqstp);
  6585. return status;
  6586. }
  6587. /*
  6588. * Decode GET_LEASE_TIME response
  6589. */
  6590. static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
  6591. struct xdr_stream *xdr,
  6592. void *data)
  6593. {
  6594. struct nfs4_get_lease_time_res *res = data;
  6595. struct compound_hdr hdr;
  6596. int status;
  6597. status = decode_compound_hdr(xdr, &hdr);
  6598. if (!status)
  6599. status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
  6600. if (!status)
  6601. status = decode_putrootfh(xdr);
  6602. if (!status)
  6603. status = decode_fsinfo(xdr, res->lr_fsinfo);
  6604. return status;
  6605. }
  6606. /*
  6607. * Decode RECLAIM_COMPLETE response
  6608. */
  6609. static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
  6610. struct xdr_stream *xdr,
  6611. void *data)
  6612. {
  6613. struct nfs41_reclaim_complete_res *res = data;
  6614. struct compound_hdr hdr;
  6615. int status;
  6616. status = decode_compound_hdr(xdr, &hdr);
  6617. if (!status)
  6618. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6619. if (!status)
  6620. status = decode_reclaim_complete(xdr, NULL);
  6621. return status;
  6622. }
  6623. /*
  6624. * Decode GETDEVINFO response
  6625. */
  6626. static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
  6627. struct xdr_stream *xdr,
  6628. void *data)
  6629. {
  6630. struct nfs4_getdeviceinfo_res *res = data;
  6631. struct compound_hdr hdr;
  6632. int status;
  6633. status = decode_compound_hdr(xdr, &hdr);
  6634. if (status != 0)
  6635. goto out;
  6636. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6637. if (status != 0)
  6638. goto out;
  6639. status = decode_getdeviceinfo(xdr, res);
  6640. out:
  6641. return status;
  6642. }
  6643. /*
  6644. * Decode LAYOUTGET response
  6645. */
  6646. static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
  6647. struct xdr_stream *xdr,
  6648. void *data)
  6649. {
  6650. struct nfs4_layoutget_res *res = data;
  6651. struct compound_hdr hdr;
  6652. int status;
  6653. status = decode_compound_hdr(xdr, &hdr);
  6654. if (status)
  6655. goto out;
  6656. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6657. if (status)
  6658. goto out;
  6659. status = decode_putfh(xdr);
  6660. if (status)
  6661. goto out;
  6662. status = decode_layoutget(xdr, rqstp, res);
  6663. out:
  6664. return status;
  6665. }
  6666. /*
  6667. * Decode LAYOUTRETURN response
  6668. */
  6669. static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
  6670. struct xdr_stream *xdr,
  6671. void *data)
  6672. {
  6673. struct nfs4_layoutreturn_res *res = data;
  6674. struct compound_hdr hdr;
  6675. int status;
  6676. status = decode_compound_hdr(xdr, &hdr);
  6677. if (status)
  6678. goto out;
  6679. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6680. if (status)
  6681. goto out;
  6682. status = decode_putfh(xdr);
  6683. if (status)
  6684. goto out;
  6685. status = decode_layoutreturn(xdr, res);
  6686. out:
  6687. return status;
  6688. }
  6689. /*
  6690. * Decode LAYOUTCOMMIT response
  6691. */
  6692. static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
  6693. struct xdr_stream *xdr,
  6694. void *data)
  6695. {
  6696. struct nfs4_layoutcommit_res *res = data;
  6697. struct compound_hdr hdr;
  6698. int status;
  6699. status = decode_compound_hdr(xdr, &hdr);
  6700. if (status)
  6701. goto out;
  6702. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6703. if (status)
  6704. goto out;
  6705. status = decode_putfh(xdr);
  6706. if (status)
  6707. goto out;
  6708. status = decode_layoutcommit(xdr, rqstp, res);
  6709. if (status)
  6710. goto out;
  6711. decode_getfattr(xdr, res->fattr, res->server);
  6712. out:
  6713. return status;
  6714. }
  6715. /*
  6716. * Decode SECINFO_NO_NAME response
  6717. */
  6718. static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
  6719. struct xdr_stream *xdr,
  6720. void *data)
  6721. {
  6722. struct nfs4_secinfo_res *res = data;
  6723. struct compound_hdr hdr;
  6724. int status;
  6725. status = decode_compound_hdr(xdr, &hdr);
  6726. if (status)
  6727. goto out;
  6728. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6729. if (status)
  6730. goto out;
  6731. status = decode_putrootfh(xdr);
  6732. if (status)
  6733. goto out;
  6734. status = decode_secinfo_no_name(xdr, res);
  6735. out:
  6736. return status;
  6737. }
  6738. /*
  6739. * Decode TEST_STATEID response
  6740. */
  6741. static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
  6742. struct xdr_stream *xdr,
  6743. void *data)
  6744. {
  6745. struct nfs41_test_stateid_res *res = data;
  6746. struct compound_hdr hdr;
  6747. int status;
  6748. status = decode_compound_hdr(xdr, &hdr);
  6749. if (status)
  6750. goto out;
  6751. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6752. if (status)
  6753. goto out;
  6754. status = decode_test_stateid(xdr, res);
  6755. out:
  6756. return status;
  6757. }
  6758. /*
  6759. * Decode FREE_STATEID response
  6760. */
  6761. static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
  6762. struct xdr_stream *xdr,
  6763. void *data)
  6764. {
  6765. struct nfs41_free_stateid_res *res = data;
  6766. struct compound_hdr hdr;
  6767. int status;
  6768. status = decode_compound_hdr(xdr, &hdr);
  6769. if (status)
  6770. goto out;
  6771. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6772. if (status)
  6773. goto out;
  6774. status = decode_free_stateid(xdr, res);
  6775. out:
  6776. return status;
  6777. }
  6778. #endif /* CONFIG_NFS_V4_1 */
  6779. /**
  6780. * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
  6781. * the local page cache.
  6782. * @xdr: XDR stream where entry resides
  6783. * @entry: buffer to fill in with entry data
  6784. * @plus: boolean indicating whether this should be a readdirplus entry
  6785. *
  6786. * Returns zero if successful, otherwise a negative errno value is
  6787. * returned.
  6788. *
  6789. * This function is not invoked during READDIR reply decoding, but
  6790. * rather whenever an application invokes the getdents(2) system call
  6791. * on a directory already in our cache.
  6792. */
  6793. int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
  6794. bool plus)
  6795. {
  6796. unsigned int savep;
  6797. uint32_t bitmap[3] = {0};
  6798. uint32_t len;
  6799. __be32 *p = xdr_inline_decode(xdr, 4);
  6800. if (unlikely(!p))
  6801. goto out_overflow;
  6802. if (*p == xdr_zero) {
  6803. p = xdr_inline_decode(xdr, 4);
  6804. if (unlikely(!p))
  6805. goto out_overflow;
  6806. if (*p == xdr_zero)
  6807. return -EAGAIN;
  6808. entry->eof = 1;
  6809. return -EBADCOOKIE;
  6810. }
  6811. p = xdr_inline_decode(xdr, 12);
  6812. if (unlikely(!p))
  6813. goto out_overflow;
  6814. entry->prev_cookie = entry->cookie;
  6815. p = xdr_decode_hyper(p, &entry->cookie);
  6816. entry->len = be32_to_cpup(p);
  6817. p = xdr_inline_decode(xdr, entry->len);
  6818. if (unlikely(!p))
  6819. goto out_overflow;
  6820. entry->name = (const char *) p;
  6821. /*
  6822. * In case the server doesn't return an inode number,
  6823. * we fake one here. (We don't use inode number 0,
  6824. * since glibc seems to choke on it...)
  6825. */
  6826. entry->ino = 1;
  6827. entry->fattr->valid = 0;
  6828. if (decode_attr_bitmap(xdr, bitmap) < 0)
  6829. goto out_overflow;
  6830. if (decode_attr_length(xdr, &len, &savep) < 0)
  6831. goto out_overflow;
  6832. if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
  6833. NULL, entry->label, entry->server) < 0)
  6834. goto out_overflow;
  6835. if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
  6836. entry->ino = entry->fattr->mounted_on_fileid;
  6837. else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
  6838. entry->ino = entry->fattr->fileid;
  6839. entry->d_type = DT_UNKNOWN;
  6840. if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
  6841. entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
  6842. return 0;
  6843. out_overflow:
  6844. print_overflow_msg(__func__, xdr);
  6845. return -EAGAIN;
  6846. }
  6847. /*
  6848. * We need to translate between nfs status return values and
  6849. * the local errno values which may not be the same.
  6850. */
  6851. static struct {
  6852. int stat;
  6853. int errno;
  6854. } nfs_errtbl[] = {
  6855. { NFS4_OK, 0 },
  6856. { NFS4ERR_PERM, -EPERM },
  6857. { NFS4ERR_NOENT, -ENOENT },
  6858. { NFS4ERR_IO, -errno_NFSERR_IO},
  6859. { NFS4ERR_NXIO, -ENXIO },
  6860. { NFS4ERR_ACCESS, -EACCES },
  6861. { NFS4ERR_EXIST, -EEXIST },
  6862. { NFS4ERR_XDEV, -EXDEV },
  6863. { NFS4ERR_NOTDIR, -ENOTDIR },
  6864. { NFS4ERR_ISDIR, -EISDIR },
  6865. { NFS4ERR_INVAL, -EINVAL },
  6866. { NFS4ERR_FBIG, -EFBIG },
  6867. { NFS4ERR_NOSPC, -ENOSPC },
  6868. { NFS4ERR_ROFS, -EROFS },
  6869. { NFS4ERR_MLINK, -EMLINK },
  6870. { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
  6871. { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
  6872. { NFS4ERR_DQUOT, -EDQUOT },
  6873. { NFS4ERR_STALE, -ESTALE },
  6874. { NFS4ERR_BADHANDLE, -EBADHANDLE },
  6875. { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
  6876. { NFS4ERR_NOTSUPP, -ENOTSUPP },
  6877. { NFS4ERR_TOOSMALL, -ETOOSMALL },
  6878. { NFS4ERR_SERVERFAULT, -EREMOTEIO },
  6879. { NFS4ERR_BADTYPE, -EBADTYPE },
  6880. { NFS4ERR_LOCKED, -EAGAIN },
  6881. { NFS4ERR_SYMLINK, -ELOOP },
  6882. { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
  6883. { NFS4ERR_DEADLOCK, -EDEADLK },
  6884. { -1, -EIO }
  6885. };
  6886. /*
  6887. * Convert an NFS error code to a local one.
  6888. * This one is used jointly by NFSv2 and NFSv3.
  6889. */
  6890. static int
  6891. nfs4_stat_to_errno(int stat)
  6892. {
  6893. int i;
  6894. for (i = 0; nfs_errtbl[i].stat != -1; i++) {
  6895. if (nfs_errtbl[i].stat == stat)
  6896. return nfs_errtbl[i].errno;
  6897. }
  6898. if (stat <= 10000 || stat > 10100) {
  6899. /* The server is looney tunes. */
  6900. return -EREMOTEIO;
  6901. }
  6902. /* If we cannot translate the error, the recovery routines should
  6903. * handle it.
  6904. * Note: remaining NFSv4 error codes have values > 10000, so should
  6905. * not conflict with native Linux error codes.
  6906. */
  6907. return -stat;
  6908. }
  6909. #ifdef CONFIG_NFS_V4_2
  6910. #include "nfs42xdr.c"
  6911. #endif /* CONFIG_NFS_V4_2 */
  6912. #define PROC(proc, argtype, restype) \
  6913. [NFSPROC4_CLNT_##proc] = { \
  6914. .p_proc = NFSPROC4_COMPOUND, \
  6915. .p_encode = nfs4_xdr_##argtype, \
  6916. .p_decode = nfs4_xdr_##restype, \
  6917. .p_arglen = NFS4_##argtype##_sz, \
  6918. .p_replen = NFS4_##restype##_sz, \
  6919. .p_statidx = NFSPROC4_CLNT_##proc, \
  6920. .p_name = #proc, \
  6921. }
  6922. #define STUB(proc) \
  6923. [NFSPROC4_CLNT_##proc] = { \
  6924. .p_name = #proc, \
  6925. }
  6926. const struct rpc_procinfo nfs4_procedures[] = {
  6927. PROC(READ, enc_read, dec_read),
  6928. PROC(WRITE, enc_write, dec_write),
  6929. PROC(COMMIT, enc_commit, dec_commit),
  6930. PROC(OPEN, enc_open, dec_open),
  6931. PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
  6932. PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
  6933. PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
  6934. PROC(CLOSE, enc_close, dec_close),
  6935. PROC(SETATTR, enc_setattr, dec_setattr),
  6936. PROC(FSINFO, enc_fsinfo, dec_fsinfo),
  6937. PROC(RENEW, enc_renew, dec_renew),
  6938. PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
  6939. PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
  6940. PROC(LOCK, enc_lock, dec_lock),
  6941. PROC(LOCKT, enc_lockt, dec_lockt),
  6942. PROC(LOCKU, enc_locku, dec_locku),
  6943. PROC(ACCESS, enc_access, dec_access),
  6944. PROC(GETATTR, enc_getattr, dec_getattr),
  6945. PROC(LOOKUP, enc_lookup, dec_lookup),
  6946. PROC(LOOKUPP, enc_lookupp, dec_lookupp),
  6947. PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
  6948. PROC(REMOVE, enc_remove, dec_remove),
  6949. PROC(RENAME, enc_rename, dec_rename),
  6950. PROC(LINK, enc_link, dec_link),
  6951. PROC(SYMLINK, enc_symlink, dec_symlink),
  6952. PROC(CREATE, enc_create, dec_create),
  6953. PROC(PATHCONF, enc_pathconf, dec_pathconf),
  6954. PROC(STATFS, enc_statfs, dec_statfs),
  6955. PROC(READLINK, enc_readlink, dec_readlink),
  6956. PROC(READDIR, enc_readdir, dec_readdir),
  6957. PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
  6958. PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
  6959. PROC(GETACL, enc_getacl, dec_getacl),
  6960. PROC(SETACL, enc_setacl, dec_setacl),
  6961. PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
  6962. PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
  6963. PROC(SECINFO, enc_secinfo, dec_secinfo),
  6964. PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
  6965. #if defined(CONFIG_NFS_V4_1)
  6966. PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
  6967. PROC(CREATE_SESSION, enc_create_session, dec_create_session),
  6968. PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
  6969. PROC(SEQUENCE, enc_sequence, dec_sequence),
  6970. PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
  6971. PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
  6972. PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
  6973. PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
  6974. PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
  6975. PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
  6976. PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
  6977. PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
  6978. PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
  6979. STUB(GETDEVICELIST),
  6980. PROC(BIND_CONN_TO_SESSION,
  6981. enc_bind_conn_to_session, dec_bind_conn_to_session),
  6982. PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
  6983. #endif /* CONFIG_NFS_V4_1 */
  6984. #ifdef CONFIG_NFS_V4_2
  6985. PROC(SEEK, enc_seek, dec_seek),
  6986. PROC(ALLOCATE, enc_allocate, dec_allocate),
  6987. PROC(DEALLOCATE, enc_deallocate, dec_deallocate),
  6988. PROC(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
  6989. PROC(CLONE, enc_clone, dec_clone),
  6990. PROC(COPY, enc_copy, dec_copy),
  6991. #endif /* CONFIG_NFS_V4_2 */
  6992. };
  6993. static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)];
  6994. const struct rpc_version nfs_version4 = {
  6995. .number = 4,
  6996. .nrprocs = ARRAY_SIZE(nfs4_procedures),
  6997. .procs = nfs4_procedures,
  6998. .counts = nfs_version4_counts,
  6999. };
  7000. /*
  7001. * Local variables:
  7002. * c-basic-offset: 8
  7003. * End:
  7004. */