nfs4xdr.c 173 KB

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