nfs4xdr.c 189 KB

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