nfs4xdr.c 197 KB

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