nfs4xdr.c 184 KB

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