nfs4xdr.c 186 KB

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