nfs4xdr.c 163 KB

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