nfs4xdr.c 196 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531
  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(nn->boot_time.tv_nsec); /* 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. p = reserve_space(xdr, 20);
  1829. *p++ = cpu_to_be32(1); /* newoffset = TRUE */
  1830. p = xdr_encode_hyper(p, args->lastbytewritten);
  1831. *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
  1832. *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
  1833. if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) {
  1834. NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
  1835. NFS_I(inode)->layout, xdr, args);
  1836. } else {
  1837. encode_uint32(xdr, args->layoutupdate_len);
  1838. if (args->layoutupdate_pages) {
  1839. xdr_write_pages(xdr, args->layoutupdate_pages, 0,
  1840. args->layoutupdate_len);
  1841. }
  1842. }
  1843. return 0;
  1844. }
  1845. static void
  1846. encode_layoutreturn(struct xdr_stream *xdr,
  1847. const struct nfs4_layoutreturn_args *args,
  1848. struct compound_hdr *hdr)
  1849. {
  1850. __be32 *p;
  1851. encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
  1852. p = reserve_space(xdr, 16);
  1853. *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
  1854. *p++ = cpu_to_be32(args->layout_type);
  1855. *p++ = cpu_to_be32(args->range.iomode);
  1856. *p = cpu_to_be32(RETURN_FILE);
  1857. p = reserve_space(xdr, 16);
  1858. p = xdr_encode_hyper(p, args->range.offset);
  1859. p = xdr_encode_hyper(p, args->range.length);
  1860. spin_lock(&args->inode->i_lock);
  1861. encode_nfs4_stateid(xdr, &args->stateid);
  1862. spin_unlock(&args->inode->i_lock);
  1863. if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
  1864. NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
  1865. NFS_I(args->inode)->layout, xdr, args);
  1866. } else
  1867. encode_uint32(xdr, 0);
  1868. }
  1869. static int
  1870. encode_secinfo_no_name(struct xdr_stream *xdr,
  1871. const struct nfs41_secinfo_no_name_args *args,
  1872. struct compound_hdr *hdr)
  1873. {
  1874. encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
  1875. encode_uint32(xdr, args->style);
  1876. return 0;
  1877. }
  1878. static void encode_test_stateid(struct xdr_stream *xdr,
  1879. struct nfs41_test_stateid_args *args,
  1880. struct compound_hdr *hdr)
  1881. {
  1882. encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
  1883. encode_uint32(xdr, 1);
  1884. encode_nfs4_stateid(xdr, args->stateid);
  1885. }
  1886. static void encode_free_stateid(struct xdr_stream *xdr,
  1887. struct nfs41_free_stateid_args *args,
  1888. struct compound_hdr *hdr)
  1889. {
  1890. encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
  1891. encode_nfs4_stateid(xdr, &args->stateid);
  1892. }
  1893. #endif /* CONFIG_NFS_V4_1 */
  1894. /*
  1895. * END OF "GENERIC" ENCODE ROUTINES.
  1896. */
  1897. static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
  1898. {
  1899. #if defined(CONFIG_NFS_V4_1)
  1900. struct nfs4_session *session = args->sa_slot->table->session;
  1901. if (session)
  1902. return session->clp->cl_mvops->minor_version;
  1903. #endif /* CONFIG_NFS_V4_1 */
  1904. return 0;
  1905. }
  1906. /*
  1907. * Encode an ACCESS request
  1908. */
  1909. static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
  1910. const struct nfs4_accessargs *args)
  1911. {
  1912. struct compound_hdr hdr = {
  1913. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1914. };
  1915. encode_compound_hdr(xdr, req, &hdr);
  1916. encode_sequence(xdr, &args->seq_args, &hdr);
  1917. encode_putfh(xdr, args->fh, &hdr);
  1918. encode_access(xdr, args->access, &hdr);
  1919. encode_getfattr(xdr, args->bitmask, &hdr);
  1920. encode_nops(&hdr);
  1921. }
  1922. /*
  1923. * Encode LOOKUP request
  1924. */
  1925. static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
  1926. const struct nfs4_lookup_arg *args)
  1927. {
  1928. struct compound_hdr hdr = {
  1929. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1930. };
  1931. encode_compound_hdr(xdr, req, &hdr);
  1932. encode_sequence(xdr, &args->seq_args, &hdr);
  1933. encode_putfh(xdr, args->dir_fh, &hdr);
  1934. encode_lookup(xdr, args->name, &hdr);
  1935. encode_getfh(xdr, &hdr);
  1936. encode_getfattr(xdr, args->bitmask, &hdr);
  1937. encode_nops(&hdr);
  1938. }
  1939. /*
  1940. * Encode LOOKUP_ROOT request
  1941. */
  1942. static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
  1943. struct xdr_stream *xdr,
  1944. const struct nfs4_lookup_root_arg *args)
  1945. {
  1946. struct compound_hdr hdr = {
  1947. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1948. };
  1949. encode_compound_hdr(xdr, req, &hdr);
  1950. encode_sequence(xdr, &args->seq_args, &hdr);
  1951. encode_putrootfh(xdr, &hdr);
  1952. encode_getfh(xdr, &hdr);
  1953. encode_getfattr(xdr, args->bitmask, &hdr);
  1954. encode_nops(&hdr);
  1955. }
  1956. /*
  1957. * Encode REMOVE request
  1958. */
  1959. static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
  1960. const struct nfs_removeargs *args)
  1961. {
  1962. struct compound_hdr hdr = {
  1963. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1964. };
  1965. encode_compound_hdr(xdr, req, &hdr);
  1966. encode_sequence(xdr, &args->seq_args, &hdr);
  1967. encode_putfh(xdr, args->fh, &hdr);
  1968. encode_remove(xdr, &args->name, &hdr);
  1969. encode_nops(&hdr);
  1970. }
  1971. /*
  1972. * Encode RENAME request
  1973. */
  1974. static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
  1975. const struct nfs_renameargs *args)
  1976. {
  1977. struct compound_hdr hdr = {
  1978. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1979. };
  1980. encode_compound_hdr(xdr, req, &hdr);
  1981. encode_sequence(xdr, &args->seq_args, &hdr);
  1982. encode_putfh(xdr, args->old_dir, &hdr);
  1983. encode_savefh(xdr, &hdr);
  1984. encode_putfh(xdr, args->new_dir, &hdr);
  1985. encode_rename(xdr, args->old_name, args->new_name, &hdr);
  1986. encode_nops(&hdr);
  1987. }
  1988. /*
  1989. * Encode LINK request
  1990. */
  1991. static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
  1992. const struct nfs4_link_arg *args)
  1993. {
  1994. struct compound_hdr hdr = {
  1995. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1996. };
  1997. encode_compound_hdr(xdr, req, &hdr);
  1998. encode_sequence(xdr, &args->seq_args, &hdr);
  1999. encode_putfh(xdr, args->fh, &hdr);
  2000. encode_savefh(xdr, &hdr);
  2001. encode_putfh(xdr, args->dir_fh, &hdr);
  2002. encode_link(xdr, args->name, &hdr);
  2003. encode_restorefh(xdr, &hdr);
  2004. encode_getfattr(xdr, args->bitmask, &hdr);
  2005. encode_nops(&hdr);
  2006. }
  2007. /*
  2008. * Encode CREATE request
  2009. */
  2010. static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
  2011. const struct nfs4_create_arg *args)
  2012. {
  2013. struct compound_hdr hdr = {
  2014. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2015. };
  2016. encode_compound_hdr(xdr, req, &hdr);
  2017. encode_sequence(xdr, &args->seq_args, &hdr);
  2018. encode_putfh(xdr, args->dir_fh, &hdr);
  2019. encode_create(xdr, args, &hdr);
  2020. encode_getfh(xdr, &hdr);
  2021. encode_getfattr(xdr, args->bitmask, &hdr);
  2022. encode_nops(&hdr);
  2023. }
  2024. /*
  2025. * Encode SYMLINK request
  2026. */
  2027. static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
  2028. const struct nfs4_create_arg *args)
  2029. {
  2030. nfs4_xdr_enc_create(req, xdr, args);
  2031. }
  2032. /*
  2033. * Encode GETATTR request
  2034. */
  2035. static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
  2036. const struct nfs4_getattr_arg *args)
  2037. {
  2038. struct compound_hdr hdr = {
  2039. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2040. };
  2041. encode_compound_hdr(xdr, req, &hdr);
  2042. encode_sequence(xdr, &args->seq_args, &hdr);
  2043. encode_putfh(xdr, args->fh, &hdr);
  2044. encode_getfattr(xdr, args->bitmask, &hdr);
  2045. encode_nops(&hdr);
  2046. }
  2047. /*
  2048. * Encode a CLOSE request
  2049. */
  2050. static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
  2051. struct nfs_closeargs *args)
  2052. {
  2053. struct compound_hdr hdr = {
  2054. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2055. };
  2056. encode_compound_hdr(xdr, req, &hdr);
  2057. encode_sequence(xdr, &args->seq_args, &hdr);
  2058. encode_putfh(xdr, args->fh, &hdr);
  2059. encode_close(xdr, args, &hdr);
  2060. encode_getfattr(xdr, args->bitmask, &hdr);
  2061. encode_nops(&hdr);
  2062. }
  2063. /*
  2064. * Encode an OPEN request
  2065. */
  2066. static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
  2067. struct nfs_openargs *args)
  2068. {
  2069. struct compound_hdr hdr = {
  2070. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2071. };
  2072. encode_compound_hdr(xdr, req, &hdr);
  2073. encode_sequence(xdr, &args->seq_args, &hdr);
  2074. encode_putfh(xdr, args->fh, &hdr);
  2075. encode_open(xdr, args, &hdr);
  2076. encode_getfh(xdr, &hdr);
  2077. if (args->access)
  2078. encode_access(xdr, args->access, &hdr);
  2079. encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
  2080. encode_nops(&hdr);
  2081. }
  2082. /*
  2083. * Encode an OPEN_CONFIRM request
  2084. */
  2085. static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
  2086. struct xdr_stream *xdr,
  2087. struct nfs_open_confirmargs *args)
  2088. {
  2089. struct compound_hdr hdr = {
  2090. .nops = 0,
  2091. };
  2092. encode_compound_hdr(xdr, req, &hdr);
  2093. encode_putfh(xdr, args->fh, &hdr);
  2094. encode_open_confirm(xdr, args, &hdr);
  2095. encode_nops(&hdr);
  2096. }
  2097. /*
  2098. * Encode an OPEN request with no attributes.
  2099. */
  2100. static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
  2101. struct xdr_stream *xdr,
  2102. struct nfs_openargs *args)
  2103. {
  2104. struct compound_hdr hdr = {
  2105. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2106. };
  2107. encode_compound_hdr(xdr, req, &hdr);
  2108. encode_sequence(xdr, &args->seq_args, &hdr);
  2109. encode_putfh(xdr, args->fh, &hdr);
  2110. encode_open(xdr, args, &hdr);
  2111. if (args->access)
  2112. encode_access(xdr, args->access, &hdr);
  2113. encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
  2114. encode_nops(&hdr);
  2115. }
  2116. /*
  2117. * Encode an OPEN_DOWNGRADE request
  2118. */
  2119. static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
  2120. struct xdr_stream *xdr,
  2121. struct nfs_closeargs *args)
  2122. {
  2123. struct compound_hdr hdr = {
  2124. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2125. };
  2126. encode_compound_hdr(xdr, req, &hdr);
  2127. encode_sequence(xdr, &args->seq_args, &hdr);
  2128. encode_putfh(xdr, args->fh, &hdr);
  2129. encode_open_downgrade(xdr, args, &hdr);
  2130. encode_getfattr(xdr, args->bitmask, &hdr);
  2131. encode_nops(&hdr);
  2132. }
  2133. /*
  2134. * Encode a LOCK request
  2135. */
  2136. static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
  2137. struct nfs_lock_args *args)
  2138. {
  2139. struct compound_hdr hdr = {
  2140. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2141. };
  2142. encode_compound_hdr(xdr, req, &hdr);
  2143. encode_sequence(xdr, &args->seq_args, &hdr);
  2144. encode_putfh(xdr, args->fh, &hdr);
  2145. encode_lock(xdr, args, &hdr);
  2146. encode_nops(&hdr);
  2147. }
  2148. /*
  2149. * Encode a LOCKT request
  2150. */
  2151. static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
  2152. struct nfs_lockt_args *args)
  2153. {
  2154. struct compound_hdr hdr = {
  2155. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2156. };
  2157. encode_compound_hdr(xdr, req, &hdr);
  2158. encode_sequence(xdr, &args->seq_args, &hdr);
  2159. encode_putfh(xdr, args->fh, &hdr);
  2160. encode_lockt(xdr, args, &hdr);
  2161. encode_nops(&hdr);
  2162. }
  2163. /*
  2164. * Encode a LOCKU request
  2165. */
  2166. static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
  2167. struct nfs_locku_args *args)
  2168. {
  2169. struct compound_hdr hdr = {
  2170. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2171. };
  2172. encode_compound_hdr(xdr, req, &hdr);
  2173. encode_sequence(xdr, &args->seq_args, &hdr);
  2174. encode_putfh(xdr, args->fh, &hdr);
  2175. encode_locku(xdr, args, &hdr);
  2176. encode_nops(&hdr);
  2177. }
  2178. static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
  2179. struct xdr_stream *xdr,
  2180. struct nfs_release_lockowner_args *args)
  2181. {
  2182. struct compound_hdr hdr = {
  2183. .minorversion = 0,
  2184. };
  2185. encode_compound_hdr(xdr, req, &hdr);
  2186. encode_release_lockowner(xdr, &args->lock_owner, &hdr);
  2187. encode_nops(&hdr);
  2188. }
  2189. /*
  2190. * Encode a READLINK request
  2191. */
  2192. static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
  2193. const struct nfs4_readlink *args)
  2194. {
  2195. struct compound_hdr hdr = {
  2196. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2197. };
  2198. encode_compound_hdr(xdr, req, &hdr);
  2199. encode_sequence(xdr, &args->seq_args, &hdr);
  2200. encode_putfh(xdr, args->fh, &hdr);
  2201. encode_readlink(xdr, args, req, &hdr);
  2202. xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
  2203. args->pgbase, args->pglen);
  2204. encode_nops(&hdr);
  2205. }
  2206. /*
  2207. * Encode a READDIR request
  2208. */
  2209. static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
  2210. const struct nfs4_readdir_arg *args)
  2211. {
  2212. struct compound_hdr hdr = {
  2213. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2214. };
  2215. encode_compound_hdr(xdr, req, &hdr);
  2216. encode_sequence(xdr, &args->seq_args, &hdr);
  2217. encode_putfh(xdr, args->fh, &hdr);
  2218. encode_readdir(xdr, args, req, &hdr);
  2219. xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
  2220. args->pgbase, args->count);
  2221. dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
  2222. __func__, hdr.replen << 2, args->pages,
  2223. args->pgbase, args->count);
  2224. encode_nops(&hdr);
  2225. }
  2226. /*
  2227. * Encode a READ request
  2228. */
  2229. static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
  2230. struct nfs_pgio_args *args)
  2231. {
  2232. struct compound_hdr hdr = {
  2233. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2234. };
  2235. encode_compound_hdr(xdr, req, &hdr);
  2236. encode_sequence(xdr, &args->seq_args, &hdr);
  2237. encode_putfh(xdr, args->fh, &hdr);
  2238. encode_read(xdr, args, &hdr);
  2239. xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
  2240. args->pages, args->pgbase, args->count);
  2241. req->rq_rcv_buf.flags |= XDRBUF_READ;
  2242. encode_nops(&hdr);
  2243. }
  2244. /*
  2245. * Encode an SETATTR request
  2246. */
  2247. static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
  2248. struct nfs_setattrargs *args)
  2249. {
  2250. struct compound_hdr hdr = {
  2251. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2252. };
  2253. encode_compound_hdr(xdr, req, &hdr);
  2254. encode_sequence(xdr, &args->seq_args, &hdr);
  2255. encode_putfh(xdr, args->fh, &hdr);
  2256. encode_setattr(xdr, args, args->server, &hdr);
  2257. encode_getfattr(xdr, args->bitmask, &hdr);
  2258. encode_nops(&hdr);
  2259. }
  2260. /*
  2261. * Encode a GETACL request
  2262. */
  2263. static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
  2264. struct nfs_getaclargs *args)
  2265. {
  2266. struct compound_hdr hdr = {
  2267. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2268. };
  2269. uint32_t replen;
  2270. encode_compound_hdr(xdr, req, &hdr);
  2271. encode_sequence(xdr, &args->seq_args, &hdr);
  2272. encode_putfh(xdr, args->fh, &hdr);
  2273. replen = hdr.replen + op_decode_hdr_maxsz;
  2274. encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
  2275. xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
  2276. args->acl_pages, 0, args->acl_len);
  2277. encode_nops(&hdr);
  2278. }
  2279. /*
  2280. * Encode a WRITE request
  2281. */
  2282. static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
  2283. struct nfs_pgio_args *args)
  2284. {
  2285. struct compound_hdr hdr = {
  2286. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2287. };
  2288. encode_compound_hdr(xdr, req, &hdr);
  2289. encode_sequence(xdr, &args->seq_args, &hdr);
  2290. encode_putfh(xdr, args->fh, &hdr);
  2291. encode_write(xdr, args, &hdr);
  2292. req->rq_snd_buf.flags |= XDRBUF_WRITE;
  2293. if (args->bitmask)
  2294. encode_getfattr(xdr, args->bitmask, &hdr);
  2295. encode_nops(&hdr);
  2296. }
  2297. /*
  2298. * a COMMIT request
  2299. */
  2300. static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
  2301. struct nfs_commitargs *args)
  2302. {
  2303. struct compound_hdr hdr = {
  2304. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2305. };
  2306. encode_compound_hdr(xdr, req, &hdr);
  2307. encode_sequence(xdr, &args->seq_args, &hdr);
  2308. encode_putfh(xdr, args->fh, &hdr);
  2309. encode_commit(xdr, args, &hdr);
  2310. encode_nops(&hdr);
  2311. }
  2312. /*
  2313. * FSINFO request
  2314. */
  2315. static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
  2316. struct nfs4_fsinfo_arg *args)
  2317. {
  2318. struct compound_hdr hdr = {
  2319. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2320. };
  2321. encode_compound_hdr(xdr, req, &hdr);
  2322. encode_sequence(xdr, &args->seq_args, &hdr);
  2323. encode_putfh(xdr, args->fh, &hdr);
  2324. encode_fsinfo(xdr, args->bitmask, &hdr);
  2325. encode_nops(&hdr);
  2326. }
  2327. /*
  2328. * a PATHCONF request
  2329. */
  2330. static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
  2331. const struct nfs4_pathconf_arg *args)
  2332. {
  2333. struct compound_hdr hdr = {
  2334. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2335. };
  2336. encode_compound_hdr(xdr, req, &hdr);
  2337. encode_sequence(xdr, &args->seq_args, &hdr);
  2338. encode_putfh(xdr, args->fh, &hdr);
  2339. encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
  2340. &hdr);
  2341. encode_nops(&hdr);
  2342. }
  2343. /*
  2344. * a STATFS request
  2345. */
  2346. static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
  2347. const struct nfs4_statfs_arg *args)
  2348. {
  2349. struct compound_hdr hdr = {
  2350. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2351. };
  2352. encode_compound_hdr(xdr, req, &hdr);
  2353. encode_sequence(xdr, &args->seq_args, &hdr);
  2354. encode_putfh(xdr, args->fh, &hdr);
  2355. encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
  2356. args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
  2357. encode_nops(&hdr);
  2358. }
  2359. /*
  2360. * GETATTR_BITMAP request
  2361. */
  2362. static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
  2363. struct xdr_stream *xdr,
  2364. struct nfs4_server_caps_arg *args)
  2365. {
  2366. const u32 *bitmask = args->bitmask;
  2367. struct compound_hdr hdr = {
  2368. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2369. };
  2370. encode_compound_hdr(xdr, req, &hdr);
  2371. encode_sequence(xdr, &args->seq_args, &hdr);
  2372. encode_putfh(xdr, args->fhandle, &hdr);
  2373. encode_getattr_three(xdr, bitmask[0], bitmask[1], bitmask[2], &hdr);
  2374. encode_nops(&hdr);
  2375. }
  2376. /*
  2377. * a RENEW request
  2378. */
  2379. static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
  2380. struct nfs_client *clp)
  2381. {
  2382. struct compound_hdr hdr = {
  2383. .nops = 0,
  2384. };
  2385. encode_compound_hdr(xdr, req, &hdr);
  2386. encode_renew(xdr, clp->cl_clientid, &hdr);
  2387. encode_nops(&hdr);
  2388. }
  2389. /*
  2390. * a SETCLIENTID request
  2391. */
  2392. static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
  2393. struct xdr_stream *xdr,
  2394. struct nfs4_setclientid *sc)
  2395. {
  2396. struct compound_hdr hdr = {
  2397. .nops = 0,
  2398. };
  2399. encode_compound_hdr(xdr, req, &hdr);
  2400. encode_setclientid(xdr, sc, &hdr);
  2401. encode_nops(&hdr);
  2402. }
  2403. /*
  2404. * a SETCLIENTID_CONFIRM request
  2405. */
  2406. static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
  2407. struct xdr_stream *xdr,
  2408. struct nfs4_setclientid_res *arg)
  2409. {
  2410. struct compound_hdr hdr = {
  2411. .nops = 0,
  2412. };
  2413. encode_compound_hdr(xdr, req, &hdr);
  2414. encode_setclientid_confirm(xdr, arg, &hdr);
  2415. encode_nops(&hdr);
  2416. }
  2417. /*
  2418. * DELEGRETURN request
  2419. */
  2420. static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
  2421. struct xdr_stream *xdr,
  2422. const struct nfs4_delegreturnargs *args)
  2423. {
  2424. struct compound_hdr hdr = {
  2425. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2426. };
  2427. encode_compound_hdr(xdr, req, &hdr);
  2428. encode_sequence(xdr, &args->seq_args, &hdr);
  2429. encode_putfh(xdr, args->fhandle, &hdr);
  2430. encode_getfattr(xdr, args->bitmask, &hdr);
  2431. encode_delegreturn(xdr, args->stateid, &hdr);
  2432. encode_nops(&hdr);
  2433. }
  2434. /*
  2435. * Encode FS_LOCATIONS request
  2436. */
  2437. static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
  2438. struct xdr_stream *xdr,
  2439. struct nfs4_fs_locations_arg *args)
  2440. {
  2441. struct compound_hdr hdr = {
  2442. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2443. };
  2444. uint32_t replen;
  2445. encode_compound_hdr(xdr, req, &hdr);
  2446. encode_sequence(xdr, &args->seq_args, &hdr);
  2447. if (args->migration) {
  2448. encode_putfh(xdr, args->fh, &hdr);
  2449. replen = hdr.replen;
  2450. encode_fs_locations(xdr, args->bitmask, &hdr);
  2451. if (args->renew)
  2452. encode_renew(xdr, args->clientid, &hdr);
  2453. } else {
  2454. encode_putfh(xdr, args->dir_fh, &hdr);
  2455. encode_lookup(xdr, args->name, &hdr);
  2456. replen = hdr.replen;
  2457. encode_fs_locations(xdr, args->bitmask, &hdr);
  2458. }
  2459. /* Set up reply kvec to capture returned fs_locations array. */
  2460. xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
  2461. 0, PAGE_SIZE);
  2462. encode_nops(&hdr);
  2463. }
  2464. /*
  2465. * Encode SECINFO request
  2466. */
  2467. static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
  2468. struct xdr_stream *xdr,
  2469. struct nfs4_secinfo_arg *args)
  2470. {
  2471. struct compound_hdr hdr = {
  2472. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2473. };
  2474. encode_compound_hdr(xdr, req, &hdr);
  2475. encode_sequence(xdr, &args->seq_args, &hdr);
  2476. encode_putfh(xdr, args->dir_fh, &hdr);
  2477. encode_secinfo(xdr, args->name, &hdr);
  2478. encode_nops(&hdr);
  2479. }
  2480. /*
  2481. * Encode FSID_PRESENT request
  2482. */
  2483. static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
  2484. struct xdr_stream *xdr,
  2485. struct nfs4_fsid_present_arg *args)
  2486. {
  2487. struct compound_hdr hdr = {
  2488. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2489. };
  2490. encode_compound_hdr(xdr, req, &hdr);
  2491. encode_sequence(xdr, &args->seq_args, &hdr);
  2492. encode_putfh(xdr, args->fh, &hdr);
  2493. encode_getfh(xdr, &hdr);
  2494. if (args->renew)
  2495. encode_renew(xdr, args->clientid, &hdr);
  2496. encode_nops(&hdr);
  2497. }
  2498. #if defined(CONFIG_NFS_V4_1)
  2499. /*
  2500. * BIND_CONN_TO_SESSION request
  2501. */
  2502. static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
  2503. struct xdr_stream *xdr,
  2504. struct nfs41_bind_conn_to_session_args *args)
  2505. {
  2506. struct compound_hdr hdr = {
  2507. .minorversion = args->client->cl_mvops->minor_version,
  2508. };
  2509. encode_compound_hdr(xdr, req, &hdr);
  2510. encode_bind_conn_to_session(xdr, args, &hdr);
  2511. encode_nops(&hdr);
  2512. }
  2513. /*
  2514. * EXCHANGE_ID request
  2515. */
  2516. static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
  2517. struct xdr_stream *xdr,
  2518. struct nfs41_exchange_id_args *args)
  2519. {
  2520. struct compound_hdr hdr = {
  2521. .minorversion = args->client->cl_mvops->minor_version,
  2522. };
  2523. encode_compound_hdr(xdr, req, &hdr);
  2524. encode_exchange_id(xdr, args, &hdr);
  2525. encode_nops(&hdr);
  2526. }
  2527. /*
  2528. * a CREATE_SESSION request
  2529. */
  2530. static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
  2531. struct xdr_stream *xdr,
  2532. struct nfs41_create_session_args *args)
  2533. {
  2534. struct compound_hdr hdr = {
  2535. .minorversion = args->client->cl_mvops->minor_version,
  2536. };
  2537. encode_compound_hdr(xdr, req, &hdr);
  2538. encode_create_session(xdr, args, &hdr);
  2539. encode_nops(&hdr);
  2540. }
  2541. /*
  2542. * a DESTROY_SESSION request
  2543. */
  2544. static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
  2545. struct xdr_stream *xdr,
  2546. struct nfs4_session *session)
  2547. {
  2548. struct compound_hdr hdr = {
  2549. .minorversion = session->clp->cl_mvops->minor_version,
  2550. };
  2551. encode_compound_hdr(xdr, req, &hdr);
  2552. encode_destroy_session(xdr, session, &hdr);
  2553. encode_nops(&hdr);
  2554. }
  2555. /*
  2556. * a DESTROY_CLIENTID request
  2557. */
  2558. static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
  2559. struct xdr_stream *xdr,
  2560. struct nfs_client *clp)
  2561. {
  2562. struct compound_hdr hdr = {
  2563. .minorversion = clp->cl_mvops->minor_version,
  2564. };
  2565. encode_compound_hdr(xdr, req, &hdr);
  2566. encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
  2567. encode_nops(&hdr);
  2568. }
  2569. /*
  2570. * a SEQUENCE request
  2571. */
  2572. static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
  2573. struct nfs4_sequence_args *args)
  2574. {
  2575. struct compound_hdr hdr = {
  2576. .minorversion = nfs4_xdr_minorversion(args),
  2577. };
  2578. encode_compound_hdr(xdr, req, &hdr);
  2579. encode_sequence(xdr, args, &hdr);
  2580. encode_nops(&hdr);
  2581. }
  2582. /*
  2583. * a GET_LEASE_TIME request
  2584. */
  2585. static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
  2586. struct xdr_stream *xdr,
  2587. struct nfs4_get_lease_time_args *args)
  2588. {
  2589. struct compound_hdr hdr = {
  2590. .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
  2591. };
  2592. const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
  2593. encode_compound_hdr(xdr, req, &hdr);
  2594. encode_sequence(xdr, &args->la_seq_args, &hdr);
  2595. encode_putrootfh(xdr, &hdr);
  2596. encode_fsinfo(xdr, lease_bitmap, &hdr);
  2597. encode_nops(&hdr);
  2598. }
  2599. /*
  2600. * a RECLAIM_COMPLETE request
  2601. */
  2602. static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
  2603. struct xdr_stream *xdr,
  2604. struct nfs41_reclaim_complete_args *args)
  2605. {
  2606. struct compound_hdr hdr = {
  2607. .minorversion = nfs4_xdr_minorversion(&args->seq_args)
  2608. };
  2609. encode_compound_hdr(xdr, req, &hdr);
  2610. encode_sequence(xdr, &args->seq_args, &hdr);
  2611. encode_reclaim_complete(xdr, args, &hdr);
  2612. encode_nops(&hdr);
  2613. }
  2614. /*
  2615. * Encode GETDEVICEINFO request
  2616. */
  2617. static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
  2618. struct xdr_stream *xdr,
  2619. struct nfs4_getdeviceinfo_args *args)
  2620. {
  2621. struct compound_hdr hdr = {
  2622. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2623. };
  2624. encode_compound_hdr(xdr, req, &hdr);
  2625. encode_sequence(xdr, &args->seq_args, &hdr);
  2626. encode_getdeviceinfo(xdr, args, &hdr);
  2627. /* set up reply kvec. Subtract notification bitmap max size (2)
  2628. * so that notification bitmap is put in xdr_buf tail */
  2629. xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
  2630. args->pdev->pages, args->pdev->pgbase,
  2631. args->pdev->pglen);
  2632. encode_nops(&hdr);
  2633. }
  2634. /*
  2635. * Encode LAYOUTGET request
  2636. */
  2637. static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
  2638. struct xdr_stream *xdr,
  2639. struct nfs4_layoutget_args *args)
  2640. {
  2641. struct compound_hdr hdr = {
  2642. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2643. };
  2644. encode_compound_hdr(xdr, req, &hdr);
  2645. encode_sequence(xdr, &args->seq_args, &hdr);
  2646. encode_putfh(xdr, NFS_FH(args->inode), &hdr);
  2647. encode_layoutget(xdr, args, &hdr);
  2648. xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
  2649. args->layout.pages, 0, args->layout.pglen);
  2650. encode_nops(&hdr);
  2651. }
  2652. /*
  2653. * Encode LAYOUTCOMMIT request
  2654. */
  2655. static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
  2656. struct xdr_stream *xdr,
  2657. struct nfs4_layoutcommit_args *args)
  2658. {
  2659. struct nfs4_layoutcommit_data *data =
  2660. container_of(args, struct nfs4_layoutcommit_data, args);
  2661. struct compound_hdr hdr = {
  2662. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2663. };
  2664. encode_compound_hdr(xdr, req, &hdr);
  2665. encode_sequence(xdr, &args->seq_args, &hdr);
  2666. encode_putfh(xdr, NFS_FH(args->inode), &hdr);
  2667. encode_layoutcommit(xdr, data->args.inode, args, &hdr);
  2668. encode_getfattr(xdr, args->bitmask, &hdr);
  2669. encode_nops(&hdr);
  2670. }
  2671. /*
  2672. * Encode LAYOUTRETURN request
  2673. */
  2674. static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
  2675. struct xdr_stream *xdr,
  2676. struct nfs4_layoutreturn_args *args)
  2677. {
  2678. struct compound_hdr hdr = {
  2679. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2680. };
  2681. encode_compound_hdr(xdr, req, &hdr);
  2682. encode_sequence(xdr, &args->seq_args, &hdr);
  2683. encode_putfh(xdr, NFS_FH(args->inode), &hdr);
  2684. encode_layoutreturn(xdr, args, &hdr);
  2685. encode_nops(&hdr);
  2686. }
  2687. /*
  2688. * Encode SECINFO_NO_NAME request
  2689. */
  2690. static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
  2691. struct xdr_stream *xdr,
  2692. struct nfs41_secinfo_no_name_args *args)
  2693. {
  2694. struct compound_hdr hdr = {
  2695. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2696. };
  2697. encode_compound_hdr(xdr, req, &hdr);
  2698. encode_sequence(xdr, &args->seq_args, &hdr);
  2699. encode_putrootfh(xdr, &hdr);
  2700. encode_secinfo_no_name(xdr, args, &hdr);
  2701. encode_nops(&hdr);
  2702. return 0;
  2703. }
  2704. /*
  2705. * Encode TEST_STATEID request
  2706. */
  2707. static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
  2708. struct xdr_stream *xdr,
  2709. struct nfs41_test_stateid_args *args)
  2710. {
  2711. struct compound_hdr hdr = {
  2712. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2713. };
  2714. encode_compound_hdr(xdr, req, &hdr);
  2715. encode_sequence(xdr, &args->seq_args, &hdr);
  2716. encode_test_stateid(xdr, args, &hdr);
  2717. encode_nops(&hdr);
  2718. }
  2719. /*
  2720. * Encode FREE_STATEID request
  2721. */
  2722. static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
  2723. struct xdr_stream *xdr,
  2724. struct nfs41_free_stateid_args *args)
  2725. {
  2726. struct compound_hdr hdr = {
  2727. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2728. };
  2729. encode_compound_hdr(xdr, req, &hdr);
  2730. encode_sequence(xdr, &args->seq_args, &hdr);
  2731. encode_free_stateid(xdr, args, &hdr);
  2732. encode_nops(&hdr);
  2733. }
  2734. #endif /* CONFIG_NFS_V4_1 */
  2735. static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
  2736. {
  2737. dprintk("nfs: %s: prematurely hit end of receive buffer. "
  2738. "Remaining buffer length is %tu words.\n",
  2739. func, xdr->end - xdr->p);
  2740. }
  2741. static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
  2742. {
  2743. __be32 *p;
  2744. p = xdr_inline_decode(xdr, 4);
  2745. if (unlikely(!p))
  2746. goto out_overflow;
  2747. *len = be32_to_cpup(p);
  2748. p = xdr_inline_decode(xdr, *len);
  2749. if (unlikely(!p))
  2750. goto out_overflow;
  2751. *string = (char *)p;
  2752. return 0;
  2753. out_overflow:
  2754. print_overflow_msg(__func__, xdr);
  2755. return -EIO;
  2756. }
  2757. static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
  2758. {
  2759. __be32 *p;
  2760. p = xdr_inline_decode(xdr, 8);
  2761. if (unlikely(!p))
  2762. goto out_overflow;
  2763. hdr->status = be32_to_cpup(p++);
  2764. hdr->taglen = be32_to_cpup(p);
  2765. p = xdr_inline_decode(xdr, hdr->taglen + 4);
  2766. if (unlikely(!p))
  2767. goto out_overflow;
  2768. hdr->tag = (char *)p;
  2769. p += XDR_QUADLEN(hdr->taglen);
  2770. hdr->nops = be32_to_cpup(p);
  2771. if (unlikely(hdr->nops < 1))
  2772. return nfs4_stat_to_errno(hdr->status);
  2773. return 0;
  2774. out_overflow:
  2775. print_overflow_msg(__func__, xdr);
  2776. return -EIO;
  2777. }
  2778. static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
  2779. int *nfs_retval)
  2780. {
  2781. __be32 *p;
  2782. uint32_t opnum;
  2783. int32_t nfserr;
  2784. p = xdr_inline_decode(xdr, 8);
  2785. if (unlikely(!p))
  2786. goto out_overflow;
  2787. opnum = be32_to_cpup(p++);
  2788. if (unlikely(opnum != expected))
  2789. goto out_bad_operation;
  2790. nfserr = be32_to_cpup(p);
  2791. if (nfserr == NFS_OK)
  2792. *nfs_retval = 0;
  2793. else
  2794. *nfs_retval = nfs4_stat_to_errno(nfserr);
  2795. return true;
  2796. out_bad_operation:
  2797. dprintk("nfs: Server returned operation"
  2798. " %d but we issued a request for %d\n",
  2799. opnum, expected);
  2800. *nfs_retval = -EREMOTEIO;
  2801. return false;
  2802. out_overflow:
  2803. print_overflow_msg(__func__, xdr);
  2804. *nfs_retval = -EIO;
  2805. return false;
  2806. }
  2807. static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
  2808. {
  2809. int retval;
  2810. __decode_op_hdr(xdr, expected, &retval);
  2811. return retval;
  2812. }
  2813. /* Dummy routine */
  2814. static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
  2815. {
  2816. __be32 *p;
  2817. unsigned int strlen;
  2818. char *str;
  2819. p = xdr_inline_decode(xdr, 12);
  2820. if (likely(p))
  2821. return decode_opaque_inline(xdr, &strlen, &str);
  2822. print_overflow_msg(__func__, xdr);
  2823. return -EIO;
  2824. }
  2825. static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
  2826. {
  2827. uint32_t bmlen;
  2828. __be32 *p;
  2829. p = xdr_inline_decode(xdr, 4);
  2830. if (unlikely(!p))
  2831. goto out_overflow;
  2832. bmlen = be32_to_cpup(p);
  2833. bitmap[0] = bitmap[1] = bitmap[2] = 0;
  2834. p = xdr_inline_decode(xdr, (bmlen << 2));
  2835. if (unlikely(!p))
  2836. goto out_overflow;
  2837. if (bmlen > 0) {
  2838. bitmap[0] = be32_to_cpup(p++);
  2839. if (bmlen > 1) {
  2840. bitmap[1] = be32_to_cpup(p++);
  2841. if (bmlen > 2)
  2842. bitmap[2] = be32_to_cpup(p);
  2843. }
  2844. }
  2845. return 0;
  2846. out_overflow:
  2847. print_overflow_msg(__func__, xdr);
  2848. return -EIO;
  2849. }
  2850. static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
  2851. {
  2852. __be32 *p;
  2853. p = xdr_inline_decode(xdr, 4);
  2854. if (unlikely(!p))
  2855. goto out_overflow;
  2856. *attrlen = be32_to_cpup(p);
  2857. *savep = xdr_stream_pos(xdr);
  2858. return 0;
  2859. out_overflow:
  2860. print_overflow_msg(__func__, xdr);
  2861. return -EIO;
  2862. }
  2863. static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
  2864. {
  2865. if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
  2866. int ret;
  2867. ret = decode_attr_bitmap(xdr, bitmask);
  2868. if (unlikely(ret < 0))
  2869. return ret;
  2870. bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
  2871. } else
  2872. bitmask[0] = bitmask[1] = bitmask[2] = 0;
  2873. dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
  2874. bitmask[0], bitmask[1], bitmask[2]);
  2875. return 0;
  2876. }
  2877. static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
  2878. {
  2879. __be32 *p;
  2880. int ret = 0;
  2881. *type = 0;
  2882. if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
  2883. return -EIO;
  2884. if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
  2885. p = xdr_inline_decode(xdr, 4);
  2886. if (unlikely(!p))
  2887. goto out_overflow;
  2888. *type = be32_to_cpup(p);
  2889. if (*type < NF4REG || *type > NF4NAMEDATTR) {
  2890. dprintk("%s: bad type %d\n", __func__, *type);
  2891. return -EIO;
  2892. }
  2893. bitmap[0] &= ~FATTR4_WORD0_TYPE;
  2894. ret = NFS_ATTR_FATTR_TYPE;
  2895. }
  2896. dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
  2897. return ret;
  2898. out_overflow:
  2899. print_overflow_msg(__func__, xdr);
  2900. return -EIO;
  2901. }
  2902. static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
  2903. uint32_t *bitmap, uint32_t *type)
  2904. {
  2905. __be32 *p;
  2906. *type = 0;
  2907. if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
  2908. return -EIO;
  2909. if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
  2910. p = xdr_inline_decode(xdr, 4);
  2911. if (unlikely(!p))
  2912. goto out_overflow;
  2913. *type = be32_to_cpup(p);
  2914. bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
  2915. }
  2916. dprintk("%s: expire type=0x%x\n", __func__, *type);
  2917. return 0;
  2918. out_overflow:
  2919. print_overflow_msg(__func__, xdr);
  2920. return -EIO;
  2921. }
  2922. static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
  2923. {
  2924. __be32 *p;
  2925. int ret = 0;
  2926. *change = 0;
  2927. if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
  2928. return -EIO;
  2929. if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
  2930. p = xdr_inline_decode(xdr, 8);
  2931. if (unlikely(!p))
  2932. goto out_overflow;
  2933. xdr_decode_hyper(p, change);
  2934. bitmap[0] &= ~FATTR4_WORD0_CHANGE;
  2935. ret = NFS_ATTR_FATTR_CHANGE;
  2936. }
  2937. dprintk("%s: change attribute=%Lu\n", __func__,
  2938. (unsigned long long)*change);
  2939. return ret;
  2940. out_overflow:
  2941. print_overflow_msg(__func__, xdr);
  2942. return -EIO;
  2943. }
  2944. static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
  2945. {
  2946. __be32 *p;
  2947. int ret = 0;
  2948. *size = 0;
  2949. if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
  2950. return -EIO;
  2951. if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
  2952. p = xdr_inline_decode(xdr, 8);
  2953. if (unlikely(!p))
  2954. goto out_overflow;
  2955. xdr_decode_hyper(p, size);
  2956. bitmap[0] &= ~FATTR4_WORD0_SIZE;
  2957. ret = NFS_ATTR_FATTR_SIZE;
  2958. }
  2959. dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
  2960. return ret;
  2961. out_overflow:
  2962. print_overflow_msg(__func__, xdr);
  2963. return -EIO;
  2964. }
  2965. static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2966. {
  2967. __be32 *p;
  2968. *res = 0;
  2969. if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
  2970. return -EIO;
  2971. if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
  2972. p = xdr_inline_decode(xdr, 4);
  2973. if (unlikely(!p))
  2974. goto out_overflow;
  2975. *res = be32_to_cpup(p);
  2976. bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
  2977. }
  2978. dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
  2979. return 0;
  2980. out_overflow:
  2981. print_overflow_msg(__func__, xdr);
  2982. return -EIO;
  2983. }
  2984. static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2985. {
  2986. __be32 *p;
  2987. *res = 0;
  2988. if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
  2989. return -EIO;
  2990. if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
  2991. p = xdr_inline_decode(xdr, 4);
  2992. if (unlikely(!p))
  2993. goto out_overflow;
  2994. *res = be32_to_cpup(p);
  2995. bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
  2996. }
  2997. dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
  2998. return 0;
  2999. out_overflow:
  3000. print_overflow_msg(__func__, xdr);
  3001. return -EIO;
  3002. }
  3003. static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
  3004. {
  3005. __be32 *p;
  3006. int ret = 0;
  3007. fsid->major = 0;
  3008. fsid->minor = 0;
  3009. if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
  3010. return -EIO;
  3011. if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
  3012. p = xdr_inline_decode(xdr, 16);
  3013. if (unlikely(!p))
  3014. goto out_overflow;
  3015. p = xdr_decode_hyper(p, &fsid->major);
  3016. xdr_decode_hyper(p, &fsid->minor);
  3017. bitmap[0] &= ~FATTR4_WORD0_FSID;
  3018. ret = NFS_ATTR_FATTR_FSID;
  3019. }
  3020. dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
  3021. (unsigned long long)fsid->major,
  3022. (unsigned long long)fsid->minor);
  3023. return ret;
  3024. out_overflow:
  3025. print_overflow_msg(__func__, xdr);
  3026. return -EIO;
  3027. }
  3028. static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3029. {
  3030. __be32 *p;
  3031. *res = 60;
  3032. if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
  3033. return -EIO;
  3034. if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
  3035. p = xdr_inline_decode(xdr, 4);
  3036. if (unlikely(!p))
  3037. goto out_overflow;
  3038. *res = be32_to_cpup(p);
  3039. bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
  3040. }
  3041. dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
  3042. return 0;
  3043. out_overflow:
  3044. print_overflow_msg(__func__, xdr);
  3045. return -EIO;
  3046. }
  3047. static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
  3048. {
  3049. __be32 *p;
  3050. if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
  3051. return -EIO;
  3052. if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
  3053. p = xdr_inline_decode(xdr, 4);
  3054. if (unlikely(!p))
  3055. goto out_overflow;
  3056. bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
  3057. *res = -be32_to_cpup(p);
  3058. }
  3059. return 0;
  3060. out_overflow:
  3061. print_overflow_msg(__func__, xdr);
  3062. return -EIO;
  3063. }
  3064. static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
  3065. uint32_t *bitmap, uint32_t *bitmask)
  3066. {
  3067. if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
  3068. int ret;
  3069. ret = decode_attr_bitmap(xdr, bitmask);
  3070. if (unlikely(ret < 0))
  3071. return ret;
  3072. bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
  3073. } else
  3074. bitmask[0] = bitmask[1] = bitmask[2] = 0;
  3075. dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
  3076. bitmask[0], bitmask[1], bitmask[2]);
  3077. return 0;
  3078. }
  3079. static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
  3080. {
  3081. __be32 *p;
  3082. int len;
  3083. if (fh != NULL)
  3084. memset(fh, 0, sizeof(*fh));
  3085. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
  3086. return -EIO;
  3087. if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
  3088. p = xdr_inline_decode(xdr, 4);
  3089. if (unlikely(!p))
  3090. goto out_overflow;
  3091. len = be32_to_cpup(p);
  3092. if (len > NFS4_FHSIZE)
  3093. return -EIO;
  3094. p = xdr_inline_decode(xdr, len);
  3095. if (unlikely(!p))
  3096. goto out_overflow;
  3097. if (fh != NULL) {
  3098. memcpy(fh->data, p, len);
  3099. fh->size = len;
  3100. }
  3101. bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
  3102. }
  3103. return 0;
  3104. out_overflow:
  3105. print_overflow_msg(__func__, xdr);
  3106. return -EIO;
  3107. }
  3108. static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3109. {
  3110. __be32 *p;
  3111. *res = 0;
  3112. if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
  3113. return -EIO;
  3114. if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
  3115. p = xdr_inline_decode(xdr, 4);
  3116. if (unlikely(!p))
  3117. goto out_overflow;
  3118. *res = be32_to_cpup(p);
  3119. bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
  3120. }
  3121. dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
  3122. return 0;
  3123. out_overflow:
  3124. print_overflow_msg(__func__, xdr);
  3125. return -EIO;
  3126. }
  3127. static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
  3128. {
  3129. __be32 *p;
  3130. int ret = 0;
  3131. *fileid = 0;
  3132. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
  3133. return -EIO;
  3134. if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
  3135. p = xdr_inline_decode(xdr, 8);
  3136. if (unlikely(!p))
  3137. goto out_overflow;
  3138. xdr_decode_hyper(p, fileid);
  3139. bitmap[0] &= ~FATTR4_WORD0_FILEID;
  3140. ret = NFS_ATTR_FATTR_FILEID;
  3141. }
  3142. dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
  3143. return ret;
  3144. out_overflow:
  3145. print_overflow_msg(__func__, xdr);
  3146. return -EIO;
  3147. }
  3148. static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
  3149. {
  3150. __be32 *p;
  3151. int ret = 0;
  3152. *fileid = 0;
  3153. if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
  3154. return -EIO;
  3155. if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
  3156. p = xdr_inline_decode(xdr, 8);
  3157. if (unlikely(!p))
  3158. goto out_overflow;
  3159. xdr_decode_hyper(p, fileid);
  3160. bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
  3161. ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
  3162. }
  3163. dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
  3164. return ret;
  3165. out_overflow:
  3166. print_overflow_msg(__func__, xdr);
  3167. return -EIO;
  3168. }
  3169. static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3170. {
  3171. __be32 *p;
  3172. int status = 0;
  3173. *res = 0;
  3174. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
  3175. return -EIO;
  3176. if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
  3177. p = xdr_inline_decode(xdr, 8);
  3178. if (unlikely(!p))
  3179. goto out_overflow;
  3180. xdr_decode_hyper(p, res);
  3181. bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
  3182. }
  3183. dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
  3184. return status;
  3185. out_overflow:
  3186. print_overflow_msg(__func__, xdr);
  3187. return -EIO;
  3188. }
  3189. static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3190. {
  3191. __be32 *p;
  3192. int status = 0;
  3193. *res = 0;
  3194. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
  3195. return -EIO;
  3196. if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
  3197. p = xdr_inline_decode(xdr, 8);
  3198. if (unlikely(!p))
  3199. goto out_overflow;
  3200. xdr_decode_hyper(p, res);
  3201. bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
  3202. }
  3203. dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
  3204. return status;
  3205. out_overflow:
  3206. print_overflow_msg(__func__, xdr);
  3207. return -EIO;
  3208. }
  3209. static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3210. {
  3211. __be32 *p;
  3212. int status = 0;
  3213. *res = 0;
  3214. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
  3215. return -EIO;
  3216. if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
  3217. p = xdr_inline_decode(xdr, 8);
  3218. if (unlikely(!p))
  3219. goto out_overflow;
  3220. xdr_decode_hyper(p, res);
  3221. bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
  3222. }
  3223. dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
  3224. return status;
  3225. out_overflow:
  3226. print_overflow_msg(__func__, xdr);
  3227. return -EIO;
  3228. }
  3229. static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
  3230. {
  3231. u32 n;
  3232. __be32 *p;
  3233. int status = 0;
  3234. p = xdr_inline_decode(xdr, 4);
  3235. if (unlikely(!p))
  3236. goto out_overflow;
  3237. n = be32_to_cpup(p);
  3238. if (n == 0)
  3239. goto root_path;
  3240. dprintk("pathname4: ");
  3241. if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
  3242. dprintk("cannot parse %d components in path\n", n);
  3243. goto out_eio;
  3244. }
  3245. for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
  3246. struct nfs4_string *component = &path->components[path->ncomponents];
  3247. status = decode_opaque_inline(xdr, &component->len, &component->data);
  3248. if (unlikely(status != 0))
  3249. goto out_eio;
  3250. ifdebug (XDR)
  3251. pr_cont("%s%.*s ",
  3252. (path->ncomponents != n ? "/ " : ""),
  3253. component->len, component->data);
  3254. }
  3255. out:
  3256. return status;
  3257. root_path:
  3258. /* a root pathname is sent as a zero component4 */
  3259. path->ncomponents = 1;
  3260. path->components[0].len=0;
  3261. path->components[0].data=NULL;
  3262. dprintk("pathname4: /\n");
  3263. goto out;
  3264. out_eio:
  3265. dprintk(" status %d", status);
  3266. status = -EIO;
  3267. goto out;
  3268. out_overflow:
  3269. print_overflow_msg(__func__, xdr);
  3270. return -EIO;
  3271. }
  3272. static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
  3273. {
  3274. int n;
  3275. __be32 *p;
  3276. int status = -EIO;
  3277. if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
  3278. goto out;
  3279. status = 0;
  3280. if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
  3281. goto out;
  3282. bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
  3283. status = -EIO;
  3284. /* Ignore borken servers that return unrequested attrs */
  3285. if (unlikely(res == NULL))
  3286. goto out;
  3287. dprintk("%s: fsroot:\n", __func__);
  3288. status = decode_pathname(xdr, &res->fs_path);
  3289. if (unlikely(status != 0))
  3290. goto out;
  3291. p = xdr_inline_decode(xdr, 4);
  3292. if (unlikely(!p))
  3293. goto out_overflow;
  3294. n = be32_to_cpup(p);
  3295. if (n <= 0)
  3296. goto out_eio;
  3297. for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
  3298. u32 m;
  3299. struct nfs4_fs_location *loc;
  3300. if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
  3301. break;
  3302. loc = &res->locations[res->nlocations];
  3303. p = xdr_inline_decode(xdr, 4);
  3304. if (unlikely(!p))
  3305. goto out_overflow;
  3306. m = be32_to_cpup(p);
  3307. dprintk("%s: servers:\n", __func__);
  3308. for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
  3309. struct nfs4_string *server;
  3310. if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
  3311. unsigned int i;
  3312. dprintk("%s: using first %u of %u servers "
  3313. "returned for location %u\n",
  3314. __func__,
  3315. NFS4_FS_LOCATION_MAXSERVERS,
  3316. m, res->nlocations);
  3317. for (i = loc->nservers; i < m; i++) {
  3318. unsigned int len;
  3319. char *data;
  3320. status = decode_opaque_inline(xdr, &len, &data);
  3321. if (unlikely(status != 0))
  3322. goto out_eio;
  3323. }
  3324. break;
  3325. }
  3326. server = &loc->servers[loc->nservers];
  3327. status = decode_opaque_inline(xdr, &server->len, &server->data);
  3328. if (unlikely(status != 0))
  3329. goto out_eio;
  3330. dprintk("%s ", server->data);
  3331. }
  3332. status = decode_pathname(xdr, &loc->rootpath);
  3333. if (unlikely(status != 0))
  3334. goto out_eio;
  3335. }
  3336. if (res->nlocations != 0)
  3337. status = NFS_ATTR_FATTR_V4_LOCATIONS;
  3338. out:
  3339. dprintk("%s: fs_locations done, error = %d\n", __func__, status);
  3340. return status;
  3341. out_overflow:
  3342. print_overflow_msg(__func__, xdr);
  3343. out_eio:
  3344. status = -EIO;
  3345. goto out;
  3346. }
  3347. static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3348. {
  3349. __be32 *p;
  3350. int status = 0;
  3351. *res = 0;
  3352. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
  3353. return -EIO;
  3354. if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
  3355. p = xdr_inline_decode(xdr, 8);
  3356. if (unlikely(!p))
  3357. goto out_overflow;
  3358. xdr_decode_hyper(p, res);
  3359. bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
  3360. }
  3361. dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
  3362. return status;
  3363. out_overflow:
  3364. print_overflow_msg(__func__, xdr);
  3365. return -EIO;
  3366. }
  3367. static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
  3368. {
  3369. __be32 *p;
  3370. int status = 0;
  3371. *maxlink = 1;
  3372. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
  3373. return -EIO;
  3374. if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
  3375. p = xdr_inline_decode(xdr, 4);
  3376. if (unlikely(!p))
  3377. goto out_overflow;
  3378. *maxlink = be32_to_cpup(p);
  3379. bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
  3380. }
  3381. dprintk("%s: maxlink=%u\n", __func__, *maxlink);
  3382. return status;
  3383. out_overflow:
  3384. print_overflow_msg(__func__, xdr);
  3385. return -EIO;
  3386. }
  3387. static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
  3388. {
  3389. __be32 *p;
  3390. int status = 0;
  3391. *maxname = 1024;
  3392. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
  3393. return -EIO;
  3394. if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
  3395. p = xdr_inline_decode(xdr, 4);
  3396. if (unlikely(!p))
  3397. goto out_overflow;
  3398. *maxname = be32_to_cpup(p);
  3399. bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
  3400. }
  3401. dprintk("%s: maxname=%u\n", __func__, *maxname);
  3402. return status;
  3403. out_overflow:
  3404. print_overflow_msg(__func__, xdr);
  3405. return -EIO;
  3406. }
  3407. static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3408. {
  3409. __be32 *p;
  3410. int status = 0;
  3411. *res = 1024;
  3412. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
  3413. return -EIO;
  3414. if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
  3415. uint64_t maxread;
  3416. p = xdr_inline_decode(xdr, 8);
  3417. if (unlikely(!p))
  3418. goto out_overflow;
  3419. xdr_decode_hyper(p, &maxread);
  3420. if (maxread > 0x7FFFFFFF)
  3421. maxread = 0x7FFFFFFF;
  3422. *res = (uint32_t)maxread;
  3423. bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
  3424. }
  3425. dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
  3426. return status;
  3427. out_overflow:
  3428. print_overflow_msg(__func__, xdr);
  3429. return -EIO;
  3430. }
  3431. static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3432. {
  3433. __be32 *p;
  3434. int status = 0;
  3435. *res = 1024;
  3436. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
  3437. return -EIO;
  3438. if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
  3439. uint64_t maxwrite;
  3440. p = xdr_inline_decode(xdr, 8);
  3441. if (unlikely(!p))
  3442. goto out_overflow;
  3443. xdr_decode_hyper(p, &maxwrite);
  3444. if (maxwrite > 0x7FFFFFFF)
  3445. maxwrite = 0x7FFFFFFF;
  3446. *res = (uint32_t)maxwrite;
  3447. bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
  3448. }
  3449. dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
  3450. return status;
  3451. out_overflow:
  3452. print_overflow_msg(__func__, xdr);
  3453. return -EIO;
  3454. }
  3455. static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
  3456. {
  3457. uint32_t tmp;
  3458. __be32 *p;
  3459. int ret = 0;
  3460. *mode = 0;
  3461. if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
  3462. return -EIO;
  3463. if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
  3464. p = xdr_inline_decode(xdr, 4);
  3465. if (unlikely(!p))
  3466. goto out_overflow;
  3467. tmp = be32_to_cpup(p);
  3468. *mode = tmp & ~S_IFMT;
  3469. bitmap[1] &= ~FATTR4_WORD1_MODE;
  3470. ret = NFS_ATTR_FATTR_MODE;
  3471. }
  3472. dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
  3473. return ret;
  3474. out_overflow:
  3475. print_overflow_msg(__func__, xdr);
  3476. return -EIO;
  3477. }
  3478. static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
  3479. {
  3480. __be32 *p;
  3481. int ret = 0;
  3482. *nlink = 1;
  3483. if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
  3484. return -EIO;
  3485. if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
  3486. p = xdr_inline_decode(xdr, 4);
  3487. if (unlikely(!p))
  3488. goto out_overflow;
  3489. *nlink = be32_to_cpup(p);
  3490. bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
  3491. ret = NFS_ATTR_FATTR_NLINK;
  3492. }
  3493. dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
  3494. return ret;
  3495. out_overflow:
  3496. print_overflow_msg(__func__, xdr);
  3497. return -EIO;
  3498. }
  3499. static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
  3500. const struct nfs_server *server, kuid_t *uid,
  3501. struct nfs4_string *owner_name)
  3502. {
  3503. uint32_t len;
  3504. __be32 *p;
  3505. int ret = 0;
  3506. *uid = make_kuid(&init_user_ns, -2);
  3507. if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
  3508. return -EIO;
  3509. if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
  3510. p = xdr_inline_decode(xdr, 4);
  3511. if (unlikely(!p))
  3512. goto out_overflow;
  3513. len = be32_to_cpup(p);
  3514. p = xdr_inline_decode(xdr, len);
  3515. if (unlikely(!p))
  3516. goto out_overflow;
  3517. if (owner_name != NULL) {
  3518. owner_name->data = kmemdup(p, len, GFP_NOWAIT);
  3519. if (owner_name->data != NULL) {
  3520. owner_name->len = len;
  3521. ret = NFS_ATTR_FATTR_OWNER_NAME;
  3522. }
  3523. } else if (len < XDR_MAX_NETOBJ) {
  3524. if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
  3525. ret = NFS_ATTR_FATTR_OWNER;
  3526. else
  3527. dprintk("%s: nfs_map_name_to_uid failed!\n",
  3528. __func__);
  3529. } else
  3530. dprintk("%s: name too long (%u)!\n",
  3531. __func__, len);
  3532. bitmap[1] &= ~FATTR4_WORD1_OWNER;
  3533. }
  3534. dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
  3535. return ret;
  3536. out_overflow:
  3537. print_overflow_msg(__func__, xdr);
  3538. return -EIO;
  3539. }
  3540. static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
  3541. const struct nfs_server *server, kgid_t *gid,
  3542. struct nfs4_string *group_name)
  3543. {
  3544. uint32_t len;
  3545. __be32 *p;
  3546. int ret = 0;
  3547. *gid = make_kgid(&init_user_ns, -2);
  3548. if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
  3549. return -EIO;
  3550. if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
  3551. p = xdr_inline_decode(xdr, 4);
  3552. if (unlikely(!p))
  3553. goto out_overflow;
  3554. len = be32_to_cpup(p);
  3555. p = xdr_inline_decode(xdr, len);
  3556. if (unlikely(!p))
  3557. goto out_overflow;
  3558. if (group_name != NULL) {
  3559. group_name->data = kmemdup(p, len, GFP_NOWAIT);
  3560. if (group_name->data != NULL) {
  3561. group_name->len = len;
  3562. ret = NFS_ATTR_FATTR_GROUP_NAME;
  3563. }
  3564. } else if (len < XDR_MAX_NETOBJ) {
  3565. if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
  3566. ret = NFS_ATTR_FATTR_GROUP;
  3567. else
  3568. dprintk("%s: nfs_map_group_to_gid failed!\n",
  3569. __func__);
  3570. } else
  3571. dprintk("%s: name too long (%u)!\n",
  3572. __func__, len);
  3573. bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
  3574. }
  3575. dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
  3576. return ret;
  3577. out_overflow:
  3578. print_overflow_msg(__func__, xdr);
  3579. return -EIO;
  3580. }
  3581. static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
  3582. {
  3583. uint32_t major = 0, minor = 0;
  3584. __be32 *p;
  3585. int ret = 0;
  3586. *rdev = MKDEV(0,0);
  3587. if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
  3588. return -EIO;
  3589. if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
  3590. dev_t tmp;
  3591. p = xdr_inline_decode(xdr, 8);
  3592. if (unlikely(!p))
  3593. goto out_overflow;
  3594. major = be32_to_cpup(p++);
  3595. minor = be32_to_cpup(p);
  3596. tmp = MKDEV(major, minor);
  3597. if (MAJOR(tmp) == major && MINOR(tmp) == minor)
  3598. *rdev = tmp;
  3599. bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
  3600. ret = NFS_ATTR_FATTR_RDEV;
  3601. }
  3602. dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
  3603. return ret;
  3604. out_overflow:
  3605. print_overflow_msg(__func__, xdr);
  3606. return -EIO;
  3607. }
  3608. static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3609. {
  3610. __be32 *p;
  3611. int status = 0;
  3612. *res = 0;
  3613. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
  3614. return -EIO;
  3615. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
  3616. p = xdr_inline_decode(xdr, 8);
  3617. if (unlikely(!p))
  3618. goto out_overflow;
  3619. xdr_decode_hyper(p, res);
  3620. bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
  3621. }
  3622. dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
  3623. return status;
  3624. out_overflow:
  3625. print_overflow_msg(__func__, xdr);
  3626. return -EIO;
  3627. }
  3628. static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3629. {
  3630. __be32 *p;
  3631. int status = 0;
  3632. *res = 0;
  3633. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
  3634. return -EIO;
  3635. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
  3636. p = xdr_inline_decode(xdr, 8);
  3637. if (unlikely(!p))
  3638. goto out_overflow;
  3639. xdr_decode_hyper(p, res);
  3640. bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
  3641. }
  3642. dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
  3643. return status;
  3644. out_overflow:
  3645. print_overflow_msg(__func__, xdr);
  3646. return -EIO;
  3647. }
  3648. static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3649. {
  3650. __be32 *p;
  3651. int status = 0;
  3652. *res = 0;
  3653. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
  3654. return -EIO;
  3655. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
  3656. p = xdr_inline_decode(xdr, 8);
  3657. if (unlikely(!p))
  3658. goto out_overflow;
  3659. xdr_decode_hyper(p, res);
  3660. bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
  3661. }
  3662. dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
  3663. return status;
  3664. out_overflow:
  3665. print_overflow_msg(__func__, xdr);
  3666. return -EIO;
  3667. }
  3668. static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
  3669. {
  3670. __be32 *p;
  3671. int ret = 0;
  3672. *used = 0;
  3673. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
  3674. return -EIO;
  3675. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
  3676. p = xdr_inline_decode(xdr, 8);
  3677. if (unlikely(!p))
  3678. goto out_overflow;
  3679. xdr_decode_hyper(p, used);
  3680. bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
  3681. ret = NFS_ATTR_FATTR_SPACE_USED;
  3682. }
  3683. dprintk("%s: space used=%Lu\n", __func__,
  3684. (unsigned long long)*used);
  3685. return ret;
  3686. out_overflow:
  3687. print_overflow_msg(__func__, xdr);
  3688. return -EIO;
  3689. }
  3690. static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
  3691. {
  3692. __be32 *p;
  3693. uint64_t sec;
  3694. uint32_t nsec;
  3695. p = xdr_inline_decode(xdr, 12);
  3696. if (unlikely(!p))
  3697. goto out_overflow;
  3698. p = xdr_decode_hyper(p, &sec);
  3699. nsec = be32_to_cpup(p);
  3700. time->tv_sec = (time_t)sec;
  3701. time->tv_nsec = (long)nsec;
  3702. return 0;
  3703. out_overflow:
  3704. print_overflow_msg(__func__, xdr);
  3705. return -EIO;
  3706. }
  3707. static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
  3708. {
  3709. int status = 0;
  3710. time->tv_sec = 0;
  3711. time->tv_nsec = 0;
  3712. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
  3713. return -EIO;
  3714. if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
  3715. status = decode_attr_time(xdr, time);
  3716. if (status == 0)
  3717. status = NFS_ATTR_FATTR_ATIME;
  3718. bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
  3719. }
  3720. dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
  3721. return status;
  3722. }
  3723. static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
  3724. {
  3725. int status = 0;
  3726. time->tv_sec = 0;
  3727. time->tv_nsec = 0;
  3728. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
  3729. return -EIO;
  3730. if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
  3731. status = decode_attr_time(xdr, time);
  3732. if (status == 0)
  3733. status = NFS_ATTR_FATTR_CTIME;
  3734. bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
  3735. }
  3736. dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
  3737. return status;
  3738. }
  3739. static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
  3740. struct timespec *time)
  3741. {
  3742. int status = 0;
  3743. time->tv_sec = 0;
  3744. time->tv_nsec = 0;
  3745. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
  3746. return -EIO;
  3747. if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
  3748. status = decode_attr_time(xdr, time);
  3749. bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
  3750. }
  3751. dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
  3752. (long)time->tv_nsec);
  3753. return status;
  3754. }
  3755. static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
  3756. struct nfs4_label *label)
  3757. {
  3758. uint32_t pi = 0;
  3759. uint32_t lfs = 0;
  3760. __u32 len;
  3761. __be32 *p;
  3762. int status = 0;
  3763. if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
  3764. return -EIO;
  3765. if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
  3766. p = xdr_inline_decode(xdr, 4);
  3767. if (unlikely(!p))
  3768. goto out_overflow;
  3769. lfs = be32_to_cpup(p++);
  3770. p = xdr_inline_decode(xdr, 4);
  3771. if (unlikely(!p))
  3772. goto out_overflow;
  3773. pi = be32_to_cpup(p++);
  3774. p = xdr_inline_decode(xdr, 4);
  3775. if (unlikely(!p))
  3776. goto out_overflow;
  3777. len = be32_to_cpup(p++);
  3778. p = xdr_inline_decode(xdr, len);
  3779. if (unlikely(!p))
  3780. goto out_overflow;
  3781. if (len < NFS4_MAXLABELLEN) {
  3782. if (label) {
  3783. memcpy(label->label, p, len);
  3784. label->len = len;
  3785. label->pi = pi;
  3786. label->lfs = lfs;
  3787. status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
  3788. }
  3789. bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
  3790. } else
  3791. printk(KERN_WARNING "%s: label too long (%u)!\n",
  3792. __func__, len);
  3793. }
  3794. if (label && label->label)
  3795. dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
  3796. (char *)label->label, label->len, label->pi, label->lfs);
  3797. return status;
  3798. out_overflow:
  3799. print_overflow_msg(__func__, xdr);
  3800. return -EIO;
  3801. }
  3802. static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
  3803. {
  3804. int status = 0;
  3805. time->tv_sec = 0;
  3806. time->tv_nsec = 0;
  3807. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
  3808. return -EIO;
  3809. if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
  3810. status = decode_attr_time(xdr, time);
  3811. if (status == 0)
  3812. status = NFS_ATTR_FATTR_MTIME;
  3813. bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
  3814. }
  3815. dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
  3816. return status;
  3817. }
  3818. static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
  3819. {
  3820. unsigned int attrwords = XDR_QUADLEN(attrlen);
  3821. unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
  3822. if (unlikely(attrwords != nwords)) {
  3823. dprintk("%s: server returned incorrect attribute length: "
  3824. "%u %c %u\n",
  3825. __func__,
  3826. attrwords << 2,
  3827. (attrwords < nwords) ? '<' : '>',
  3828. nwords << 2);
  3829. return -EIO;
  3830. }
  3831. return 0;
  3832. }
  3833. static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  3834. {
  3835. __be32 *p;
  3836. p = xdr_inline_decode(xdr, 20);
  3837. if (unlikely(!p))
  3838. goto out_overflow;
  3839. cinfo->atomic = be32_to_cpup(p++);
  3840. p = xdr_decode_hyper(p, &cinfo->before);
  3841. xdr_decode_hyper(p, &cinfo->after);
  3842. return 0;
  3843. out_overflow:
  3844. print_overflow_msg(__func__, xdr);
  3845. return -EIO;
  3846. }
  3847. static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
  3848. {
  3849. __be32 *p;
  3850. uint32_t supp, acc;
  3851. int status;
  3852. status = decode_op_hdr(xdr, OP_ACCESS);
  3853. if (status)
  3854. return status;
  3855. p = xdr_inline_decode(xdr, 8);
  3856. if (unlikely(!p))
  3857. goto out_overflow;
  3858. supp = be32_to_cpup(p++);
  3859. acc = be32_to_cpup(p);
  3860. *supported = supp;
  3861. *access = acc;
  3862. return 0;
  3863. out_overflow:
  3864. print_overflow_msg(__func__, xdr);
  3865. return -EIO;
  3866. }
  3867. static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
  3868. {
  3869. __be32 *p;
  3870. p = xdr_inline_decode(xdr, len);
  3871. if (likely(p)) {
  3872. memcpy(buf, p, len);
  3873. return 0;
  3874. }
  3875. print_overflow_msg(__func__, xdr);
  3876. return -EIO;
  3877. }
  3878. static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  3879. {
  3880. return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
  3881. }
  3882. static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
  3883. {
  3884. int status;
  3885. status = decode_op_hdr(xdr, OP_CLOSE);
  3886. if (status != -EIO)
  3887. nfs_increment_open_seqid(status, res->seqid);
  3888. if (!status)
  3889. status = decode_stateid(xdr, &res->stateid);
  3890. return status;
  3891. }
  3892. static int decode_verifier(struct xdr_stream *xdr, void *verifier)
  3893. {
  3894. return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
  3895. }
  3896. static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
  3897. {
  3898. return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
  3899. }
  3900. static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
  3901. {
  3902. int status;
  3903. status = decode_op_hdr(xdr, OP_COMMIT);
  3904. if (!status)
  3905. status = decode_write_verifier(xdr, &res->verf->verifier);
  3906. return status;
  3907. }
  3908. static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  3909. {
  3910. __be32 *p;
  3911. uint32_t bmlen;
  3912. int status;
  3913. status = decode_op_hdr(xdr, OP_CREATE);
  3914. if (status)
  3915. return status;
  3916. if ((status = decode_change_info(xdr, cinfo)))
  3917. return status;
  3918. p = xdr_inline_decode(xdr, 4);
  3919. if (unlikely(!p))
  3920. goto out_overflow;
  3921. bmlen = be32_to_cpup(p);
  3922. p = xdr_inline_decode(xdr, bmlen << 2);
  3923. if (likely(p))
  3924. return 0;
  3925. out_overflow:
  3926. print_overflow_msg(__func__, xdr);
  3927. return -EIO;
  3928. }
  3929. static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
  3930. {
  3931. unsigned int savep;
  3932. uint32_t attrlen, bitmap[3] = {0};
  3933. int status;
  3934. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  3935. goto xdr_error;
  3936. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  3937. goto xdr_error;
  3938. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  3939. goto xdr_error;
  3940. if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
  3941. goto xdr_error;
  3942. if ((status = decode_attr_fh_expire_type(xdr, bitmap,
  3943. &res->fh_expire_type)) != 0)
  3944. goto xdr_error;
  3945. if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
  3946. goto xdr_error;
  3947. if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
  3948. goto xdr_error;
  3949. if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
  3950. goto xdr_error;
  3951. if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
  3952. res->exclcreat_bitmask)) != 0)
  3953. goto xdr_error;
  3954. status = verify_attr_len(xdr, savep, attrlen);
  3955. xdr_error:
  3956. dprintk("%s: xdr returned %d!\n", __func__, -status);
  3957. return status;
  3958. }
  3959. static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
  3960. {
  3961. unsigned int savep;
  3962. uint32_t attrlen, bitmap[3] = {0};
  3963. int status;
  3964. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  3965. goto xdr_error;
  3966. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  3967. goto xdr_error;
  3968. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  3969. goto xdr_error;
  3970. if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
  3971. goto xdr_error;
  3972. if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
  3973. goto xdr_error;
  3974. if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
  3975. goto xdr_error;
  3976. status = -EIO;
  3977. if (unlikely(bitmap[0]))
  3978. goto xdr_error;
  3979. if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
  3980. goto xdr_error;
  3981. if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
  3982. goto xdr_error;
  3983. if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
  3984. goto xdr_error;
  3985. status = verify_attr_len(xdr, savep, attrlen);
  3986. xdr_error:
  3987. dprintk("%s: xdr returned %d!\n", __func__, -status);
  3988. return status;
  3989. }
  3990. static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
  3991. {
  3992. unsigned int savep;
  3993. uint32_t attrlen, bitmap[3] = {0};
  3994. int status;
  3995. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  3996. goto xdr_error;
  3997. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  3998. goto xdr_error;
  3999. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  4000. goto xdr_error;
  4001. if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
  4002. goto xdr_error;
  4003. if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 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_threshold_hint(struct xdr_stream *xdr,
  4011. uint32_t *bitmap,
  4012. uint64_t *res,
  4013. uint32_t hint_bit)
  4014. {
  4015. __be32 *p;
  4016. *res = 0;
  4017. if (likely(bitmap[0] & hint_bit)) {
  4018. p = xdr_inline_decode(xdr, 8);
  4019. if (unlikely(!p))
  4020. goto out_overflow;
  4021. xdr_decode_hyper(p, res);
  4022. }
  4023. return 0;
  4024. out_overflow:
  4025. print_overflow_msg(__func__, xdr);
  4026. return -EIO;
  4027. }
  4028. static int decode_first_threshold_item4(struct xdr_stream *xdr,
  4029. struct nfs4_threshold *res)
  4030. {
  4031. __be32 *p;
  4032. unsigned int savep;
  4033. uint32_t bitmap[3] = {0,}, attrlen;
  4034. int status;
  4035. /* layout type */
  4036. p = xdr_inline_decode(xdr, 4);
  4037. if (unlikely(!p)) {
  4038. print_overflow_msg(__func__, xdr);
  4039. return -EIO;
  4040. }
  4041. res->l_type = be32_to_cpup(p);
  4042. /* thi_hintset bitmap */
  4043. status = decode_attr_bitmap(xdr, bitmap);
  4044. if (status < 0)
  4045. goto xdr_error;
  4046. /* thi_hintlist length */
  4047. status = decode_attr_length(xdr, &attrlen, &savep);
  4048. if (status < 0)
  4049. goto xdr_error;
  4050. /* thi_hintlist */
  4051. status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
  4052. if (status < 0)
  4053. goto xdr_error;
  4054. status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
  4055. if (status < 0)
  4056. goto xdr_error;
  4057. status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
  4058. THRESHOLD_RD_IO);
  4059. if (status < 0)
  4060. goto xdr_error;
  4061. status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
  4062. THRESHOLD_WR_IO);
  4063. if (status < 0)
  4064. goto xdr_error;
  4065. status = verify_attr_len(xdr, savep, attrlen);
  4066. res->bm = bitmap[0];
  4067. dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
  4068. __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
  4069. res->wr_io_sz);
  4070. xdr_error:
  4071. dprintk("%s ret=%d!\n", __func__, status);
  4072. return status;
  4073. }
  4074. /*
  4075. * Thresholds on pNFS direct I/O vrs MDS I/O
  4076. */
  4077. static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
  4078. uint32_t *bitmap,
  4079. struct nfs4_threshold *res)
  4080. {
  4081. __be32 *p;
  4082. int status = 0;
  4083. uint32_t num;
  4084. if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
  4085. return -EIO;
  4086. if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
  4087. /* Did the server return an unrequested attribute? */
  4088. if (unlikely(res == NULL))
  4089. return -EREMOTEIO;
  4090. p = xdr_inline_decode(xdr, 4);
  4091. if (unlikely(!p))
  4092. goto out_overflow;
  4093. num = be32_to_cpup(p);
  4094. if (num == 0)
  4095. return 0;
  4096. if (num > 1)
  4097. printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
  4098. "drivers per filesystem not supported\n",
  4099. __func__);
  4100. status = decode_first_threshold_item4(xdr, res);
  4101. bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
  4102. }
  4103. return status;
  4104. out_overflow:
  4105. print_overflow_msg(__func__, xdr);
  4106. return -EIO;
  4107. }
  4108. static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
  4109. struct nfs_fattr *fattr, struct nfs_fh *fh,
  4110. struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
  4111. const struct nfs_server *server)
  4112. {
  4113. int status;
  4114. umode_t fmode = 0;
  4115. uint32_t type;
  4116. int32_t err;
  4117. status = decode_attr_type(xdr, bitmap, &type);
  4118. if (status < 0)
  4119. goto xdr_error;
  4120. fattr->mode = 0;
  4121. if (status != 0) {
  4122. fattr->mode |= nfs_type2fmt[type];
  4123. fattr->valid |= status;
  4124. }
  4125. status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
  4126. if (status < 0)
  4127. goto xdr_error;
  4128. fattr->valid |= status;
  4129. status = decode_attr_size(xdr, bitmap, &fattr->size);
  4130. if (status < 0)
  4131. goto xdr_error;
  4132. fattr->valid |= status;
  4133. status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
  4134. if (status < 0)
  4135. goto xdr_error;
  4136. fattr->valid |= status;
  4137. err = 0;
  4138. status = decode_attr_error(xdr, bitmap, &err);
  4139. if (status < 0)
  4140. goto xdr_error;
  4141. status = decode_attr_filehandle(xdr, bitmap, fh);
  4142. if (status < 0)
  4143. goto xdr_error;
  4144. status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
  4145. if (status < 0)
  4146. goto xdr_error;
  4147. fattr->valid |= status;
  4148. status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
  4149. if (status < 0)
  4150. goto xdr_error;
  4151. fattr->valid |= status;
  4152. status = -EIO;
  4153. if (unlikely(bitmap[0]))
  4154. goto xdr_error;
  4155. status = decode_attr_mode(xdr, bitmap, &fmode);
  4156. if (status < 0)
  4157. goto xdr_error;
  4158. if (status != 0) {
  4159. fattr->mode |= fmode;
  4160. fattr->valid |= status;
  4161. }
  4162. status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
  4163. if (status < 0)
  4164. goto xdr_error;
  4165. fattr->valid |= status;
  4166. status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
  4167. if (status < 0)
  4168. goto xdr_error;
  4169. fattr->valid |= status;
  4170. status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
  4171. if (status < 0)
  4172. goto xdr_error;
  4173. fattr->valid |= status;
  4174. status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
  4175. if (status < 0)
  4176. goto xdr_error;
  4177. fattr->valid |= status;
  4178. status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
  4179. if (status < 0)
  4180. goto xdr_error;
  4181. fattr->valid |= status;
  4182. status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
  4183. if (status < 0)
  4184. goto xdr_error;
  4185. fattr->valid |= status;
  4186. status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
  4187. if (status < 0)
  4188. goto xdr_error;
  4189. fattr->valid |= status;
  4190. status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
  4191. if (status < 0)
  4192. goto xdr_error;
  4193. fattr->valid |= status;
  4194. status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
  4195. if (status < 0)
  4196. goto xdr_error;
  4197. fattr->valid |= status;
  4198. status = -EIO;
  4199. if (unlikely(bitmap[1]))
  4200. goto xdr_error;
  4201. status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
  4202. if (status < 0)
  4203. goto xdr_error;
  4204. if (label) {
  4205. status = decode_attr_security_label(xdr, bitmap, label);
  4206. if (status < 0)
  4207. goto xdr_error;
  4208. fattr->valid |= status;
  4209. }
  4210. xdr_error:
  4211. dprintk("%s: xdr returned %d\n", __func__, -status);
  4212. return status;
  4213. }
  4214. static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
  4215. struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
  4216. struct nfs4_label *label, const struct nfs_server *server)
  4217. {
  4218. unsigned int savep;
  4219. uint32_t attrlen,
  4220. bitmap[3] = {0};
  4221. int status;
  4222. status = decode_op_hdr(xdr, OP_GETATTR);
  4223. if (status < 0)
  4224. goto xdr_error;
  4225. status = decode_attr_bitmap(xdr, bitmap);
  4226. if (status < 0)
  4227. goto xdr_error;
  4228. status = decode_attr_length(xdr, &attrlen, &savep);
  4229. if (status < 0)
  4230. goto xdr_error;
  4231. status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
  4232. label, server);
  4233. if (status < 0)
  4234. goto xdr_error;
  4235. status = verify_attr_len(xdr, savep, attrlen);
  4236. xdr_error:
  4237. dprintk("%s: xdr returned %d\n", __func__, -status);
  4238. return status;
  4239. }
  4240. static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
  4241. struct nfs4_label *label, const struct nfs_server *server)
  4242. {
  4243. return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
  4244. }
  4245. static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
  4246. const struct nfs_server *server)
  4247. {
  4248. return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
  4249. }
  4250. /*
  4251. * Decode potentially multiple layout types. Currently we only support
  4252. * one layout driver per file system.
  4253. */
  4254. static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
  4255. uint32_t *layouttype)
  4256. {
  4257. __be32 *p;
  4258. int num;
  4259. p = xdr_inline_decode(xdr, 4);
  4260. if (unlikely(!p))
  4261. goto out_overflow;
  4262. num = be32_to_cpup(p);
  4263. /* pNFS is not supported by the underlying file system */
  4264. if (num == 0) {
  4265. *layouttype = 0;
  4266. return 0;
  4267. }
  4268. if (num > 1)
  4269. printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
  4270. "drivers per filesystem not supported\n", __func__);
  4271. /* Decode and set first layout type, move xdr->p past unused types */
  4272. p = xdr_inline_decode(xdr, num * 4);
  4273. if (unlikely(!p))
  4274. goto out_overflow;
  4275. *layouttype = be32_to_cpup(p);
  4276. return 0;
  4277. out_overflow:
  4278. print_overflow_msg(__func__, xdr);
  4279. return -EIO;
  4280. }
  4281. /*
  4282. * The type of file system exported.
  4283. * Note we must ensure that layouttype is set in any non-error case.
  4284. */
  4285. static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
  4286. uint32_t *layouttype)
  4287. {
  4288. int status = 0;
  4289. dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
  4290. if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
  4291. return -EIO;
  4292. if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
  4293. status = decode_first_pnfs_layout_type(xdr, layouttype);
  4294. bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
  4295. } else
  4296. *layouttype = 0;
  4297. return status;
  4298. }
  4299. /*
  4300. * The prefered block size for layout directed io
  4301. */
  4302. static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
  4303. uint32_t *res)
  4304. {
  4305. __be32 *p;
  4306. dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
  4307. *res = 0;
  4308. if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
  4309. p = xdr_inline_decode(xdr, 4);
  4310. if (unlikely(!p)) {
  4311. print_overflow_msg(__func__, xdr);
  4312. return -EIO;
  4313. }
  4314. *res = be32_to_cpup(p);
  4315. bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
  4316. }
  4317. return 0;
  4318. }
  4319. /*
  4320. * The granularity of a CLONE operation.
  4321. */
  4322. static int decode_attr_clone_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_CLONE_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_CLONE_BLKSIZE;
  4336. }
  4337. return 0;
  4338. }
  4339. static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
  4340. {
  4341. unsigned int savep;
  4342. uint32_t attrlen, bitmap[3];
  4343. int status;
  4344. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  4345. goto xdr_error;
  4346. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  4347. goto xdr_error;
  4348. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  4349. goto xdr_error;
  4350. fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
  4351. if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
  4352. goto xdr_error;
  4353. if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
  4354. goto xdr_error;
  4355. if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
  4356. goto xdr_error;
  4357. fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
  4358. if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
  4359. goto xdr_error;
  4360. fsinfo->wtpref = fsinfo->wtmax;
  4361. status = -EIO;
  4362. if (unlikely(bitmap[0]))
  4363. goto xdr_error;
  4364. status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
  4365. if (status != 0)
  4366. goto xdr_error;
  4367. status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
  4368. if (status != 0)
  4369. goto xdr_error;
  4370. status = -EIO;
  4371. if (unlikely(bitmap[1]))
  4372. goto xdr_error;
  4373. status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
  4374. if (status)
  4375. goto xdr_error;
  4376. status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
  4377. if (status)
  4378. goto xdr_error;
  4379. status = verify_attr_len(xdr, savep, attrlen);
  4380. xdr_error:
  4381. dprintk("%s: xdr returned %d!\n", __func__, -status);
  4382. return status;
  4383. }
  4384. static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
  4385. {
  4386. __be32 *p;
  4387. uint32_t len;
  4388. int status;
  4389. /* Zero handle first to allow comparisons */
  4390. memset(fh, 0, sizeof(*fh));
  4391. status = decode_op_hdr(xdr, OP_GETFH);
  4392. if (status)
  4393. return status;
  4394. p = xdr_inline_decode(xdr, 4);
  4395. if (unlikely(!p))
  4396. goto out_overflow;
  4397. len = be32_to_cpup(p);
  4398. if (len > NFS4_FHSIZE)
  4399. return -EIO;
  4400. fh->size = len;
  4401. p = xdr_inline_decode(xdr, len);
  4402. if (unlikely(!p))
  4403. goto out_overflow;
  4404. memcpy(fh->data, p, len);
  4405. return 0;
  4406. out_overflow:
  4407. print_overflow_msg(__func__, xdr);
  4408. return -EIO;
  4409. }
  4410. static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  4411. {
  4412. int status;
  4413. status = decode_op_hdr(xdr, OP_LINK);
  4414. if (status)
  4415. return status;
  4416. return decode_change_info(xdr, cinfo);
  4417. }
  4418. /*
  4419. * We create the owner, so we know a proper owner.id length is 4.
  4420. */
  4421. static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
  4422. {
  4423. uint64_t offset, length, clientid;
  4424. __be32 *p;
  4425. uint32_t namelen, type;
  4426. p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
  4427. if (unlikely(!p))
  4428. goto out_overflow;
  4429. p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
  4430. p = xdr_decode_hyper(p, &length);
  4431. type = be32_to_cpup(p++); /* 4 byte read */
  4432. if (fl != NULL) { /* manipulate file lock */
  4433. fl->fl_start = (loff_t)offset;
  4434. fl->fl_end = fl->fl_start + (loff_t)length - 1;
  4435. if (length == ~(uint64_t)0)
  4436. fl->fl_end = OFFSET_MAX;
  4437. fl->fl_type = F_WRLCK;
  4438. if (type & 1)
  4439. fl->fl_type = F_RDLCK;
  4440. fl->fl_pid = 0;
  4441. }
  4442. p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
  4443. namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
  4444. p = xdr_inline_decode(xdr, namelen); /* variable size field */
  4445. if (likely(p))
  4446. return -NFS4ERR_DENIED;
  4447. out_overflow:
  4448. print_overflow_msg(__func__, xdr);
  4449. return -EIO;
  4450. }
  4451. static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
  4452. {
  4453. int status;
  4454. status = decode_op_hdr(xdr, OP_LOCK);
  4455. if (status == -EIO)
  4456. goto out;
  4457. if (status == 0) {
  4458. status = decode_stateid(xdr, &res->stateid);
  4459. if (unlikely(status))
  4460. goto out;
  4461. } else if (status == -NFS4ERR_DENIED)
  4462. status = decode_lock_denied(xdr, NULL);
  4463. if (res->open_seqid != NULL)
  4464. nfs_increment_open_seqid(status, res->open_seqid);
  4465. nfs_increment_lock_seqid(status, res->lock_seqid);
  4466. out:
  4467. return status;
  4468. }
  4469. static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
  4470. {
  4471. int status;
  4472. status = decode_op_hdr(xdr, OP_LOCKT);
  4473. if (status == -NFS4ERR_DENIED)
  4474. return decode_lock_denied(xdr, res->denied);
  4475. return status;
  4476. }
  4477. static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
  4478. {
  4479. int status;
  4480. status = decode_op_hdr(xdr, OP_LOCKU);
  4481. if (status != -EIO)
  4482. nfs_increment_lock_seqid(status, res->seqid);
  4483. if (status == 0)
  4484. status = decode_stateid(xdr, &res->stateid);
  4485. return status;
  4486. }
  4487. static int decode_release_lockowner(struct xdr_stream *xdr)
  4488. {
  4489. return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
  4490. }
  4491. static int decode_lookup(struct xdr_stream *xdr)
  4492. {
  4493. return decode_op_hdr(xdr, OP_LOOKUP);
  4494. }
  4495. /* This is too sick! */
  4496. static int decode_space_limit(struct xdr_stream *xdr,
  4497. unsigned long *pagemod_limit)
  4498. {
  4499. __be32 *p;
  4500. uint32_t limit_type, nblocks, blocksize;
  4501. u64 maxsize = 0;
  4502. p = xdr_inline_decode(xdr, 12);
  4503. if (unlikely(!p))
  4504. goto out_overflow;
  4505. limit_type = be32_to_cpup(p++);
  4506. switch (limit_type) {
  4507. case NFS4_LIMIT_SIZE:
  4508. xdr_decode_hyper(p, &maxsize);
  4509. break;
  4510. case NFS4_LIMIT_BLOCKS:
  4511. nblocks = be32_to_cpup(p++);
  4512. blocksize = be32_to_cpup(p);
  4513. maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
  4514. }
  4515. maxsize >>= PAGE_CACHE_SHIFT;
  4516. *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
  4517. return 0;
  4518. out_overflow:
  4519. print_overflow_msg(__func__, xdr);
  4520. return -EIO;
  4521. }
  4522. static int decode_rw_delegation(struct xdr_stream *xdr,
  4523. uint32_t delegation_type,
  4524. struct nfs_openres *res)
  4525. {
  4526. __be32 *p;
  4527. int status;
  4528. status = decode_stateid(xdr, &res->delegation);
  4529. if (unlikely(status))
  4530. return status;
  4531. p = xdr_inline_decode(xdr, 4);
  4532. if (unlikely(!p))
  4533. goto out_overflow;
  4534. res->do_recall = be32_to_cpup(p);
  4535. switch (delegation_type) {
  4536. case NFS4_OPEN_DELEGATE_READ:
  4537. res->delegation_type = FMODE_READ;
  4538. break;
  4539. case NFS4_OPEN_DELEGATE_WRITE:
  4540. res->delegation_type = FMODE_WRITE|FMODE_READ;
  4541. if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
  4542. return -EIO;
  4543. }
  4544. return decode_ace(xdr, NULL, res->server->nfs_client);
  4545. out_overflow:
  4546. print_overflow_msg(__func__, xdr);
  4547. return -EIO;
  4548. }
  4549. static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
  4550. {
  4551. __be32 *p;
  4552. uint32_t why_no_delegation;
  4553. p = xdr_inline_decode(xdr, 4);
  4554. if (unlikely(!p))
  4555. goto out_overflow;
  4556. why_no_delegation = be32_to_cpup(p);
  4557. switch (why_no_delegation) {
  4558. case WND4_CONTENTION:
  4559. case WND4_RESOURCE:
  4560. xdr_inline_decode(xdr, 4);
  4561. /* Ignore for now */
  4562. }
  4563. return 0;
  4564. out_overflow:
  4565. print_overflow_msg(__func__, xdr);
  4566. return -EIO;
  4567. }
  4568. static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
  4569. {
  4570. __be32 *p;
  4571. uint32_t delegation_type;
  4572. p = xdr_inline_decode(xdr, 4);
  4573. if (unlikely(!p))
  4574. goto out_overflow;
  4575. delegation_type = be32_to_cpup(p);
  4576. res->delegation_type = 0;
  4577. switch (delegation_type) {
  4578. case NFS4_OPEN_DELEGATE_NONE:
  4579. return 0;
  4580. case NFS4_OPEN_DELEGATE_READ:
  4581. case NFS4_OPEN_DELEGATE_WRITE:
  4582. return decode_rw_delegation(xdr, delegation_type, res);
  4583. case NFS4_OPEN_DELEGATE_NONE_EXT:
  4584. return decode_no_delegation(xdr, res);
  4585. }
  4586. return -EIO;
  4587. out_overflow:
  4588. print_overflow_msg(__func__, xdr);
  4589. return -EIO;
  4590. }
  4591. static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
  4592. {
  4593. __be32 *p;
  4594. uint32_t savewords, bmlen, i;
  4595. int status;
  4596. if (!__decode_op_hdr(xdr, OP_OPEN, &status))
  4597. return status;
  4598. nfs_increment_open_seqid(status, res->seqid);
  4599. if (status)
  4600. return status;
  4601. status = decode_stateid(xdr, &res->stateid);
  4602. if (unlikely(status))
  4603. return status;
  4604. decode_change_info(xdr, &res->cinfo);
  4605. p = xdr_inline_decode(xdr, 8);
  4606. if (unlikely(!p))
  4607. goto out_overflow;
  4608. res->rflags = be32_to_cpup(p++);
  4609. bmlen = be32_to_cpup(p);
  4610. if (bmlen > 10)
  4611. goto xdr_error;
  4612. p = xdr_inline_decode(xdr, bmlen << 2);
  4613. if (unlikely(!p))
  4614. goto out_overflow;
  4615. savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
  4616. for (i = 0; i < savewords; ++i)
  4617. res->attrset[i] = be32_to_cpup(p++);
  4618. for (; i < NFS4_BITMAP_SIZE; i++)
  4619. res->attrset[i] = 0;
  4620. return decode_delegation(xdr, res);
  4621. xdr_error:
  4622. dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
  4623. return -EIO;
  4624. out_overflow:
  4625. print_overflow_msg(__func__, xdr);
  4626. return -EIO;
  4627. }
  4628. static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
  4629. {
  4630. int status;
  4631. status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
  4632. if (status != -EIO)
  4633. nfs_increment_open_seqid(status, res->seqid);
  4634. if (!status)
  4635. status = decode_stateid(xdr, &res->stateid);
  4636. return status;
  4637. }
  4638. static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
  4639. {
  4640. int status;
  4641. status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
  4642. if (status != -EIO)
  4643. nfs_increment_open_seqid(status, res->seqid);
  4644. if (!status)
  4645. status = decode_stateid(xdr, &res->stateid);
  4646. return status;
  4647. }
  4648. static int decode_putfh(struct xdr_stream *xdr)
  4649. {
  4650. return decode_op_hdr(xdr, OP_PUTFH);
  4651. }
  4652. static int decode_putrootfh(struct xdr_stream *xdr)
  4653. {
  4654. return decode_op_hdr(xdr, OP_PUTROOTFH);
  4655. }
  4656. static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
  4657. struct nfs_pgio_res *res)
  4658. {
  4659. __be32 *p;
  4660. uint32_t count, eof, recvd;
  4661. int status;
  4662. status = decode_op_hdr(xdr, OP_READ);
  4663. if (status)
  4664. return status;
  4665. p = xdr_inline_decode(xdr, 8);
  4666. if (unlikely(!p))
  4667. goto out_overflow;
  4668. eof = be32_to_cpup(p++);
  4669. count = be32_to_cpup(p);
  4670. recvd = xdr_read_pages(xdr, count);
  4671. if (count > recvd) {
  4672. dprintk("NFS: server cheating in read reply: "
  4673. "count %u > recvd %u\n", count, recvd);
  4674. count = recvd;
  4675. eof = 0;
  4676. }
  4677. res->eof = eof;
  4678. res->count = count;
  4679. return 0;
  4680. out_overflow:
  4681. print_overflow_msg(__func__, xdr);
  4682. return -EIO;
  4683. }
  4684. static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
  4685. {
  4686. int status;
  4687. __be32 verf[2];
  4688. status = decode_op_hdr(xdr, OP_READDIR);
  4689. if (!status)
  4690. status = decode_verifier(xdr, readdir->verifier.data);
  4691. if (unlikely(status))
  4692. return status;
  4693. memcpy(verf, readdir->verifier.data, sizeof(verf));
  4694. dprintk("%s: verifier = %08x:%08x\n",
  4695. __func__, verf[0], verf[1]);
  4696. return xdr_read_pages(xdr, xdr->buf->page_len);
  4697. }
  4698. static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
  4699. {
  4700. struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
  4701. u32 len, recvd;
  4702. __be32 *p;
  4703. int status;
  4704. status = decode_op_hdr(xdr, OP_READLINK);
  4705. if (status)
  4706. return status;
  4707. /* Convert length of symlink */
  4708. p = xdr_inline_decode(xdr, 4);
  4709. if (unlikely(!p))
  4710. goto out_overflow;
  4711. len = be32_to_cpup(p);
  4712. if (len >= rcvbuf->page_len || len <= 0) {
  4713. dprintk("nfs: server returned giant symlink!\n");
  4714. return -ENAMETOOLONG;
  4715. }
  4716. recvd = xdr_read_pages(xdr, len);
  4717. if (recvd < len) {
  4718. dprintk("NFS: server cheating in readlink reply: "
  4719. "count %u > recvd %u\n", len, recvd);
  4720. return -EIO;
  4721. }
  4722. /*
  4723. * The XDR encode routine has set things up so that
  4724. * the link text will be copied directly into the
  4725. * buffer. We just have to do overflow-checking,
  4726. * and and null-terminate the text (the VFS expects
  4727. * null-termination).
  4728. */
  4729. xdr_terminate_string(rcvbuf, len);
  4730. return 0;
  4731. out_overflow:
  4732. print_overflow_msg(__func__, xdr);
  4733. return -EIO;
  4734. }
  4735. static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  4736. {
  4737. int status;
  4738. status = decode_op_hdr(xdr, OP_REMOVE);
  4739. if (status)
  4740. goto out;
  4741. status = decode_change_info(xdr, cinfo);
  4742. out:
  4743. return status;
  4744. }
  4745. static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
  4746. struct nfs4_change_info *new_cinfo)
  4747. {
  4748. int status;
  4749. status = decode_op_hdr(xdr, OP_RENAME);
  4750. if (status)
  4751. goto out;
  4752. if ((status = decode_change_info(xdr, old_cinfo)))
  4753. goto out;
  4754. status = decode_change_info(xdr, new_cinfo);
  4755. out:
  4756. return status;
  4757. }
  4758. static int decode_renew(struct xdr_stream *xdr)
  4759. {
  4760. return decode_op_hdr(xdr, OP_RENEW);
  4761. }
  4762. static int
  4763. decode_restorefh(struct xdr_stream *xdr)
  4764. {
  4765. return decode_op_hdr(xdr, OP_RESTOREFH);
  4766. }
  4767. static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
  4768. struct nfs_getaclres *res)
  4769. {
  4770. unsigned int savep;
  4771. uint32_t attrlen,
  4772. bitmap[3] = {0};
  4773. int status;
  4774. unsigned int pg_offset;
  4775. res->acl_len = 0;
  4776. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  4777. goto out;
  4778. xdr_enter_page(xdr, xdr->buf->page_len);
  4779. /* Calculate the offset of the page data */
  4780. pg_offset = xdr->buf->head[0].iov_len;
  4781. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  4782. goto out;
  4783. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  4784. goto out;
  4785. if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
  4786. return -EIO;
  4787. if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
  4788. /* The bitmap (xdr len + bitmaps) and the attr xdr len words
  4789. * are stored with the acl data to handle the problem of
  4790. * variable length bitmaps.*/
  4791. res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
  4792. res->acl_len = attrlen;
  4793. /* Check for receive buffer overflow */
  4794. if (res->acl_len > (xdr->nwords << 2) ||
  4795. res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
  4796. res->acl_flags |= NFS4_ACL_TRUNC;
  4797. dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
  4798. attrlen, xdr->nwords << 2);
  4799. }
  4800. } else
  4801. status = -EOPNOTSUPP;
  4802. out:
  4803. return status;
  4804. }
  4805. static int
  4806. decode_savefh(struct xdr_stream *xdr)
  4807. {
  4808. return decode_op_hdr(xdr, OP_SAVEFH);
  4809. }
  4810. static int decode_setattr(struct xdr_stream *xdr)
  4811. {
  4812. __be32 *p;
  4813. uint32_t bmlen;
  4814. int status;
  4815. status = decode_op_hdr(xdr, OP_SETATTR);
  4816. if (status)
  4817. return status;
  4818. p = xdr_inline_decode(xdr, 4);
  4819. if (unlikely(!p))
  4820. goto out_overflow;
  4821. bmlen = be32_to_cpup(p);
  4822. p = xdr_inline_decode(xdr, bmlen << 2);
  4823. if (likely(p))
  4824. return 0;
  4825. out_overflow:
  4826. print_overflow_msg(__func__, xdr);
  4827. return -EIO;
  4828. }
  4829. static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
  4830. {
  4831. __be32 *p;
  4832. uint32_t opnum;
  4833. int32_t nfserr;
  4834. p = xdr_inline_decode(xdr, 8);
  4835. if (unlikely(!p))
  4836. goto out_overflow;
  4837. opnum = be32_to_cpup(p++);
  4838. if (opnum != OP_SETCLIENTID) {
  4839. dprintk("nfs: decode_setclientid: Server returned operation"
  4840. " %d\n", opnum);
  4841. return -EIO;
  4842. }
  4843. nfserr = be32_to_cpup(p);
  4844. if (nfserr == NFS_OK) {
  4845. p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
  4846. if (unlikely(!p))
  4847. goto out_overflow;
  4848. p = xdr_decode_hyper(p, &res->clientid);
  4849. memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
  4850. } else if (nfserr == NFSERR_CLID_INUSE) {
  4851. uint32_t len;
  4852. /* skip netid string */
  4853. p = xdr_inline_decode(xdr, 4);
  4854. if (unlikely(!p))
  4855. goto out_overflow;
  4856. len = be32_to_cpup(p);
  4857. p = xdr_inline_decode(xdr, len);
  4858. if (unlikely(!p))
  4859. goto out_overflow;
  4860. /* skip uaddr string */
  4861. p = xdr_inline_decode(xdr, 4);
  4862. if (unlikely(!p))
  4863. goto out_overflow;
  4864. len = be32_to_cpup(p);
  4865. p = xdr_inline_decode(xdr, len);
  4866. if (unlikely(!p))
  4867. goto out_overflow;
  4868. return -NFSERR_CLID_INUSE;
  4869. } else
  4870. return nfs4_stat_to_errno(nfserr);
  4871. return 0;
  4872. out_overflow:
  4873. print_overflow_msg(__func__, xdr);
  4874. return -EIO;
  4875. }
  4876. static int decode_setclientid_confirm(struct xdr_stream *xdr)
  4877. {
  4878. return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
  4879. }
  4880. static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
  4881. {
  4882. __be32 *p;
  4883. int status;
  4884. status = decode_op_hdr(xdr, OP_WRITE);
  4885. if (status)
  4886. return status;
  4887. p = xdr_inline_decode(xdr, 8);
  4888. if (unlikely(!p))
  4889. goto out_overflow;
  4890. res->count = be32_to_cpup(p++);
  4891. res->verf->committed = be32_to_cpup(p++);
  4892. return decode_write_verifier(xdr, &res->verf->verifier);
  4893. out_overflow:
  4894. print_overflow_msg(__func__, xdr);
  4895. return -EIO;
  4896. }
  4897. static int decode_delegreturn(struct xdr_stream *xdr)
  4898. {
  4899. return decode_op_hdr(xdr, OP_DELEGRETURN);
  4900. }
  4901. static int decode_secinfo_gss(struct xdr_stream *xdr,
  4902. struct nfs4_secinfo4 *flavor)
  4903. {
  4904. u32 oid_len;
  4905. __be32 *p;
  4906. p = xdr_inline_decode(xdr, 4);
  4907. if (unlikely(!p))
  4908. goto out_overflow;
  4909. oid_len = be32_to_cpup(p);
  4910. if (oid_len > GSS_OID_MAX_LEN)
  4911. goto out_err;
  4912. p = xdr_inline_decode(xdr, oid_len);
  4913. if (unlikely(!p))
  4914. goto out_overflow;
  4915. memcpy(flavor->flavor_info.oid.data, p, oid_len);
  4916. flavor->flavor_info.oid.len = oid_len;
  4917. p = xdr_inline_decode(xdr, 8);
  4918. if (unlikely(!p))
  4919. goto out_overflow;
  4920. flavor->flavor_info.qop = be32_to_cpup(p++);
  4921. flavor->flavor_info.service = be32_to_cpup(p);
  4922. return 0;
  4923. out_overflow:
  4924. print_overflow_msg(__func__, xdr);
  4925. return -EIO;
  4926. out_err:
  4927. return -EINVAL;
  4928. }
  4929. static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
  4930. {
  4931. struct nfs4_secinfo4 *sec_flavor;
  4932. unsigned int i, num_flavors;
  4933. int status;
  4934. __be32 *p;
  4935. p = xdr_inline_decode(xdr, 4);
  4936. if (unlikely(!p))
  4937. goto out_overflow;
  4938. res->flavors->num_flavors = 0;
  4939. num_flavors = be32_to_cpup(p);
  4940. for (i = 0; i < num_flavors; i++) {
  4941. sec_flavor = &res->flavors->flavors[i];
  4942. if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
  4943. break;
  4944. p = xdr_inline_decode(xdr, 4);
  4945. if (unlikely(!p))
  4946. goto out_overflow;
  4947. sec_flavor->flavor = be32_to_cpup(p);
  4948. if (sec_flavor->flavor == RPC_AUTH_GSS) {
  4949. status = decode_secinfo_gss(xdr, sec_flavor);
  4950. if (status)
  4951. goto out;
  4952. }
  4953. res->flavors->num_flavors++;
  4954. }
  4955. status = 0;
  4956. out:
  4957. return status;
  4958. out_overflow:
  4959. print_overflow_msg(__func__, xdr);
  4960. return -EIO;
  4961. }
  4962. static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
  4963. {
  4964. int status = decode_op_hdr(xdr, OP_SECINFO);
  4965. if (status)
  4966. return status;
  4967. return decode_secinfo_common(xdr, res);
  4968. }
  4969. #if defined(CONFIG_NFS_V4_1)
  4970. static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
  4971. {
  4972. int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
  4973. if (status)
  4974. return status;
  4975. return decode_secinfo_common(xdr, res);
  4976. }
  4977. static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
  4978. {
  4979. __be32 *p;
  4980. uint32_t bitmap_words;
  4981. unsigned int i;
  4982. p = xdr_inline_decode(xdr, 4);
  4983. bitmap_words = be32_to_cpup(p++);
  4984. if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
  4985. return -EIO;
  4986. p = xdr_inline_decode(xdr, 4 * bitmap_words);
  4987. for (i = 0; i < bitmap_words; i++)
  4988. op_map->u.words[i] = be32_to_cpup(p++);
  4989. return 0;
  4990. }
  4991. static int decode_exchange_id(struct xdr_stream *xdr,
  4992. struct nfs41_exchange_id_res *res)
  4993. {
  4994. __be32 *p;
  4995. uint32_t dummy;
  4996. char *dummy_str;
  4997. int status;
  4998. uint32_t impl_id_count;
  4999. status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
  5000. if (status)
  5001. return status;
  5002. p = xdr_inline_decode(xdr, 8);
  5003. if (unlikely(!p))
  5004. goto out_overflow;
  5005. xdr_decode_hyper(p, &res->clientid);
  5006. p = xdr_inline_decode(xdr, 12);
  5007. if (unlikely(!p))
  5008. goto out_overflow;
  5009. res->seqid = be32_to_cpup(p++);
  5010. res->flags = be32_to_cpup(p++);
  5011. res->state_protect.how = be32_to_cpup(p);
  5012. switch (res->state_protect.how) {
  5013. case SP4_NONE:
  5014. break;
  5015. case SP4_MACH_CRED:
  5016. status = decode_op_map(xdr, &res->state_protect.enforce);
  5017. if (status)
  5018. return status;
  5019. status = decode_op_map(xdr, &res->state_protect.allow);
  5020. if (status)
  5021. return status;
  5022. break;
  5023. default:
  5024. WARN_ON_ONCE(1);
  5025. return -EIO;
  5026. }
  5027. /* server_owner4.so_minor_id */
  5028. p = xdr_inline_decode(xdr, 8);
  5029. if (unlikely(!p))
  5030. goto out_overflow;
  5031. p = xdr_decode_hyper(p, &res->server_owner->minor_id);
  5032. /* server_owner4.so_major_id */
  5033. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  5034. if (unlikely(status))
  5035. return status;
  5036. if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
  5037. return -EIO;
  5038. memcpy(res->server_owner->major_id, dummy_str, dummy);
  5039. res->server_owner->major_id_sz = dummy;
  5040. /* server_scope4 */
  5041. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  5042. if (unlikely(status))
  5043. return status;
  5044. if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
  5045. return -EIO;
  5046. memcpy(res->server_scope->server_scope, dummy_str, dummy);
  5047. res->server_scope->server_scope_sz = dummy;
  5048. /* Implementation Id */
  5049. p = xdr_inline_decode(xdr, 4);
  5050. if (unlikely(!p))
  5051. goto out_overflow;
  5052. impl_id_count = be32_to_cpup(p++);
  5053. if (impl_id_count) {
  5054. /* nii_domain */
  5055. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  5056. if (unlikely(status))
  5057. return status;
  5058. if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
  5059. return -EIO;
  5060. memcpy(res->impl_id->domain, dummy_str, dummy);
  5061. /* nii_name */
  5062. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  5063. if (unlikely(status))
  5064. return status;
  5065. if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
  5066. return -EIO;
  5067. memcpy(res->impl_id->name, dummy_str, dummy);
  5068. /* nii_date */
  5069. p = xdr_inline_decode(xdr, 12);
  5070. if (unlikely(!p))
  5071. goto out_overflow;
  5072. p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
  5073. res->impl_id->date.nseconds = be32_to_cpup(p);
  5074. /* if there's more than one entry, ignore the rest */
  5075. }
  5076. return 0;
  5077. out_overflow:
  5078. print_overflow_msg(__func__, xdr);
  5079. return -EIO;
  5080. }
  5081. static int decode_chan_attrs(struct xdr_stream *xdr,
  5082. struct nfs4_channel_attrs *attrs)
  5083. {
  5084. __be32 *p;
  5085. u32 nr_attrs, val;
  5086. p = xdr_inline_decode(xdr, 28);
  5087. if (unlikely(!p))
  5088. goto out_overflow;
  5089. val = be32_to_cpup(p++); /* headerpadsz */
  5090. if (val)
  5091. return -EINVAL; /* no support for header padding yet */
  5092. attrs->max_rqst_sz = be32_to_cpup(p++);
  5093. attrs->max_resp_sz = be32_to_cpup(p++);
  5094. attrs->max_resp_sz_cached = be32_to_cpup(p++);
  5095. attrs->max_ops = be32_to_cpup(p++);
  5096. attrs->max_reqs = be32_to_cpup(p++);
  5097. nr_attrs = be32_to_cpup(p);
  5098. if (unlikely(nr_attrs > 1)) {
  5099. printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
  5100. "count %u\n", __func__, nr_attrs);
  5101. return -EINVAL;
  5102. }
  5103. if (nr_attrs == 1) {
  5104. p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
  5105. if (unlikely(!p))
  5106. goto out_overflow;
  5107. }
  5108. return 0;
  5109. out_overflow:
  5110. print_overflow_msg(__func__, xdr);
  5111. return -EIO;
  5112. }
  5113. static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
  5114. {
  5115. return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
  5116. }
  5117. static int decode_bind_conn_to_session(struct xdr_stream *xdr,
  5118. struct nfs41_bind_conn_to_session_res *res)
  5119. {
  5120. __be32 *p;
  5121. int status;
  5122. status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
  5123. if (!status)
  5124. status = decode_sessionid(xdr, &res->sessionid);
  5125. if (unlikely(status))
  5126. return status;
  5127. /* dir flags, rdma mode bool */
  5128. p = xdr_inline_decode(xdr, 8);
  5129. if (unlikely(!p))
  5130. goto out_overflow;
  5131. res->dir = be32_to_cpup(p++);
  5132. if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
  5133. return -EIO;
  5134. if (be32_to_cpup(p) == 0)
  5135. res->use_conn_in_rdma_mode = false;
  5136. else
  5137. res->use_conn_in_rdma_mode = true;
  5138. return 0;
  5139. out_overflow:
  5140. print_overflow_msg(__func__, xdr);
  5141. return -EIO;
  5142. }
  5143. static int decode_create_session(struct xdr_stream *xdr,
  5144. struct nfs41_create_session_res *res)
  5145. {
  5146. __be32 *p;
  5147. int status;
  5148. status = decode_op_hdr(xdr, OP_CREATE_SESSION);
  5149. if (!status)
  5150. status = decode_sessionid(xdr, &res->sessionid);
  5151. if (unlikely(status))
  5152. return status;
  5153. /* seqid, flags */
  5154. p = xdr_inline_decode(xdr, 8);
  5155. if (unlikely(!p))
  5156. goto out_overflow;
  5157. res->seqid = be32_to_cpup(p++);
  5158. res->flags = be32_to_cpup(p);
  5159. /* Channel attributes */
  5160. status = decode_chan_attrs(xdr, &res->fc_attrs);
  5161. if (!status)
  5162. status = decode_chan_attrs(xdr, &res->bc_attrs);
  5163. return status;
  5164. out_overflow:
  5165. print_overflow_msg(__func__, xdr);
  5166. return -EIO;
  5167. }
  5168. static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
  5169. {
  5170. return decode_op_hdr(xdr, OP_DESTROY_SESSION);
  5171. }
  5172. static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
  5173. {
  5174. return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
  5175. }
  5176. static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
  5177. {
  5178. return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
  5179. }
  5180. #endif /* CONFIG_NFS_V4_1 */
  5181. static int decode_sequence(struct xdr_stream *xdr,
  5182. struct nfs4_sequence_res *res,
  5183. struct rpc_rqst *rqstp)
  5184. {
  5185. #if defined(CONFIG_NFS_V4_1)
  5186. struct nfs4_session *session;
  5187. struct nfs4_sessionid id;
  5188. u32 dummy;
  5189. int status;
  5190. __be32 *p;
  5191. if (res->sr_slot == NULL)
  5192. return 0;
  5193. if (!res->sr_slot->table->session)
  5194. return 0;
  5195. status = decode_op_hdr(xdr, OP_SEQUENCE);
  5196. if (!status)
  5197. status = decode_sessionid(xdr, &id);
  5198. if (unlikely(status))
  5199. goto out_err;
  5200. /*
  5201. * If the server returns different values for sessionID, slotID or
  5202. * sequence number, the server is looney tunes.
  5203. */
  5204. status = -EREMOTEIO;
  5205. session = res->sr_slot->table->session;
  5206. if (memcmp(id.data, session->sess_id.data,
  5207. NFS4_MAX_SESSIONID_LEN)) {
  5208. dprintk("%s Invalid session id\n", __func__);
  5209. goto out_err;
  5210. }
  5211. p = xdr_inline_decode(xdr, 20);
  5212. if (unlikely(!p))
  5213. goto out_overflow;
  5214. /* seqid */
  5215. dummy = be32_to_cpup(p++);
  5216. if (dummy != res->sr_slot->seq_nr) {
  5217. dprintk("%s Invalid sequence number\n", __func__);
  5218. goto out_err;
  5219. }
  5220. /* slot id */
  5221. dummy = be32_to_cpup(p++);
  5222. if (dummy != res->sr_slot->slot_nr) {
  5223. dprintk("%s Invalid slot id\n", __func__);
  5224. goto out_err;
  5225. }
  5226. /* highest slot id */
  5227. res->sr_highest_slotid = be32_to_cpup(p++);
  5228. /* target highest slot id */
  5229. res->sr_target_highest_slotid = be32_to_cpup(p++);
  5230. /* result flags */
  5231. res->sr_status_flags = be32_to_cpup(p);
  5232. status = 0;
  5233. out_err:
  5234. res->sr_status = status;
  5235. return status;
  5236. out_overflow:
  5237. print_overflow_msg(__func__, xdr);
  5238. status = -EIO;
  5239. goto out_err;
  5240. #else /* CONFIG_NFS_V4_1 */
  5241. return 0;
  5242. #endif /* CONFIG_NFS_V4_1 */
  5243. }
  5244. #if defined(CONFIG_NFS_V4_1)
  5245. static int decode_getdeviceinfo(struct xdr_stream *xdr,
  5246. struct nfs4_getdeviceinfo_res *res)
  5247. {
  5248. struct pnfs_device *pdev = res->pdev;
  5249. __be32 *p;
  5250. uint32_t len, type;
  5251. int status;
  5252. status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
  5253. if (status) {
  5254. if (status == -ETOOSMALL) {
  5255. p = xdr_inline_decode(xdr, 4);
  5256. if (unlikely(!p))
  5257. goto out_overflow;
  5258. pdev->mincount = be32_to_cpup(p);
  5259. dprintk("%s: Min count too small. mincnt = %u\n",
  5260. __func__, pdev->mincount);
  5261. }
  5262. return status;
  5263. }
  5264. p = xdr_inline_decode(xdr, 8);
  5265. if (unlikely(!p))
  5266. goto out_overflow;
  5267. type = be32_to_cpup(p++);
  5268. if (type != pdev->layout_type) {
  5269. dprintk("%s: layout mismatch req: %u pdev: %u\n",
  5270. __func__, pdev->layout_type, type);
  5271. return -EINVAL;
  5272. }
  5273. /*
  5274. * Get the length of the opaque device_addr4. xdr_read_pages places
  5275. * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
  5276. * and places the remaining xdr data in xdr_buf->tail
  5277. */
  5278. pdev->mincount = be32_to_cpup(p);
  5279. if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
  5280. goto out_overflow;
  5281. /* Parse notification bitmap, verifying that it is zero. */
  5282. p = xdr_inline_decode(xdr, 4);
  5283. if (unlikely(!p))
  5284. goto out_overflow;
  5285. len = be32_to_cpup(p);
  5286. if (len) {
  5287. uint32_t i;
  5288. p = xdr_inline_decode(xdr, 4 * len);
  5289. if (unlikely(!p))
  5290. goto out_overflow;
  5291. res->notification = be32_to_cpup(p++);
  5292. for (i = 1; i < len; i++) {
  5293. if (be32_to_cpup(p++)) {
  5294. dprintk("%s: unsupported notification\n",
  5295. __func__);
  5296. return -EIO;
  5297. }
  5298. }
  5299. }
  5300. return 0;
  5301. out_overflow:
  5302. print_overflow_msg(__func__, xdr);
  5303. return -EIO;
  5304. }
  5305. static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
  5306. struct nfs4_layoutget_res *res)
  5307. {
  5308. __be32 *p;
  5309. int status;
  5310. u32 layout_count;
  5311. u32 recvd;
  5312. status = decode_op_hdr(xdr, OP_LAYOUTGET);
  5313. if (status)
  5314. return status;
  5315. p = xdr_inline_decode(xdr, 4);
  5316. if (unlikely(!p))
  5317. goto out_overflow;
  5318. res->return_on_close = be32_to_cpup(p);
  5319. decode_stateid(xdr, &res->stateid);
  5320. p = xdr_inline_decode(xdr, 4);
  5321. if (unlikely(!p))
  5322. goto out_overflow;
  5323. layout_count = be32_to_cpup(p);
  5324. if (!layout_count) {
  5325. dprintk("%s: server responded with empty layout array\n",
  5326. __func__);
  5327. return -EINVAL;
  5328. }
  5329. p = xdr_inline_decode(xdr, 28);
  5330. if (unlikely(!p))
  5331. goto out_overflow;
  5332. p = xdr_decode_hyper(p, &res->range.offset);
  5333. p = xdr_decode_hyper(p, &res->range.length);
  5334. res->range.iomode = be32_to_cpup(p++);
  5335. res->type = be32_to_cpup(p++);
  5336. res->layoutp->len = be32_to_cpup(p);
  5337. dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
  5338. __func__,
  5339. (unsigned long)res->range.offset,
  5340. (unsigned long)res->range.length,
  5341. res->range.iomode,
  5342. res->type,
  5343. res->layoutp->len);
  5344. recvd = xdr_read_pages(xdr, res->layoutp->len);
  5345. if (res->layoutp->len > recvd) {
  5346. dprintk("NFS: server cheating in layoutget reply: "
  5347. "layout len %u > recvd %u\n",
  5348. res->layoutp->len, recvd);
  5349. return -EINVAL;
  5350. }
  5351. if (layout_count > 1) {
  5352. /* We only handle a length one array at the moment. Any
  5353. * further entries are just ignored. Note that this means
  5354. * the client may see a response that is less than the
  5355. * minimum it requested.
  5356. */
  5357. dprintk("%s: server responded with %d layouts, dropping tail\n",
  5358. __func__, layout_count);
  5359. }
  5360. return 0;
  5361. out_overflow:
  5362. print_overflow_msg(__func__, xdr);
  5363. return -EIO;
  5364. }
  5365. static int decode_layoutreturn(struct xdr_stream *xdr,
  5366. struct nfs4_layoutreturn_res *res)
  5367. {
  5368. __be32 *p;
  5369. int status;
  5370. status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
  5371. if (status)
  5372. return status;
  5373. p = xdr_inline_decode(xdr, 4);
  5374. if (unlikely(!p))
  5375. goto out_overflow;
  5376. res->lrs_present = be32_to_cpup(p);
  5377. if (res->lrs_present)
  5378. status = decode_stateid(xdr, &res->stateid);
  5379. return status;
  5380. out_overflow:
  5381. print_overflow_msg(__func__, xdr);
  5382. return -EIO;
  5383. }
  5384. static int decode_layoutcommit(struct xdr_stream *xdr,
  5385. struct rpc_rqst *req,
  5386. struct nfs4_layoutcommit_res *res)
  5387. {
  5388. __be32 *p;
  5389. __u32 sizechanged;
  5390. int status;
  5391. status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
  5392. res->status = status;
  5393. if (status)
  5394. return status;
  5395. p = xdr_inline_decode(xdr, 4);
  5396. if (unlikely(!p))
  5397. goto out_overflow;
  5398. sizechanged = be32_to_cpup(p);
  5399. if (sizechanged) {
  5400. /* throw away new size */
  5401. p = xdr_inline_decode(xdr, 8);
  5402. if (unlikely(!p))
  5403. goto out_overflow;
  5404. }
  5405. return 0;
  5406. out_overflow:
  5407. print_overflow_msg(__func__, xdr);
  5408. return -EIO;
  5409. }
  5410. static int decode_test_stateid(struct xdr_stream *xdr,
  5411. struct nfs41_test_stateid_res *res)
  5412. {
  5413. __be32 *p;
  5414. int status;
  5415. int num_res;
  5416. status = decode_op_hdr(xdr, OP_TEST_STATEID);
  5417. if (status)
  5418. return status;
  5419. p = xdr_inline_decode(xdr, 4);
  5420. if (unlikely(!p))
  5421. goto out_overflow;
  5422. num_res = be32_to_cpup(p++);
  5423. if (num_res != 1)
  5424. goto out;
  5425. p = xdr_inline_decode(xdr, 4);
  5426. if (unlikely(!p))
  5427. goto out_overflow;
  5428. res->status = be32_to_cpup(p++);
  5429. return status;
  5430. out_overflow:
  5431. print_overflow_msg(__func__, xdr);
  5432. out:
  5433. return -EIO;
  5434. }
  5435. static int decode_free_stateid(struct xdr_stream *xdr,
  5436. struct nfs41_free_stateid_res *res)
  5437. {
  5438. res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
  5439. return res->status;
  5440. }
  5441. #endif /* CONFIG_NFS_V4_1 */
  5442. /*
  5443. * END OF "GENERIC" DECODE ROUTINES.
  5444. */
  5445. /*
  5446. * Decode OPEN_DOWNGRADE response
  5447. */
  5448. static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
  5449. struct xdr_stream *xdr,
  5450. struct nfs_closeres *res)
  5451. {
  5452. struct compound_hdr hdr;
  5453. int status;
  5454. status = decode_compound_hdr(xdr, &hdr);
  5455. if (status)
  5456. goto out;
  5457. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5458. if (status)
  5459. goto out;
  5460. status = decode_putfh(xdr);
  5461. if (status)
  5462. goto out;
  5463. status = decode_open_downgrade(xdr, res);
  5464. if (status != 0)
  5465. goto out;
  5466. decode_getfattr(xdr, res->fattr, res->server);
  5467. out:
  5468. return status;
  5469. }
  5470. /*
  5471. * Decode ACCESS response
  5472. */
  5473. static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5474. struct nfs4_accessres *res)
  5475. {
  5476. struct compound_hdr hdr;
  5477. int status;
  5478. status = decode_compound_hdr(xdr, &hdr);
  5479. if (status)
  5480. goto out;
  5481. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5482. if (status)
  5483. goto out;
  5484. status = decode_putfh(xdr);
  5485. if (status != 0)
  5486. goto out;
  5487. status = decode_access(xdr, &res->supported, &res->access);
  5488. if (status != 0)
  5489. goto out;
  5490. decode_getfattr(xdr, res->fattr, res->server);
  5491. out:
  5492. return status;
  5493. }
  5494. /*
  5495. * Decode LOOKUP response
  5496. */
  5497. static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5498. struct nfs4_lookup_res *res)
  5499. {
  5500. struct compound_hdr hdr;
  5501. int status;
  5502. status = decode_compound_hdr(xdr, &hdr);
  5503. if (status)
  5504. goto out;
  5505. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5506. if (status)
  5507. goto out;
  5508. status = decode_putfh(xdr);
  5509. if (status)
  5510. goto out;
  5511. status = decode_lookup(xdr);
  5512. if (status)
  5513. goto out;
  5514. status = decode_getfh(xdr, res->fh);
  5515. if (status)
  5516. goto out;
  5517. status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
  5518. out:
  5519. return status;
  5520. }
  5521. /*
  5522. * Decode LOOKUP_ROOT response
  5523. */
  5524. static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
  5525. struct xdr_stream *xdr,
  5526. struct nfs4_lookup_res *res)
  5527. {
  5528. struct compound_hdr hdr;
  5529. int status;
  5530. status = decode_compound_hdr(xdr, &hdr);
  5531. if (status)
  5532. goto out;
  5533. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5534. if (status)
  5535. goto out;
  5536. status = decode_putrootfh(xdr);
  5537. if (status)
  5538. goto out;
  5539. status = decode_getfh(xdr, res->fh);
  5540. if (status == 0)
  5541. status = decode_getfattr_label(xdr, res->fattr,
  5542. res->label, res->server);
  5543. out:
  5544. return status;
  5545. }
  5546. /*
  5547. * Decode REMOVE response
  5548. */
  5549. static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5550. struct nfs_removeres *res)
  5551. {
  5552. struct compound_hdr hdr;
  5553. int status;
  5554. status = decode_compound_hdr(xdr, &hdr);
  5555. if (status)
  5556. goto out;
  5557. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5558. if (status)
  5559. goto out;
  5560. status = decode_putfh(xdr);
  5561. if (status)
  5562. goto out;
  5563. status = decode_remove(xdr, &res->cinfo);
  5564. out:
  5565. return status;
  5566. }
  5567. /*
  5568. * Decode RENAME response
  5569. */
  5570. static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5571. struct nfs_renameres *res)
  5572. {
  5573. struct compound_hdr hdr;
  5574. int status;
  5575. status = decode_compound_hdr(xdr, &hdr);
  5576. if (status)
  5577. goto out;
  5578. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5579. if (status)
  5580. goto out;
  5581. status = decode_putfh(xdr);
  5582. if (status)
  5583. goto out;
  5584. status = decode_savefh(xdr);
  5585. if (status)
  5586. goto out;
  5587. status = decode_putfh(xdr);
  5588. if (status)
  5589. goto out;
  5590. status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
  5591. out:
  5592. return status;
  5593. }
  5594. /*
  5595. * Decode LINK response
  5596. */
  5597. static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5598. struct nfs4_link_res *res)
  5599. {
  5600. struct compound_hdr hdr;
  5601. int status;
  5602. status = decode_compound_hdr(xdr, &hdr);
  5603. if (status)
  5604. goto out;
  5605. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5606. if (status)
  5607. goto out;
  5608. status = decode_putfh(xdr);
  5609. if (status)
  5610. goto out;
  5611. status = decode_savefh(xdr);
  5612. if (status)
  5613. goto out;
  5614. status = decode_putfh(xdr);
  5615. if (status)
  5616. goto out;
  5617. status = decode_link(xdr, &res->cinfo);
  5618. if (status)
  5619. goto out;
  5620. /*
  5621. * Note order: OP_LINK leaves the directory as the current
  5622. * filehandle.
  5623. */
  5624. status = decode_restorefh(xdr);
  5625. if (status)
  5626. goto out;
  5627. decode_getfattr_label(xdr, res->fattr, res->label, res->server);
  5628. out:
  5629. return status;
  5630. }
  5631. /*
  5632. * Decode CREATE response
  5633. */
  5634. static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5635. struct nfs4_create_res *res)
  5636. {
  5637. struct compound_hdr hdr;
  5638. int status;
  5639. status = decode_compound_hdr(xdr, &hdr);
  5640. if (status)
  5641. goto out;
  5642. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5643. if (status)
  5644. goto out;
  5645. status = decode_putfh(xdr);
  5646. if (status)
  5647. goto out;
  5648. status = decode_create(xdr, &res->dir_cinfo);
  5649. if (status)
  5650. goto out;
  5651. status = decode_getfh(xdr, res->fh);
  5652. if (status)
  5653. goto out;
  5654. decode_getfattr_label(xdr, res->fattr, res->label, res->server);
  5655. out:
  5656. return status;
  5657. }
  5658. /*
  5659. * Decode SYMLINK response
  5660. */
  5661. static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5662. struct nfs4_create_res *res)
  5663. {
  5664. return nfs4_xdr_dec_create(rqstp, xdr, res);
  5665. }
  5666. /*
  5667. * Decode GETATTR response
  5668. */
  5669. static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5670. struct nfs4_getattr_res *res)
  5671. {
  5672. struct compound_hdr hdr;
  5673. int status;
  5674. status = decode_compound_hdr(xdr, &hdr);
  5675. if (status)
  5676. goto out;
  5677. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5678. if (status)
  5679. goto out;
  5680. status = decode_putfh(xdr);
  5681. if (status)
  5682. goto out;
  5683. status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
  5684. out:
  5685. return status;
  5686. }
  5687. /*
  5688. * Encode an SETACL request
  5689. */
  5690. static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
  5691. struct nfs_setaclargs *args)
  5692. {
  5693. struct compound_hdr hdr = {
  5694. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  5695. };
  5696. encode_compound_hdr(xdr, req, &hdr);
  5697. encode_sequence(xdr, &args->seq_args, &hdr);
  5698. encode_putfh(xdr, args->fh, &hdr);
  5699. encode_setacl(xdr, args, &hdr);
  5700. encode_nops(&hdr);
  5701. }
  5702. /*
  5703. * Decode SETACL response
  5704. */
  5705. static int
  5706. nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5707. struct nfs_setaclres *res)
  5708. {
  5709. struct compound_hdr hdr;
  5710. int status;
  5711. status = decode_compound_hdr(xdr, &hdr);
  5712. if (status)
  5713. goto out;
  5714. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5715. if (status)
  5716. goto out;
  5717. status = decode_putfh(xdr);
  5718. if (status)
  5719. goto out;
  5720. status = decode_setattr(xdr);
  5721. out:
  5722. return status;
  5723. }
  5724. /*
  5725. * Decode GETACL response
  5726. */
  5727. static int
  5728. nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5729. struct nfs_getaclres *res)
  5730. {
  5731. struct compound_hdr hdr;
  5732. int status;
  5733. if (res->acl_scratch != NULL) {
  5734. void *p = page_address(res->acl_scratch);
  5735. xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
  5736. }
  5737. status = decode_compound_hdr(xdr, &hdr);
  5738. if (status)
  5739. goto out;
  5740. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5741. if (status)
  5742. goto out;
  5743. status = decode_putfh(xdr);
  5744. if (status)
  5745. goto out;
  5746. status = decode_getacl(xdr, rqstp, res);
  5747. out:
  5748. return status;
  5749. }
  5750. /*
  5751. * Decode CLOSE response
  5752. */
  5753. static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5754. struct nfs_closeres *res)
  5755. {
  5756. struct compound_hdr hdr;
  5757. int status;
  5758. status = decode_compound_hdr(xdr, &hdr);
  5759. if (status)
  5760. goto out;
  5761. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5762. if (status)
  5763. goto out;
  5764. status = decode_putfh(xdr);
  5765. if (status)
  5766. goto out;
  5767. status = decode_close(xdr, res);
  5768. if (status != 0)
  5769. goto out;
  5770. /*
  5771. * Note: Server may do delete on close for this file
  5772. * in which case the getattr call will fail with
  5773. * an ESTALE error. Shouldn't be a problem,
  5774. * though, since fattr->valid will remain unset.
  5775. */
  5776. decode_getfattr(xdr, res->fattr, res->server);
  5777. out:
  5778. return status;
  5779. }
  5780. /*
  5781. * Decode OPEN response
  5782. */
  5783. static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5784. struct nfs_openres *res)
  5785. {
  5786. struct compound_hdr hdr;
  5787. int status;
  5788. status = decode_compound_hdr(xdr, &hdr);
  5789. if (status)
  5790. goto out;
  5791. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5792. if (status)
  5793. goto out;
  5794. status = decode_putfh(xdr);
  5795. if (status)
  5796. goto out;
  5797. status = decode_open(xdr, res);
  5798. if (status)
  5799. goto out;
  5800. status = decode_getfh(xdr, &res->fh);
  5801. if (status)
  5802. goto out;
  5803. if (res->access_request)
  5804. decode_access(xdr, &res->access_supported, &res->access_result);
  5805. decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
  5806. out:
  5807. return status;
  5808. }
  5809. /*
  5810. * Decode OPEN_CONFIRM response
  5811. */
  5812. static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
  5813. struct xdr_stream *xdr,
  5814. struct nfs_open_confirmres *res)
  5815. {
  5816. struct compound_hdr hdr;
  5817. int status;
  5818. status = decode_compound_hdr(xdr, &hdr);
  5819. if (status)
  5820. goto out;
  5821. status = decode_putfh(xdr);
  5822. if (status)
  5823. goto out;
  5824. status = decode_open_confirm(xdr, res);
  5825. out:
  5826. return status;
  5827. }
  5828. /*
  5829. * Decode OPEN response
  5830. */
  5831. static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
  5832. struct xdr_stream *xdr,
  5833. struct nfs_openres *res)
  5834. {
  5835. struct compound_hdr hdr;
  5836. int status;
  5837. status = decode_compound_hdr(xdr, &hdr);
  5838. if (status)
  5839. goto out;
  5840. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5841. if (status)
  5842. goto out;
  5843. status = decode_putfh(xdr);
  5844. if (status)
  5845. goto out;
  5846. status = decode_open(xdr, res);
  5847. if (status)
  5848. goto out;
  5849. if (res->access_request)
  5850. decode_access(xdr, &res->access_supported, &res->access_result);
  5851. decode_getfattr(xdr, res->f_attr, res->server);
  5852. out:
  5853. return status;
  5854. }
  5855. /*
  5856. * Decode SETATTR response
  5857. */
  5858. static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
  5859. struct xdr_stream *xdr,
  5860. struct nfs_setattrres *res)
  5861. {
  5862. struct compound_hdr hdr;
  5863. int status;
  5864. status = decode_compound_hdr(xdr, &hdr);
  5865. if (status)
  5866. goto out;
  5867. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5868. if (status)
  5869. goto out;
  5870. status = decode_putfh(xdr);
  5871. if (status)
  5872. goto out;
  5873. status = decode_setattr(xdr);
  5874. if (status)
  5875. goto out;
  5876. decode_getfattr_label(xdr, res->fattr, res->label, res->server);
  5877. out:
  5878. return status;
  5879. }
  5880. /*
  5881. * Decode LOCK response
  5882. */
  5883. static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5884. struct nfs_lock_res *res)
  5885. {
  5886. struct compound_hdr hdr;
  5887. int status;
  5888. status = decode_compound_hdr(xdr, &hdr);
  5889. if (status)
  5890. goto out;
  5891. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5892. if (status)
  5893. goto out;
  5894. status = decode_putfh(xdr);
  5895. if (status)
  5896. goto out;
  5897. status = decode_lock(xdr, res);
  5898. out:
  5899. return status;
  5900. }
  5901. /*
  5902. * Decode LOCKT response
  5903. */
  5904. static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5905. struct nfs_lockt_res *res)
  5906. {
  5907. struct compound_hdr hdr;
  5908. int status;
  5909. status = decode_compound_hdr(xdr, &hdr);
  5910. if (status)
  5911. goto out;
  5912. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5913. if (status)
  5914. goto out;
  5915. status = decode_putfh(xdr);
  5916. if (status)
  5917. goto out;
  5918. status = decode_lockt(xdr, res);
  5919. out:
  5920. return status;
  5921. }
  5922. /*
  5923. * Decode LOCKU response
  5924. */
  5925. static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5926. struct nfs_locku_res *res)
  5927. {
  5928. struct compound_hdr hdr;
  5929. int status;
  5930. status = decode_compound_hdr(xdr, &hdr);
  5931. if (status)
  5932. goto out;
  5933. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5934. if (status)
  5935. goto out;
  5936. status = decode_putfh(xdr);
  5937. if (status)
  5938. goto out;
  5939. status = decode_locku(xdr, res);
  5940. out:
  5941. return status;
  5942. }
  5943. static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
  5944. struct xdr_stream *xdr, void *dummy)
  5945. {
  5946. struct compound_hdr hdr;
  5947. int status;
  5948. status = decode_compound_hdr(xdr, &hdr);
  5949. if (!status)
  5950. status = decode_release_lockowner(xdr);
  5951. return status;
  5952. }
  5953. /*
  5954. * Decode READLINK response
  5955. */
  5956. static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
  5957. struct xdr_stream *xdr,
  5958. struct nfs4_readlink_res *res)
  5959. {
  5960. struct compound_hdr hdr;
  5961. int status;
  5962. status = decode_compound_hdr(xdr, &hdr);
  5963. if (status)
  5964. goto out;
  5965. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5966. if (status)
  5967. goto out;
  5968. status = decode_putfh(xdr);
  5969. if (status)
  5970. goto out;
  5971. status = decode_readlink(xdr, rqstp);
  5972. out:
  5973. return status;
  5974. }
  5975. /*
  5976. * Decode READDIR response
  5977. */
  5978. static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5979. struct nfs4_readdir_res *res)
  5980. {
  5981. struct compound_hdr hdr;
  5982. int status;
  5983. status = decode_compound_hdr(xdr, &hdr);
  5984. if (status)
  5985. goto out;
  5986. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5987. if (status)
  5988. goto out;
  5989. status = decode_putfh(xdr);
  5990. if (status)
  5991. goto out;
  5992. status = decode_readdir(xdr, rqstp, res);
  5993. out:
  5994. return status;
  5995. }
  5996. /*
  5997. * Decode Read response
  5998. */
  5999. static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6000. struct nfs_pgio_res *res)
  6001. {
  6002. struct compound_hdr hdr;
  6003. int status;
  6004. status = decode_compound_hdr(xdr, &hdr);
  6005. res->op_status = hdr.status;
  6006. if (status)
  6007. goto out;
  6008. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6009. if (status)
  6010. goto out;
  6011. status = decode_putfh(xdr);
  6012. if (status)
  6013. goto out;
  6014. status = decode_read(xdr, rqstp, res);
  6015. if (!status)
  6016. status = res->count;
  6017. out:
  6018. return status;
  6019. }
  6020. /*
  6021. * Decode WRITE response
  6022. */
  6023. static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6024. struct nfs_pgio_res *res)
  6025. {
  6026. struct compound_hdr hdr;
  6027. int status;
  6028. status = decode_compound_hdr(xdr, &hdr);
  6029. res->op_status = hdr.status;
  6030. if (status)
  6031. goto out;
  6032. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6033. if (status)
  6034. goto out;
  6035. status = decode_putfh(xdr);
  6036. if (status)
  6037. goto out;
  6038. status = decode_write(xdr, res);
  6039. if (status)
  6040. goto out;
  6041. if (res->fattr)
  6042. decode_getfattr(xdr, res->fattr, res->server);
  6043. if (!status)
  6044. status = res->count;
  6045. out:
  6046. return status;
  6047. }
  6048. /*
  6049. * Decode COMMIT response
  6050. */
  6051. static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6052. struct nfs_commitres *res)
  6053. {
  6054. struct compound_hdr hdr;
  6055. int status;
  6056. status = decode_compound_hdr(xdr, &hdr);
  6057. res->op_status = hdr.status;
  6058. if (status)
  6059. goto out;
  6060. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6061. if (status)
  6062. goto out;
  6063. status = decode_putfh(xdr);
  6064. if (status)
  6065. goto out;
  6066. status = decode_commit(xdr, res);
  6067. out:
  6068. return status;
  6069. }
  6070. /*
  6071. * Decode FSINFO response
  6072. */
  6073. static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
  6074. struct nfs4_fsinfo_res *res)
  6075. {
  6076. struct compound_hdr hdr;
  6077. int status;
  6078. status = decode_compound_hdr(xdr, &hdr);
  6079. if (!status)
  6080. status = decode_sequence(xdr, &res->seq_res, req);
  6081. if (!status)
  6082. status = decode_putfh(xdr);
  6083. if (!status)
  6084. status = decode_fsinfo(xdr, res->fsinfo);
  6085. return status;
  6086. }
  6087. /*
  6088. * Decode PATHCONF response
  6089. */
  6090. static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
  6091. struct nfs4_pathconf_res *res)
  6092. {
  6093. struct compound_hdr hdr;
  6094. int status;
  6095. status = decode_compound_hdr(xdr, &hdr);
  6096. if (!status)
  6097. status = decode_sequence(xdr, &res->seq_res, req);
  6098. if (!status)
  6099. status = decode_putfh(xdr);
  6100. if (!status)
  6101. status = decode_pathconf(xdr, res->pathconf);
  6102. return status;
  6103. }
  6104. /*
  6105. * Decode STATFS response
  6106. */
  6107. static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
  6108. struct nfs4_statfs_res *res)
  6109. {
  6110. struct compound_hdr hdr;
  6111. int status;
  6112. status = decode_compound_hdr(xdr, &hdr);
  6113. if (!status)
  6114. status = decode_sequence(xdr, &res->seq_res, req);
  6115. if (!status)
  6116. status = decode_putfh(xdr);
  6117. if (!status)
  6118. status = decode_statfs(xdr, res->fsstat);
  6119. return status;
  6120. }
  6121. /*
  6122. * Decode GETATTR_BITMAP response
  6123. */
  6124. static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
  6125. struct xdr_stream *xdr,
  6126. struct nfs4_server_caps_res *res)
  6127. {
  6128. struct compound_hdr hdr;
  6129. int status;
  6130. status = decode_compound_hdr(xdr, &hdr);
  6131. if (status)
  6132. goto out;
  6133. status = decode_sequence(xdr, &res->seq_res, req);
  6134. if (status)
  6135. goto out;
  6136. status = decode_putfh(xdr);
  6137. if (status)
  6138. goto out;
  6139. status = decode_server_caps(xdr, res);
  6140. out:
  6141. return status;
  6142. }
  6143. /*
  6144. * Decode RENEW response
  6145. */
  6146. static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6147. void *__unused)
  6148. {
  6149. struct compound_hdr hdr;
  6150. int status;
  6151. status = decode_compound_hdr(xdr, &hdr);
  6152. if (!status)
  6153. status = decode_renew(xdr);
  6154. return status;
  6155. }
  6156. /*
  6157. * Decode SETCLIENTID response
  6158. */
  6159. static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
  6160. struct xdr_stream *xdr,
  6161. struct nfs4_setclientid_res *res)
  6162. {
  6163. struct compound_hdr hdr;
  6164. int status;
  6165. status = decode_compound_hdr(xdr, &hdr);
  6166. if (!status)
  6167. status = decode_setclientid(xdr, res);
  6168. return status;
  6169. }
  6170. /*
  6171. * Decode SETCLIENTID_CONFIRM response
  6172. */
  6173. static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
  6174. struct xdr_stream *xdr)
  6175. {
  6176. struct compound_hdr hdr;
  6177. int status;
  6178. status = decode_compound_hdr(xdr, &hdr);
  6179. if (!status)
  6180. status = decode_setclientid_confirm(xdr);
  6181. return status;
  6182. }
  6183. /*
  6184. * Decode DELEGRETURN response
  6185. */
  6186. static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
  6187. struct xdr_stream *xdr,
  6188. struct nfs4_delegreturnres *res)
  6189. {
  6190. struct compound_hdr hdr;
  6191. int status;
  6192. status = decode_compound_hdr(xdr, &hdr);
  6193. if (status)
  6194. goto out;
  6195. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6196. if (status)
  6197. goto out;
  6198. status = decode_putfh(xdr);
  6199. if (status != 0)
  6200. goto out;
  6201. status = decode_getfattr(xdr, res->fattr, res->server);
  6202. if (status != 0)
  6203. goto out;
  6204. status = decode_delegreturn(xdr);
  6205. out:
  6206. return status;
  6207. }
  6208. /*
  6209. * Decode FS_LOCATIONS response
  6210. */
  6211. static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
  6212. struct xdr_stream *xdr,
  6213. struct nfs4_fs_locations_res *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, req);
  6221. if (status)
  6222. goto out;
  6223. status = decode_putfh(xdr);
  6224. if (status)
  6225. goto out;
  6226. if (res->migration) {
  6227. xdr_enter_page(xdr, PAGE_SIZE);
  6228. status = decode_getfattr_generic(xdr,
  6229. &res->fs_locations->fattr,
  6230. NULL, res->fs_locations,
  6231. NULL, res->fs_locations->server);
  6232. if (status)
  6233. goto out;
  6234. if (res->renew)
  6235. status = decode_renew(xdr);
  6236. } else {
  6237. status = decode_lookup(xdr);
  6238. if (status)
  6239. goto out;
  6240. xdr_enter_page(xdr, PAGE_SIZE);
  6241. status = decode_getfattr_generic(xdr,
  6242. &res->fs_locations->fattr,
  6243. NULL, res->fs_locations,
  6244. NULL, res->fs_locations->server);
  6245. }
  6246. out:
  6247. return status;
  6248. }
  6249. /*
  6250. * Decode SECINFO response
  6251. */
  6252. static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
  6253. struct xdr_stream *xdr,
  6254. struct nfs4_secinfo_res *res)
  6255. {
  6256. struct compound_hdr hdr;
  6257. int status;
  6258. status = decode_compound_hdr(xdr, &hdr);
  6259. if (status)
  6260. goto out;
  6261. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6262. if (status)
  6263. goto out;
  6264. status = decode_putfh(xdr);
  6265. if (status)
  6266. goto out;
  6267. status = decode_secinfo(xdr, res);
  6268. out:
  6269. return status;
  6270. }
  6271. /*
  6272. * Decode FSID_PRESENT response
  6273. */
  6274. static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
  6275. struct xdr_stream *xdr,
  6276. struct nfs4_fsid_present_res *res)
  6277. {
  6278. struct compound_hdr hdr;
  6279. int status;
  6280. status = decode_compound_hdr(xdr, &hdr);
  6281. if (status)
  6282. goto out;
  6283. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6284. if (status)
  6285. goto out;
  6286. status = decode_putfh(xdr);
  6287. if (status)
  6288. goto out;
  6289. status = decode_getfh(xdr, res->fh);
  6290. if (status)
  6291. goto out;
  6292. if (res->renew)
  6293. status = decode_renew(xdr);
  6294. out:
  6295. return status;
  6296. }
  6297. #if defined(CONFIG_NFS_V4_1)
  6298. /*
  6299. * Decode BIND_CONN_TO_SESSION response
  6300. */
  6301. static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
  6302. struct xdr_stream *xdr,
  6303. void *res)
  6304. {
  6305. struct compound_hdr hdr;
  6306. int status;
  6307. status = decode_compound_hdr(xdr, &hdr);
  6308. if (!status)
  6309. status = decode_bind_conn_to_session(xdr, res);
  6310. return status;
  6311. }
  6312. /*
  6313. * Decode EXCHANGE_ID response
  6314. */
  6315. static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
  6316. struct xdr_stream *xdr,
  6317. void *res)
  6318. {
  6319. struct compound_hdr hdr;
  6320. int status;
  6321. status = decode_compound_hdr(xdr, &hdr);
  6322. if (!status)
  6323. status = decode_exchange_id(xdr, res);
  6324. return status;
  6325. }
  6326. /*
  6327. * Decode CREATE_SESSION response
  6328. */
  6329. static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
  6330. struct xdr_stream *xdr,
  6331. struct nfs41_create_session_res *res)
  6332. {
  6333. struct compound_hdr hdr;
  6334. int status;
  6335. status = decode_compound_hdr(xdr, &hdr);
  6336. if (!status)
  6337. status = decode_create_session(xdr, res);
  6338. return status;
  6339. }
  6340. /*
  6341. * Decode DESTROY_SESSION response
  6342. */
  6343. static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
  6344. struct xdr_stream *xdr,
  6345. void *res)
  6346. {
  6347. struct compound_hdr hdr;
  6348. int status;
  6349. status = decode_compound_hdr(xdr, &hdr);
  6350. if (!status)
  6351. status = decode_destroy_session(xdr, res);
  6352. return status;
  6353. }
  6354. /*
  6355. * Decode DESTROY_CLIENTID response
  6356. */
  6357. static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
  6358. struct xdr_stream *xdr,
  6359. void *res)
  6360. {
  6361. struct compound_hdr hdr;
  6362. int status;
  6363. status = decode_compound_hdr(xdr, &hdr);
  6364. if (!status)
  6365. status = decode_destroy_clientid(xdr, res);
  6366. return status;
  6367. }
  6368. /*
  6369. * Decode SEQUENCE response
  6370. */
  6371. static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
  6372. struct xdr_stream *xdr,
  6373. struct nfs4_sequence_res *res)
  6374. {
  6375. struct compound_hdr hdr;
  6376. int status;
  6377. status = decode_compound_hdr(xdr, &hdr);
  6378. if (!status)
  6379. status = decode_sequence(xdr, res, rqstp);
  6380. return status;
  6381. }
  6382. /*
  6383. * Decode GET_LEASE_TIME response
  6384. */
  6385. static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
  6386. struct xdr_stream *xdr,
  6387. struct nfs4_get_lease_time_res *res)
  6388. {
  6389. struct compound_hdr hdr;
  6390. int status;
  6391. status = decode_compound_hdr(xdr, &hdr);
  6392. if (!status)
  6393. status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
  6394. if (!status)
  6395. status = decode_putrootfh(xdr);
  6396. if (!status)
  6397. status = decode_fsinfo(xdr, res->lr_fsinfo);
  6398. return status;
  6399. }
  6400. /*
  6401. * Decode RECLAIM_COMPLETE response
  6402. */
  6403. static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
  6404. struct xdr_stream *xdr,
  6405. struct nfs41_reclaim_complete_res *res)
  6406. {
  6407. struct compound_hdr hdr;
  6408. int status;
  6409. status = decode_compound_hdr(xdr, &hdr);
  6410. if (!status)
  6411. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6412. if (!status)
  6413. status = decode_reclaim_complete(xdr, NULL);
  6414. return status;
  6415. }
  6416. /*
  6417. * Decode GETDEVINFO response
  6418. */
  6419. static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
  6420. struct xdr_stream *xdr,
  6421. struct nfs4_getdeviceinfo_res *res)
  6422. {
  6423. struct compound_hdr hdr;
  6424. int status;
  6425. status = decode_compound_hdr(xdr, &hdr);
  6426. if (status != 0)
  6427. goto out;
  6428. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6429. if (status != 0)
  6430. goto out;
  6431. status = decode_getdeviceinfo(xdr, res);
  6432. out:
  6433. return status;
  6434. }
  6435. /*
  6436. * Decode LAYOUTGET response
  6437. */
  6438. static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
  6439. struct xdr_stream *xdr,
  6440. struct nfs4_layoutget_res *res)
  6441. {
  6442. struct compound_hdr hdr;
  6443. int status;
  6444. status = decode_compound_hdr(xdr, &hdr);
  6445. if (status)
  6446. goto out;
  6447. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6448. if (status)
  6449. goto out;
  6450. status = decode_putfh(xdr);
  6451. if (status)
  6452. goto out;
  6453. status = decode_layoutget(xdr, rqstp, res);
  6454. out:
  6455. return status;
  6456. }
  6457. /*
  6458. * Decode LAYOUTRETURN response
  6459. */
  6460. static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
  6461. struct xdr_stream *xdr,
  6462. struct nfs4_layoutreturn_res *res)
  6463. {
  6464. struct compound_hdr hdr;
  6465. int status;
  6466. status = decode_compound_hdr(xdr, &hdr);
  6467. if (status)
  6468. goto out;
  6469. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6470. if (status)
  6471. goto out;
  6472. status = decode_putfh(xdr);
  6473. if (status)
  6474. goto out;
  6475. status = decode_layoutreturn(xdr, res);
  6476. out:
  6477. return status;
  6478. }
  6479. /*
  6480. * Decode LAYOUTCOMMIT response
  6481. */
  6482. static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
  6483. struct xdr_stream *xdr,
  6484. struct nfs4_layoutcommit_res *res)
  6485. {
  6486. struct compound_hdr hdr;
  6487. int status;
  6488. status = decode_compound_hdr(xdr, &hdr);
  6489. if (status)
  6490. goto out;
  6491. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6492. if (status)
  6493. goto out;
  6494. status = decode_putfh(xdr);
  6495. if (status)
  6496. goto out;
  6497. status = decode_layoutcommit(xdr, rqstp, res);
  6498. if (status)
  6499. goto out;
  6500. decode_getfattr(xdr, res->fattr, res->server);
  6501. out:
  6502. return status;
  6503. }
  6504. /*
  6505. * Decode SECINFO_NO_NAME response
  6506. */
  6507. static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
  6508. struct xdr_stream *xdr,
  6509. struct nfs4_secinfo_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_putrootfh(xdr);
  6520. if (status)
  6521. goto out;
  6522. status = decode_secinfo_no_name(xdr, res);
  6523. out:
  6524. return status;
  6525. }
  6526. /*
  6527. * Decode TEST_STATEID response
  6528. */
  6529. static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
  6530. struct xdr_stream *xdr,
  6531. struct nfs41_test_stateid_res *res)
  6532. {
  6533. struct compound_hdr hdr;
  6534. int status;
  6535. status = decode_compound_hdr(xdr, &hdr);
  6536. if (status)
  6537. goto out;
  6538. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6539. if (status)
  6540. goto out;
  6541. status = decode_test_stateid(xdr, res);
  6542. out:
  6543. return status;
  6544. }
  6545. /*
  6546. * Decode FREE_STATEID response
  6547. */
  6548. static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
  6549. struct xdr_stream *xdr,
  6550. struct nfs41_free_stateid_res *res)
  6551. {
  6552. struct compound_hdr hdr;
  6553. int status;
  6554. status = decode_compound_hdr(xdr, &hdr);
  6555. if (status)
  6556. goto out;
  6557. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6558. if (status)
  6559. goto out;
  6560. status = decode_free_stateid(xdr, res);
  6561. out:
  6562. return status;
  6563. }
  6564. #endif /* CONFIG_NFS_V4_1 */
  6565. /**
  6566. * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
  6567. * the local page cache.
  6568. * @xdr: XDR stream where entry resides
  6569. * @entry: buffer to fill in with entry data
  6570. * @plus: boolean indicating whether this should be a readdirplus entry
  6571. *
  6572. * Returns zero if successful, otherwise a negative errno value is
  6573. * returned.
  6574. *
  6575. * This function is not invoked during READDIR reply decoding, but
  6576. * rather whenever an application invokes the getdents(2) system call
  6577. * on a directory already in our cache.
  6578. */
  6579. int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
  6580. int plus)
  6581. {
  6582. unsigned int savep;
  6583. uint32_t bitmap[3] = {0};
  6584. uint32_t len;
  6585. __be32 *p = xdr_inline_decode(xdr, 4);
  6586. if (unlikely(!p))
  6587. goto out_overflow;
  6588. if (*p == xdr_zero) {
  6589. p = xdr_inline_decode(xdr, 4);
  6590. if (unlikely(!p))
  6591. goto out_overflow;
  6592. if (*p == xdr_zero)
  6593. return -EAGAIN;
  6594. entry->eof = 1;
  6595. return -EBADCOOKIE;
  6596. }
  6597. p = xdr_inline_decode(xdr, 12);
  6598. if (unlikely(!p))
  6599. goto out_overflow;
  6600. entry->prev_cookie = entry->cookie;
  6601. p = xdr_decode_hyper(p, &entry->cookie);
  6602. entry->len = be32_to_cpup(p);
  6603. p = xdr_inline_decode(xdr, entry->len);
  6604. if (unlikely(!p))
  6605. goto out_overflow;
  6606. entry->name = (const char *) p;
  6607. /*
  6608. * In case the server doesn't return an inode number,
  6609. * we fake one here. (We don't use inode number 0,
  6610. * since glibc seems to choke on it...)
  6611. */
  6612. entry->ino = 1;
  6613. entry->fattr->valid = 0;
  6614. if (decode_attr_bitmap(xdr, bitmap) < 0)
  6615. goto out_overflow;
  6616. if (decode_attr_length(xdr, &len, &savep) < 0)
  6617. goto out_overflow;
  6618. if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
  6619. NULL, entry->label, entry->server) < 0)
  6620. goto out_overflow;
  6621. if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
  6622. entry->ino = entry->fattr->mounted_on_fileid;
  6623. else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
  6624. entry->ino = entry->fattr->fileid;
  6625. entry->d_type = DT_UNKNOWN;
  6626. if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
  6627. entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
  6628. return 0;
  6629. out_overflow:
  6630. print_overflow_msg(__func__, xdr);
  6631. return -EAGAIN;
  6632. }
  6633. /*
  6634. * We need to translate between nfs status return values and
  6635. * the local errno values which may not be the same.
  6636. */
  6637. static struct {
  6638. int stat;
  6639. int errno;
  6640. } nfs_errtbl[] = {
  6641. { NFS4_OK, 0 },
  6642. { NFS4ERR_PERM, -EPERM },
  6643. { NFS4ERR_NOENT, -ENOENT },
  6644. { NFS4ERR_IO, -errno_NFSERR_IO},
  6645. { NFS4ERR_NXIO, -ENXIO },
  6646. { NFS4ERR_ACCESS, -EACCES },
  6647. { NFS4ERR_EXIST, -EEXIST },
  6648. { NFS4ERR_XDEV, -EXDEV },
  6649. { NFS4ERR_NOTDIR, -ENOTDIR },
  6650. { NFS4ERR_ISDIR, -EISDIR },
  6651. { NFS4ERR_INVAL, -EINVAL },
  6652. { NFS4ERR_FBIG, -EFBIG },
  6653. { NFS4ERR_NOSPC, -ENOSPC },
  6654. { NFS4ERR_ROFS, -EROFS },
  6655. { NFS4ERR_MLINK, -EMLINK },
  6656. { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
  6657. { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
  6658. { NFS4ERR_DQUOT, -EDQUOT },
  6659. { NFS4ERR_STALE, -ESTALE },
  6660. { NFS4ERR_BADHANDLE, -EBADHANDLE },
  6661. { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
  6662. { NFS4ERR_NOTSUPP, -ENOTSUPP },
  6663. { NFS4ERR_TOOSMALL, -ETOOSMALL },
  6664. { NFS4ERR_SERVERFAULT, -EREMOTEIO },
  6665. { NFS4ERR_BADTYPE, -EBADTYPE },
  6666. { NFS4ERR_LOCKED, -EAGAIN },
  6667. { NFS4ERR_SYMLINK, -ELOOP },
  6668. { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
  6669. { NFS4ERR_DEADLOCK, -EDEADLK },
  6670. { -1, -EIO }
  6671. };
  6672. /*
  6673. * Convert an NFS error code to a local one.
  6674. * This one is used jointly by NFSv2 and NFSv3.
  6675. */
  6676. static int
  6677. nfs4_stat_to_errno(int stat)
  6678. {
  6679. int i;
  6680. for (i = 0; nfs_errtbl[i].stat != -1; i++) {
  6681. if (nfs_errtbl[i].stat == stat)
  6682. return nfs_errtbl[i].errno;
  6683. }
  6684. if (stat <= 10000 || stat > 10100) {
  6685. /* The server is looney tunes. */
  6686. return -EREMOTEIO;
  6687. }
  6688. /* If we cannot translate the error, the recovery routines should
  6689. * handle it.
  6690. * Note: remaining NFSv4 error codes have values > 10000, so should
  6691. * not conflict with native Linux error codes.
  6692. */
  6693. return -stat;
  6694. }
  6695. #ifdef CONFIG_NFS_V4_2
  6696. #include "nfs42xdr.c"
  6697. #endif /* CONFIG_NFS_V4_2 */
  6698. #define PROC(proc, argtype, restype) \
  6699. [NFSPROC4_CLNT_##proc] = { \
  6700. .p_proc = NFSPROC4_COMPOUND, \
  6701. .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
  6702. .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
  6703. .p_arglen = NFS4_##argtype##_sz, \
  6704. .p_replen = NFS4_##restype##_sz, \
  6705. .p_statidx = NFSPROC4_CLNT_##proc, \
  6706. .p_name = #proc, \
  6707. }
  6708. #define STUB(proc) \
  6709. [NFSPROC4_CLNT_##proc] = { \
  6710. .p_name = #proc, \
  6711. }
  6712. struct rpc_procinfo nfs4_procedures[] = {
  6713. PROC(READ, enc_read, dec_read),
  6714. PROC(WRITE, enc_write, dec_write),
  6715. PROC(COMMIT, enc_commit, dec_commit),
  6716. PROC(OPEN, enc_open, dec_open),
  6717. PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
  6718. PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
  6719. PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
  6720. PROC(CLOSE, enc_close, dec_close),
  6721. PROC(SETATTR, enc_setattr, dec_setattr),
  6722. PROC(FSINFO, enc_fsinfo, dec_fsinfo),
  6723. PROC(RENEW, enc_renew, dec_renew),
  6724. PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
  6725. PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
  6726. PROC(LOCK, enc_lock, dec_lock),
  6727. PROC(LOCKT, enc_lockt, dec_lockt),
  6728. PROC(LOCKU, enc_locku, dec_locku),
  6729. PROC(ACCESS, enc_access, dec_access),
  6730. PROC(GETATTR, enc_getattr, dec_getattr),
  6731. PROC(LOOKUP, enc_lookup, dec_lookup),
  6732. PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
  6733. PROC(REMOVE, enc_remove, dec_remove),
  6734. PROC(RENAME, enc_rename, dec_rename),
  6735. PROC(LINK, enc_link, dec_link),
  6736. PROC(SYMLINK, enc_symlink, dec_symlink),
  6737. PROC(CREATE, enc_create, dec_create),
  6738. PROC(PATHCONF, enc_pathconf, dec_pathconf),
  6739. PROC(STATFS, enc_statfs, dec_statfs),
  6740. PROC(READLINK, enc_readlink, dec_readlink),
  6741. PROC(READDIR, enc_readdir, dec_readdir),
  6742. PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
  6743. PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
  6744. PROC(GETACL, enc_getacl, dec_getacl),
  6745. PROC(SETACL, enc_setacl, dec_setacl),
  6746. PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
  6747. PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
  6748. PROC(SECINFO, enc_secinfo, dec_secinfo),
  6749. PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
  6750. #if defined(CONFIG_NFS_V4_1)
  6751. PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
  6752. PROC(CREATE_SESSION, enc_create_session, dec_create_session),
  6753. PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
  6754. PROC(SEQUENCE, enc_sequence, dec_sequence),
  6755. PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
  6756. PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
  6757. PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
  6758. PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
  6759. PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
  6760. PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
  6761. PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
  6762. PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
  6763. PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
  6764. STUB(GETDEVICELIST),
  6765. PROC(BIND_CONN_TO_SESSION,
  6766. enc_bind_conn_to_session, dec_bind_conn_to_session),
  6767. PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
  6768. #endif /* CONFIG_NFS_V4_1 */
  6769. #ifdef CONFIG_NFS_V4_2
  6770. PROC(SEEK, enc_seek, dec_seek),
  6771. PROC(ALLOCATE, enc_allocate, dec_allocate),
  6772. PROC(DEALLOCATE, enc_deallocate, dec_deallocate),
  6773. PROC(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
  6774. PROC(CLONE, enc_clone, dec_clone),
  6775. #endif /* CONFIG_NFS_V4_2 */
  6776. };
  6777. const struct rpc_version nfs_version4 = {
  6778. .number = 4,
  6779. .nrprocs = ARRAY_SIZE(nfs4_procedures),
  6780. .procs = nfs4_procedures
  6781. };
  6782. /*
  6783. * Local variables:
  6784. * c-basic-offset: 8
  6785. * End:
  6786. */