nfs4xdr.c 115 KB

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