nfs4xdr.c 151 KB

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