nfs4xdr.c 163 KB

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