nfs4xdr.c 179 KB

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