nfs4xdr.c 195 KB

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