nfs4xdr.c 192 KB

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