nfs4xdr.c 189 KB

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