nfs4xdr.c 204 KB

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