nfs4xdr.c 193 KB

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