nfs4xdr.c 199 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636
  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/module.h>
  47. #include <linux/utsname.h>
  48. #include <linux/sunrpc/clnt.h>
  49. #include <linux/sunrpc/msg_prot.h>
  50. #include <linux/sunrpc/gss_api.h>
  51. #include <linux/nfs.h>
  52. #include <linux/nfs4.h>
  53. #include <linux/nfs_fs.h>
  54. #include "nfs4_fs.h"
  55. #include "nfs4trace.h"
  56. #include "internal.h"
  57. #include "nfs4idmap.h"
  58. #include "nfs4session.h"
  59. #include "pnfs.h"
  60. #include "netns.h"
  61. #define NFSDBG_FACILITY NFSDBG_XDR
  62. /* Mapping from NFS error code to "errno" error code. */
  63. #define errno_NFSERR_IO EIO
  64. struct compound_hdr;
  65. static int nfs4_stat_to_errno(int);
  66. static void encode_layoutget(struct xdr_stream *xdr,
  67. const struct nfs4_layoutget_args *args,
  68. struct compound_hdr *hdr);
  69. static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
  70. struct nfs4_layoutget_res *res);
  71. /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
  72. #ifdef DEBUG
  73. #define NFS4_MAXTAGLEN 20
  74. #else
  75. #define NFS4_MAXTAGLEN 0
  76. #endif
  77. /* lock,open owner id:
  78. * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
  79. */
  80. #define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
  81. #define lock_owner_id_maxsz (1 + 1 + 4)
  82. #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
  83. #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
  84. #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
  85. #define op_encode_hdr_maxsz (1)
  86. #define op_decode_hdr_maxsz (2)
  87. #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
  88. #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
  89. #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
  90. #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
  91. #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
  92. (NFS4_FHSIZE >> 2))
  93. #define decode_putfh_maxsz (op_decode_hdr_maxsz)
  94. #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
  95. #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
  96. #define encode_getfh_maxsz (op_encode_hdr_maxsz)
  97. #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
  98. ((3+NFS4_FHSIZE) >> 2))
  99. #define nfs4_fattr_bitmap_maxsz 4
  100. #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
  101. #define nfstime4_maxsz (3)
  102. #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
  103. #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
  104. #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
  105. #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
  106. #ifdef CONFIG_NFS_V4_SECURITY_LABEL
  107. /* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
  108. #define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
  109. #else
  110. #define nfs4_label_maxsz 0
  111. #endif
  112. /* We support only one layout type per file system */
  113. #define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
  114. /* This is based on getfattr, which uses the most attributes: */
  115. #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
  116. 3*nfstime4_maxsz + \
  117. nfs4_owner_maxsz + \
  118. nfs4_group_maxsz + nfs4_label_maxsz + \
  119. decode_mdsthreshold_maxsz))
  120. #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
  121. nfs4_fattr_value_maxsz)
  122. #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
  123. #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
  124. 1 + 2 + 1 + \
  125. nfs4_owner_maxsz + \
  126. nfs4_group_maxsz + \
  127. nfs4_label_maxsz + \
  128. 1 + nfstime4_maxsz + \
  129. 1 + nfstime4_maxsz)
  130. #define encode_savefh_maxsz (op_encode_hdr_maxsz)
  131. #define decode_savefh_maxsz (op_decode_hdr_maxsz)
  132. #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
  133. #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
  134. #define encode_fsinfo_maxsz (encode_getattr_maxsz)
  135. /* The 5 accounts for the PNFS attributes, and assumes that at most three
  136. * layout types will be returned.
  137. */
  138. #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
  139. nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
  140. #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
  141. #define decode_renew_maxsz (op_decode_hdr_maxsz)
  142. #define encode_setclientid_maxsz \
  143. (op_encode_hdr_maxsz + \
  144. XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
  145. /* client name */ \
  146. 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
  147. 1 /* sc_prog */ + \
  148. 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
  149. 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
  150. 1) /* sc_cb_ident */
  151. #define decode_setclientid_maxsz \
  152. (op_decode_hdr_maxsz + \
  153. 2 /* clientid */ + \
  154. XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
  155. 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
  156. 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
  157. #define encode_setclientid_confirm_maxsz \
  158. (op_encode_hdr_maxsz + \
  159. 3 + (NFS4_VERIFIER_SIZE >> 2))
  160. #define decode_setclientid_confirm_maxsz \
  161. (op_decode_hdr_maxsz)
  162. #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
  163. #define decode_lookup_maxsz (op_decode_hdr_maxsz)
  164. #define encode_lookupp_maxsz (op_encode_hdr_maxsz)
  165. #define decode_lookupp_maxsz (op_decode_hdr_maxsz)
  166. #define encode_share_access_maxsz \
  167. (2)
  168. #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
  169. #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
  170. #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
  171. #define encode_open_maxsz (op_encode_hdr_maxsz + \
  172. 2 + encode_share_access_maxsz + 2 + \
  173. open_owner_id_maxsz + \
  174. encode_opentype_maxsz + \
  175. encode_claim_null_maxsz)
  176. #define decode_space_limit_maxsz (3)
  177. #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
  178. #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
  179. decode_space_limit_maxsz + \
  180. decode_ace_maxsz)
  181. #define decode_change_info_maxsz (5)
  182. #define decode_open_maxsz (op_decode_hdr_maxsz + \
  183. decode_stateid_maxsz + \
  184. decode_change_info_maxsz + 1 + \
  185. nfs4_fattr_bitmap_maxsz + \
  186. decode_delegation_maxsz)
  187. #define encode_open_confirm_maxsz \
  188. (op_encode_hdr_maxsz + \
  189. encode_stateid_maxsz + 1)
  190. #define decode_open_confirm_maxsz \
  191. (op_decode_hdr_maxsz + \
  192. decode_stateid_maxsz)
  193. #define encode_open_downgrade_maxsz \
  194. (op_encode_hdr_maxsz + \
  195. encode_stateid_maxsz + 1 + \
  196. encode_share_access_maxsz)
  197. #define decode_open_downgrade_maxsz \
  198. (op_decode_hdr_maxsz + \
  199. decode_stateid_maxsz)
  200. #define encode_close_maxsz (op_encode_hdr_maxsz + \
  201. 1 + encode_stateid_maxsz)
  202. #define decode_close_maxsz (op_decode_hdr_maxsz + \
  203. decode_stateid_maxsz)
  204. #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
  205. encode_stateid_maxsz + \
  206. encode_attrs_maxsz)
  207. #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
  208. nfs4_fattr_bitmap_maxsz)
  209. #define encode_read_maxsz (op_encode_hdr_maxsz + \
  210. encode_stateid_maxsz + 3)
  211. #define decode_read_maxsz (op_decode_hdr_maxsz + 2 + 1)
  212. #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
  213. 2 + encode_verifier_maxsz + 5 + \
  214. nfs4_label_maxsz)
  215. #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
  216. decode_verifier_maxsz + 1)
  217. #define encode_readlink_maxsz (op_encode_hdr_maxsz)
  218. #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1 + 1)
  219. #define encode_write_maxsz (op_encode_hdr_maxsz + \
  220. encode_stateid_maxsz + 4)
  221. #define decode_write_maxsz (op_decode_hdr_maxsz + \
  222. 2 + decode_verifier_maxsz)
  223. #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
  224. #define decode_commit_maxsz (op_decode_hdr_maxsz + \
  225. decode_verifier_maxsz)
  226. #define encode_remove_maxsz (op_encode_hdr_maxsz + \
  227. nfs4_name_maxsz)
  228. #define decode_remove_maxsz (op_decode_hdr_maxsz + \
  229. decode_change_info_maxsz)
  230. #define encode_rename_maxsz (op_encode_hdr_maxsz + \
  231. 2 * nfs4_name_maxsz)
  232. #define decode_rename_maxsz (op_decode_hdr_maxsz + \
  233. decode_change_info_maxsz + \
  234. decode_change_info_maxsz)
  235. #define encode_link_maxsz (op_encode_hdr_maxsz + \
  236. nfs4_name_maxsz)
  237. #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
  238. #define encode_lockowner_maxsz (7)
  239. #define encode_lock_maxsz (op_encode_hdr_maxsz + \
  240. 7 + \
  241. 1 + encode_stateid_maxsz + 1 + \
  242. encode_lockowner_maxsz)
  243. #define decode_lock_denied_maxsz \
  244. (8 + decode_lockowner_maxsz)
  245. #define decode_lock_maxsz (op_decode_hdr_maxsz + \
  246. decode_lock_denied_maxsz)
  247. #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
  248. encode_lockowner_maxsz)
  249. #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
  250. decode_lock_denied_maxsz)
  251. #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
  252. encode_stateid_maxsz + \
  253. 4)
  254. #define decode_locku_maxsz (op_decode_hdr_maxsz + \
  255. decode_stateid_maxsz)
  256. #define encode_release_lockowner_maxsz \
  257. (op_encode_hdr_maxsz + \
  258. encode_lockowner_maxsz)
  259. #define decode_release_lockowner_maxsz \
  260. (op_decode_hdr_maxsz)
  261. #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
  262. #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
  263. #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
  264. 1 + nfs4_name_maxsz + \
  265. 1 + \
  266. nfs4_fattr_maxsz)
  267. #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
  268. #define encode_create_maxsz (op_encode_hdr_maxsz + \
  269. 1 + 2 + nfs4_name_maxsz + \
  270. encode_attrs_maxsz)
  271. #define decode_create_maxsz (op_decode_hdr_maxsz + \
  272. decode_change_info_maxsz + \
  273. nfs4_fattr_bitmap_maxsz)
  274. #define encode_statfs_maxsz (encode_getattr_maxsz)
  275. #define decode_statfs_maxsz (decode_getattr_maxsz)
  276. #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
  277. #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
  278. #define encode_getacl_maxsz (encode_getattr_maxsz)
  279. #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
  280. nfs4_fattr_bitmap_maxsz + 1 + 1)
  281. #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
  282. encode_stateid_maxsz + 3)
  283. #define decode_setacl_maxsz (decode_setattr_maxsz)
  284. #define encode_fs_locations_maxsz \
  285. (encode_getattr_maxsz)
  286. #define decode_fs_locations_maxsz \
  287. (1)
  288. #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
  289. #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
  290. #if defined(CONFIG_NFS_V4_1)
  291. #define NFS4_MAX_MACHINE_NAME_LEN (64)
  292. #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
  293. sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
  294. #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
  295. encode_verifier_maxsz + \
  296. 1 /* co_ownerid.len */ + \
  297. /* eia_clientowner */ \
  298. 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
  299. 1 /* flags */ + \
  300. 1 /* spa_how */ + \
  301. /* max is SP4_MACH_CRED (for now) */ + \
  302. 1 + NFS4_OP_MAP_NUM_WORDS + \
  303. 1 + NFS4_OP_MAP_NUM_WORDS + \
  304. 1 /* implementation id array of size 1 */ + \
  305. 1 /* nii_domain */ + \
  306. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
  307. 1 /* nii_name */ + \
  308. XDR_QUADLEN(IMPL_NAME_LIMIT) + \
  309. 3 /* nii_date */)
  310. #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
  311. 2 /* eir_clientid */ + \
  312. 1 /* eir_sequenceid */ + \
  313. 1 /* eir_flags */ + \
  314. 1 /* spr_how */ + \
  315. /* max is SP4_MACH_CRED (for now) */ + \
  316. 1 + NFS4_OP_MAP_NUM_WORDS + \
  317. 1 + NFS4_OP_MAP_NUM_WORDS + \
  318. 2 /* eir_server_owner.so_minor_id */ + \
  319. /* eir_server_owner.so_major_id<> */ \
  320. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
  321. /* eir_server_scope<> */ \
  322. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
  323. 1 /* eir_server_impl_id array length */ + \
  324. 1 /* nii_domain */ + \
  325. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
  326. 1 /* nii_name */ + \
  327. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
  328. 3 /* nii_date */)
  329. #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
  330. #define decode_channel_attrs_maxsz (6 + \
  331. 1 /* ca_rdma_ird.len */ + \
  332. 1 /* ca_rdma_ird */)
  333. #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
  334. 2 /* csa_clientid */ + \
  335. 1 /* csa_sequence */ + \
  336. 1 /* csa_flags */ + \
  337. encode_channel_attrs_maxsz + \
  338. encode_channel_attrs_maxsz + \
  339. 1 /* csa_cb_program */ + \
  340. 1 /* csa_sec_parms.len (1) */ + \
  341. 1 /* cb_secflavor (AUTH_SYS) */ + \
  342. 1 /* stamp */ + \
  343. 1 /* machinename.len */ + \
  344. XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
  345. 1 /* uid */ + \
  346. 1 /* gid */ + \
  347. 1 /* gids.len (0) */)
  348. #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
  349. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
  350. 1 /* csr_sequence */ + \
  351. 1 /* csr_flags */ + \
  352. decode_channel_attrs_maxsz + \
  353. decode_channel_attrs_maxsz)
  354. #define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
  355. /* bctsa_sessid */ \
  356. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
  357. 1 /* bctsa_dir */ + \
  358. 1 /* bctsa_use_conn_in_rdma_mode */)
  359. #define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
  360. /* bctsr_sessid */ \
  361. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
  362. 1 /* bctsr_dir */ + \
  363. 1 /* bctsr_use_conn_in_rdma_mode */)
  364. #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
  365. #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
  366. #define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
  367. #define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
  368. #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
  369. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
  370. #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
  371. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
  372. #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
  373. #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
  374. #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
  375. XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
  376. 1 /* layout type */ + \
  377. 1 /* maxcount */ + \
  378. 1 /* bitmap size */ + \
  379. 1 /* notification bitmap length */ + \
  380. 1 /* notification bitmap, word 0 */)
  381. #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
  382. 1 /* layout type */ + \
  383. 1 /* opaque devaddr4 length */ + \
  384. /* devaddr4 payload is read into page */ \
  385. 1 /* notification bitmap length */ + \
  386. 1 /* notification bitmap, word 0 */ + \
  387. 1 /* possible XDR padding */)
  388. #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
  389. encode_stateid_maxsz)
  390. #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
  391. decode_stateid_maxsz + \
  392. XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE) + 1)
  393. #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
  394. 2 /* offset */ + \
  395. 2 /* length */ + \
  396. 1 /* reclaim */ + \
  397. encode_stateid_maxsz + \
  398. 1 /* new offset (true) */ + \
  399. 2 /* last byte written */ + \
  400. 1 /* nt_timechanged (false) */ + \
  401. 1 /* layoutupdate4 layout type */ + \
  402. 1 /* layoutupdate4 opaqueue len */)
  403. /* the actual content of layoutupdate4 should
  404. be allocated by drivers and spliced in
  405. using xdr_write_pages */
  406. #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
  407. #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
  408. encode_stateid_maxsz + \
  409. 1 + \
  410. XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
  411. #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
  412. 1 + decode_stateid_maxsz)
  413. #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
  414. #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
  415. #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
  416. XDR_QUADLEN(NFS4_STATEID_SIZE))
  417. #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
  418. #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
  419. XDR_QUADLEN(NFS4_STATEID_SIZE))
  420. #define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
  421. #else /* CONFIG_NFS_V4_1 */
  422. #define encode_sequence_maxsz 0
  423. #define decode_sequence_maxsz 0
  424. #define encode_layoutreturn_maxsz 0
  425. #define decode_layoutreturn_maxsz 0
  426. #define encode_layoutget_maxsz 0
  427. #define decode_layoutget_maxsz 0
  428. #endif /* CONFIG_NFS_V4_1 */
  429. #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
  430. #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
  431. #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
  432. encode_sequence_maxsz + \
  433. encode_putfh_maxsz + \
  434. encode_read_maxsz)
  435. #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
  436. decode_sequence_maxsz + \
  437. decode_putfh_maxsz + \
  438. decode_read_maxsz)
  439. #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
  440. encode_sequence_maxsz + \
  441. encode_putfh_maxsz + \
  442. encode_readlink_maxsz)
  443. #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
  444. decode_sequence_maxsz + \
  445. decode_putfh_maxsz + \
  446. decode_readlink_maxsz)
  447. #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
  448. encode_sequence_maxsz + \
  449. encode_putfh_maxsz + \
  450. encode_readdir_maxsz)
  451. #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
  452. decode_sequence_maxsz + \
  453. decode_putfh_maxsz + \
  454. decode_readdir_maxsz)
  455. #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
  456. encode_sequence_maxsz + \
  457. encode_putfh_maxsz + \
  458. encode_write_maxsz + \
  459. encode_getattr_maxsz)
  460. #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
  461. decode_sequence_maxsz + \
  462. decode_putfh_maxsz + \
  463. decode_write_maxsz + \
  464. decode_getattr_maxsz)
  465. #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
  466. encode_sequence_maxsz + \
  467. encode_putfh_maxsz + \
  468. encode_commit_maxsz)
  469. #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
  470. decode_sequence_maxsz + \
  471. decode_putfh_maxsz + \
  472. decode_commit_maxsz)
  473. #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
  474. encode_sequence_maxsz + \
  475. encode_putfh_maxsz + \
  476. encode_open_maxsz + \
  477. encode_access_maxsz + \
  478. encode_getfh_maxsz + \
  479. encode_getattr_maxsz + \
  480. encode_layoutget_maxsz)
  481. #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
  482. decode_sequence_maxsz + \
  483. decode_putfh_maxsz + \
  484. decode_open_maxsz + \
  485. decode_access_maxsz + \
  486. decode_getfh_maxsz + \
  487. decode_getattr_maxsz + \
  488. decode_layoutget_maxsz)
  489. #define NFS4_enc_open_confirm_sz \
  490. (compound_encode_hdr_maxsz + \
  491. encode_putfh_maxsz + \
  492. encode_open_confirm_maxsz)
  493. #define NFS4_dec_open_confirm_sz \
  494. (compound_decode_hdr_maxsz + \
  495. decode_putfh_maxsz + \
  496. decode_open_confirm_maxsz)
  497. #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
  498. encode_sequence_maxsz + \
  499. encode_putfh_maxsz + \
  500. encode_open_maxsz + \
  501. encode_access_maxsz + \
  502. encode_getattr_maxsz + \
  503. encode_layoutget_maxsz)
  504. #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
  505. decode_sequence_maxsz + \
  506. decode_putfh_maxsz + \
  507. decode_open_maxsz + \
  508. decode_access_maxsz + \
  509. decode_getattr_maxsz + \
  510. decode_layoutget_maxsz)
  511. #define NFS4_enc_open_downgrade_sz \
  512. (compound_encode_hdr_maxsz + \
  513. encode_sequence_maxsz + \
  514. encode_putfh_maxsz + \
  515. encode_layoutreturn_maxsz + \
  516. encode_open_downgrade_maxsz)
  517. #define NFS4_dec_open_downgrade_sz \
  518. (compound_decode_hdr_maxsz + \
  519. decode_sequence_maxsz + \
  520. decode_putfh_maxsz + \
  521. decode_layoutreturn_maxsz + \
  522. decode_open_downgrade_maxsz)
  523. #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
  524. encode_sequence_maxsz + \
  525. encode_putfh_maxsz + \
  526. encode_layoutreturn_maxsz + \
  527. encode_close_maxsz + \
  528. encode_getattr_maxsz)
  529. #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
  530. decode_sequence_maxsz + \
  531. decode_putfh_maxsz + \
  532. decode_layoutreturn_maxsz + \
  533. decode_close_maxsz + \
  534. decode_getattr_maxsz)
  535. #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
  536. encode_sequence_maxsz + \
  537. encode_putfh_maxsz + \
  538. encode_setattr_maxsz + \
  539. encode_getattr_maxsz)
  540. #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
  541. decode_sequence_maxsz + \
  542. decode_putfh_maxsz + \
  543. decode_setattr_maxsz + \
  544. decode_getattr_maxsz)
  545. #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
  546. encode_sequence_maxsz + \
  547. encode_putfh_maxsz + \
  548. encode_fsinfo_maxsz)
  549. #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
  550. decode_sequence_maxsz + \
  551. decode_putfh_maxsz + \
  552. decode_fsinfo_maxsz)
  553. #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
  554. encode_renew_maxsz)
  555. #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
  556. decode_renew_maxsz)
  557. #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
  558. encode_setclientid_maxsz)
  559. #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
  560. decode_setclientid_maxsz)
  561. #define NFS4_enc_setclientid_confirm_sz \
  562. (compound_encode_hdr_maxsz + \
  563. encode_setclientid_confirm_maxsz)
  564. #define NFS4_dec_setclientid_confirm_sz \
  565. (compound_decode_hdr_maxsz + \
  566. decode_setclientid_confirm_maxsz)
  567. #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
  568. encode_sequence_maxsz + \
  569. encode_putfh_maxsz + \
  570. encode_lock_maxsz)
  571. #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
  572. decode_sequence_maxsz + \
  573. decode_putfh_maxsz + \
  574. decode_lock_maxsz)
  575. #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
  576. encode_sequence_maxsz + \
  577. encode_putfh_maxsz + \
  578. encode_lockt_maxsz)
  579. #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
  580. decode_sequence_maxsz + \
  581. decode_putfh_maxsz + \
  582. decode_lockt_maxsz)
  583. #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
  584. encode_sequence_maxsz + \
  585. encode_putfh_maxsz + \
  586. encode_locku_maxsz)
  587. #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
  588. decode_sequence_maxsz + \
  589. decode_putfh_maxsz + \
  590. decode_locku_maxsz)
  591. #define NFS4_enc_release_lockowner_sz \
  592. (compound_encode_hdr_maxsz + \
  593. encode_lockowner_maxsz)
  594. #define NFS4_dec_release_lockowner_sz \
  595. (compound_decode_hdr_maxsz + \
  596. decode_lockowner_maxsz)
  597. #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
  598. encode_sequence_maxsz + \
  599. encode_putfh_maxsz + \
  600. encode_access_maxsz + \
  601. encode_getattr_maxsz)
  602. #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
  603. decode_sequence_maxsz + \
  604. decode_putfh_maxsz + \
  605. decode_access_maxsz + \
  606. decode_getattr_maxsz)
  607. #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
  608. encode_sequence_maxsz + \
  609. encode_putfh_maxsz + \
  610. encode_getattr_maxsz + \
  611. encode_renew_maxsz)
  612. #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
  613. decode_sequence_maxsz + \
  614. decode_putfh_maxsz + \
  615. decode_getattr_maxsz + \
  616. decode_renew_maxsz)
  617. #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
  618. encode_sequence_maxsz + \
  619. encode_putfh_maxsz + \
  620. encode_lookup_maxsz + \
  621. encode_getattr_maxsz + \
  622. encode_getfh_maxsz)
  623. #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
  624. decode_sequence_maxsz + \
  625. decode_putfh_maxsz + \
  626. decode_lookup_maxsz + \
  627. decode_getattr_maxsz + \
  628. decode_getfh_maxsz)
  629. #define NFS4_enc_lookupp_sz (compound_encode_hdr_maxsz + \
  630. encode_sequence_maxsz + \
  631. encode_putfh_maxsz + \
  632. encode_lookupp_maxsz + \
  633. encode_getattr_maxsz + \
  634. encode_getfh_maxsz)
  635. #define NFS4_dec_lookupp_sz (compound_decode_hdr_maxsz + \
  636. decode_sequence_maxsz + \
  637. decode_putfh_maxsz + \
  638. decode_lookupp_maxsz + \
  639. decode_getattr_maxsz + \
  640. decode_getfh_maxsz)
  641. #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
  642. encode_sequence_maxsz + \
  643. encode_putrootfh_maxsz + \
  644. encode_getattr_maxsz + \
  645. encode_getfh_maxsz)
  646. #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
  647. decode_sequence_maxsz + \
  648. decode_putrootfh_maxsz + \
  649. decode_getattr_maxsz + \
  650. decode_getfh_maxsz)
  651. #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
  652. encode_sequence_maxsz + \
  653. encode_putfh_maxsz + \
  654. encode_remove_maxsz)
  655. #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
  656. decode_sequence_maxsz + \
  657. decode_putfh_maxsz + \
  658. decode_remove_maxsz)
  659. #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
  660. encode_sequence_maxsz + \
  661. encode_putfh_maxsz + \
  662. encode_savefh_maxsz + \
  663. encode_putfh_maxsz + \
  664. encode_rename_maxsz)
  665. #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
  666. decode_sequence_maxsz + \
  667. decode_putfh_maxsz + \
  668. decode_savefh_maxsz + \
  669. decode_putfh_maxsz + \
  670. decode_rename_maxsz)
  671. #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
  672. encode_sequence_maxsz + \
  673. encode_putfh_maxsz + \
  674. encode_savefh_maxsz + \
  675. encode_putfh_maxsz + \
  676. encode_link_maxsz + \
  677. encode_restorefh_maxsz + \
  678. encode_getattr_maxsz)
  679. #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
  680. decode_sequence_maxsz + \
  681. decode_putfh_maxsz + \
  682. decode_savefh_maxsz + \
  683. decode_putfh_maxsz + \
  684. decode_link_maxsz + \
  685. decode_restorefh_maxsz + \
  686. decode_getattr_maxsz)
  687. #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
  688. encode_sequence_maxsz + \
  689. encode_putfh_maxsz + \
  690. encode_symlink_maxsz + \
  691. encode_getattr_maxsz + \
  692. encode_getfh_maxsz)
  693. #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
  694. decode_sequence_maxsz + \
  695. decode_putfh_maxsz + \
  696. decode_symlink_maxsz + \
  697. decode_getattr_maxsz + \
  698. decode_getfh_maxsz)
  699. #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
  700. encode_sequence_maxsz + \
  701. encode_putfh_maxsz + \
  702. encode_create_maxsz + \
  703. encode_getfh_maxsz + \
  704. encode_getattr_maxsz)
  705. #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
  706. decode_sequence_maxsz + \
  707. decode_putfh_maxsz + \
  708. decode_create_maxsz + \
  709. decode_getfh_maxsz + \
  710. decode_getattr_maxsz)
  711. #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
  712. encode_sequence_maxsz + \
  713. encode_putfh_maxsz + \
  714. encode_getattr_maxsz)
  715. #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
  716. decode_sequence_maxsz + \
  717. decode_putfh_maxsz + \
  718. decode_getattr_maxsz)
  719. #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
  720. encode_sequence_maxsz + \
  721. encode_putfh_maxsz + \
  722. encode_statfs_maxsz)
  723. #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
  724. decode_sequence_maxsz + \
  725. decode_putfh_maxsz + \
  726. decode_statfs_maxsz)
  727. #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
  728. encode_sequence_maxsz + \
  729. encode_putfh_maxsz + \
  730. encode_getattr_maxsz)
  731. #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
  732. decode_sequence_maxsz + \
  733. decode_putfh_maxsz + \
  734. decode_getattr_maxsz)
  735. #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
  736. encode_sequence_maxsz + \
  737. encode_putfh_maxsz + \
  738. encode_layoutreturn_maxsz + \
  739. encode_delegreturn_maxsz + \
  740. encode_getattr_maxsz)
  741. #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
  742. decode_sequence_maxsz + \
  743. decode_putfh_maxsz + \
  744. decode_layoutreturn_maxsz + \
  745. decode_delegreturn_maxsz + \
  746. decode_getattr_maxsz)
  747. #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
  748. encode_sequence_maxsz + \
  749. encode_putfh_maxsz + \
  750. encode_getacl_maxsz)
  751. #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
  752. decode_sequence_maxsz + \
  753. decode_putfh_maxsz + \
  754. decode_getacl_maxsz)
  755. #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
  756. encode_sequence_maxsz + \
  757. encode_putfh_maxsz + \
  758. encode_setacl_maxsz)
  759. #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
  760. decode_sequence_maxsz + \
  761. decode_putfh_maxsz + \
  762. decode_setacl_maxsz)
  763. #define NFS4_enc_fs_locations_sz \
  764. (compound_encode_hdr_maxsz + \
  765. encode_sequence_maxsz + \
  766. encode_putfh_maxsz + \
  767. encode_lookup_maxsz + \
  768. encode_fs_locations_maxsz + \
  769. encode_renew_maxsz)
  770. #define NFS4_dec_fs_locations_sz \
  771. (compound_decode_hdr_maxsz + \
  772. decode_sequence_maxsz + \
  773. decode_putfh_maxsz + \
  774. decode_lookup_maxsz + \
  775. decode_fs_locations_maxsz + \
  776. decode_renew_maxsz)
  777. #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
  778. encode_sequence_maxsz + \
  779. encode_putfh_maxsz + \
  780. encode_secinfo_maxsz)
  781. #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
  782. decode_sequence_maxsz + \
  783. decode_putfh_maxsz + \
  784. decode_secinfo_maxsz)
  785. #define NFS4_enc_fsid_present_sz \
  786. (compound_encode_hdr_maxsz + \
  787. encode_sequence_maxsz + \
  788. encode_putfh_maxsz + \
  789. encode_getfh_maxsz + \
  790. encode_renew_maxsz)
  791. #define NFS4_dec_fsid_present_sz \
  792. (compound_decode_hdr_maxsz + \
  793. decode_sequence_maxsz + \
  794. decode_putfh_maxsz + \
  795. decode_getfh_maxsz + \
  796. decode_renew_maxsz)
  797. #if defined(CONFIG_NFS_V4_1)
  798. #define NFS4_enc_bind_conn_to_session_sz \
  799. (compound_encode_hdr_maxsz + \
  800. encode_bind_conn_to_session_maxsz)
  801. #define NFS4_dec_bind_conn_to_session_sz \
  802. (compound_decode_hdr_maxsz + \
  803. decode_bind_conn_to_session_maxsz)
  804. #define NFS4_enc_exchange_id_sz \
  805. (compound_encode_hdr_maxsz + \
  806. encode_exchange_id_maxsz)
  807. #define NFS4_dec_exchange_id_sz \
  808. (compound_decode_hdr_maxsz + \
  809. decode_exchange_id_maxsz)
  810. #define NFS4_enc_create_session_sz \
  811. (compound_encode_hdr_maxsz + \
  812. encode_create_session_maxsz)
  813. #define NFS4_dec_create_session_sz \
  814. (compound_decode_hdr_maxsz + \
  815. decode_create_session_maxsz)
  816. #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
  817. encode_destroy_session_maxsz)
  818. #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
  819. decode_destroy_session_maxsz)
  820. #define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
  821. encode_destroy_clientid_maxsz)
  822. #define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
  823. decode_destroy_clientid_maxsz)
  824. #define NFS4_enc_sequence_sz \
  825. (compound_decode_hdr_maxsz + \
  826. encode_sequence_maxsz)
  827. #define NFS4_dec_sequence_sz \
  828. (compound_decode_hdr_maxsz + \
  829. decode_sequence_maxsz)
  830. #endif
  831. #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
  832. encode_sequence_maxsz + \
  833. encode_putrootfh_maxsz + \
  834. encode_fsinfo_maxsz)
  835. #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
  836. decode_sequence_maxsz + \
  837. decode_putrootfh_maxsz + \
  838. decode_fsinfo_maxsz)
  839. #if defined(CONFIG_NFS_V4_1)
  840. #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
  841. encode_sequence_maxsz + \
  842. encode_reclaim_complete_maxsz)
  843. #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
  844. decode_sequence_maxsz + \
  845. decode_reclaim_complete_maxsz)
  846. #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
  847. encode_sequence_maxsz +\
  848. encode_getdeviceinfo_maxsz)
  849. #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
  850. decode_sequence_maxsz + \
  851. decode_getdeviceinfo_maxsz)
  852. #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
  853. encode_sequence_maxsz + \
  854. encode_putfh_maxsz + \
  855. encode_layoutget_maxsz)
  856. #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
  857. decode_sequence_maxsz + \
  858. decode_putfh_maxsz + \
  859. decode_layoutget_maxsz)
  860. #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
  861. encode_sequence_maxsz +\
  862. encode_putfh_maxsz + \
  863. encode_layoutcommit_maxsz + \
  864. encode_getattr_maxsz)
  865. #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
  866. decode_sequence_maxsz + \
  867. decode_putfh_maxsz + \
  868. decode_layoutcommit_maxsz + \
  869. decode_getattr_maxsz)
  870. #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
  871. encode_sequence_maxsz + \
  872. encode_putfh_maxsz + \
  873. encode_layoutreturn_maxsz)
  874. #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
  875. decode_sequence_maxsz + \
  876. decode_putfh_maxsz + \
  877. decode_layoutreturn_maxsz)
  878. #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
  879. encode_sequence_maxsz + \
  880. encode_putrootfh_maxsz +\
  881. encode_secinfo_no_name_maxsz)
  882. #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
  883. decode_sequence_maxsz + \
  884. decode_putrootfh_maxsz + \
  885. decode_secinfo_no_name_maxsz)
  886. #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
  887. encode_sequence_maxsz + \
  888. encode_test_stateid_maxsz)
  889. #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
  890. decode_sequence_maxsz + \
  891. decode_test_stateid_maxsz)
  892. #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
  893. encode_sequence_maxsz + \
  894. encode_free_stateid_maxsz)
  895. #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
  896. decode_sequence_maxsz + \
  897. decode_free_stateid_maxsz)
  898. const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
  899. compound_encode_hdr_maxsz +
  900. encode_sequence_maxsz +
  901. encode_putfh_maxsz +
  902. encode_getattr_maxsz) *
  903. XDR_UNIT);
  904. const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
  905. compound_decode_hdr_maxsz +
  906. decode_sequence_maxsz +
  907. decode_putfh_maxsz) *
  908. XDR_UNIT);
  909. const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
  910. compound_decode_hdr_maxsz +
  911. decode_sequence_maxsz) *
  912. XDR_UNIT);
  913. EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
  914. #endif /* CONFIG_NFS_V4_1 */
  915. static const umode_t nfs_type2fmt[] = {
  916. [NF4BAD] = 0,
  917. [NF4REG] = S_IFREG,
  918. [NF4DIR] = S_IFDIR,
  919. [NF4BLK] = S_IFBLK,
  920. [NF4CHR] = S_IFCHR,
  921. [NF4LNK] = S_IFLNK,
  922. [NF4SOCK] = S_IFSOCK,
  923. [NF4FIFO] = S_IFIFO,
  924. [NF4ATTRDIR] = 0,
  925. [NF4NAMEDATTR] = 0,
  926. };
  927. struct compound_hdr {
  928. int32_t status;
  929. uint32_t nops;
  930. __be32 * nops_p;
  931. uint32_t taglen;
  932. char * tag;
  933. uint32_t replen; /* expected reply words */
  934. u32 minorversion;
  935. };
  936. static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
  937. {
  938. __be32 *p = xdr_reserve_space(xdr, nbytes);
  939. BUG_ON(!p);
  940. return p;
  941. }
  942. static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
  943. {
  944. WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0);
  945. }
  946. static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
  947. {
  948. WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0);
  949. }
  950. static void encode_uint32(struct xdr_stream *xdr, u32 n)
  951. {
  952. WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0);
  953. }
  954. static void encode_uint64(struct xdr_stream *xdr, u64 n)
  955. {
  956. WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0);
  957. }
  958. static ssize_t xdr_encode_bitmap4(struct xdr_stream *xdr,
  959. const __u32 *bitmap, size_t len)
  960. {
  961. ssize_t ret;
  962. /* Trim empty words */
  963. while (len > 0 && bitmap[len-1] == 0)
  964. len--;
  965. ret = xdr_stream_encode_uint32_array(xdr, bitmap, len);
  966. if (WARN_ON_ONCE(ret < 0))
  967. return ret;
  968. return len;
  969. }
  970. static size_t mask_bitmap4(const __u32 *bitmap, const __u32 *mask,
  971. __u32 *res, size_t len)
  972. {
  973. size_t i;
  974. __u32 tmp;
  975. while (len > 0 && (bitmap[len-1] == 0 || mask[len-1] == 0))
  976. len--;
  977. for (i = len; i-- > 0;) {
  978. tmp = bitmap[i] & mask[i];
  979. res[i] = tmp;
  980. }
  981. return len;
  982. }
  983. static void encode_nfs4_seqid(struct xdr_stream *xdr,
  984. const struct nfs_seqid *seqid)
  985. {
  986. if (seqid != NULL)
  987. encode_uint32(xdr, seqid->sequence->counter);
  988. else
  989. encode_uint32(xdr, 0);
  990. }
  991. static void encode_compound_hdr(struct xdr_stream *xdr,
  992. struct rpc_rqst *req,
  993. struct compound_hdr *hdr)
  994. {
  995. __be32 *p;
  996. /* initialize running count of expected bytes in reply.
  997. * NOTE: the replied tag SHOULD be the same is the one sent,
  998. * but this is not required as a MUST for the server to do so. */
  999. hdr->replen = 3 + hdr->taglen;
  1000. WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
  1001. encode_string(xdr, hdr->taglen, hdr->tag);
  1002. p = reserve_space(xdr, 8);
  1003. *p++ = cpu_to_be32(hdr->minorversion);
  1004. hdr->nops_p = p;
  1005. *p = cpu_to_be32(hdr->nops);
  1006. }
  1007. static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
  1008. uint32_t replen,
  1009. struct compound_hdr *hdr)
  1010. {
  1011. encode_uint32(xdr, op);
  1012. hdr->nops++;
  1013. hdr->replen += replen;
  1014. }
  1015. static void encode_nops(struct compound_hdr *hdr)
  1016. {
  1017. WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
  1018. *hdr->nops_p = htonl(hdr->nops);
  1019. }
  1020. static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
  1021. {
  1022. encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
  1023. }
  1024. static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
  1025. {
  1026. encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
  1027. }
  1028. static __be32 *
  1029. xdr_encode_nfstime4(__be32 *p, const struct timespec64 *t)
  1030. {
  1031. p = xdr_encode_hyper(p, t->tv_sec);
  1032. *p++ = cpu_to_be32(t->tv_nsec);
  1033. return p;
  1034. }
  1035. static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
  1036. const struct nfs4_label *label,
  1037. const umode_t *umask,
  1038. const struct nfs_server *server,
  1039. const uint32_t attrmask[])
  1040. {
  1041. char owner_name[IDMAP_NAMESZ];
  1042. char owner_group[IDMAP_NAMESZ];
  1043. int owner_namelen = 0;
  1044. int owner_grouplen = 0;
  1045. __be32 *p;
  1046. uint32_t len = 0;
  1047. uint32_t bmval[3] = { 0 };
  1048. /*
  1049. * We reserve enough space to write the entire attribute buffer at once.
  1050. */
  1051. if ((iap->ia_valid & ATTR_SIZE) && (attrmask[0] & FATTR4_WORD0_SIZE)) {
  1052. bmval[0] |= FATTR4_WORD0_SIZE;
  1053. len += 8;
  1054. }
  1055. if (iap->ia_valid & ATTR_MODE) {
  1056. if (umask && (attrmask[2] & FATTR4_WORD2_MODE_UMASK)) {
  1057. bmval[2] |= FATTR4_WORD2_MODE_UMASK;
  1058. len += 8;
  1059. } else if (attrmask[1] & FATTR4_WORD1_MODE) {
  1060. bmval[1] |= FATTR4_WORD1_MODE;
  1061. len += 4;
  1062. }
  1063. }
  1064. if ((iap->ia_valid & ATTR_UID) && (attrmask[1] & FATTR4_WORD1_OWNER)) {
  1065. owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
  1066. if (owner_namelen < 0) {
  1067. dprintk("nfs: couldn't resolve uid %d to string\n",
  1068. from_kuid(&init_user_ns, iap->ia_uid));
  1069. /* XXX */
  1070. strcpy(owner_name, "nobody");
  1071. owner_namelen = sizeof("nobody") - 1;
  1072. /* goto out; */
  1073. }
  1074. bmval[1] |= FATTR4_WORD1_OWNER;
  1075. len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
  1076. }
  1077. if ((iap->ia_valid & ATTR_GID) &&
  1078. (attrmask[1] & FATTR4_WORD1_OWNER_GROUP)) {
  1079. owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
  1080. if (owner_grouplen < 0) {
  1081. dprintk("nfs: couldn't resolve gid %d to string\n",
  1082. from_kgid(&init_user_ns, iap->ia_gid));
  1083. strcpy(owner_group, "nobody");
  1084. owner_grouplen = sizeof("nobody") - 1;
  1085. /* goto out; */
  1086. }
  1087. bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
  1088. len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
  1089. }
  1090. if (attrmask[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
  1091. if (iap->ia_valid & ATTR_ATIME_SET) {
  1092. bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
  1093. len += 4 + (nfstime4_maxsz << 2);
  1094. } else if (iap->ia_valid & ATTR_ATIME) {
  1095. bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
  1096. len += 4;
  1097. }
  1098. }
  1099. if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
  1100. if (iap->ia_valid & ATTR_MTIME_SET) {
  1101. bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
  1102. len += 4 + (nfstime4_maxsz << 2);
  1103. } else if (iap->ia_valid & ATTR_MTIME) {
  1104. bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
  1105. len += 4;
  1106. }
  1107. }
  1108. if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) {
  1109. len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
  1110. bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
  1111. }
  1112. xdr_encode_bitmap4(xdr, bmval, ARRAY_SIZE(bmval));
  1113. xdr_stream_encode_opaque_inline(xdr, (void **)&p, len);
  1114. if (bmval[0] & FATTR4_WORD0_SIZE)
  1115. p = xdr_encode_hyper(p, iap->ia_size);
  1116. if (bmval[1] & FATTR4_WORD1_MODE)
  1117. *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
  1118. if (bmval[1] & FATTR4_WORD1_OWNER)
  1119. p = xdr_encode_opaque(p, owner_name, owner_namelen);
  1120. if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
  1121. p = xdr_encode_opaque(p, owner_group, owner_grouplen);
  1122. if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
  1123. if (iap->ia_valid & ATTR_ATIME_SET) {
  1124. *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
  1125. p = xdr_encode_nfstime4(p, &iap->ia_atime);
  1126. } else
  1127. *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
  1128. }
  1129. if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
  1130. if (iap->ia_valid & ATTR_MTIME_SET) {
  1131. *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
  1132. p = xdr_encode_nfstime4(p, &iap->ia_mtime);
  1133. } else
  1134. *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
  1135. }
  1136. if (label && (bmval[2] & FATTR4_WORD2_SECURITY_LABEL)) {
  1137. *p++ = cpu_to_be32(label->lfs);
  1138. *p++ = cpu_to_be32(label->pi);
  1139. *p++ = cpu_to_be32(label->len);
  1140. p = xdr_encode_opaque_fixed(p, label->label, label->len);
  1141. }
  1142. if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
  1143. *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
  1144. *p++ = cpu_to_be32(*umask);
  1145. }
  1146. /* out: */
  1147. }
  1148. static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
  1149. {
  1150. encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
  1151. encode_uint32(xdr, access);
  1152. }
  1153. static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
  1154. {
  1155. encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
  1156. encode_nfs4_seqid(xdr, arg->seqid);
  1157. encode_nfs4_stateid(xdr, &arg->stateid);
  1158. }
  1159. static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
  1160. {
  1161. __be32 *p;
  1162. encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
  1163. p = reserve_space(xdr, 12);
  1164. p = xdr_encode_hyper(p, args->offset);
  1165. *p = cpu_to_be32(args->count);
  1166. }
  1167. static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
  1168. {
  1169. __be32 *p;
  1170. encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
  1171. encode_uint32(xdr, create->ftype);
  1172. switch (create->ftype) {
  1173. case NF4LNK:
  1174. p = reserve_space(xdr, 4);
  1175. *p = cpu_to_be32(create->u.symlink.len);
  1176. xdr_write_pages(xdr, create->u.symlink.pages, 0,
  1177. create->u.symlink.len);
  1178. xdr->buf->flags |= XDRBUF_WRITE;
  1179. break;
  1180. case NF4BLK: case NF4CHR:
  1181. p = reserve_space(xdr, 8);
  1182. *p++ = cpu_to_be32(create->u.device.specdata1);
  1183. *p = cpu_to_be32(create->u.device.specdata2);
  1184. break;
  1185. default:
  1186. break;
  1187. }
  1188. encode_string(xdr, create->name->len, create->name->name);
  1189. encode_attrs(xdr, create->attrs, create->label, &create->umask,
  1190. create->server, create->server->attr_bitmask);
  1191. }
  1192. static void encode_getattr(struct xdr_stream *xdr,
  1193. const __u32 *bitmap, const __u32 *mask, size_t len,
  1194. struct compound_hdr *hdr)
  1195. {
  1196. __u32 masked_bitmap[nfs4_fattr_bitmap_maxsz];
  1197. encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
  1198. if (mask) {
  1199. if (WARN_ON_ONCE(len > ARRAY_SIZE(masked_bitmap)))
  1200. len = ARRAY_SIZE(masked_bitmap);
  1201. len = mask_bitmap4(bitmap, mask, masked_bitmap, len);
  1202. bitmap = masked_bitmap;
  1203. }
  1204. xdr_encode_bitmap4(xdr, bitmap, len);
  1205. }
  1206. static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
  1207. {
  1208. encode_getattr(xdr, nfs4_fattr_bitmap, bitmask,
  1209. ARRAY_SIZE(nfs4_fattr_bitmap), hdr);
  1210. }
  1211. static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
  1212. const u32 *open_bitmap,
  1213. struct compound_hdr *hdr)
  1214. {
  1215. encode_getattr(xdr, open_bitmap, bitmask, 3, hdr);
  1216. }
  1217. static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
  1218. {
  1219. encode_getattr(xdr, nfs4_fsinfo_bitmap, bitmask,
  1220. ARRAY_SIZE(nfs4_fsinfo_bitmap), hdr);
  1221. }
  1222. static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
  1223. {
  1224. encode_getattr(xdr, nfs4_fs_locations_bitmap, bitmask,
  1225. ARRAY_SIZE(nfs4_fs_locations_bitmap), hdr);
  1226. }
  1227. static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
  1228. {
  1229. encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
  1230. }
  1231. static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
  1232. {
  1233. encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
  1234. encode_string(xdr, name->len, name->name);
  1235. }
  1236. static inline int nfs4_lock_type(struct file_lock *fl, int block)
  1237. {
  1238. if (fl->fl_type == F_RDLCK)
  1239. return block ? NFS4_READW_LT : NFS4_READ_LT;
  1240. return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
  1241. }
  1242. static inline uint64_t nfs4_lock_length(struct file_lock *fl)
  1243. {
  1244. if (fl->fl_end == OFFSET_MAX)
  1245. return ~(uint64_t)0;
  1246. return fl->fl_end - fl->fl_start + 1;
  1247. }
  1248. static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
  1249. {
  1250. __be32 *p;
  1251. p = reserve_space(xdr, 32);
  1252. p = xdr_encode_hyper(p, lowner->clientid);
  1253. *p++ = cpu_to_be32(20);
  1254. p = xdr_encode_opaque_fixed(p, "lock id:", 8);
  1255. *p++ = cpu_to_be32(lowner->s_dev);
  1256. xdr_encode_hyper(p, lowner->id);
  1257. }
  1258. /*
  1259. * opcode,type,reclaim,offset,length,new_lock_owner = 32
  1260. * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
  1261. */
  1262. static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
  1263. {
  1264. __be32 *p;
  1265. encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
  1266. p = reserve_space(xdr, 28);
  1267. *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
  1268. *p++ = cpu_to_be32(args->reclaim);
  1269. p = xdr_encode_hyper(p, args->fl->fl_start);
  1270. p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
  1271. *p = cpu_to_be32(args->new_lock_owner);
  1272. if (args->new_lock_owner){
  1273. encode_nfs4_seqid(xdr, args->open_seqid);
  1274. encode_nfs4_stateid(xdr, &args->open_stateid);
  1275. encode_nfs4_seqid(xdr, args->lock_seqid);
  1276. encode_lockowner(xdr, &args->lock_owner);
  1277. }
  1278. else {
  1279. encode_nfs4_stateid(xdr, &args->lock_stateid);
  1280. encode_nfs4_seqid(xdr, args->lock_seqid);
  1281. }
  1282. }
  1283. static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
  1284. {
  1285. __be32 *p;
  1286. encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
  1287. p = reserve_space(xdr, 20);
  1288. *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
  1289. p = xdr_encode_hyper(p, args->fl->fl_start);
  1290. p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
  1291. encode_lockowner(xdr, &args->lock_owner);
  1292. }
  1293. static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
  1294. {
  1295. __be32 *p;
  1296. encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
  1297. encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
  1298. encode_nfs4_seqid(xdr, args->seqid);
  1299. encode_nfs4_stateid(xdr, &args->stateid);
  1300. p = reserve_space(xdr, 16);
  1301. p = xdr_encode_hyper(p, args->fl->fl_start);
  1302. xdr_encode_hyper(p, nfs4_lock_length(args->fl));
  1303. }
  1304. static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
  1305. {
  1306. encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
  1307. encode_lockowner(xdr, lowner);
  1308. }
  1309. static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
  1310. {
  1311. encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
  1312. encode_string(xdr, name->len, name->name);
  1313. }
  1314. static void encode_lookupp(struct xdr_stream *xdr, struct compound_hdr *hdr)
  1315. {
  1316. encode_op_hdr(xdr, OP_LOOKUPP, decode_lookupp_maxsz, hdr);
  1317. }
  1318. static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
  1319. {
  1320. __be32 *p;
  1321. p = reserve_space(xdr, 8);
  1322. *p++ = cpu_to_be32(share_access);
  1323. *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
  1324. }
  1325. static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
  1326. {
  1327. __be32 *p;
  1328. /*
  1329. * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
  1330. * owner 4 = 32
  1331. */
  1332. encode_nfs4_seqid(xdr, arg->seqid);
  1333. encode_share_access(xdr, arg->share_access);
  1334. p = reserve_space(xdr, 36);
  1335. p = xdr_encode_hyper(p, arg->clientid);
  1336. *p++ = cpu_to_be32(24);
  1337. p = xdr_encode_opaque_fixed(p, "open id:", 8);
  1338. *p++ = cpu_to_be32(arg->server->s_dev);
  1339. *p++ = cpu_to_be32(arg->id.uniquifier);
  1340. xdr_encode_hyper(p, arg->id.create_time);
  1341. }
  1342. static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
  1343. {
  1344. __be32 *p;
  1345. p = reserve_space(xdr, 4);
  1346. switch(arg->createmode) {
  1347. case NFS4_CREATE_UNCHECKED:
  1348. *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
  1349. encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
  1350. arg->server, arg->server->attr_bitmask);
  1351. break;
  1352. case NFS4_CREATE_GUARDED:
  1353. *p = cpu_to_be32(NFS4_CREATE_GUARDED);
  1354. encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
  1355. arg->server, arg->server->attr_bitmask);
  1356. break;
  1357. case NFS4_CREATE_EXCLUSIVE:
  1358. *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
  1359. encode_nfs4_verifier(xdr, &arg->u.verifier);
  1360. break;
  1361. case NFS4_CREATE_EXCLUSIVE4_1:
  1362. *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
  1363. encode_nfs4_verifier(xdr, &arg->u.verifier);
  1364. encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
  1365. arg->server, arg->server->exclcreat_bitmask);
  1366. }
  1367. }
  1368. static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
  1369. {
  1370. __be32 *p;
  1371. p = reserve_space(xdr, 4);
  1372. switch (arg->open_flags & O_CREAT) {
  1373. case 0:
  1374. *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
  1375. break;
  1376. default:
  1377. *p = cpu_to_be32(NFS4_OPEN_CREATE);
  1378. encode_createmode(xdr, arg);
  1379. }
  1380. }
  1381. static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
  1382. {
  1383. __be32 *p;
  1384. p = reserve_space(xdr, 4);
  1385. switch (delegation_type) {
  1386. case 0:
  1387. *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
  1388. break;
  1389. case FMODE_READ:
  1390. *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
  1391. break;
  1392. case FMODE_WRITE|FMODE_READ:
  1393. *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
  1394. break;
  1395. default:
  1396. BUG();
  1397. }
  1398. }
  1399. static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
  1400. {
  1401. __be32 *p;
  1402. p = reserve_space(xdr, 4);
  1403. *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
  1404. encode_string(xdr, name->len, name->name);
  1405. }
  1406. static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
  1407. {
  1408. __be32 *p;
  1409. p = reserve_space(xdr, 4);
  1410. *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
  1411. encode_delegation_type(xdr, type);
  1412. }
  1413. static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
  1414. {
  1415. __be32 *p;
  1416. p = reserve_space(xdr, 4);
  1417. *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
  1418. encode_nfs4_stateid(xdr, stateid);
  1419. encode_string(xdr, name->len, name->name);
  1420. }
  1421. static inline void encode_claim_fh(struct xdr_stream *xdr)
  1422. {
  1423. __be32 *p;
  1424. p = reserve_space(xdr, 4);
  1425. *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
  1426. }
  1427. static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
  1428. {
  1429. __be32 *p;
  1430. p = reserve_space(xdr, 4);
  1431. *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
  1432. encode_nfs4_stateid(xdr, stateid);
  1433. }
  1434. static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
  1435. {
  1436. encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
  1437. encode_openhdr(xdr, arg);
  1438. encode_opentype(xdr, arg);
  1439. switch (arg->claim) {
  1440. case NFS4_OPEN_CLAIM_NULL:
  1441. encode_claim_null(xdr, arg->name);
  1442. break;
  1443. case NFS4_OPEN_CLAIM_PREVIOUS:
  1444. encode_claim_previous(xdr, arg->u.delegation_type);
  1445. break;
  1446. case NFS4_OPEN_CLAIM_DELEGATE_CUR:
  1447. encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
  1448. break;
  1449. case NFS4_OPEN_CLAIM_FH:
  1450. encode_claim_fh(xdr);
  1451. break;
  1452. case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
  1453. encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
  1454. break;
  1455. default:
  1456. BUG();
  1457. }
  1458. }
  1459. static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
  1460. {
  1461. encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
  1462. encode_nfs4_stateid(xdr, arg->stateid);
  1463. encode_nfs4_seqid(xdr, arg->seqid);
  1464. }
  1465. static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
  1466. {
  1467. encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
  1468. encode_nfs4_stateid(xdr, &arg->stateid);
  1469. encode_nfs4_seqid(xdr, arg->seqid);
  1470. encode_share_access(xdr, arg->share_access);
  1471. }
  1472. static void
  1473. encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
  1474. {
  1475. encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
  1476. encode_string(xdr, fh->size, fh->data);
  1477. }
  1478. static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
  1479. {
  1480. encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
  1481. }
  1482. static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
  1483. struct compound_hdr *hdr)
  1484. {
  1485. __be32 *p;
  1486. encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
  1487. encode_nfs4_stateid(xdr, &args->stateid);
  1488. p = reserve_space(xdr, 12);
  1489. p = xdr_encode_hyper(p, args->offset);
  1490. *p = cpu_to_be32(args->count);
  1491. }
  1492. static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
  1493. {
  1494. uint32_t attrs[3] = {
  1495. FATTR4_WORD0_RDATTR_ERROR,
  1496. FATTR4_WORD1_MOUNTED_ON_FILEID,
  1497. };
  1498. uint32_t dircount = readdir->count >> 1;
  1499. __be32 *p, verf[2];
  1500. uint32_t attrlen = 0;
  1501. unsigned int i;
  1502. if (readdir->plus) {
  1503. attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
  1504. FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
  1505. attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
  1506. FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
  1507. FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
  1508. FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
  1509. attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
  1510. dircount >>= 1;
  1511. }
  1512. /* Use mounted_on_fileid only if the server supports it */
  1513. if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
  1514. attrs[0] |= FATTR4_WORD0_FILEID;
  1515. for (i = 0; i < ARRAY_SIZE(attrs); i++) {
  1516. attrs[i] &= readdir->bitmask[i];
  1517. if (attrs[i] != 0)
  1518. attrlen = i+1;
  1519. }
  1520. encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
  1521. encode_uint64(xdr, readdir->cookie);
  1522. encode_nfs4_verifier(xdr, &readdir->verifier);
  1523. p = reserve_space(xdr, 12 + (attrlen << 2));
  1524. *p++ = cpu_to_be32(dircount);
  1525. *p++ = cpu_to_be32(readdir->count);
  1526. *p++ = cpu_to_be32(attrlen);
  1527. for (i = 0; i < attrlen; i++)
  1528. *p++ = cpu_to_be32(attrs[i]);
  1529. memcpy(verf, readdir->verifier.data, sizeof(verf));
  1530. dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
  1531. __func__,
  1532. (unsigned long long)readdir->cookie,
  1533. verf[0], verf[1],
  1534. attrs[0] & readdir->bitmask[0],
  1535. attrs[1] & readdir->bitmask[1],
  1536. attrs[2] & readdir->bitmask[2]);
  1537. }
  1538. static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
  1539. {
  1540. encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
  1541. }
  1542. static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
  1543. {
  1544. encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
  1545. encode_string(xdr, name->len, name->name);
  1546. }
  1547. static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
  1548. {
  1549. encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
  1550. encode_string(xdr, oldname->len, oldname->name);
  1551. encode_string(xdr, newname->len, newname->name);
  1552. }
  1553. static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
  1554. struct compound_hdr *hdr)
  1555. {
  1556. encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
  1557. encode_uint64(xdr, clid);
  1558. }
  1559. static void
  1560. encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
  1561. {
  1562. encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
  1563. }
  1564. static void
  1565. encode_setacl(struct xdr_stream *xdr, const struct nfs_setaclargs *arg,
  1566. struct compound_hdr *hdr)
  1567. {
  1568. __be32 *p;
  1569. encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
  1570. encode_nfs4_stateid(xdr, &zero_stateid);
  1571. p = reserve_space(xdr, 2*4);
  1572. *p++ = cpu_to_be32(1);
  1573. *p = cpu_to_be32(FATTR4_WORD0_ACL);
  1574. p = reserve_space(xdr, 4);
  1575. *p = cpu_to_be32(arg->acl_len);
  1576. xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
  1577. }
  1578. static void
  1579. encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
  1580. {
  1581. encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
  1582. }
  1583. static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
  1584. {
  1585. encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
  1586. encode_nfs4_stateid(xdr, &arg->stateid);
  1587. encode_attrs(xdr, arg->iap, arg->label, NULL, server,
  1588. server->attr_bitmask);
  1589. }
  1590. static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
  1591. {
  1592. __be32 *p;
  1593. encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
  1594. encode_nfs4_verifier(xdr, setclientid->sc_verifier);
  1595. encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
  1596. setclientid->sc_clnt->cl_owner_id);
  1597. p = reserve_space(xdr, 4);
  1598. *p = cpu_to_be32(setclientid->sc_prog);
  1599. encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
  1600. encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
  1601. p = reserve_space(xdr, 4);
  1602. *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
  1603. }
  1604. static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
  1605. {
  1606. encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
  1607. decode_setclientid_confirm_maxsz, hdr);
  1608. encode_uint64(xdr, arg->clientid);
  1609. encode_nfs4_verifier(xdr, &arg->confirm);
  1610. }
  1611. static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
  1612. struct compound_hdr *hdr)
  1613. {
  1614. __be32 *p;
  1615. encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
  1616. encode_nfs4_stateid(xdr, &args->stateid);
  1617. p = reserve_space(xdr, 16);
  1618. p = xdr_encode_hyper(p, args->offset);
  1619. *p++ = cpu_to_be32(args->stable);
  1620. *p = cpu_to_be32(args->count);
  1621. xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
  1622. }
  1623. static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
  1624. {
  1625. encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
  1626. encode_nfs4_stateid(xdr, stateid);
  1627. }
  1628. static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
  1629. {
  1630. encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
  1631. encode_string(xdr, name->len, name->name);
  1632. }
  1633. #if defined(CONFIG_NFS_V4_1)
  1634. /* NFSv4.1 operations */
  1635. static void encode_bind_conn_to_session(struct xdr_stream *xdr,
  1636. const struct nfs41_bind_conn_to_session_args *args,
  1637. struct compound_hdr *hdr)
  1638. {
  1639. __be32 *p;
  1640. encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
  1641. decode_bind_conn_to_session_maxsz, hdr);
  1642. encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
  1643. p = xdr_reserve_space(xdr, 8);
  1644. *p++ = cpu_to_be32(args->dir);
  1645. *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
  1646. }
  1647. static void encode_op_map(struct xdr_stream *xdr, const struct nfs4_op_map *op_map)
  1648. {
  1649. unsigned int i;
  1650. encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
  1651. for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
  1652. encode_uint32(xdr, op_map->u.words[i]);
  1653. }
  1654. static void encode_exchange_id(struct xdr_stream *xdr,
  1655. const struct nfs41_exchange_id_args *args,
  1656. struct compound_hdr *hdr)
  1657. {
  1658. __be32 *p;
  1659. char impl_name[IMPL_NAME_LIMIT];
  1660. int len = 0;
  1661. encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
  1662. encode_nfs4_verifier(xdr, &args->verifier);
  1663. encode_string(xdr, strlen(args->client->cl_owner_id),
  1664. args->client->cl_owner_id);
  1665. encode_uint32(xdr, args->flags);
  1666. encode_uint32(xdr, args->state_protect.how);
  1667. switch (args->state_protect.how) {
  1668. case SP4_NONE:
  1669. break;
  1670. case SP4_MACH_CRED:
  1671. encode_op_map(xdr, &args->state_protect.enforce);
  1672. encode_op_map(xdr, &args->state_protect.allow);
  1673. break;
  1674. default:
  1675. WARN_ON_ONCE(1);
  1676. break;
  1677. }
  1678. if (send_implementation_id &&
  1679. sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
  1680. sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
  1681. <= sizeof(impl_name) + 1)
  1682. len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
  1683. utsname()->sysname, utsname()->release,
  1684. utsname()->version, utsname()->machine);
  1685. if (len > 0) {
  1686. encode_uint32(xdr, 1); /* implementation id array length=1 */
  1687. encode_string(xdr,
  1688. sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
  1689. CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
  1690. encode_string(xdr, len, impl_name);
  1691. /* just send zeros for nii_date - the date is in nii_name */
  1692. p = reserve_space(xdr, 12);
  1693. p = xdr_encode_hyper(p, 0);
  1694. *p = cpu_to_be32(0);
  1695. } else
  1696. encode_uint32(xdr, 0); /* implementation id array length=0 */
  1697. }
  1698. static void encode_create_session(struct xdr_stream *xdr,
  1699. const struct nfs41_create_session_args *args,
  1700. struct compound_hdr *hdr)
  1701. {
  1702. __be32 *p;
  1703. struct nfs_client *clp = args->client;
  1704. struct rpc_clnt *clnt = clp->cl_rpcclient;
  1705. struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
  1706. u32 max_resp_sz_cached;
  1707. /*
  1708. * Assumes OPEN is the biggest non-idempotent compound.
  1709. * 2 is the verifier.
  1710. */
  1711. max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 2)
  1712. * XDR_UNIT + RPC_MAX_AUTH_SIZE;
  1713. encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
  1714. p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
  1715. p = xdr_encode_hyper(p, args->clientid);
  1716. *p++ = cpu_to_be32(args->seqid); /*Sequence id */
  1717. *p++ = cpu_to_be32(args->flags); /*flags */
  1718. /* Fore Channel */
  1719. *p++ = cpu_to_be32(0); /* header padding size */
  1720. *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
  1721. *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
  1722. *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
  1723. *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
  1724. *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
  1725. *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
  1726. /* Back Channel */
  1727. *p++ = cpu_to_be32(0); /* header padding size */
  1728. *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
  1729. *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
  1730. *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
  1731. *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
  1732. *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
  1733. *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
  1734. *p++ = cpu_to_be32(args->cb_program); /* cb_program */
  1735. *p++ = cpu_to_be32(1);
  1736. *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
  1737. /* authsys_parms rfc1831 */
  1738. *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */
  1739. p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
  1740. *p++ = cpu_to_be32(0); /* UID */
  1741. *p++ = cpu_to_be32(0); /* GID */
  1742. *p = cpu_to_be32(0); /* No more gids */
  1743. }
  1744. static void encode_destroy_session(struct xdr_stream *xdr,
  1745. const struct nfs4_session *session,
  1746. struct compound_hdr *hdr)
  1747. {
  1748. encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
  1749. encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
  1750. }
  1751. static void encode_destroy_clientid(struct xdr_stream *xdr,
  1752. uint64_t clientid,
  1753. struct compound_hdr *hdr)
  1754. {
  1755. encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
  1756. encode_uint64(xdr, clientid);
  1757. }
  1758. static void encode_reclaim_complete(struct xdr_stream *xdr,
  1759. const struct nfs41_reclaim_complete_args *args,
  1760. struct compound_hdr *hdr)
  1761. {
  1762. encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
  1763. encode_uint32(xdr, args->one_fs);
  1764. }
  1765. #endif /* CONFIG_NFS_V4_1 */
  1766. static void encode_sequence(struct xdr_stream *xdr,
  1767. const struct nfs4_sequence_args *args,
  1768. struct compound_hdr *hdr)
  1769. {
  1770. #if defined(CONFIG_NFS_V4_1)
  1771. struct nfs4_session *session;
  1772. struct nfs4_slot_table *tp;
  1773. struct nfs4_slot *slot = args->sa_slot;
  1774. __be32 *p;
  1775. tp = slot->table;
  1776. session = tp->session;
  1777. if (!session)
  1778. return;
  1779. encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
  1780. /*
  1781. * Sessionid + seqid + slotid + max slotid + cache_this
  1782. */
  1783. dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
  1784. "max_slotid=%d cache_this=%d\n",
  1785. __func__,
  1786. ((u32 *)session->sess_id.data)[0],
  1787. ((u32 *)session->sess_id.data)[1],
  1788. ((u32 *)session->sess_id.data)[2],
  1789. ((u32 *)session->sess_id.data)[3],
  1790. slot->seq_nr, slot->slot_nr,
  1791. tp->highest_used_slotid, args->sa_cache_this);
  1792. p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
  1793. p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
  1794. *p++ = cpu_to_be32(slot->seq_nr);
  1795. *p++ = cpu_to_be32(slot->slot_nr);
  1796. *p++ = cpu_to_be32(tp->highest_used_slotid);
  1797. *p = cpu_to_be32(args->sa_cache_this);
  1798. #endif /* CONFIG_NFS_V4_1 */
  1799. }
  1800. #ifdef CONFIG_NFS_V4_1
  1801. static void
  1802. encode_getdeviceinfo(struct xdr_stream *xdr,
  1803. const struct nfs4_getdeviceinfo_args *args,
  1804. struct compound_hdr *hdr)
  1805. {
  1806. __be32 *p;
  1807. encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
  1808. p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
  1809. p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
  1810. NFS4_DEVICEID4_SIZE);
  1811. *p++ = cpu_to_be32(args->pdev->layout_type);
  1812. *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
  1813. p = reserve_space(xdr, 4 + 4);
  1814. *p++ = cpu_to_be32(1); /* bitmap length */
  1815. *p++ = cpu_to_be32(args->notify_types);
  1816. }
  1817. static void
  1818. encode_layoutget(struct xdr_stream *xdr,
  1819. const struct nfs4_layoutget_args *args,
  1820. struct compound_hdr *hdr)
  1821. {
  1822. __be32 *p;
  1823. encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
  1824. p = reserve_space(xdr, 36);
  1825. *p++ = cpu_to_be32(0); /* Signal layout available */
  1826. *p++ = cpu_to_be32(args->type);
  1827. *p++ = cpu_to_be32(args->range.iomode);
  1828. p = xdr_encode_hyper(p, args->range.offset);
  1829. p = xdr_encode_hyper(p, args->range.length);
  1830. p = xdr_encode_hyper(p, args->minlength);
  1831. encode_nfs4_stateid(xdr, &args->stateid);
  1832. encode_uint32(xdr, args->maxcount);
  1833. dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
  1834. __func__,
  1835. args->type,
  1836. args->range.iomode,
  1837. (unsigned long)args->range.offset,
  1838. (unsigned long)args->range.length,
  1839. args->maxcount);
  1840. }
  1841. static int
  1842. encode_layoutcommit(struct xdr_stream *xdr,
  1843. struct inode *inode,
  1844. const struct nfs4_layoutcommit_args *args,
  1845. struct compound_hdr *hdr)
  1846. {
  1847. __be32 *p;
  1848. dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
  1849. NFS_SERVER(args->inode)->pnfs_curr_ld->id);
  1850. encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
  1851. p = reserve_space(xdr, 20);
  1852. /* Only whole file layouts */
  1853. p = xdr_encode_hyper(p, 0); /* offset */
  1854. p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
  1855. *p = cpu_to_be32(0); /* reclaim */
  1856. encode_nfs4_stateid(xdr, &args->stateid);
  1857. if (args->lastbytewritten != U64_MAX) {
  1858. p = reserve_space(xdr, 20);
  1859. *p++ = cpu_to_be32(1); /* newoffset = TRUE */
  1860. p = xdr_encode_hyper(p, args->lastbytewritten);
  1861. } else {
  1862. p = reserve_space(xdr, 12);
  1863. *p++ = cpu_to_be32(0); /* newoffset = FALSE */
  1864. }
  1865. *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
  1866. *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
  1867. encode_uint32(xdr, args->layoutupdate_len);
  1868. if (args->layoutupdate_pages)
  1869. xdr_write_pages(xdr, args->layoutupdate_pages, 0,
  1870. args->layoutupdate_len);
  1871. return 0;
  1872. }
  1873. static void
  1874. encode_layoutreturn(struct xdr_stream *xdr,
  1875. const struct nfs4_layoutreturn_args *args,
  1876. struct compound_hdr *hdr)
  1877. {
  1878. __be32 *p;
  1879. encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
  1880. p = reserve_space(xdr, 16);
  1881. *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
  1882. *p++ = cpu_to_be32(args->layout_type);
  1883. *p++ = cpu_to_be32(args->range.iomode);
  1884. *p = cpu_to_be32(RETURN_FILE);
  1885. p = reserve_space(xdr, 16);
  1886. p = xdr_encode_hyper(p, args->range.offset);
  1887. p = xdr_encode_hyper(p, args->range.length);
  1888. spin_lock(&args->inode->i_lock);
  1889. encode_nfs4_stateid(xdr, &args->stateid);
  1890. spin_unlock(&args->inode->i_lock);
  1891. if (args->ld_private->ops && args->ld_private->ops->encode)
  1892. args->ld_private->ops->encode(xdr, args, args->ld_private);
  1893. else
  1894. encode_uint32(xdr, 0);
  1895. }
  1896. static int
  1897. encode_secinfo_no_name(struct xdr_stream *xdr,
  1898. const struct nfs41_secinfo_no_name_args *args,
  1899. struct compound_hdr *hdr)
  1900. {
  1901. encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
  1902. encode_uint32(xdr, args->style);
  1903. return 0;
  1904. }
  1905. static void encode_test_stateid(struct xdr_stream *xdr,
  1906. const struct nfs41_test_stateid_args *args,
  1907. struct compound_hdr *hdr)
  1908. {
  1909. encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
  1910. encode_uint32(xdr, 1);
  1911. encode_nfs4_stateid(xdr, args->stateid);
  1912. }
  1913. static void encode_free_stateid(struct xdr_stream *xdr,
  1914. const struct nfs41_free_stateid_args *args,
  1915. struct compound_hdr *hdr)
  1916. {
  1917. encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
  1918. encode_nfs4_stateid(xdr, &args->stateid);
  1919. }
  1920. #else
  1921. static inline void
  1922. encode_layoutreturn(struct xdr_stream *xdr,
  1923. const struct nfs4_layoutreturn_args *args,
  1924. struct compound_hdr *hdr)
  1925. {
  1926. }
  1927. static void
  1928. encode_layoutget(struct xdr_stream *xdr,
  1929. const struct nfs4_layoutget_args *args,
  1930. struct compound_hdr *hdr)
  1931. {
  1932. }
  1933. #endif /* CONFIG_NFS_V4_1 */
  1934. /*
  1935. * END OF "GENERIC" ENCODE ROUTINES.
  1936. */
  1937. static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
  1938. {
  1939. #if defined(CONFIG_NFS_V4_1)
  1940. struct nfs4_session *session = args->sa_slot->table->session;
  1941. if (session)
  1942. return session->clp->cl_mvops->minor_version;
  1943. #endif /* CONFIG_NFS_V4_1 */
  1944. return 0;
  1945. }
  1946. /*
  1947. * Encode an ACCESS request
  1948. */
  1949. static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
  1950. const void *data)
  1951. {
  1952. const struct nfs4_accessargs *args = data;
  1953. struct compound_hdr hdr = {
  1954. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1955. };
  1956. encode_compound_hdr(xdr, req, &hdr);
  1957. encode_sequence(xdr, &args->seq_args, &hdr);
  1958. encode_putfh(xdr, args->fh, &hdr);
  1959. encode_access(xdr, args->access, &hdr);
  1960. if (args->bitmask)
  1961. encode_getfattr(xdr, args->bitmask, &hdr);
  1962. encode_nops(&hdr);
  1963. }
  1964. /*
  1965. * Encode LOOKUP request
  1966. */
  1967. static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
  1968. const void *data)
  1969. {
  1970. const struct nfs4_lookup_arg *args = data;
  1971. struct compound_hdr hdr = {
  1972. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1973. };
  1974. encode_compound_hdr(xdr, req, &hdr);
  1975. encode_sequence(xdr, &args->seq_args, &hdr);
  1976. encode_putfh(xdr, args->dir_fh, &hdr);
  1977. encode_lookup(xdr, args->name, &hdr);
  1978. encode_getfh(xdr, &hdr);
  1979. encode_getfattr(xdr, args->bitmask, &hdr);
  1980. encode_nops(&hdr);
  1981. }
  1982. /*
  1983. * Encode LOOKUPP request
  1984. */
  1985. static void nfs4_xdr_enc_lookupp(struct rpc_rqst *req, struct xdr_stream *xdr,
  1986. const void *data)
  1987. {
  1988. const struct nfs4_lookupp_arg *args = data;
  1989. struct compound_hdr hdr = {
  1990. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1991. };
  1992. encode_compound_hdr(xdr, req, &hdr);
  1993. encode_sequence(xdr, &args->seq_args, &hdr);
  1994. encode_putfh(xdr, args->fh, &hdr);
  1995. encode_lookupp(xdr, &hdr);
  1996. encode_getfh(xdr, &hdr);
  1997. encode_getfattr(xdr, args->bitmask, &hdr);
  1998. encode_nops(&hdr);
  1999. }
  2000. /*
  2001. * Encode LOOKUP_ROOT request
  2002. */
  2003. static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
  2004. struct xdr_stream *xdr,
  2005. const void *data)
  2006. {
  2007. const struct nfs4_lookup_root_arg *args = data;
  2008. struct compound_hdr hdr = {
  2009. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2010. };
  2011. encode_compound_hdr(xdr, req, &hdr);
  2012. encode_sequence(xdr, &args->seq_args, &hdr);
  2013. encode_putrootfh(xdr, &hdr);
  2014. encode_getfh(xdr, &hdr);
  2015. encode_getfattr(xdr, args->bitmask, &hdr);
  2016. encode_nops(&hdr);
  2017. }
  2018. /*
  2019. * Encode REMOVE request
  2020. */
  2021. static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
  2022. const void *data)
  2023. {
  2024. const struct nfs_removeargs *args = data;
  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_remove(xdr, &args->name, &hdr);
  2032. encode_nops(&hdr);
  2033. }
  2034. /*
  2035. * Encode RENAME request
  2036. */
  2037. static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
  2038. const void *data)
  2039. {
  2040. const struct nfs_renameargs *args = data;
  2041. struct compound_hdr hdr = {
  2042. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2043. };
  2044. encode_compound_hdr(xdr, req, &hdr);
  2045. encode_sequence(xdr, &args->seq_args, &hdr);
  2046. encode_putfh(xdr, args->old_dir, &hdr);
  2047. encode_savefh(xdr, &hdr);
  2048. encode_putfh(xdr, args->new_dir, &hdr);
  2049. encode_rename(xdr, args->old_name, args->new_name, &hdr);
  2050. encode_nops(&hdr);
  2051. }
  2052. /*
  2053. * Encode LINK request
  2054. */
  2055. static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
  2056. const void *data)
  2057. {
  2058. const struct nfs4_link_arg *args = data;
  2059. struct compound_hdr hdr = {
  2060. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2061. };
  2062. encode_compound_hdr(xdr, req, &hdr);
  2063. encode_sequence(xdr, &args->seq_args, &hdr);
  2064. encode_putfh(xdr, args->fh, &hdr);
  2065. encode_savefh(xdr, &hdr);
  2066. encode_putfh(xdr, args->dir_fh, &hdr);
  2067. encode_link(xdr, args->name, &hdr);
  2068. encode_restorefh(xdr, &hdr);
  2069. encode_getfattr(xdr, args->bitmask, &hdr);
  2070. encode_nops(&hdr);
  2071. }
  2072. /*
  2073. * Encode CREATE request
  2074. */
  2075. static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
  2076. const void *data)
  2077. {
  2078. const struct nfs4_create_arg *args = data;
  2079. struct compound_hdr hdr = {
  2080. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2081. };
  2082. encode_compound_hdr(xdr, req, &hdr);
  2083. encode_sequence(xdr, &args->seq_args, &hdr);
  2084. encode_putfh(xdr, args->dir_fh, &hdr);
  2085. encode_create(xdr, args, &hdr);
  2086. encode_getfh(xdr, &hdr);
  2087. encode_getfattr(xdr, args->bitmask, &hdr);
  2088. encode_nops(&hdr);
  2089. }
  2090. /*
  2091. * Encode SYMLINK request
  2092. */
  2093. static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
  2094. const void *data)
  2095. {
  2096. const struct nfs4_create_arg *args = data;
  2097. nfs4_xdr_enc_create(req, xdr, args);
  2098. }
  2099. /*
  2100. * Encode GETATTR request
  2101. */
  2102. static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
  2103. const void *data)
  2104. {
  2105. const struct nfs4_getattr_arg *args = data;
  2106. struct compound_hdr hdr = {
  2107. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2108. };
  2109. encode_compound_hdr(xdr, req, &hdr);
  2110. encode_sequence(xdr, &args->seq_args, &hdr);
  2111. encode_putfh(xdr, args->fh, &hdr);
  2112. encode_getfattr(xdr, args->bitmask, &hdr);
  2113. encode_nops(&hdr);
  2114. }
  2115. /*
  2116. * Encode a CLOSE request
  2117. */
  2118. static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
  2119. const void *data)
  2120. {
  2121. const struct nfs_closeargs *args = data;
  2122. struct compound_hdr hdr = {
  2123. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2124. };
  2125. encode_compound_hdr(xdr, req, &hdr);
  2126. encode_sequence(xdr, &args->seq_args, &hdr);
  2127. encode_putfh(xdr, args->fh, &hdr);
  2128. if (args->lr_args)
  2129. encode_layoutreturn(xdr, args->lr_args, &hdr);
  2130. if (args->bitmask != NULL)
  2131. encode_getfattr(xdr, args->bitmask, &hdr);
  2132. encode_close(xdr, args, &hdr);
  2133. encode_nops(&hdr);
  2134. }
  2135. /*
  2136. * Encode an OPEN request
  2137. */
  2138. static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
  2139. const void *data)
  2140. {
  2141. const struct nfs_openargs *args = data;
  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->fh, &hdr);
  2148. encode_open(xdr, args, &hdr);
  2149. encode_getfh(xdr, &hdr);
  2150. if (args->access)
  2151. encode_access(xdr, args->access, &hdr);
  2152. encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
  2153. if (args->lg_args) {
  2154. encode_layoutget(xdr, args->lg_args, &hdr);
  2155. rpc_prepare_reply_pages(req, args->lg_args->layout.pages, 0,
  2156. args->lg_args->layout.pglen,
  2157. hdr.replen);
  2158. }
  2159. encode_nops(&hdr);
  2160. }
  2161. /*
  2162. * Encode an OPEN_CONFIRM request
  2163. */
  2164. static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
  2165. struct xdr_stream *xdr,
  2166. const void *data)
  2167. {
  2168. const struct nfs_open_confirmargs *args = data;
  2169. struct compound_hdr hdr = {
  2170. .nops = 0,
  2171. };
  2172. encode_compound_hdr(xdr, req, &hdr);
  2173. encode_putfh(xdr, args->fh, &hdr);
  2174. encode_open_confirm(xdr, args, &hdr);
  2175. encode_nops(&hdr);
  2176. }
  2177. /*
  2178. * Encode an OPEN request with no attributes.
  2179. */
  2180. static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
  2181. struct xdr_stream *xdr,
  2182. const void *data)
  2183. {
  2184. const struct nfs_openargs *args = data;
  2185. struct compound_hdr hdr = {
  2186. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2187. };
  2188. encode_compound_hdr(xdr, req, &hdr);
  2189. encode_sequence(xdr, &args->seq_args, &hdr);
  2190. encode_putfh(xdr, args->fh, &hdr);
  2191. encode_open(xdr, args, &hdr);
  2192. if (args->access)
  2193. encode_access(xdr, args->access, &hdr);
  2194. encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
  2195. if (args->lg_args) {
  2196. encode_layoutget(xdr, args->lg_args, &hdr);
  2197. rpc_prepare_reply_pages(req, args->lg_args->layout.pages, 0,
  2198. args->lg_args->layout.pglen,
  2199. hdr.replen);
  2200. }
  2201. encode_nops(&hdr);
  2202. }
  2203. /*
  2204. * Encode an OPEN_DOWNGRADE request
  2205. */
  2206. static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
  2207. struct xdr_stream *xdr,
  2208. const void *data)
  2209. {
  2210. const struct nfs_closeargs *args = data;
  2211. struct compound_hdr hdr = {
  2212. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2213. };
  2214. encode_compound_hdr(xdr, req, &hdr);
  2215. encode_sequence(xdr, &args->seq_args, &hdr);
  2216. encode_putfh(xdr, args->fh, &hdr);
  2217. if (args->lr_args)
  2218. encode_layoutreturn(xdr, args->lr_args, &hdr);
  2219. encode_open_downgrade(xdr, args, &hdr);
  2220. encode_nops(&hdr);
  2221. }
  2222. /*
  2223. * Encode a LOCK request
  2224. */
  2225. static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
  2226. const void *data)
  2227. {
  2228. const struct nfs_lock_args *args = data;
  2229. struct compound_hdr hdr = {
  2230. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2231. };
  2232. encode_compound_hdr(xdr, req, &hdr);
  2233. encode_sequence(xdr, &args->seq_args, &hdr);
  2234. encode_putfh(xdr, args->fh, &hdr);
  2235. encode_lock(xdr, args, &hdr);
  2236. encode_nops(&hdr);
  2237. }
  2238. /*
  2239. * Encode a LOCKT request
  2240. */
  2241. static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
  2242. const void *data)
  2243. {
  2244. const struct nfs_lockt_args *args = data;
  2245. struct compound_hdr hdr = {
  2246. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2247. };
  2248. encode_compound_hdr(xdr, req, &hdr);
  2249. encode_sequence(xdr, &args->seq_args, &hdr);
  2250. encode_putfh(xdr, args->fh, &hdr);
  2251. encode_lockt(xdr, args, &hdr);
  2252. encode_nops(&hdr);
  2253. }
  2254. /*
  2255. * Encode a LOCKU request
  2256. */
  2257. static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
  2258. const void *data)
  2259. {
  2260. const struct nfs_locku_args *args = data;
  2261. struct compound_hdr hdr = {
  2262. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2263. };
  2264. encode_compound_hdr(xdr, req, &hdr);
  2265. encode_sequence(xdr, &args->seq_args, &hdr);
  2266. encode_putfh(xdr, args->fh, &hdr);
  2267. encode_locku(xdr, args, &hdr);
  2268. encode_nops(&hdr);
  2269. }
  2270. static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
  2271. struct xdr_stream *xdr,
  2272. const void *data)
  2273. {
  2274. const struct nfs_release_lockowner_args *args = data;
  2275. struct compound_hdr hdr = {
  2276. .minorversion = 0,
  2277. };
  2278. encode_compound_hdr(xdr, req, &hdr);
  2279. encode_release_lockowner(xdr, &args->lock_owner, &hdr);
  2280. encode_nops(&hdr);
  2281. }
  2282. /*
  2283. * Encode a READLINK request
  2284. */
  2285. static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
  2286. const void *data)
  2287. {
  2288. const struct nfs4_readlink *args = data;
  2289. struct compound_hdr hdr = {
  2290. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2291. };
  2292. encode_compound_hdr(xdr, req, &hdr);
  2293. encode_sequence(xdr, &args->seq_args, &hdr);
  2294. encode_putfh(xdr, args->fh, &hdr);
  2295. encode_readlink(xdr, args, req, &hdr);
  2296. rpc_prepare_reply_pages(req, args->pages, args->pgbase,
  2297. args->pglen, hdr.replen);
  2298. encode_nops(&hdr);
  2299. }
  2300. /*
  2301. * Encode a READDIR request
  2302. */
  2303. static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
  2304. const void *data)
  2305. {
  2306. const struct nfs4_readdir_arg *args = data;
  2307. struct compound_hdr hdr = {
  2308. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2309. };
  2310. encode_compound_hdr(xdr, req, &hdr);
  2311. encode_sequence(xdr, &args->seq_args, &hdr);
  2312. encode_putfh(xdr, args->fh, &hdr);
  2313. encode_readdir(xdr, args, req, &hdr);
  2314. rpc_prepare_reply_pages(req, args->pages, args->pgbase,
  2315. args->count, hdr.replen);
  2316. encode_nops(&hdr);
  2317. }
  2318. /*
  2319. * Encode a READ request
  2320. */
  2321. static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
  2322. const void *data)
  2323. {
  2324. const struct nfs_pgio_args *args = data;
  2325. struct compound_hdr hdr = {
  2326. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2327. };
  2328. encode_compound_hdr(xdr, req, &hdr);
  2329. encode_sequence(xdr, &args->seq_args, &hdr);
  2330. encode_putfh(xdr, args->fh, &hdr);
  2331. encode_read(xdr, args, &hdr);
  2332. rpc_prepare_reply_pages(req, args->pages, args->pgbase,
  2333. args->count, hdr.replen);
  2334. req->rq_rcv_buf.flags |= XDRBUF_READ;
  2335. encode_nops(&hdr);
  2336. }
  2337. /*
  2338. * Encode an SETATTR request
  2339. */
  2340. static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
  2341. const void *data)
  2342. {
  2343. const struct nfs_setattrargs *args = data;
  2344. struct compound_hdr hdr = {
  2345. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2346. };
  2347. encode_compound_hdr(xdr, req, &hdr);
  2348. encode_sequence(xdr, &args->seq_args, &hdr);
  2349. encode_putfh(xdr, args->fh, &hdr);
  2350. encode_setattr(xdr, args, args->server, &hdr);
  2351. encode_getfattr(xdr, args->bitmask, &hdr);
  2352. encode_nops(&hdr);
  2353. }
  2354. /*
  2355. * Encode a GETACL request
  2356. */
  2357. static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
  2358. const void *data)
  2359. {
  2360. const struct nfs_getaclargs *args = data;
  2361. struct compound_hdr hdr = {
  2362. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2363. };
  2364. const __u32 nfs4_acl_bitmap[1] = {
  2365. [0] = FATTR4_WORD0_ACL,
  2366. };
  2367. uint32_t replen;
  2368. encode_compound_hdr(xdr, req, &hdr);
  2369. encode_sequence(xdr, &args->seq_args, &hdr);
  2370. encode_putfh(xdr, args->fh, &hdr);
  2371. replen = hdr.replen + op_decode_hdr_maxsz;
  2372. encode_getattr(xdr, nfs4_acl_bitmap, NULL,
  2373. ARRAY_SIZE(nfs4_acl_bitmap), &hdr);
  2374. rpc_prepare_reply_pages(req, args->acl_pages, 0,
  2375. args->acl_len, replen + 1);
  2376. encode_nops(&hdr);
  2377. }
  2378. /*
  2379. * Encode a WRITE request
  2380. */
  2381. static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
  2382. const void *data)
  2383. {
  2384. const struct nfs_pgio_args *args = data;
  2385. struct compound_hdr hdr = {
  2386. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2387. };
  2388. encode_compound_hdr(xdr, req, &hdr);
  2389. encode_sequence(xdr, &args->seq_args, &hdr);
  2390. encode_putfh(xdr, args->fh, &hdr);
  2391. encode_write(xdr, args, &hdr);
  2392. req->rq_snd_buf.flags |= XDRBUF_WRITE;
  2393. if (args->bitmask)
  2394. encode_getfattr(xdr, args->bitmask, &hdr);
  2395. encode_nops(&hdr);
  2396. }
  2397. /*
  2398. * a COMMIT request
  2399. */
  2400. static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
  2401. const void *data)
  2402. {
  2403. const struct nfs_commitargs *args = data;
  2404. struct compound_hdr hdr = {
  2405. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2406. };
  2407. encode_compound_hdr(xdr, req, &hdr);
  2408. encode_sequence(xdr, &args->seq_args, &hdr);
  2409. encode_putfh(xdr, args->fh, &hdr);
  2410. encode_commit(xdr, args, &hdr);
  2411. encode_nops(&hdr);
  2412. }
  2413. /*
  2414. * FSINFO request
  2415. */
  2416. static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
  2417. const void *data)
  2418. {
  2419. const struct nfs4_fsinfo_arg *args = data;
  2420. struct compound_hdr hdr = {
  2421. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2422. };
  2423. encode_compound_hdr(xdr, req, &hdr);
  2424. encode_sequence(xdr, &args->seq_args, &hdr);
  2425. encode_putfh(xdr, args->fh, &hdr);
  2426. encode_fsinfo(xdr, args->bitmask, &hdr);
  2427. encode_nops(&hdr);
  2428. }
  2429. /*
  2430. * a PATHCONF request
  2431. */
  2432. static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
  2433. const void *data)
  2434. {
  2435. const struct nfs4_pathconf_arg *args = data;
  2436. struct compound_hdr hdr = {
  2437. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2438. };
  2439. encode_compound_hdr(xdr, req, &hdr);
  2440. encode_sequence(xdr, &args->seq_args, &hdr);
  2441. encode_putfh(xdr, args->fh, &hdr);
  2442. encode_getattr(xdr, nfs4_pathconf_bitmap, args->bitmask,
  2443. ARRAY_SIZE(nfs4_pathconf_bitmap), &hdr);
  2444. encode_nops(&hdr);
  2445. }
  2446. /*
  2447. * a STATFS request
  2448. */
  2449. static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
  2450. const void *data)
  2451. {
  2452. const struct nfs4_statfs_arg *args = data;
  2453. struct compound_hdr hdr = {
  2454. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2455. };
  2456. encode_compound_hdr(xdr, req, &hdr);
  2457. encode_sequence(xdr, &args->seq_args, &hdr);
  2458. encode_putfh(xdr, args->fh, &hdr);
  2459. encode_getattr(xdr, nfs4_statfs_bitmap, args->bitmask,
  2460. ARRAY_SIZE(nfs4_statfs_bitmap), &hdr);
  2461. encode_nops(&hdr);
  2462. }
  2463. /*
  2464. * GETATTR_BITMAP request
  2465. */
  2466. static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
  2467. struct xdr_stream *xdr,
  2468. const void *data)
  2469. {
  2470. const struct nfs4_server_caps_arg *args = data;
  2471. const u32 *bitmask = args->bitmask;
  2472. struct compound_hdr hdr = {
  2473. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2474. };
  2475. encode_compound_hdr(xdr, req, &hdr);
  2476. encode_sequence(xdr, &args->seq_args, &hdr);
  2477. encode_putfh(xdr, args->fhandle, &hdr);
  2478. encode_getattr(xdr, bitmask, NULL, 3, &hdr);
  2479. encode_nops(&hdr);
  2480. }
  2481. /*
  2482. * a RENEW request
  2483. */
  2484. static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
  2485. const void *data)
  2486. {
  2487. const struct nfs_client *clp = data;
  2488. struct compound_hdr hdr = {
  2489. .nops = 0,
  2490. };
  2491. encode_compound_hdr(xdr, req, &hdr);
  2492. encode_renew(xdr, clp->cl_clientid, &hdr);
  2493. encode_nops(&hdr);
  2494. }
  2495. /*
  2496. * a SETCLIENTID request
  2497. */
  2498. static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
  2499. struct xdr_stream *xdr,
  2500. const void *data)
  2501. {
  2502. const struct nfs4_setclientid *sc = data;
  2503. struct compound_hdr hdr = {
  2504. .nops = 0,
  2505. };
  2506. encode_compound_hdr(xdr, req, &hdr);
  2507. encode_setclientid(xdr, sc, &hdr);
  2508. encode_nops(&hdr);
  2509. }
  2510. /*
  2511. * a SETCLIENTID_CONFIRM request
  2512. */
  2513. static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
  2514. struct xdr_stream *xdr,
  2515. const void *data)
  2516. {
  2517. const struct nfs4_setclientid_res *arg = data;
  2518. struct compound_hdr hdr = {
  2519. .nops = 0,
  2520. };
  2521. encode_compound_hdr(xdr, req, &hdr);
  2522. encode_setclientid_confirm(xdr, arg, &hdr);
  2523. encode_nops(&hdr);
  2524. }
  2525. /*
  2526. * DELEGRETURN request
  2527. */
  2528. static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
  2529. struct xdr_stream *xdr,
  2530. const void *data)
  2531. {
  2532. const struct nfs4_delegreturnargs *args = data;
  2533. struct compound_hdr hdr = {
  2534. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2535. };
  2536. encode_compound_hdr(xdr, req, &hdr);
  2537. encode_sequence(xdr, &args->seq_args, &hdr);
  2538. encode_putfh(xdr, args->fhandle, &hdr);
  2539. if (args->lr_args)
  2540. encode_layoutreturn(xdr, args->lr_args, &hdr);
  2541. if (args->bitmask)
  2542. encode_getfattr(xdr, args->bitmask, &hdr);
  2543. encode_delegreturn(xdr, args->stateid, &hdr);
  2544. encode_nops(&hdr);
  2545. }
  2546. /*
  2547. * Encode FS_LOCATIONS request
  2548. */
  2549. static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
  2550. struct xdr_stream *xdr,
  2551. const void *data)
  2552. {
  2553. const struct nfs4_fs_locations_arg *args = data;
  2554. struct compound_hdr hdr = {
  2555. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2556. };
  2557. uint32_t replen;
  2558. encode_compound_hdr(xdr, req, &hdr);
  2559. encode_sequence(xdr, &args->seq_args, &hdr);
  2560. if (args->migration) {
  2561. encode_putfh(xdr, args->fh, &hdr);
  2562. replen = hdr.replen;
  2563. encode_fs_locations(xdr, args->bitmask, &hdr);
  2564. if (args->renew)
  2565. encode_renew(xdr, args->clientid, &hdr);
  2566. } else {
  2567. encode_putfh(xdr, args->dir_fh, &hdr);
  2568. encode_lookup(xdr, args->name, &hdr);
  2569. replen = hdr.replen;
  2570. encode_fs_locations(xdr, args->bitmask, &hdr);
  2571. }
  2572. rpc_prepare_reply_pages(req, (struct page **)&args->page, 0,
  2573. PAGE_SIZE, replen + 1);
  2574. encode_nops(&hdr);
  2575. }
  2576. /*
  2577. * Encode SECINFO request
  2578. */
  2579. static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
  2580. struct xdr_stream *xdr,
  2581. const void *data)
  2582. {
  2583. const struct nfs4_secinfo_arg *args = data;
  2584. struct compound_hdr hdr = {
  2585. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2586. };
  2587. encode_compound_hdr(xdr, req, &hdr);
  2588. encode_sequence(xdr, &args->seq_args, &hdr);
  2589. encode_putfh(xdr, args->dir_fh, &hdr);
  2590. encode_secinfo(xdr, args->name, &hdr);
  2591. encode_nops(&hdr);
  2592. }
  2593. /*
  2594. * Encode FSID_PRESENT request
  2595. */
  2596. static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
  2597. struct xdr_stream *xdr,
  2598. const void *data)
  2599. {
  2600. const struct nfs4_fsid_present_arg *args = data;
  2601. struct compound_hdr hdr = {
  2602. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2603. };
  2604. encode_compound_hdr(xdr, req, &hdr);
  2605. encode_sequence(xdr, &args->seq_args, &hdr);
  2606. encode_putfh(xdr, args->fh, &hdr);
  2607. encode_getfh(xdr, &hdr);
  2608. if (args->renew)
  2609. encode_renew(xdr, args->clientid, &hdr);
  2610. encode_nops(&hdr);
  2611. }
  2612. #if defined(CONFIG_NFS_V4_1)
  2613. /*
  2614. * BIND_CONN_TO_SESSION request
  2615. */
  2616. static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
  2617. struct xdr_stream *xdr,
  2618. const void *data)
  2619. {
  2620. const struct nfs41_bind_conn_to_session_args *args = data;
  2621. struct compound_hdr hdr = {
  2622. .minorversion = args->client->cl_mvops->minor_version,
  2623. };
  2624. encode_compound_hdr(xdr, req, &hdr);
  2625. encode_bind_conn_to_session(xdr, args, &hdr);
  2626. encode_nops(&hdr);
  2627. }
  2628. /*
  2629. * EXCHANGE_ID request
  2630. */
  2631. static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
  2632. struct xdr_stream *xdr,
  2633. const void *data)
  2634. {
  2635. const struct nfs41_exchange_id_args *args = data;
  2636. struct compound_hdr hdr = {
  2637. .minorversion = args->client->cl_mvops->minor_version,
  2638. };
  2639. encode_compound_hdr(xdr, req, &hdr);
  2640. encode_exchange_id(xdr, args, &hdr);
  2641. encode_nops(&hdr);
  2642. }
  2643. /*
  2644. * a CREATE_SESSION request
  2645. */
  2646. static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
  2647. struct xdr_stream *xdr,
  2648. const void *data)
  2649. {
  2650. const struct nfs41_create_session_args *args = data;
  2651. struct compound_hdr hdr = {
  2652. .minorversion = args->client->cl_mvops->minor_version,
  2653. };
  2654. encode_compound_hdr(xdr, req, &hdr);
  2655. encode_create_session(xdr, args, &hdr);
  2656. encode_nops(&hdr);
  2657. }
  2658. /*
  2659. * a DESTROY_SESSION request
  2660. */
  2661. static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
  2662. struct xdr_stream *xdr,
  2663. const void *data)
  2664. {
  2665. const struct nfs4_session *session = data;
  2666. struct compound_hdr hdr = {
  2667. .minorversion = session->clp->cl_mvops->minor_version,
  2668. };
  2669. encode_compound_hdr(xdr, req, &hdr);
  2670. encode_destroy_session(xdr, session, &hdr);
  2671. encode_nops(&hdr);
  2672. }
  2673. /*
  2674. * a DESTROY_CLIENTID request
  2675. */
  2676. static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
  2677. struct xdr_stream *xdr,
  2678. const void *data)
  2679. {
  2680. const struct nfs_client *clp = data;
  2681. struct compound_hdr hdr = {
  2682. .minorversion = clp->cl_mvops->minor_version,
  2683. };
  2684. encode_compound_hdr(xdr, req, &hdr);
  2685. encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
  2686. encode_nops(&hdr);
  2687. }
  2688. /*
  2689. * a SEQUENCE request
  2690. */
  2691. static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
  2692. const void *data)
  2693. {
  2694. const struct nfs4_sequence_args *args = data;
  2695. struct compound_hdr hdr = {
  2696. .minorversion = nfs4_xdr_minorversion(args),
  2697. };
  2698. encode_compound_hdr(xdr, req, &hdr);
  2699. encode_sequence(xdr, args, &hdr);
  2700. encode_nops(&hdr);
  2701. }
  2702. #endif
  2703. /*
  2704. * a GET_LEASE_TIME request
  2705. */
  2706. static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
  2707. struct xdr_stream *xdr,
  2708. const void *data)
  2709. {
  2710. const struct nfs4_get_lease_time_args *args = data;
  2711. struct compound_hdr hdr = {
  2712. .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
  2713. };
  2714. const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
  2715. encode_compound_hdr(xdr, req, &hdr);
  2716. encode_sequence(xdr, &args->la_seq_args, &hdr);
  2717. encode_putrootfh(xdr, &hdr);
  2718. encode_fsinfo(xdr, lease_bitmap, &hdr);
  2719. encode_nops(&hdr);
  2720. }
  2721. #ifdef CONFIG_NFS_V4_1
  2722. /*
  2723. * a RECLAIM_COMPLETE request
  2724. */
  2725. static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
  2726. struct xdr_stream *xdr,
  2727. const void *data)
  2728. {
  2729. const struct nfs41_reclaim_complete_args *args = data;
  2730. struct compound_hdr hdr = {
  2731. .minorversion = nfs4_xdr_minorversion(&args->seq_args)
  2732. };
  2733. encode_compound_hdr(xdr, req, &hdr);
  2734. encode_sequence(xdr, &args->seq_args, &hdr);
  2735. encode_reclaim_complete(xdr, args, &hdr);
  2736. encode_nops(&hdr);
  2737. }
  2738. /*
  2739. * Encode GETDEVICEINFO request
  2740. */
  2741. static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
  2742. struct xdr_stream *xdr,
  2743. const void *data)
  2744. {
  2745. const struct nfs4_getdeviceinfo_args *args = data;
  2746. struct compound_hdr hdr = {
  2747. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2748. };
  2749. uint32_t replen;
  2750. encode_compound_hdr(xdr, req, &hdr);
  2751. encode_sequence(xdr, &args->seq_args, &hdr);
  2752. replen = hdr.replen + op_decode_hdr_maxsz;
  2753. encode_getdeviceinfo(xdr, args, &hdr);
  2754. /* set up reply kvec. device_addr4 opaque data is read into the
  2755. * pages */
  2756. rpc_prepare_reply_pages(req, args->pdev->pages, args->pdev->pgbase,
  2757. args->pdev->pglen, replen + 2 + 1);
  2758. encode_nops(&hdr);
  2759. }
  2760. /*
  2761. * Encode LAYOUTGET request
  2762. */
  2763. static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
  2764. struct xdr_stream *xdr,
  2765. const void *data)
  2766. {
  2767. const struct nfs4_layoutget_args *args = data;
  2768. struct compound_hdr hdr = {
  2769. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2770. };
  2771. encode_compound_hdr(xdr, req, &hdr);
  2772. encode_sequence(xdr, &args->seq_args, &hdr);
  2773. encode_putfh(xdr, NFS_FH(args->inode), &hdr);
  2774. encode_layoutget(xdr, args, &hdr);
  2775. rpc_prepare_reply_pages(req, args->layout.pages, 0,
  2776. args->layout.pglen, hdr.replen);
  2777. encode_nops(&hdr);
  2778. }
  2779. /*
  2780. * Encode LAYOUTCOMMIT request
  2781. */
  2782. static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
  2783. struct xdr_stream *xdr,
  2784. const void *priv)
  2785. {
  2786. const struct nfs4_layoutcommit_args *args = priv;
  2787. struct nfs4_layoutcommit_data *data =
  2788. container_of(args, struct nfs4_layoutcommit_data, args);
  2789. struct compound_hdr hdr = {
  2790. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2791. };
  2792. encode_compound_hdr(xdr, req, &hdr);
  2793. encode_sequence(xdr, &args->seq_args, &hdr);
  2794. encode_putfh(xdr, NFS_FH(args->inode), &hdr);
  2795. encode_layoutcommit(xdr, data->args.inode, args, &hdr);
  2796. encode_getfattr(xdr, args->bitmask, &hdr);
  2797. encode_nops(&hdr);
  2798. }
  2799. /*
  2800. * Encode LAYOUTRETURN request
  2801. */
  2802. static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
  2803. struct xdr_stream *xdr,
  2804. const void *data)
  2805. {
  2806. const struct nfs4_layoutreturn_args *args = data;
  2807. struct compound_hdr hdr = {
  2808. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2809. };
  2810. encode_compound_hdr(xdr, req, &hdr);
  2811. encode_sequence(xdr, &args->seq_args, &hdr);
  2812. encode_putfh(xdr, NFS_FH(args->inode), &hdr);
  2813. encode_layoutreturn(xdr, args, &hdr);
  2814. encode_nops(&hdr);
  2815. }
  2816. /*
  2817. * Encode SECINFO_NO_NAME request
  2818. */
  2819. static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
  2820. struct xdr_stream *xdr,
  2821. const void *data)
  2822. {
  2823. const struct nfs41_secinfo_no_name_args *args = data;
  2824. struct compound_hdr hdr = {
  2825. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2826. };
  2827. encode_compound_hdr(xdr, req, &hdr);
  2828. encode_sequence(xdr, &args->seq_args, &hdr);
  2829. encode_putrootfh(xdr, &hdr);
  2830. encode_secinfo_no_name(xdr, args, &hdr);
  2831. encode_nops(&hdr);
  2832. }
  2833. /*
  2834. * Encode TEST_STATEID request
  2835. */
  2836. static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
  2837. struct xdr_stream *xdr,
  2838. const void *data)
  2839. {
  2840. const struct nfs41_test_stateid_args *args = data;
  2841. struct compound_hdr hdr = {
  2842. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2843. };
  2844. encode_compound_hdr(xdr, req, &hdr);
  2845. encode_sequence(xdr, &args->seq_args, &hdr);
  2846. encode_test_stateid(xdr, args, &hdr);
  2847. encode_nops(&hdr);
  2848. }
  2849. /*
  2850. * Encode FREE_STATEID request
  2851. */
  2852. static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
  2853. struct xdr_stream *xdr,
  2854. const void *data)
  2855. {
  2856. const struct nfs41_free_stateid_args *args = data;
  2857. struct compound_hdr hdr = {
  2858. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2859. };
  2860. encode_compound_hdr(xdr, req, &hdr);
  2861. encode_sequence(xdr, &args->seq_args, &hdr);
  2862. encode_free_stateid(xdr, args, &hdr);
  2863. encode_nops(&hdr);
  2864. }
  2865. #endif /* CONFIG_NFS_V4_1 */
  2866. static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
  2867. {
  2868. ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string,
  2869. NFS4_OPAQUE_LIMIT);
  2870. if (unlikely(ret < 0))
  2871. return -EIO;
  2872. *len = ret;
  2873. return 0;
  2874. }
  2875. static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
  2876. {
  2877. __be32 *p;
  2878. p = xdr_inline_decode(xdr, 8);
  2879. if (unlikely(!p))
  2880. return -EIO;
  2881. hdr->status = be32_to_cpup(p++);
  2882. hdr->taglen = be32_to_cpup(p);
  2883. p = xdr_inline_decode(xdr, hdr->taglen + 4);
  2884. if (unlikely(!p))
  2885. return -EIO;
  2886. hdr->tag = (char *)p;
  2887. p += XDR_QUADLEN(hdr->taglen);
  2888. hdr->nops = be32_to_cpup(p);
  2889. if (unlikely(hdr->nops < 1))
  2890. return nfs4_stat_to_errno(hdr->status);
  2891. return 0;
  2892. }
  2893. static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
  2894. int *nfs_retval)
  2895. {
  2896. __be32 *p;
  2897. uint32_t opnum;
  2898. int32_t nfserr;
  2899. p = xdr_inline_decode(xdr, 8);
  2900. if (unlikely(!p))
  2901. goto out_overflow;
  2902. opnum = be32_to_cpup(p++);
  2903. if (unlikely(opnum != expected))
  2904. goto out_bad_operation;
  2905. if (unlikely(*p != cpu_to_be32(NFS_OK)))
  2906. goto out_status;
  2907. *nfs_retval = 0;
  2908. return true;
  2909. out_status:
  2910. nfserr = be32_to_cpup(p);
  2911. trace_nfs4_xdr_status(xdr, opnum, nfserr);
  2912. *nfs_retval = nfs4_stat_to_errno(nfserr);
  2913. return true;
  2914. out_bad_operation:
  2915. dprintk("nfs: Server returned operation"
  2916. " %d but we issued a request for %d\n",
  2917. opnum, expected);
  2918. *nfs_retval = -EREMOTEIO;
  2919. return false;
  2920. out_overflow:
  2921. *nfs_retval = -EIO;
  2922. return false;
  2923. }
  2924. static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
  2925. {
  2926. int retval;
  2927. __decode_op_hdr(xdr, expected, &retval);
  2928. return retval;
  2929. }
  2930. /* Dummy routine */
  2931. static int decode_ace(struct xdr_stream *xdr, void *ace)
  2932. {
  2933. __be32 *p;
  2934. unsigned int strlen;
  2935. char *str;
  2936. p = xdr_inline_decode(xdr, 12);
  2937. if (unlikely(!p))
  2938. return -EIO;
  2939. return decode_opaque_inline(xdr, &strlen, &str);
  2940. }
  2941. static ssize_t
  2942. decode_bitmap4(struct xdr_stream *xdr, uint32_t *bitmap, size_t sz)
  2943. {
  2944. ssize_t ret;
  2945. ret = xdr_stream_decode_uint32_array(xdr, bitmap, sz);
  2946. if (likely(ret >= 0))
  2947. return ret;
  2948. if (ret != -EMSGSIZE)
  2949. return -EIO;
  2950. return sz;
  2951. }
  2952. static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
  2953. {
  2954. ssize_t ret;
  2955. ret = decode_bitmap4(xdr, bitmap, 3);
  2956. return ret < 0 ? ret : 0;
  2957. }
  2958. static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
  2959. {
  2960. __be32 *p;
  2961. p = xdr_inline_decode(xdr, 4);
  2962. if (unlikely(!p))
  2963. return -EIO;
  2964. *attrlen = be32_to_cpup(p);
  2965. *savep = xdr_stream_pos(xdr);
  2966. return 0;
  2967. }
  2968. static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
  2969. {
  2970. if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
  2971. int ret;
  2972. ret = decode_attr_bitmap(xdr, bitmask);
  2973. if (unlikely(ret < 0))
  2974. return ret;
  2975. bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
  2976. } else
  2977. bitmask[0] = bitmask[1] = bitmask[2] = 0;
  2978. dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
  2979. bitmask[0], bitmask[1], bitmask[2]);
  2980. return 0;
  2981. }
  2982. static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
  2983. {
  2984. __be32 *p;
  2985. int ret = 0;
  2986. *type = 0;
  2987. if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
  2988. return -EIO;
  2989. if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
  2990. p = xdr_inline_decode(xdr, 4);
  2991. if (unlikely(!p))
  2992. return -EIO;
  2993. *type = be32_to_cpup(p);
  2994. if (*type < NF4REG || *type > NF4NAMEDATTR) {
  2995. dprintk("%s: bad type %d\n", __func__, *type);
  2996. return -EIO;
  2997. }
  2998. bitmap[0] &= ~FATTR4_WORD0_TYPE;
  2999. ret = NFS_ATTR_FATTR_TYPE;
  3000. }
  3001. dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
  3002. return ret;
  3003. }
  3004. static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
  3005. uint32_t *bitmap, uint32_t *type)
  3006. {
  3007. __be32 *p;
  3008. *type = 0;
  3009. if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
  3010. return -EIO;
  3011. if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
  3012. p = xdr_inline_decode(xdr, 4);
  3013. if (unlikely(!p))
  3014. return -EIO;
  3015. *type = be32_to_cpup(p);
  3016. bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
  3017. }
  3018. dprintk("%s: expire type=0x%x\n", __func__, *type);
  3019. return 0;
  3020. }
  3021. static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
  3022. {
  3023. __be32 *p;
  3024. int ret = 0;
  3025. *change = 0;
  3026. if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
  3027. return -EIO;
  3028. if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
  3029. p = xdr_inline_decode(xdr, 8);
  3030. if (unlikely(!p))
  3031. return -EIO;
  3032. xdr_decode_hyper(p, change);
  3033. bitmap[0] &= ~FATTR4_WORD0_CHANGE;
  3034. ret = NFS_ATTR_FATTR_CHANGE;
  3035. }
  3036. dprintk("%s: change attribute=%Lu\n", __func__,
  3037. (unsigned long long)*change);
  3038. return ret;
  3039. }
  3040. static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
  3041. {
  3042. __be32 *p;
  3043. int ret = 0;
  3044. *size = 0;
  3045. if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
  3046. return -EIO;
  3047. if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
  3048. p = xdr_inline_decode(xdr, 8);
  3049. if (unlikely(!p))
  3050. return -EIO;
  3051. xdr_decode_hyper(p, size);
  3052. bitmap[0] &= ~FATTR4_WORD0_SIZE;
  3053. ret = NFS_ATTR_FATTR_SIZE;
  3054. }
  3055. dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
  3056. return ret;
  3057. }
  3058. static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3059. {
  3060. __be32 *p;
  3061. *res = 0;
  3062. if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
  3063. return -EIO;
  3064. if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
  3065. p = xdr_inline_decode(xdr, 4);
  3066. if (unlikely(!p))
  3067. return -EIO;
  3068. *res = be32_to_cpup(p);
  3069. bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
  3070. }
  3071. dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
  3072. return 0;
  3073. }
  3074. static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3075. {
  3076. __be32 *p;
  3077. *res = 0;
  3078. if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
  3079. return -EIO;
  3080. if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
  3081. p = xdr_inline_decode(xdr, 4);
  3082. if (unlikely(!p))
  3083. return -EIO;
  3084. *res = be32_to_cpup(p);
  3085. bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
  3086. }
  3087. dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
  3088. return 0;
  3089. }
  3090. static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
  3091. {
  3092. __be32 *p;
  3093. int ret = 0;
  3094. fsid->major = 0;
  3095. fsid->minor = 0;
  3096. if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
  3097. return -EIO;
  3098. if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
  3099. p = xdr_inline_decode(xdr, 16);
  3100. if (unlikely(!p))
  3101. return -EIO;
  3102. p = xdr_decode_hyper(p, &fsid->major);
  3103. xdr_decode_hyper(p, &fsid->minor);
  3104. bitmap[0] &= ~FATTR4_WORD0_FSID;
  3105. ret = NFS_ATTR_FATTR_FSID;
  3106. }
  3107. dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
  3108. (unsigned long long)fsid->major,
  3109. (unsigned long long)fsid->minor);
  3110. return ret;
  3111. }
  3112. static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3113. {
  3114. __be32 *p;
  3115. *res = 60;
  3116. if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
  3117. return -EIO;
  3118. if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
  3119. p = xdr_inline_decode(xdr, 4);
  3120. if (unlikely(!p))
  3121. return -EIO;
  3122. *res = be32_to_cpup(p);
  3123. bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
  3124. }
  3125. dprintk("%s: lease time=%u\n", __func__, (unsigned int)*res);
  3126. return 0;
  3127. }
  3128. static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
  3129. {
  3130. __be32 *p;
  3131. if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
  3132. return -EIO;
  3133. if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
  3134. p = xdr_inline_decode(xdr, 4);
  3135. if (unlikely(!p))
  3136. return -EIO;
  3137. bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
  3138. *res = -be32_to_cpup(p);
  3139. }
  3140. return 0;
  3141. }
  3142. static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
  3143. uint32_t *bitmap, uint32_t *bitmask)
  3144. {
  3145. if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
  3146. int ret;
  3147. ret = decode_attr_bitmap(xdr, bitmask);
  3148. if (unlikely(ret < 0))
  3149. return ret;
  3150. bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
  3151. } else
  3152. bitmask[0] = bitmask[1] = bitmask[2] = 0;
  3153. dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
  3154. bitmask[0], bitmask[1], bitmask[2]);
  3155. return 0;
  3156. }
  3157. static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
  3158. {
  3159. __be32 *p;
  3160. u32 len;
  3161. if (fh != NULL)
  3162. memset(fh, 0, sizeof(*fh));
  3163. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
  3164. return -EIO;
  3165. if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
  3166. p = xdr_inline_decode(xdr, 4);
  3167. if (unlikely(!p))
  3168. return -EIO;
  3169. len = be32_to_cpup(p);
  3170. if (len > NFS4_FHSIZE)
  3171. return -EIO;
  3172. p = xdr_inline_decode(xdr, len);
  3173. if (unlikely(!p))
  3174. return -EIO;
  3175. if (fh != NULL) {
  3176. memcpy(fh->data, p, len);
  3177. fh->size = len;
  3178. }
  3179. bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
  3180. }
  3181. return 0;
  3182. }
  3183. static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3184. {
  3185. __be32 *p;
  3186. *res = 0;
  3187. if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
  3188. return -EIO;
  3189. if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
  3190. p = xdr_inline_decode(xdr, 4);
  3191. if (unlikely(!p))
  3192. return -EIO;
  3193. *res = be32_to_cpup(p);
  3194. bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
  3195. }
  3196. dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
  3197. return 0;
  3198. }
  3199. static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
  3200. {
  3201. __be32 *p;
  3202. int ret = 0;
  3203. *fileid = 0;
  3204. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
  3205. return -EIO;
  3206. if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
  3207. p = xdr_inline_decode(xdr, 8);
  3208. if (unlikely(!p))
  3209. return -EIO;
  3210. xdr_decode_hyper(p, fileid);
  3211. bitmap[0] &= ~FATTR4_WORD0_FILEID;
  3212. ret = NFS_ATTR_FATTR_FILEID;
  3213. }
  3214. dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
  3215. return ret;
  3216. }
  3217. static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
  3218. {
  3219. __be32 *p;
  3220. int ret = 0;
  3221. *fileid = 0;
  3222. if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
  3223. return -EIO;
  3224. if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
  3225. p = xdr_inline_decode(xdr, 8);
  3226. if (unlikely(!p))
  3227. return -EIO;
  3228. xdr_decode_hyper(p, fileid);
  3229. bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
  3230. ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
  3231. }
  3232. dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
  3233. return ret;
  3234. }
  3235. static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3236. {
  3237. __be32 *p;
  3238. int status = 0;
  3239. *res = 0;
  3240. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
  3241. return -EIO;
  3242. if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
  3243. p = xdr_inline_decode(xdr, 8);
  3244. if (unlikely(!p))
  3245. return -EIO;
  3246. xdr_decode_hyper(p, res);
  3247. bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
  3248. }
  3249. dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
  3250. return status;
  3251. }
  3252. static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3253. {
  3254. __be32 *p;
  3255. int status = 0;
  3256. *res = 0;
  3257. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
  3258. return -EIO;
  3259. if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
  3260. p = xdr_inline_decode(xdr, 8);
  3261. if (unlikely(!p))
  3262. return -EIO;
  3263. xdr_decode_hyper(p, res);
  3264. bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
  3265. }
  3266. dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
  3267. return status;
  3268. }
  3269. static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3270. {
  3271. __be32 *p;
  3272. int status = 0;
  3273. *res = 0;
  3274. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
  3275. return -EIO;
  3276. if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
  3277. p = xdr_inline_decode(xdr, 8);
  3278. if (unlikely(!p))
  3279. return -EIO;
  3280. xdr_decode_hyper(p, res);
  3281. bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
  3282. }
  3283. dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
  3284. return status;
  3285. }
  3286. static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
  3287. {
  3288. u32 n;
  3289. __be32 *p;
  3290. int status = 0;
  3291. p = xdr_inline_decode(xdr, 4);
  3292. if (unlikely(!p))
  3293. return -EIO;
  3294. n = be32_to_cpup(p);
  3295. if (n == 0)
  3296. goto root_path;
  3297. dprintk("pathname4: ");
  3298. if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
  3299. dprintk("cannot parse %d components in path\n", n);
  3300. goto out_eio;
  3301. }
  3302. for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
  3303. struct nfs4_string *component = &path->components[path->ncomponents];
  3304. status = decode_opaque_inline(xdr, &component->len, &component->data);
  3305. if (unlikely(status != 0))
  3306. goto out_eio;
  3307. ifdebug (XDR)
  3308. pr_cont("%s%.*s ",
  3309. (path->ncomponents != n ? "/ " : ""),
  3310. component->len, component->data);
  3311. }
  3312. out:
  3313. return status;
  3314. root_path:
  3315. /* a root pathname is sent as a zero component4 */
  3316. path->ncomponents = 1;
  3317. path->components[0].len=0;
  3318. path->components[0].data=NULL;
  3319. dprintk("pathname4: /\n");
  3320. goto out;
  3321. out_eio:
  3322. dprintk(" status %d", status);
  3323. status = -EIO;
  3324. goto out;
  3325. }
  3326. static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
  3327. {
  3328. int n;
  3329. __be32 *p;
  3330. int status = -EIO;
  3331. if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
  3332. goto out;
  3333. status = 0;
  3334. if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
  3335. goto out;
  3336. bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
  3337. status = -EIO;
  3338. /* Ignore borken servers that return unrequested attrs */
  3339. if (unlikely(res == NULL))
  3340. goto out;
  3341. dprintk("%s: fsroot:\n", __func__);
  3342. status = decode_pathname(xdr, &res->fs_path);
  3343. if (unlikely(status != 0))
  3344. goto out;
  3345. p = xdr_inline_decode(xdr, 4);
  3346. if (unlikely(!p))
  3347. goto out_eio;
  3348. n = be32_to_cpup(p);
  3349. for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
  3350. u32 m;
  3351. struct nfs4_fs_location *loc;
  3352. if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
  3353. break;
  3354. loc = &res->locations[res->nlocations];
  3355. p = xdr_inline_decode(xdr, 4);
  3356. if (unlikely(!p))
  3357. goto out_eio;
  3358. m = be32_to_cpup(p);
  3359. dprintk("%s: servers:\n", __func__);
  3360. for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
  3361. struct nfs4_string *server;
  3362. if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
  3363. unsigned int i;
  3364. dprintk("%s: using first %u of %u servers "
  3365. "returned for location %u\n",
  3366. __func__,
  3367. NFS4_FS_LOCATION_MAXSERVERS,
  3368. m, res->nlocations);
  3369. for (i = loc->nservers; i < m; i++) {
  3370. unsigned int len;
  3371. char *data;
  3372. status = decode_opaque_inline(xdr, &len, &data);
  3373. if (unlikely(status != 0))
  3374. goto out_eio;
  3375. }
  3376. break;
  3377. }
  3378. server = &loc->servers[loc->nservers];
  3379. status = decode_opaque_inline(xdr, &server->len, &server->data);
  3380. if (unlikely(status != 0))
  3381. goto out_eio;
  3382. dprintk("%s ", server->data);
  3383. }
  3384. status = decode_pathname(xdr, &loc->rootpath);
  3385. if (unlikely(status != 0))
  3386. goto out_eio;
  3387. }
  3388. if (res->nlocations != 0)
  3389. status = NFS_ATTR_FATTR_V4_LOCATIONS;
  3390. out:
  3391. dprintk("%s: fs_locations done, error = %d\n", __func__, status);
  3392. return status;
  3393. out_eio:
  3394. status = -EIO;
  3395. goto out;
  3396. }
  3397. static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3398. {
  3399. __be32 *p;
  3400. int status = 0;
  3401. *res = 0;
  3402. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
  3403. return -EIO;
  3404. if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
  3405. p = xdr_inline_decode(xdr, 8);
  3406. if (unlikely(!p))
  3407. return -EIO;
  3408. xdr_decode_hyper(p, res);
  3409. bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
  3410. }
  3411. dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
  3412. return status;
  3413. }
  3414. static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
  3415. {
  3416. __be32 *p;
  3417. int status = 0;
  3418. *maxlink = 1;
  3419. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
  3420. return -EIO;
  3421. if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
  3422. p = xdr_inline_decode(xdr, 4);
  3423. if (unlikely(!p))
  3424. return -EIO;
  3425. *maxlink = be32_to_cpup(p);
  3426. bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
  3427. }
  3428. dprintk("%s: maxlink=%u\n", __func__, *maxlink);
  3429. return status;
  3430. }
  3431. static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
  3432. {
  3433. __be32 *p;
  3434. int status = 0;
  3435. *maxname = 1024;
  3436. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
  3437. return -EIO;
  3438. if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
  3439. p = xdr_inline_decode(xdr, 4);
  3440. if (unlikely(!p))
  3441. return -EIO;
  3442. *maxname = be32_to_cpup(p);
  3443. bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
  3444. }
  3445. dprintk("%s: maxname=%u\n", __func__, *maxname);
  3446. return status;
  3447. }
  3448. static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3449. {
  3450. __be32 *p;
  3451. int status = 0;
  3452. *res = 1024;
  3453. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
  3454. return -EIO;
  3455. if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
  3456. uint64_t maxread;
  3457. p = xdr_inline_decode(xdr, 8);
  3458. if (unlikely(!p))
  3459. return -EIO;
  3460. xdr_decode_hyper(p, &maxread);
  3461. if (maxread > 0x7FFFFFFF)
  3462. maxread = 0x7FFFFFFF;
  3463. *res = (uint32_t)maxread;
  3464. bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
  3465. }
  3466. dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
  3467. return status;
  3468. }
  3469. static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3470. {
  3471. __be32 *p;
  3472. int status = 0;
  3473. *res = 1024;
  3474. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
  3475. return -EIO;
  3476. if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
  3477. uint64_t maxwrite;
  3478. p = xdr_inline_decode(xdr, 8);
  3479. if (unlikely(!p))
  3480. return -EIO;
  3481. xdr_decode_hyper(p, &maxwrite);
  3482. if (maxwrite > 0x7FFFFFFF)
  3483. maxwrite = 0x7FFFFFFF;
  3484. *res = (uint32_t)maxwrite;
  3485. bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
  3486. }
  3487. dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
  3488. return status;
  3489. }
  3490. static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
  3491. {
  3492. uint32_t tmp;
  3493. __be32 *p;
  3494. int ret = 0;
  3495. *mode = 0;
  3496. if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
  3497. return -EIO;
  3498. if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
  3499. p = xdr_inline_decode(xdr, 4);
  3500. if (unlikely(!p))
  3501. return -EIO;
  3502. tmp = be32_to_cpup(p);
  3503. *mode = tmp & ~S_IFMT;
  3504. bitmap[1] &= ~FATTR4_WORD1_MODE;
  3505. ret = NFS_ATTR_FATTR_MODE;
  3506. }
  3507. dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
  3508. return ret;
  3509. }
  3510. static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
  3511. {
  3512. __be32 *p;
  3513. int ret = 0;
  3514. *nlink = 1;
  3515. if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
  3516. return -EIO;
  3517. if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
  3518. p = xdr_inline_decode(xdr, 4);
  3519. if (unlikely(!p))
  3520. return -EIO;
  3521. *nlink = be32_to_cpup(p);
  3522. bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
  3523. ret = NFS_ATTR_FATTR_NLINK;
  3524. }
  3525. dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
  3526. return ret;
  3527. }
  3528. static ssize_t decode_nfs4_string(struct xdr_stream *xdr,
  3529. struct nfs4_string *name, gfp_t gfp_flags)
  3530. {
  3531. ssize_t ret;
  3532. ret = xdr_stream_decode_string_dup(xdr, &name->data,
  3533. XDR_MAX_NETOBJ, gfp_flags);
  3534. name->len = 0;
  3535. if (ret > 0)
  3536. name->len = ret;
  3537. return ret;
  3538. }
  3539. static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
  3540. const struct nfs_server *server, kuid_t *uid,
  3541. struct nfs4_string *owner_name)
  3542. {
  3543. ssize_t len;
  3544. char *p;
  3545. *uid = make_kuid(&init_user_ns, -2);
  3546. if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
  3547. return -EIO;
  3548. if (!(bitmap[1] & FATTR4_WORD1_OWNER))
  3549. return 0;
  3550. bitmap[1] &= ~FATTR4_WORD1_OWNER;
  3551. if (owner_name != NULL) {
  3552. len = decode_nfs4_string(xdr, owner_name, GFP_NOIO);
  3553. if (len <= 0)
  3554. goto out;
  3555. dprintk("%s: name=%s\n", __func__, owner_name->data);
  3556. return NFS_ATTR_FATTR_OWNER_NAME;
  3557. } else {
  3558. len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
  3559. XDR_MAX_NETOBJ);
  3560. if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0)
  3561. goto out;
  3562. dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
  3563. return NFS_ATTR_FATTR_OWNER;
  3564. }
  3565. out:
  3566. if (len == -EBADMSG)
  3567. return -EIO;
  3568. return 0;
  3569. }
  3570. static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
  3571. const struct nfs_server *server, kgid_t *gid,
  3572. struct nfs4_string *group_name)
  3573. {
  3574. ssize_t len;
  3575. char *p;
  3576. *gid = make_kgid(&init_user_ns, -2);
  3577. if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
  3578. return -EIO;
  3579. if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP))
  3580. return 0;
  3581. bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
  3582. if (group_name != NULL) {
  3583. len = decode_nfs4_string(xdr, group_name, GFP_NOIO);
  3584. if (len <= 0)
  3585. goto out;
  3586. dprintk("%s: name=%s\n", __func__, group_name->data);
  3587. return NFS_ATTR_FATTR_GROUP_NAME;
  3588. } else {
  3589. len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
  3590. XDR_MAX_NETOBJ);
  3591. if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0)
  3592. goto out;
  3593. dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
  3594. return NFS_ATTR_FATTR_GROUP;
  3595. }
  3596. out:
  3597. if (len == -EBADMSG)
  3598. return -EIO;
  3599. return 0;
  3600. }
  3601. static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
  3602. {
  3603. uint32_t major = 0, minor = 0;
  3604. __be32 *p;
  3605. int ret = 0;
  3606. *rdev = MKDEV(0,0);
  3607. if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
  3608. return -EIO;
  3609. if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
  3610. dev_t tmp;
  3611. p = xdr_inline_decode(xdr, 8);
  3612. if (unlikely(!p))
  3613. return -EIO;
  3614. major = be32_to_cpup(p++);
  3615. minor = be32_to_cpup(p);
  3616. tmp = MKDEV(major, minor);
  3617. if (MAJOR(tmp) == major && MINOR(tmp) == minor)
  3618. *rdev = tmp;
  3619. bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
  3620. ret = NFS_ATTR_FATTR_RDEV;
  3621. }
  3622. dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
  3623. return ret;
  3624. }
  3625. static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3626. {
  3627. __be32 *p;
  3628. int status = 0;
  3629. *res = 0;
  3630. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
  3631. return -EIO;
  3632. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
  3633. p = xdr_inline_decode(xdr, 8);
  3634. if (unlikely(!p))
  3635. return -EIO;
  3636. xdr_decode_hyper(p, res);
  3637. bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
  3638. }
  3639. dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
  3640. return status;
  3641. }
  3642. static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3643. {
  3644. __be32 *p;
  3645. int status = 0;
  3646. *res = 0;
  3647. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
  3648. return -EIO;
  3649. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
  3650. p = xdr_inline_decode(xdr, 8);
  3651. if (unlikely(!p))
  3652. return -EIO;
  3653. xdr_decode_hyper(p, res);
  3654. bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
  3655. }
  3656. dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
  3657. return status;
  3658. }
  3659. static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3660. {
  3661. __be32 *p;
  3662. int status = 0;
  3663. *res = 0;
  3664. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
  3665. return -EIO;
  3666. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
  3667. p = xdr_inline_decode(xdr, 8);
  3668. if (unlikely(!p))
  3669. return -EIO;
  3670. xdr_decode_hyper(p, res);
  3671. bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
  3672. }
  3673. dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
  3674. return status;
  3675. }
  3676. static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
  3677. {
  3678. __be32 *p;
  3679. int ret = 0;
  3680. *used = 0;
  3681. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
  3682. return -EIO;
  3683. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
  3684. p = xdr_inline_decode(xdr, 8);
  3685. if (unlikely(!p))
  3686. return -EIO;
  3687. xdr_decode_hyper(p, used);
  3688. bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
  3689. ret = NFS_ATTR_FATTR_SPACE_USED;
  3690. }
  3691. dprintk("%s: space used=%Lu\n", __func__,
  3692. (unsigned long long)*used);
  3693. return ret;
  3694. }
  3695. static __be32 *
  3696. xdr_decode_nfstime4(__be32 *p, struct timespec64 *t)
  3697. {
  3698. __u64 sec;
  3699. p = xdr_decode_hyper(p, &sec);
  3700. t-> tv_sec = sec;
  3701. t->tv_nsec = be32_to_cpup(p++);
  3702. return p;
  3703. }
  3704. static int decode_attr_time(struct xdr_stream *xdr, struct timespec64 *time)
  3705. {
  3706. __be32 *p;
  3707. p = xdr_inline_decode(xdr, nfstime4_maxsz << 2);
  3708. if (unlikely(!p))
  3709. return -EIO;
  3710. xdr_decode_nfstime4(p, time);
  3711. return 0;
  3712. }
  3713. static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
  3714. {
  3715. int status = 0;
  3716. time->tv_sec = 0;
  3717. time->tv_nsec = 0;
  3718. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
  3719. return -EIO;
  3720. if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
  3721. status = decode_attr_time(xdr, time);
  3722. if (status == 0)
  3723. status = NFS_ATTR_FATTR_ATIME;
  3724. bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
  3725. }
  3726. dprintk("%s: atime=%lld\n", __func__, time->tv_sec);
  3727. return status;
  3728. }
  3729. static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
  3730. {
  3731. int status = 0;
  3732. time->tv_sec = 0;
  3733. time->tv_nsec = 0;
  3734. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
  3735. return -EIO;
  3736. if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
  3737. status = decode_attr_time(xdr, time);
  3738. if (status == 0)
  3739. status = NFS_ATTR_FATTR_CTIME;
  3740. bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
  3741. }
  3742. dprintk("%s: ctime=%lld\n", __func__, time->tv_sec);
  3743. return status;
  3744. }
  3745. static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
  3746. struct timespec64 *time)
  3747. {
  3748. int status = 0;
  3749. time->tv_sec = 0;
  3750. time->tv_nsec = 0;
  3751. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
  3752. return -EIO;
  3753. if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
  3754. status = decode_attr_time(xdr, time);
  3755. bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
  3756. }
  3757. dprintk("%s: time_delta=%lld %ld\n", __func__, time->tv_sec,
  3758. time->tv_nsec);
  3759. return status;
  3760. }
  3761. static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
  3762. struct nfs4_label *label)
  3763. {
  3764. uint32_t pi = 0;
  3765. uint32_t lfs = 0;
  3766. __u32 len;
  3767. __be32 *p;
  3768. int status = 0;
  3769. if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
  3770. return -EIO;
  3771. if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
  3772. p = xdr_inline_decode(xdr, 4);
  3773. if (unlikely(!p))
  3774. return -EIO;
  3775. lfs = be32_to_cpup(p++);
  3776. p = xdr_inline_decode(xdr, 4);
  3777. if (unlikely(!p))
  3778. return -EIO;
  3779. pi = be32_to_cpup(p++);
  3780. p = xdr_inline_decode(xdr, 4);
  3781. if (unlikely(!p))
  3782. return -EIO;
  3783. len = be32_to_cpup(p++);
  3784. p = xdr_inline_decode(xdr, len);
  3785. if (unlikely(!p))
  3786. return -EIO;
  3787. if (len < NFS4_MAXLABELLEN) {
  3788. if (label) {
  3789. if (label->len) {
  3790. if (label->len < len)
  3791. return -ERANGE;
  3792. memcpy(label->label, p, len);
  3793. }
  3794. label->len = len;
  3795. label->pi = pi;
  3796. label->lfs = lfs;
  3797. status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
  3798. }
  3799. bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
  3800. } else
  3801. printk(KERN_WARNING "%s: label too long (%u)!\n",
  3802. __func__, len);
  3803. if (label && label->label)
  3804. dprintk("%s: label=%.*s, len=%d, PI=%d, LFS=%d\n",
  3805. __func__, label->len, (char *)label->label,
  3806. label->len, label->pi, label->lfs);
  3807. }
  3808. return status;
  3809. }
  3810. static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
  3811. {
  3812. int status = 0;
  3813. time->tv_sec = 0;
  3814. time->tv_nsec = 0;
  3815. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
  3816. return -EIO;
  3817. if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
  3818. status = decode_attr_time(xdr, time);
  3819. if (status == 0)
  3820. status = NFS_ATTR_FATTR_MTIME;
  3821. bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
  3822. }
  3823. dprintk("%s: mtime=%lld\n", __func__, time->tv_sec);
  3824. return status;
  3825. }
  3826. static int decode_attr_xattrsupport(struct xdr_stream *xdr, uint32_t *bitmap,
  3827. uint32_t *res)
  3828. {
  3829. __be32 *p;
  3830. *res = 0;
  3831. if (unlikely(bitmap[2] & (FATTR4_WORD2_XATTR_SUPPORT - 1U)))
  3832. return -EIO;
  3833. if (likely(bitmap[2] & FATTR4_WORD2_XATTR_SUPPORT)) {
  3834. p = xdr_inline_decode(xdr, 4);
  3835. if (unlikely(!p))
  3836. return -EIO;
  3837. *res = be32_to_cpup(p);
  3838. bitmap[2] &= ~FATTR4_WORD2_XATTR_SUPPORT;
  3839. }
  3840. dprintk("%s: XATTR support=%s\n", __func__,
  3841. *res == 0 ? "false" : "true");
  3842. return 0;
  3843. }
  3844. static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
  3845. {
  3846. unsigned int attrwords = XDR_QUADLEN(attrlen);
  3847. unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
  3848. if (unlikely(attrwords != nwords)) {
  3849. dprintk("%s: server returned incorrect attribute length: "
  3850. "%u %c %u\n",
  3851. __func__,
  3852. attrwords << 2,
  3853. (attrwords < nwords) ? '<' : '>',
  3854. nwords << 2);
  3855. return -EIO;
  3856. }
  3857. return 0;
  3858. }
  3859. static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  3860. {
  3861. __be32 *p;
  3862. p = xdr_inline_decode(xdr, 20);
  3863. if (unlikely(!p))
  3864. return -EIO;
  3865. cinfo->atomic = be32_to_cpup(p++);
  3866. p = xdr_decode_hyper(p, &cinfo->before);
  3867. xdr_decode_hyper(p, &cinfo->after);
  3868. return 0;
  3869. }
  3870. static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
  3871. {
  3872. __be32 *p;
  3873. uint32_t supp, acc;
  3874. int status;
  3875. status = decode_op_hdr(xdr, OP_ACCESS);
  3876. if (status)
  3877. return status;
  3878. p = xdr_inline_decode(xdr, 8);
  3879. if (unlikely(!p))
  3880. return -EIO;
  3881. supp = be32_to_cpup(p++);
  3882. acc = be32_to_cpup(p);
  3883. *supported = supp;
  3884. *access = acc;
  3885. return 0;
  3886. }
  3887. static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
  3888. {
  3889. ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
  3890. if (unlikely(ret < 0))
  3891. return -EIO;
  3892. return 0;
  3893. }
  3894. static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  3895. {
  3896. return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
  3897. }
  3898. static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  3899. {
  3900. stateid->type = NFS4_OPEN_STATEID_TYPE;
  3901. return decode_stateid(xdr, stateid);
  3902. }
  3903. static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  3904. {
  3905. stateid->type = NFS4_LOCK_STATEID_TYPE;
  3906. return decode_stateid(xdr, stateid);
  3907. }
  3908. static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  3909. {
  3910. stateid->type = NFS4_DELEGATION_STATEID_TYPE;
  3911. return decode_stateid(xdr, stateid);
  3912. }
  3913. static int decode_invalid_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  3914. {
  3915. nfs4_stateid dummy;
  3916. nfs4_stateid_copy(stateid, &invalid_stateid);
  3917. return decode_stateid(xdr, &dummy);
  3918. }
  3919. static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
  3920. {
  3921. int status;
  3922. status = decode_op_hdr(xdr, OP_CLOSE);
  3923. if (status != -EIO)
  3924. nfs_increment_open_seqid(status, res->seqid);
  3925. if (!status)
  3926. status = decode_invalid_stateid(xdr, &res->stateid);
  3927. return status;
  3928. }
  3929. static int decode_verifier(struct xdr_stream *xdr, void *verifier)
  3930. {
  3931. return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
  3932. }
  3933. static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
  3934. {
  3935. return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
  3936. }
  3937. static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
  3938. {
  3939. struct nfs_writeverf *verf = res->verf;
  3940. int status;
  3941. status = decode_op_hdr(xdr, OP_COMMIT);
  3942. if (!status)
  3943. status = decode_write_verifier(xdr, &verf->verifier);
  3944. if (!status)
  3945. verf->committed = NFS_FILE_SYNC;
  3946. return status;
  3947. }
  3948. static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  3949. {
  3950. __be32 *p;
  3951. uint32_t bmlen;
  3952. int status;
  3953. status = decode_op_hdr(xdr, OP_CREATE);
  3954. if (status)
  3955. return status;
  3956. if ((status = decode_change_info(xdr, cinfo)))
  3957. return status;
  3958. p = xdr_inline_decode(xdr, 4);
  3959. if (unlikely(!p))
  3960. return -EIO;
  3961. bmlen = be32_to_cpup(p);
  3962. p = xdr_inline_decode(xdr, bmlen << 2);
  3963. if (likely(p))
  3964. return 0;
  3965. return -EIO;
  3966. }
  3967. static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
  3968. {
  3969. unsigned int savep;
  3970. uint32_t attrlen, bitmap[3] = {0};
  3971. int status;
  3972. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  3973. goto xdr_error;
  3974. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  3975. goto xdr_error;
  3976. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  3977. goto xdr_error;
  3978. if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
  3979. goto xdr_error;
  3980. if ((status = decode_attr_fh_expire_type(xdr, bitmap,
  3981. &res->fh_expire_type)) != 0)
  3982. goto xdr_error;
  3983. if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
  3984. goto xdr_error;
  3985. if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
  3986. goto xdr_error;
  3987. if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
  3988. goto xdr_error;
  3989. if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
  3990. res->exclcreat_bitmask)) != 0)
  3991. goto xdr_error;
  3992. status = verify_attr_len(xdr, savep, attrlen);
  3993. xdr_error:
  3994. dprintk("%s: xdr returned %d!\n", __func__, -status);
  3995. return status;
  3996. }
  3997. static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
  3998. {
  3999. unsigned int savep;
  4000. uint32_t attrlen, bitmap[3] = {0};
  4001. int status;
  4002. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  4003. goto xdr_error;
  4004. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  4005. goto xdr_error;
  4006. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  4007. goto xdr_error;
  4008. if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
  4009. goto xdr_error;
  4010. if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
  4011. goto xdr_error;
  4012. if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
  4013. goto xdr_error;
  4014. status = -EIO;
  4015. if (unlikely(bitmap[0]))
  4016. goto xdr_error;
  4017. if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
  4018. goto xdr_error;
  4019. if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
  4020. goto xdr_error;
  4021. if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
  4022. goto xdr_error;
  4023. status = verify_attr_len(xdr, savep, attrlen);
  4024. xdr_error:
  4025. dprintk("%s: xdr returned %d!\n", __func__, -status);
  4026. return status;
  4027. }
  4028. static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
  4029. {
  4030. unsigned int savep;
  4031. uint32_t attrlen, bitmap[3] = {0};
  4032. int status;
  4033. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  4034. goto xdr_error;
  4035. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  4036. goto xdr_error;
  4037. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  4038. goto xdr_error;
  4039. if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
  4040. goto xdr_error;
  4041. if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
  4042. goto xdr_error;
  4043. status = verify_attr_len(xdr, savep, attrlen);
  4044. xdr_error:
  4045. dprintk("%s: xdr returned %d!\n", __func__, -status);
  4046. return status;
  4047. }
  4048. static int decode_threshold_hint(struct xdr_stream *xdr,
  4049. uint32_t *bitmap,
  4050. uint64_t *res,
  4051. uint32_t hint_bit)
  4052. {
  4053. __be32 *p;
  4054. *res = 0;
  4055. if (likely(bitmap[0] & hint_bit)) {
  4056. p = xdr_inline_decode(xdr, 8);
  4057. if (unlikely(!p))
  4058. return -EIO;
  4059. xdr_decode_hyper(p, res);
  4060. }
  4061. return 0;
  4062. }
  4063. static int decode_first_threshold_item4(struct xdr_stream *xdr,
  4064. struct nfs4_threshold *res)
  4065. {
  4066. __be32 *p;
  4067. unsigned int savep;
  4068. uint32_t bitmap[3] = {0,}, attrlen;
  4069. int status;
  4070. /* layout type */
  4071. p = xdr_inline_decode(xdr, 4);
  4072. if (unlikely(!p))
  4073. return -EIO;
  4074. res->l_type = be32_to_cpup(p);
  4075. /* thi_hintset bitmap */
  4076. status = decode_attr_bitmap(xdr, bitmap);
  4077. if (status < 0)
  4078. goto xdr_error;
  4079. /* thi_hintlist length */
  4080. status = decode_attr_length(xdr, &attrlen, &savep);
  4081. if (status < 0)
  4082. goto xdr_error;
  4083. /* thi_hintlist */
  4084. status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
  4085. if (status < 0)
  4086. goto xdr_error;
  4087. status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
  4088. if (status < 0)
  4089. goto xdr_error;
  4090. status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
  4091. THRESHOLD_RD_IO);
  4092. if (status < 0)
  4093. goto xdr_error;
  4094. status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
  4095. THRESHOLD_WR_IO);
  4096. if (status < 0)
  4097. goto xdr_error;
  4098. status = verify_attr_len(xdr, savep, attrlen);
  4099. res->bm = bitmap[0];
  4100. dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
  4101. __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
  4102. res->wr_io_sz);
  4103. xdr_error:
  4104. dprintk("%s ret=%d!\n", __func__, status);
  4105. return status;
  4106. }
  4107. /*
  4108. * Thresholds on pNFS direct I/O vrs MDS I/O
  4109. */
  4110. static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
  4111. uint32_t *bitmap,
  4112. struct nfs4_threshold *res)
  4113. {
  4114. __be32 *p;
  4115. int status = 0;
  4116. uint32_t num;
  4117. if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
  4118. return -EIO;
  4119. if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
  4120. /* Did the server return an unrequested attribute? */
  4121. if (unlikely(res == NULL))
  4122. return -EREMOTEIO;
  4123. p = xdr_inline_decode(xdr, 4);
  4124. if (unlikely(!p))
  4125. return -EIO;
  4126. num = be32_to_cpup(p);
  4127. if (num == 0)
  4128. return 0;
  4129. if (num > 1)
  4130. printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
  4131. "drivers per filesystem not supported\n",
  4132. __func__);
  4133. status = decode_first_threshold_item4(xdr, res);
  4134. bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
  4135. }
  4136. return status;
  4137. }
  4138. static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
  4139. struct nfs_fattr *fattr, struct nfs_fh *fh,
  4140. struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
  4141. const struct nfs_server *server)
  4142. {
  4143. int status;
  4144. umode_t fmode = 0;
  4145. uint32_t type;
  4146. int32_t err;
  4147. status = decode_attr_type(xdr, bitmap, &type);
  4148. if (status < 0)
  4149. goto xdr_error;
  4150. fattr->mode = 0;
  4151. if (status != 0) {
  4152. fattr->mode |= nfs_type2fmt[type];
  4153. fattr->valid |= status;
  4154. }
  4155. status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
  4156. if (status < 0)
  4157. goto xdr_error;
  4158. fattr->valid |= status;
  4159. status = decode_attr_size(xdr, bitmap, &fattr->size);
  4160. if (status < 0)
  4161. goto xdr_error;
  4162. fattr->valid |= status;
  4163. status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
  4164. if (status < 0)
  4165. goto xdr_error;
  4166. fattr->valid |= status;
  4167. err = 0;
  4168. status = decode_attr_error(xdr, bitmap, &err);
  4169. if (status < 0)
  4170. goto xdr_error;
  4171. status = decode_attr_filehandle(xdr, bitmap, fh);
  4172. if (status < 0)
  4173. goto xdr_error;
  4174. status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
  4175. if (status < 0)
  4176. goto xdr_error;
  4177. fattr->valid |= status;
  4178. status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
  4179. if (status < 0)
  4180. goto xdr_error;
  4181. fattr->valid |= status;
  4182. status = -EIO;
  4183. if (unlikely(bitmap[0]))
  4184. goto xdr_error;
  4185. status = decode_attr_mode(xdr, bitmap, &fmode);
  4186. if (status < 0)
  4187. goto xdr_error;
  4188. if (status != 0) {
  4189. fattr->mode |= fmode;
  4190. fattr->valid |= status;
  4191. }
  4192. status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
  4193. if (status < 0)
  4194. goto xdr_error;
  4195. fattr->valid |= status;
  4196. status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
  4197. if (status < 0)
  4198. goto xdr_error;
  4199. fattr->valid |= status;
  4200. status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
  4201. if (status < 0)
  4202. goto xdr_error;
  4203. fattr->valid |= status;
  4204. status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
  4205. if (status < 0)
  4206. goto xdr_error;
  4207. fattr->valid |= status;
  4208. status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
  4209. if (status < 0)
  4210. goto xdr_error;
  4211. fattr->valid |= status;
  4212. status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
  4213. if (status < 0)
  4214. goto xdr_error;
  4215. fattr->valid |= status;
  4216. status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
  4217. if (status < 0)
  4218. goto xdr_error;
  4219. fattr->valid |= status;
  4220. status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
  4221. if (status < 0)
  4222. goto xdr_error;
  4223. fattr->valid |= status;
  4224. status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
  4225. if (status < 0)
  4226. goto xdr_error;
  4227. fattr->valid |= status;
  4228. status = -EIO;
  4229. if (unlikely(bitmap[1]))
  4230. goto xdr_error;
  4231. status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
  4232. if (status < 0)
  4233. goto xdr_error;
  4234. if (label) {
  4235. status = decode_attr_security_label(xdr, bitmap, label);
  4236. if (status < 0)
  4237. goto xdr_error;
  4238. fattr->valid |= status;
  4239. }
  4240. xdr_error:
  4241. dprintk("%s: xdr returned %d\n", __func__, -status);
  4242. return status;
  4243. }
  4244. static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
  4245. struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
  4246. struct nfs4_label *label, const struct nfs_server *server)
  4247. {
  4248. unsigned int savep;
  4249. uint32_t attrlen,
  4250. bitmap[3] = {0};
  4251. int status;
  4252. status = decode_op_hdr(xdr, OP_GETATTR);
  4253. if (status < 0)
  4254. goto xdr_error;
  4255. status = decode_attr_bitmap(xdr, bitmap);
  4256. if (status < 0)
  4257. goto xdr_error;
  4258. status = decode_attr_length(xdr, &attrlen, &savep);
  4259. if (status < 0)
  4260. goto xdr_error;
  4261. status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
  4262. label, server);
  4263. if (status < 0)
  4264. goto xdr_error;
  4265. status = verify_attr_len(xdr, savep, attrlen);
  4266. xdr_error:
  4267. dprintk("%s: xdr returned %d\n", __func__, -status);
  4268. return status;
  4269. }
  4270. static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
  4271. struct nfs4_label *label, const struct nfs_server *server)
  4272. {
  4273. return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
  4274. }
  4275. static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
  4276. const struct nfs_server *server)
  4277. {
  4278. return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
  4279. }
  4280. /*
  4281. * Decode potentially multiple layout types.
  4282. */
  4283. static int decode_pnfs_layout_types(struct xdr_stream *xdr,
  4284. struct nfs_fsinfo *fsinfo)
  4285. {
  4286. __be32 *p;
  4287. uint32_t i;
  4288. p = xdr_inline_decode(xdr, 4);
  4289. if (unlikely(!p))
  4290. return -EIO;
  4291. fsinfo->nlayouttypes = be32_to_cpup(p);
  4292. /* pNFS is not supported by the underlying file system */
  4293. if (fsinfo->nlayouttypes == 0)
  4294. return 0;
  4295. /* Decode and set first layout type, move xdr->p past unused types */
  4296. p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
  4297. if (unlikely(!p))
  4298. return -EIO;
  4299. /* If we get too many, then just cap it at the max */
  4300. if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
  4301. printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
  4302. __func__, fsinfo->nlayouttypes);
  4303. fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
  4304. }
  4305. for(i = 0; i < fsinfo->nlayouttypes; ++i)
  4306. fsinfo->layouttype[i] = be32_to_cpup(p++);
  4307. return 0;
  4308. }
  4309. /*
  4310. * The type of file system exported.
  4311. * Note we must ensure that layouttype is set in any non-error case.
  4312. */
  4313. static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
  4314. struct nfs_fsinfo *fsinfo)
  4315. {
  4316. int status = 0;
  4317. dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
  4318. if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
  4319. return -EIO;
  4320. if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
  4321. status = decode_pnfs_layout_types(xdr, fsinfo);
  4322. bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
  4323. }
  4324. return status;
  4325. }
  4326. /*
  4327. * The prefered block size for layout directed io
  4328. */
  4329. static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
  4330. uint32_t *res)
  4331. {
  4332. __be32 *p;
  4333. dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
  4334. *res = 0;
  4335. if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
  4336. p = xdr_inline_decode(xdr, 4);
  4337. if (unlikely(!p))
  4338. return -EIO;
  4339. *res = be32_to_cpup(p);
  4340. bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
  4341. }
  4342. return 0;
  4343. }
  4344. /*
  4345. * The granularity of a CLONE operation.
  4346. */
  4347. static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
  4348. uint32_t *res)
  4349. {
  4350. __be32 *p;
  4351. dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
  4352. *res = 0;
  4353. if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
  4354. p = xdr_inline_decode(xdr, 4);
  4355. if (unlikely(!p))
  4356. return -EIO;
  4357. *res = be32_to_cpup(p);
  4358. bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
  4359. }
  4360. return 0;
  4361. }
  4362. static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
  4363. {
  4364. unsigned int savep;
  4365. uint32_t attrlen, bitmap[3];
  4366. int status;
  4367. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  4368. goto xdr_error;
  4369. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  4370. goto xdr_error;
  4371. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  4372. goto xdr_error;
  4373. fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
  4374. if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
  4375. goto xdr_error;
  4376. if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
  4377. goto xdr_error;
  4378. if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
  4379. goto xdr_error;
  4380. fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
  4381. if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
  4382. goto xdr_error;
  4383. fsinfo->wtpref = fsinfo->wtmax;
  4384. status = -EIO;
  4385. if (unlikely(bitmap[0]))
  4386. goto xdr_error;
  4387. status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
  4388. if (status != 0)
  4389. goto xdr_error;
  4390. status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
  4391. if (status != 0)
  4392. goto xdr_error;
  4393. status = -EIO;
  4394. if (unlikely(bitmap[1]))
  4395. goto xdr_error;
  4396. status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
  4397. if (status)
  4398. goto xdr_error;
  4399. status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
  4400. if (status)
  4401. goto xdr_error;
  4402. status = decode_attr_xattrsupport(xdr, bitmap,
  4403. &fsinfo->xattr_support);
  4404. if (status)
  4405. goto xdr_error;
  4406. status = verify_attr_len(xdr, savep, attrlen);
  4407. xdr_error:
  4408. dprintk("%s: xdr returned %d!\n", __func__, -status);
  4409. return status;
  4410. }
  4411. static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
  4412. {
  4413. __be32 *p;
  4414. uint32_t len;
  4415. int status;
  4416. /* Zero handle first to allow comparisons */
  4417. memset(fh, 0, sizeof(*fh));
  4418. status = decode_op_hdr(xdr, OP_GETFH);
  4419. if (status)
  4420. return status;
  4421. p = xdr_inline_decode(xdr, 4);
  4422. if (unlikely(!p))
  4423. return -EIO;
  4424. len = be32_to_cpup(p);
  4425. if (len > NFS4_FHSIZE)
  4426. return -EIO;
  4427. fh->size = len;
  4428. p = xdr_inline_decode(xdr, len);
  4429. if (unlikely(!p))
  4430. return -EIO;
  4431. memcpy(fh->data, p, len);
  4432. return 0;
  4433. }
  4434. static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  4435. {
  4436. int status;
  4437. status = decode_op_hdr(xdr, OP_LINK);
  4438. if (status)
  4439. return status;
  4440. return decode_change_info(xdr, cinfo);
  4441. }
  4442. /*
  4443. * We create the owner, so we know a proper owner.id length is 4.
  4444. */
  4445. static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
  4446. {
  4447. uint64_t offset, length, clientid;
  4448. __be32 *p;
  4449. uint32_t namelen, type;
  4450. p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
  4451. if (unlikely(!p))
  4452. return -EIO;
  4453. p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
  4454. p = xdr_decode_hyper(p, &length);
  4455. type = be32_to_cpup(p++); /* 4 byte read */
  4456. if (fl != NULL) { /* manipulate file lock */
  4457. fl->fl_start = (loff_t)offset;
  4458. fl->fl_end = fl->fl_start + (loff_t)length - 1;
  4459. if (length == ~(uint64_t)0)
  4460. fl->fl_end = OFFSET_MAX;
  4461. fl->fl_type = F_WRLCK;
  4462. if (type & 1)
  4463. fl->fl_type = F_RDLCK;
  4464. fl->fl_pid = 0;
  4465. }
  4466. p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
  4467. namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
  4468. p = xdr_inline_decode(xdr, namelen); /* variable size field */
  4469. if (likely(!p))
  4470. return -EIO;
  4471. return -NFS4ERR_DENIED;
  4472. }
  4473. static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
  4474. {
  4475. int status;
  4476. status = decode_op_hdr(xdr, OP_LOCK);
  4477. if (status == -EIO)
  4478. goto out;
  4479. if (status == 0) {
  4480. status = decode_lock_stateid(xdr, &res->stateid);
  4481. if (unlikely(status))
  4482. goto out;
  4483. } else if (status == -NFS4ERR_DENIED)
  4484. status = decode_lock_denied(xdr, NULL);
  4485. if (res->open_seqid != NULL)
  4486. nfs_increment_open_seqid(status, res->open_seqid);
  4487. nfs_increment_lock_seqid(status, res->lock_seqid);
  4488. out:
  4489. return status;
  4490. }
  4491. static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
  4492. {
  4493. int status;
  4494. status = decode_op_hdr(xdr, OP_LOCKT);
  4495. if (status == -NFS4ERR_DENIED)
  4496. return decode_lock_denied(xdr, res->denied);
  4497. return status;
  4498. }
  4499. static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
  4500. {
  4501. int status;
  4502. status = decode_op_hdr(xdr, OP_LOCKU);
  4503. if (status != -EIO)
  4504. nfs_increment_lock_seqid(status, res->seqid);
  4505. if (status == 0)
  4506. status = decode_lock_stateid(xdr, &res->stateid);
  4507. return status;
  4508. }
  4509. static int decode_release_lockowner(struct xdr_stream *xdr)
  4510. {
  4511. return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
  4512. }
  4513. static int decode_lookup(struct xdr_stream *xdr)
  4514. {
  4515. return decode_op_hdr(xdr, OP_LOOKUP);
  4516. }
  4517. static int decode_lookupp(struct xdr_stream *xdr)
  4518. {
  4519. return decode_op_hdr(xdr, OP_LOOKUPP);
  4520. }
  4521. /* This is too sick! */
  4522. static int decode_space_limit(struct xdr_stream *xdr,
  4523. unsigned long *pagemod_limit)
  4524. {
  4525. __be32 *p;
  4526. uint32_t limit_type, nblocks, blocksize;
  4527. u64 maxsize = 0;
  4528. p = xdr_inline_decode(xdr, 12);
  4529. if (unlikely(!p))
  4530. return -EIO;
  4531. limit_type = be32_to_cpup(p++);
  4532. switch (limit_type) {
  4533. case NFS4_LIMIT_SIZE:
  4534. xdr_decode_hyper(p, &maxsize);
  4535. break;
  4536. case NFS4_LIMIT_BLOCKS:
  4537. nblocks = be32_to_cpup(p++);
  4538. blocksize = be32_to_cpup(p);
  4539. maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
  4540. }
  4541. maxsize >>= PAGE_SHIFT;
  4542. *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
  4543. return 0;
  4544. }
  4545. static int decode_rw_delegation(struct xdr_stream *xdr,
  4546. uint32_t delegation_type,
  4547. struct nfs_openres *res)
  4548. {
  4549. __be32 *p;
  4550. int status;
  4551. status = decode_delegation_stateid(xdr, &res->delegation);
  4552. if (unlikely(status))
  4553. return status;
  4554. p = xdr_inline_decode(xdr, 4);
  4555. if (unlikely(!p))
  4556. return -EIO;
  4557. res->do_recall = be32_to_cpup(p);
  4558. switch (delegation_type) {
  4559. case NFS4_OPEN_DELEGATE_READ:
  4560. res->delegation_type = FMODE_READ;
  4561. break;
  4562. case NFS4_OPEN_DELEGATE_WRITE:
  4563. res->delegation_type = FMODE_WRITE|FMODE_READ;
  4564. if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
  4565. return -EIO;
  4566. }
  4567. return decode_ace(xdr, NULL);
  4568. }
  4569. static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
  4570. {
  4571. __be32 *p;
  4572. uint32_t why_no_delegation;
  4573. p = xdr_inline_decode(xdr, 4);
  4574. if (unlikely(!p))
  4575. return -EIO;
  4576. why_no_delegation = be32_to_cpup(p);
  4577. switch (why_no_delegation) {
  4578. case WND4_CONTENTION:
  4579. case WND4_RESOURCE:
  4580. xdr_inline_decode(xdr, 4);
  4581. /* Ignore for now */
  4582. }
  4583. return 0;
  4584. }
  4585. static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
  4586. {
  4587. __be32 *p;
  4588. uint32_t delegation_type;
  4589. p = xdr_inline_decode(xdr, 4);
  4590. if (unlikely(!p))
  4591. return -EIO;
  4592. delegation_type = be32_to_cpup(p);
  4593. res->delegation_type = 0;
  4594. switch (delegation_type) {
  4595. case NFS4_OPEN_DELEGATE_NONE:
  4596. return 0;
  4597. case NFS4_OPEN_DELEGATE_READ:
  4598. case NFS4_OPEN_DELEGATE_WRITE:
  4599. return decode_rw_delegation(xdr, delegation_type, res);
  4600. case NFS4_OPEN_DELEGATE_NONE_EXT:
  4601. return decode_no_delegation(xdr, res);
  4602. }
  4603. return -EIO;
  4604. }
  4605. static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
  4606. {
  4607. __be32 *p;
  4608. uint32_t savewords, bmlen, i;
  4609. int status;
  4610. if (!__decode_op_hdr(xdr, OP_OPEN, &status))
  4611. return status;
  4612. nfs_increment_open_seqid(status, res->seqid);
  4613. if (status)
  4614. return status;
  4615. status = decode_open_stateid(xdr, &res->stateid);
  4616. if (unlikely(status))
  4617. return status;
  4618. decode_change_info(xdr, &res->cinfo);
  4619. p = xdr_inline_decode(xdr, 8);
  4620. if (unlikely(!p))
  4621. return -EIO;
  4622. res->rflags = be32_to_cpup(p++);
  4623. bmlen = be32_to_cpup(p);
  4624. if (bmlen > 10)
  4625. goto xdr_error;
  4626. p = xdr_inline_decode(xdr, bmlen << 2);
  4627. if (unlikely(!p))
  4628. return -EIO;
  4629. savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
  4630. for (i = 0; i < savewords; ++i)
  4631. res->attrset[i] = be32_to_cpup(p++);
  4632. for (; i < NFS4_BITMAP_SIZE; i++)
  4633. res->attrset[i] = 0;
  4634. return decode_delegation(xdr, res);
  4635. xdr_error:
  4636. dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
  4637. return -EIO;
  4638. }
  4639. static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
  4640. {
  4641. int status;
  4642. status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
  4643. if (status != -EIO)
  4644. nfs_increment_open_seqid(status, res->seqid);
  4645. if (!status)
  4646. status = decode_open_stateid(xdr, &res->stateid);
  4647. return status;
  4648. }
  4649. static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
  4650. {
  4651. int status;
  4652. status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
  4653. if (status != -EIO)
  4654. nfs_increment_open_seqid(status, res->seqid);
  4655. if (!status)
  4656. status = decode_open_stateid(xdr, &res->stateid);
  4657. return status;
  4658. }
  4659. static int decode_putfh(struct xdr_stream *xdr)
  4660. {
  4661. return decode_op_hdr(xdr, OP_PUTFH);
  4662. }
  4663. static int decode_putrootfh(struct xdr_stream *xdr)
  4664. {
  4665. return decode_op_hdr(xdr, OP_PUTROOTFH);
  4666. }
  4667. static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
  4668. struct nfs_pgio_res *res)
  4669. {
  4670. __be32 *p;
  4671. uint32_t count, eof, recvd;
  4672. int status;
  4673. status = decode_op_hdr(xdr, OP_READ);
  4674. if (status)
  4675. return status;
  4676. p = xdr_inline_decode(xdr, 8);
  4677. if (unlikely(!p))
  4678. return -EIO;
  4679. eof = be32_to_cpup(p++);
  4680. count = be32_to_cpup(p);
  4681. recvd = xdr_read_pages(xdr, count);
  4682. if (count > recvd) {
  4683. dprintk("NFS: server cheating in read reply: "
  4684. "count %u > recvd %u\n", count, recvd);
  4685. count = recvd;
  4686. eof = 0;
  4687. }
  4688. res->eof = eof;
  4689. res->count = count;
  4690. return 0;
  4691. }
  4692. static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
  4693. {
  4694. int status;
  4695. __be32 verf[2];
  4696. status = decode_op_hdr(xdr, OP_READDIR);
  4697. if (!status)
  4698. status = decode_verifier(xdr, readdir->verifier.data);
  4699. if (unlikely(status))
  4700. return status;
  4701. memcpy(verf, readdir->verifier.data, sizeof(verf));
  4702. dprintk("%s: verifier = %08x:%08x\n",
  4703. __func__, verf[0], verf[1]);
  4704. return xdr_read_pages(xdr, xdr->buf->page_len);
  4705. }
  4706. static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
  4707. {
  4708. struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
  4709. u32 len, recvd;
  4710. __be32 *p;
  4711. int status;
  4712. status = decode_op_hdr(xdr, OP_READLINK);
  4713. if (status)
  4714. return status;
  4715. /* Convert length of symlink */
  4716. p = xdr_inline_decode(xdr, 4);
  4717. if (unlikely(!p))
  4718. return -EIO;
  4719. len = be32_to_cpup(p);
  4720. if (len >= rcvbuf->page_len || len <= 0) {
  4721. dprintk("nfs: server returned giant symlink!\n");
  4722. return -ENAMETOOLONG;
  4723. }
  4724. recvd = xdr_read_pages(xdr, len);
  4725. if (recvd < len) {
  4726. dprintk("NFS: server cheating in readlink reply: "
  4727. "count %u > recvd %u\n", len, recvd);
  4728. return -EIO;
  4729. }
  4730. /*
  4731. * The XDR encode routine has set things up so that
  4732. * the link text will be copied directly into the
  4733. * buffer. We just have to do overflow-checking,
  4734. * and null-terminate the text (the VFS expects
  4735. * null-termination).
  4736. */
  4737. xdr_terminate_string(rcvbuf, len);
  4738. return 0;
  4739. }
  4740. static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  4741. {
  4742. int status;
  4743. status = decode_op_hdr(xdr, OP_REMOVE);
  4744. if (status)
  4745. goto out;
  4746. status = decode_change_info(xdr, cinfo);
  4747. out:
  4748. return status;
  4749. }
  4750. static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
  4751. struct nfs4_change_info *new_cinfo)
  4752. {
  4753. int status;
  4754. status = decode_op_hdr(xdr, OP_RENAME);
  4755. if (status)
  4756. goto out;
  4757. if ((status = decode_change_info(xdr, old_cinfo)))
  4758. goto out;
  4759. status = decode_change_info(xdr, new_cinfo);
  4760. out:
  4761. return status;
  4762. }
  4763. static int decode_renew(struct xdr_stream *xdr)
  4764. {
  4765. return decode_op_hdr(xdr, OP_RENEW);
  4766. }
  4767. static int
  4768. decode_restorefh(struct xdr_stream *xdr)
  4769. {
  4770. return decode_op_hdr(xdr, OP_RESTOREFH);
  4771. }
  4772. static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
  4773. struct nfs_getaclres *res)
  4774. {
  4775. unsigned int savep;
  4776. uint32_t attrlen,
  4777. bitmap[3] = {0};
  4778. int status;
  4779. res->acl_len = 0;
  4780. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  4781. goto out;
  4782. xdr_enter_page(xdr, xdr->buf->page_len);
  4783. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  4784. goto out;
  4785. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  4786. goto out;
  4787. if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
  4788. return -EIO;
  4789. if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
  4790. /* The bitmap (xdr len + bitmaps) and the attr xdr len words
  4791. * are stored with the acl data to handle the problem of
  4792. * variable length bitmaps.*/
  4793. res->acl_data_offset = xdr_page_pos(xdr);
  4794. res->acl_len = attrlen;
  4795. /* Check for receive buffer overflow */
  4796. if (res->acl_len > (xdr->nwords << 2) ||
  4797. res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
  4798. res->acl_flags |= NFS4_ACL_TRUNC;
  4799. dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
  4800. attrlen, xdr->nwords << 2);
  4801. }
  4802. } else
  4803. status = -EOPNOTSUPP;
  4804. out:
  4805. return status;
  4806. }
  4807. static int
  4808. decode_savefh(struct xdr_stream *xdr)
  4809. {
  4810. return decode_op_hdr(xdr, OP_SAVEFH);
  4811. }
  4812. static int decode_setattr(struct xdr_stream *xdr)
  4813. {
  4814. int status;
  4815. status = decode_op_hdr(xdr, OP_SETATTR);
  4816. if (status)
  4817. return status;
  4818. if (decode_bitmap4(xdr, NULL, 0) >= 0)
  4819. return 0;
  4820. return -EIO;
  4821. }
  4822. static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
  4823. {
  4824. __be32 *p;
  4825. uint32_t opnum;
  4826. int32_t nfserr;
  4827. p = xdr_inline_decode(xdr, 8);
  4828. if (unlikely(!p))
  4829. return -EIO;
  4830. opnum = be32_to_cpup(p++);
  4831. if (opnum != OP_SETCLIENTID) {
  4832. dprintk("nfs: decode_setclientid: Server returned operation"
  4833. " %d\n", opnum);
  4834. return -EIO;
  4835. }
  4836. nfserr = be32_to_cpup(p);
  4837. if (nfserr == NFS_OK) {
  4838. p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
  4839. if (unlikely(!p))
  4840. return -EIO;
  4841. p = xdr_decode_hyper(p, &res->clientid);
  4842. memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
  4843. } else if (nfserr == NFSERR_CLID_INUSE) {
  4844. uint32_t len;
  4845. /* skip netid string */
  4846. p = xdr_inline_decode(xdr, 4);
  4847. if (unlikely(!p))
  4848. return -EIO;
  4849. len = be32_to_cpup(p);
  4850. p = xdr_inline_decode(xdr, len);
  4851. if (unlikely(!p))
  4852. return -EIO;
  4853. /* skip uaddr string */
  4854. p = xdr_inline_decode(xdr, 4);
  4855. if (unlikely(!p))
  4856. return -EIO;
  4857. len = be32_to_cpup(p);
  4858. p = xdr_inline_decode(xdr, len);
  4859. if (unlikely(!p))
  4860. return -EIO;
  4861. return -NFSERR_CLID_INUSE;
  4862. } else
  4863. return nfs4_stat_to_errno(nfserr);
  4864. return 0;
  4865. }
  4866. static int decode_setclientid_confirm(struct xdr_stream *xdr)
  4867. {
  4868. return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
  4869. }
  4870. static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
  4871. {
  4872. __be32 *p;
  4873. int status;
  4874. status = decode_op_hdr(xdr, OP_WRITE);
  4875. if (status)
  4876. return status;
  4877. p = xdr_inline_decode(xdr, 8);
  4878. if (unlikely(!p))
  4879. return -EIO;
  4880. res->count = be32_to_cpup(p++);
  4881. res->verf->committed = be32_to_cpup(p++);
  4882. return decode_write_verifier(xdr, &res->verf->verifier);
  4883. }
  4884. static int decode_delegreturn(struct xdr_stream *xdr)
  4885. {
  4886. return decode_op_hdr(xdr, OP_DELEGRETURN);
  4887. }
  4888. static int decode_secinfo_gss(struct xdr_stream *xdr,
  4889. struct nfs4_secinfo4 *flavor)
  4890. {
  4891. u32 oid_len;
  4892. __be32 *p;
  4893. p = xdr_inline_decode(xdr, 4);
  4894. if (unlikely(!p))
  4895. return -EIO;
  4896. oid_len = be32_to_cpup(p);
  4897. if (oid_len > GSS_OID_MAX_LEN)
  4898. return -EINVAL;
  4899. p = xdr_inline_decode(xdr, oid_len);
  4900. if (unlikely(!p))
  4901. return -EIO;
  4902. memcpy(flavor->flavor_info.oid.data, p, oid_len);
  4903. flavor->flavor_info.oid.len = oid_len;
  4904. p = xdr_inline_decode(xdr, 8);
  4905. if (unlikely(!p))
  4906. return -EIO;
  4907. flavor->flavor_info.qop = be32_to_cpup(p++);
  4908. flavor->flavor_info.service = be32_to_cpup(p);
  4909. return 0;
  4910. }
  4911. static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
  4912. {
  4913. struct nfs4_secinfo4 *sec_flavor;
  4914. unsigned int i, num_flavors;
  4915. int status;
  4916. __be32 *p;
  4917. p = xdr_inline_decode(xdr, 4);
  4918. if (unlikely(!p))
  4919. return -EIO;
  4920. res->flavors->num_flavors = 0;
  4921. num_flavors = be32_to_cpup(p);
  4922. for (i = 0; i < num_flavors; i++) {
  4923. sec_flavor = &res->flavors->flavors[i];
  4924. if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
  4925. break;
  4926. p = xdr_inline_decode(xdr, 4);
  4927. if (unlikely(!p))
  4928. return -EIO;
  4929. sec_flavor->flavor = be32_to_cpup(p);
  4930. if (sec_flavor->flavor == RPC_AUTH_GSS) {
  4931. status = decode_secinfo_gss(xdr, sec_flavor);
  4932. if (status)
  4933. goto out;
  4934. }
  4935. res->flavors->num_flavors++;
  4936. }
  4937. status = 0;
  4938. out:
  4939. return status;
  4940. }
  4941. static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
  4942. {
  4943. int status = decode_op_hdr(xdr, OP_SECINFO);
  4944. if (status)
  4945. return status;
  4946. return decode_secinfo_common(xdr, res);
  4947. }
  4948. #if defined(CONFIG_NFS_V4_1)
  4949. static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
  4950. {
  4951. int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
  4952. if (status)
  4953. return status;
  4954. return decode_secinfo_common(xdr, res);
  4955. }
  4956. static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
  4957. {
  4958. __be32 *p;
  4959. uint32_t bitmap_words;
  4960. unsigned int i;
  4961. p = xdr_inline_decode(xdr, 4);
  4962. if (!p)
  4963. return -EIO;
  4964. bitmap_words = be32_to_cpup(p++);
  4965. if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
  4966. return -EIO;
  4967. p = xdr_inline_decode(xdr, 4 * bitmap_words);
  4968. for (i = 0; i < bitmap_words; i++)
  4969. op_map->u.words[i] = be32_to_cpup(p++);
  4970. return 0;
  4971. }
  4972. static int decode_exchange_id(struct xdr_stream *xdr,
  4973. struct nfs41_exchange_id_res *res)
  4974. {
  4975. __be32 *p;
  4976. uint32_t dummy;
  4977. char *dummy_str;
  4978. int status;
  4979. uint32_t impl_id_count;
  4980. status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
  4981. if (status)
  4982. return status;
  4983. p = xdr_inline_decode(xdr, 8);
  4984. if (unlikely(!p))
  4985. return -EIO;
  4986. xdr_decode_hyper(p, &res->clientid);
  4987. p = xdr_inline_decode(xdr, 12);
  4988. if (unlikely(!p))
  4989. return -EIO;
  4990. res->seqid = be32_to_cpup(p++);
  4991. res->flags = be32_to_cpup(p++);
  4992. res->state_protect.how = be32_to_cpup(p);
  4993. switch (res->state_protect.how) {
  4994. case SP4_NONE:
  4995. break;
  4996. case SP4_MACH_CRED:
  4997. status = decode_op_map(xdr, &res->state_protect.enforce);
  4998. if (status)
  4999. return status;
  5000. status = decode_op_map(xdr, &res->state_protect.allow);
  5001. if (status)
  5002. return status;
  5003. break;
  5004. default:
  5005. WARN_ON_ONCE(1);
  5006. return -EIO;
  5007. }
  5008. /* server_owner4.so_minor_id */
  5009. p = xdr_inline_decode(xdr, 8);
  5010. if (unlikely(!p))
  5011. return -EIO;
  5012. p = xdr_decode_hyper(p, &res->server_owner->minor_id);
  5013. /* server_owner4.so_major_id */
  5014. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  5015. if (unlikely(status))
  5016. return status;
  5017. memcpy(res->server_owner->major_id, dummy_str, dummy);
  5018. res->server_owner->major_id_sz = dummy;
  5019. /* server_scope4 */
  5020. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  5021. if (unlikely(status))
  5022. return status;
  5023. memcpy(res->server_scope->server_scope, dummy_str, dummy);
  5024. res->server_scope->server_scope_sz = dummy;
  5025. /* Implementation Id */
  5026. p = xdr_inline_decode(xdr, 4);
  5027. if (unlikely(!p))
  5028. return -EIO;
  5029. impl_id_count = be32_to_cpup(p++);
  5030. if (impl_id_count) {
  5031. /* nii_domain */
  5032. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  5033. if (unlikely(status))
  5034. return status;
  5035. memcpy(res->impl_id->domain, dummy_str, dummy);
  5036. /* nii_name */
  5037. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  5038. if (unlikely(status))
  5039. return status;
  5040. memcpy(res->impl_id->name, dummy_str, dummy);
  5041. /* nii_date */
  5042. p = xdr_inline_decode(xdr, 12);
  5043. if (unlikely(!p))
  5044. return -EIO;
  5045. p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
  5046. res->impl_id->date.nseconds = be32_to_cpup(p);
  5047. /* if there's more than one entry, ignore the rest */
  5048. }
  5049. return 0;
  5050. }
  5051. static int decode_chan_attrs(struct xdr_stream *xdr,
  5052. struct nfs4_channel_attrs *attrs)
  5053. {
  5054. __be32 *p;
  5055. u32 nr_attrs, val;
  5056. p = xdr_inline_decode(xdr, 28);
  5057. if (unlikely(!p))
  5058. return -EIO;
  5059. val = be32_to_cpup(p++); /* headerpadsz */
  5060. if (val)
  5061. return -EINVAL; /* no support for header padding yet */
  5062. attrs->max_rqst_sz = be32_to_cpup(p++);
  5063. attrs->max_resp_sz = be32_to_cpup(p++);
  5064. attrs->max_resp_sz_cached = be32_to_cpup(p++);
  5065. attrs->max_ops = be32_to_cpup(p++);
  5066. attrs->max_reqs = be32_to_cpup(p++);
  5067. nr_attrs = be32_to_cpup(p);
  5068. if (unlikely(nr_attrs > 1)) {
  5069. printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
  5070. "count %u\n", __func__, nr_attrs);
  5071. return -EINVAL;
  5072. }
  5073. if (nr_attrs == 1) {
  5074. p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
  5075. if (unlikely(!p))
  5076. return -EIO;
  5077. }
  5078. return 0;
  5079. }
  5080. static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
  5081. {
  5082. return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
  5083. }
  5084. static int decode_bind_conn_to_session(struct xdr_stream *xdr,
  5085. struct nfs41_bind_conn_to_session_res *res)
  5086. {
  5087. __be32 *p;
  5088. int status;
  5089. status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
  5090. if (!status)
  5091. status = decode_sessionid(xdr, &res->sessionid);
  5092. if (unlikely(status))
  5093. return status;
  5094. /* dir flags, rdma mode bool */
  5095. p = xdr_inline_decode(xdr, 8);
  5096. if (unlikely(!p))
  5097. return -EIO;
  5098. res->dir = be32_to_cpup(p++);
  5099. if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
  5100. return -EIO;
  5101. if (be32_to_cpup(p) == 0)
  5102. res->use_conn_in_rdma_mode = false;
  5103. else
  5104. res->use_conn_in_rdma_mode = true;
  5105. return 0;
  5106. }
  5107. static int decode_create_session(struct xdr_stream *xdr,
  5108. struct nfs41_create_session_res *res)
  5109. {
  5110. __be32 *p;
  5111. int status;
  5112. status = decode_op_hdr(xdr, OP_CREATE_SESSION);
  5113. if (!status)
  5114. status = decode_sessionid(xdr, &res->sessionid);
  5115. if (unlikely(status))
  5116. return status;
  5117. /* seqid, flags */
  5118. p = xdr_inline_decode(xdr, 8);
  5119. if (unlikely(!p))
  5120. return -EIO;
  5121. res->seqid = be32_to_cpup(p++);
  5122. res->flags = be32_to_cpup(p);
  5123. /* Channel attributes */
  5124. status = decode_chan_attrs(xdr, &res->fc_attrs);
  5125. if (!status)
  5126. status = decode_chan_attrs(xdr, &res->bc_attrs);
  5127. return status;
  5128. }
  5129. static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
  5130. {
  5131. return decode_op_hdr(xdr, OP_DESTROY_SESSION);
  5132. }
  5133. static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
  5134. {
  5135. return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
  5136. }
  5137. static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
  5138. {
  5139. return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
  5140. }
  5141. #endif /* CONFIG_NFS_V4_1 */
  5142. static int decode_sequence(struct xdr_stream *xdr,
  5143. struct nfs4_sequence_res *res,
  5144. struct rpc_rqst *rqstp)
  5145. {
  5146. #if defined(CONFIG_NFS_V4_1)
  5147. struct nfs4_session *session;
  5148. struct nfs4_sessionid id;
  5149. u32 dummy;
  5150. int status;
  5151. __be32 *p;
  5152. if (res->sr_slot == NULL)
  5153. return 0;
  5154. if (!res->sr_slot->table->session)
  5155. return 0;
  5156. status = decode_op_hdr(xdr, OP_SEQUENCE);
  5157. if (!status)
  5158. status = decode_sessionid(xdr, &id);
  5159. if (unlikely(status))
  5160. goto out_err;
  5161. /*
  5162. * If the server returns different values for sessionID, slotID or
  5163. * sequence number, the server is looney tunes.
  5164. */
  5165. status = -EREMOTEIO;
  5166. session = res->sr_slot->table->session;
  5167. if (memcmp(id.data, session->sess_id.data,
  5168. NFS4_MAX_SESSIONID_LEN)) {
  5169. dprintk("%s Invalid session id\n", __func__);
  5170. goto out_err;
  5171. }
  5172. p = xdr_inline_decode(xdr, 20);
  5173. if (unlikely(!p))
  5174. goto out_overflow;
  5175. /* seqid */
  5176. dummy = be32_to_cpup(p++);
  5177. if (dummy != res->sr_slot->seq_nr) {
  5178. dprintk("%s Invalid sequence number\n", __func__);
  5179. goto out_err;
  5180. }
  5181. /* slot id */
  5182. dummy = be32_to_cpup(p++);
  5183. if (dummy != res->sr_slot->slot_nr) {
  5184. dprintk("%s Invalid slot id\n", __func__);
  5185. goto out_err;
  5186. }
  5187. /* highest slot id */
  5188. res->sr_highest_slotid = be32_to_cpup(p++);
  5189. /* target highest slot id */
  5190. res->sr_target_highest_slotid = be32_to_cpup(p++);
  5191. /* result flags */
  5192. res->sr_status_flags = be32_to_cpup(p);
  5193. status = 0;
  5194. out_err:
  5195. res->sr_status = status;
  5196. return status;
  5197. out_overflow:
  5198. status = -EIO;
  5199. goto out_err;
  5200. #else /* CONFIG_NFS_V4_1 */
  5201. return 0;
  5202. #endif /* CONFIG_NFS_V4_1 */
  5203. }
  5204. #if defined(CONFIG_NFS_V4_1)
  5205. static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  5206. {
  5207. stateid->type = NFS4_LAYOUT_STATEID_TYPE;
  5208. return decode_stateid(xdr, stateid);
  5209. }
  5210. static int decode_getdeviceinfo(struct xdr_stream *xdr,
  5211. struct nfs4_getdeviceinfo_res *res)
  5212. {
  5213. struct pnfs_device *pdev = res->pdev;
  5214. __be32 *p;
  5215. uint32_t len, type;
  5216. int status;
  5217. status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
  5218. if (status) {
  5219. if (status == -ETOOSMALL) {
  5220. p = xdr_inline_decode(xdr, 4);
  5221. if (unlikely(!p))
  5222. return -EIO;
  5223. pdev->mincount = be32_to_cpup(p);
  5224. dprintk("%s: Min count too small. mincnt = %u\n",
  5225. __func__, pdev->mincount);
  5226. }
  5227. return status;
  5228. }
  5229. p = xdr_inline_decode(xdr, 8);
  5230. if (unlikely(!p))
  5231. return -EIO;
  5232. type = be32_to_cpup(p++);
  5233. if (type != pdev->layout_type) {
  5234. dprintk("%s: layout mismatch req: %u pdev: %u\n",
  5235. __func__, pdev->layout_type, type);
  5236. return -EINVAL;
  5237. }
  5238. /*
  5239. * Get the length of the opaque device_addr4. xdr_read_pages places
  5240. * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
  5241. * and places the remaining xdr data in xdr_buf->tail
  5242. */
  5243. pdev->mincount = be32_to_cpup(p);
  5244. if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
  5245. return -EIO;
  5246. /* Parse notification bitmap, verifying that it is zero. */
  5247. p = xdr_inline_decode(xdr, 4);
  5248. if (unlikely(!p))
  5249. return -EIO;
  5250. len = be32_to_cpup(p);
  5251. if (len) {
  5252. uint32_t i;
  5253. p = xdr_inline_decode(xdr, 4 * len);
  5254. if (unlikely(!p))
  5255. return -EIO;
  5256. res->notification = be32_to_cpup(p++);
  5257. for (i = 1; i < len; i++) {
  5258. if (be32_to_cpup(p++)) {
  5259. dprintk("%s: unsupported notification\n",
  5260. __func__);
  5261. return -EIO;
  5262. }
  5263. }
  5264. }
  5265. return 0;
  5266. }
  5267. static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
  5268. struct nfs4_layoutget_res *res)
  5269. {
  5270. __be32 *p;
  5271. int status;
  5272. u32 layout_count;
  5273. u32 recvd;
  5274. status = decode_op_hdr(xdr, OP_LAYOUTGET);
  5275. if (status)
  5276. goto out;
  5277. p = xdr_inline_decode(xdr, 4);
  5278. if (unlikely(!p))
  5279. goto out_overflow;
  5280. res->return_on_close = be32_to_cpup(p);
  5281. decode_layout_stateid(xdr, &res->stateid);
  5282. p = xdr_inline_decode(xdr, 4);
  5283. if (unlikely(!p))
  5284. goto out_overflow;
  5285. layout_count = be32_to_cpup(p);
  5286. if (!layout_count) {
  5287. dprintk("%s: server responded with empty layout array\n",
  5288. __func__);
  5289. status = -EINVAL;
  5290. goto out;
  5291. }
  5292. p = xdr_inline_decode(xdr, 28);
  5293. if (unlikely(!p))
  5294. goto out_overflow;
  5295. p = xdr_decode_hyper(p, &res->range.offset);
  5296. p = xdr_decode_hyper(p, &res->range.length);
  5297. res->range.iomode = be32_to_cpup(p++);
  5298. res->type = be32_to_cpup(p++);
  5299. res->layoutp->len = be32_to_cpup(p);
  5300. dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
  5301. __func__,
  5302. (unsigned long)res->range.offset,
  5303. (unsigned long)res->range.length,
  5304. res->range.iomode,
  5305. res->type,
  5306. res->layoutp->len);
  5307. recvd = xdr_read_pages(xdr, res->layoutp->len);
  5308. if (res->layoutp->len > recvd) {
  5309. dprintk("NFS: server cheating in layoutget reply: "
  5310. "layout len %u > recvd %u\n",
  5311. res->layoutp->len, recvd);
  5312. status = -EINVAL;
  5313. goto out;
  5314. }
  5315. if (layout_count > 1) {
  5316. /* We only handle a length one array at the moment. Any
  5317. * further entries are just ignored. Note that this means
  5318. * the client may see a response that is less than the
  5319. * minimum it requested.
  5320. */
  5321. dprintk("%s: server responded with %d layouts, dropping tail\n",
  5322. __func__, layout_count);
  5323. }
  5324. out:
  5325. res->status = status;
  5326. return status;
  5327. out_overflow:
  5328. status = -EIO;
  5329. goto out;
  5330. }
  5331. static int decode_layoutreturn(struct xdr_stream *xdr,
  5332. struct nfs4_layoutreturn_res *res)
  5333. {
  5334. __be32 *p;
  5335. int status;
  5336. status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
  5337. if (status)
  5338. return status;
  5339. p = xdr_inline_decode(xdr, 4);
  5340. if (unlikely(!p))
  5341. return -EIO;
  5342. res->lrs_present = be32_to_cpup(p);
  5343. if (res->lrs_present)
  5344. status = decode_layout_stateid(xdr, &res->stateid);
  5345. else
  5346. nfs4_stateid_copy(&res->stateid, &invalid_stateid);
  5347. return status;
  5348. }
  5349. static int decode_layoutcommit(struct xdr_stream *xdr,
  5350. struct rpc_rqst *req,
  5351. struct nfs4_layoutcommit_res *res)
  5352. {
  5353. __be32 *p;
  5354. __u32 sizechanged;
  5355. int status;
  5356. status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
  5357. res->status = status;
  5358. if (status)
  5359. return status;
  5360. p = xdr_inline_decode(xdr, 4);
  5361. if (unlikely(!p))
  5362. return -EIO;
  5363. sizechanged = be32_to_cpup(p);
  5364. if (sizechanged) {
  5365. /* throw away new size */
  5366. p = xdr_inline_decode(xdr, 8);
  5367. if (unlikely(!p))
  5368. return -EIO;
  5369. }
  5370. return 0;
  5371. }
  5372. static int decode_test_stateid(struct xdr_stream *xdr,
  5373. struct nfs41_test_stateid_res *res)
  5374. {
  5375. __be32 *p;
  5376. int status;
  5377. int num_res;
  5378. status = decode_op_hdr(xdr, OP_TEST_STATEID);
  5379. if (status)
  5380. return status;
  5381. p = xdr_inline_decode(xdr, 4);
  5382. if (unlikely(!p))
  5383. return -EIO;
  5384. num_res = be32_to_cpup(p++);
  5385. if (num_res != 1)
  5386. return -EIO;
  5387. p = xdr_inline_decode(xdr, 4);
  5388. if (unlikely(!p))
  5389. return -EIO;
  5390. res->status = be32_to_cpup(p++);
  5391. return status;
  5392. }
  5393. static int decode_free_stateid(struct xdr_stream *xdr,
  5394. struct nfs41_free_stateid_res *res)
  5395. {
  5396. res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
  5397. return res->status;
  5398. }
  5399. #else
  5400. static inline
  5401. int decode_layoutreturn(struct xdr_stream *xdr,
  5402. struct nfs4_layoutreturn_res *res)
  5403. {
  5404. return 0;
  5405. }
  5406. static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
  5407. struct nfs4_layoutget_res *res)
  5408. {
  5409. return 0;
  5410. }
  5411. #endif /* CONFIG_NFS_V4_1 */
  5412. /*
  5413. * END OF "GENERIC" DECODE ROUTINES.
  5414. */
  5415. /*
  5416. * Decode OPEN_DOWNGRADE response
  5417. */
  5418. static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
  5419. struct xdr_stream *xdr,
  5420. void *data)
  5421. {
  5422. struct nfs_closeres *res = data;
  5423. struct compound_hdr hdr;
  5424. int status;
  5425. status = decode_compound_hdr(xdr, &hdr);
  5426. if (status)
  5427. goto out;
  5428. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5429. if (status)
  5430. goto out;
  5431. status = decode_putfh(xdr);
  5432. if (status)
  5433. goto out;
  5434. if (res->lr_res) {
  5435. status = decode_layoutreturn(xdr, res->lr_res);
  5436. res->lr_ret = status;
  5437. if (status)
  5438. goto out;
  5439. }
  5440. status = decode_open_downgrade(xdr, res);
  5441. out:
  5442. return status;
  5443. }
  5444. /*
  5445. * Decode ACCESS response
  5446. */
  5447. static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5448. void *data)
  5449. {
  5450. struct nfs4_accessres *res = data;
  5451. struct compound_hdr hdr;
  5452. int status;
  5453. status = decode_compound_hdr(xdr, &hdr);
  5454. if (status)
  5455. goto out;
  5456. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5457. if (status)
  5458. goto out;
  5459. status = decode_putfh(xdr);
  5460. if (status != 0)
  5461. goto out;
  5462. status = decode_access(xdr, &res->supported, &res->access);
  5463. if (status != 0)
  5464. goto out;
  5465. if (res->fattr)
  5466. decode_getfattr(xdr, res->fattr, res->server);
  5467. out:
  5468. return status;
  5469. }
  5470. /*
  5471. * Decode LOOKUP response
  5472. */
  5473. static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5474. void *data)
  5475. {
  5476. struct nfs4_lookup_res *res = data;
  5477. struct compound_hdr hdr;
  5478. int status;
  5479. status = decode_compound_hdr(xdr, &hdr);
  5480. if (status)
  5481. goto out;
  5482. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5483. if (status)
  5484. goto out;
  5485. status = decode_putfh(xdr);
  5486. if (status)
  5487. goto out;
  5488. status = decode_lookup(xdr);
  5489. if (status)
  5490. goto out;
  5491. status = decode_getfh(xdr, res->fh);
  5492. if (status)
  5493. goto out;
  5494. status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
  5495. out:
  5496. return status;
  5497. }
  5498. /*
  5499. * Decode LOOKUPP response
  5500. */
  5501. static int nfs4_xdr_dec_lookupp(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5502. void *data)
  5503. {
  5504. struct nfs4_lookupp_res *res = data;
  5505. struct compound_hdr hdr;
  5506. int status;
  5507. status = decode_compound_hdr(xdr, &hdr);
  5508. if (status)
  5509. goto out;
  5510. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5511. if (status)
  5512. goto out;
  5513. status = decode_putfh(xdr);
  5514. if (status)
  5515. goto out;
  5516. status = decode_lookupp(xdr);
  5517. if (status)
  5518. goto out;
  5519. status = decode_getfh(xdr, res->fh);
  5520. if (status)
  5521. goto out;
  5522. status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
  5523. out:
  5524. return status;
  5525. }
  5526. /*
  5527. * Decode LOOKUP_ROOT response
  5528. */
  5529. static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
  5530. struct xdr_stream *xdr,
  5531. void *data)
  5532. {
  5533. struct nfs4_lookup_res *res = data;
  5534. struct compound_hdr hdr;
  5535. int status;
  5536. status = decode_compound_hdr(xdr, &hdr);
  5537. if (status)
  5538. goto out;
  5539. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5540. if (status)
  5541. goto out;
  5542. status = decode_putrootfh(xdr);
  5543. if (status)
  5544. goto out;
  5545. status = decode_getfh(xdr, res->fh);
  5546. if (status == 0)
  5547. status = decode_getfattr_label(xdr, res->fattr,
  5548. res->label, res->server);
  5549. out:
  5550. return status;
  5551. }
  5552. /*
  5553. * Decode REMOVE response
  5554. */
  5555. static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5556. void *data)
  5557. {
  5558. struct nfs_removeres *res = data;
  5559. struct compound_hdr hdr;
  5560. int status;
  5561. status = decode_compound_hdr(xdr, &hdr);
  5562. if (status)
  5563. goto out;
  5564. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5565. if (status)
  5566. goto out;
  5567. status = decode_putfh(xdr);
  5568. if (status)
  5569. goto out;
  5570. status = decode_remove(xdr, &res->cinfo);
  5571. out:
  5572. return status;
  5573. }
  5574. /*
  5575. * Decode RENAME response
  5576. */
  5577. static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5578. void *data)
  5579. {
  5580. struct nfs_renameres *res = data;
  5581. struct compound_hdr hdr;
  5582. int status;
  5583. status = decode_compound_hdr(xdr, &hdr);
  5584. if (status)
  5585. goto out;
  5586. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5587. if (status)
  5588. goto out;
  5589. status = decode_putfh(xdr);
  5590. if (status)
  5591. goto out;
  5592. status = decode_savefh(xdr);
  5593. if (status)
  5594. goto out;
  5595. status = decode_putfh(xdr);
  5596. if (status)
  5597. goto out;
  5598. status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
  5599. out:
  5600. return status;
  5601. }
  5602. /*
  5603. * Decode LINK response
  5604. */
  5605. static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5606. void *data)
  5607. {
  5608. struct nfs4_link_res *res = data;
  5609. struct compound_hdr hdr;
  5610. int status;
  5611. status = decode_compound_hdr(xdr, &hdr);
  5612. if (status)
  5613. goto out;
  5614. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5615. if (status)
  5616. goto out;
  5617. status = decode_putfh(xdr);
  5618. if (status)
  5619. goto out;
  5620. status = decode_savefh(xdr);
  5621. if (status)
  5622. goto out;
  5623. status = decode_putfh(xdr);
  5624. if (status)
  5625. goto out;
  5626. status = decode_link(xdr, &res->cinfo);
  5627. if (status)
  5628. goto out;
  5629. /*
  5630. * Note order: OP_LINK leaves the directory as the current
  5631. * filehandle.
  5632. */
  5633. status = decode_restorefh(xdr);
  5634. if (status)
  5635. goto out;
  5636. decode_getfattr_label(xdr, res->fattr, res->label, res->server);
  5637. out:
  5638. return status;
  5639. }
  5640. /*
  5641. * Decode CREATE response
  5642. */
  5643. static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5644. void *data)
  5645. {
  5646. struct nfs4_create_res *res = data;
  5647. struct compound_hdr hdr;
  5648. int status;
  5649. status = decode_compound_hdr(xdr, &hdr);
  5650. if (status)
  5651. goto out;
  5652. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5653. if (status)
  5654. goto out;
  5655. status = decode_putfh(xdr);
  5656. if (status)
  5657. goto out;
  5658. status = decode_create(xdr, &res->dir_cinfo);
  5659. if (status)
  5660. goto out;
  5661. status = decode_getfh(xdr, res->fh);
  5662. if (status)
  5663. goto out;
  5664. decode_getfattr_label(xdr, res->fattr, res->label, res->server);
  5665. out:
  5666. return status;
  5667. }
  5668. /*
  5669. * Decode SYMLINK response
  5670. */
  5671. static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5672. void *res)
  5673. {
  5674. return nfs4_xdr_dec_create(rqstp, xdr, res);
  5675. }
  5676. /*
  5677. * Decode GETATTR response
  5678. */
  5679. static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5680. void *data)
  5681. {
  5682. struct nfs4_getattr_res *res = data;
  5683. struct compound_hdr hdr;
  5684. int status;
  5685. status = decode_compound_hdr(xdr, &hdr);
  5686. if (status)
  5687. goto out;
  5688. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5689. if (status)
  5690. goto out;
  5691. status = decode_putfh(xdr);
  5692. if (status)
  5693. goto out;
  5694. status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
  5695. out:
  5696. return status;
  5697. }
  5698. /*
  5699. * Encode an SETACL request
  5700. */
  5701. static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
  5702. const void *data)
  5703. {
  5704. const struct nfs_setaclargs *args = data;
  5705. struct compound_hdr hdr = {
  5706. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  5707. };
  5708. encode_compound_hdr(xdr, req, &hdr);
  5709. encode_sequence(xdr, &args->seq_args, &hdr);
  5710. encode_putfh(xdr, args->fh, &hdr);
  5711. encode_setacl(xdr, args, &hdr);
  5712. encode_nops(&hdr);
  5713. }
  5714. /*
  5715. * Decode SETACL response
  5716. */
  5717. static int
  5718. nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5719. void *data)
  5720. {
  5721. struct nfs_setaclres *res = data;
  5722. struct compound_hdr hdr;
  5723. int status;
  5724. status = decode_compound_hdr(xdr, &hdr);
  5725. if (status)
  5726. goto out;
  5727. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5728. if (status)
  5729. goto out;
  5730. status = decode_putfh(xdr);
  5731. if (status)
  5732. goto out;
  5733. status = decode_setattr(xdr);
  5734. out:
  5735. return status;
  5736. }
  5737. /*
  5738. * Decode GETACL response
  5739. */
  5740. static int
  5741. nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5742. void *data)
  5743. {
  5744. struct nfs_getaclres *res = data;
  5745. struct compound_hdr hdr;
  5746. int status;
  5747. if (res->acl_scratch != NULL) {
  5748. void *p = page_address(res->acl_scratch);
  5749. xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
  5750. }
  5751. status = decode_compound_hdr(xdr, &hdr);
  5752. if (status)
  5753. goto out;
  5754. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5755. if (status)
  5756. goto out;
  5757. status = decode_putfh(xdr);
  5758. if (status)
  5759. goto out;
  5760. status = decode_getacl(xdr, rqstp, res);
  5761. out:
  5762. return status;
  5763. }
  5764. /*
  5765. * Decode CLOSE response
  5766. */
  5767. static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5768. void *data)
  5769. {
  5770. struct nfs_closeres *res = data;
  5771. struct compound_hdr hdr;
  5772. int status;
  5773. status = decode_compound_hdr(xdr, &hdr);
  5774. if (status)
  5775. goto out;
  5776. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5777. if (status)
  5778. goto out;
  5779. status = decode_putfh(xdr);
  5780. if (status)
  5781. goto out;
  5782. if (res->lr_res) {
  5783. status = decode_layoutreturn(xdr, res->lr_res);
  5784. res->lr_ret = status;
  5785. if (status)
  5786. goto out;
  5787. }
  5788. if (res->fattr != NULL) {
  5789. status = decode_getfattr(xdr, res->fattr, res->server);
  5790. if (status != 0)
  5791. goto out;
  5792. }
  5793. status = decode_close(xdr, res);
  5794. out:
  5795. return status;
  5796. }
  5797. /*
  5798. * Decode OPEN response
  5799. */
  5800. static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5801. void *data)
  5802. {
  5803. struct nfs_openres *res = data;
  5804. struct compound_hdr hdr;
  5805. int status;
  5806. status = decode_compound_hdr(xdr, &hdr);
  5807. if (status)
  5808. goto out;
  5809. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5810. if (status)
  5811. goto out;
  5812. status = decode_putfh(xdr);
  5813. if (status)
  5814. goto out;
  5815. status = decode_open(xdr, res);
  5816. if (status)
  5817. goto out;
  5818. status = decode_getfh(xdr, &res->fh);
  5819. if (status)
  5820. goto out;
  5821. if (res->access_request)
  5822. decode_access(xdr, &res->access_supported, &res->access_result);
  5823. decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
  5824. if (res->lg_res)
  5825. decode_layoutget(xdr, rqstp, res->lg_res);
  5826. out:
  5827. return status;
  5828. }
  5829. /*
  5830. * Decode OPEN_CONFIRM response
  5831. */
  5832. static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
  5833. struct xdr_stream *xdr,
  5834. void *data)
  5835. {
  5836. struct nfs_open_confirmres *res = data;
  5837. struct compound_hdr hdr;
  5838. int status;
  5839. status = decode_compound_hdr(xdr, &hdr);
  5840. if (status)
  5841. goto out;
  5842. status = decode_putfh(xdr);
  5843. if (status)
  5844. goto out;
  5845. status = decode_open_confirm(xdr, res);
  5846. out:
  5847. return status;
  5848. }
  5849. /*
  5850. * Decode OPEN response
  5851. */
  5852. static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
  5853. struct xdr_stream *xdr,
  5854. void *data)
  5855. {
  5856. struct nfs_openres *res = data;
  5857. struct compound_hdr hdr;
  5858. int status;
  5859. status = decode_compound_hdr(xdr, &hdr);
  5860. if (status)
  5861. goto out;
  5862. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5863. if (status)
  5864. goto out;
  5865. status = decode_putfh(xdr);
  5866. if (status)
  5867. goto out;
  5868. status = decode_open(xdr, res);
  5869. if (status)
  5870. goto out;
  5871. if (res->access_request)
  5872. decode_access(xdr, &res->access_supported, &res->access_result);
  5873. decode_getfattr(xdr, res->f_attr, res->server);
  5874. if (res->lg_res)
  5875. decode_layoutget(xdr, rqstp, res->lg_res);
  5876. out:
  5877. return status;
  5878. }
  5879. /*
  5880. * Decode SETATTR response
  5881. */
  5882. static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
  5883. struct xdr_stream *xdr,
  5884. void *data)
  5885. {
  5886. struct nfs_setattrres *res = data;
  5887. struct compound_hdr hdr;
  5888. int status;
  5889. status = decode_compound_hdr(xdr, &hdr);
  5890. if (status)
  5891. goto out;
  5892. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5893. if (status)
  5894. goto out;
  5895. status = decode_putfh(xdr);
  5896. if (status)
  5897. goto out;
  5898. status = decode_setattr(xdr);
  5899. if (status)
  5900. goto out;
  5901. decode_getfattr_label(xdr, res->fattr, res->label, res->server);
  5902. out:
  5903. return status;
  5904. }
  5905. /*
  5906. * Decode LOCK response
  5907. */
  5908. static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5909. void *data)
  5910. {
  5911. struct nfs_lock_res *res = data;
  5912. struct compound_hdr hdr;
  5913. int status;
  5914. status = decode_compound_hdr(xdr, &hdr);
  5915. if (status)
  5916. goto out;
  5917. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5918. if (status)
  5919. goto out;
  5920. status = decode_putfh(xdr);
  5921. if (status)
  5922. goto out;
  5923. status = decode_lock(xdr, res);
  5924. out:
  5925. return status;
  5926. }
  5927. /*
  5928. * Decode LOCKT response
  5929. */
  5930. static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5931. void *data)
  5932. {
  5933. struct nfs_lockt_res *res = data;
  5934. struct compound_hdr hdr;
  5935. int status;
  5936. status = decode_compound_hdr(xdr, &hdr);
  5937. if (status)
  5938. goto out;
  5939. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5940. if (status)
  5941. goto out;
  5942. status = decode_putfh(xdr);
  5943. if (status)
  5944. goto out;
  5945. status = decode_lockt(xdr, res);
  5946. out:
  5947. return status;
  5948. }
  5949. /*
  5950. * Decode LOCKU response
  5951. */
  5952. static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5953. void *data)
  5954. {
  5955. struct nfs_locku_res *res = data;
  5956. struct compound_hdr hdr;
  5957. int status;
  5958. status = decode_compound_hdr(xdr, &hdr);
  5959. if (status)
  5960. goto out;
  5961. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5962. if (status)
  5963. goto out;
  5964. status = decode_putfh(xdr);
  5965. if (status)
  5966. goto out;
  5967. status = decode_locku(xdr, res);
  5968. out:
  5969. return status;
  5970. }
  5971. static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
  5972. struct xdr_stream *xdr, void *dummy)
  5973. {
  5974. struct compound_hdr hdr;
  5975. int status;
  5976. status = decode_compound_hdr(xdr, &hdr);
  5977. if (!status)
  5978. status = decode_release_lockowner(xdr);
  5979. return status;
  5980. }
  5981. /*
  5982. * Decode READLINK response
  5983. */
  5984. static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
  5985. struct xdr_stream *xdr,
  5986. void *data)
  5987. {
  5988. struct nfs4_readlink_res *res = data;
  5989. struct compound_hdr hdr;
  5990. int status;
  5991. status = decode_compound_hdr(xdr, &hdr);
  5992. if (status)
  5993. goto out;
  5994. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5995. if (status)
  5996. goto out;
  5997. status = decode_putfh(xdr);
  5998. if (status)
  5999. goto out;
  6000. status = decode_readlink(xdr, rqstp);
  6001. out:
  6002. return status;
  6003. }
  6004. /*
  6005. * Decode READDIR response
  6006. */
  6007. static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6008. void *data)
  6009. {
  6010. struct nfs4_readdir_res *res = data;
  6011. struct compound_hdr hdr;
  6012. int status;
  6013. status = decode_compound_hdr(xdr, &hdr);
  6014. if (status)
  6015. goto out;
  6016. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6017. if (status)
  6018. goto out;
  6019. status = decode_putfh(xdr);
  6020. if (status)
  6021. goto out;
  6022. status = decode_readdir(xdr, rqstp, res);
  6023. out:
  6024. return status;
  6025. }
  6026. /*
  6027. * Decode Read response
  6028. */
  6029. static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6030. void *data)
  6031. {
  6032. struct nfs_pgio_res *res = data;
  6033. struct compound_hdr hdr;
  6034. int status;
  6035. status = decode_compound_hdr(xdr, &hdr);
  6036. res->op_status = hdr.status;
  6037. if (status)
  6038. goto out;
  6039. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6040. if (status)
  6041. goto out;
  6042. status = decode_putfh(xdr);
  6043. if (status)
  6044. goto out;
  6045. status = decode_read(xdr, rqstp, res);
  6046. if (!status)
  6047. status = res->count;
  6048. out:
  6049. return status;
  6050. }
  6051. /*
  6052. * Decode WRITE response
  6053. */
  6054. static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6055. void *data)
  6056. {
  6057. struct nfs_pgio_res *res = data;
  6058. struct compound_hdr hdr;
  6059. int status;
  6060. status = decode_compound_hdr(xdr, &hdr);
  6061. res->op_status = hdr.status;
  6062. if (status)
  6063. goto out;
  6064. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6065. if (status)
  6066. goto out;
  6067. status = decode_putfh(xdr);
  6068. if (status)
  6069. goto out;
  6070. status = decode_write(xdr, res);
  6071. if (status)
  6072. goto out;
  6073. if (res->fattr)
  6074. decode_getfattr(xdr, res->fattr, res->server);
  6075. if (!status)
  6076. status = res->count;
  6077. out:
  6078. return status;
  6079. }
  6080. /*
  6081. * Decode COMMIT response
  6082. */
  6083. static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6084. void *data)
  6085. {
  6086. struct nfs_commitres *res = data;
  6087. struct compound_hdr hdr;
  6088. int status;
  6089. status = decode_compound_hdr(xdr, &hdr);
  6090. res->op_status = hdr.status;
  6091. if (status)
  6092. goto out;
  6093. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6094. if (status)
  6095. goto out;
  6096. status = decode_putfh(xdr);
  6097. if (status)
  6098. goto out;
  6099. status = decode_commit(xdr, res);
  6100. out:
  6101. return status;
  6102. }
  6103. /*
  6104. * Decode FSINFO response
  6105. */
  6106. static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
  6107. void *data)
  6108. {
  6109. struct nfs4_fsinfo_res *res = data;
  6110. struct compound_hdr hdr;
  6111. int status;
  6112. status = decode_compound_hdr(xdr, &hdr);
  6113. if (!status)
  6114. status = decode_sequence(xdr, &res->seq_res, req);
  6115. if (!status)
  6116. status = decode_putfh(xdr);
  6117. if (!status)
  6118. status = decode_fsinfo(xdr, res->fsinfo);
  6119. return status;
  6120. }
  6121. /*
  6122. * Decode PATHCONF response
  6123. */
  6124. static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
  6125. void *data)
  6126. {
  6127. struct nfs4_pathconf_res *res = data;
  6128. struct compound_hdr hdr;
  6129. int status;
  6130. status = decode_compound_hdr(xdr, &hdr);
  6131. if (!status)
  6132. status = decode_sequence(xdr, &res->seq_res, req);
  6133. if (!status)
  6134. status = decode_putfh(xdr);
  6135. if (!status)
  6136. status = decode_pathconf(xdr, res->pathconf);
  6137. return status;
  6138. }
  6139. /*
  6140. * Decode STATFS response
  6141. */
  6142. static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
  6143. void *data)
  6144. {
  6145. struct nfs4_statfs_res *res = data;
  6146. struct compound_hdr hdr;
  6147. int status;
  6148. status = decode_compound_hdr(xdr, &hdr);
  6149. if (!status)
  6150. status = decode_sequence(xdr, &res->seq_res, req);
  6151. if (!status)
  6152. status = decode_putfh(xdr);
  6153. if (!status)
  6154. status = decode_statfs(xdr, res->fsstat);
  6155. return status;
  6156. }
  6157. /*
  6158. * Decode GETATTR_BITMAP response
  6159. */
  6160. static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
  6161. struct xdr_stream *xdr,
  6162. void *data)
  6163. {
  6164. struct nfs4_server_caps_res *res = data;
  6165. struct compound_hdr hdr;
  6166. int status;
  6167. status = decode_compound_hdr(xdr, &hdr);
  6168. if (status)
  6169. goto out;
  6170. status = decode_sequence(xdr, &res->seq_res, req);
  6171. if (status)
  6172. goto out;
  6173. status = decode_putfh(xdr);
  6174. if (status)
  6175. goto out;
  6176. status = decode_server_caps(xdr, res);
  6177. out:
  6178. return status;
  6179. }
  6180. /*
  6181. * Decode RENEW response
  6182. */
  6183. static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6184. void *__unused)
  6185. {
  6186. struct compound_hdr hdr;
  6187. int status;
  6188. status = decode_compound_hdr(xdr, &hdr);
  6189. if (!status)
  6190. status = decode_renew(xdr);
  6191. return status;
  6192. }
  6193. /*
  6194. * Decode SETCLIENTID response
  6195. */
  6196. static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
  6197. struct xdr_stream *xdr,
  6198. void *data)
  6199. {
  6200. struct nfs4_setclientid_res *res = data;
  6201. struct compound_hdr hdr;
  6202. int status;
  6203. status = decode_compound_hdr(xdr, &hdr);
  6204. if (!status)
  6205. status = decode_setclientid(xdr, res);
  6206. return status;
  6207. }
  6208. /*
  6209. * Decode SETCLIENTID_CONFIRM response
  6210. */
  6211. static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
  6212. struct xdr_stream *xdr,
  6213. void *data)
  6214. {
  6215. struct compound_hdr hdr;
  6216. int status;
  6217. status = decode_compound_hdr(xdr, &hdr);
  6218. if (!status)
  6219. status = decode_setclientid_confirm(xdr);
  6220. return status;
  6221. }
  6222. /*
  6223. * Decode DELEGRETURN response
  6224. */
  6225. static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
  6226. struct xdr_stream *xdr,
  6227. void *data)
  6228. {
  6229. struct nfs4_delegreturnres *res = data;
  6230. struct compound_hdr hdr;
  6231. int status;
  6232. status = decode_compound_hdr(xdr, &hdr);
  6233. if (status)
  6234. goto out;
  6235. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6236. if (status)
  6237. goto out;
  6238. status = decode_putfh(xdr);
  6239. if (status != 0)
  6240. goto out;
  6241. if (res->lr_res) {
  6242. status = decode_layoutreturn(xdr, res->lr_res);
  6243. res->lr_ret = status;
  6244. if (status)
  6245. goto out;
  6246. }
  6247. if (res->fattr) {
  6248. status = decode_getfattr(xdr, res->fattr, res->server);
  6249. if (status != 0)
  6250. goto out;
  6251. }
  6252. status = decode_delegreturn(xdr);
  6253. out:
  6254. return status;
  6255. }
  6256. /*
  6257. * Decode FS_LOCATIONS response
  6258. */
  6259. static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
  6260. struct xdr_stream *xdr,
  6261. void *data)
  6262. {
  6263. struct nfs4_fs_locations_res *res = data;
  6264. struct compound_hdr hdr;
  6265. int status;
  6266. status = decode_compound_hdr(xdr, &hdr);
  6267. if (status)
  6268. goto out;
  6269. status = decode_sequence(xdr, &res->seq_res, req);
  6270. if (status)
  6271. goto out;
  6272. status = decode_putfh(xdr);
  6273. if (status)
  6274. goto out;
  6275. if (res->migration) {
  6276. xdr_enter_page(xdr, PAGE_SIZE);
  6277. status = decode_getfattr_generic(xdr,
  6278. &res->fs_locations->fattr,
  6279. NULL, res->fs_locations,
  6280. NULL, res->fs_locations->server);
  6281. if (status)
  6282. goto out;
  6283. if (res->renew)
  6284. status = decode_renew(xdr);
  6285. } else {
  6286. status = decode_lookup(xdr);
  6287. if (status)
  6288. goto out;
  6289. xdr_enter_page(xdr, PAGE_SIZE);
  6290. status = decode_getfattr_generic(xdr,
  6291. &res->fs_locations->fattr,
  6292. NULL, res->fs_locations,
  6293. NULL, res->fs_locations->server);
  6294. }
  6295. out:
  6296. return status;
  6297. }
  6298. /*
  6299. * Decode SECINFO response
  6300. */
  6301. static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
  6302. struct xdr_stream *xdr,
  6303. void *data)
  6304. {
  6305. struct nfs4_secinfo_res *res = data;
  6306. struct compound_hdr hdr;
  6307. int status;
  6308. status = decode_compound_hdr(xdr, &hdr);
  6309. if (status)
  6310. goto out;
  6311. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6312. if (status)
  6313. goto out;
  6314. status = decode_putfh(xdr);
  6315. if (status)
  6316. goto out;
  6317. status = decode_secinfo(xdr, res);
  6318. out:
  6319. return status;
  6320. }
  6321. /*
  6322. * Decode FSID_PRESENT response
  6323. */
  6324. static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
  6325. struct xdr_stream *xdr,
  6326. void *data)
  6327. {
  6328. struct nfs4_fsid_present_res *res = data;
  6329. struct compound_hdr hdr;
  6330. int status;
  6331. status = decode_compound_hdr(xdr, &hdr);
  6332. if (status)
  6333. goto out;
  6334. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6335. if (status)
  6336. goto out;
  6337. status = decode_putfh(xdr);
  6338. if (status)
  6339. goto out;
  6340. status = decode_getfh(xdr, res->fh);
  6341. if (status)
  6342. goto out;
  6343. if (res->renew)
  6344. status = decode_renew(xdr);
  6345. out:
  6346. return status;
  6347. }
  6348. #if defined(CONFIG_NFS_V4_1)
  6349. /*
  6350. * Decode BIND_CONN_TO_SESSION response
  6351. */
  6352. static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
  6353. struct xdr_stream *xdr,
  6354. void *res)
  6355. {
  6356. struct compound_hdr hdr;
  6357. int status;
  6358. status = decode_compound_hdr(xdr, &hdr);
  6359. if (!status)
  6360. status = decode_bind_conn_to_session(xdr, res);
  6361. return status;
  6362. }
  6363. /*
  6364. * Decode EXCHANGE_ID response
  6365. */
  6366. static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
  6367. struct xdr_stream *xdr,
  6368. void *res)
  6369. {
  6370. struct compound_hdr hdr;
  6371. int status;
  6372. status = decode_compound_hdr(xdr, &hdr);
  6373. if (!status)
  6374. status = decode_exchange_id(xdr, res);
  6375. return status;
  6376. }
  6377. /*
  6378. * Decode CREATE_SESSION response
  6379. */
  6380. static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
  6381. struct xdr_stream *xdr,
  6382. void *res)
  6383. {
  6384. struct compound_hdr hdr;
  6385. int status;
  6386. status = decode_compound_hdr(xdr, &hdr);
  6387. if (!status)
  6388. status = decode_create_session(xdr, res);
  6389. return status;
  6390. }
  6391. /*
  6392. * Decode DESTROY_SESSION response
  6393. */
  6394. static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
  6395. struct xdr_stream *xdr,
  6396. void *res)
  6397. {
  6398. struct compound_hdr hdr;
  6399. int status;
  6400. status = decode_compound_hdr(xdr, &hdr);
  6401. if (!status)
  6402. status = decode_destroy_session(xdr, res);
  6403. return status;
  6404. }
  6405. /*
  6406. * Decode DESTROY_CLIENTID response
  6407. */
  6408. static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
  6409. struct xdr_stream *xdr,
  6410. void *res)
  6411. {
  6412. struct compound_hdr hdr;
  6413. int status;
  6414. status = decode_compound_hdr(xdr, &hdr);
  6415. if (!status)
  6416. status = decode_destroy_clientid(xdr, res);
  6417. return status;
  6418. }
  6419. /*
  6420. * Decode SEQUENCE response
  6421. */
  6422. static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
  6423. struct xdr_stream *xdr,
  6424. void *res)
  6425. {
  6426. struct compound_hdr hdr;
  6427. int status;
  6428. status = decode_compound_hdr(xdr, &hdr);
  6429. if (!status)
  6430. status = decode_sequence(xdr, res, rqstp);
  6431. return status;
  6432. }
  6433. #endif
  6434. /*
  6435. * Decode GET_LEASE_TIME response
  6436. */
  6437. static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
  6438. struct xdr_stream *xdr,
  6439. void *data)
  6440. {
  6441. struct nfs4_get_lease_time_res *res = data;
  6442. struct compound_hdr hdr;
  6443. int status;
  6444. status = decode_compound_hdr(xdr, &hdr);
  6445. if (!status)
  6446. status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
  6447. if (!status)
  6448. status = decode_putrootfh(xdr);
  6449. if (!status)
  6450. status = decode_fsinfo(xdr, res->lr_fsinfo);
  6451. return status;
  6452. }
  6453. #ifdef CONFIG_NFS_V4_1
  6454. /*
  6455. * Decode RECLAIM_COMPLETE response
  6456. */
  6457. static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
  6458. struct xdr_stream *xdr,
  6459. void *data)
  6460. {
  6461. struct nfs41_reclaim_complete_res *res = data;
  6462. struct compound_hdr hdr;
  6463. int status;
  6464. status = decode_compound_hdr(xdr, &hdr);
  6465. if (!status)
  6466. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6467. if (!status)
  6468. status = decode_reclaim_complete(xdr, NULL);
  6469. return status;
  6470. }
  6471. /*
  6472. * Decode GETDEVINFO response
  6473. */
  6474. static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
  6475. struct xdr_stream *xdr,
  6476. void *data)
  6477. {
  6478. struct nfs4_getdeviceinfo_res *res = data;
  6479. struct compound_hdr hdr;
  6480. int status;
  6481. status = decode_compound_hdr(xdr, &hdr);
  6482. if (status != 0)
  6483. goto out;
  6484. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6485. if (status != 0)
  6486. goto out;
  6487. status = decode_getdeviceinfo(xdr, res);
  6488. out:
  6489. return status;
  6490. }
  6491. /*
  6492. * Decode LAYOUTGET response
  6493. */
  6494. static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
  6495. struct xdr_stream *xdr,
  6496. void *data)
  6497. {
  6498. struct nfs4_layoutget_res *res = data;
  6499. struct compound_hdr hdr;
  6500. int status;
  6501. status = decode_compound_hdr(xdr, &hdr);
  6502. if (status)
  6503. goto out;
  6504. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6505. if (status)
  6506. goto out;
  6507. status = decode_putfh(xdr);
  6508. if (status)
  6509. goto out;
  6510. status = decode_layoutget(xdr, rqstp, res);
  6511. out:
  6512. return status;
  6513. }
  6514. /*
  6515. * Decode LAYOUTRETURN response
  6516. */
  6517. static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
  6518. struct xdr_stream *xdr,
  6519. void *data)
  6520. {
  6521. struct nfs4_layoutreturn_res *res = data;
  6522. struct compound_hdr hdr;
  6523. int status;
  6524. status = decode_compound_hdr(xdr, &hdr);
  6525. if (status)
  6526. goto out;
  6527. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6528. if (status)
  6529. goto out;
  6530. status = decode_putfh(xdr);
  6531. if (status)
  6532. goto out;
  6533. status = decode_layoutreturn(xdr, res);
  6534. out:
  6535. return status;
  6536. }
  6537. /*
  6538. * Decode LAYOUTCOMMIT response
  6539. */
  6540. static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
  6541. struct xdr_stream *xdr,
  6542. void *data)
  6543. {
  6544. struct nfs4_layoutcommit_res *res = data;
  6545. struct compound_hdr hdr;
  6546. int status;
  6547. status = decode_compound_hdr(xdr, &hdr);
  6548. if (status)
  6549. goto out;
  6550. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6551. if (status)
  6552. goto out;
  6553. status = decode_putfh(xdr);
  6554. if (status)
  6555. goto out;
  6556. status = decode_layoutcommit(xdr, rqstp, res);
  6557. if (status)
  6558. goto out;
  6559. decode_getfattr(xdr, res->fattr, res->server);
  6560. out:
  6561. return status;
  6562. }
  6563. /*
  6564. * Decode SECINFO_NO_NAME response
  6565. */
  6566. static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
  6567. struct xdr_stream *xdr,
  6568. void *data)
  6569. {
  6570. struct nfs4_secinfo_res *res = data;
  6571. struct compound_hdr hdr;
  6572. int status;
  6573. status = decode_compound_hdr(xdr, &hdr);
  6574. if (status)
  6575. goto out;
  6576. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6577. if (status)
  6578. goto out;
  6579. status = decode_putrootfh(xdr);
  6580. if (status)
  6581. goto out;
  6582. status = decode_secinfo_no_name(xdr, res);
  6583. out:
  6584. return status;
  6585. }
  6586. /*
  6587. * Decode TEST_STATEID response
  6588. */
  6589. static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
  6590. struct xdr_stream *xdr,
  6591. void *data)
  6592. {
  6593. struct nfs41_test_stateid_res *res = data;
  6594. struct compound_hdr hdr;
  6595. int status;
  6596. status = decode_compound_hdr(xdr, &hdr);
  6597. if (status)
  6598. goto out;
  6599. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6600. if (status)
  6601. goto out;
  6602. status = decode_test_stateid(xdr, res);
  6603. out:
  6604. return status;
  6605. }
  6606. /*
  6607. * Decode FREE_STATEID response
  6608. */
  6609. static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
  6610. struct xdr_stream *xdr,
  6611. void *data)
  6612. {
  6613. struct nfs41_free_stateid_res *res = data;
  6614. struct compound_hdr hdr;
  6615. int status;
  6616. status = decode_compound_hdr(xdr, &hdr);
  6617. if (status)
  6618. goto out;
  6619. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6620. if (status)
  6621. goto out;
  6622. status = decode_free_stateid(xdr, res);
  6623. out:
  6624. return status;
  6625. }
  6626. #endif /* CONFIG_NFS_V4_1 */
  6627. /**
  6628. * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
  6629. * the local page cache.
  6630. * @xdr: XDR stream where entry resides
  6631. * @entry: buffer to fill in with entry data
  6632. * @plus: boolean indicating whether this should be a readdirplus entry
  6633. *
  6634. * Returns zero if successful, otherwise a negative errno value is
  6635. * returned.
  6636. *
  6637. * This function is not invoked during READDIR reply decoding, but
  6638. * rather whenever an application invokes the getdents(2) system call
  6639. * on a directory already in our cache.
  6640. */
  6641. int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
  6642. bool plus)
  6643. {
  6644. unsigned int savep;
  6645. uint32_t bitmap[3] = {0};
  6646. uint32_t len;
  6647. uint64_t new_cookie;
  6648. __be32 *p = xdr_inline_decode(xdr, 4);
  6649. if (unlikely(!p))
  6650. return -EAGAIN;
  6651. if (*p == xdr_zero) {
  6652. p = xdr_inline_decode(xdr, 4);
  6653. if (unlikely(!p))
  6654. return -EAGAIN;
  6655. if (*p == xdr_zero)
  6656. return -EAGAIN;
  6657. entry->eof = 1;
  6658. return -EBADCOOKIE;
  6659. }
  6660. p = xdr_inline_decode(xdr, 12);
  6661. if (unlikely(!p))
  6662. return -EAGAIN;
  6663. p = xdr_decode_hyper(p, &new_cookie);
  6664. entry->len = be32_to_cpup(p);
  6665. p = xdr_inline_decode(xdr, entry->len);
  6666. if (unlikely(!p))
  6667. return -EAGAIN;
  6668. entry->name = (const char *) p;
  6669. /*
  6670. * In case the server doesn't return an inode number,
  6671. * we fake one here. (We don't use inode number 0,
  6672. * since glibc seems to choke on it...)
  6673. */
  6674. entry->ino = 1;
  6675. entry->fattr->valid = 0;
  6676. if (decode_attr_bitmap(xdr, bitmap) < 0)
  6677. return -EAGAIN;
  6678. if (decode_attr_length(xdr, &len, &savep) < 0)
  6679. return -EAGAIN;
  6680. if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
  6681. NULL, entry->label, entry->server) < 0)
  6682. return -EAGAIN;
  6683. if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
  6684. entry->ino = entry->fattr->mounted_on_fileid;
  6685. else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
  6686. entry->ino = entry->fattr->fileid;
  6687. entry->d_type = DT_UNKNOWN;
  6688. if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
  6689. entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
  6690. entry->prev_cookie = entry->cookie;
  6691. entry->cookie = new_cookie;
  6692. return 0;
  6693. }
  6694. /*
  6695. * We need to translate between nfs status return values and
  6696. * the local errno values which may not be the same.
  6697. */
  6698. static struct {
  6699. int stat;
  6700. int errno;
  6701. } nfs_errtbl[] = {
  6702. { NFS4_OK, 0 },
  6703. { NFS4ERR_PERM, -EPERM },
  6704. { NFS4ERR_NOENT, -ENOENT },
  6705. { NFS4ERR_IO, -errno_NFSERR_IO},
  6706. { NFS4ERR_NXIO, -ENXIO },
  6707. { NFS4ERR_ACCESS, -EACCES },
  6708. { NFS4ERR_EXIST, -EEXIST },
  6709. { NFS4ERR_XDEV, -EXDEV },
  6710. { NFS4ERR_NOTDIR, -ENOTDIR },
  6711. { NFS4ERR_ISDIR, -EISDIR },
  6712. { NFS4ERR_INVAL, -EINVAL },
  6713. { NFS4ERR_FBIG, -EFBIG },
  6714. { NFS4ERR_NOSPC, -ENOSPC },
  6715. { NFS4ERR_ROFS, -EROFS },
  6716. { NFS4ERR_MLINK, -EMLINK },
  6717. { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
  6718. { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
  6719. { NFS4ERR_DQUOT, -EDQUOT },
  6720. { NFS4ERR_STALE, -ESTALE },
  6721. { NFS4ERR_BADHANDLE, -EBADHANDLE },
  6722. { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
  6723. { NFS4ERR_NOTSUPP, -ENOTSUPP },
  6724. { NFS4ERR_TOOSMALL, -ETOOSMALL },
  6725. { NFS4ERR_SERVERFAULT, -EREMOTEIO },
  6726. { NFS4ERR_BADTYPE, -EBADTYPE },
  6727. { NFS4ERR_LOCKED, -EAGAIN },
  6728. { NFS4ERR_SYMLINK, -ELOOP },
  6729. { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
  6730. { NFS4ERR_DEADLOCK, -EDEADLK },
  6731. { NFS4ERR_NOXATTR, -ENODATA },
  6732. { NFS4ERR_XATTR2BIG, -E2BIG },
  6733. { -1, -EIO }
  6734. };
  6735. /*
  6736. * Convert an NFS error code to a local one.
  6737. * This one is used jointly by NFSv2 and NFSv3.
  6738. */
  6739. static int
  6740. nfs4_stat_to_errno(int stat)
  6741. {
  6742. int i;
  6743. for (i = 0; nfs_errtbl[i].stat != -1; i++) {
  6744. if (nfs_errtbl[i].stat == stat)
  6745. return nfs_errtbl[i].errno;
  6746. }
  6747. if (stat <= 10000 || stat > 10100) {
  6748. /* The server is looney tunes. */
  6749. return -EREMOTEIO;
  6750. }
  6751. /* If we cannot translate the error, the recovery routines should
  6752. * handle it.
  6753. * Note: remaining NFSv4 error codes have values > 10000, so should
  6754. * not conflict with native Linux error codes.
  6755. */
  6756. return -stat;
  6757. }
  6758. #ifdef CONFIG_NFS_V4_2
  6759. #include "nfs42xdr.c"
  6760. #endif /* CONFIG_NFS_V4_2 */
  6761. #define PROC(proc, argtype, restype) \
  6762. [NFSPROC4_CLNT_##proc] = { \
  6763. .p_proc = NFSPROC4_COMPOUND, \
  6764. .p_encode = nfs4_xdr_##argtype, \
  6765. .p_decode = nfs4_xdr_##restype, \
  6766. .p_arglen = NFS4_##argtype##_sz, \
  6767. .p_replen = NFS4_##restype##_sz, \
  6768. .p_statidx = NFSPROC4_CLNT_##proc, \
  6769. .p_name = #proc, \
  6770. }
  6771. #define STUB(proc) \
  6772. [NFSPROC4_CLNT_##proc] = { \
  6773. .p_name = #proc, \
  6774. }
  6775. #if defined(CONFIG_NFS_V4_1)
  6776. #define PROC41(proc, argtype, restype) \
  6777. PROC(proc, argtype, restype)
  6778. #else
  6779. #define PROC41(proc, argtype, restype) \
  6780. STUB(proc)
  6781. #endif
  6782. #if defined(CONFIG_NFS_V4_2)
  6783. #define PROC42(proc, argtype, restype) \
  6784. PROC(proc, argtype, restype)
  6785. #else
  6786. #define PROC42(proc, argtype, restype) \
  6787. STUB(proc)
  6788. #endif
  6789. const struct rpc_procinfo nfs4_procedures[] = {
  6790. PROC(READ, enc_read, dec_read),
  6791. PROC(WRITE, enc_write, dec_write),
  6792. PROC(COMMIT, enc_commit, dec_commit),
  6793. PROC(OPEN, enc_open, dec_open),
  6794. PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
  6795. PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
  6796. PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
  6797. PROC(CLOSE, enc_close, dec_close),
  6798. PROC(SETATTR, enc_setattr, dec_setattr),
  6799. PROC(FSINFO, enc_fsinfo, dec_fsinfo),
  6800. PROC(RENEW, enc_renew, dec_renew),
  6801. PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
  6802. PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
  6803. PROC(LOCK, enc_lock, dec_lock),
  6804. PROC(LOCKT, enc_lockt, dec_lockt),
  6805. PROC(LOCKU, enc_locku, dec_locku),
  6806. PROC(ACCESS, enc_access, dec_access),
  6807. PROC(GETATTR, enc_getattr, dec_getattr),
  6808. PROC(LOOKUP, enc_lookup, dec_lookup),
  6809. PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
  6810. PROC(REMOVE, enc_remove, dec_remove),
  6811. PROC(RENAME, enc_rename, dec_rename),
  6812. PROC(LINK, enc_link, dec_link),
  6813. PROC(SYMLINK, enc_symlink, dec_symlink),
  6814. PROC(CREATE, enc_create, dec_create),
  6815. PROC(PATHCONF, enc_pathconf, dec_pathconf),
  6816. PROC(STATFS, enc_statfs, dec_statfs),
  6817. PROC(READLINK, enc_readlink, dec_readlink),
  6818. PROC(READDIR, enc_readdir, dec_readdir),
  6819. PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
  6820. PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
  6821. PROC(GETACL, enc_getacl, dec_getacl),
  6822. PROC(SETACL, enc_setacl, dec_setacl),
  6823. PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
  6824. PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
  6825. PROC(SECINFO, enc_secinfo, dec_secinfo),
  6826. PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
  6827. PROC41(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
  6828. PROC41(CREATE_SESSION, enc_create_session, dec_create_session),
  6829. PROC41(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
  6830. PROC41(SEQUENCE, enc_sequence, dec_sequence),
  6831. PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
  6832. PROC41(RECLAIM_COMPLETE,enc_reclaim_complete, dec_reclaim_complete),
  6833. PROC41(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
  6834. PROC41(LAYOUTGET, enc_layoutget, dec_layoutget),
  6835. PROC41(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
  6836. PROC41(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
  6837. PROC41(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
  6838. PROC41(TEST_STATEID, enc_test_stateid, dec_test_stateid),
  6839. PROC41(FREE_STATEID, enc_free_stateid, dec_free_stateid),
  6840. STUB(GETDEVICELIST),
  6841. PROC41(BIND_CONN_TO_SESSION,
  6842. enc_bind_conn_to_session, dec_bind_conn_to_session),
  6843. PROC41(DESTROY_CLIENTID,enc_destroy_clientid, dec_destroy_clientid),
  6844. PROC42(SEEK, enc_seek, dec_seek),
  6845. PROC42(ALLOCATE, enc_allocate, dec_allocate),
  6846. PROC42(DEALLOCATE, enc_deallocate, dec_deallocate),
  6847. PROC42(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
  6848. PROC42(CLONE, enc_clone, dec_clone),
  6849. PROC42(COPY, enc_copy, dec_copy),
  6850. PROC42(OFFLOAD_CANCEL, enc_offload_cancel, dec_offload_cancel),
  6851. PROC42(COPY_NOTIFY, enc_copy_notify, dec_copy_notify),
  6852. PROC(LOOKUPP, enc_lookupp, dec_lookupp),
  6853. PROC42(LAYOUTERROR, enc_layouterror, dec_layouterror),
  6854. PROC42(GETXATTR, enc_getxattr, dec_getxattr),
  6855. PROC42(SETXATTR, enc_setxattr, dec_setxattr),
  6856. PROC42(LISTXATTRS, enc_listxattrs, dec_listxattrs),
  6857. PROC42(REMOVEXATTR, enc_removexattr, dec_removexattr),
  6858. PROC42(READ_PLUS, enc_read_plus, dec_read_plus),
  6859. };
  6860. static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)];
  6861. const struct rpc_version nfs_version4 = {
  6862. .number = 4,
  6863. .nrprocs = ARRAY_SIZE(nfs4_procedures),
  6864. .procs = nfs4_procedures,
  6865. .counts = nfs_version4_counts,
  6866. };
  6867. /*
  6868. * Local variables:
  6869. * c-basic-offset: 8
  6870. * End:
  6871. */