nfs4xdr.c 163 KB

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