nfs4xdr.c 185 KB

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