nfs4xdr.c 189 KB

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