nfs4xdr.c 167 KB

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