nfs4xdr.c 119 KB

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