nfs4xdr.c 118 KB

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