nfs4xdr.c 186 KB

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