nfs4xdr.c 115 KB

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