nfs4xdr.c 193 KB

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