nfs4xdr.c 192 KB

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