nfs4xdr.c 195 KB

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