nfs4xdr.c 198 KB

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