nfs4xdr.c 185 KB

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