nfs4xdr.c 159 KB

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