nfs4xdr.c 189 KB

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