nfs4xdr.c 193 KB

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