nfs4xdr.c 175 KB

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