nfs4xdr.c 187 KB

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