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