nfs4xdr.c 116 KB

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