nfs4xdr.c 118 KB

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