nfs4xdr.c 184 KB

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