nfs4xdr.c 184 KB

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