nfs4xdr.c 141 KB

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