nfs4xdr.c 190 KB

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