nfs4xdr.c 185 KB

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