nfs4xdr.c 163 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291
  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. nfs4_stateid stateid;
  1636. __be32 *p;
  1637. p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
  1638. *p++ = cpu_to_be32(OP_LAYOUTGET);
  1639. *p++ = cpu_to_be32(0); /* Signal layout available */
  1640. *p++ = cpu_to_be32(args->type);
  1641. *p++ = cpu_to_be32(args->range.iomode);
  1642. p = xdr_encode_hyper(p, args->range.offset);
  1643. p = xdr_encode_hyper(p, args->range.length);
  1644. p = xdr_encode_hyper(p, args->minlength);
  1645. pnfs_choose_layoutget_stateid(&stateid, NFS_I(args->inode)->layout,
  1646. args->ctx->state);
  1647. p = xdr_encode_opaque_fixed(p, &stateid.data, NFS4_STATEID_SIZE);
  1648. *p = cpu_to_be32(args->maxcount);
  1649. dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
  1650. __func__,
  1651. args->type,
  1652. args->range.iomode,
  1653. (unsigned long)args->range.offset,
  1654. (unsigned long)args->range.length,
  1655. args->maxcount);
  1656. hdr->nops++;
  1657. hdr->replen += decode_layoutget_maxsz;
  1658. }
  1659. #endif /* CONFIG_NFS_V4_1 */
  1660. /*
  1661. * END OF "GENERIC" ENCODE ROUTINES.
  1662. */
  1663. static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
  1664. {
  1665. #if defined(CONFIG_NFS_V4_1)
  1666. if (args->sa_session)
  1667. return args->sa_session->clp->cl_mvops->minor_version;
  1668. #endif /* CONFIG_NFS_V4_1 */
  1669. return 0;
  1670. }
  1671. /*
  1672. * Encode an ACCESS request
  1673. */
  1674. static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
  1675. const struct nfs4_accessargs *args)
  1676. {
  1677. struct compound_hdr hdr = {
  1678. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1679. };
  1680. encode_compound_hdr(xdr, req, &hdr);
  1681. encode_sequence(xdr, &args->seq_args, &hdr);
  1682. encode_putfh(xdr, args->fh, &hdr);
  1683. encode_access(xdr, args->access, &hdr);
  1684. encode_getfattr(xdr, args->bitmask, &hdr);
  1685. encode_nops(&hdr);
  1686. }
  1687. /*
  1688. * Encode LOOKUP request
  1689. */
  1690. static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
  1691. const struct nfs4_lookup_arg *args)
  1692. {
  1693. struct compound_hdr hdr = {
  1694. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1695. };
  1696. encode_compound_hdr(xdr, req, &hdr);
  1697. encode_sequence(xdr, &args->seq_args, &hdr);
  1698. encode_putfh(xdr, args->dir_fh, &hdr);
  1699. encode_lookup(xdr, args->name, &hdr);
  1700. encode_getfh(xdr, &hdr);
  1701. encode_getfattr(xdr, args->bitmask, &hdr);
  1702. encode_nops(&hdr);
  1703. }
  1704. /*
  1705. * Encode LOOKUP_ROOT request
  1706. */
  1707. static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
  1708. struct xdr_stream *xdr,
  1709. const struct nfs4_lookup_root_arg *args)
  1710. {
  1711. struct compound_hdr hdr = {
  1712. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1713. };
  1714. encode_compound_hdr(xdr, req, &hdr);
  1715. encode_sequence(xdr, &args->seq_args, &hdr);
  1716. encode_putrootfh(xdr, &hdr);
  1717. encode_getfh(xdr, &hdr);
  1718. encode_getfattr(xdr, args->bitmask, &hdr);
  1719. encode_nops(&hdr);
  1720. }
  1721. /*
  1722. * Encode REMOVE request
  1723. */
  1724. static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
  1725. const struct nfs_removeargs *args)
  1726. {
  1727. struct compound_hdr hdr = {
  1728. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1729. };
  1730. encode_compound_hdr(xdr, req, &hdr);
  1731. encode_sequence(xdr, &args->seq_args, &hdr);
  1732. encode_putfh(xdr, args->fh, &hdr);
  1733. encode_remove(xdr, &args->name, &hdr);
  1734. encode_getfattr(xdr, args->bitmask, &hdr);
  1735. encode_nops(&hdr);
  1736. }
  1737. /*
  1738. * Encode RENAME request
  1739. */
  1740. static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
  1741. const struct nfs_renameargs *args)
  1742. {
  1743. struct compound_hdr hdr = {
  1744. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1745. };
  1746. encode_compound_hdr(xdr, req, &hdr);
  1747. encode_sequence(xdr, &args->seq_args, &hdr);
  1748. encode_putfh(xdr, args->old_dir, &hdr);
  1749. encode_savefh(xdr, &hdr);
  1750. encode_putfh(xdr, args->new_dir, &hdr);
  1751. encode_rename(xdr, args->old_name, args->new_name, &hdr);
  1752. encode_getfattr(xdr, args->bitmask, &hdr);
  1753. encode_restorefh(xdr, &hdr);
  1754. encode_getfattr(xdr, args->bitmask, &hdr);
  1755. encode_nops(&hdr);
  1756. }
  1757. /*
  1758. * Encode LINK request
  1759. */
  1760. static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
  1761. const struct nfs4_link_arg *args)
  1762. {
  1763. struct compound_hdr hdr = {
  1764. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1765. };
  1766. encode_compound_hdr(xdr, req, &hdr);
  1767. encode_sequence(xdr, &args->seq_args, &hdr);
  1768. encode_putfh(xdr, args->fh, &hdr);
  1769. encode_savefh(xdr, &hdr);
  1770. encode_putfh(xdr, args->dir_fh, &hdr);
  1771. encode_link(xdr, args->name, &hdr);
  1772. encode_getfattr(xdr, args->bitmask, &hdr);
  1773. encode_restorefh(xdr, &hdr);
  1774. encode_getfattr(xdr, args->bitmask, &hdr);
  1775. encode_nops(&hdr);
  1776. }
  1777. /*
  1778. * Encode CREATE request
  1779. */
  1780. static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
  1781. const struct nfs4_create_arg *args)
  1782. {
  1783. struct compound_hdr hdr = {
  1784. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1785. };
  1786. encode_compound_hdr(xdr, req, &hdr);
  1787. encode_sequence(xdr, &args->seq_args, &hdr);
  1788. encode_putfh(xdr, args->dir_fh, &hdr);
  1789. encode_savefh(xdr, &hdr);
  1790. encode_create(xdr, args, &hdr);
  1791. encode_getfh(xdr, &hdr);
  1792. encode_getfattr(xdr, args->bitmask, &hdr);
  1793. encode_restorefh(xdr, &hdr);
  1794. encode_getfattr(xdr, args->bitmask, &hdr);
  1795. encode_nops(&hdr);
  1796. }
  1797. /*
  1798. * Encode SYMLINK request
  1799. */
  1800. static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
  1801. const struct nfs4_create_arg *args)
  1802. {
  1803. nfs4_xdr_enc_create(req, xdr, args);
  1804. }
  1805. /*
  1806. * Encode GETATTR request
  1807. */
  1808. static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
  1809. const struct nfs4_getattr_arg *args)
  1810. {
  1811. struct compound_hdr hdr = {
  1812. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1813. };
  1814. encode_compound_hdr(xdr, req, &hdr);
  1815. encode_sequence(xdr, &args->seq_args, &hdr);
  1816. encode_putfh(xdr, args->fh, &hdr);
  1817. encode_getfattr(xdr, args->bitmask, &hdr);
  1818. encode_nops(&hdr);
  1819. }
  1820. /*
  1821. * Encode a CLOSE request
  1822. */
  1823. static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
  1824. struct nfs_closeargs *args)
  1825. {
  1826. struct compound_hdr hdr = {
  1827. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1828. };
  1829. encode_compound_hdr(xdr, req, &hdr);
  1830. encode_sequence(xdr, &args->seq_args, &hdr);
  1831. encode_putfh(xdr, args->fh, &hdr);
  1832. encode_close(xdr, args, &hdr);
  1833. encode_getfattr(xdr, args->bitmask, &hdr);
  1834. encode_nops(&hdr);
  1835. }
  1836. /*
  1837. * Encode an OPEN request
  1838. */
  1839. static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
  1840. struct nfs_openargs *args)
  1841. {
  1842. struct compound_hdr hdr = {
  1843. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1844. };
  1845. encode_compound_hdr(xdr, req, &hdr);
  1846. encode_sequence(xdr, &args->seq_args, &hdr);
  1847. encode_putfh(xdr, args->fh, &hdr);
  1848. encode_savefh(xdr, &hdr);
  1849. encode_open(xdr, args, &hdr);
  1850. encode_getfh(xdr, &hdr);
  1851. encode_getfattr(xdr, args->bitmask, &hdr);
  1852. encode_restorefh(xdr, &hdr);
  1853. encode_getfattr(xdr, args->bitmask, &hdr);
  1854. encode_nops(&hdr);
  1855. }
  1856. /*
  1857. * Encode an OPEN_CONFIRM request
  1858. */
  1859. static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
  1860. struct xdr_stream *xdr,
  1861. struct nfs_open_confirmargs *args)
  1862. {
  1863. struct compound_hdr hdr = {
  1864. .nops = 0,
  1865. };
  1866. encode_compound_hdr(xdr, req, &hdr);
  1867. encode_putfh(xdr, args->fh, &hdr);
  1868. encode_open_confirm(xdr, args, &hdr);
  1869. encode_nops(&hdr);
  1870. }
  1871. /*
  1872. * Encode an OPEN request with no attributes.
  1873. */
  1874. static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
  1875. struct xdr_stream *xdr,
  1876. struct nfs_openargs *args)
  1877. {
  1878. struct compound_hdr hdr = {
  1879. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1880. };
  1881. encode_compound_hdr(xdr, req, &hdr);
  1882. encode_sequence(xdr, &args->seq_args, &hdr);
  1883. encode_putfh(xdr, args->fh, &hdr);
  1884. encode_open(xdr, args, &hdr);
  1885. encode_getfattr(xdr, args->bitmask, &hdr);
  1886. encode_nops(&hdr);
  1887. }
  1888. /*
  1889. * Encode an OPEN_DOWNGRADE request
  1890. */
  1891. static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
  1892. struct xdr_stream *xdr,
  1893. struct nfs_closeargs *args)
  1894. {
  1895. struct compound_hdr hdr = {
  1896. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1897. };
  1898. encode_compound_hdr(xdr, req, &hdr);
  1899. encode_sequence(xdr, &args->seq_args, &hdr);
  1900. encode_putfh(xdr, args->fh, &hdr);
  1901. encode_open_downgrade(xdr, args, &hdr);
  1902. encode_getfattr(xdr, args->bitmask, &hdr);
  1903. encode_nops(&hdr);
  1904. }
  1905. /*
  1906. * Encode a LOCK request
  1907. */
  1908. static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
  1909. struct nfs_lock_args *args)
  1910. {
  1911. struct compound_hdr hdr = {
  1912. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1913. };
  1914. encode_compound_hdr(xdr, req, &hdr);
  1915. encode_sequence(xdr, &args->seq_args, &hdr);
  1916. encode_putfh(xdr, args->fh, &hdr);
  1917. encode_lock(xdr, args, &hdr);
  1918. encode_nops(&hdr);
  1919. }
  1920. /*
  1921. * Encode a LOCKT request
  1922. */
  1923. static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
  1924. struct nfs_lockt_args *args)
  1925. {
  1926. struct compound_hdr hdr = {
  1927. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1928. };
  1929. encode_compound_hdr(xdr, req, &hdr);
  1930. encode_sequence(xdr, &args->seq_args, &hdr);
  1931. encode_putfh(xdr, args->fh, &hdr);
  1932. encode_lockt(xdr, args, &hdr);
  1933. encode_nops(&hdr);
  1934. }
  1935. /*
  1936. * Encode a LOCKU request
  1937. */
  1938. static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
  1939. struct nfs_locku_args *args)
  1940. {
  1941. struct compound_hdr hdr = {
  1942. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1943. };
  1944. encode_compound_hdr(xdr, req, &hdr);
  1945. encode_sequence(xdr, &args->seq_args, &hdr);
  1946. encode_putfh(xdr, args->fh, &hdr);
  1947. encode_locku(xdr, args, &hdr);
  1948. encode_nops(&hdr);
  1949. }
  1950. static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
  1951. struct xdr_stream *xdr,
  1952. struct nfs_release_lockowner_args *args)
  1953. {
  1954. struct compound_hdr hdr = {
  1955. .minorversion = 0,
  1956. };
  1957. encode_compound_hdr(xdr, req, &hdr);
  1958. encode_release_lockowner(xdr, &args->lock_owner, &hdr);
  1959. encode_nops(&hdr);
  1960. }
  1961. /*
  1962. * Encode a READLINK request
  1963. */
  1964. static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
  1965. const struct nfs4_readlink *args)
  1966. {
  1967. struct compound_hdr hdr = {
  1968. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1969. };
  1970. encode_compound_hdr(xdr, req, &hdr);
  1971. encode_sequence(xdr, &args->seq_args, &hdr);
  1972. encode_putfh(xdr, args->fh, &hdr);
  1973. encode_readlink(xdr, args, req, &hdr);
  1974. xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
  1975. args->pgbase, args->pglen);
  1976. encode_nops(&hdr);
  1977. }
  1978. /*
  1979. * Encode a READDIR request
  1980. */
  1981. static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
  1982. const struct nfs4_readdir_arg *args)
  1983. {
  1984. struct compound_hdr hdr = {
  1985. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1986. };
  1987. encode_compound_hdr(xdr, req, &hdr);
  1988. encode_sequence(xdr, &args->seq_args, &hdr);
  1989. encode_putfh(xdr, args->fh, &hdr);
  1990. encode_readdir(xdr, args, req, &hdr);
  1991. xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
  1992. args->pgbase, args->count);
  1993. dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
  1994. __func__, hdr.replen << 2, args->pages,
  1995. args->pgbase, args->count);
  1996. encode_nops(&hdr);
  1997. }
  1998. /*
  1999. * Encode a READ request
  2000. */
  2001. static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
  2002. struct nfs_readargs *args)
  2003. {
  2004. struct compound_hdr hdr = {
  2005. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2006. };
  2007. encode_compound_hdr(xdr, req, &hdr);
  2008. encode_sequence(xdr, &args->seq_args, &hdr);
  2009. encode_putfh(xdr, args->fh, &hdr);
  2010. encode_read(xdr, args, &hdr);
  2011. xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
  2012. args->pages, args->pgbase, args->count);
  2013. req->rq_rcv_buf.flags |= XDRBUF_READ;
  2014. encode_nops(&hdr);
  2015. }
  2016. /*
  2017. * Encode an SETATTR request
  2018. */
  2019. static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
  2020. struct nfs_setattrargs *args)
  2021. {
  2022. struct compound_hdr hdr = {
  2023. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2024. };
  2025. encode_compound_hdr(xdr, req, &hdr);
  2026. encode_sequence(xdr, &args->seq_args, &hdr);
  2027. encode_putfh(xdr, args->fh, &hdr);
  2028. encode_setattr(xdr, args, args->server, &hdr);
  2029. encode_getfattr(xdr, args->bitmask, &hdr);
  2030. encode_nops(&hdr);
  2031. }
  2032. /*
  2033. * Encode a GETACL request
  2034. */
  2035. static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
  2036. struct nfs_getaclargs *args)
  2037. {
  2038. struct compound_hdr hdr = {
  2039. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2040. };
  2041. uint32_t replen;
  2042. encode_compound_hdr(xdr, req, &hdr);
  2043. encode_sequence(xdr, &args->seq_args, &hdr);
  2044. encode_putfh(xdr, args->fh, &hdr);
  2045. replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
  2046. encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
  2047. xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
  2048. args->acl_pages, args->acl_pgbase, args->acl_len);
  2049. encode_nops(&hdr);
  2050. }
  2051. /*
  2052. * Encode a WRITE request
  2053. */
  2054. static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
  2055. struct nfs_writeargs *args)
  2056. {
  2057. struct compound_hdr hdr = {
  2058. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2059. };
  2060. encode_compound_hdr(xdr, req, &hdr);
  2061. encode_sequence(xdr, &args->seq_args, &hdr);
  2062. encode_putfh(xdr, args->fh, &hdr);
  2063. encode_write(xdr, args, &hdr);
  2064. req->rq_snd_buf.flags |= XDRBUF_WRITE;
  2065. encode_getfattr(xdr, args->bitmask, &hdr);
  2066. encode_nops(&hdr);
  2067. }
  2068. /*
  2069. * a COMMIT request
  2070. */
  2071. static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
  2072. struct nfs_writeargs *args)
  2073. {
  2074. struct compound_hdr hdr = {
  2075. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2076. };
  2077. encode_compound_hdr(xdr, req, &hdr);
  2078. encode_sequence(xdr, &args->seq_args, &hdr);
  2079. encode_putfh(xdr, args->fh, &hdr);
  2080. encode_commit(xdr, args, &hdr);
  2081. encode_getfattr(xdr, args->bitmask, &hdr);
  2082. encode_nops(&hdr);
  2083. }
  2084. /*
  2085. * FSINFO request
  2086. */
  2087. static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
  2088. struct nfs4_fsinfo_arg *args)
  2089. {
  2090. struct compound_hdr hdr = {
  2091. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2092. };
  2093. encode_compound_hdr(xdr, req, &hdr);
  2094. encode_sequence(xdr, &args->seq_args, &hdr);
  2095. encode_putfh(xdr, args->fh, &hdr);
  2096. encode_fsinfo(xdr, args->bitmask, &hdr);
  2097. encode_nops(&hdr);
  2098. }
  2099. /*
  2100. * a PATHCONF request
  2101. */
  2102. static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
  2103. const struct nfs4_pathconf_arg *args)
  2104. {
  2105. struct compound_hdr hdr = {
  2106. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2107. };
  2108. encode_compound_hdr(xdr, req, &hdr);
  2109. encode_sequence(xdr, &args->seq_args, &hdr);
  2110. encode_putfh(xdr, args->fh, &hdr);
  2111. encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
  2112. &hdr);
  2113. encode_nops(&hdr);
  2114. }
  2115. /*
  2116. * a STATFS request
  2117. */
  2118. static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
  2119. const struct nfs4_statfs_arg *args)
  2120. {
  2121. struct compound_hdr hdr = {
  2122. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2123. };
  2124. encode_compound_hdr(xdr, req, &hdr);
  2125. encode_sequence(xdr, &args->seq_args, &hdr);
  2126. encode_putfh(xdr, args->fh, &hdr);
  2127. encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
  2128. args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
  2129. encode_nops(&hdr);
  2130. }
  2131. /*
  2132. * GETATTR_BITMAP request
  2133. */
  2134. static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
  2135. struct xdr_stream *xdr,
  2136. struct nfs4_server_caps_arg *args)
  2137. {
  2138. struct compound_hdr hdr = {
  2139. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2140. };
  2141. encode_compound_hdr(xdr, req, &hdr);
  2142. encode_sequence(xdr, &args->seq_args, &hdr);
  2143. encode_putfh(xdr, args->fhandle, &hdr);
  2144. encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
  2145. FATTR4_WORD0_LINK_SUPPORT|
  2146. FATTR4_WORD0_SYMLINK_SUPPORT|
  2147. FATTR4_WORD0_ACLSUPPORT, &hdr);
  2148. encode_nops(&hdr);
  2149. }
  2150. /*
  2151. * a RENEW request
  2152. */
  2153. static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
  2154. struct nfs_client *clp)
  2155. {
  2156. struct compound_hdr hdr = {
  2157. .nops = 0,
  2158. };
  2159. encode_compound_hdr(xdr, req, &hdr);
  2160. encode_renew(xdr, clp, &hdr);
  2161. encode_nops(&hdr);
  2162. }
  2163. /*
  2164. * a SETCLIENTID request
  2165. */
  2166. static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
  2167. struct xdr_stream *xdr,
  2168. struct nfs4_setclientid *sc)
  2169. {
  2170. struct compound_hdr hdr = {
  2171. .nops = 0,
  2172. };
  2173. encode_compound_hdr(xdr, req, &hdr);
  2174. encode_setclientid(xdr, sc, &hdr);
  2175. encode_nops(&hdr);
  2176. }
  2177. /*
  2178. * a SETCLIENTID_CONFIRM request
  2179. */
  2180. static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
  2181. struct xdr_stream *xdr,
  2182. struct nfs4_setclientid_res *arg)
  2183. {
  2184. struct compound_hdr hdr = {
  2185. .nops = 0,
  2186. };
  2187. const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
  2188. encode_compound_hdr(xdr, req, &hdr);
  2189. encode_setclientid_confirm(xdr, arg, &hdr);
  2190. encode_putrootfh(xdr, &hdr);
  2191. encode_fsinfo(xdr, lease_bitmap, &hdr);
  2192. encode_nops(&hdr);
  2193. }
  2194. /*
  2195. * DELEGRETURN request
  2196. */
  2197. static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
  2198. struct xdr_stream *xdr,
  2199. const struct nfs4_delegreturnargs *args)
  2200. {
  2201. struct compound_hdr hdr = {
  2202. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2203. };
  2204. encode_compound_hdr(xdr, req, &hdr);
  2205. encode_sequence(xdr, &args->seq_args, &hdr);
  2206. encode_putfh(xdr, args->fhandle, &hdr);
  2207. encode_delegreturn(xdr, args->stateid, &hdr);
  2208. encode_getfattr(xdr, args->bitmask, &hdr);
  2209. encode_nops(&hdr);
  2210. }
  2211. /*
  2212. * Encode FS_LOCATIONS request
  2213. */
  2214. static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
  2215. struct xdr_stream *xdr,
  2216. struct nfs4_fs_locations_arg *args)
  2217. {
  2218. struct compound_hdr hdr = {
  2219. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2220. };
  2221. uint32_t replen;
  2222. encode_compound_hdr(xdr, req, &hdr);
  2223. encode_sequence(xdr, &args->seq_args, &hdr);
  2224. encode_putfh(xdr, args->dir_fh, &hdr);
  2225. encode_lookup(xdr, args->name, &hdr);
  2226. replen = hdr.replen; /* get the attribute into args->page */
  2227. encode_fs_locations(xdr, args->bitmask, &hdr);
  2228. xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
  2229. 0, PAGE_SIZE);
  2230. encode_nops(&hdr);
  2231. }
  2232. #if defined(CONFIG_NFS_V4_1)
  2233. /*
  2234. * EXCHANGE_ID request
  2235. */
  2236. static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
  2237. struct xdr_stream *xdr,
  2238. struct nfs41_exchange_id_args *args)
  2239. {
  2240. struct compound_hdr hdr = {
  2241. .minorversion = args->client->cl_mvops->minor_version,
  2242. };
  2243. encode_compound_hdr(xdr, req, &hdr);
  2244. encode_exchange_id(xdr, args, &hdr);
  2245. encode_nops(&hdr);
  2246. }
  2247. /*
  2248. * a CREATE_SESSION request
  2249. */
  2250. static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
  2251. struct xdr_stream *xdr,
  2252. struct nfs41_create_session_args *args)
  2253. {
  2254. struct compound_hdr hdr = {
  2255. .minorversion = args->client->cl_mvops->minor_version,
  2256. };
  2257. encode_compound_hdr(xdr, req, &hdr);
  2258. encode_create_session(xdr, args, &hdr);
  2259. encode_nops(&hdr);
  2260. }
  2261. /*
  2262. * a DESTROY_SESSION request
  2263. */
  2264. static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
  2265. struct xdr_stream *xdr,
  2266. struct nfs4_session *session)
  2267. {
  2268. struct compound_hdr hdr = {
  2269. .minorversion = session->clp->cl_mvops->minor_version,
  2270. };
  2271. encode_compound_hdr(xdr, req, &hdr);
  2272. encode_destroy_session(xdr, session, &hdr);
  2273. encode_nops(&hdr);
  2274. }
  2275. /*
  2276. * a SEQUENCE request
  2277. */
  2278. static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
  2279. struct nfs4_sequence_args *args)
  2280. {
  2281. struct compound_hdr hdr = {
  2282. .minorversion = nfs4_xdr_minorversion(args),
  2283. };
  2284. encode_compound_hdr(xdr, req, &hdr);
  2285. encode_sequence(xdr, args, &hdr);
  2286. encode_nops(&hdr);
  2287. }
  2288. /*
  2289. * a GET_LEASE_TIME request
  2290. */
  2291. static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
  2292. struct xdr_stream *xdr,
  2293. struct nfs4_get_lease_time_args *args)
  2294. {
  2295. struct compound_hdr hdr = {
  2296. .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
  2297. };
  2298. const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
  2299. encode_compound_hdr(xdr, req, &hdr);
  2300. encode_sequence(xdr, &args->la_seq_args, &hdr);
  2301. encode_putrootfh(xdr, &hdr);
  2302. encode_fsinfo(xdr, lease_bitmap, &hdr);
  2303. encode_nops(&hdr);
  2304. }
  2305. /*
  2306. * a RECLAIM_COMPLETE request
  2307. */
  2308. static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
  2309. struct xdr_stream *xdr,
  2310. struct nfs41_reclaim_complete_args *args)
  2311. {
  2312. struct compound_hdr hdr = {
  2313. .minorversion = nfs4_xdr_minorversion(&args->seq_args)
  2314. };
  2315. encode_compound_hdr(xdr, req, &hdr);
  2316. encode_sequence(xdr, &args->seq_args, &hdr);
  2317. encode_reclaim_complete(xdr, args, &hdr);
  2318. encode_nops(&hdr);
  2319. }
  2320. /*
  2321. * Encode GETDEVICEINFO request
  2322. */
  2323. static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
  2324. struct xdr_stream *xdr,
  2325. struct nfs4_getdeviceinfo_args *args)
  2326. {
  2327. struct compound_hdr hdr = {
  2328. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2329. };
  2330. encode_compound_hdr(xdr, req, &hdr);
  2331. encode_sequence(xdr, &args->seq_args, &hdr);
  2332. encode_getdeviceinfo(xdr, args, &hdr);
  2333. /* set up reply kvec. Subtract notification bitmap max size (2)
  2334. * so that notification bitmap is put in xdr_buf tail */
  2335. xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
  2336. args->pdev->pages, args->pdev->pgbase,
  2337. args->pdev->pglen);
  2338. encode_nops(&hdr);
  2339. }
  2340. /*
  2341. * Encode LAYOUTGET request
  2342. */
  2343. static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
  2344. struct xdr_stream *xdr,
  2345. struct nfs4_layoutget_args *args)
  2346. {
  2347. struct compound_hdr hdr = {
  2348. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2349. };
  2350. encode_compound_hdr(xdr, req, &hdr);
  2351. encode_sequence(xdr, &args->seq_args, &hdr);
  2352. encode_putfh(xdr, NFS_FH(args->inode), &hdr);
  2353. encode_layoutget(xdr, args, &hdr);
  2354. encode_nops(&hdr);
  2355. }
  2356. #endif /* CONFIG_NFS_V4_1 */
  2357. static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
  2358. {
  2359. dprintk("nfs: %s: prematurely hit end of receive buffer. "
  2360. "Remaining buffer length is %tu words.\n",
  2361. func, xdr->end - xdr->p);
  2362. }
  2363. static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
  2364. {
  2365. __be32 *p;
  2366. p = xdr_inline_decode(xdr, 4);
  2367. if (unlikely(!p))
  2368. goto out_overflow;
  2369. *len = be32_to_cpup(p);
  2370. p = xdr_inline_decode(xdr, *len);
  2371. if (unlikely(!p))
  2372. goto out_overflow;
  2373. *string = (char *)p;
  2374. return 0;
  2375. out_overflow:
  2376. print_overflow_msg(__func__, xdr);
  2377. return -EIO;
  2378. }
  2379. static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
  2380. {
  2381. __be32 *p;
  2382. p = xdr_inline_decode(xdr, 8);
  2383. if (unlikely(!p))
  2384. goto out_overflow;
  2385. hdr->status = be32_to_cpup(p++);
  2386. hdr->taglen = be32_to_cpup(p);
  2387. p = xdr_inline_decode(xdr, hdr->taglen + 4);
  2388. if (unlikely(!p))
  2389. goto out_overflow;
  2390. hdr->tag = (char *)p;
  2391. p += XDR_QUADLEN(hdr->taglen);
  2392. hdr->nops = be32_to_cpup(p);
  2393. if (unlikely(hdr->nops < 1))
  2394. return nfs4_stat_to_errno(hdr->status);
  2395. return 0;
  2396. out_overflow:
  2397. print_overflow_msg(__func__, xdr);
  2398. return -EIO;
  2399. }
  2400. static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
  2401. {
  2402. __be32 *p;
  2403. uint32_t opnum;
  2404. int32_t nfserr;
  2405. p = xdr_inline_decode(xdr, 8);
  2406. if (unlikely(!p))
  2407. goto out_overflow;
  2408. opnum = be32_to_cpup(p++);
  2409. if (opnum != expected) {
  2410. dprintk("nfs: Server returned operation"
  2411. " %d but we issued a request for %d\n",
  2412. opnum, expected);
  2413. return -EIO;
  2414. }
  2415. nfserr = be32_to_cpup(p);
  2416. if (nfserr != NFS_OK)
  2417. return nfs4_stat_to_errno(nfserr);
  2418. return 0;
  2419. out_overflow:
  2420. print_overflow_msg(__func__, xdr);
  2421. return -EIO;
  2422. }
  2423. /* Dummy routine */
  2424. static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
  2425. {
  2426. __be32 *p;
  2427. unsigned int strlen;
  2428. char *str;
  2429. p = xdr_inline_decode(xdr, 12);
  2430. if (likely(p))
  2431. return decode_opaque_inline(xdr, &strlen, &str);
  2432. print_overflow_msg(__func__, xdr);
  2433. return -EIO;
  2434. }
  2435. static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
  2436. {
  2437. uint32_t bmlen;
  2438. __be32 *p;
  2439. p = xdr_inline_decode(xdr, 4);
  2440. if (unlikely(!p))
  2441. goto out_overflow;
  2442. bmlen = be32_to_cpup(p);
  2443. bitmap[0] = bitmap[1] = 0;
  2444. p = xdr_inline_decode(xdr, (bmlen << 2));
  2445. if (unlikely(!p))
  2446. goto out_overflow;
  2447. if (bmlen > 0) {
  2448. bitmap[0] = be32_to_cpup(p++);
  2449. if (bmlen > 1)
  2450. bitmap[1] = be32_to_cpup(p);
  2451. }
  2452. return 0;
  2453. out_overflow:
  2454. print_overflow_msg(__func__, xdr);
  2455. return -EIO;
  2456. }
  2457. static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
  2458. {
  2459. __be32 *p;
  2460. p = xdr_inline_decode(xdr, 4);
  2461. if (unlikely(!p))
  2462. goto out_overflow;
  2463. *attrlen = be32_to_cpup(p);
  2464. *savep = xdr->p;
  2465. return 0;
  2466. out_overflow:
  2467. print_overflow_msg(__func__, xdr);
  2468. return -EIO;
  2469. }
  2470. static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
  2471. {
  2472. if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
  2473. int ret;
  2474. ret = decode_attr_bitmap(xdr, bitmask);
  2475. if (unlikely(ret < 0))
  2476. return ret;
  2477. bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
  2478. } else
  2479. bitmask[0] = bitmask[1] = 0;
  2480. dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
  2481. return 0;
  2482. }
  2483. static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
  2484. {
  2485. __be32 *p;
  2486. int ret = 0;
  2487. *type = 0;
  2488. if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
  2489. return -EIO;
  2490. if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
  2491. p = xdr_inline_decode(xdr, 4);
  2492. if (unlikely(!p))
  2493. goto out_overflow;
  2494. *type = be32_to_cpup(p);
  2495. if (*type < NF4REG || *type > NF4NAMEDATTR) {
  2496. dprintk("%s: bad type %d\n", __func__, *type);
  2497. return -EIO;
  2498. }
  2499. bitmap[0] &= ~FATTR4_WORD0_TYPE;
  2500. ret = NFS_ATTR_FATTR_TYPE;
  2501. }
  2502. dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
  2503. return ret;
  2504. out_overflow:
  2505. print_overflow_msg(__func__, xdr);
  2506. return -EIO;
  2507. }
  2508. static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
  2509. {
  2510. __be32 *p;
  2511. int ret = 0;
  2512. *change = 0;
  2513. if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
  2514. return -EIO;
  2515. if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
  2516. p = xdr_inline_decode(xdr, 8);
  2517. if (unlikely(!p))
  2518. goto out_overflow;
  2519. xdr_decode_hyper(p, change);
  2520. bitmap[0] &= ~FATTR4_WORD0_CHANGE;
  2521. ret = NFS_ATTR_FATTR_CHANGE;
  2522. }
  2523. dprintk("%s: change attribute=%Lu\n", __func__,
  2524. (unsigned long long)*change);
  2525. return ret;
  2526. out_overflow:
  2527. print_overflow_msg(__func__, xdr);
  2528. return -EIO;
  2529. }
  2530. static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
  2531. {
  2532. __be32 *p;
  2533. int ret = 0;
  2534. *size = 0;
  2535. if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
  2536. return -EIO;
  2537. if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
  2538. p = xdr_inline_decode(xdr, 8);
  2539. if (unlikely(!p))
  2540. goto out_overflow;
  2541. xdr_decode_hyper(p, size);
  2542. bitmap[0] &= ~FATTR4_WORD0_SIZE;
  2543. ret = NFS_ATTR_FATTR_SIZE;
  2544. }
  2545. dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
  2546. return ret;
  2547. out_overflow:
  2548. print_overflow_msg(__func__, xdr);
  2549. return -EIO;
  2550. }
  2551. static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2552. {
  2553. __be32 *p;
  2554. *res = 0;
  2555. if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
  2556. return -EIO;
  2557. if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
  2558. p = xdr_inline_decode(xdr, 4);
  2559. if (unlikely(!p))
  2560. goto out_overflow;
  2561. *res = be32_to_cpup(p);
  2562. bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
  2563. }
  2564. dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
  2565. return 0;
  2566. out_overflow:
  2567. print_overflow_msg(__func__, xdr);
  2568. return -EIO;
  2569. }
  2570. static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2571. {
  2572. __be32 *p;
  2573. *res = 0;
  2574. if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
  2575. return -EIO;
  2576. if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
  2577. p = xdr_inline_decode(xdr, 4);
  2578. if (unlikely(!p))
  2579. goto out_overflow;
  2580. *res = be32_to_cpup(p);
  2581. bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
  2582. }
  2583. dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
  2584. return 0;
  2585. out_overflow:
  2586. print_overflow_msg(__func__, xdr);
  2587. return -EIO;
  2588. }
  2589. static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
  2590. {
  2591. __be32 *p;
  2592. int ret = 0;
  2593. fsid->major = 0;
  2594. fsid->minor = 0;
  2595. if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
  2596. return -EIO;
  2597. if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
  2598. p = xdr_inline_decode(xdr, 16);
  2599. if (unlikely(!p))
  2600. goto out_overflow;
  2601. p = xdr_decode_hyper(p, &fsid->major);
  2602. xdr_decode_hyper(p, &fsid->minor);
  2603. bitmap[0] &= ~FATTR4_WORD0_FSID;
  2604. ret = NFS_ATTR_FATTR_FSID;
  2605. }
  2606. dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
  2607. (unsigned long long)fsid->major,
  2608. (unsigned long long)fsid->minor);
  2609. return ret;
  2610. out_overflow:
  2611. print_overflow_msg(__func__, xdr);
  2612. return -EIO;
  2613. }
  2614. static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2615. {
  2616. __be32 *p;
  2617. *res = 60;
  2618. if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
  2619. return -EIO;
  2620. if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
  2621. p = xdr_inline_decode(xdr, 4);
  2622. if (unlikely(!p))
  2623. goto out_overflow;
  2624. *res = be32_to_cpup(p);
  2625. bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
  2626. }
  2627. dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
  2628. return 0;
  2629. out_overflow:
  2630. print_overflow_msg(__func__, xdr);
  2631. return -EIO;
  2632. }
  2633. static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap)
  2634. {
  2635. __be32 *p;
  2636. if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
  2637. return -EIO;
  2638. if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
  2639. p = xdr_inline_decode(xdr, 4);
  2640. if (unlikely(!p))
  2641. goto out_overflow;
  2642. bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
  2643. }
  2644. return 0;
  2645. out_overflow:
  2646. print_overflow_msg(__func__, xdr);
  2647. return -EIO;
  2648. }
  2649. static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
  2650. {
  2651. __be32 *p;
  2652. int len;
  2653. if (fh != NULL)
  2654. memset(fh, 0, sizeof(*fh));
  2655. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
  2656. return -EIO;
  2657. if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
  2658. p = xdr_inline_decode(xdr, 4);
  2659. if (unlikely(!p))
  2660. goto out_overflow;
  2661. len = be32_to_cpup(p);
  2662. if (len > NFS4_FHSIZE)
  2663. return -EIO;
  2664. p = xdr_inline_decode(xdr, len);
  2665. if (unlikely(!p))
  2666. goto out_overflow;
  2667. if (fh != NULL) {
  2668. memcpy(fh->data, p, len);
  2669. fh->size = len;
  2670. }
  2671. bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
  2672. }
  2673. return 0;
  2674. out_overflow:
  2675. print_overflow_msg(__func__, xdr);
  2676. return -EIO;
  2677. }
  2678. static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2679. {
  2680. __be32 *p;
  2681. *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
  2682. if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
  2683. return -EIO;
  2684. if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
  2685. p = xdr_inline_decode(xdr, 4);
  2686. if (unlikely(!p))
  2687. goto out_overflow;
  2688. *res = be32_to_cpup(p);
  2689. bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
  2690. }
  2691. dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
  2692. return 0;
  2693. out_overflow:
  2694. print_overflow_msg(__func__, xdr);
  2695. return -EIO;
  2696. }
  2697. static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
  2698. {
  2699. __be32 *p;
  2700. int ret = 0;
  2701. *fileid = 0;
  2702. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
  2703. return -EIO;
  2704. if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
  2705. p = xdr_inline_decode(xdr, 8);
  2706. if (unlikely(!p))
  2707. goto out_overflow;
  2708. xdr_decode_hyper(p, fileid);
  2709. bitmap[0] &= ~FATTR4_WORD0_FILEID;
  2710. ret = NFS_ATTR_FATTR_FILEID;
  2711. }
  2712. dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
  2713. return ret;
  2714. out_overflow:
  2715. print_overflow_msg(__func__, xdr);
  2716. return -EIO;
  2717. }
  2718. static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
  2719. {
  2720. __be32 *p;
  2721. int ret = 0;
  2722. *fileid = 0;
  2723. if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
  2724. return -EIO;
  2725. if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
  2726. p = xdr_inline_decode(xdr, 8);
  2727. if (unlikely(!p))
  2728. goto out_overflow;
  2729. xdr_decode_hyper(p, fileid);
  2730. bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
  2731. ret = NFS_ATTR_FATTR_FILEID;
  2732. }
  2733. dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
  2734. return ret;
  2735. out_overflow:
  2736. print_overflow_msg(__func__, xdr);
  2737. return -EIO;
  2738. }
  2739. static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2740. {
  2741. __be32 *p;
  2742. int status = 0;
  2743. *res = 0;
  2744. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
  2745. return -EIO;
  2746. if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
  2747. p = xdr_inline_decode(xdr, 8);
  2748. if (unlikely(!p))
  2749. goto out_overflow;
  2750. xdr_decode_hyper(p, res);
  2751. bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
  2752. }
  2753. dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
  2754. return status;
  2755. out_overflow:
  2756. print_overflow_msg(__func__, xdr);
  2757. return -EIO;
  2758. }
  2759. static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2760. {
  2761. __be32 *p;
  2762. int status = 0;
  2763. *res = 0;
  2764. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
  2765. return -EIO;
  2766. if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
  2767. p = xdr_inline_decode(xdr, 8);
  2768. if (unlikely(!p))
  2769. goto out_overflow;
  2770. xdr_decode_hyper(p, res);
  2771. bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
  2772. }
  2773. dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
  2774. return status;
  2775. out_overflow:
  2776. print_overflow_msg(__func__, xdr);
  2777. return -EIO;
  2778. }
  2779. static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2780. {
  2781. __be32 *p;
  2782. int status = 0;
  2783. *res = 0;
  2784. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
  2785. return -EIO;
  2786. if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
  2787. p = xdr_inline_decode(xdr, 8);
  2788. if (unlikely(!p))
  2789. goto out_overflow;
  2790. xdr_decode_hyper(p, res);
  2791. bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
  2792. }
  2793. dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
  2794. return status;
  2795. out_overflow:
  2796. print_overflow_msg(__func__, xdr);
  2797. return -EIO;
  2798. }
  2799. static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
  2800. {
  2801. u32 n;
  2802. __be32 *p;
  2803. int status = 0;
  2804. p = xdr_inline_decode(xdr, 4);
  2805. if (unlikely(!p))
  2806. goto out_overflow;
  2807. n = be32_to_cpup(p);
  2808. if (n == 0)
  2809. goto root_path;
  2810. dprintk("path ");
  2811. path->ncomponents = 0;
  2812. while (path->ncomponents < n) {
  2813. struct nfs4_string *component = &path->components[path->ncomponents];
  2814. status = decode_opaque_inline(xdr, &component->len, &component->data);
  2815. if (unlikely(status != 0))
  2816. goto out_eio;
  2817. if (path->ncomponents != n)
  2818. dprintk("/");
  2819. dprintk("%s", component->data);
  2820. if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
  2821. path->ncomponents++;
  2822. else {
  2823. dprintk("cannot parse %d components in path\n", n);
  2824. goto out_eio;
  2825. }
  2826. }
  2827. out:
  2828. dprintk("\n");
  2829. return status;
  2830. root_path:
  2831. /* a root pathname is sent as a zero component4 */
  2832. path->ncomponents = 1;
  2833. path->components[0].len=0;
  2834. path->components[0].data=NULL;
  2835. dprintk("path /\n");
  2836. goto out;
  2837. out_eio:
  2838. dprintk(" status %d", status);
  2839. status = -EIO;
  2840. goto out;
  2841. out_overflow:
  2842. print_overflow_msg(__func__, xdr);
  2843. return -EIO;
  2844. }
  2845. static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
  2846. {
  2847. int n;
  2848. __be32 *p;
  2849. int status = -EIO;
  2850. if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
  2851. goto out;
  2852. status = 0;
  2853. if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
  2854. goto out;
  2855. dprintk("%s: fsroot ", __func__);
  2856. status = decode_pathname(xdr, &res->fs_path);
  2857. if (unlikely(status != 0))
  2858. goto out;
  2859. p = xdr_inline_decode(xdr, 4);
  2860. if (unlikely(!p))
  2861. goto out_overflow;
  2862. n = be32_to_cpup(p);
  2863. if (n <= 0)
  2864. goto out_eio;
  2865. res->nlocations = 0;
  2866. while (res->nlocations < n) {
  2867. u32 m;
  2868. struct nfs4_fs_location *loc = &res->locations[res->nlocations];
  2869. p = xdr_inline_decode(xdr, 4);
  2870. if (unlikely(!p))
  2871. goto out_overflow;
  2872. m = be32_to_cpup(p);
  2873. loc->nservers = 0;
  2874. dprintk("%s: servers ", __func__);
  2875. while (loc->nservers < m) {
  2876. struct nfs4_string *server = &loc->servers[loc->nservers];
  2877. status = decode_opaque_inline(xdr, &server->len, &server->data);
  2878. if (unlikely(status != 0))
  2879. goto out_eio;
  2880. dprintk("%s ", server->data);
  2881. if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
  2882. loc->nservers++;
  2883. else {
  2884. unsigned int i;
  2885. dprintk("%s: using first %u of %u servers "
  2886. "returned for location %u\n",
  2887. __func__,
  2888. NFS4_FS_LOCATION_MAXSERVERS,
  2889. m, res->nlocations);
  2890. for (i = loc->nservers; i < m; i++) {
  2891. unsigned int len;
  2892. char *data;
  2893. status = decode_opaque_inline(xdr, &len, &data);
  2894. if (unlikely(status != 0))
  2895. goto out_eio;
  2896. }
  2897. }
  2898. }
  2899. status = decode_pathname(xdr, &loc->rootpath);
  2900. if (unlikely(status != 0))
  2901. goto out_eio;
  2902. if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
  2903. res->nlocations++;
  2904. }
  2905. if (res->nlocations != 0)
  2906. status = NFS_ATTR_FATTR_V4_REFERRAL;
  2907. out:
  2908. dprintk("%s: fs_locations done, error = %d\n", __func__, status);
  2909. return status;
  2910. out_overflow:
  2911. print_overflow_msg(__func__, xdr);
  2912. out_eio:
  2913. status = -EIO;
  2914. goto out;
  2915. }
  2916. static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2917. {
  2918. __be32 *p;
  2919. int status = 0;
  2920. *res = 0;
  2921. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
  2922. return -EIO;
  2923. if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
  2924. p = xdr_inline_decode(xdr, 8);
  2925. if (unlikely(!p))
  2926. goto out_overflow;
  2927. xdr_decode_hyper(p, res);
  2928. bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
  2929. }
  2930. dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
  2931. return status;
  2932. out_overflow:
  2933. print_overflow_msg(__func__, xdr);
  2934. return -EIO;
  2935. }
  2936. static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
  2937. {
  2938. __be32 *p;
  2939. int status = 0;
  2940. *maxlink = 1;
  2941. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
  2942. return -EIO;
  2943. if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
  2944. p = xdr_inline_decode(xdr, 4);
  2945. if (unlikely(!p))
  2946. goto out_overflow;
  2947. *maxlink = be32_to_cpup(p);
  2948. bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
  2949. }
  2950. dprintk("%s: maxlink=%u\n", __func__, *maxlink);
  2951. return status;
  2952. out_overflow:
  2953. print_overflow_msg(__func__, xdr);
  2954. return -EIO;
  2955. }
  2956. static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
  2957. {
  2958. __be32 *p;
  2959. int status = 0;
  2960. *maxname = 1024;
  2961. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
  2962. return -EIO;
  2963. if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
  2964. p = xdr_inline_decode(xdr, 4);
  2965. if (unlikely(!p))
  2966. goto out_overflow;
  2967. *maxname = be32_to_cpup(p);
  2968. bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
  2969. }
  2970. dprintk("%s: maxname=%u\n", __func__, *maxname);
  2971. return status;
  2972. out_overflow:
  2973. print_overflow_msg(__func__, xdr);
  2974. return -EIO;
  2975. }
  2976. static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2977. {
  2978. __be32 *p;
  2979. int status = 0;
  2980. *res = 1024;
  2981. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
  2982. return -EIO;
  2983. if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
  2984. uint64_t maxread;
  2985. p = xdr_inline_decode(xdr, 8);
  2986. if (unlikely(!p))
  2987. goto out_overflow;
  2988. xdr_decode_hyper(p, &maxread);
  2989. if (maxread > 0x7FFFFFFF)
  2990. maxread = 0x7FFFFFFF;
  2991. *res = (uint32_t)maxread;
  2992. bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
  2993. }
  2994. dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
  2995. return status;
  2996. out_overflow:
  2997. print_overflow_msg(__func__, xdr);
  2998. return -EIO;
  2999. }
  3000. static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3001. {
  3002. __be32 *p;
  3003. int status = 0;
  3004. *res = 1024;
  3005. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
  3006. return -EIO;
  3007. if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
  3008. uint64_t maxwrite;
  3009. p = xdr_inline_decode(xdr, 8);
  3010. if (unlikely(!p))
  3011. goto out_overflow;
  3012. xdr_decode_hyper(p, &maxwrite);
  3013. if (maxwrite > 0x7FFFFFFF)
  3014. maxwrite = 0x7FFFFFFF;
  3015. *res = (uint32_t)maxwrite;
  3016. bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
  3017. }
  3018. dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
  3019. return status;
  3020. out_overflow:
  3021. print_overflow_msg(__func__, xdr);
  3022. return -EIO;
  3023. }
  3024. static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
  3025. {
  3026. uint32_t tmp;
  3027. __be32 *p;
  3028. int ret = 0;
  3029. *mode = 0;
  3030. if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
  3031. return -EIO;
  3032. if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
  3033. p = xdr_inline_decode(xdr, 4);
  3034. if (unlikely(!p))
  3035. goto out_overflow;
  3036. tmp = be32_to_cpup(p);
  3037. *mode = tmp & ~S_IFMT;
  3038. bitmap[1] &= ~FATTR4_WORD1_MODE;
  3039. ret = NFS_ATTR_FATTR_MODE;
  3040. }
  3041. dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
  3042. return ret;
  3043. out_overflow:
  3044. print_overflow_msg(__func__, xdr);
  3045. return -EIO;
  3046. }
  3047. static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
  3048. {
  3049. __be32 *p;
  3050. int ret = 0;
  3051. *nlink = 1;
  3052. if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
  3053. return -EIO;
  3054. if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
  3055. p = xdr_inline_decode(xdr, 4);
  3056. if (unlikely(!p))
  3057. goto out_overflow;
  3058. *nlink = be32_to_cpup(p);
  3059. bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
  3060. ret = NFS_ATTR_FATTR_NLINK;
  3061. }
  3062. dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
  3063. return ret;
  3064. out_overflow:
  3065. print_overflow_msg(__func__, xdr);
  3066. return -EIO;
  3067. }
  3068. static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
  3069. struct nfs_client *clp, uint32_t *uid, int may_sleep)
  3070. {
  3071. uint32_t len;
  3072. __be32 *p;
  3073. int ret = 0;
  3074. *uid = -2;
  3075. if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
  3076. return -EIO;
  3077. if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
  3078. p = xdr_inline_decode(xdr, 4);
  3079. if (unlikely(!p))
  3080. goto out_overflow;
  3081. len = be32_to_cpup(p);
  3082. p = xdr_inline_decode(xdr, len);
  3083. if (unlikely(!p))
  3084. goto out_overflow;
  3085. if (!may_sleep) {
  3086. /* do nothing */
  3087. } else if (len < XDR_MAX_NETOBJ) {
  3088. if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
  3089. ret = NFS_ATTR_FATTR_OWNER;
  3090. else
  3091. dprintk("%s: nfs_map_name_to_uid failed!\n",
  3092. __func__);
  3093. } else
  3094. dprintk("%s: name too long (%u)!\n",
  3095. __func__, len);
  3096. bitmap[1] &= ~FATTR4_WORD1_OWNER;
  3097. }
  3098. dprintk("%s: uid=%d\n", __func__, (int)*uid);
  3099. return ret;
  3100. out_overflow:
  3101. print_overflow_msg(__func__, xdr);
  3102. return -EIO;
  3103. }
  3104. static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
  3105. struct nfs_client *clp, uint32_t *gid, int may_sleep)
  3106. {
  3107. uint32_t len;
  3108. __be32 *p;
  3109. int ret = 0;
  3110. *gid = -2;
  3111. if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
  3112. return -EIO;
  3113. if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
  3114. p = xdr_inline_decode(xdr, 4);
  3115. if (unlikely(!p))
  3116. goto out_overflow;
  3117. len = be32_to_cpup(p);
  3118. p = xdr_inline_decode(xdr, len);
  3119. if (unlikely(!p))
  3120. goto out_overflow;
  3121. if (!may_sleep) {
  3122. /* do nothing */
  3123. } else if (len < XDR_MAX_NETOBJ) {
  3124. if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
  3125. ret = NFS_ATTR_FATTR_GROUP;
  3126. else
  3127. dprintk("%s: nfs_map_group_to_gid failed!\n",
  3128. __func__);
  3129. } else
  3130. dprintk("%s: name too long (%u)!\n",
  3131. __func__, len);
  3132. bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
  3133. }
  3134. dprintk("%s: gid=%d\n", __func__, (int)*gid);
  3135. return ret;
  3136. out_overflow:
  3137. print_overflow_msg(__func__, xdr);
  3138. return -EIO;
  3139. }
  3140. static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
  3141. {
  3142. uint32_t major = 0, minor = 0;
  3143. __be32 *p;
  3144. int ret = 0;
  3145. *rdev = MKDEV(0,0);
  3146. if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
  3147. return -EIO;
  3148. if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
  3149. dev_t tmp;
  3150. p = xdr_inline_decode(xdr, 8);
  3151. if (unlikely(!p))
  3152. goto out_overflow;
  3153. major = be32_to_cpup(p++);
  3154. minor = be32_to_cpup(p);
  3155. tmp = MKDEV(major, minor);
  3156. if (MAJOR(tmp) == major && MINOR(tmp) == minor)
  3157. *rdev = tmp;
  3158. bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
  3159. ret = NFS_ATTR_FATTR_RDEV;
  3160. }
  3161. dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
  3162. return ret;
  3163. out_overflow:
  3164. print_overflow_msg(__func__, xdr);
  3165. return -EIO;
  3166. }
  3167. static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3168. {
  3169. __be32 *p;
  3170. int status = 0;
  3171. *res = 0;
  3172. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
  3173. return -EIO;
  3174. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
  3175. p = xdr_inline_decode(xdr, 8);
  3176. if (unlikely(!p))
  3177. goto out_overflow;
  3178. xdr_decode_hyper(p, res);
  3179. bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
  3180. }
  3181. dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
  3182. return status;
  3183. out_overflow:
  3184. print_overflow_msg(__func__, xdr);
  3185. return -EIO;
  3186. }
  3187. static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3188. {
  3189. __be32 *p;
  3190. int status = 0;
  3191. *res = 0;
  3192. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
  3193. return -EIO;
  3194. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
  3195. p = xdr_inline_decode(xdr, 8);
  3196. if (unlikely(!p))
  3197. goto out_overflow;
  3198. xdr_decode_hyper(p, res);
  3199. bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
  3200. }
  3201. dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
  3202. return status;
  3203. out_overflow:
  3204. print_overflow_msg(__func__, xdr);
  3205. return -EIO;
  3206. }
  3207. static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3208. {
  3209. __be32 *p;
  3210. int status = 0;
  3211. *res = 0;
  3212. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
  3213. return -EIO;
  3214. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
  3215. p = xdr_inline_decode(xdr, 8);
  3216. if (unlikely(!p))
  3217. goto out_overflow;
  3218. xdr_decode_hyper(p, res);
  3219. bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
  3220. }
  3221. dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
  3222. return status;
  3223. out_overflow:
  3224. print_overflow_msg(__func__, xdr);
  3225. return -EIO;
  3226. }
  3227. static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
  3228. {
  3229. __be32 *p;
  3230. int ret = 0;
  3231. *used = 0;
  3232. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
  3233. return -EIO;
  3234. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
  3235. p = xdr_inline_decode(xdr, 8);
  3236. if (unlikely(!p))
  3237. goto out_overflow;
  3238. xdr_decode_hyper(p, used);
  3239. bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
  3240. ret = NFS_ATTR_FATTR_SPACE_USED;
  3241. }
  3242. dprintk("%s: space used=%Lu\n", __func__,
  3243. (unsigned long long)*used);
  3244. return ret;
  3245. out_overflow:
  3246. print_overflow_msg(__func__, xdr);
  3247. return -EIO;
  3248. }
  3249. static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
  3250. {
  3251. __be32 *p;
  3252. uint64_t sec;
  3253. uint32_t nsec;
  3254. p = xdr_inline_decode(xdr, 12);
  3255. if (unlikely(!p))
  3256. goto out_overflow;
  3257. p = xdr_decode_hyper(p, &sec);
  3258. nsec = be32_to_cpup(p);
  3259. time->tv_sec = (time_t)sec;
  3260. time->tv_nsec = (long)nsec;
  3261. return 0;
  3262. out_overflow:
  3263. print_overflow_msg(__func__, xdr);
  3264. return -EIO;
  3265. }
  3266. static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
  3267. {
  3268. int status = 0;
  3269. time->tv_sec = 0;
  3270. time->tv_nsec = 0;
  3271. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
  3272. return -EIO;
  3273. if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
  3274. status = decode_attr_time(xdr, time);
  3275. if (status == 0)
  3276. status = NFS_ATTR_FATTR_ATIME;
  3277. bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
  3278. }
  3279. dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
  3280. return status;
  3281. }
  3282. static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
  3283. {
  3284. int status = 0;
  3285. time->tv_sec = 0;
  3286. time->tv_nsec = 0;
  3287. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
  3288. return -EIO;
  3289. if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
  3290. status = decode_attr_time(xdr, time);
  3291. if (status == 0)
  3292. status = NFS_ATTR_FATTR_CTIME;
  3293. bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
  3294. }
  3295. dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
  3296. return status;
  3297. }
  3298. static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
  3299. struct timespec *time)
  3300. {
  3301. int status = 0;
  3302. time->tv_sec = 0;
  3303. time->tv_nsec = 0;
  3304. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
  3305. return -EIO;
  3306. if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
  3307. status = decode_attr_time(xdr, time);
  3308. bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
  3309. }
  3310. dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
  3311. (long)time->tv_nsec);
  3312. return status;
  3313. }
  3314. static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
  3315. {
  3316. int status = 0;
  3317. time->tv_sec = 0;
  3318. time->tv_nsec = 0;
  3319. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
  3320. return -EIO;
  3321. if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
  3322. status = decode_attr_time(xdr, time);
  3323. if (status == 0)
  3324. status = NFS_ATTR_FATTR_MTIME;
  3325. bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
  3326. }
  3327. dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
  3328. return status;
  3329. }
  3330. static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
  3331. {
  3332. unsigned int attrwords = XDR_QUADLEN(attrlen);
  3333. unsigned int nwords = xdr->p - savep;
  3334. if (unlikely(attrwords != nwords)) {
  3335. dprintk("%s: server returned incorrect attribute length: "
  3336. "%u %c %u\n",
  3337. __func__,
  3338. attrwords << 2,
  3339. (attrwords < nwords) ? '<' : '>',
  3340. nwords << 2);
  3341. return -EIO;
  3342. }
  3343. return 0;
  3344. }
  3345. static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  3346. {
  3347. __be32 *p;
  3348. p = xdr_inline_decode(xdr, 20);
  3349. if (unlikely(!p))
  3350. goto out_overflow;
  3351. cinfo->atomic = be32_to_cpup(p++);
  3352. p = xdr_decode_hyper(p, &cinfo->before);
  3353. xdr_decode_hyper(p, &cinfo->after);
  3354. return 0;
  3355. out_overflow:
  3356. print_overflow_msg(__func__, xdr);
  3357. return -EIO;
  3358. }
  3359. static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
  3360. {
  3361. __be32 *p;
  3362. uint32_t supp, acc;
  3363. int status;
  3364. status = decode_op_hdr(xdr, OP_ACCESS);
  3365. if (status)
  3366. return status;
  3367. p = xdr_inline_decode(xdr, 8);
  3368. if (unlikely(!p))
  3369. goto out_overflow;
  3370. supp = be32_to_cpup(p++);
  3371. acc = be32_to_cpup(p);
  3372. access->supported = supp;
  3373. access->access = acc;
  3374. return 0;
  3375. out_overflow:
  3376. print_overflow_msg(__func__, xdr);
  3377. return -EIO;
  3378. }
  3379. static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
  3380. {
  3381. __be32 *p;
  3382. p = xdr_inline_decode(xdr, len);
  3383. if (likely(p)) {
  3384. memcpy(buf, p, len);
  3385. return 0;
  3386. }
  3387. print_overflow_msg(__func__, xdr);
  3388. return -EIO;
  3389. }
  3390. static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  3391. {
  3392. return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
  3393. }
  3394. static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
  3395. {
  3396. int status;
  3397. status = decode_op_hdr(xdr, OP_CLOSE);
  3398. if (status != -EIO)
  3399. nfs_increment_open_seqid(status, res->seqid);
  3400. if (!status)
  3401. status = decode_stateid(xdr, &res->stateid);
  3402. return status;
  3403. }
  3404. static int decode_verifier(struct xdr_stream *xdr, void *verifier)
  3405. {
  3406. return decode_opaque_fixed(xdr, verifier, 8);
  3407. }
  3408. static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
  3409. {
  3410. int status;
  3411. status = decode_op_hdr(xdr, OP_COMMIT);
  3412. if (!status)
  3413. status = decode_verifier(xdr, res->verf->verifier);
  3414. return status;
  3415. }
  3416. static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  3417. {
  3418. __be32 *p;
  3419. uint32_t bmlen;
  3420. int status;
  3421. status = decode_op_hdr(xdr, OP_CREATE);
  3422. if (status)
  3423. return status;
  3424. if ((status = decode_change_info(xdr, cinfo)))
  3425. return status;
  3426. p = xdr_inline_decode(xdr, 4);
  3427. if (unlikely(!p))
  3428. goto out_overflow;
  3429. bmlen = be32_to_cpup(p);
  3430. p = xdr_inline_decode(xdr, bmlen << 2);
  3431. if (likely(p))
  3432. return 0;
  3433. out_overflow:
  3434. print_overflow_msg(__func__, xdr);
  3435. return -EIO;
  3436. }
  3437. static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
  3438. {
  3439. __be32 *savep;
  3440. uint32_t attrlen, bitmap[2] = {0};
  3441. int status;
  3442. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  3443. goto xdr_error;
  3444. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  3445. goto xdr_error;
  3446. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  3447. goto xdr_error;
  3448. if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
  3449. goto xdr_error;
  3450. if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
  3451. goto xdr_error;
  3452. if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
  3453. goto xdr_error;
  3454. if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
  3455. goto xdr_error;
  3456. status = verify_attr_len(xdr, savep, attrlen);
  3457. xdr_error:
  3458. dprintk("%s: xdr returned %d!\n", __func__, -status);
  3459. return status;
  3460. }
  3461. static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
  3462. {
  3463. __be32 *savep;
  3464. uint32_t attrlen, bitmap[2] = {0};
  3465. int status;
  3466. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  3467. goto xdr_error;
  3468. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  3469. goto xdr_error;
  3470. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  3471. goto xdr_error;
  3472. if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
  3473. goto xdr_error;
  3474. if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
  3475. goto xdr_error;
  3476. if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
  3477. goto xdr_error;
  3478. if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
  3479. goto xdr_error;
  3480. if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
  3481. goto xdr_error;
  3482. if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
  3483. goto xdr_error;
  3484. status = verify_attr_len(xdr, savep, attrlen);
  3485. xdr_error:
  3486. dprintk("%s: xdr returned %d!\n", __func__, -status);
  3487. return status;
  3488. }
  3489. static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
  3490. {
  3491. __be32 *savep;
  3492. uint32_t attrlen, bitmap[2] = {0};
  3493. int status;
  3494. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  3495. goto xdr_error;
  3496. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  3497. goto xdr_error;
  3498. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  3499. goto xdr_error;
  3500. if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
  3501. goto xdr_error;
  3502. if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
  3503. goto xdr_error;
  3504. status = verify_attr_len(xdr, savep, attrlen);
  3505. xdr_error:
  3506. dprintk("%s: xdr returned %d!\n", __func__, -status);
  3507. return status;
  3508. }
  3509. static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
  3510. struct nfs_fattr *fattr, struct nfs_fh *fh,
  3511. const struct nfs_server *server, int may_sleep)
  3512. {
  3513. int status;
  3514. umode_t fmode = 0;
  3515. uint64_t fileid;
  3516. uint32_t type;
  3517. status = decode_attr_type(xdr, bitmap, &type);
  3518. if (status < 0)
  3519. goto xdr_error;
  3520. fattr->mode = 0;
  3521. if (status != 0) {
  3522. fattr->mode |= nfs_type2fmt[type];
  3523. fattr->valid |= status;
  3524. }
  3525. status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
  3526. if (status < 0)
  3527. goto xdr_error;
  3528. fattr->valid |= status;
  3529. status = decode_attr_size(xdr, bitmap, &fattr->size);
  3530. if (status < 0)
  3531. goto xdr_error;
  3532. fattr->valid |= status;
  3533. status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
  3534. if (status < 0)
  3535. goto xdr_error;
  3536. fattr->valid |= status;
  3537. status = decode_attr_error(xdr, bitmap);
  3538. if (status < 0)
  3539. goto xdr_error;
  3540. status = decode_attr_filehandle(xdr, bitmap, fh);
  3541. if (status < 0)
  3542. goto xdr_error;
  3543. status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
  3544. if (status < 0)
  3545. goto xdr_error;
  3546. fattr->valid |= status;
  3547. status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
  3548. struct nfs4_fs_locations,
  3549. fattr));
  3550. if (status < 0)
  3551. goto xdr_error;
  3552. fattr->valid |= status;
  3553. status = decode_attr_mode(xdr, bitmap, &fmode);
  3554. if (status < 0)
  3555. goto xdr_error;
  3556. if (status != 0) {
  3557. fattr->mode |= fmode;
  3558. fattr->valid |= status;
  3559. }
  3560. status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
  3561. if (status < 0)
  3562. goto xdr_error;
  3563. fattr->valid |= status;
  3564. status = decode_attr_owner(xdr, bitmap, server->nfs_client,
  3565. &fattr->uid, may_sleep);
  3566. if (status < 0)
  3567. goto xdr_error;
  3568. fattr->valid |= status;
  3569. status = decode_attr_group(xdr, bitmap, server->nfs_client,
  3570. &fattr->gid, may_sleep);
  3571. if (status < 0)
  3572. goto xdr_error;
  3573. fattr->valid |= status;
  3574. status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
  3575. if (status < 0)
  3576. goto xdr_error;
  3577. fattr->valid |= status;
  3578. status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
  3579. if (status < 0)
  3580. goto xdr_error;
  3581. fattr->valid |= status;
  3582. status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
  3583. if (status < 0)
  3584. goto xdr_error;
  3585. fattr->valid |= status;
  3586. status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
  3587. if (status < 0)
  3588. goto xdr_error;
  3589. fattr->valid |= status;
  3590. status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
  3591. if (status < 0)
  3592. goto xdr_error;
  3593. fattr->valid |= status;
  3594. status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
  3595. if (status < 0)
  3596. goto xdr_error;
  3597. if (status != 0 && !(fattr->valid & status)) {
  3598. fattr->fileid = fileid;
  3599. fattr->valid |= status;
  3600. }
  3601. xdr_error:
  3602. dprintk("%s: xdr returned %d\n", __func__, -status);
  3603. return status;
  3604. }
  3605. static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
  3606. struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
  3607. {
  3608. __be32 *savep;
  3609. uint32_t attrlen,
  3610. bitmap[2] = {0};
  3611. int status;
  3612. status = decode_op_hdr(xdr, OP_GETATTR);
  3613. if (status < 0)
  3614. goto xdr_error;
  3615. status = decode_attr_bitmap(xdr, bitmap);
  3616. if (status < 0)
  3617. goto xdr_error;
  3618. status = decode_attr_length(xdr, &attrlen, &savep);
  3619. if (status < 0)
  3620. goto xdr_error;
  3621. status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
  3622. if (status < 0)
  3623. goto xdr_error;
  3624. status = verify_attr_len(xdr, savep, attrlen);
  3625. xdr_error:
  3626. dprintk("%s: xdr returned %d\n", __func__, -status);
  3627. return status;
  3628. }
  3629. static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
  3630. const struct nfs_server *server, int may_sleep)
  3631. {
  3632. return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
  3633. }
  3634. /*
  3635. * Decode potentially multiple layout types. Currently we only support
  3636. * one layout driver per file system.
  3637. */
  3638. static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
  3639. uint32_t *layouttype)
  3640. {
  3641. uint32_t *p;
  3642. int num;
  3643. p = xdr_inline_decode(xdr, 4);
  3644. if (unlikely(!p))
  3645. goto out_overflow;
  3646. num = be32_to_cpup(p);
  3647. /* pNFS is not supported by the underlying file system */
  3648. if (num == 0) {
  3649. *layouttype = 0;
  3650. return 0;
  3651. }
  3652. if (num > 1)
  3653. printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers "
  3654. "per filesystem not supported\n", __func__);
  3655. /* Decode and set first layout type, move xdr->p past unused types */
  3656. p = xdr_inline_decode(xdr, num * 4);
  3657. if (unlikely(!p))
  3658. goto out_overflow;
  3659. *layouttype = be32_to_cpup(p);
  3660. return 0;
  3661. out_overflow:
  3662. print_overflow_msg(__func__, xdr);
  3663. return -EIO;
  3664. }
  3665. /*
  3666. * The type of file system exported.
  3667. * Note we must ensure that layouttype is set in any non-error case.
  3668. */
  3669. static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
  3670. uint32_t *layouttype)
  3671. {
  3672. int status = 0;
  3673. dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
  3674. if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
  3675. return -EIO;
  3676. if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
  3677. status = decode_first_pnfs_layout_type(xdr, layouttype);
  3678. bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
  3679. } else
  3680. *layouttype = 0;
  3681. return status;
  3682. }
  3683. static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
  3684. {
  3685. __be32 *savep;
  3686. uint32_t attrlen, bitmap[2];
  3687. int status;
  3688. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  3689. goto xdr_error;
  3690. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  3691. goto xdr_error;
  3692. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  3693. goto xdr_error;
  3694. fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
  3695. if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
  3696. goto xdr_error;
  3697. if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
  3698. goto xdr_error;
  3699. if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
  3700. goto xdr_error;
  3701. fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
  3702. if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
  3703. goto xdr_error;
  3704. fsinfo->wtpref = fsinfo->wtmax;
  3705. status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
  3706. if (status != 0)
  3707. goto xdr_error;
  3708. status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
  3709. if (status != 0)
  3710. goto xdr_error;
  3711. status = verify_attr_len(xdr, savep, attrlen);
  3712. xdr_error:
  3713. dprintk("%s: xdr returned %d!\n", __func__, -status);
  3714. return status;
  3715. }
  3716. static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
  3717. {
  3718. __be32 *p;
  3719. uint32_t len;
  3720. int status;
  3721. /* Zero handle first to allow comparisons */
  3722. memset(fh, 0, sizeof(*fh));
  3723. status = decode_op_hdr(xdr, OP_GETFH);
  3724. if (status)
  3725. return status;
  3726. p = xdr_inline_decode(xdr, 4);
  3727. if (unlikely(!p))
  3728. goto out_overflow;
  3729. len = be32_to_cpup(p);
  3730. if (len > NFS4_FHSIZE)
  3731. return -EIO;
  3732. fh->size = len;
  3733. p = xdr_inline_decode(xdr, len);
  3734. if (unlikely(!p))
  3735. goto out_overflow;
  3736. memcpy(fh->data, p, len);
  3737. return 0;
  3738. out_overflow:
  3739. print_overflow_msg(__func__, xdr);
  3740. return -EIO;
  3741. }
  3742. static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  3743. {
  3744. int status;
  3745. status = decode_op_hdr(xdr, OP_LINK);
  3746. if (status)
  3747. return status;
  3748. return decode_change_info(xdr, cinfo);
  3749. }
  3750. /*
  3751. * We create the owner, so we know a proper owner.id length is 4.
  3752. */
  3753. static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
  3754. {
  3755. uint64_t offset, length, clientid;
  3756. __be32 *p;
  3757. uint32_t namelen, type;
  3758. p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
  3759. if (unlikely(!p))
  3760. goto out_overflow;
  3761. p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
  3762. p = xdr_decode_hyper(p, &length);
  3763. type = be32_to_cpup(p++); /* 4 byte read */
  3764. if (fl != NULL) { /* manipulate file lock */
  3765. fl->fl_start = (loff_t)offset;
  3766. fl->fl_end = fl->fl_start + (loff_t)length - 1;
  3767. if (length == ~(uint64_t)0)
  3768. fl->fl_end = OFFSET_MAX;
  3769. fl->fl_type = F_WRLCK;
  3770. if (type & 1)
  3771. fl->fl_type = F_RDLCK;
  3772. fl->fl_pid = 0;
  3773. }
  3774. p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
  3775. namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
  3776. p = xdr_inline_decode(xdr, namelen); /* variable size field */
  3777. if (likely(p))
  3778. return -NFS4ERR_DENIED;
  3779. out_overflow:
  3780. print_overflow_msg(__func__, xdr);
  3781. return -EIO;
  3782. }
  3783. static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
  3784. {
  3785. int status;
  3786. status = decode_op_hdr(xdr, OP_LOCK);
  3787. if (status == -EIO)
  3788. goto out;
  3789. if (status == 0) {
  3790. status = decode_stateid(xdr, &res->stateid);
  3791. if (unlikely(status))
  3792. goto out;
  3793. } else if (status == -NFS4ERR_DENIED)
  3794. status = decode_lock_denied(xdr, NULL);
  3795. if (res->open_seqid != NULL)
  3796. nfs_increment_open_seqid(status, res->open_seqid);
  3797. nfs_increment_lock_seqid(status, res->lock_seqid);
  3798. out:
  3799. return status;
  3800. }
  3801. static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
  3802. {
  3803. int status;
  3804. status = decode_op_hdr(xdr, OP_LOCKT);
  3805. if (status == -NFS4ERR_DENIED)
  3806. return decode_lock_denied(xdr, res->denied);
  3807. return status;
  3808. }
  3809. static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
  3810. {
  3811. int status;
  3812. status = decode_op_hdr(xdr, OP_LOCKU);
  3813. if (status != -EIO)
  3814. nfs_increment_lock_seqid(status, res->seqid);
  3815. if (status == 0)
  3816. status = decode_stateid(xdr, &res->stateid);
  3817. return status;
  3818. }
  3819. static int decode_release_lockowner(struct xdr_stream *xdr)
  3820. {
  3821. return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
  3822. }
  3823. static int decode_lookup(struct xdr_stream *xdr)
  3824. {
  3825. return decode_op_hdr(xdr, OP_LOOKUP);
  3826. }
  3827. /* This is too sick! */
  3828. static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
  3829. {
  3830. __be32 *p;
  3831. uint32_t limit_type, nblocks, blocksize;
  3832. p = xdr_inline_decode(xdr, 12);
  3833. if (unlikely(!p))
  3834. goto out_overflow;
  3835. limit_type = be32_to_cpup(p++);
  3836. switch (limit_type) {
  3837. case 1:
  3838. xdr_decode_hyper(p, maxsize);
  3839. break;
  3840. case 2:
  3841. nblocks = be32_to_cpup(p++);
  3842. blocksize = be32_to_cpup(p);
  3843. *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
  3844. }
  3845. return 0;
  3846. out_overflow:
  3847. print_overflow_msg(__func__, xdr);
  3848. return -EIO;
  3849. }
  3850. static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
  3851. {
  3852. __be32 *p;
  3853. uint32_t delegation_type;
  3854. int status;
  3855. p = xdr_inline_decode(xdr, 4);
  3856. if (unlikely(!p))
  3857. goto out_overflow;
  3858. delegation_type = be32_to_cpup(p);
  3859. if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
  3860. res->delegation_type = 0;
  3861. return 0;
  3862. }
  3863. status = decode_stateid(xdr, &res->delegation);
  3864. if (unlikely(status))
  3865. return status;
  3866. p = xdr_inline_decode(xdr, 4);
  3867. if (unlikely(!p))
  3868. goto out_overflow;
  3869. res->do_recall = be32_to_cpup(p);
  3870. switch (delegation_type) {
  3871. case NFS4_OPEN_DELEGATE_READ:
  3872. res->delegation_type = FMODE_READ;
  3873. break;
  3874. case NFS4_OPEN_DELEGATE_WRITE:
  3875. res->delegation_type = FMODE_WRITE|FMODE_READ;
  3876. if (decode_space_limit(xdr, &res->maxsize) < 0)
  3877. return -EIO;
  3878. }
  3879. return decode_ace(xdr, NULL, res->server->nfs_client);
  3880. out_overflow:
  3881. print_overflow_msg(__func__, xdr);
  3882. return -EIO;
  3883. }
  3884. static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
  3885. {
  3886. __be32 *p;
  3887. uint32_t savewords, bmlen, i;
  3888. int status;
  3889. status = decode_op_hdr(xdr, OP_OPEN);
  3890. if (status != -EIO)
  3891. nfs_increment_open_seqid(status, res->seqid);
  3892. if (!status)
  3893. status = decode_stateid(xdr, &res->stateid);
  3894. if (unlikely(status))
  3895. return status;
  3896. decode_change_info(xdr, &res->cinfo);
  3897. p = xdr_inline_decode(xdr, 8);
  3898. if (unlikely(!p))
  3899. goto out_overflow;
  3900. res->rflags = be32_to_cpup(p++);
  3901. bmlen = be32_to_cpup(p);
  3902. if (bmlen > 10)
  3903. goto xdr_error;
  3904. p = xdr_inline_decode(xdr, bmlen << 2);
  3905. if (unlikely(!p))
  3906. goto out_overflow;
  3907. savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
  3908. for (i = 0; i < savewords; ++i)
  3909. res->attrset[i] = be32_to_cpup(p++);
  3910. for (; i < NFS4_BITMAP_SIZE; i++)
  3911. res->attrset[i] = 0;
  3912. return decode_delegation(xdr, res);
  3913. xdr_error:
  3914. dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
  3915. return -EIO;
  3916. out_overflow:
  3917. print_overflow_msg(__func__, xdr);
  3918. return -EIO;
  3919. }
  3920. static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
  3921. {
  3922. int status;
  3923. status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
  3924. if (status != -EIO)
  3925. nfs_increment_open_seqid(status, res->seqid);
  3926. if (!status)
  3927. status = decode_stateid(xdr, &res->stateid);
  3928. return status;
  3929. }
  3930. static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
  3931. {
  3932. int status;
  3933. status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
  3934. if (status != -EIO)
  3935. nfs_increment_open_seqid(status, res->seqid);
  3936. if (!status)
  3937. status = decode_stateid(xdr, &res->stateid);
  3938. return status;
  3939. }
  3940. static int decode_putfh(struct xdr_stream *xdr)
  3941. {
  3942. return decode_op_hdr(xdr, OP_PUTFH);
  3943. }
  3944. static int decode_putrootfh(struct xdr_stream *xdr)
  3945. {
  3946. return decode_op_hdr(xdr, OP_PUTROOTFH);
  3947. }
  3948. static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
  3949. {
  3950. struct kvec *iov = req->rq_rcv_buf.head;
  3951. __be32 *p;
  3952. uint32_t count, eof, recvd, hdrlen;
  3953. int status;
  3954. status = decode_op_hdr(xdr, OP_READ);
  3955. if (status)
  3956. return status;
  3957. p = xdr_inline_decode(xdr, 8);
  3958. if (unlikely(!p))
  3959. goto out_overflow;
  3960. eof = be32_to_cpup(p++);
  3961. count = be32_to_cpup(p);
  3962. hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
  3963. recvd = req->rq_rcv_buf.len - hdrlen;
  3964. if (count > recvd) {
  3965. dprintk("NFS: server cheating in read reply: "
  3966. "count %u > recvd %u\n", count, recvd);
  3967. count = recvd;
  3968. eof = 0;
  3969. }
  3970. xdr_read_pages(xdr, count);
  3971. res->eof = eof;
  3972. res->count = count;
  3973. return 0;
  3974. out_overflow:
  3975. print_overflow_msg(__func__, xdr);
  3976. return -EIO;
  3977. }
  3978. static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
  3979. {
  3980. struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
  3981. struct kvec *iov = rcvbuf->head;
  3982. size_t hdrlen;
  3983. u32 recvd, pglen = rcvbuf->page_len;
  3984. int status;
  3985. status = decode_op_hdr(xdr, OP_READDIR);
  3986. if (!status)
  3987. status = decode_verifier(xdr, readdir->verifier.data);
  3988. if (unlikely(status))
  3989. return status;
  3990. dprintk("%s: verifier = %08x:%08x\n",
  3991. __func__,
  3992. ((u32 *)readdir->verifier.data)[0],
  3993. ((u32 *)readdir->verifier.data)[1]);
  3994. hdrlen = (char *) xdr->p - (char *) iov->iov_base;
  3995. recvd = rcvbuf->len - hdrlen;
  3996. if (pglen > recvd)
  3997. pglen = recvd;
  3998. xdr_read_pages(xdr, pglen);
  3999. return pglen;
  4000. }
  4001. static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
  4002. {
  4003. struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
  4004. struct kvec *iov = rcvbuf->head;
  4005. size_t hdrlen;
  4006. u32 len, recvd;
  4007. __be32 *p;
  4008. int status;
  4009. status = decode_op_hdr(xdr, OP_READLINK);
  4010. if (status)
  4011. return status;
  4012. /* Convert length of symlink */
  4013. p = xdr_inline_decode(xdr, 4);
  4014. if (unlikely(!p))
  4015. goto out_overflow;
  4016. len = be32_to_cpup(p);
  4017. if (len >= rcvbuf->page_len || len <= 0) {
  4018. dprintk("nfs: server returned giant symlink!\n");
  4019. return -ENAMETOOLONG;
  4020. }
  4021. hdrlen = (char *) xdr->p - (char *) iov->iov_base;
  4022. recvd = req->rq_rcv_buf.len - hdrlen;
  4023. if (recvd < len) {
  4024. dprintk("NFS: server cheating in readlink reply: "
  4025. "count %u > recvd %u\n", len, recvd);
  4026. return -EIO;
  4027. }
  4028. xdr_read_pages(xdr, len);
  4029. /*
  4030. * The XDR encode routine has set things up so that
  4031. * the link text will be copied directly into the
  4032. * buffer. We just have to do overflow-checking,
  4033. * and and null-terminate the text (the VFS expects
  4034. * null-termination).
  4035. */
  4036. xdr_terminate_string(rcvbuf, len);
  4037. return 0;
  4038. out_overflow:
  4039. print_overflow_msg(__func__, xdr);
  4040. return -EIO;
  4041. }
  4042. static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  4043. {
  4044. int status;
  4045. status = decode_op_hdr(xdr, OP_REMOVE);
  4046. if (status)
  4047. goto out;
  4048. status = decode_change_info(xdr, cinfo);
  4049. out:
  4050. return status;
  4051. }
  4052. static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
  4053. struct nfs4_change_info *new_cinfo)
  4054. {
  4055. int status;
  4056. status = decode_op_hdr(xdr, OP_RENAME);
  4057. if (status)
  4058. goto out;
  4059. if ((status = decode_change_info(xdr, old_cinfo)))
  4060. goto out;
  4061. status = decode_change_info(xdr, new_cinfo);
  4062. out:
  4063. return status;
  4064. }
  4065. static int decode_renew(struct xdr_stream *xdr)
  4066. {
  4067. return decode_op_hdr(xdr, OP_RENEW);
  4068. }
  4069. static int
  4070. decode_restorefh(struct xdr_stream *xdr)
  4071. {
  4072. return decode_op_hdr(xdr, OP_RESTOREFH);
  4073. }
  4074. static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
  4075. size_t *acl_len)
  4076. {
  4077. __be32 *savep;
  4078. uint32_t attrlen,
  4079. bitmap[2] = {0};
  4080. struct kvec *iov = req->rq_rcv_buf.head;
  4081. int status;
  4082. *acl_len = 0;
  4083. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  4084. goto out;
  4085. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  4086. goto out;
  4087. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  4088. goto out;
  4089. if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
  4090. return -EIO;
  4091. if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
  4092. size_t hdrlen;
  4093. u32 recvd;
  4094. /* We ignore &savep and don't do consistency checks on
  4095. * the attr length. Let userspace figure it out.... */
  4096. hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
  4097. recvd = req->rq_rcv_buf.len - hdrlen;
  4098. if (attrlen > recvd) {
  4099. dprintk("NFS: server cheating in getattr"
  4100. " acl reply: attrlen %u > recvd %u\n",
  4101. attrlen, recvd);
  4102. return -EINVAL;
  4103. }
  4104. xdr_read_pages(xdr, attrlen);
  4105. *acl_len = attrlen;
  4106. } else
  4107. status = -EOPNOTSUPP;
  4108. out:
  4109. return status;
  4110. }
  4111. static int
  4112. decode_savefh(struct xdr_stream *xdr)
  4113. {
  4114. return decode_op_hdr(xdr, OP_SAVEFH);
  4115. }
  4116. static int decode_setattr(struct xdr_stream *xdr)
  4117. {
  4118. __be32 *p;
  4119. uint32_t bmlen;
  4120. int status;
  4121. status = decode_op_hdr(xdr, OP_SETATTR);
  4122. if (status)
  4123. return status;
  4124. p = xdr_inline_decode(xdr, 4);
  4125. if (unlikely(!p))
  4126. goto out_overflow;
  4127. bmlen = be32_to_cpup(p);
  4128. p = xdr_inline_decode(xdr, bmlen << 2);
  4129. if (likely(p))
  4130. return 0;
  4131. out_overflow:
  4132. print_overflow_msg(__func__, xdr);
  4133. return -EIO;
  4134. }
  4135. static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
  4136. {
  4137. __be32 *p;
  4138. uint32_t opnum;
  4139. int32_t nfserr;
  4140. p = xdr_inline_decode(xdr, 8);
  4141. if (unlikely(!p))
  4142. goto out_overflow;
  4143. opnum = be32_to_cpup(p++);
  4144. if (opnum != OP_SETCLIENTID) {
  4145. dprintk("nfs: decode_setclientid: Server returned operation"
  4146. " %d\n", opnum);
  4147. return -EIO;
  4148. }
  4149. nfserr = be32_to_cpup(p);
  4150. if (nfserr == NFS_OK) {
  4151. p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
  4152. if (unlikely(!p))
  4153. goto out_overflow;
  4154. p = xdr_decode_hyper(p, &res->clientid);
  4155. memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
  4156. } else if (nfserr == NFSERR_CLID_INUSE) {
  4157. uint32_t len;
  4158. /* skip netid string */
  4159. p = xdr_inline_decode(xdr, 4);
  4160. if (unlikely(!p))
  4161. goto out_overflow;
  4162. len = be32_to_cpup(p);
  4163. p = xdr_inline_decode(xdr, len);
  4164. if (unlikely(!p))
  4165. goto out_overflow;
  4166. /* skip uaddr string */
  4167. p = xdr_inline_decode(xdr, 4);
  4168. if (unlikely(!p))
  4169. goto out_overflow;
  4170. len = be32_to_cpup(p);
  4171. p = xdr_inline_decode(xdr, len);
  4172. if (unlikely(!p))
  4173. goto out_overflow;
  4174. return -NFSERR_CLID_INUSE;
  4175. } else
  4176. return nfs4_stat_to_errno(nfserr);
  4177. return 0;
  4178. out_overflow:
  4179. print_overflow_msg(__func__, xdr);
  4180. return -EIO;
  4181. }
  4182. static int decode_setclientid_confirm(struct xdr_stream *xdr)
  4183. {
  4184. return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
  4185. }
  4186. static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
  4187. {
  4188. __be32 *p;
  4189. int status;
  4190. status = decode_op_hdr(xdr, OP_WRITE);
  4191. if (status)
  4192. return status;
  4193. p = xdr_inline_decode(xdr, 16);
  4194. if (unlikely(!p))
  4195. goto out_overflow;
  4196. res->count = be32_to_cpup(p++);
  4197. res->verf->committed = be32_to_cpup(p++);
  4198. memcpy(res->verf->verifier, p, 8);
  4199. return 0;
  4200. out_overflow:
  4201. print_overflow_msg(__func__, xdr);
  4202. return -EIO;
  4203. }
  4204. static int decode_delegreturn(struct xdr_stream *xdr)
  4205. {
  4206. return decode_op_hdr(xdr, OP_DELEGRETURN);
  4207. }
  4208. #if defined(CONFIG_NFS_V4_1)
  4209. static int decode_exchange_id(struct xdr_stream *xdr,
  4210. struct nfs41_exchange_id_res *res)
  4211. {
  4212. __be32 *p;
  4213. uint32_t dummy;
  4214. char *dummy_str;
  4215. int status;
  4216. struct nfs_client *clp = res->client;
  4217. status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
  4218. if (status)
  4219. return status;
  4220. p = xdr_inline_decode(xdr, 8);
  4221. if (unlikely(!p))
  4222. goto out_overflow;
  4223. xdr_decode_hyper(p, &clp->cl_ex_clid);
  4224. p = xdr_inline_decode(xdr, 12);
  4225. if (unlikely(!p))
  4226. goto out_overflow;
  4227. clp->cl_seqid = be32_to_cpup(p++);
  4228. clp->cl_exchange_flags = be32_to_cpup(p++);
  4229. /* We ask for SP4_NONE */
  4230. dummy = be32_to_cpup(p);
  4231. if (dummy != SP4_NONE)
  4232. return -EIO;
  4233. /* Throw away minor_id */
  4234. p = xdr_inline_decode(xdr, 8);
  4235. if (unlikely(!p))
  4236. goto out_overflow;
  4237. /* Throw away Major id */
  4238. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  4239. if (unlikely(status))
  4240. return status;
  4241. /* Throw away server_scope */
  4242. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  4243. if (unlikely(status))
  4244. return status;
  4245. /* Throw away Implementation id array */
  4246. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  4247. if (unlikely(status))
  4248. return status;
  4249. return 0;
  4250. out_overflow:
  4251. print_overflow_msg(__func__, xdr);
  4252. return -EIO;
  4253. }
  4254. static int decode_chan_attrs(struct xdr_stream *xdr,
  4255. struct nfs4_channel_attrs *attrs)
  4256. {
  4257. __be32 *p;
  4258. u32 nr_attrs;
  4259. p = xdr_inline_decode(xdr, 28);
  4260. if (unlikely(!p))
  4261. goto out_overflow;
  4262. attrs->headerpadsz = be32_to_cpup(p++);
  4263. attrs->max_rqst_sz = be32_to_cpup(p++);
  4264. attrs->max_resp_sz = be32_to_cpup(p++);
  4265. attrs->max_resp_sz_cached = be32_to_cpup(p++);
  4266. attrs->max_ops = be32_to_cpup(p++);
  4267. attrs->max_reqs = be32_to_cpup(p++);
  4268. nr_attrs = be32_to_cpup(p);
  4269. if (unlikely(nr_attrs > 1)) {
  4270. printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
  4271. __func__, nr_attrs);
  4272. return -EINVAL;
  4273. }
  4274. if (nr_attrs == 1) {
  4275. p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
  4276. if (unlikely(!p))
  4277. goto out_overflow;
  4278. }
  4279. return 0;
  4280. out_overflow:
  4281. print_overflow_msg(__func__, xdr);
  4282. return -EIO;
  4283. }
  4284. static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
  4285. {
  4286. return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
  4287. }
  4288. static int decode_create_session(struct xdr_stream *xdr,
  4289. struct nfs41_create_session_res *res)
  4290. {
  4291. __be32 *p;
  4292. int status;
  4293. struct nfs_client *clp = res->client;
  4294. struct nfs4_session *session = clp->cl_session;
  4295. status = decode_op_hdr(xdr, OP_CREATE_SESSION);
  4296. if (!status)
  4297. status = decode_sessionid(xdr, &session->sess_id);
  4298. if (unlikely(status))
  4299. return status;
  4300. /* seqid, flags */
  4301. p = xdr_inline_decode(xdr, 8);
  4302. if (unlikely(!p))
  4303. goto out_overflow;
  4304. clp->cl_seqid = be32_to_cpup(p++);
  4305. session->flags = be32_to_cpup(p);
  4306. /* Channel attributes */
  4307. status = decode_chan_attrs(xdr, &session->fc_attrs);
  4308. if (!status)
  4309. status = decode_chan_attrs(xdr, &session->bc_attrs);
  4310. return status;
  4311. out_overflow:
  4312. print_overflow_msg(__func__, xdr);
  4313. return -EIO;
  4314. }
  4315. static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
  4316. {
  4317. return decode_op_hdr(xdr, OP_DESTROY_SESSION);
  4318. }
  4319. static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
  4320. {
  4321. return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
  4322. }
  4323. #endif /* CONFIG_NFS_V4_1 */
  4324. static int decode_sequence(struct xdr_stream *xdr,
  4325. struct nfs4_sequence_res *res,
  4326. struct rpc_rqst *rqstp)
  4327. {
  4328. #if defined(CONFIG_NFS_V4_1)
  4329. struct nfs4_sessionid id;
  4330. u32 dummy;
  4331. int status;
  4332. __be32 *p;
  4333. if (!res->sr_session)
  4334. return 0;
  4335. status = decode_op_hdr(xdr, OP_SEQUENCE);
  4336. if (!status)
  4337. status = decode_sessionid(xdr, &id);
  4338. if (unlikely(status))
  4339. goto out_err;
  4340. /*
  4341. * If the server returns different values for sessionID, slotID or
  4342. * sequence number, the server is looney tunes.
  4343. */
  4344. status = -EREMOTEIO;
  4345. if (memcmp(id.data, res->sr_session->sess_id.data,
  4346. NFS4_MAX_SESSIONID_LEN)) {
  4347. dprintk("%s Invalid session id\n", __func__);
  4348. goto out_err;
  4349. }
  4350. p = xdr_inline_decode(xdr, 20);
  4351. if (unlikely(!p))
  4352. goto out_overflow;
  4353. /* seqid */
  4354. dummy = be32_to_cpup(p++);
  4355. if (dummy != res->sr_slot->seq_nr) {
  4356. dprintk("%s Invalid sequence number\n", __func__);
  4357. goto out_err;
  4358. }
  4359. /* slot id */
  4360. dummy = be32_to_cpup(p++);
  4361. if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
  4362. dprintk("%s Invalid slot id\n", __func__);
  4363. goto out_err;
  4364. }
  4365. /* highest slot id - currently not processed */
  4366. dummy = be32_to_cpup(p++);
  4367. /* target highest slot id - currently not processed */
  4368. dummy = be32_to_cpup(p++);
  4369. /* result flags */
  4370. res->sr_status_flags = be32_to_cpup(p);
  4371. status = 0;
  4372. out_err:
  4373. res->sr_status = status;
  4374. return status;
  4375. out_overflow:
  4376. print_overflow_msg(__func__, xdr);
  4377. status = -EIO;
  4378. goto out_err;
  4379. #else /* CONFIG_NFS_V4_1 */
  4380. return 0;
  4381. #endif /* CONFIG_NFS_V4_1 */
  4382. }
  4383. #if defined(CONFIG_NFS_V4_1)
  4384. static int decode_getdeviceinfo(struct xdr_stream *xdr,
  4385. struct pnfs_device *pdev)
  4386. {
  4387. __be32 *p;
  4388. uint32_t len, type;
  4389. int status;
  4390. status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
  4391. if (status) {
  4392. if (status == -ETOOSMALL) {
  4393. p = xdr_inline_decode(xdr, 4);
  4394. if (unlikely(!p))
  4395. goto out_overflow;
  4396. pdev->mincount = be32_to_cpup(p);
  4397. dprintk("%s: Min count too small. mincnt = %u\n",
  4398. __func__, pdev->mincount);
  4399. }
  4400. return status;
  4401. }
  4402. p = xdr_inline_decode(xdr, 8);
  4403. if (unlikely(!p))
  4404. goto out_overflow;
  4405. type = be32_to_cpup(p++);
  4406. if (type != pdev->layout_type) {
  4407. dprintk("%s: layout mismatch req: %u pdev: %u\n",
  4408. __func__, pdev->layout_type, type);
  4409. return -EINVAL;
  4410. }
  4411. /*
  4412. * Get the length of the opaque device_addr4. xdr_read_pages places
  4413. * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
  4414. * and places the remaining xdr data in xdr_buf->tail
  4415. */
  4416. pdev->mincount = be32_to_cpup(p);
  4417. xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
  4418. /* Parse notification bitmap, verifying that it is zero. */
  4419. p = xdr_inline_decode(xdr, 4);
  4420. if (unlikely(!p))
  4421. goto out_overflow;
  4422. len = be32_to_cpup(p);
  4423. if (len) {
  4424. uint32_t i;
  4425. p = xdr_inline_decode(xdr, 4 * len);
  4426. if (unlikely(!p))
  4427. goto out_overflow;
  4428. for (i = 0; i < len; i++, p++) {
  4429. if (be32_to_cpup(p)) {
  4430. dprintk("%s: notifications not supported\n",
  4431. __func__);
  4432. return -EIO;
  4433. }
  4434. }
  4435. }
  4436. return 0;
  4437. out_overflow:
  4438. print_overflow_msg(__func__, xdr);
  4439. return -EIO;
  4440. }
  4441. static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
  4442. struct nfs4_layoutget_res *res)
  4443. {
  4444. __be32 *p;
  4445. int status;
  4446. u32 layout_count;
  4447. status = decode_op_hdr(xdr, OP_LAYOUTGET);
  4448. if (status)
  4449. return status;
  4450. p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
  4451. if (unlikely(!p))
  4452. goto out_overflow;
  4453. res->return_on_close = be32_to_cpup(p++);
  4454. p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
  4455. layout_count = be32_to_cpup(p);
  4456. if (!layout_count) {
  4457. dprintk("%s: server responded with empty layout array\n",
  4458. __func__);
  4459. return -EINVAL;
  4460. }
  4461. p = xdr_inline_decode(xdr, 24);
  4462. if (unlikely(!p))
  4463. goto out_overflow;
  4464. p = xdr_decode_hyper(p, &res->range.offset);
  4465. p = xdr_decode_hyper(p, &res->range.length);
  4466. res->range.iomode = be32_to_cpup(p++);
  4467. res->type = be32_to_cpup(p++);
  4468. status = decode_opaque_inline(xdr, &res->layout.len, (char **)&p);
  4469. if (unlikely(status))
  4470. return status;
  4471. dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
  4472. __func__,
  4473. (unsigned long)res->range.offset,
  4474. (unsigned long)res->range.length,
  4475. res->range.iomode,
  4476. res->type,
  4477. res->layout.len);
  4478. /* nfs4_proc_layoutget allocated a single page */
  4479. if (res->layout.len > PAGE_SIZE)
  4480. return -ENOMEM;
  4481. memcpy(res->layout.buf, p, res->layout.len);
  4482. if (layout_count > 1) {
  4483. /* We only handle a length one array at the moment. Any
  4484. * further entries are just ignored. Note that this means
  4485. * the client may see a response that is less than the
  4486. * minimum it requested.
  4487. */
  4488. dprintk("%s: server responded with %d layouts, dropping tail\n",
  4489. __func__, layout_count);
  4490. }
  4491. return 0;
  4492. out_overflow:
  4493. print_overflow_msg(__func__, xdr);
  4494. return -EIO;
  4495. }
  4496. #endif /* CONFIG_NFS_V4_1 */
  4497. /*
  4498. * END OF "GENERIC" DECODE ROUTINES.
  4499. */
  4500. /*
  4501. * Decode OPEN_DOWNGRADE response
  4502. */
  4503. static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
  4504. struct xdr_stream *xdr,
  4505. struct nfs_closeres *res)
  4506. {
  4507. struct compound_hdr hdr;
  4508. int status;
  4509. status = decode_compound_hdr(xdr, &hdr);
  4510. if (status)
  4511. goto out;
  4512. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4513. if (status)
  4514. goto out;
  4515. status = decode_putfh(xdr);
  4516. if (status)
  4517. goto out;
  4518. status = decode_open_downgrade(xdr, res);
  4519. if (status != 0)
  4520. goto out;
  4521. decode_getfattr(xdr, res->fattr, res->server,
  4522. !RPC_IS_ASYNC(rqstp->rq_task));
  4523. out:
  4524. return status;
  4525. }
  4526. /*
  4527. * Decode ACCESS response
  4528. */
  4529. static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4530. struct nfs4_accessres *res)
  4531. {
  4532. struct compound_hdr hdr;
  4533. int status;
  4534. status = decode_compound_hdr(xdr, &hdr);
  4535. if (status)
  4536. goto out;
  4537. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4538. if (status)
  4539. goto out;
  4540. status = decode_putfh(xdr);
  4541. if (status != 0)
  4542. goto out;
  4543. status = decode_access(xdr, res);
  4544. if (status != 0)
  4545. goto out;
  4546. decode_getfattr(xdr, res->fattr, res->server,
  4547. !RPC_IS_ASYNC(rqstp->rq_task));
  4548. out:
  4549. return status;
  4550. }
  4551. /*
  4552. * Decode LOOKUP response
  4553. */
  4554. static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4555. struct nfs4_lookup_res *res)
  4556. {
  4557. struct compound_hdr hdr;
  4558. int status;
  4559. status = decode_compound_hdr(xdr, &hdr);
  4560. if (status)
  4561. goto out;
  4562. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4563. if (status)
  4564. goto out;
  4565. status = decode_putfh(xdr);
  4566. if (status)
  4567. goto out;
  4568. status = decode_lookup(xdr);
  4569. if (status)
  4570. goto out;
  4571. status = decode_getfh(xdr, res->fh);
  4572. if (status)
  4573. goto out;
  4574. status = decode_getfattr(xdr, res->fattr, res->server
  4575. ,!RPC_IS_ASYNC(rqstp->rq_task));
  4576. out:
  4577. return status;
  4578. }
  4579. /*
  4580. * Decode LOOKUP_ROOT response
  4581. */
  4582. static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
  4583. struct xdr_stream *xdr,
  4584. struct nfs4_lookup_res *res)
  4585. {
  4586. struct compound_hdr hdr;
  4587. int status;
  4588. status = decode_compound_hdr(xdr, &hdr);
  4589. if (status)
  4590. goto out;
  4591. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4592. if (status)
  4593. goto out;
  4594. status = decode_putrootfh(xdr);
  4595. if (status)
  4596. goto out;
  4597. status = decode_getfh(xdr, res->fh);
  4598. if (status == 0)
  4599. status = decode_getfattr(xdr, res->fattr, res->server,
  4600. !RPC_IS_ASYNC(rqstp->rq_task));
  4601. out:
  4602. return status;
  4603. }
  4604. /*
  4605. * Decode REMOVE response
  4606. */
  4607. static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4608. struct nfs_removeres *res)
  4609. {
  4610. struct compound_hdr hdr;
  4611. int status;
  4612. status = decode_compound_hdr(xdr, &hdr);
  4613. if (status)
  4614. goto out;
  4615. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4616. if (status)
  4617. goto out;
  4618. status = decode_putfh(xdr);
  4619. if (status)
  4620. goto out;
  4621. status = decode_remove(xdr, &res->cinfo);
  4622. if (status)
  4623. goto out;
  4624. decode_getfattr(xdr, res->dir_attr, res->server,
  4625. !RPC_IS_ASYNC(rqstp->rq_task));
  4626. out:
  4627. return status;
  4628. }
  4629. /*
  4630. * Decode RENAME response
  4631. */
  4632. static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4633. struct nfs_renameres *res)
  4634. {
  4635. struct compound_hdr hdr;
  4636. int status;
  4637. status = decode_compound_hdr(xdr, &hdr);
  4638. if (status)
  4639. goto out;
  4640. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4641. if (status)
  4642. goto out;
  4643. status = decode_putfh(xdr);
  4644. if (status)
  4645. goto out;
  4646. status = decode_savefh(xdr);
  4647. if (status)
  4648. goto out;
  4649. status = decode_putfh(xdr);
  4650. if (status)
  4651. goto out;
  4652. status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
  4653. if (status)
  4654. goto out;
  4655. /* Current FH is target directory */
  4656. if (decode_getfattr(xdr, res->new_fattr, res->server,
  4657. !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
  4658. goto out;
  4659. status = decode_restorefh(xdr);
  4660. if (status)
  4661. goto out;
  4662. decode_getfattr(xdr, res->old_fattr, res->server,
  4663. !RPC_IS_ASYNC(rqstp->rq_task));
  4664. out:
  4665. return status;
  4666. }
  4667. /*
  4668. * Decode LINK response
  4669. */
  4670. static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4671. struct nfs4_link_res *res)
  4672. {
  4673. struct compound_hdr hdr;
  4674. int status;
  4675. status = decode_compound_hdr(xdr, &hdr);
  4676. if (status)
  4677. goto out;
  4678. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4679. if (status)
  4680. goto out;
  4681. status = decode_putfh(xdr);
  4682. if (status)
  4683. goto out;
  4684. status = decode_savefh(xdr);
  4685. if (status)
  4686. goto out;
  4687. status = decode_putfh(xdr);
  4688. if (status)
  4689. goto out;
  4690. status = decode_link(xdr, &res->cinfo);
  4691. if (status)
  4692. goto out;
  4693. /*
  4694. * Note order: OP_LINK leaves the directory as the current
  4695. * filehandle.
  4696. */
  4697. if (decode_getfattr(xdr, res->dir_attr, res->server,
  4698. !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
  4699. goto out;
  4700. status = decode_restorefh(xdr);
  4701. if (status)
  4702. goto out;
  4703. decode_getfattr(xdr, res->fattr, res->server,
  4704. !RPC_IS_ASYNC(rqstp->rq_task));
  4705. out:
  4706. return status;
  4707. }
  4708. /*
  4709. * Decode CREATE response
  4710. */
  4711. static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4712. struct nfs4_create_res *res)
  4713. {
  4714. struct compound_hdr hdr;
  4715. int status;
  4716. status = decode_compound_hdr(xdr, &hdr);
  4717. if (status)
  4718. goto out;
  4719. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4720. if (status)
  4721. goto out;
  4722. status = decode_putfh(xdr);
  4723. if (status)
  4724. goto out;
  4725. status = decode_savefh(xdr);
  4726. if (status)
  4727. goto out;
  4728. status = decode_create(xdr, &res->dir_cinfo);
  4729. if (status)
  4730. goto out;
  4731. status = decode_getfh(xdr, res->fh);
  4732. if (status)
  4733. goto out;
  4734. if (decode_getfattr(xdr, res->fattr, res->server,
  4735. !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
  4736. goto out;
  4737. status = decode_restorefh(xdr);
  4738. if (status)
  4739. goto out;
  4740. decode_getfattr(xdr, res->dir_fattr, res->server,
  4741. !RPC_IS_ASYNC(rqstp->rq_task));
  4742. out:
  4743. return status;
  4744. }
  4745. /*
  4746. * Decode SYMLINK response
  4747. */
  4748. static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4749. struct nfs4_create_res *res)
  4750. {
  4751. return nfs4_xdr_dec_create(rqstp, xdr, res);
  4752. }
  4753. /*
  4754. * Decode GETATTR response
  4755. */
  4756. static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4757. struct nfs4_getattr_res *res)
  4758. {
  4759. struct compound_hdr hdr;
  4760. int status;
  4761. status = decode_compound_hdr(xdr, &hdr);
  4762. if (status)
  4763. goto out;
  4764. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4765. if (status)
  4766. goto out;
  4767. status = decode_putfh(xdr);
  4768. if (status)
  4769. goto out;
  4770. status = decode_getfattr(xdr, res->fattr, res->server,
  4771. !RPC_IS_ASYNC(rqstp->rq_task));
  4772. out:
  4773. return status;
  4774. }
  4775. /*
  4776. * Encode an SETACL request
  4777. */
  4778. static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
  4779. struct nfs_setaclargs *args)
  4780. {
  4781. struct compound_hdr hdr = {
  4782. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  4783. };
  4784. encode_compound_hdr(xdr, req, &hdr);
  4785. encode_sequence(xdr, &args->seq_args, &hdr);
  4786. encode_putfh(xdr, args->fh, &hdr);
  4787. encode_setacl(xdr, args, &hdr);
  4788. encode_nops(&hdr);
  4789. }
  4790. /*
  4791. * Decode SETACL response
  4792. */
  4793. static int
  4794. nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4795. struct nfs_setaclres *res)
  4796. {
  4797. struct compound_hdr hdr;
  4798. int status;
  4799. status = decode_compound_hdr(xdr, &hdr);
  4800. if (status)
  4801. goto out;
  4802. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4803. if (status)
  4804. goto out;
  4805. status = decode_putfh(xdr);
  4806. if (status)
  4807. goto out;
  4808. status = decode_setattr(xdr);
  4809. out:
  4810. return status;
  4811. }
  4812. /*
  4813. * Decode GETACL response
  4814. */
  4815. static int
  4816. nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4817. struct nfs_getaclres *res)
  4818. {
  4819. struct compound_hdr hdr;
  4820. int status;
  4821. status = decode_compound_hdr(xdr, &hdr);
  4822. if (status)
  4823. goto out;
  4824. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4825. if (status)
  4826. goto out;
  4827. status = decode_putfh(xdr);
  4828. if (status)
  4829. goto out;
  4830. status = decode_getacl(xdr, rqstp, &res->acl_len);
  4831. out:
  4832. return status;
  4833. }
  4834. /*
  4835. * Decode CLOSE response
  4836. */
  4837. static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4838. struct nfs_closeres *res)
  4839. {
  4840. struct compound_hdr hdr;
  4841. int status;
  4842. status = decode_compound_hdr(xdr, &hdr);
  4843. if (status)
  4844. goto out;
  4845. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4846. if (status)
  4847. goto out;
  4848. status = decode_putfh(xdr);
  4849. if (status)
  4850. goto out;
  4851. status = decode_close(xdr, res);
  4852. if (status != 0)
  4853. goto out;
  4854. /*
  4855. * Note: Server may do delete on close for this file
  4856. * in which case the getattr call will fail with
  4857. * an ESTALE error. Shouldn't be a problem,
  4858. * though, since fattr->valid will remain unset.
  4859. */
  4860. decode_getfattr(xdr, res->fattr, res->server,
  4861. !RPC_IS_ASYNC(rqstp->rq_task));
  4862. out:
  4863. return status;
  4864. }
  4865. /*
  4866. * Decode OPEN response
  4867. */
  4868. static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4869. struct nfs_openres *res)
  4870. {
  4871. struct compound_hdr hdr;
  4872. int status;
  4873. status = decode_compound_hdr(xdr, &hdr);
  4874. if (status)
  4875. goto out;
  4876. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4877. if (status)
  4878. goto out;
  4879. status = decode_putfh(xdr);
  4880. if (status)
  4881. goto out;
  4882. status = decode_savefh(xdr);
  4883. if (status)
  4884. goto out;
  4885. status = decode_open(xdr, res);
  4886. if (status)
  4887. goto out;
  4888. if (decode_getfh(xdr, &res->fh) != 0)
  4889. goto out;
  4890. if (decode_getfattr(xdr, res->f_attr, res->server,
  4891. !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
  4892. goto out;
  4893. if (decode_restorefh(xdr) != 0)
  4894. goto out;
  4895. decode_getfattr(xdr, res->dir_attr, res->server,
  4896. !RPC_IS_ASYNC(rqstp->rq_task));
  4897. out:
  4898. return status;
  4899. }
  4900. /*
  4901. * Decode OPEN_CONFIRM response
  4902. */
  4903. static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
  4904. struct xdr_stream *xdr,
  4905. struct nfs_open_confirmres *res)
  4906. {
  4907. struct compound_hdr hdr;
  4908. int status;
  4909. status = decode_compound_hdr(xdr, &hdr);
  4910. if (status)
  4911. goto out;
  4912. status = decode_putfh(xdr);
  4913. if (status)
  4914. goto out;
  4915. status = decode_open_confirm(xdr, res);
  4916. out:
  4917. return status;
  4918. }
  4919. /*
  4920. * Decode OPEN response
  4921. */
  4922. static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
  4923. struct xdr_stream *xdr,
  4924. struct nfs_openres *res)
  4925. {
  4926. struct compound_hdr hdr;
  4927. int status;
  4928. status = decode_compound_hdr(xdr, &hdr);
  4929. if (status)
  4930. goto out;
  4931. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4932. if (status)
  4933. goto out;
  4934. status = decode_putfh(xdr);
  4935. if (status)
  4936. goto out;
  4937. status = decode_open(xdr, res);
  4938. if (status)
  4939. goto out;
  4940. decode_getfattr(xdr, res->f_attr, res->server,
  4941. !RPC_IS_ASYNC(rqstp->rq_task));
  4942. out:
  4943. return status;
  4944. }
  4945. /*
  4946. * Decode SETATTR response
  4947. */
  4948. static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
  4949. struct xdr_stream *xdr,
  4950. struct nfs_setattrres *res)
  4951. {
  4952. struct compound_hdr hdr;
  4953. int status;
  4954. status = decode_compound_hdr(xdr, &hdr);
  4955. if (status)
  4956. goto out;
  4957. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4958. if (status)
  4959. goto out;
  4960. status = decode_putfh(xdr);
  4961. if (status)
  4962. goto out;
  4963. status = decode_setattr(xdr);
  4964. if (status)
  4965. goto out;
  4966. decode_getfattr(xdr, res->fattr, res->server,
  4967. !RPC_IS_ASYNC(rqstp->rq_task));
  4968. out:
  4969. return status;
  4970. }
  4971. /*
  4972. * Decode LOCK response
  4973. */
  4974. static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4975. struct nfs_lock_res *res)
  4976. {
  4977. struct compound_hdr hdr;
  4978. int status;
  4979. status = decode_compound_hdr(xdr, &hdr);
  4980. if (status)
  4981. goto out;
  4982. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4983. if (status)
  4984. goto out;
  4985. status = decode_putfh(xdr);
  4986. if (status)
  4987. goto out;
  4988. status = decode_lock(xdr, res);
  4989. out:
  4990. return status;
  4991. }
  4992. /*
  4993. * Decode LOCKT response
  4994. */
  4995. static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4996. struct nfs_lockt_res *res)
  4997. {
  4998. struct compound_hdr hdr;
  4999. int status;
  5000. status = decode_compound_hdr(xdr, &hdr);
  5001. if (status)
  5002. goto out;
  5003. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5004. if (status)
  5005. goto out;
  5006. status = decode_putfh(xdr);
  5007. if (status)
  5008. goto out;
  5009. status = decode_lockt(xdr, res);
  5010. out:
  5011. return status;
  5012. }
  5013. /*
  5014. * Decode LOCKU response
  5015. */
  5016. static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5017. struct nfs_locku_res *res)
  5018. {
  5019. struct compound_hdr hdr;
  5020. int status;
  5021. status = decode_compound_hdr(xdr, &hdr);
  5022. if (status)
  5023. goto out;
  5024. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5025. if (status)
  5026. goto out;
  5027. status = decode_putfh(xdr);
  5028. if (status)
  5029. goto out;
  5030. status = decode_locku(xdr, res);
  5031. out:
  5032. return status;
  5033. }
  5034. static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
  5035. struct xdr_stream *xdr, void *dummy)
  5036. {
  5037. struct compound_hdr hdr;
  5038. int status;
  5039. status = decode_compound_hdr(xdr, &hdr);
  5040. if (!status)
  5041. status = decode_release_lockowner(xdr);
  5042. return status;
  5043. }
  5044. /*
  5045. * Decode READLINK response
  5046. */
  5047. static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
  5048. struct xdr_stream *xdr,
  5049. struct nfs4_readlink_res *res)
  5050. {
  5051. struct compound_hdr hdr;
  5052. int status;
  5053. status = decode_compound_hdr(xdr, &hdr);
  5054. if (status)
  5055. goto out;
  5056. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5057. if (status)
  5058. goto out;
  5059. status = decode_putfh(xdr);
  5060. if (status)
  5061. goto out;
  5062. status = decode_readlink(xdr, rqstp);
  5063. out:
  5064. return status;
  5065. }
  5066. /*
  5067. * Decode READDIR response
  5068. */
  5069. static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5070. struct nfs4_readdir_res *res)
  5071. {
  5072. struct compound_hdr hdr;
  5073. int status;
  5074. status = decode_compound_hdr(xdr, &hdr);
  5075. if (status)
  5076. goto out;
  5077. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5078. if (status)
  5079. goto out;
  5080. status = decode_putfh(xdr);
  5081. if (status)
  5082. goto out;
  5083. status = decode_readdir(xdr, rqstp, res);
  5084. out:
  5085. return status;
  5086. }
  5087. /*
  5088. * Decode Read response
  5089. */
  5090. static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5091. struct nfs_readres *res)
  5092. {
  5093. struct compound_hdr hdr;
  5094. int status;
  5095. status = decode_compound_hdr(xdr, &hdr);
  5096. if (status)
  5097. goto out;
  5098. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5099. if (status)
  5100. goto out;
  5101. status = decode_putfh(xdr);
  5102. if (status)
  5103. goto out;
  5104. status = decode_read(xdr, rqstp, res);
  5105. if (!status)
  5106. status = res->count;
  5107. out:
  5108. return status;
  5109. }
  5110. /*
  5111. * Decode WRITE response
  5112. */
  5113. static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5114. struct nfs_writeres *res)
  5115. {
  5116. struct compound_hdr hdr;
  5117. int status;
  5118. status = decode_compound_hdr(xdr, &hdr);
  5119. if (status)
  5120. goto out;
  5121. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5122. if (status)
  5123. goto out;
  5124. status = decode_putfh(xdr);
  5125. if (status)
  5126. goto out;
  5127. status = decode_write(xdr, res);
  5128. if (status)
  5129. goto out;
  5130. decode_getfattr(xdr, res->fattr, res->server,
  5131. !RPC_IS_ASYNC(rqstp->rq_task));
  5132. if (!status)
  5133. status = res->count;
  5134. out:
  5135. return status;
  5136. }
  5137. /*
  5138. * Decode COMMIT response
  5139. */
  5140. static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5141. struct nfs_writeres *res)
  5142. {
  5143. struct compound_hdr hdr;
  5144. int status;
  5145. status = decode_compound_hdr(xdr, &hdr);
  5146. if (status)
  5147. goto out;
  5148. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5149. if (status)
  5150. goto out;
  5151. status = decode_putfh(xdr);
  5152. if (status)
  5153. goto out;
  5154. status = decode_commit(xdr, res);
  5155. if (status)
  5156. goto out;
  5157. decode_getfattr(xdr, res->fattr, res->server,
  5158. !RPC_IS_ASYNC(rqstp->rq_task));
  5159. out:
  5160. return status;
  5161. }
  5162. /*
  5163. * Decode FSINFO response
  5164. */
  5165. static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
  5166. struct nfs4_fsinfo_res *res)
  5167. {
  5168. struct compound_hdr hdr;
  5169. int status;
  5170. status = decode_compound_hdr(xdr, &hdr);
  5171. if (!status)
  5172. status = decode_sequence(xdr, &res->seq_res, req);
  5173. if (!status)
  5174. status = decode_putfh(xdr);
  5175. if (!status)
  5176. status = decode_fsinfo(xdr, res->fsinfo);
  5177. return status;
  5178. }
  5179. /*
  5180. * Decode PATHCONF response
  5181. */
  5182. static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
  5183. struct nfs4_pathconf_res *res)
  5184. {
  5185. struct compound_hdr hdr;
  5186. int status;
  5187. status = decode_compound_hdr(xdr, &hdr);
  5188. if (!status)
  5189. status = decode_sequence(xdr, &res->seq_res, req);
  5190. if (!status)
  5191. status = decode_putfh(xdr);
  5192. if (!status)
  5193. status = decode_pathconf(xdr, res->pathconf);
  5194. return status;
  5195. }
  5196. /*
  5197. * Decode STATFS response
  5198. */
  5199. static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
  5200. struct nfs4_statfs_res *res)
  5201. {
  5202. struct compound_hdr hdr;
  5203. int status;
  5204. status = decode_compound_hdr(xdr, &hdr);
  5205. if (!status)
  5206. status = decode_sequence(xdr, &res->seq_res, req);
  5207. if (!status)
  5208. status = decode_putfh(xdr);
  5209. if (!status)
  5210. status = decode_statfs(xdr, res->fsstat);
  5211. return status;
  5212. }
  5213. /*
  5214. * Decode GETATTR_BITMAP response
  5215. */
  5216. static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
  5217. struct xdr_stream *xdr,
  5218. struct nfs4_server_caps_res *res)
  5219. {
  5220. struct compound_hdr hdr;
  5221. int status;
  5222. status = decode_compound_hdr(xdr, &hdr);
  5223. if (status)
  5224. goto out;
  5225. status = decode_sequence(xdr, &res->seq_res, req);
  5226. if (status)
  5227. goto out;
  5228. status = decode_putfh(xdr);
  5229. if (status)
  5230. goto out;
  5231. status = decode_server_caps(xdr, res);
  5232. out:
  5233. return status;
  5234. }
  5235. /*
  5236. * Decode RENEW response
  5237. */
  5238. static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5239. void *__unused)
  5240. {
  5241. struct compound_hdr hdr;
  5242. int status;
  5243. status = decode_compound_hdr(xdr, &hdr);
  5244. if (!status)
  5245. status = decode_renew(xdr);
  5246. return status;
  5247. }
  5248. /*
  5249. * Decode SETCLIENTID response
  5250. */
  5251. static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
  5252. struct xdr_stream *xdr,
  5253. struct nfs4_setclientid_res *res)
  5254. {
  5255. struct compound_hdr hdr;
  5256. int status;
  5257. status = decode_compound_hdr(xdr, &hdr);
  5258. if (!status)
  5259. status = decode_setclientid(xdr, res);
  5260. return status;
  5261. }
  5262. /*
  5263. * Decode SETCLIENTID_CONFIRM response
  5264. */
  5265. static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
  5266. struct xdr_stream *xdr,
  5267. struct nfs_fsinfo *fsinfo)
  5268. {
  5269. struct compound_hdr hdr;
  5270. int status;
  5271. status = decode_compound_hdr(xdr, &hdr);
  5272. if (!status)
  5273. status = decode_setclientid_confirm(xdr);
  5274. if (!status)
  5275. status = decode_putrootfh(xdr);
  5276. if (!status)
  5277. status = decode_fsinfo(xdr, fsinfo);
  5278. return status;
  5279. }
  5280. /*
  5281. * Decode DELEGRETURN response
  5282. */
  5283. static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
  5284. struct xdr_stream *xdr,
  5285. struct nfs4_delegreturnres *res)
  5286. {
  5287. struct compound_hdr hdr;
  5288. int status;
  5289. status = decode_compound_hdr(xdr, &hdr);
  5290. if (status)
  5291. goto out;
  5292. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5293. if (status)
  5294. goto out;
  5295. status = decode_putfh(xdr);
  5296. if (status != 0)
  5297. goto out;
  5298. status = decode_delegreturn(xdr);
  5299. if (status != 0)
  5300. goto out;
  5301. decode_getfattr(xdr, res->fattr, res->server,
  5302. !RPC_IS_ASYNC(rqstp->rq_task));
  5303. out:
  5304. return status;
  5305. }
  5306. /*
  5307. * Decode FS_LOCATIONS response
  5308. */
  5309. static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
  5310. struct xdr_stream *xdr,
  5311. struct nfs4_fs_locations_res *res)
  5312. {
  5313. struct compound_hdr hdr;
  5314. int status;
  5315. status = decode_compound_hdr(xdr, &hdr);
  5316. if (status)
  5317. goto out;
  5318. status = decode_sequence(xdr, &res->seq_res, req);
  5319. if (status)
  5320. goto out;
  5321. status = decode_putfh(xdr);
  5322. if (status)
  5323. goto out;
  5324. status = decode_lookup(xdr);
  5325. if (status)
  5326. goto out;
  5327. xdr_enter_page(xdr, PAGE_SIZE);
  5328. status = decode_getfattr(xdr, &res->fs_locations->fattr,
  5329. res->fs_locations->server,
  5330. !RPC_IS_ASYNC(req->rq_task));
  5331. out:
  5332. return status;
  5333. }
  5334. #if defined(CONFIG_NFS_V4_1)
  5335. /*
  5336. * Decode EXCHANGE_ID response
  5337. */
  5338. static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
  5339. struct xdr_stream *xdr,
  5340. void *res)
  5341. {
  5342. struct compound_hdr hdr;
  5343. int status;
  5344. status = decode_compound_hdr(xdr, &hdr);
  5345. if (!status)
  5346. status = decode_exchange_id(xdr, res);
  5347. return status;
  5348. }
  5349. /*
  5350. * Decode CREATE_SESSION response
  5351. */
  5352. static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
  5353. struct xdr_stream *xdr,
  5354. struct nfs41_create_session_res *res)
  5355. {
  5356. struct compound_hdr hdr;
  5357. int status;
  5358. status = decode_compound_hdr(xdr, &hdr);
  5359. if (!status)
  5360. status = decode_create_session(xdr, res);
  5361. return status;
  5362. }
  5363. /*
  5364. * Decode DESTROY_SESSION response
  5365. */
  5366. static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
  5367. struct xdr_stream *xdr,
  5368. void *res)
  5369. {
  5370. struct compound_hdr hdr;
  5371. int status;
  5372. status = decode_compound_hdr(xdr, &hdr);
  5373. if (!status)
  5374. status = decode_destroy_session(xdr, res);
  5375. return status;
  5376. }
  5377. /*
  5378. * Decode SEQUENCE response
  5379. */
  5380. static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
  5381. struct xdr_stream *xdr,
  5382. struct nfs4_sequence_res *res)
  5383. {
  5384. struct compound_hdr hdr;
  5385. int status;
  5386. status = decode_compound_hdr(xdr, &hdr);
  5387. if (!status)
  5388. status = decode_sequence(xdr, res, rqstp);
  5389. return status;
  5390. }
  5391. /*
  5392. * Decode GET_LEASE_TIME response
  5393. */
  5394. static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
  5395. struct xdr_stream *xdr,
  5396. struct nfs4_get_lease_time_res *res)
  5397. {
  5398. struct compound_hdr hdr;
  5399. int status;
  5400. status = decode_compound_hdr(xdr, &hdr);
  5401. if (!status)
  5402. status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
  5403. if (!status)
  5404. status = decode_putrootfh(xdr);
  5405. if (!status)
  5406. status = decode_fsinfo(xdr, res->lr_fsinfo);
  5407. return status;
  5408. }
  5409. /*
  5410. * Decode RECLAIM_COMPLETE response
  5411. */
  5412. static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
  5413. struct xdr_stream *xdr,
  5414. struct nfs41_reclaim_complete_res *res)
  5415. {
  5416. struct compound_hdr hdr;
  5417. int status;
  5418. status = decode_compound_hdr(xdr, &hdr);
  5419. if (!status)
  5420. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5421. if (!status)
  5422. status = decode_reclaim_complete(xdr, (void *)NULL);
  5423. return status;
  5424. }
  5425. /*
  5426. * Decode GETDEVINFO response
  5427. */
  5428. static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
  5429. struct xdr_stream *xdr,
  5430. struct nfs4_getdeviceinfo_res *res)
  5431. {
  5432. struct compound_hdr hdr;
  5433. int status;
  5434. status = decode_compound_hdr(xdr, &hdr);
  5435. if (status != 0)
  5436. goto out;
  5437. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5438. if (status != 0)
  5439. goto out;
  5440. status = decode_getdeviceinfo(xdr, res->pdev);
  5441. out:
  5442. return status;
  5443. }
  5444. /*
  5445. * Decode LAYOUTGET response
  5446. */
  5447. static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
  5448. struct xdr_stream *xdr,
  5449. struct nfs4_layoutget_res *res)
  5450. {
  5451. struct compound_hdr hdr;
  5452. int status;
  5453. status = decode_compound_hdr(xdr, &hdr);
  5454. if (status)
  5455. goto out;
  5456. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5457. if (status)
  5458. goto out;
  5459. status = decode_putfh(xdr);
  5460. if (status)
  5461. goto out;
  5462. status = decode_layoutget(xdr, rqstp, res);
  5463. out:
  5464. return status;
  5465. }
  5466. #endif /* CONFIG_NFS_V4_1 */
  5467. /**
  5468. * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
  5469. * the local page cache.
  5470. * @xdr: XDR stream where entry resides
  5471. * @entry: buffer to fill in with entry data
  5472. * @plus: boolean indicating whether this should be a readdirplus entry
  5473. *
  5474. * Returns zero if successful, otherwise a negative errno value is
  5475. * returned.
  5476. *
  5477. * This function is not invoked during READDIR reply decoding, but
  5478. * rather whenever an application invokes the getdents(2) system call
  5479. * on a directory already in our cache.
  5480. */
  5481. int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
  5482. int plus)
  5483. {
  5484. uint32_t bitmap[2] = {0};
  5485. uint32_t len;
  5486. __be32 *p = xdr_inline_decode(xdr, 4);
  5487. if (unlikely(!p))
  5488. goto out_overflow;
  5489. if (!ntohl(*p++)) {
  5490. p = xdr_inline_decode(xdr, 4);
  5491. if (unlikely(!p))
  5492. goto out_overflow;
  5493. if (!ntohl(*p++))
  5494. return -EAGAIN;
  5495. entry->eof = 1;
  5496. return -EBADCOOKIE;
  5497. }
  5498. p = xdr_inline_decode(xdr, 12);
  5499. if (unlikely(!p))
  5500. goto out_overflow;
  5501. entry->prev_cookie = entry->cookie;
  5502. p = xdr_decode_hyper(p, &entry->cookie);
  5503. entry->len = ntohl(*p++);
  5504. p = xdr_inline_decode(xdr, entry->len);
  5505. if (unlikely(!p))
  5506. goto out_overflow;
  5507. entry->name = (const char *) p;
  5508. /*
  5509. * In case the server doesn't return an inode number,
  5510. * we fake one here. (We don't use inode number 0,
  5511. * since glibc seems to choke on it...)
  5512. */
  5513. entry->ino = 1;
  5514. entry->fattr->valid = 0;
  5515. if (decode_attr_bitmap(xdr, bitmap) < 0)
  5516. goto out_overflow;
  5517. if (decode_attr_length(xdr, &len, &p) < 0)
  5518. goto out_overflow;
  5519. if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
  5520. entry->server, 1) < 0)
  5521. goto out_overflow;
  5522. if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
  5523. entry->ino = entry->fattr->fileid;
  5524. entry->d_type = DT_UNKNOWN;
  5525. if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
  5526. entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
  5527. if (verify_attr_len(xdr, p, len) < 0)
  5528. goto out_overflow;
  5529. p = xdr_inline_peek(xdr, 8);
  5530. if (p != NULL)
  5531. entry->eof = !p[0] && p[1];
  5532. else
  5533. entry->eof = 0;
  5534. return 0;
  5535. out_overflow:
  5536. print_overflow_msg(__func__, xdr);
  5537. return -EAGAIN;
  5538. }
  5539. /*
  5540. * We need to translate between nfs status return values and
  5541. * the local errno values which may not be the same.
  5542. */
  5543. static struct {
  5544. int stat;
  5545. int errno;
  5546. } nfs_errtbl[] = {
  5547. { NFS4_OK, 0 },
  5548. { NFS4ERR_PERM, -EPERM },
  5549. { NFS4ERR_NOENT, -ENOENT },
  5550. { NFS4ERR_IO, -errno_NFSERR_IO},
  5551. { NFS4ERR_NXIO, -ENXIO },
  5552. { NFS4ERR_ACCESS, -EACCES },
  5553. { NFS4ERR_EXIST, -EEXIST },
  5554. { NFS4ERR_XDEV, -EXDEV },
  5555. { NFS4ERR_NOTDIR, -ENOTDIR },
  5556. { NFS4ERR_ISDIR, -EISDIR },
  5557. { NFS4ERR_INVAL, -EINVAL },
  5558. { NFS4ERR_FBIG, -EFBIG },
  5559. { NFS4ERR_NOSPC, -ENOSPC },
  5560. { NFS4ERR_ROFS, -EROFS },
  5561. { NFS4ERR_MLINK, -EMLINK },
  5562. { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
  5563. { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
  5564. { NFS4ERR_DQUOT, -EDQUOT },
  5565. { NFS4ERR_STALE, -ESTALE },
  5566. { NFS4ERR_BADHANDLE, -EBADHANDLE },
  5567. { NFS4ERR_BADOWNER, -EINVAL },
  5568. { NFS4ERR_BADNAME, -EINVAL },
  5569. { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
  5570. { NFS4ERR_NOTSUPP, -ENOTSUPP },
  5571. { NFS4ERR_TOOSMALL, -ETOOSMALL },
  5572. { NFS4ERR_SERVERFAULT, -EREMOTEIO },
  5573. { NFS4ERR_BADTYPE, -EBADTYPE },
  5574. { NFS4ERR_LOCKED, -EAGAIN },
  5575. { NFS4ERR_SYMLINK, -ELOOP },
  5576. { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
  5577. { NFS4ERR_DEADLOCK, -EDEADLK },
  5578. { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
  5579. * to be handled by a
  5580. * middle-layer.
  5581. */
  5582. { -1, -EIO }
  5583. };
  5584. /*
  5585. * Convert an NFS error code to a local one.
  5586. * This one is used jointly by NFSv2 and NFSv3.
  5587. */
  5588. static int
  5589. nfs4_stat_to_errno(int stat)
  5590. {
  5591. int i;
  5592. for (i = 0; nfs_errtbl[i].stat != -1; i++) {
  5593. if (nfs_errtbl[i].stat == stat)
  5594. return nfs_errtbl[i].errno;
  5595. }
  5596. if (stat <= 10000 || stat > 10100) {
  5597. /* The server is looney tunes. */
  5598. return -EREMOTEIO;
  5599. }
  5600. /* If we cannot translate the error, the recovery routines should
  5601. * handle it.
  5602. * Note: remaining NFSv4 error codes have values > 10000, so should
  5603. * not conflict with native Linux error codes.
  5604. */
  5605. return -stat;
  5606. }
  5607. #define PROC(proc, argtype, restype) \
  5608. [NFSPROC4_CLNT_##proc] = { \
  5609. .p_proc = NFSPROC4_COMPOUND, \
  5610. .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
  5611. .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
  5612. .p_arglen = NFS4_##argtype##_sz, \
  5613. .p_replen = NFS4_##restype##_sz, \
  5614. .p_statidx = NFSPROC4_CLNT_##proc, \
  5615. .p_name = #proc, \
  5616. }
  5617. struct rpc_procinfo nfs4_procedures[] = {
  5618. PROC(READ, enc_read, dec_read),
  5619. PROC(WRITE, enc_write, dec_write),
  5620. PROC(COMMIT, enc_commit, dec_commit),
  5621. PROC(OPEN, enc_open, dec_open),
  5622. PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
  5623. PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
  5624. PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
  5625. PROC(CLOSE, enc_close, dec_close),
  5626. PROC(SETATTR, enc_setattr, dec_setattr),
  5627. PROC(FSINFO, enc_fsinfo, dec_fsinfo),
  5628. PROC(RENEW, enc_renew, dec_renew),
  5629. PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
  5630. PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
  5631. PROC(LOCK, enc_lock, dec_lock),
  5632. PROC(LOCKT, enc_lockt, dec_lockt),
  5633. PROC(LOCKU, enc_locku, dec_locku),
  5634. PROC(ACCESS, enc_access, dec_access),
  5635. PROC(GETATTR, enc_getattr, dec_getattr),
  5636. PROC(LOOKUP, enc_lookup, dec_lookup),
  5637. PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
  5638. PROC(REMOVE, enc_remove, dec_remove),
  5639. PROC(RENAME, enc_rename, dec_rename),
  5640. PROC(LINK, enc_link, dec_link),
  5641. PROC(SYMLINK, enc_symlink, dec_symlink),
  5642. PROC(CREATE, enc_create, dec_create),
  5643. PROC(PATHCONF, enc_pathconf, dec_pathconf),
  5644. PROC(STATFS, enc_statfs, dec_statfs),
  5645. PROC(READLINK, enc_readlink, dec_readlink),
  5646. PROC(READDIR, enc_readdir, dec_readdir),
  5647. PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
  5648. PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
  5649. PROC(GETACL, enc_getacl, dec_getacl),
  5650. PROC(SETACL, enc_setacl, dec_setacl),
  5651. PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
  5652. PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
  5653. #if defined(CONFIG_NFS_V4_1)
  5654. PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
  5655. PROC(CREATE_SESSION, enc_create_session, dec_create_session),
  5656. PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
  5657. PROC(SEQUENCE, enc_sequence, dec_sequence),
  5658. PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
  5659. PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
  5660. PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
  5661. PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
  5662. #endif /* CONFIG_NFS_V4_1 */
  5663. };
  5664. struct rpc_version nfs_version4 = {
  5665. .number = 4,
  5666. .nrprocs = ARRAY_SIZE(nfs4_procedures),
  5667. .procs = nfs4_procedures
  5668. };
  5669. /*
  5670. * Local variables:
  5671. * c-basic-offset: 8
  5672. * End:
  5673. */