nfs4xdr.c 186 KB

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