nfs4xdr.c 202 KB

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