nfs4xdr.c 183 KB

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