nfs4xdr.c 203 KB

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