nfs4xdr.c 144 KB

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