nfs4xdr.c 143 KB

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