nfs4xdr.c 193 KB

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