nfs4xdr.c 189 KB

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