nfs4xdr.c 197 KB

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