nfs4xdr.c 194 KB

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