nfs4xdr.c 203 KB

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