nfs4xdr.c 195 KB

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