super.c 160 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668
  1. /*
  2. * linux/fs/ext4/super.c
  3. *
  4. * Copyright (C) 1992, 1993, 1994, 1995
  5. * Remy Card (card@masi.ibp.fr)
  6. * Laboratoire MASI - Institut Blaise Pascal
  7. * Universite Pierre et Marie Curie (Paris VI)
  8. *
  9. * from
  10. *
  11. * linux/fs/minix/inode.c
  12. *
  13. * Copyright (C) 1991, 1992 Linus Torvalds
  14. *
  15. * Big-endian to little-endian byte-swapping/bitmaps by
  16. * David S. Miller (davem@caip.rutgers.edu), 1995
  17. */
  18. #include <linux/module.h>
  19. #include <linux/string.h>
  20. #include <linux/fs.h>
  21. #include <linux/time.h>
  22. #include <linux/vmalloc.h>
  23. #include <linux/slab.h>
  24. #include <linux/init.h>
  25. #include <linux/blkdev.h>
  26. #include <linux/parser.h>
  27. #include <linux/buffer_head.h>
  28. #include <linux/exportfs.h>
  29. #include <linux/vfs.h>
  30. #include <linux/random.h>
  31. #include <linux/mount.h>
  32. #include <linux/namei.h>
  33. #include <linux/quotaops.h>
  34. #include <linux/seq_file.h>
  35. #include <linux/proc_fs.h>
  36. #include <linux/ctype.h>
  37. #include <linux/log2.h>
  38. #include <linux/crc16.h>
  39. #include <linux/cleancache.h>
  40. #include <asm/uaccess.h>
  41. #include <linux/kthread.h>
  42. #include <linux/freezer.h>
  43. #include "ext4.h"
  44. #include "ext4_extents.h" /* Needed for trace points definition */
  45. #include "ext4_jbd2.h"
  46. #include "xattr.h"
  47. #include "acl.h"
  48. #include "mballoc.h"
  49. #define CREATE_TRACE_POINTS
  50. #include <trace/events/ext4.h>
  51. static struct proc_dir_entry *ext4_proc_root;
  52. static struct kset *ext4_kset;
  53. static struct ext4_lazy_init *ext4_li_info;
  54. static struct mutex ext4_li_mtx;
  55. static struct ext4_features *ext4_feat;
  56. static int ext4_mballoc_ready;
  57. static int ext4_load_journal(struct super_block *, struct ext4_super_block *,
  58. unsigned long journal_devnum);
  59. static int ext4_show_options(struct seq_file *seq, struct dentry *root);
  60. static int ext4_commit_super(struct super_block *sb, int sync);
  61. static void ext4_mark_recovery_complete(struct super_block *sb,
  62. struct ext4_super_block *es);
  63. static void ext4_clear_journal_err(struct super_block *sb,
  64. struct ext4_super_block *es);
  65. static int ext4_sync_fs(struct super_block *sb, int wait);
  66. static int ext4_remount(struct super_block *sb, int *flags, char *data);
  67. static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf);
  68. static int ext4_unfreeze(struct super_block *sb);
  69. static int ext4_freeze(struct super_block *sb);
  70. static struct dentry *ext4_mount(struct file_system_type *fs_type, int flags,
  71. const char *dev_name, void *data);
  72. static inline int ext2_feature_set_ok(struct super_block *sb);
  73. static inline int ext3_feature_set_ok(struct super_block *sb);
  74. static int ext4_feature_set_ok(struct super_block *sb, int readonly);
  75. static void ext4_destroy_lazyinit_thread(void);
  76. static void ext4_unregister_li_request(struct super_block *sb);
  77. static void ext4_clear_request_list(void);
  78. static int ext4_reserve_clusters(struct ext4_sb_info *, ext4_fsblk_t);
  79. #if !defined(CONFIG_EXT2_FS) && !defined(CONFIG_EXT2_FS_MODULE) && defined(CONFIG_EXT4_USE_FOR_EXT23)
  80. static struct file_system_type ext2_fs_type = {
  81. .owner = THIS_MODULE,
  82. .name = "ext2",
  83. .mount = ext4_mount,
  84. .kill_sb = kill_block_super,
  85. .fs_flags = FS_REQUIRES_DEV,
  86. };
  87. MODULE_ALIAS_FS("ext2");
  88. MODULE_ALIAS("ext2");
  89. #define IS_EXT2_SB(sb) ((sb)->s_bdev->bd_holder == &ext2_fs_type)
  90. #else
  91. #define IS_EXT2_SB(sb) (0)
  92. #endif
  93. #if !defined(CONFIG_EXT3_FS) && !defined(CONFIG_EXT3_FS_MODULE) && defined(CONFIG_EXT4_USE_FOR_EXT23)
  94. static struct file_system_type ext3_fs_type = {
  95. .owner = THIS_MODULE,
  96. .name = "ext3",
  97. .mount = ext4_mount,
  98. .kill_sb = kill_block_super,
  99. .fs_flags = FS_REQUIRES_DEV,
  100. };
  101. MODULE_ALIAS_FS("ext3");
  102. MODULE_ALIAS("ext3");
  103. #define IS_EXT3_SB(sb) ((sb)->s_bdev->bd_holder == &ext3_fs_type)
  104. #else
  105. #define IS_EXT3_SB(sb) (0)
  106. #endif
  107. static int ext4_verify_csum_type(struct super_block *sb,
  108. struct ext4_super_block *es)
  109. {
  110. if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
  111. EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
  112. return 1;
  113. return es->s_checksum_type == EXT4_CRC32C_CHKSUM;
  114. }
  115. static __le32 ext4_superblock_csum(struct super_block *sb,
  116. struct ext4_super_block *es)
  117. {
  118. struct ext4_sb_info *sbi = EXT4_SB(sb);
  119. int offset = offsetof(struct ext4_super_block, s_checksum);
  120. __u32 csum;
  121. csum = ext4_chksum(sbi, ~0, (char *)es, offset);
  122. return cpu_to_le32(csum);
  123. }
  124. static int ext4_superblock_csum_verify(struct super_block *sb,
  125. struct ext4_super_block *es)
  126. {
  127. if (!ext4_has_metadata_csum(sb))
  128. return 1;
  129. return es->s_checksum == ext4_superblock_csum(sb, es);
  130. }
  131. void ext4_superblock_csum_set(struct super_block *sb)
  132. {
  133. struct ext4_super_block *es = EXT4_SB(sb)->s_es;
  134. if (!ext4_has_metadata_csum(sb))
  135. return;
  136. es->s_checksum = ext4_superblock_csum(sb, es);
  137. }
  138. void *ext4_kvmalloc(size_t size, gfp_t flags)
  139. {
  140. void *ret;
  141. ret = kmalloc(size, flags | __GFP_NOWARN);
  142. if (!ret)
  143. ret = __vmalloc(size, flags, PAGE_KERNEL);
  144. return ret;
  145. }
  146. void *ext4_kvzalloc(size_t size, gfp_t flags)
  147. {
  148. void *ret;
  149. ret = kzalloc(size, flags | __GFP_NOWARN);
  150. if (!ret)
  151. ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL);
  152. return ret;
  153. }
  154. ext4_fsblk_t ext4_block_bitmap(struct super_block *sb,
  155. struct ext4_group_desc *bg)
  156. {
  157. return le32_to_cpu(bg->bg_block_bitmap_lo) |
  158. (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
  159. (ext4_fsblk_t)le32_to_cpu(bg->bg_block_bitmap_hi) << 32 : 0);
  160. }
  161. ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb,
  162. struct ext4_group_desc *bg)
  163. {
  164. return le32_to_cpu(bg->bg_inode_bitmap_lo) |
  165. (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
  166. (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_bitmap_hi) << 32 : 0);
  167. }
  168. ext4_fsblk_t ext4_inode_table(struct super_block *sb,
  169. struct ext4_group_desc *bg)
  170. {
  171. return le32_to_cpu(bg->bg_inode_table_lo) |
  172. (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
  173. (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_table_hi) << 32 : 0);
  174. }
  175. __u32 ext4_free_group_clusters(struct super_block *sb,
  176. struct ext4_group_desc *bg)
  177. {
  178. return le16_to_cpu(bg->bg_free_blocks_count_lo) |
  179. (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
  180. (__u32)le16_to_cpu(bg->bg_free_blocks_count_hi) << 16 : 0);
  181. }
  182. __u32 ext4_free_inodes_count(struct super_block *sb,
  183. struct ext4_group_desc *bg)
  184. {
  185. return le16_to_cpu(bg->bg_free_inodes_count_lo) |
  186. (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
  187. (__u32)le16_to_cpu(bg->bg_free_inodes_count_hi) << 16 : 0);
  188. }
  189. __u32 ext4_used_dirs_count(struct super_block *sb,
  190. struct ext4_group_desc *bg)
  191. {
  192. return le16_to_cpu(bg->bg_used_dirs_count_lo) |
  193. (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
  194. (__u32)le16_to_cpu(bg->bg_used_dirs_count_hi) << 16 : 0);
  195. }
  196. __u32 ext4_itable_unused_count(struct super_block *sb,
  197. struct ext4_group_desc *bg)
  198. {
  199. return le16_to_cpu(bg->bg_itable_unused_lo) |
  200. (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
  201. (__u32)le16_to_cpu(bg->bg_itable_unused_hi) << 16 : 0);
  202. }
  203. void ext4_block_bitmap_set(struct super_block *sb,
  204. struct ext4_group_desc *bg, ext4_fsblk_t blk)
  205. {
  206. bg->bg_block_bitmap_lo = cpu_to_le32((u32)blk);
  207. if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
  208. bg->bg_block_bitmap_hi = cpu_to_le32(blk >> 32);
  209. }
  210. void ext4_inode_bitmap_set(struct super_block *sb,
  211. struct ext4_group_desc *bg, ext4_fsblk_t blk)
  212. {
  213. bg->bg_inode_bitmap_lo = cpu_to_le32((u32)blk);
  214. if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
  215. bg->bg_inode_bitmap_hi = cpu_to_le32(blk >> 32);
  216. }
  217. void ext4_inode_table_set(struct super_block *sb,
  218. struct ext4_group_desc *bg, ext4_fsblk_t blk)
  219. {
  220. bg->bg_inode_table_lo = cpu_to_le32((u32)blk);
  221. if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
  222. bg->bg_inode_table_hi = cpu_to_le32(blk >> 32);
  223. }
  224. void ext4_free_group_clusters_set(struct super_block *sb,
  225. struct ext4_group_desc *bg, __u32 count)
  226. {
  227. bg->bg_free_blocks_count_lo = cpu_to_le16((__u16)count);
  228. if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
  229. bg->bg_free_blocks_count_hi = cpu_to_le16(count >> 16);
  230. }
  231. void ext4_free_inodes_set(struct super_block *sb,
  232. struct ext4_group_desc *bg, __u32 count)
  233. {
  234. bg->bg_free_inodes_count_lo = cpu_to_le16((__u16)count);
  235. if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
  236. bg->bg_free_inodes_count_hi = cpu_to_le16(count >> 16);
  237. }
  238. void ext4_used_dirs_set(struct super_block *sb,
  239. struct ext4_group_desc *bg, __u32 count)
  240. {
  241. bg->bg_used_dirs_count_lo = cpu_to_le16((__u16)count);
  242. if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
  243. bg->bg_used_dirs_count_hi = cpu_to_le16(count >> 16);
  244. }
  245. void ext4_itable_unused_set(struct super_block *sb,
  246. struct ext4_group_desc *bg, __u32 count)
  247. {
  248. bg->bg_itable_unused_lo = cpu_to_le16((__u16)count);
  249. if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
  250. bg->bg_itable_unused_hi = cpu_to_le16(count >> 16);
  251. }
  252. static void __save_error_info(struct super_block *sb, const char *func,
  253. unsigned int line)
  254. {
  255. struct ext4_super_block *es = EXT4_SB(sb)->s_es;
  256. EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
  257. if (bdev_read_only(sb->s_bdev))
  258. return;
  259. es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
  260. es->s_last_error_time = cpu_to_le32(get_seconds());
  261. strncpy(es->s_last_error_func, func, sizeof(es->s_last_error_func));
  262. es->s_last_error_line = cpu_to_le32(line);
  263. if (!es->s_first_error_time) {
  264. es->s_first_error_time = es->s_last_error_time;
  265. strncpy(es->s_first_error_func, func,
  266. sizeof(es->s_first_error_func));
  267. es->s_first_error_line = cpu_to_le32(line);
  268. es->s_first_error_ino = es->s_last_error_ino;
  269. es->s_first_error_block = es->s_last_error_block;
  270. }
  271. /*
  272. * Start the daily error reporting function if it hasn't been
  273. * started already
  274. */
  275. if (!es->s_error_count)
  276. mod_timer(&EXT4_SB(sb)->s_err_report, jiffies + 24*60*60*HZ);
  277. le32_add_cpu(&es->s_error_count, 1);
  278. }
  279. static void save_error_info(struct super_block *sb, const char *func,
  280. unsigned int line)
  281. {
  282. __save_error_info(sb, func, line);
  283. ext4_commit_super(sb, 1);
  284. }
  285. static void ext4_journal_commit_callback(journal_t *journal, transaction_t *txn)
  286. {
  287. struct super_block *sb = journal->j_private;
  288. struct ext4_sb_info *sbi = EXT4_SB(sb);
  289. int error = is_journal_aborted(journal);
  290. struct ext4_journal_cb_entry *jce;
  291. BUG_ON(txn->t_state == T_FINISHED);
  292. spin_lock(&sbi->s_md_lock);
  293. while (!list_empty(&txn->t_private_list)) {
  294. jce = list_entry(txn->t_private_list.next,
  295. struct ext4_journal_cb_entry, jce_list);
  296. list_del_init(&jce->jce_list);
  297. spin_unlock(&sbi->s_md_lock);
  298. jce->jce_func(sb, jce, error);
  299. spin_lock(&sbi->s_md_lock);
  300. }
  301. spin_unlock(&sbi->s_md_lock);
  302. }
  303. /* Deal with the reporting of failure conditions on a filesystem such as
  304. * inconsistencies detected or read IO failures.
  305. *
  306. * On ext2, we can store the error state of the filesystem in the
  307. * superblock. That is not possible on ext4, because we may have other
  308. * write ordering constraints on the superblock which prevent us from
  309. * writing it out straight away; and given that the journal is about to
  310. * be aborted, we can't rely on the current, or future, transactions to
  311. * write out the superblock safely.
  312. *
  313. * We'll just use the jbd2_journal_abort() error code to record an error in
  314. * the journal instead. On recovery, the journal will complain about
  315. * that error until we've noted it down and cleared it.
  316. */
  317. static void ext4_handle_error(struct super_block *sb)
  318. {
  319. if (sb->s_flags & MS_RDONLY)
  320. return;
  321. if (!test_opt(sb, ERRORS_CONT)) {
  322. journal_t *journal = EXT4_SB(sb)->s_journal;
  323. EXT4_SB(sb)->s_mount_flags |= EXT4_MF_FS_ABORTED;
  324. if (journal)
  325. jbd2_journal_abort(journal, -EIO);
  326. }
  327. if (test_opt(sb, ERRORS_RO)) {
  328. ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only");
  329. /*
  330. * Make sure updated value of ->s_mount_flags will be visible
  331. * before ->s_flags update
  332. */
  333. smp_wmb();
  334. sb->s_flags |= MS_RDONLY;
  335. }
  336. if (test_opt(sb, ERRORS_PANIC))
  337. panic("EXT4-fs (device %s): panic forced after error\n",
  338. sb->s_id);
  339. }
  340. #define ext4_error_ratelimit(sb) \
  341. ___ratelimit(&(EXT4_SB(sb)->s_err_ratelimit_state), \
  342. "EXT4-fs error")
  343. void __ext4_error(struct super_block *sb, const char *function,
  344. unsigned int line, const char *fmt, ...)
  345. {
  346. struct va_format vaf;
  347. va_list args;
  348. if (ext4_error_ratelimit(sb)) {
  349. va_start(args, fmt);
  350. vaf.fmt = fmt;
  351. vaf.va = &args;
  352. printk(KERN_CRIT
  353. "EXT4-fs error (device %s): %s:%d: comm %s: %pV\n",
  354. sb->s_id, function, line, current->comm, &vaf);
  355. va_end(args);
  356. }
  357. save_error_info(sb, function, line);
  358. ext4_handle_error(sb);
  359. }
  360. void __ext4_error_inode(struct inode *inode, const char *function,
  361. unsigned int line, ext4_fsblk_t block,
  362. const char *fmt, ...)
  363. {
  364. va_list args;
  365. struct va_format vaf;
  366. struct ext4_super_block *es = EXT4_SB(inode->i_sb)->s_es;
  367. es->s_last_error_ino = cpu_to_le32(inode->i_ino);
  368. es->s_last_error_block = cpu_to_le64(block);
  369. if (ext4_error_ratelimit(inode->i_sb)) {
  370. va_start(args, fmt);
  371. vaf.fmt = fmt;
  372. vaf.va = &args;
  373. if (block)
  374. printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: "
  375. "inode #%lu: block %llu: comm %s: %pV\n",
  376. inode->i_sb->s_id, function, line, inode->i_ino,
  377. block, current->comm, &vaf);
  378. else
  379. printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: "
  380. "inode #%lu: comm %s: %pV\n",
  381. inode->i_sb->s_id, function, line, inode->i_ino,
  382. current->comm, &vaf);
  383. va_end(args);
  384. }
  385. save_error_info(inode->i_sb, function, line);
  386. ext4_handle_error(inode->i_sb);
  387. }
  388. void __ext4_error_file(struct file *file, const char *function,
  389. unsigned int line, ext4_fsblk_t block,
  390. const char *fmt, ...)
  391. {
  392. va_list args;
  393. struct va_format vaf;
  394. struct ext4_super_block *es;
  395. struct inode *inode = file_inode(file);
  396. char pathname[80], *path;
  397. es = EXT4_SB(inode->i_sb)->s_es;
  398. es->s_last_error_ino = cpu_to_le32(inode->i_ino);
  399. if (ext4_error_ratelimit(inode->i_sb)) {
  400. path = d_path(&(file->f_path), pathname, sizeof(pathname));
  401. if (IS_ERR(path))
  402. path = "(unknown)";
  403. va_start(args, fmt);
  404. vaf.fmt = fmt;
  405. vaf.va = &args;
  406. if (block)
  407. printk(KERN_CRIT
  408. "EXT4-fs error (device %s): %s:%d: inode #%lu: "
  409. "block %llu: comm %s: path %s: %pV\n",
  410. inode->i_sb->s_id, function, line, inode->i_ino,
  411. block, current->comm, path, &vaf);
  412. else
  413. printk(KERN_CRIT
  414. "EXT4-fs error (device %s): %s:%d: inode #%lu: "
  415. "comm %s: path %s: %pV\n",
  416. inode->i_sb->s_id, function, line, inode->i_ino,
  417. current->comm, path, &vaf);
  418. va_end(args);
  419. }
  420. save_error_info(inode->i_sb, function, line);
  421. ext4_handle_error(inode->i_sb);
  422. }
  423. const char *ext4_decode_error(struct super_block *sb, int errno,
  424. char nbuf[16])
  425. {
  426. char *errstr = NULL;
  427. switch (errno) {
  428. case -EIO:
  429. errstr = "IO failure";
  430. break;
  431. case -ENOMEM:
  432. errstr = "Out of memory";
  433. break;
  434. case -EROFS:
  435. if (!sb || (EXT4_SB(sb)->s_journal &&
  436. EXT4_SB(sb)->s_journal->j_flags & JBD2_ABORT))
  437. errstr = "Journal has aborted";
  438. else
  439. errstr = "Readonly filesystem";
  440. break;
  441. default:
  442. /* If the caller passed in an extra buffer for unknown
  443. * errors, textualise them now. Else we just return
  444. * NULL. */
  445. if (nbuf) {
  446. /* Check for truncated error codes... */
  447. if (snprintf(nbuf, 16, "error %d", -errno) >= 0)
  448. errstr = nbuf;
  449. }
  450. break;
  451. }
  452. return errstr;
  453. }
  454. /* __ext4_std_error decodes expected errors from journaling functions
  455. * automatically and invokes the appropriate error response. */
  456. void __ext4_std_error(struct super_block *sb, const char *function,
  457. unsigned int line, int errno)
  458. {
  459. char nbuf[16];
  460. const char *errstr;
  461. /* Special case: if the error is EROFS, and we're not already
  462. * inside a transaction, then there's really no point in logging
  463. * an error. */
  464. if (errno == -EROFS && journal_current_handle() == NULL &&
  465. (sb->s_flags & MS_RDONLY))
  466. return;
  467. if (ext4_error_ratelimit(sb)) {
  468. errstr = ext4_decode_error(sb, errno, nbuf);
  469. printk(KERN_CRIT "EXT4-fs error (device %s) in %s:%d: %s\n",
  470. sb->s_id, function, line, errstr);
  471. }
  472. save_error_info(sb, function, line);
  473. ext4_handle_error(sb);
  474. }
  475. /*
  476. * ext4_abort is a much stronger failure handler than ext4_error. The
  477. * abort function may be used to deal with unrecoverable failures such
  478. * as journal IO errors or ENOMEM at a critical moment in log management.
  479. *
  480. * We unconditionally force the filesystem into an ABORT|READONLY state,
  481. * unless the error response on the fs has been set to panic in which
  482. * case we take the easy way out and panic immediately.
  483. */
  484. void __ext4_abort(struct super_block *sb, const char *function,
  485. unsigned int line, const char *fmt, ...)
  486. {
  487. va_list args;
  488. save_error_info(sb, function, line);
  489. va_start(args, fmt);
  490. printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: ", sb->s_id,
  491. function, line);
  492. vprintk(fmt, args);
  493. printk("\n");
  494. va_end(args);
  495. if ((sb->s_flags & MS_RDONLY) == 0) {
  496. ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only");
  497. EXT4_SB(sb)->s_mount_flags |= EXT4_MF_FS_ABORTED;
  498. /*
  499. * Make sure updated value of ->s_mount_flags will be visible
  500. * before ->s_flags update
  501. */
  502. smp_wmb();
  503. sb->s_flags |= MS_RDONLY;
  504. if (EXT4_SB(sb)->s_journal)
  505. jbd2_journal_abort(EXT4_SB(sb)->s_journal, -EIO);
  506. save_error_info(sb, function, line);
  507. }
  508. if (test_opt(sb, ERRORS_PANIC))
  509. panic("EXT4-fs panic from previous error\n");
  510. }
  511. void __ext4_msg(struct super_block *sb,
  512. const char *prefix, const char *fmt, ...)
  513. {
  514. struct va_format vaf;
  515. va_list args;
  516. if (!___ratelimit(&(EXT4_SB(sb)->s_msg_ratelimit_state), "EXT4-fs"))
  517. return;
  518. va_start(args, fmt);
  519. vaf.fmt = fmt;
  520. vaf.va = &args;
  521. printk("%sEXT4-fs (%s): %pV\n", prefix, sb->s_id, &vaf);
  522. va_end(args);
  523. }
  524. void __ext4_warning(struct super_block *sb, const char *function,
  525. unsigned int line, const char *fmt, ...)
  526. {
  527. struct va_format vaf;
  528. va_list args;
  529. if (!___ratelimit(&(EXT4_SB(sb)->s_warning_ratelimit_state),
  530. "EXT4-fs warning"))
  531. return;
  532. va_start(args, fmt);
  533. vaf.fmt = fmt;
  534. vaf.va = &args;
  535. printk(KERN_WARNING "EXT4-fs warning (device %s): %s:%d: %pV\n",
  536. sb->s_id, function, line, &vaf);
  537. va_end(args);
  538. }
  539. void __ext4_grp_locked_error(const char *function, unsigned int line,
  540. struct super_block *sb, ext4_group_t grp,
  541. unsigned long ino, ext4_fsblk_t block,
  542. const char *fmt, ...)
  543. __releases(bitlock)
  544. __acquires(bitlock)
  545. {
  546. struct va_format vaf;
  547. va_list args;
  548. struct ext4_super_block *es = EXT4_SB(sb)->s_es;
  549. es->s_last_error_ino = cpu_to_le32(ino);
  550. es->s_last_error_block = cpu_to_le64(block);
  551. __save_error_info(sb, function, line);
  552. if (ext4_error_ratelimit(sb)) {
  553. va_start(args, fmt);
  554. vaf.fmt = fmt;
  555. vaf.va = &args;
  556. printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: group %u, ",
  557. sb->s_id, function, line, grp);
  558. if (ino)
  559. printk(KERN_CONT "inode %lu: ", ino);
  560. if (block)
  561. printk(KERN_CONT "block %llu:",
  562. (unsigned long long) block);
  563. printk(KERN_CONT "%pV\n", &vaf);
  564. va_end(args);
  565. }
  566. if (test_opt(sb, ERRORS_CONT)) {
  567. ext4_commit_super(sb, 0);
  568. return;
  569. }
  570. ext4_unlock_group(sb, grp);
  571. ext4_handle_error(sb);
  572. /*
  573. * We only get here in the ERRORS_RO case; relocking the group
  574. * may be dangerous, but nothing bad will happen since the
  575. * filesystem will have already been marked read/only and the
  576. * journal has been aborted. We return 1 as a hint to callers
  577. * who might what to use the return value from
  578. * ext4_grp_locked_error() to distinguish between the
  579. * ERRORS_CONT and ERRORS_RO case, and perhaps return more
  580. * aggressively from the ext4 function in question, with a
  581. * more appropriate error code.
  582. */
  583. ext4_lock_group(sb, grp);
  584. return;
  585. }
  586. void ext4_update_dynamic_rev(struct super_block *sb)
  587. {
  588. struct ext4_super_block *es = EXT4_SB(sb)->s_es;
  589. if (le32_to_cpu(es->s_rev_level) > EXT4_GOOD_OLD_REV)
  590. return;
  591. ext4_warning(sb,
  592. "updating to rev %d because of new feature flag, "
  593. "running e2fsck is recommended",
  594. EXT4_DYNAMIC_REV);
  595. es->s_first_ino = cpu_to_le32(EXT4_GOOD_OLD_FIRST_INO);
  596. es->s_inode_size = cpu_to_le16(EXT4_GOOD_OLD_INODE_SIZE);
  597. es->s_rev_level = cpu_to_le32(EXT4_DYNAMIC_REV);
  598. /* leave es->s_feature_*compat flags alone */
  599. /* es->s_uuid will be set by e2fsck if empty */
  600. /*
  601. * The rest of the superblock fields should be zero, and if not it
  602. * means they are likely already in use, so leave them alone. We
  603. * can leave it up to e2fsck to clean up any inconsistencies there.
  604. */
  605. }
  606. /*
  607. * Open the external journal device
  608. */
  609. static struct block_device *ext4_blkdev_get(dev_t dev, struct super_block *sb)
  610. {
  611. struct block_device *bdev;
  612. char b[BDEVNAME_SIZE];
  613. bdev = blkdev_get_by_dev(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL, sb);
  614. if (IS_ERR(bdev))
  615. goto fail;
  616. return bdev;
  617. fail:
  618. ext4_msg(sb, KERN_ERR, "failed to open journal device %s: %ld",
  619. __bdevname(dev, b), PTR_ERR(bdev));
  620. return NULL;
  621. }
  622. /*
  623. * Release the journal device
  624. */
  625. static void ext4_blkdev_put(struct block_device *bdev)
  626. {
  627. blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
  628. }
  629. static void ext4_blkdev_remove(struct ext4_sb_info *sbi)
  630. {
  631. struct block_device *bdev;
  632. bdev = sbi->journal_bdev;
  633. if (bdev) {
  634. ext4_blkdev_put(bdev);
  635. sbi->journal_bdev = NULL;
  636. }
  637. }
  638. static inline struct inode *orphan_list_entry(struct list_head *l)
  639. {
  640. return &list_entry(l, struct ext4_inode_info, i_orphan)->vfs_inode;
  641. }
  642. static void dump_orphan_list(struct super_block *sb, struct ext4_sb_info *sbi)
  643. {
  644. struct list_head *l;
  645. ext4_msg(sb, KERN_ERR, "sb orphan head is %d",
  646. le32_to_cpu(sbi->s_es->s_last_orphan));
  647. printk(KERN_ERR "sb_info orphan list:\n");
  648. list_for_each(l, &sbi->s_orphan) {
  649. struct inode *inode = orphan_list_entry(l);
  650. printk(KERN_ERR " "
  651. "inode %s:%lu at %p: mode %o, nlink %d, next %d\n",
  652. inode->i_sb->s_id, inode->i_ino, inode,
  653. inode->i_mode, inode->i_nlink,
  654. NEXT_ORPHAN(inode));
  655. }
  656. }
  657. static void ext4_put_super(struct super_block *sb)
  658. {
  659. struct ext4_sb_info *sbi = EXT4_SB(sb);
  660. struct ext4_super_block *es = sbi->s_es;
  661. int i, err;
  662. ext4_unregister_li_request(sb);
  663. dquot_disable(sb, -1, DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED);
  664. flush_workqueue(sbi->rsv_conversion_wq);
  665. destroy_workqueue(sbi->rsv_conversion_wq);
  666. if (sbi->s_journal) {
  667. err = jbd2_journal_destroy(sbi->s_journal);
  668. sbi->s_journal = NULL;
  669. if (err < 0)
  670. ext4_abort(sb, "Couldn't clean up the journal");
  671. }
  672. ext4_es_unregister_shrinker(sbi);
  673. del_timer_sync(&sbi->s_err_report);
  674. ext4_release_system_zone(sb);
  675. ext4_mb_release(sb);
  676. ext4_ext_release(sb);
  677. ext4_xattr_put_super(sb);
  678. if (!(sb->s_flags & MS_RDONLY)) {
  679. EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
  680. es->s_state = cpu_to_le16(sbi->s_mount_state);
  681. }
  682. if (!(sb->s_flags & MS_RDONLY))
  683. ext4_commit_super(sb, 1);
  684. if (sbi->s_proc) {
  685. remove_proc_entry("options", sbi->s_proc);
  686. remove_proc_entry(sb->s_id, ext4_proc_root);
  687. }
  688. kobject_del(&sbi->s_kobj);
  689. for (i = 0; i < sbi->s_gdb_count; i++)
  690. brelse(sbi->s_group_desc[i]);
  691. kvfree(sbi->s_group_desc);
  692. kvfree(sbi->s_flex_groups);
  693. percpu_counter_destroy(&sbi->s_freeclusters_counter);
  694. percpu_counter_destroy(&sbi->s_freeinodes_counter);
  695. percpu_counter_destroy(&sbi->s_dirs_counter);
  696. percpu_counter_destroy(&sbi->s_dirtyclusters_counter);
  697. brelse(sbi->s_sbh);
  698. #ifdef CONFIG_QUOTA
  699. for (i = 0; i < EXT4_MAXQUOTAS; i++)
  700. kfree(sbi->s_qf_names[i]);
  701. #endif
  702. /* Debugging code just in case the in-memory inode orphan list
  703. * isn't empty. The on-disk one can be non-empty if we've
  704. * detected an error and taken the fs readonly, but the
  705. * in-memory list had better be clean by this point. */
  706. if (!list_empty(&sbi->s_orphan))
  707. dump_orphan_list(sb, sbi);
  708. J_ASSERT(list_empty(&sbi->s_orphan));
  709. invalidate_bdev(sb->s_bdev);
  710. if (sbi->journal_bdev && sbi->journal_bdev != sb->s_bdev) {
  711. /*
  712. * Invalidate the journal device's buffers. We don't want them
  713. * floating about in memory - the physical journal device may
  714. * hotswapped, and it breaks the `ro-after' testing code.
  715. */
  716. sync_blockdev(sbi->journal_bdev);
  717. invalidate_bdev(sbi->journal_bdev);
  718. ext4_blkdev_remove(sbi);
  719. }
  720. if (sbi->s_mb_cache) {
  721. ext4_xattr_destroy_cache(sbi->s_mb_cache);
  722. sbi->s_mb_cache = NULL;
  723. }
  724. if (sbi->s_mmp_tsk)
  725. kthread_stop(sbi->s_mmp_tsk);
  726. sb->s_fs_info = NULL;
  727. /*
  728. * Now that we are completely done shutting down the
  729. * superblock, we need to actually destroy the kobject.
  730. */
  731. kobject_put(&sbi->s_kobj);
  732. wait_for_completion(&sbi->s_kobj_unregister);
  733. if (sbi->s_chksum_driver)
  734. crypto_free_shash(sbi->s_chksum_driver);
  735. kfree(sbi->s_blockgroup_lock);
  736. kfree(sbi);
  737. }
  738. static struct kmem_cache *ext4_inode_cachep;
  739. /*
  740. * Called inside transaction, so use GFP_NOFS
  741. */
  742. static struct inode *ext4_alloc_inode(struct super_block *sb)
  743. {
  744. struct ext4_inode_info *ei;
  745. ei = kmem_cache_alloc(ext4_inode_cachep, GFP_NOFS);
  746. if (!ei)
  747. return NULL;
  748. ei->vfs_inode.i_version = 1;
  749. spin_lock_init(&ei->i_raw_lock);
  750. INIT_LIST_HEAD(&ei->i_prealloc_list);
  751. spin_lock_init(&ei->i_prealloc_lock);
  752. ext4_es_init_tree(&ei->i_es_tree);
  753. rwlock_init(&ei->i_es_lock);
  754. INIT_LIST_HEAD(&ei->i_es_list);
  755. ei->i_es_all_nr = 0;
  756. ei->i_es_shk_nr = 0;
  757. ei->i_es_shrink_lblk = 0;
  758. ei->i_reserved_data_blocks = 0;
  759. ei->i_reserved_meta_blocks = 0;
  760. ei->i_allocated_meta_blocks = 0;
  761. ei->i_da_metadata_calc_len = 0;
  762. ei->i_da_metadata_calc_last_lblock = 0;
  763. spin_lock_init(&(ei->i_block_reservation_lock));
  764. #ifdef CONFIG_QUOTA
  765. ei->i_reserved_quota = 0;
  766. memset(&ei->i_dquot, 0, sizeof(ei->i_dquot));
  767. #endif
  768. ei->jinode = NULL;
  769. INIT_LIST_HEAD(&ei->i_rsv_conversion_list);
  770. spin_lock_init(&ei->i_completed_io_lock);
  771. ei->i_sync_tid = 0;
  772. ei->i_datasync_tid = 0;
  773. atomic_set(&ei->i_ioend_count, 0);
  774. atomic_set(&ei->i_unwritten, 0);
  775. INIT_WORK(&ei->i_rsv_conversion_work, ext4_end_io_rsv_work);
  776. #ifdef CONFIG_EXT4_FS_ENCRYPTION
  777. ei->i_encryption_key.mode = EXT4_ENCRYPTION_MODE_INVALID;
  778. #endif
  779. return &ei->vfs_inode;
  780. }
  781. static int ext4_drop_inode(struct inode *inode)
  782. {
  783. int drop = generic_drop_inode(inode);
  784. trace_ext4_drop_inode(inode, drop);
  785. return drop;
  786. }
  787. static void ext4_i_callback(struct rcu_head *head)
  788. {
  789. struct inode *inode = container_of(head, struct inode, i_rcu);
  790. kmem_cache_free(ext4_inode_cachep, EXT4_I(inode));
  791. }
  792. static void ext4_destroy_inode(struct inode *inode)
  793. {
  794. if (!list_empty(&(EXT4_I(inode)->i_orphan))) {
  795. ext4_msg(inode->i_sb, KERN_ERR,
  796. "Inode %lu (%p): orphan list check failed!",
  797. inode->i_ino, EXT4_I(inode));
  798. print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, 16, 4,
  799. EXT4_I(inode), sizeof(struct ext4_inode_info),
  800. true);
  801. dump_stack();
  802. }
  803. call_rcu(&inode->i_rcu, ext4_i_callback);
  804. }
  805. static void init_once(void *foo)
  806. {
  807. struct ext4_inode_info *ei = (struct ext4_inode_info *) foo;
  808. INIT_LIST_HEAD(&ei->i_orphan);
  809. init_rwsem(&ei->xattr_sem);
  810. init_rwsem(&ei->i_data_sem);
  811. inode_init_once(&ei->vfs_inode);
  812. }
  813. static int __init init_inodecache(void)
  814. {
  815. ext4_inode_cachep = kmem_cache_create("ext4_inode_cache",
  816. sizeof(struct ext4_inode_info),
  817. 0, (SLAB_RECLAIM_ACCOUNT|
  818. SLAB_MEM_SPREAD),
  819. init_once);
  820. if (ext4_inode_cachep == NULL)
  821. return -ENOMEM;
  822. return 0;
  823. }
  824. static void destroy_inodecache(void)
  825. {
  826. /*
  827. * Make sure all delayed rcu free inodes are flushed before we
  828. * destroy cache.
  829. */
  830. rcu_barrier();
  831. kmem_cache_destroy(ext4_inode_cachep);
  832. }
  833. void ext4_clear_inode(struct inode *inode)
  834. {
  835. invalidate_inode_buffers(inode);
  836. clear_inode(inode);
  837. dquot_drop(inode);
  838. ext4_discard_preallocations(inode);
  839. ext4_es_remove_extent(inode, 0, EXT_MAX_BLOCKS);
  840. if (EXT4_I(inode)->jinode) {
  841. jbd2_journal_release_jbd_inode(EXT4_JOURNAL(inode),
  842. EXT4_I(inode)->jinode);
  843. jbd2_free_inode(EXT4_I(inode)->jinode);
  844. EXT4_I(inode)->jinode = NULL;
  845. }
  846. }
  847. static struct inode *ext4_nfs_get_inode(struct super_block *sb,
  848. u64 ino, u32 generation)
  849. {
  850. struct inode *inode;
  851. if (ino < EXT4_FIRST_INO(sb) && ino != EXT4_ROOT_INO)
  852. return ERR_PTR(-ESTALE);
  853. if (ino > le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count))
  854. return ERR_PTR(-ESTALE);
  855. /* iget isn't really right if the inode is currently unallocated!!
  856. *
  857. * ext4_read_inode will return a bad_inode if the inode had been
  858. * deleted, so we should be safe.
  859. *
  860. * Currently we don't know the generation for parent directory, so
  861. * a generation of 0 means "accept any"
  862. */
  863. inode = ext4_iget_normal(sb, ino);
  864. if (IS_ERR(inode))
  865. return ERR_CAST(inode);
  866. if (generation && inode->i_generation != generation) {
  867. iput(inode);
  868. return ERR_PTR(-ESTALE);
  869. }
  870. return inode;
  871. }
  872. static struct dentry *ext4_fh_to_dentry(struct super_block *sb, struct fid *fid,
  873. int fh_len, int fh_type)
  874. {
  875. return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
  876. ext4_nfs_get_inode);
  877. }
  878. static struct dentry *ext4_fh_to_parent(struct super_block *sb, struct fid *fid,
  879. int fh_len, int fh_type)
  880. {
  881. return generic_fh_to_parent(sb, fid, fh_len, fh_type,
  882. ext4_nfs_get_inode);
  883. }
  884. /*
  885. * Try to release metadata pages (indirect blocks, directories) which are
  886. * mapped via the block device. Since these pages could have journal heads
  887. * which would prevent try_to_free_buffers() from freeing them, we must use
  888. * jbd2 layer's try_to_free_buffers() function to release them.
  889. */
  890. static int bdev_try_to_free_page(struct super_block *sb, struct page *page,
  891. gfp_t wait)
  892. {
  893. journal_t *journal = EXT4_SB(sb)->s_journal;
  894. WARN_ON(PageChecked(page));
  895. if (!page_has_buffers(page))
  896. return 0;
  897. if (journal)
  898. return jbd2_journal_try_to_free_buffers(journal, page,
  899. wait & ~__GFP_WAIT);
  900. return try_to_free_buffers(page);
  901. }
  902. #ifdef CONFIG_QUOTA
  903. #define QTYPE2NAME(t) ((t) == USRQUOTA ? "user" : "group")
  904. #define QTYPE2MOPT(on, t) ((t) == USRQUOTA?((on)##USRJQUOTA):((on)##GRPJQUOTA))
  905. static int ext4_write_dquot(struct dquot *dquot);
  906. static int ext4_acquire_dquot(struct dquot *dquot);
  907. static int ext4_release_dquot(struct dquot *dquot);
  908. static int ext4_mark_dquot_dirty(struct dquot *dquot);
  909. static int ext4_write_info(struct super_block *sb, int type);
  910. static int ext4_quota_on(struct super_block *sb, int type, int format_id,
  911. struct path *path);
  912. static int ext4_quota_off(struct super_block *sb, int type);
  913. static int ext4_quota_on_mount(struct super_block *sb, int type);
  914. static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data,
  915. size_t len, loff_t off);
  916. static ssize_t ext4_quota_write(struct super_block *sb, int type,
  917. const char *data, size_t len, loff_t off);
  918. static int ext4_quota_enable(struct super_block *sb, int type, int format_id,
  919. unsigned int flags);
  920. static int ext4_enable_quotas(struct super_block *sb);
  921. static struct dquot **ext4_get_dquots(struct inode *inode)
  922. {
  923. return EXT4_I(inode)->i_dquot;
  924. }
  925. static const struct dquot_operations ext4_quota_operations = {
  926. .get_reserved_space = ext4_get_reserved_space,
  927. .write_dquot = ext4_write_dquot,
  928. .acquire_dquot = ext4_acquire_dquot,
  929. .release_dquot = ext4_release_dquot,
  930. .mark_dirty = ext4_mark_dquot_dirty,
  931. .write_info = ext4_write_info,
  932. .alloc_dquot = dquot_alloc,
  933. .destroy_dquot = dquot_destroy,
  934. };
  935. static const struct quotactl_ops ext4_qctl_operations = {
  936. .quota_on = ext4_quota_on,
  937. .quota_off = ext4_quota_off,
  938. .quota_sync = dquot_quota_sync,
  939. .get_state = dquot_get_state,
  940. .set_info = dquot_set_dqinfo,
  941. .get_dqblk = dquot_get_dqblk,
  942. .set_dqblk = dquot_set_dqblk
  943. };
  944. #endif
  945. static const struct super_operations ext4_sops = {
  946. .alloc_inode = ext4_alloc_inode,
  947. .destroy_inode = ext4_destroy_inode,
  948. .write_inode = ext4_write_inode,
  949. .dirty_inode = ext4_dirty_inode,
  950. .drop_inode = ext4_drop_inode,
  951. .evict_inode = ext4_evict_inode,
  952. .put_super = ext4_put_super,
  953. .sync_fs = ext4_sync_fs,
  954. .freeze_fs = ext4_freeze,
  955. .unfreeze_fs = ext4_unfreeze,
  956. .statfs = ext4_statfs,
  957. .remount_fs = ext4_remount,
  958. .show_options = ext4_show_options,
  959. #ifdef CONFIG_QUOTA
  960. .quota_read = ext4_quota_read,
  961. .quota_write = ext4_quota_write,
  962. .get_dquots = ext4_get_dquots,
  963. #endif
  964. .bdev_try_to_free_page = bdev_try_to_free_page,
  965. };
  966. static const struct export_operations ext4_export_ops = {
  967. .fh_to_dentry = ext4_fh_to_dentry,
  968. .fh_to_parent = ext4_fh_to_parent,
  969. .get_parent = ext4_get_parent,
  970. };
  971. enum {
  972. Opt_bsd_df, Opt_minix_df, Opt_grpid, Opt_nogrpid,
  973. Opt_resgid, Opt_resuid, Opt_sb, Opt_err_cont, Opt_err_panic, Opt_err_ro,
  974. Opt_nouid32, Opt_debug, Opt_removed,
  975. Opt_user_xattr, Opt_nouser_xattr, Opt_acl, Opt_noacl,
  976. Opt_auto_da_alloc, Opt_noauto_da_alloc, Opt_noload,
  977. Opt_commit, Opt_min_batch_time, Opt_max_batch_time, Opt_journal_dev,
  978. Opt_journal_path, Opt_journal_checksum, Opt_journal_async_commit,
  979. Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback,
  980. Opt_data_err_abort, Opt_data_err_ignore, Opt_test_dummy_encryption,
  981. Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
  982. Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
  983. Opt_noquota, Opt_barrier, Opt_nobarrier, Opt_err,
  984. Opt_usrquota, Opt_grpquota, Opt_i_version, Opt_dax,
  985. Opt_stripe, Opt_delalloc, Opt_nodelalloc, Opt_mblk_io_submit,
  986. Opt_lazytime, Opt_nolazytime,
  987. Opt_nomblk_io_submit, Opt_block_validity, Opt_noblock_validity,
  988. Opt_inode_readahead_blks, Opt_journal_ioprio,
  989. Opt_dioread_nolock, Opt_dioread_lock,
  990. Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
  991. Opt_max_dir_size_kb, Opt_nojournal_checksum,
  992. };
  993. static const match_table_t tokens = {
  994. {Opt_bsd_df, "bsddf"},
  995. {Opt_minix_df, "minixdf"},
  996. {Opt_grpid, "grpid"},
  997. {Opt_grpid, "bsdgroups"},
  998. {Opt_nogrpid, "nogrpid"},
  999. {Opt_nogrpid, "sysvgroups"},
  1000. {Opt_resgid, "resgid=%u"},
  1001. {Opt_resuid, "resuid=%u"},
  1002. {Opt_sb, "sb=%u"},
  1003. {Opt_err_cont, "errors=continue"},
  1004. {Opt_err_panic, "errors=panic"},
  1005. {Opt_err_ro, "errors=remount-ro"},
  1006. {Opt_nouid32, "nouid32"},
  1007. {Opt_debug, "debug"},
  1008. {Opt_removed, "oldalloc"},
  1009. {Opt_removed, "orlov"},
  1010. {Opt_user_xattr, "user_xattr"},
  1011. {Opt_nouser_xattr, "nouser_xattr"},
  1012. {Opt_acl, "acl"},
  1013. {Opt_noacl, "noacl"},
  1014. {Opt_noload, "norecovery"},
  1015. {Opt_noload, "noload"},
  1016. {Opt_removed, "nobh"},
  1017. {Opt_removed, "bh"},
  1018. {Opt_commit, "commit=%u"},
  1019. {Opt_min_batch_time, "min_batch_time=%u"},
  1020. {Opt_max_batch_time, "max_batch_time=%u"},
  1021. {Opt_journal_dev, "journal_dev=%u"},
  1022. {Opt_journal_path, "journal_path=%s"},
  1023. {Opt_journal_checksum, "journal_checksum"},
  1024. {Opt_nojournal_checksum, "nojournal_checksum"},
  1025. {Opt_journal_async_commit, "journal_async_commit"},
  1026. {Opt_abort, "abort"},
  1027. {Opt_data_journal, "data=journal"},
  1028. {Opt_data_ordered, "data=ordered"},
  1029. {Opt_data_writeback, "data=writeback"},
  1030. {Opt_data_err_abort, "data_err=abort"},
  1031. {Opt_data_err_ignore, "data_err=ignore"},
  1032. {Opt_offusrjquota, "usrjquota="},
  1033. {Opt_usrjquota, "usrjquota=%s"},
  1034. {Opt_offgrpjquota, "grpjquota="},
  1035. {Opt_grpjquota, "grpjquota=%s"},
  1036. {Opt_jqfmt_vfsold, "jqfmt=vfsold"},
  1037. {Opt_jqfmt_vfsv0, "jqfmt=vfsv0"},
  1038. {Opt_jqfmt_vfsv1, "jqfmt=vfsv1"},
  1039. {Opt_grpquota, "grpquota"},
  1040. {Opt_noquota, "noquota"},
  1041. {Opt_quota, "quota"},
  1042. {Opt_usrquota, "usrquota"},
  1043. {Opt_barrier, "barrier=%u"},
  1044. {Opt_barrier, "barrier"},
  1045. {Opt_nobarrier, "nobarrier"},
  1046. {Opt_i_version, "i_version"},
  1047. {Opt_dax, "dax"},
  1048. {Opt_stripe, "stripe=%u"},
  1049. {Opt_delalloc, "delalloc"},
  1050. {Opt_lazytime, "lazytime"},
  1051. {Opt_nolazytime, "nolazytime"},
  1052. {Opt_nodelalloc, "nodelalloc"},
  1053. {Opt_removed, "mblk_io_submit"},
  1054. {Opt_removed, "nomblk_io_submit"},
  1055. {Opt_block_validity, "block_validity"},
  1056. {Opt_noblock_validity, "noblock_validity"},
  1057. {Opt_inode_readahead_blks, "inode_readahead_blks=%u"},
  1058. {Opt_journal_ioprio, "journal_ioprio=%u"},
  1059. {Opt_auto_da_alloc, "auto_da_alloc=%u"},
  1060. {Opt_auto_da_alloc, "auto_da_alloc"},
  1061. {Opt_noauto_da_alloc, "noauto_da_alloc"},
  1062. {Opt_dioread_nolock, "dioread_nolock"},
  1063. {Opt_dioread_lock, "dioread_lock"},
  1064. {Opt_discard, "discard"},
  1065. {Opt_nodiscard, "nodiscard"},
  1066. {Opt_init_itable, "init_itable=%u"},
  1067. {Opt_init_itable, "init_itable"},
  1068. {Opt_noinit_itable, "noinit_itable"},
  1069. {Opt_max_dir_size_kb, "max_dir_size_kb=%u"},
  1070. {Opt_test_dummy_encryption, "test_dummy_encryption"},
  1071. {Opt_removed, "check=none"}, /* mount option from ext2/3 */
  1072. {Opt_removed, "nocheck"}, /* mount option from ext2/3 */
  1073. {Opt_removed, "reservation"}, /* mount option from ext2/3 */
  1074. {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
  1075. {Opt_removed, "journal=%u"}, /* mount option from ext2/3 */
  1076. {Opt_err, NULL},
  1077. };
  1078. static ext4_fsblk_t get_sb_block(void **data)
  1079. {
  1080. ext4_fsblk_t sb_block;
  1081. char *options = (char *) *data;
  1082. if (!options || strncmp(options, "sb=", 3) != 0)
  1083. return 1; /* Default location */
  1084. options += 3;
  1085. /* TODO: use simple_strtoll with >32bit ext4 */
  1086. sb_block = simple_strtoul(options, &options, 0);
  1087. if (*options && *options != ',') {
  1088. printk(KERN_ERR "EXT4-fs: Invalid sb specification: %s\n",
  1089. (char *) *data);
  1090. return 1;
  1091. }
  1092. if (*options == ',')
  1093. options++;
  1094. *data = (void *) options;
  1095. return sb_block;
  1096. }
  1097. #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
  1098. static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
  1099. "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
  1100. #ifdef CONFIG_QUOTA
  1101. static int set_qf_name(struct super_block *sb, int qtype, substring_t *args)
  1102. {
  1103. struct ext4_sb_info *sbi = EXT4_SB(sb);
  1104. char *qname;
  1105. int ret = -1;
  1106. if (sb_any_quota_loaded(sb) &&
  1107. !sbi->s_qf_names[qtype]) {
  1108. ext4_msg(sb, KERN_ERR,
  1109. "Cannot change journaled "
  1110. "quota options when quota turned on");
  1111. return -1;
  1112. }
  1113. if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_QUOTA)) {
  1114. ext4_msg(sb, KERN_ERR, "Cannot set journaled quota options "
  1115. "when QUOTA feature is enabled");
  1116. return -1;
  1117. }
  1118. qname = match_strdup(args);
  1119. if (!qname) {
  1120. ext4_msg(sb, KERN_ERR,
  1121. "Not enough memory for storing quotafile name");
  1122. return -1;
  1123. }
  1124. if (sbi->s_qf_names[qtype]) {
  1125. if (strcmp(sbi->s_qf_names[qtype], qname) == 0)
  1126. ret = 1;
  1127. else
  1128. ext4_msg(sb, KERN_ERR,
  1129. "%s quota file already specified",
  1130. QTYPE2NAME(qtype));
  1131. goto errout;
  1132. }
  1133. if (strchr(qname, '/')) {
  1134. ext4_msg(sb, KERN_ERR,
  1135. "quotafile must be on filesystem root");
  1136. goto errout;
  1137. }
  1138. sbi->s_qf_names[qtype] = qname;
  1139. set_opt(sb, QUOTA);
  1140. return 1;
  1141. errout:
  1142. kfree(qname);
  1143. return ret;
  1144. }
  1145. static int clear_qf_name(struct super_block *sb, int qtype)
  1146. {
  1147. struct ext4_sb_info *sbi = EXT4_SB(sb);
  1148. if (sb_any_quota_loaded(sb) &&
  1149. sbi->s_qf_names[qtype]) {
  1150. ext4_msg(sb, KERN_ERR, "Cannot change journaled quota options"
  1151. " when quota turned on");
  1152. return -1;
  1153. }
  1154. kfree(sbi->s_qf_names[qtype]);
  1155. sbi->s_qf_names[qtype] = NULL;
  1156. return 1;
  1157. }
  1158. #endif
  1159. #define MOPT_SET 0x0001
  1160. #define MOPT_CLEAR 0x0002
  1161. #define MOPT_NOSUPPORT 0x0004
  1162. #define MOPT_EXPLICIT 0x0008
  1163. #define MOPT_CLEAR_ERR 0x0010
  1164. #define MOPT_GTE0 0x0020
  1165. #ifdef CONFIG_QUOTA
  1166. #define MOPT_Q 0
  1167. #define MOPT_QFMT 0x0040
  1168. #else
  1169. #define MOPT_Q MOPT_NOSUPPORT
  1170. #define MOPT_QFMT MOPT_NOSUPPORT
  1171. #endif
  1172. #define MOPT_DATAJ 0x0080
  1173. #define MOPT_NO_EXT2 0x0100
  1174. #define MOPT_NO_EXT3 0x0200
  1175. #define MOPT_EXT4_ONLY (MOPT_NO_EXT2 | MOPT_NO_EXT3)
  1176. #define MOPT_STRING 0x0400
  1177. static const struct mount_opts {
  1178. int token;
  1179. int mount_opt;
  1180. int flags;
  1181. } ext4_mount_opts[] = {
  1182. {Opt_minix_df, EXT4_MOUNT_MINIX_DF, MOPT_SET},
  1183. {Opt_bsd_df, EXT4_MOUNT_MINIX_DF, MOPT_CLEAR},
  1184. {Opt_grpid, EXT4_MOUNT_GRPID, MOPT_SET},
  1185. {Opt_nogrpid, EXT4_MOUNT_GRPID, MOPT_CLEAR},
  1186. {Opt_block_validity, EXT4_MOUNT_BLOCK_VALIDITY, MOPT_SET},
  1187. {Opt_noblock_validity, EXT4_MOUNT_BLOCK_VALIDITY, MOPT_CLEAR},
  1188. {Opt_dioread_nolock, EXT4_MOUNT_DIOREAD_NOLOCK,
  1189. MOPT_EXT4_ONLY | MOPT_SET},
  1190. {Opt_dioread_lock, EXT4_MOUNT_DIOREAD_NOLOCK,
  1191. MOPT_EXT4_ONLY | MOPT_CLEAR},
  1192. {Opt_discard, EXT4_MOUNT_DISCARD, MOPT_SET},
  1193. {Opt_nodiscard, EXT4_MOUNT_DISCARD, MOPT_CLEAR},
  1194. {Opt_delalloc, EXT4_MOUNT_DELALLOC,
  1195. MOPT_EXT4_ONLY | MOPT_SET | MOPT_EXPLICIT},
  1196. {Opt_nodelalloc, EXT4_MOUNT_DELALLOC,
  1197. MOPT_EXT4_ONLY | MOPT_CLEAR},
  1198. {Opt_nojournal_checksum, EXT4_MOUNT_JOURNAL_CHECKSUM,
  1199. MOPT_EXT4_ONLY | MOPT_CLEAR},
  1200. {Opt_journal_checksum, EXT4_MOUNT_JOURNAL_CHECKSUM,
  1201. MOPT_EXT4_ONLY | MOPT_SET},
  1202. {Opt_journal_async_commit, (EXT4_MOUNT_JOURNAL_ASYNC_COMMIT |
  1203. EXT4_MOUNT_JOURNAL_CHECKSUM),
  1204. MOPT_EXT4_ONLY | MOPT_SET},
  1205. {Opt_noload, EXT4_MOUNT_NOLOAD, MOPT_NO_EXT2 | MOPT_SET},
  1206. {Opt_err_panic, EXT4_MOUNT_ERRORS_PANIC, MOPT_SET | MOPT_CLEAR_ERR},
  1207. {Opt_err_ro, EXT4_MOUNT_ERRORS_RO, MOPT_SET | MOPT_CLEAR_ERR},
  1208. {Opt_err_cont, EXT4_MOUNT_ERRORS_CONT, MOPT_SET | MOPT_CLEAR_ERR},
  1209. {Opt_data_err_abort, EXT4_MOUNT_DATA_ERR_ABORT,
  1210. MOPT_NO_EXT2 | MOPT_SET},
  1211. {Opt_data_err_ignore, EXT4_MOUNT_DATA_ERR_ABORT,
  1212. MOPT_NO_EXT2 | MOPT_CLEAR},
  1213. {Opt_barrier, EXT4_MOUNT_BARRIER, MOPT_SET},
  1214. {Opt_nobarrier, EXT4_MOUNT_BARRIER, MOPT_CLEAR},
  1215. {Opt_noauto_da_alloc, EXT4_MOUNT_NO_AUTO_DA_ALLOC, MOPT_SET},
  1216. {Opt_auto_da_alloc, EXT4_MOUNT_NO_AUTO_DA_ALLOC, MOPT_CLEAR},
  1217. {Opt_noinit_itable, EXT4_MOUNT_INIT_INODE_TABLE, MOPT_CLEAR},
  1218. {Opt_commit, 0, MOPT_GTE0},
  1219. {Opt_max_batch_time, 0, MOPT_GTE0},
  1220. {Opt_min_batch_time, 0, MOPT_GTE0},
  1221. {Opt_inode_readahead_blks, 0, MOPT_GTE0},
  1222. {Opt_init_itable, 0, MOPT_GTE0},
  1223. {Opt_dax, EXT4_MOUNT_DAX, MOPT_SET},
  1224. {Opt_stripe, 0, MOPT_GTE0},
  1225. {Opt_resuid, 0, MOPT_GTE0},
  1226. {Opt_resgid, 0, MOPT_GTE0},
  1227. {Opt_journal_dev, 0, MOPT_GTE0},
  1228. {Opt_journal_path, 0, MOPT_STRING},
  1229. {Opt_journal_ioprio, 0, MOPT_GTE0},
  1230. {Opt_data_journal, EXT4_MOUNT_JOURNAL_DATA, MOPT_NO_EXT2 | MOPT_DATAJ},
  1231. {Opt_data_ordered, EXT4_MOUNT_ORDERED_DATA, MOPT_NO_EXT2 | MOPT_DATAJ},
  1232. {Opt_data_writeback, EXT4_MOUNT_WRITEBACK_DATA,
  1233. MOPT_NO_EXT2 | MOPT_DATAJ},
  1234. {Opt_user_xattr, EXT4_MOUNT_XATTR_USER, MOPT_SET},
  1235. {Opt_nouser_xattr, EXT4_MOUNT_XATTR_USER, MOPT_CLEAR},
  1236. #ifdef CONFIG_EXT4_FS_POSIX_ACL
  1237. {Opt_acl, EXT4_MOUNT_POSIX_ACL, MOPT_SET},
  1238. {Opt_noacl, EXT4_MOUNT_POSIX_ACL, MOPT_CLEAR},
  1239. #else
  1240. {Opt_acl, 0, MOPT_NOSUPPORT},
  1241. {Opt_noacl, 0, MOPT_NOSUPPORT},
  1242. #endif
  1243. {Opt_nouid32, EXT4_MOUNT_NO_UID32, MOPT_SET},
  1244. {Opt_debug, EXT4_MOUNT_DEBUG, MOPT_SET},
  1245. {Opt_quota, EXT4_MOUNT_QUOTA | EXT4_MOUNT_USRQUOTA, MOPT_SET | MOPT_Q},
  1246. {Opt_usrquota, EXT4_MOUNT_QUOTA | EXT4_MOUNT_USRQUOTA,
  1247. MOPT_SET | MOPT_Q},
  1248. {Opt_grpquota, EXT4_MOUNT_QUOTA | EXT4_MOUNT_GRPQUOTA,
  1249. MOPT_SET | MOPT_Q},
  1250. {Opt_noquota, (EXT4_MOUNT_QUOTA | EXT4_MOUNT_USRQUOTA |
  1251. EXT4_MOUNT_GRPQUOTA), MOPT_CLEAR | MOPT_Q},
  1252. {Opt_usrjquota, 0, MOPT_Q},
  1253. {Opt_grpjquota, 0, MOPT_Q},
  1254. {Opt_offusrjquota, 0, MOPT_Q},
  1255. {Opt_offgrpjquota, 0, MOPT_Q},
  1256. {Opt_jqfmt_vfsold, QFMT_VFS_OLD, MOPT_QFMT},
  1257. {Opt_jqfmt_vfsv0, QFMT_VFS_V0, MOPT_QFMT},
  1258. {Opt_jqfmt_vfsv1, QFMT_VFS_V1, MOPT_QFMT},
  1259. {Opt_max_dir_size_kb, 0, MOPT_GTE0},
  1260. {Opt_test_dummy_encryption, 0, MOPT_GTE0},
  1261. {Opt_err, 0, 0}
  1262. };
  1263. static int handle_mount_opt(struct super_block *sb, char *opt, int token,
  1264. substring_t *args, unsigned long *journal_devnum,
  1265. unsigned int *journal_ioprio, int is_remount)
  1266. {
  1267. struct ext4_sb_info *sbi = EXT4_SB(sb);
  1268. const struct mount_opts *m;
  1269. kuid_t uid;
  1270. kgid_t gid;
  1271. int arg = 0;
  1272. #ifdef CONFIG_QUOTA
  1273. if (token == Opt_usrjquota)
  1274. return set_qf_name(sb, USRQUOTA, &args[0]);
  1275. else if (token == Opt_grpjquota)
  1276. return set_qf_name(sb, GRPQUOTA, &args[0]);
  1277. else if (token == Opt_offusrjquota)
  1278. return clear_qf_name(sb, USRQUOTA);
  1279. else if (token == Opt_offgrpjquota)
  1280. return clear_qf_name(sb, GRPQUOTA);
  1281. #endif
  1282. switch (token) {
  1283. case Opt_noacl:
  1284. case Opt_nouser_xattr:
  1285. ext4_msg(sb, KERN_WARNING, deprecated_msg, opt, "3.5");
  1286. break;
  1287. case Opt_sb:
  1288. return 1; /* handled by get_sb_block() */
  1289. case Opt_removed:
  1290. ext4_msg(sb, KERN_WARNING, "Ignoring removed %s option", opt);
  1291. return 1;
  1292. case Opt_abort:
  1293. sbi->s_mount_flags |= EXT4_MF_FS_ABORTED;
  1294. return 1;
  1295. case Opt_i_version:
  1296. sb->s_flags |= MS_I_VERSION;
  1297. return 1;
  1298. case Opt_lazytime:
  1299. sb->s_flags |= MS_LAZYTIME;
  1300. return 1;
  1301. case Opt_nolazytime:
  1302. sb->s_flags &= ~MS_LAZYTIME;
  1303. return 1;
  1304. }
  1305. for (m = ext4_mount_opts; m->token != Opt_err; m++)
  1306. if (token == m->token)
  1307. break;
  1308. if (m->token == Opt_err) {
  1309. ext4_msg(sb, KERN_ERR, "Unrecognized mount option \"%s\" "
  1310. "or missing value", opt);
  1311. return -1;
  1312. }
  1313. if ((m->flags & MOPT_NO_EXT2) && IS_EXT2_SB(sb)) {
  1314. ext4_msg(sb, KERN_ERR,
  1315. "Mount option \"%s\" incompatible with ext2", opt);
  1316. return -1;
  1317. }
  1318. if ((m->flags & MOPT_NO_EXT3) && IS_EXT3_SB(sb)) {
  1319. ext4_msg(sb, KERN_ERR,
  1320. "Mount option \"%s\" incompatible with ext3", opt);
  1321. return -1;
  1322. }
  1323. if (args->from && !(m->flags & MOPT_STRING) && match_int(args, &arg))
  1324. return -1;
  1325. if (args->from && (m->flags & MOPT_GTE0) && (arg < 0))
  1326. return -1;
  1327. if (m->flags & MOPT_EXPLICIT)
  1328. set_opt2(sb, EXPLICIT_DELALLOC);
  1329. if (m->flags & MOPT_CLEAR_ERR)
  1330. clear_opt(sb, ERRORS_MASK);
  1331. if (token == Opt_noquota && sb_any_quota_loaded(sb)) {
  1332. ext4_msg(sb, KERN_ERR, "Cannot change quota "
  1333. "options when quota turned on");
  1334. return -1;
  1335. }
  1336. if (m->flags & MOPT_NOSUPPORT) {
  1337. ext4_msg(sb, KERN_ERR, "%s option not supported", opt);
  1338. } else if (token == Opt_commit) {
  1339. if (arg == 0)
  1340. arg = JBD2_DEFAULT_MAX_COMMIT_AGE;
  1341. sbi->s_commit_interval = HZ * arg;
  1342. } else if (token == Opt_max_batch_time) {
  1343. sbi->s_max_batch_time = arg;
  1344. } else if (token == Opt_min_batch_time) {
  1345. sbi->s_min_batch_time = arg;
  1346. } else if (token == Opt_inode_readahead_blks) {
  1347. if (arg && (arg > (1 << 30) || !is_power_of_2(arg))) {
  1348. ext4_msg(sb, KERN_ERR,
  1349. "EXT4-fs: inode_readahead_blks must be "
  1350. "0 or a power of 2 smaller than 2^31");
  1351. return -1;
  1352. }
  1353. sbi->s_inode_readahead_blks = arg;
  1354. } else if (token == Opt_init_itable) {
  1355. set_opt(sb, INIT_INODE_TABLE);
  1356. if (!args->from)
  1357. arg = EXT4_DEF_LI_WAIT_MULT;
  1358. sbi->s_li_wait_mult = arg;
  1359. } else if (token == Opt_max_dir_size_kb) {
  1360. sbi->s_max_dir_size_kb = arg;
  1361. } else if (token == Opt_stripe) {
  1362. sbi->s_stripe = arg;
  1363. } else if (token == Opt_resuid) {
  1364. uid = make_kuid(current_user_ns(), arg);
  1365. if (!uid_valid(uid)) {
  1366. ext4_msg(sb, KERN_ERR, "Invalid uid value %d", arg);
  1367. return -1;
  1368. }
  1369. sbi->s_resuid = uid;
  1370. } else if (token == Opt_resgid) {
  1371. gid = make_kgid(current_user_ns(), arg);
  1372. if (!gid_valid(gid)) {
  1373. ext4_msg(sb, KERN_ERR, "Invalid gid value %d", arg);
  1374. return -1;
  1375. }
  1376. sbi->s_resgid = gid;
  1377. } else if (token == Opt_journal_dev) {
  1378. if (is_remount) {
  1379. ext4_msg(sb, KERN_ERR,
  1380. "Cannot specify journal on remount");
  1381. return -1;
  1382. }
  1383. *journal_devnum = arg;
  1384. } else if (token == Opt_journal_path) {
  1385. char *journal_path;
  1386. struct inode *journal_inode;
  1387. struct path path;
  1388. int error;
  1389. if (is_remount) {
  1390. ext4_msg(sb, KERN_ERR,
  1391. "Cannot specify journal on remount");
  1392. return -1;
  1393. }
  1394. journal_path = match_strdup(&args[0]);
  1395. if (!journal_path) {
  1396. ext4_msg(sb, KERN_ERR, "error: could not dup "
  1397. "journal device string");
  1398. return -1;
  1399. }
  1400. error = kern_path(journal_path, LOOKUP_FOLLOW, &path);
  1401. if (error) {
  1402. ext4_msg(sb, KERN_ERR, "error: could not find "
  1403. "journal device path: error %d", error);
  1404. kfree(journal_path);
  1405. return -1;
  1406. }
  1407. journal_inode = d_inode(path.dentry);
  1408. if (!S_ISBLK(journal_inode->i_mode)) {
  1409. ext4_msg(sb, KERN_ERR, "error: journal path %s "
  1410. "is not a block device", journal_path);
  1411. path_put(&path);
  1412. kfree(journal_path);
  1413. return -1;
  1414. }
  1415. *journal_devnum = new_encode_dev(journal_inode->i_rdev);
  1416. path_put(&path);
  1417. kfree(journal_path);
  1418. } else if (token == Opt_journal_ioprio) {
  1419. if (arg > 7) {
  1420. ext4_msg(sb, KERN_ERR, "Invalid journal IO priority"
  1421. " (must be 0-7)");
  1422. return -1;
  1423. }
  1424. *journal_ioprio =
  1425. IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, arg);
  1426. } else if (token == Opt_test_dummy_encryption) {
  1427. #ifdef CONFIG_EXT4_FS_ENCRYPTION
  1428. sbi->s_mount_flags |= EXT4_MF_TEST_DUMMY_ENCRYPTION;
  1429. ext4_msg(sb, KERN_WARNING,
  1430. "Test dummy encryption mode enabled");
  1431. #else
  1432. ext4_msg(sb, KERN_WARNING,
  1433. "Test dummy encryption mount option ignored");
  1434. #endif
  1435. } else if (m->flags & MOPT_DATAJ) {
  1436. if (is_remount) {
  1437. if (!sbi->s_journal)
  1438. ext4_msg(sb, KERN_WARNING, "Remounting file system with no journal so ignoring journalled data option");
  1439. else if (test_opt(sb, DATA_FLAGS) != m->mount_opt) {
  1440. ext4_msg(sb, KERN_ERR,
  1441. "Cannot change data mode on remount");
  1442. return -1;
  1443. }
  1444. } else {
  1445. clear_opt(sb, DATA_FLAGS);
  1446. sbi->s_mount_opt |= m->mount_opt;
  1447. }
  1448. #ifdef CONFIG_QUOTA
  1449. } else if (m->flags & MOPT_QFMT) {
  1450. if (sb_any_quota_loaded(sb) &&
  1451. sbi->s_jquota_fmt != m->mount_opt) {
  1452. ext4_msg(sb, KERN_ERR, "Cannot change journaled "
  1453. "quota options when quota turned on");
  1454. return -1;
  1455. }
  1456. if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
  1457. EXT4_FEATURE_RO_COMPAT_QUOTA)) {
  1458. ext4_msg(sb, KERN_ERR,
  1459. "Cannot set journaled quota options "
  1460. "when QUOTA feature is enabled");
  1461. return -1;
  1462. }
  1463. sbi->s_jquota_fmt = m->mount_opt;
  1464. #endif
  1465. #ifndef CONFIG_FS_DAX
  1466. } else if (token == Opt_dax) {
  1467. ext4_msg(sb, KERN_INFO, "dax option not supported");
  1468. return -1;
  1469. #endif
  1470. } else {
  1471. if (!args->from)
  1472. arg = 1;
  1473. if (m->flags & MOPT_CLEAR)
  1474. arg = !arg;
  1475. else if (unlikely(!(m->flags & MOPT_SET))) {
  1476. ext4_msg(sb, KERN_WARNING,
  1477. "buggy handling of option %s", opt);
  1478. WARN_ON(1);
  1479. return -1;
  1480. }
  1481. if (arg != 0)
  1482. sbi->s_mount_opt |= m->mount_opt;
  1483. else
  1484. sbi->s_mount_opt &= ~m->mount_opt;
  1485. }
  1486. return 1;
  1487. }
  1488. static int parse_options(char *options, struct super_block *sb,
  1489. unsigned long *journal_devnum,
  1490. unsigned int *journal_ioprio,
  1491. int is_remount)
  1492. {
  1493. struct ext4_sb_info *sbi = EXT4_SB(sb);
  1494. char *p;
  1495. substring_t args[MAX_OPT_ARGS];
  1496. int token;
  1497. if (!options)
  1498. return 1;
  1499. while ((p = strsep(&options, ",")) != NULL) {
  1500. if (!*p)
  1501. continue;
  1502. /*
  1503. * Initialize args struct so we know whether arg was
  1504. * found; some options take optional arguments.
  1505. */
  1506. args[0].to = args[0].from = NULL;
  1507. token = match_token(p, tokens, args);
  1508. if (handle_mount_opt(sb, p, token, args, journal_devnum,
  1509. journal_ioprio, is_remount) < 0)
  1510. return 0;
  1511. }
  1512. #ifdef CONFIG_QUOTA
  1513. if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_QUOTA) &&
  1514. (test_opt(sb, USRQUOTA) || test_opt(sb, GRPQUOTA))) {
  1515. ext4_msg(sb, KERN_ERR, "Cannot set quota options when QUOTA "
  1516. "feature is enabled");
  1517. return 0;
  1518. }
  1519. if (sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) {
  1520. if (test_opt(sb, USRQUOTA) && sbi->s_qf_names[USRQUOTA])
  1521. clear_opt(sb, USRQUOTA);
  1522. if (test_opt(sb, GRPQUOTA) && sbi->s_qf_names[GRPQUOTA])
  1523. clear_opt(sb, GRPQUOTA);
  1524. if (test_opt(sb, GRPQUOTA) || test_opt(sb, USRQUOTA)) {
  1525. ext4_msg(sb, KERN_ERR, "old and new quota "
  1526. "format mixing");
  1527. return 0;
  1528. }
  1529. if (!sbi->s_jquota_fmt) {
  1530. ext4_msg(sb, KERN_ERR, "journaled quota format "
  1531. "not specified");
  1532. return 0;
  1533. }
  1534. }
  1535. #endif
  1536. if (test_opt(sb, DIOREAD_NOLOCK)) {
  1537. int blocksize =
  1538. BLOCK_SIZE << le32_to_cpu(sbi->s_es->s_log_block_size);
  1539. if (blocksize < PAGE_CACHE_SIZE) {
  1540. ext4_msg(sb, KERN_ERR, "can't mount with "
  1541. "dioread_nolock if block size != PAGE_SIZE");
  1542. return 0;
  1543. }
  1544. }
  1545. if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA &&
  1546. test_opt(sb, JOURNAL_ASYNC_COMMIT)) {
  1547. ext4_msg(sb, KERN_ERR, "can't mount with journal_async_commit "
  1548. "in data=ordered mode");
  1549. return 0;
  1550. }
  1551. return 1;
  1552. }
  1553. static inline void ext4_show_quota_options(struct seq_file *seq,
  1554. struct super_block *sb)
  1555. {
  1556. #if defined(CONFIG_QUOTA)
  1557. struct ext4_sb_info *sbi = EXT4_SB(sb);
  1558. if (sbi->s_jquota_fmt) {
  1559. char *fmtname = "";
  1560. switch (sbi->s_jquota_fmt) {
  1561. case QFMT_VFS_OLD:
  1562. fmtname = "vfsold";
  1563. break;
  1564. case QFMT_VFS_V0:
  1565. fmtname = "vfsv0";
  1566. break;
  1567. case QFMT_VFS_V1:
  1568. fmtname = "vfsv1";
  1569. break;
  1570. }
  1571. seq_printf(seq, ",jqfmt=%s", fmtname);
  1572. }
  1573. if (sbi->s_qf_names[USRQUOTA])
  1574. seq_printf(seq, ",usrjquota=%s", sbi->s_qf_names[USRQUOTA]);
  1575. if (sbi->s_qf_names[GRPQUOTA])
  1576. seq_printf(seq, ",grpjquota=%s", sbi->s_qf_names[GRPQUOTA]);
  1577. #endif
  1578. }
  1579. static const char *token2str(int token)
  1580. {
  1581. const struct match_token *t;
  1582. for (t = tokens; t->token != Opt_err; t++)
  1583. if (t->token == token && !strchr(t->pattern, '='))
  1584. break;
  1585. return t->pattern;
  1586. }
  1587. /*
  1588. * Show an option if
  1589. * - it's set to a non-default value OR
  1590. * - if the per-sb default is different from the global default
  1591. */
  1592. static int _ext4_show_options(struct seq_file *seq, struct super_block *sb,
  1593. int nodefs)
  1594. {
  1595. struct ext4_sb_info *sbi = EXT4_SB(sb);
  1596. struct ext4_super_block *es = sbi->s_es;
  1597. int def_errors, def_mount_opt = nodefs ? 0 : sbi->s_def_mount_opt;
  1598. const struct mount_opts *m;
  1599. char sep = nodefs ? '\n' : ',';
  1600. #define SEQ_OPTS_PUTS(str) seq_printf(seq, "%c" str, sep)
  1601. #define SEQ_OPTS_PRINT(str, arg) seq_printf(seq, "%c" str, sep, arg)
  1602. if (sbi->s_sb_block != 1)
  1603. SEQ_OPTS_PRINT("sb=%llu", sbi->s_sb_block);
  1604. for (m = ext4_mount_opts; m->token != Opt_err; m++) {
  1605. int want_set = m->flags & MOPT_SET;
  1606. if (((m->flags & (MOPT_SET|MOPT_CLEAR)) == 0) ||
  1607. (m->flags & MOPT_CLEAR_ERR))
  1608. continue;
  1609. if (!(m->mount_opt & (sbi->s_mount_opt ^ def_mount_opt)))
  1610. continue; /* skip if same as the default */
  1611. if ((want_set &&
  1612. (sbi->s_mount_opt & m->mount_opt) != m->mount_opt) ||
  1613. (!want_set && (sbi->s_mount_opt & m->mount_opt)))
  1614. continue; /* select Opt_noFoo vs Opt_Foo */
  1615. SEQ_OPTS_PRINT("%s", token2str(m->token));
  1616. }
  1617. if (nodefs || !uid_eq(sbi->s_resuid, make_kuid(&init_user_ns, EXT4_DEF_RESUID)) ||
  1618. le16_to_cpu(es->s_def_resuid) != EXT4_DEF_RESUID)
  1619. SEQ_OPTS_PRINT("resuid=%u",
  1620. from_kuid_munged(&init_user_ns, sbi->s_resuid));
  1621. if (nodefs || !gid_eq(sbi->s_resgid, make_kgid(&init_user_ns, EXT4_DEF_RESGID)) ||
  1622. le16_to_cpu(es->s_def_resgid) != EXT4_DEF_RESGID)
  1623. SEQ_OPTS_PRINT("resgid=%u",
  1624. from_kgid_munged(&init_user_ns, sbi->s_resgid));
  1625. def_errors = nodefs ? -1 : le16_to_cpu(es->s_errors);
  1626. if (test_opt(sb, ERRORS_RO) && def_errors != EXT4_ERRORS_RO)
  1627. SEQ_OPTS_PUTS("errors=remount-ro");
  1628. if (test_opt(sb, ERRORS_CONT) && def_errors != EXT4_ERRORS_CONTINUE)
  1629. SEQ_OPTS_PUTS("errors=continue");
  1630. if (test_opt(sb, ERRORS_PANIC) && def_errors != EXT4_ERRORS_PANIC)
  1631. SEQ_OPTS_PUTS("errors=panic");
  1632. if (nodefs || sbi->s_commit_interval != JBD2_DEFAULT_MAX_COMMIT_AGE*HZ)
  1633. SEQ_OPTS_PRINT("commit=%lu", sbi->s_commit_interval / HZ);
  1634. if (nodefs || sbi->s_min_batch_time != EXT4_DEF_MIN_BATCH_TIME)
  1635. SEQ_OPTS_PRINT("min_batch_time=%u", sbi->s_min_batch_time);
  1636. if (nodefs || sbi->s_max_batch_time != EXT4_DEF_MAX_BATCH_TIME)
  1637. SEQ_OPTS_PRINT("max_batch_time=%u", sbi->s_max_batch_time);
  1638. if (sb->s_flags & MS_I_VERSION)
  1639. SEQ_OPTS_PUTS("i_version");
  1640. if (nodefs || sbi->s_stripe)
  1641. SEQ_OPTS_PRINT("stripe=%lu", sbi->s_stripe);
  1642. if (EXT4_MOUNT_DATA_FLAGS & (sbi->s_mount_opt ^ def_mount_opt)) {
  1643. if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)
  1644. SEQ_OPTS_PUTS("data=journal");
  1645. else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA)
  1646. SEQ_OPTS_PUTS("data=ordered");
  1647. else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)
  1648. SEQ_OPTS_PUTS("data=writeback");
  1649. }
  1650. if (nodefs ||
  1651. sbi->s_inode_readahead_blks != EXT4_DEF_INODE_READAHEAD_BLKS)
  1652. SEQ_OPTS_PRINT("inode_readahead_blks=%u",
  1653. sbi->s_inode_readahead_blks);
  1654. if (nodefs || (test_opt(sb, INIT_INODE_TABLE) &&
  1655. (sbi->s_li_wait_mult != EXT4_DEF_LI_WAIT_MULT)))
  1656. SEQ_OPTS_PRINT("init_itable=%u", sbi->s_li_wait_mult);
  1657. if (nodefs || sbi->s_max_dir_size_kb)
  1658. SEQ_OPTS_PRINT("max_dir_size_kb=%u", sbi->s_max_dir_size_kb);
  1659. ext4_show_quota_options(seq, sb);
  1660. return 0;
  1661. }
  1662. static int ext4_show_options(struct seq_file *seq, struct dentry *root)
  1663. {
  1664. return _ext4_show_options(seq, root->d_sb, 0);
  1665. }
  1666. static int options_seq_show(struct seq_file *seq, void *offset)
  1667. {
  1668. struct super_block *sb = seq->private;
  1669. int rc;
  1670. seq_puts(seq, (sb->s_flags & MS_RDONLY) ? "ro" : "rw");
  1671. rc = _ext4_show_options(seq, sb, 1);
  1672. seq_puts(seq, "\n");
  1673. return rc;
  1674. }
  1675. static int options_open_fs(struct inode *inode, struct file *file)
  1676. {
  1677. return single_open(file, options_seq_show, PDE_DATA(inode));
  1678. }
  1679. static const struct file_operations ext4_seq_options_fops = {
  1680. .owner = THIS_MODULE,
  1681. .open = options_open_fs,
  1682. .read = seq_read,
  1683. .llseek = seq_lseek,
  1684. .release = single_release,
  1685. };
  1686. static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
  1687. int read_only)
  1688. {
  1689. struct ext4_sb_info *sbi = EXT4_SB(sb);
  1690. int res = 0;
  1691. if (le32_to_cpu(es->s_rev_level) > EXT4_MAX_SUPP_REV) {
  1692. ext4_msg(sb, KERN_ERR, "revision level too high, "
  1693. "forcing read-only mode");
  1694. res = MS_RDONLY;
  1695. }
  1696. if (read_only)
  1697. goto done;
  1698. if (!(sbi->s_mount_state & EXT4_VALID_FS))
  1699. ext4_msg(sb, KERN_WARNING, "warning: mounting unchecked fs, "
  1700. "running e2fsck is recommended");
  1701. else if (sbi->s_mount_state & EXT4_ERROR_FS)
  1702. ext4_msg(sb, KERN_WARNING,
  1703. "warning: mounting fs with errors, "
  1704. "running e2fsck is recommended");
  1705. else if ((__s16) le16_to_cpu(es->s_max_mnt_count) > 0 &&
  1706. le16_to_cpu(es->s_mnt_count) >=
  1707. (unsigned short) (__s16) le16_to_cpu(es->s_max_mnt_count))
  1708. ext4_msg(sb, KERN_WARNING,
  1709. "warning: maximal mount count reached, "
  1710. "running e2fsck is recommended");
  1711. else if (le32_to_cpu(es->s_checkinterval) &&
  1712. (le32_to_cpu(es->s_lastcheck) +
  1713. le32_to_cpu(es->s_checkinterval) <= get_seconds()))
  1714. ext4_msg(sb, KERN_WARNING,
  1715. "warning: checktime reached, "
  1716. "running e2fsck is recommended");
  1717. if (!sbi->s_journal)
  1718. es->s_state &= cpu_to_le16(~EXT4_VALID_FS);
  1719. if (!(__s16) le16_to_cpu(es->s_max_mnt_count))
  1720. es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT);
  1721. le16_add_cpu(&es->s_mnt_count, 1);
  1722. es->s_mtime = cpu_to_le32(get_seconds());
  1723. ext4_update_dynamic_rev(sb);
  1724. if (sbi->s_journal)
  1725. EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
  1726. ext4_commit_super(sb, 1);
  1727. done:
  1728. if (test_opt(sb, DEBUG))
  1729. printk(KERN_INFO "[EXT4 FS bs=%lu, gc=%u, "
  1730. "bpg=%lu, ipg=%lu, mo=%04x, mo2=%04x]\n",
  1731. sb->s_blocksize,
  1732. sbi->s_groups_count,
  1733. EXT4_BLOCKS_PER_GROUP(sb),
  1734. EXT4_INODES_PER_GROUP(sb),
  1735. sbi->s_mount_opt, sbi->s_mount_opt2);
  1736. cleancache_init_fs(sb);
  1737. return res;
  1738. }
  1739. int ext4_alloc_flex_bg_array(struct super_block *sb, ext4_group_t ngroup)
  1740. {
  1741. struct ext4_sb_info *sbi = EXT4_SB(sb);
  1742. struct flex_groups *new_groups;
  1743. int size;
  1744. if (!sbi->s_log_groups_per_flex)
  1745. return 0;
  1746. size = ext4_flex_group(sbi, ngroup - 1) + 1;
  1747. if (size <= sbi->s_flex_groups_allocated)
  1748. return 0;
  1749. size = roundup_pow_of_two(size * sizeof(struct flex_groups));
  1750. new_groups = ext4_kvzalloc(size, GFP_KERNEL);
  1751. if (!new_groups) {
  1752. ext4_msg(sb, KERN_ERR, "not enough memory for %d flex groups",
  1753. size / (int) sizeof(struct flex_groups));
  1754. return -ENOMEM;
  1755. }
  1756. if (sbi->s_flex_groups) {
  1757. memcpy(new_groups, sbi->s_flex_groups,
  1758. (sbi->s_flex_groups_allocated *
  1759. sizeof(struct flex_groups)));
  1760. kvfree(sbi->s_flex_groups);
  1761. }
  1762. sbi->s_flex_groups = new_groups;
  1763. sbi->s_flex_groups_allocated = size / sizeof(struct flex_groups);
  1764. return 0;
  1765. }
  1766. static int ext4_fill_flex_info(struct super_block *sb)
  1767. {
  1768. struct ext4_sb_info *sbi = EXT4_SB(sb);
  1769. struct ext4_group_desc *gdp = NULL;
  1770. ext4_group_t flex_group;
  1771. int i, err;
  1772. sbi->s_log_groups_per_flex = sbi->s_es->s_log_groups_per_flex;
  1773. if (sbi->s_log_groups_per_flex < 1 || sbi->s_log_groups_per_flex > 31) {
  1774. sbi->s_log_groups_per_flex = 0;
  1775. return 1;
  1776. }
  1777. err = ext4_alloc_flex_bg_array(sb, sbi->s_groups_count);
  1778. if (err)
  1779. goto failed;
  1780. for (i = 0; i < sbi->s_groups_count; i++) {
  1781. gdp = ext4_get_group_desc(sb, i, NULL);
  1782. flex_group = ext4_flex_group(sbi, i);
  1783. atomic_add(ext4_free_inodes_count(sb, gdp),
  1784. &sbi->s_flex_groups[flex_group].free_inodes);
  1785. atomic64_add(ext4_free_group_clusters(sb, gdp),
  1786. &sbi->s_flex_groups[flex_group].free_clusters);
  1787. atomic_add(ext4_used_dirs_count(sb, gdp),
  1788. &sbi->s_flex_groups[flex_group].used_dirs);
  1789. }
  1790. return 1;
  1791. failed:
  1792. return 0;
  1793. }
  1794. static __le16 ext4_group_desc_csum(struct ext4_sb_info *sbi, __u32 block_group,
  1795. struct ext4_group_desc *gdp)
  1796. {
  1797. int offset;
  1798. __u16 crc = 0;
  1799. __le32 le_group = cpu_to_le32(block_group);
  1800. if (ext4_has_metadata_csum(sbi->s_sb)) {
  1801. /* Use new metadata_csum algorithm */
  1802. __le16 save_csum;
  1803. __u32 csum32;
  1804. save_csum = gdp->bg_checksum;
  1805. gdp->bg_checksum = 0;
  1806. csum32 = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)&le_group,
  1807. sizeof(le_group));
  1808. csum32 = ext4_chksum(sbi, csum32, (__u8 *)gdp,
  1809. sbi->s_desc_size);
  1810. gdp->bg_checksum = save_csum;
  1811. crc = csum32 & 0xFFFF;
  1812. goto out;
  1813. }
  1814. /* old crc16 code */
  1815. if (!(sbi->s_es->s_feature_ro_compat &
  1816. cpu_to_le32(EXT4_FEATURE_RO_COMPAT_GDT_CSUM)))
  1817. return 0;
  1818. offset = offsetof(struct ext4_group_desc, bg_checksum);
  1819. crc = crc16(~0, sbi->s_es->s_uuid, sizeof(sbi->s_es->s_uuid));
  1820. crc = crc16(crc, (__u8 *)&le_group, sizeof(le_group));
  1821. crc = crc16(crc, (__u8 *)gdp, offset);
  1822. offset += sizeof(gdp->bg_checksum); /* skip checksum */
  1823. /* for checksum of struct ext4_group_desc do the rest...*/
  1824. if ((sbi->s_es->s_feature_incompat &
  1825. cpu_to_le32(EXT4_FEATURE_INCOMPAT_64BIT)) &&
  1826. offset < le16_to_cpu(sbi->s_es->s_desc_size))
  1827. crc = crc16(crc, (__u8 *)gdp + offset,
  1828. le16_to_cpu(sbi->s_es->s_desc_size) -
  1829. offset);
  1830. out:
  1831. return cpu_to_le16(crc);
  1832. }
  1833. int ext4_group_desc_csum_verify(struct super_block *sb, __u32 block_group,
  1834. struct ext4_group_desc *gdp)
  1835. {
  1836. if (ext4_has_group_desc_csum(sb) &&
  1837. (gdp->bg_checksum != ext4_group_desc_csum(EXT4_SB(sb),
  1838. block_group, gdp)))
  1839. return 0;
  1840. return 1;
  1841. }
  1842. void ext4_group_desc_csum_set(struct super_block *sb, __u32 block_group,
  1843. struct ext4_group_desc *gdp)
  1844. {
  1845. if (!ext4_has_group_desc_csum(sb))
  1846. return;
  1847. gdp->bg_checksum = ext4_group_desc_csum(EXT4_SB(sb), block_group, gdp);
  1848. }
  1849. /* Called at mount-time, super-block is locked */
  1850. static int ext4_check_descriptors(struct super_block *sb,
  1851. ext4_group_t *first_not_zeroed)
  1852. {
  1853. struct ext4_sb_info *sbi = EXT4_SB(sb);
  1854. ext4_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block);
  1855. ext4_fsblk_t last_block;
  1856. ext4_fsblk_t block_bitmap;
  1857. ext4_fsblk_t inode_bitmap;
  1858. ext4_fsblk_t inode_table;
  1859. int flexbg_flag = 0;
  1860. ext4_group_t i, grp = sbi->s_groups_count;
  1861. if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG))
  1862. flexbg_flag = 1;
  1863. ext4_debug("Checking group descriptors");
  1864. for (i = 0; i < sbi->s_groups_count; i++) {
  1865. struct ext4_group_desc *gdp = ext4_get_group_desc(sb, i, NULL);
  1866. if (i == sbi->s_groups_count - 1 || flexbg_flag)
  1867. last_block = ext4_blocks_count(sbi->s_es) - 1;
  1868. else
  1869. last_block = first_block +
  1870. (EXT4_BLOCKS_PER_GROUP(sb) - 1);
  1871. if ((grp == sbi->s_groups_count) &&
  1872. !(gdp->bg_flags & cpu_to_le16(EXT4_BG_INODE_ZEROED)))
  1873. grp = i;
  1874. block_bitmap = ext4_block_bitmap(sb, gdp);
  1875. if (block_bitmap < first_block || block_bitmap > last_block) {
  1876. ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
  1877. "Block bitmap for group %u not in group "
  1878. "(block %llu)!", i, block_bitmap);
  1879. return 0;
  1880. }
  1881. inode_bitmap = ext4_inode_bitmap(sb, gdp);
  1882. if (inode_bitmap < first_block || inode_bitmap > last_block) {
  1883. ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
  1884. "Inode bitmap for group %u not in group "
  1885. "(block %llu)!", i, inode_bitmap);
  1886. return 0;
  1887. }
  1888. inode_table = ext4_inode_table(sb, gdp);
  1889. if (inode_table < first_block ||
  1890. inode_table + sbi->s_itb_per_group - 1 > last_block) {
  1891. ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
  1892. "Inode table for group %u not in group "
  1893. "(block %llu)!", i, inode_table);
  1894. return 0;
  1895. }
  1896. ext4_lock_group(sb, i);
  1897. if (!ext4_group_desc_csum_verify(sb, i, gdp)) {
  1898. ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
  1899. "Checksum for group %u failed (%u!=%u)",
  1900. i, le16_to_cpu(ext4_group_desc_csum(sbi, i,
  1901. gdp)), le16_to_cpu(gdp->bg_checksum));
  1902. if (!(sb->s_flags & MS_RDONLY)) {
  1903. ext4_unlock_group(sb, i);
  1904. return 0;
  1905. }
  1906. }
  1907. ext4_unlock_group(sb, i);
  1908. if (!flexbg_flag)
  1909. first_block += EXT4_BLOCKS_PER_GROUP(sb);
  1910. }
  1911. if (NULL != first_not_zeroed)
  1912. *first_not_zeroed = grp;
  1913. return 1;
  1914. }
  1915. /* ext4_orphan_cleanup() walks a singly-linked list of inodes (starting at
  1916. * the superblock) which were deleted from all directories, but held open by
  1917. * a process at the time of a crash. We walk the list and try to delete these
  1918. * inodes at recovery time (only with a read-write filesystem).
  1919. *
  1920. * In order to keep the orphan inode chain consistent during traversal (in
  1921. * case of crash during recovery), we link each inode into the superblock
  1922. * orphan list_head and handle it the same way as an inode deletion during
  1923. * normal operation (which journals the operations for us).
  1924. *
  1925. * We only do an iget() and an iput() on each inode, which is very safe if we
  1926. * accidentally point at an in-use or already deleted inode. The worst that
  1927. * can happen in this case is that we get a "bit already cleared" message from
  1928. * ext4_free_inode(). The only reason we would point at a wrong inode is if
  1929. * e2fsck was run on this filesystem, and it must have already done the orphan
  1930. * inode cleanup for us, so we can safely abort without any further action.
  1931. */
  1932. static void ext4_orphan_cleanup(struct super_block *sb,
  1933. struct ext4_super_block *es)
  1934. {
  1935. unsigned int s_flags = sb->s_flags;
  1936. int nr_orphans = 0, nr_truncates = 0;
  1937. #ifdef CONFIG_QUOTA
  1938. int i;
  1939. #endif
  1940. if (!es->s_last_orphan) {
  1941. jbd_debug(4, "no orphan inodes to clean up\n");
  1942. return;
  1943. }
  1944. if (bdev_read_only(sb->s_bdev)) {
  1945. ext4_msg(sb, KERN_ERR, "write access "
  1946. "unavailable, skipping orphan cleanup");
  1947. return;
  1948. }
  1949. /* Check if feature set would not allow a r/w mount */
  1950. if (!ext4_feature_set_ok(sb, 0)) {
  1951. ext4_msg(sb, KERN_INFO, "Skipping orphan cleanup due to "
  1952. "unknown ROCOMPAT features");
  1953. return;
  1954. }
  1955. if (EXT4_SB(sb)->s_mount_state & EXT4_ERROR_FS) {
  1956. /* don't clear list on RO mount w/ errors */
  1957. if (es->s_last_orphan && !(s_flags & MS_RDONLY)) {
  1958. ext4_msg(sb, KERN_INFO, "Errors on filesystem, "
  1959. "clearing orphan list.\n");
  1960. es->s_last_orphan = 0;
  1961. }
  1962. jbd_debug(1, "Skipping orphan recovery on fs with errors.\n");
  1963. return;
  1964. }
  1965. if (s_flags & MS_RDONLY) {
  1966. ext4_msg(sb, KERN_INFO, "orphan cleanup on readonly fs");
  1967. sb->s_flags &= ~MS_RDONLY;
  1968. }
  1969. #ifdef CONFIG_QUOTA
  1970. /* Needed for iput() to work correctly and not trash data */
  1971. sb->s_flags |= MS_ACTIVE;
  1972. /* Turn on quotas so that they are updated correctly */
  1973. for (i = 0; i < EXT4_MAXQUOTAS; i++) {
  1974. if (EXT4_SB(sb)->s_qf_names[i]) {
  1975. int ret = ext4_quota_on_mount(sb, i);
  1976. if (ret < 0)
  1977. ext4_msg(sb, KERN_ERR,
  1978. "Cannot turn on journaled "
  1979. "quota: error %d", ret);
  1980. }
  1981. }
  1982. #endif
  1983. while (es->s_last_orphan) {
  1984. struct inode *inode;
  1985. inode = ext4_orphan_get(sb, le32_to_cpu(es->s_last_orphan));
  1986. if (IS_ERR(inode)) {
  1987. es->s_last_orphan = 0;
  1988. break;
  1989. }
  1990. list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan);
  1991. dquot_initialize(inode);
  1992. if (inode->i_nlink) {
  1993. if (test_opt(sb, DEBUG))
  1994. ext4_msg(sb, KERN_DEBUG,
  1995. "%s: truncating inode %lu to %lld bytes",
  1996. __func__, inode->i_ino, inode->i_size);
  1997. jbd_debug(2, "truncating inode %lu to %lld bytes\n",
  1998. inode->i_ino, inode->i_size);
  1999. mutex_lock(&inode->i_mutex);
  2000. truncate_inode_pages(inode->i_mapping, inode->i_size);
  2001. ext4_truncate(inode);
  2002. mutex_unlock(&inode->i_mutex);
  2003. nr_truncates++;
  2004. } else {
  2005. if (test_opt(sb, DEBUG))
  2006. ext4_msg(sb, KERN_DEBUG,
  2007. "%s: deleting unreferenced inode %lu",
  2008. __func__, inode->i_ino);
  2009. jbd_debug(2, "deleting unreferenced inode %lu\n",
  2010. inode->i_ino);
  2011. nr_orphans++;
  2012. }
  2013. iput(inode); /* The delete magic happens here! */
  2014. }
  2015. #define PLURAL(x) (x), ((x) == 1) ? "" : "s"
  2016. if (nr_orphans)
  2017. ext4_msg(sb, KERN_INFO, "%d orphan inode%s deleted",
  2018. PLURAL(nr_orphans));
  2019. if (nr_truncates)
  2020. ext4_msg(sb, KERN_INFO, "%d truncate%s cleaned up",
  2021. PLURAL(nr_truncates));
  2022. #ifdef CONFIG_QUOTA
  2023. /* Turn quotas off */
  2024. for (i = 0; i < EXT4_MAXQUOTAS; i++) {
  2025. if (sb_dqopt(sb)->files[i])
  2026. dquot_quota_off(sb, i);
  2027. }
  2028. #endif
  2029. sb->s_flags = s_flags; /* Restore MS_RDONLY status */
  2030. }
  2031. /*
  2032. * Maximal extent format file size.
  2033. * Resulting logical blkno at s_maxbytes must fit in our on-disk
  2034. * extent format containers, within a sector_t, and within i_blocks
  2035. * in the vfs. ext4 inode has 48 bits of i_block in fsblock units,
  2036. * so that won't be a limiting factor.
  2037. *
  2038. * However there is other limiting factor. We do store extents in the form
  2039. * of starting block and length, hence the resulting length of the extent
  2040. * covering maximum file size must fit into on-disk format containers as
  2041. * well. Given that length is always by 1 unit bigger than max unit (because
  2042. * we count 0 as well) we have to lower the s_maxbytes by one fs block.
  2043. *
  2044. * Note, this does *not* consider any metadata overhead for vfs i_blocks.
  2045. */
  2046. static loff_t ext4_max_size(int blkbits, int has_huge_files)
  2047. {
  2048. loff_t res;
  2049. loff_t upper_limit = MAX_LFS_FILESIZE;
  2050. /* small i_blocks in vfs inode? */
  2051. if (!has_huge_files || sizeof(blkcnt_t) < sizeof(u64)) {
  2052. /*
  2053. * CONFIG_LBDAF is not enabled implies the inode
  2054. * i_block represent total blocks in 512 bytes
  2055. * 32 == size of vfs inode i_blocks * 8
  2056. */
  2057. upper_limit = (1LL << 32) - 1;
  2058. /* total blocks in file system block size */
  2059. upper_limit >>= (blkbits - 9);
  2060. upper_limit <<= blkbits;
  2061. }
  2062. /*
  2063. * 32-bit extent-start container, ee_block. We lower the maxbytes
  2064. * by one fs block, so ee_len can cover the extent of maximum file
  2065. * size
  2066. */
  2067. res = (1LL << 32) - 1;
  2068. res <<= blkbits;
  2069. /* Sanity check against vm- & vfs- imposed limits */
  2070. if (res > upper_limit)
  2071. res = upper_limit;
  2072. return res;
  2073. }
  2074. /*
  2075. * Maximal bitmap file size. There is a direct, and {,double-,triple-}indirect
  2076. * block limit, and also a limit of (2^48 - 1) 512-byte sectors in i_blocks.
  2077. * We need to be 1 filesystem block less than the 2^48 sector limit.
  2078. */
  2079. static loff_t ext4_max_bitmap_size(int bits, int has_huge_files)
  2080. {
  2081. loff_t res = EXT4_NDIR_BLOCKS;
  2082. int meta_blocks;
  2083. loff_t upper_limit;
  2084. /* This is calculated to be the largest file size for a dense, block
  2085. * mapped file such that the file's total number of 512-byte sectors,
  2086. * including data and all indirect blocks, does not exceed (2^48 - 1).
  2087. *
  2088. * __u32 i_blocks_lo and _u16 i_blocks_high represent the total
  2089. * number of 512-byte sectors of the file.
  2090. */
  2091. if (!has_huge_files || sizeof(blkcnt_t) < sizeof(u64)) {
  2092. /*
  2093. * !has_huge_files or CONFIG_LBDAF not enabled implies that
  2094. * the inode i_block field represents total file blocks in
  2095. * 2^32 512-byte sectors == size of vfs inode i_blocks * 8
  2096. */
  2097. upper_limit = (1LL << 32) - 1;
  2098. /* total blocks in file system block size */
  2099. upper_limit >>= (bits - 9);
  2100. } else {
  2101. /*
  2102. * We use 48 bit ext4_inode i_blocks
  2103. * With EXT4_HUGE_FILE_FL set the i_blocks
  2104. * represent total number of blocks in
  2105. * file system block size
  2106. */
  2107. upper_limit = (1LL << 48) - 1;
  2108. }
  2109. /* indirect blocks */
  2110. meta_blocks = 1;
  2111. /* double indirect blocks */
  2112. meta_blocks += 1 + (1LL << (bits-2));
  2113. /* tripple indirect blocks */
  2114. meta_blocks += 1 + (1LL << (bits-2)) + (1LL << (2*(bits-2)));
  2115. upper_limit -= meta_blocks;
  2116. upper_limit <<= bits;
  2117. res += 1LL << (bits-2);
  2118. res += 1LL << (2*(bits-2));
  2119. res += 1LL << (3*(bits-2));
  2120. res <<= bits;
  2121. if (res > upper_limit)
  2122. res = upper_limit;
  2123. if (res > MAX_LFS_FILESIZE)
  2124. res = MAX_LFS_FILESIZE;
  2125. return res;
  2126. }
  2127. static ext4_fsblk_t descriptor_loc(struct super_block *sb,
  2128. ext4_fsblk_t logical_sb_block, int nr)
  2129. {
  2130. struct ext4_sb_info *sbi = EXT4_SB(sb);
  2131. ext4_group_t bg, first_meta_bg;
  2132. int has_super = 0;
  2133. first_meta_bg = le32_to_cpu(sbi->s_es->s_first_meta_bg);
  2134. if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_META_BG) ||
  2135. nr < first_meta_bg)
  2136. return logical_sb_block + nr + 1;
  2137. bg = sbi->s_desc_per_block * nr;
  2138. if (ext4_bg_has_super(sb, bg))
  2139. has_super = 1;
  2140. /*
  2141. * If we have a meta_bg fs with 1k blocks, group 0's GDT is at
  2142. * block 2, not 1. If s_first_data_block == 0 (bigalloc is enabled
  2143. * on modern mke2fs or blksize > 1k on older mke2fs) then we must
  2144. * compensate.
  2145. */
  2146. if (sb->s_blocksize == 1024 && nr == 0 &&
  2147. le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block) == 0)
  2148. has_super++;
  2149. return (has_super + ext4_group_first_block_no(sb, bg));
  2150. }
  2151. /**
  2152. * ext4_get_stripe_size: Get the stripe size.
  2153. * @sbi: In memory super block info
  2154. *
  2155. * If we have specified it via mount option, then
  2156. * use the mount option value. If the value specified at mount time is
  2157. * greater than the blocks per group use the super block value.
  2158. * If the super block value is greater than blocks per group return 0.
  2159. * Allocator needs it be less than blocks per group.
  2160. *
  2161. */
  2162. static unsigned long ext4_get_stripe_size(struct ext4_sb_info *sbi)
  2163. {
  2164. unsigned long stride = le16_to_cpu(sbi->s_es->s_raid_stride);
  2165. unsigned long stripe_width =
  2166. le32_to_cpu(sbi->s_es->s_raid_stripe_width);
  2167. int ret;
  2168. if (sbi->s_stripe && sbi->s_stripe <= sbi->s_blocks_per_group)
  2169. ret = sbi->s_stripe;
  2170. else if (stripe_width <= sbi->s_blocks_per_group)
  2171. ret = stripe_width;
  2172. else if (stride <= sbi->s_blocks_per_group)
  2173. ret = stride;
  2174. else
  2175. ret = 0;
  2176. /*
  2177. * If the stripe width is 1, this makes no sense and
  2178. * we set it to 0 to turn off stripe handling code.
  2179. */
  2180. if (ret <= 1)
  2181. ret = 0;
  2182. return ret;
  2183. }
  2184. /* sysfs supprt */
  2185. struct ext4_attr {
  2186. struct attribute attr;
  2187. ssize_t (*show)(struct ext4_attr *, struct ext4_sb_info *, char *);
  2188. ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
  2189. const char *, size_t);
  2190. union {
  2191. int offset;
  2192. int deprecated_val;
  2193. } u;
  2194. };
  2195. static int parse_strtoull(const char *buf,
  2196. unsigned long long max, unsigned long long *value)
  2197. {
  2198. int ret;
  2199. ret = kstrtoull(skip_spaces(buf), 0, value);
  2200. if (!ret && *value > max)
  2201. ret = -EINVAL;
  2202. return ret;
  2203. }
  2204. static ssize_t delayed_allocation_blocks_show(struct ext4_attr *a,
  2205. struct ext4_sb_info *sbi,
  2206. char *buf)
  2207. {
  2208. return snprintf(buf, PAGE_SIZE, "%llu\n",
  2209. (s64) EXT4_C2B(sbi,
  2210. percpu_counter_sum(&sbi->s_dirtyclusters_counter)));
  2211. }
  2212. static ssize_t session_write_kbytes_show(struct ext4_attr *a,
  2213. struct ext4_sb_info *sbi, char *buf)
  2214. {
  2215. struct super_block *sb = sbi->s_buddy_cache->i_sb;
  2216. if (!sb->s_bdev->bd_part)
  2217. return snprintf(buf, PAGE_SIZE, "0\n");
  2218. return snprintf(buf, PAGE_SIZE, "%lu\n",
  2219. (part_stat_read(sb->s_bdev->bd_part, sectors[1]) -
  2220. sbi->s_sectors_written_start) >> 1);
  2221. }
  2222. static ssize_t lifetime_write_kbytes_show(struct ext4_attr *a,
  2223. struct ext4_sb_info *sbi, char *buf)
  2224. {
  2225. struct super_block *sb = sbi->s_buddy_cache->i_sb;
  2226. if (!sb->s_bdev->bd_part)
  2227. return snprintf(buf, PAGE_SIZE, "0\n");
  2228. return snprintf(buf, PAGE_SIZE, "%llu\n",
  2229. (unsigned long long)(sbi->s_kbytes_written +
  2230. ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) -
  2231. EXT4_SB(sb)->s_sectors_written_start) >> 1)));
  2232. }
  2233. static ssize_t inode_readahead_blks_store(struct ext4_attr *a,
  2234. struct ext4_sb_info *sbi,
  2235. const char *buf, size_t count)
  2236. {
  2237. unsigned long t;
  2238. int ret;
  2239. ret = kstrtoul(skip_spaces(buf), 0, &t);
  2240. if (ret)
  2241. return ret;
  2242. if (t && (!is_power_of_2(t) || t > 0x40000000))
  2243. return -EINVAL;
  2244. sbi->s_inode_readahead_blks = t;
  2245. return count;
  2246. }
  2247. static ssize_t sbi_ui_show(struct ext4_attr *a,
  2248. struct ext4_sb_info *sbi, char *buf)
  2249. {
  2250. unsigned int *ui = (unsigned int *) (((char *) sbi) + a->u.offset);
  2251. return snprintf(buf, PAGE_SIZE, "%u\n", *ui);
  2252. }
  2253. static ssize_t sbi_ui_store(struct ext4_attr *a,
  2254. struct ext4_sb_info *sbi,
  2255. const char *buf, size_t count)
  2256. {
  2257. unsigned int *ui = (unsigned int *) (((char *) sbi) + a->u.offset);
  2258. unsigned long t;
  2259. int ret;
  2260. ret = kstrtoul(skip_spaces(buf), 0, &t);
  2261. if (ret)
  2262. return ret;
  2263. *ui = t;
  2264. return count;
  2265. }
  2266. static ssize_t es_ui_show(struct ext4_attr *a,
  2267. struct ext4_sb_info *sbi, char *buf)
  2268. {
  2269. unsigned int *ui = (unsigned int *) (((char *) sbi->s_es) +
  2270. a->u.offset);
  2271. return snprintf(buf, PAGE_SIZE, "%u\n", *ui);
  2272. }
  2273. static ssize_t reserved_clusters_show(struct ext4_attr *a,
  2274. struct ext4_sb_info *sbi, char *buf)
  2275. {
  2276. return snprintf(buf, PAGE_SIZE, "%llu\n",
  2277. (unsigned long long) atomic64_read(&sbi->s_resv_clusters));
  2278. }
  2279. static ssize_t reserved_clusters_store(struct ext4_attr *a,
  2280. struct ext4_sb_info *sbi,
  2281. const char *buf, size_t count)
  2282. {
  2283. unsigned long long val;
  2284. int ret;
  2285. if (parse_strtoull(buf, -1ULL, &val))
  2286. return -EINVAL;
  2287. ret = ext4_reserve_clusters(sbi, val);
  2288. return ret ? ret : count;
  2289. }
  2290. static ssize_t trigger_test_error(struct ext4_attr *a,
  2291. struct ext4_sb_info *sbi,
  2292. const char *buf, size_t count)
  2293. {
  2294. int len = count;
  2295. if (!capable(CAP_SYS_ADMIN))
  2296. return -EPERM;
  2297. if (len && buf[len-1] == '\n')
  2298. len--;
  2299. if (len)
  2300. ext4_error(sbi->s_sb, "%.*s", len, buf);
  2301. return count;
  2302. }
  2303. static ssize_t sbi_deprecated_show(struct ext4_attr *a,
  2304. struct ext4_sb_info *sbi, char *buf)
  2305. {
  2306. return snprintf(buf, PAGE_SIZE, "%d\n", a->u.deprecated_val);
  2307. }
  2308. #define EXT4_ATTR_OFFSET(_name,_mode,_show,_store,_elname) \
  2309. static struct ext4_attr ext4_attr_##_name = { \
  2310. .attr = {.name = __stringify(_name), .mode = _mode }, \
  2311. .show = _show, \
  2312. .store = _store, \
  2313. .u = { \
  2314. .offset = offsetof(struct ext4_sb_info, _elname),\
  2315. }, \
  2316. }
  2317. #define EXT4_ATTR_OFFSET_ES(_name,_mode,_show,_store,_elname) \
  2318. static struct ext4_attr ext4_attr_##_name = { \
  2319. .attr = {.name = __stringify(_name), .mode = _mode }, \
  2320. .show = _show, \
  2321. .store = _store, \
  2322. .u = { \
  2323. .offset = offsetof(struct ext4_super_block, _elname), \
  2324. }, \
  2325. }
  2326. #define EXT4_ATTR(name, mode, show, store) \
  2327. static struct ext4_attr ext4_attr_##name = __ATTR(name, mode, show, store)
  2328. #define EXT4_INFO_ATTR(name) EXT4_ATTR(name, 0444, NULL, NULL)
  2329. #define EXT4_RO_ATTR(name) EXT4_ATTR(name, 0444, name##_show, NULL)
  2330. #define EXT4_RW_ATTR(name) EXT4_ATTR(name, 0644, name##_show, name##_store)
  2331. #define EXT4_RO_ATTR_ES_UI(name, elname) \
  2332. EXT4_ATTR_OFFSET_ES(name, 0444, es_ui_show, NULL, elname)
  2333. #define EXT4_RW_ATTR_SBI_UI(name, elname) \
  2334. EXT4_ATTR_OFFSET(name, 0644, sbi_ui_show, sbi_ui_store, elname)
  2335. #define ATTR_LIST(name) &ext4_attr_##name.attr
  2336. #define EXT4_DEPRECATED_ATTR(_name, _val) \
  2337. static struct ext4_attr ext4_attr_##_name = { \
  2338. .attr = {.name = __stringify(_name), .mode = 0444 }, \
  2339. .show = sbi_deprecated_show, \
  2340. .u = { \
  2341. .deprecated_val = _val, \
  2342. }, \
  2343. }
  2344. EXT4_RO_ATTR(delayed_allocation_blocks);
  2345. EXT4_RO_ATTR(session_write_kbytes);
  2346. EXT4_RO_ATTR(lifetime_write_kbytes);
  2347. EXT4_RW_ATTR(reserved_clusters);
  2348. EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, sbi_ui_show,
  2349. inode_readahead_blks_store, s_inode_readahead_blks);
  2350. EXT4_RW_ATTR_SBI_UI(inode_goal, s_inode_goal);
  2351. EXT4_RW_ATTR_SBI_UI(mb_stats, s_mb_stats);
  2352. EXT4_RW_ATTR_SBI_UI(mb_max_to_scan, s_mb_max_to_scan);
  2353. EXT4_RW_ATTR_SBI_UI(mb_min_to_scan, s_mb_min_to_scan);
  2354. EXT4_RW_ATTR_SBI_UI(mb_order2_req, s_mb_order2_reqs);
  2355. EXT4_RW_ATTR_SBI_UI(mb_stream_req, s_mb_stream_request);
  2356. EXT4_RW_ATTR_SBI_UI(mb_group_prealloc, s_mb_group_prealloc);
  2357. EXT4_DEPRECATED_ATTR(max_writeback_mb_bump, 128);
  2358. EXT4_RW_ATTR_SBI_UI(extent_max_zeroout_kb, s_extent_max_zeroout_kb);
  2359. EXT4_ATTR(trigger_fs_error, 0200, NULL, trigger_test_error);
  2360. EXT4_RW_ATTR_SBI_UI(err_ratelimit_interval_ms, s_err_ratelimit_state.interval);
  2361. EXT4_RW_ATTR_SBI_UI(err_ratelimit_burst, s_err_ratelimit_state.burst);
  2362. EXT4_RW_ATTR_SBI_UI(warning_ratelimit_interval_ms, s_warning_ratelimit_state.interval);
  2363. EXT4_RW_ATTR_SBI_UI(warning_ratelimit_burst, s_warning_ratelimit_state.burst);
  2364. EXT4_RW_ATTR_SBI_UI(msg_ratelimit_interval_ms, s_msg_ratelimit_state.interval);
  2365. EXT4_RW_ATTR_SBI_UI(msg_ratelimit_burst, s_msg_ratelimit_state.burst);
  2366. EXT4_RO_ATTR_ES_UI(errors_count, s_error_count);
  2367. EXT4_RO_ATTR_ES_UI(first_error_time, s_first_error_time);
  2368. EXT4_RO_ATTR_ES_UI(last_error_time, s_last_error_time);
  2369. static struct attribute *ext4_attrs[] = {
  2370. ATTR_LIST(delayed_allocation_blocks),
  2371. ATTR_LIST(session_write_kbytes),
  2372. ATTR_LIST(lifetime_write_kbytes),
  2373. ATTR_LIST(reserved_clusters),
  2374. ATTR_LIST(inode_readahead_blks),
  2375. ATTR_LIST(inode_goal),
  2376. ATTR_LIST(mb_stats),
  2377. ATTR_LIST(mb_max_to_scan),
  2378. ATTR_LIST(mb_min_to_scan),
  2379. ATTR_LIST(mb_order2_req),
  2380. ATTR_LIST(mb_stream_req),
  2381. ATTR_LIST(mb_group_prealloc),
  2382. ATTR_LIST(max_writeback_mb_bump),
  2383. ATTR_LIST(extent_max_zeroout_kb),
  2384. ATTR_LIST(trigger_fs_error),
  2385. ATTR_LIST(err_ratelimit_interval_ms),
  2386. ATTR_LIST(err_ratelimit_burst),
  2387. ATTR_LIST(warning_ratelimit_interval_ms),
  2388. ATTR_LIST(warning_ratelimit_burst),
  2389. ATTR_LIST(msg_ratelimit_interval_ms),
  2390. ATTR_LIST(msg_ratelimit_burst),
  2391. ATTR_LIST(errors_count),
  2392. ATTR_LIST(first_error_time),
  2393. ATTR_LIST(last_error_time),
  2394. NULL,
  2395. };
  2396. /* Features this copy of ext4 supports */
  2397. EXT4_INFO_ATTR(lazy_itable_init);
  2398. EXT4_INFO_ATTR(batched_discard);
  2399. EXT4_INFO_ATTR(meta_bg_resize);
  2400. EXT4_INFO_ATTR(encryption);
  2401. static struct attribute *ext4_feat_attrs[] = {
  2402. ATTR_LIST(lazy_itable_init),
  2403. ATTR_LIST(batched_discard),
  2404. ATTR_LIST(meta_bg_resize),
  2405. ATTR_LIST(encryption),
  2406. NULL,
  2407. };
  2408. static ssize_t ext4_attr_show(struct kobject *kobj,
  2409. struct attribute *attr, char *buf)
  2410. {
  2411. struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info,
  2412. s_kobj);
  2413. struct ext4_attr *a = container_of(attr, struct ext4_attr, attr);
  2414. return a->show ? a->show(a, sbi, buf) : 0;
  2415. }
  2416. static ssize_t ext4_attr_store(struct kobject *kobj,
  2417. struct attribute *attr,
  2418. const char *buf, size_t len)
  2419. {
  2420. struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info,
  2421. s_kobj);
  2422. struct ext4_attr *a = container_of(attr, struct ext4_attr, attr);
  2423. return a->store ? a->store(a, sbi, buf, len) : 0;
  2424. }
  2425. static void ext4_sb_release(struct kobject *kobj)
  2426. {
  2427. struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info,
  2428. s_kobj);
  2429. complete(&sbi->s_kobj_unregister);
  2430. }
  2431. static const struct sysfs_ops ext4_attr_ops = {
  2432. .show = ext4_attr_show,
  2433. .store = ext4_attr_store,
  2434. };
  2435. static struct kobj_type ext4_ktype = {
  2436. .default_attrs = ext4_attrs,
  2437. .sysfs_ops = &ext4_attr_ops,
  2438. .release = ext4_sb_release,
  2439. };
  2440. static void ext4_feat_release(struct kobject *kobj)
  2441. {
  2442. complete(&ext4_feat->f_kobj_unregister);
  2443. }
  2444. static ssize_t ext4_feat_show(struct kobject *kobj,
  2445. struct attribute *attr, char *buf)
  2446. {
  2447. return snprintf(buf, PAGE_SIZE, "supported\n");
  2448. }
  2449. /*
  2450. * We can not use ext4_attr_show/store because it relies on the kobject
  2451. * being embedded in the ext4_sb_info structure which is definitely not
  2452. * true in this case.
  2453. */
  2454. static const struct sysfs_ops ext4_feat_ops = {
  2455. .show = ext4_feat_show,
  2456. .store = NULL,
  2457. };
  2458. static struct kobj_type ext4_feat_ktype = {
  2459. .default_attrs = ext4_feat_attrs,
  2460. .sysfs_ops = &ext4_feat_ops,
  2461. .release = ext4_feat_release,
  2462. };
  2463. /*
  2464. * Check whether this filesystem can be mounted based on
  2465. * the features present and the RDONLY/RDWR mount requested.
  2466. * Returns 1 if this filesystem can be mounted as requested,
  2467. * 0 if it cannot be.
  2468. */
  2469. static int ext4_feature_set_ok(struct super_block *sb, int readonly)
  2470. {
  2471. if (EXT4_HAS_INCOMPAT_FEATURE(sb, ~EXT4_FEATURE_INCOMPAT_SUPP)) {
  2472. ext4_msg(sb, KERN_ERR,
  2473. "Couldn't mount because of "
  2474. "unsupported optional features (%x)",
  2475. (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_incompat) &
  2476. ~EXT4_FEATURE_INCOMPAT_SUPP));
  2477. return 0;
  2478. }
  2479. if (readonly)
  2480. return 1;
  2481. if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_READONLY)) {
  2482. ext4_msg(sb, KERN_INFO, "filesystem is read-only");
  2483. sb->s_flags |= MS_RDONLY;
  2484. return 1;
  2485. }
  2486. /* Check that feature set is OK for a read-write mount */
  2487. if (EXT4_HAS_RO_COMPAT_FEATURE(sb, ~EXT4_FEATURE_RO_COMPAT_SUPP)) {
  2488. ext4_msg(sb, KERN_ERR, "couldn't mount RDWR because of "
  2489. "unsupported optional features (%x)",
  2490. (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_ro_compat) &
  2491. ~EXT4_FEATURE_RO_COMPAT_SUPP));
  2492. return 0;
  2493. }
  2494. /*
  2495. * Large file size enabled file system can only be mounted
  2496. * read-write on 32-bit systems if kernel is built with CONFIG_LBDAF
  2497. */
  2498. if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_HUGE_FILE)) {
  2499. if (sizeof(blkcnt_t) < sizeof(u64)) {
  2500. ext4_msg(sb, KERN_ERR, "Filesystem with huge files "
  2501. "cannot be mounted RDWR without "
  2502. "CONFIG_LBDAF");
  2503. return 0;
  2504. }
  2505. }
  2506. if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_BIGALLOC) &&
  2507. !EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_EXTENTS)) {
  2508. ext4_msg(sb, KERN_ERR,
  2509. "Can't support bigalloc feature without "
  2510. "extents feature\n");
  2511. return 0;
  2512. }
  2513. #ifndef CONFIG_QUOTA
  2514. if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_QUOTA) &&
  2515. !readonly) {
  2516. ext4_msg(sb, KERN_ERR,
  2517. "Filesystem with quota feature cannot be mounted RDWR "
  2518. "without CONFIG_QUOTA");
  2519. return 0;
  2520. }
  2521. #endif /* CONFIG_QUOTA */
  2522. return 1;
  2523. }
  2524. /*
  2525. * This function is called once a day if we have errors logged
  2526. * on the file system
  2527. */
  2528. static void print_daily_error_info(unsigned long arg)
  2529. {
  2530. struct super_block *sb = (struct super_block *) arg;
  2531. struct ext4_sb_info *sbi;
  2532. struct ext4_super_block *es;
  2533. sbi = EXT4_SB(sb);
  2534. es = sbi->s_es;
  2535. if (es->s_error_count)
  2536. /* fsck newer than v1.41.13 is needed to clean this condition. */
  2537. ext4_msg(sb, KERN_NOTICE, "error count since last fsck: %u",
  2538. le32_to_cpu(es->s_error_count));
  2539. if (es->s_first_error_time) {
  2540. printk(KERN_NOTICE "EXT4-fs (%s): initial error at time %u: %.*s:%d",
  2541. sb->s_id, le32_to_cpu(es->s_first_error_time),
  2542. (int) sizeof(es->s_first_error_func),
  2543. es->s_first_error_func,
  2544. le32_to_cpu(es->s_first_error_line));
  2545. if (es->s_first_error_ino)
  2546. printk(": inode %u",
  2547. le32_to_cpu(es->s_first_error_ino));
  2548. if (es->s_first_error_block)
  2549. printk(": block %llu", (unsigned long long)
  2550. le64_to_cpu(es->s_first_error_block));
  2551. printk("\n");
  2552. }
  2553. if (es->s_last_error_time) {
  2554. printk(KERN_NOTICE "EXT4-fs (%s): last error at time %u: %.*s:%d",
  2555. sb->s_id, le32_to_cpu(es->s_last_error_time),
  2556. (int) sizeof(es->s_last_error_func),
  2557. es->s_last_error_func,
  2558. le32_to_cpu(es->s_last_error_line));
  2559. if (es->s_last_error_ino)
  2560. printk(": inode %u",
  2561. le32_to_cpu(es->s_last_error_ino));
  2562. if (es->s_last_error_block)
  2563. printk(": block %llu", (unsigned long long)
  2564. le64_to_cpu(es->s_last_error_block));
  2565. printk("\n");
  2566. }
  2567. mod_timer(&sbi->s_err_report, jiffies + 24*60*60*HZ); /* Once a day */
  2568. }
  2569. /* Find next suitable group and run ext4_init_inode_table */
  2570. static int ext4_run_li_request(struct ext4_li_request *elr)
  2571. {
  2572. struct ext4_group_desc *gdp = NULL;
  2573. ext4_group_t group, ngroups;
  2574. struct super_block *sb;
  2575. unsigned long timeout = 0;
  2576. int ret = 0;
  2577. sb = elr->lr_super;
  2578. ngroups = EXT4_SB(sb)->s_groups_count;
  2579. sb_start_write(sb);
  2580. for (group = elr->lr_next_group; group < ngroups; group++) {
  2581. gdp = ext4_get_group_desc(sb, group, NULL);
  2582. if (!gdp) {
  2583. ret = 1;
  2584. break;
  2585. }
  2586. if (!(gdp->bg_flags & cpu_to_le16(EXT4_BG_INODE_ZEROED)))
  2587. break;
  2588. }
  2589. if (group >= ngroups)
  2590. ret = 1;
  2591. if (!ret) {
  2592. timeout = jiffies;
  2593. ret = ext4_init_inode_table(sb, group,
  2594. elr->lr_timeout ? 0 : 1);
  2595. if (elr->lr_timeout == 0) {
  2596. timeout = (jiffies - timeout) *
  2597. elr->lr_sbi->s_li_wait_mult;
  2598. elr->lr_timeout = timeout;
  2599. }
  2600. elr->lr_next_sched = jiffies + elr->lr_timeout;
  2601. elr->lr_next_group = group + 1;
  2602. }
  2603. sb_end_write(sb);
  2604. return ret;
  2605. }
  2606. /*
  2607. * Remove lr_request from the list_request and free the
  2608. * request structure. Should be called with li_list_mtx held
  2609. */
  2610. static void ext4_remove_li_request(struct ext4_li_request *elr)
  2611. {
  2612. struct ext4_sb_info *sbi;
  2613. if (!elr)
  2614. return;
  2615. sbi = elr->lr_sbi;
  2616. list_del(&elr->lr_request);
  2617. sbi->s_li_request = NULL;
  2618. kfree(elr);
  2619. }
  2620. static void ext4_unregister_li_request(struct super_block *sb)
  2621. {
  2622. mutex_lock(&ext4_li_mtx);
  2623. if (!ext4_li_info) {
  2624. mutex_unlock(&ext4_li_mtx);
  2625. return;
  2626. }
  2627. mutex_lock(&ext4_li_info->li_list_mtx);
  2628. ext4_remove_li_request(EXT4_SB(sb)->s_li_request);
  2629. mutex_unlock(&ext4_li_info->li_list_mtx);
  2630. mutex_unlock(&ext4_li_mtx);
  2631. }
  2632. static struct task_struct *ext4_lazyinit_task;
  2633. /*
  2634. * This is the function where ext4lazyinit thread lives. It walks
  2635. * through the request list searching for next scheduled filesystem.
  2636. * When such a fs is found, run the lazy initialization request
  2637. * (ext4_rn_li_request) and keep track of the time spend in this
  2638. * function. Based on that time we compute next schedule time of
  2639. * the request. When walking through the list is complete, compute
  2640. * next waking time and put itself into sleep.
  2641. */
  2642. static int ext4_lazyinit_thread(void *arg)
  2643. {
  2644. struct ext4_lazy_init *eli = (struct ext4_lazy_init *)arg;
  2645. struct list_head *pos, *n;
  2646. struct ext4_li_request *elr;
  2647. unsigned long next_wakeup, cur;
  2648. BUG_ON(NULL == eli);
  2649. cont_thread:
  2650. while (true) {
  2651. next_wakeup = MAX_JIFFY_OFFSET;
  2652. mutex_lock(&eli->li_list_mtx);
  2653. if (list_empty(&eli->li_request_list)) {
  2654. mutex_unlock(&eli->li_list_mtx);
  2655. goto exit_thread;
  2656. }
  2657. list_for_each_safe(pos, n, &eli->li_request_list) {
  2658. elr = list_entry(pos, struct ext4_li_request,
  2659. lr_request);
  2660. if (time_after_eq(jiffies, elr->lr_next_sched)) {
  2661. if (ext4_run_li_request(elr) != 0) {
  2662. /* error, remove the lazy_init job */
  2663. ext4_remove_li_request(elr);
  2664. continue;
  2665. }
  2666. }
  2667. if (time_before(elr->lr_next_sched, next_wakeup))
  2668. next_wakeup = elr->lr_next_sched;
  2669. }
  2670. mutex_unlock(&eli->li_list_mtx);
  2671. try_to_freeze();
  2672. cur = jiffies;
  2673. if ((time_after_eq(cur, next_wakeup)) ||
  2674. (MAX_JIFFY_OFFSET == next_wakeup)) {
  2675. cond_resched();
  2676. continue;
  2677. }
  2678. schedule_timeout_interruptible(next_wakeup - cur);
  2679. if (kthread_should_stop()) {
  2680. ext4_clear_request_list();
  2681. goto exit_thread;
  2682. }
  2683. }
  2684. exit_thread:
  2685. /*
  2686. * It looks like the request list is empty, but we need
  2687. * to check it under the li_list_mtx lock, to prevent any
  2688. * additions into it, and of course we should lock ext4_li_mtx
  2689. * to atomically free the list and ext4_li_info, because at
  2690. * this point another ext4 filesystem could be registering
  2691. * new one.
  2692. */
  2693. mutex_lock(&ext4_li_mtx);
  2694. mutex_lock(&eli->li_list_mtx);
  2695. if (!list_empty(&eli->li_request_list)) {
  2696. mutex_unlock(&eli->li_list_mtx);
  2697. mutex_unlock(&ext4_li_mtx);
  2698. goto cont_thread;
  2699. }
  2700. mutex_unlock(&eli->li_list_mtx);
  2701. kfree(ext4_li_info);
  2702. ext4_li_info = NULL;
  2703. mutex_unlock(&ext4_li_mtx);
  2704. return 0;
  2705. }
  2706. static void ext4_clear_request_list(void)
  2707. {
  2708. struct list_head *pos, *n;
  2709. struct ext4_li_request *elr;
  2710. mutex_lock(&ext4_li_info->li_list_mtx);
  2711. list_for_each_safe(pos, n, &ext4_li_info->li_request_list) {
  2712. elr = list_entry(pos, struct ext4_li_request,
  2713. lr_request);
  2714. ext4_remove_li_request(elr);
  2715. }
  2716. mutex_unlock(&ext4_li_info->li_list_mtx);
  2717. }
  2718. static int ext4_run_lazyinit_thread(void)
  2719. {
  2720. ext4_lazyinit_task = kthread_run(ext4_lazyinit_thread,
  2721. ext4_li_info, "ext4lazyinit");
  2722. if (IS_ERR(ext4_lazyinit_task)) {
  2723. int err = PTR_ERR(ext4_lazyinit_task);
  2724. ext4_clear_request_list();
  2725. kfree(ext4_li_info);
  2726. ext4_li_info = NULL;
  2727. printk(KERN_CRIT "EXT4-fs: error %d creating inode table "
  2728. "initialization thread\n",
  2729. err);
  2730. return err;
  2731. }
  2732. ext4_li_info->li_state |= EXT4_LAZYINIT_RUNNING;
  2733. return 0;
  2734. }
  2735. /*
  2736. * Check whether it make sense to run itable init. thread or not.
  2737. * If there is at least one uninitialized inode table, return
  2738. * corresponding group number, else the loop goes through all
  2739. * groups and return total number of groups.
  2740. */
  2741. static ext4_group_t ext4_has_uninit_itable(struct super_block *sb)
  2742. {
  2743. ext4_group_t group, ngroups = EXT4_SB(sb)->s_groups_count;
  2744. struct ext4_group_desc *gdp = NULL;
  2745. for (group = 0; group < ngroups; group++) {
  2746. gdp = ext4_get_group_desc(sb, group, NULL);
  2747. if (!gdp)
  2748. continue;
  2749. if (!(gdp->bg_flags & cpu_to_le16(EXT4_BG_INODE_ZEROED)))
  2750. break;
  2751. }
  2752. return group;
  2753. }
  2754. static int ext4_li_info_new(void)
  2755. {
  2756. struct ext4_lazy_init *eli = NULL;
  2757. eli = kzalloc(sizeof(*eli), GFP_KERNEL);
  2758. if (!eli)
  2759. return -ENOMEM;
  2760. INIT_LIST_HEAD(&eli->li_request_list);
  2761. mutex_init(&eli->li_list_mtx);
  2762. eli->li_state |= EXT4_LAZYINIT_QUIT;
  2763. ext4_li_info = eli;
  2764. return 0;
  2765. }
  2766. static struct ext4_li_request *ext4_li_request_new(struct super_block *sb,
  2767. ext4_group_t start)
  2768. {
  2769. struct ext4_sb_info *sbi = EXT4_SB(sb);
  2770. struct ext4_li_request *elr;
  2771. elr = kzalloc(sizeof(*elr), GFP_KERNEL);
  2772. if (!elr)
  2773. return NULL;
  2774. elr->lr_super = sb;
  2775. elr->lr_sbi = sbi;
  2776. elr->lr_next_group = start;
  2777. /*
  2778. * Randomize first schedule time of the request to
  2779. * spread the inode table initialization requests
  2780. * better.
  2781. */
  2782. elr->lr_next_sched = jiffies + (prandom_u32() %
  2783. (EXT4_DEF_LI_MAX_START_DELAY * HZ));
  2784. return elr;
  2785. }
  2786. int ext4_register_li_request(struct super_block *sb,
  2787. ext4_group_t first_not_zeroed)
  2788. {
  2789. struct ext4_sb_info *sbi = EXT4_SB(sb);
  2790. struct ext4_li_request *elr = NULL;
  2791. ext4_group_t ngroups = EXT4_SB(sb)->s_groups_count;
  2792. int ret = 0;
  2793. mutex_lock(&ext4_li_mtx);
  2794. if (sbi->s_li_request != NULL) {
  2795. /*
  2796. * Reset timeout so it can be computed again, because
  2797. * s_li_wait_mult might have changed.
  2798. */
  2799. sbi->s_li_request->lr_timeout = 0;
  2800. goto out;
  2801. }
  2802. if (first_not_zeroed == ngroups ||
  2803. (sb->s_flags & MS_RDONLY) ||
  2804. !test_opt(sb, INIT_INODE_TABLE))
  2805. goto out;
  2806. elr = ext4_li_request_new(sb, first_not_zeroed);
  2807. if (!elr) {
  2808. ret = -ENOMEM;
  2809. goto out;
  2810. }
  2811. if (NULL == ext4_li_info) {
  2812. ret = ext4_li_info_new();
  2813. if (ret)
  2814. goto out;
  2815. }
  2816. mutex_lock(&ext4_li_info->li_list_mtx);
  2817. list_add(&elr->lr_request, &ext4_li_info->li_request_list);
  2818. mutex_unlock(&ext4_li_info->li_list_mtx);
  2819. sbi->s_li_request = elr;
  2820. /*
  2821. * set elr to NULL here since it has been inserted to
  2822. * the request_list and the removal and free of it is
  2823. * handled by ext4_clear_request_list from now on.
  2824. */
  2825. elr = NULL;
  2826. if (!(ext4_li_info->li_state & EXT4_LAZYINIT_RUNNING)) {
  2827. ret = ext4_run_lazyinit_thread();
  2828. if (ret)
  2829. goto out;
  2830. }
  2831. out:
  2832. mutex_unlock(&ext4_li_mtx);
  2833. if (ret)
  2834. kfree(elr);
  2835. return ret;
  2836. }
  2837. /*
  2838. * We do not need to lock anything since this is called on
  2839. * module unload.
  2840. */
  2841. static void ext4_destroy_lazyinit_thread(void)
  2842. {
  2843. /*
  2844. * If thread exited earlier
  2845. * there's nothing to be done.
  2846. */
  2847. if (!ext4_li_info || !ext4_lazyinit_task)
  2848. return;
  2849. kthread_stop(ext4_lazyinit_task);
  2850. }
  2851. static int set_journal_csum_feature_set(struct super_block *sb)
  2852. {
  2853. int ret = 1;
  2854. int compat, incompat;
  2855. struct ext4_sb_info *sbi = EXT4_SB(sb);
  2856. if (ext4_has_metadata_csum(sb)) {
  2857. /* journal checksum v3 */
  2858. compat = 0;
  2859. incompat = JBD2_FEATURE_INCOMPAT_CSUM_V3;
  2860. } else {
  2861. /* journal checksum v1 */
  2862. compat = JBD2_FEATURE_COMPAT_CHECKSUM;
  2863. incompat = 0;
  2864. }
  2865. jbd2_journal_clear_features(sbi->s_journal,
  2866. JBD2_FEATURE_COMPAT_CHECKSUM, 0,
  2867. JBD2_FEATURE_INCOMPAT_CSUM_V3 |
  2868. JBD2_FEATURE_INCOMPAT_CSUM_V2);
  2869. if (test_opt(sb, JOURNAL_ASYNC_COMMIT)) {
  2870. ret = jbd2_journal_set_features(sbi->s_journal,
  2871. compat, 0,
  2872. JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT |
  2873. incompat);
  2874. } else if (test_opt(sb, JOURNAL_CHECKSUM)) {
  2875. ret = jbd2_journal_set_features(sbi->s_journal,
  2876. compat, 0,
  2877. incompat);
  2878. jbd2_journal_clear_features(sbi->s_journal, 0, 0,
  2879. JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
  2880. } else {
  2881. jbd2_journal_clear_features(sbi->s_journal, 0, 0,
  2882. JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
  2883. }
  2884. return ret;
  2885. }
  2886. /*
  2887. * Note: calculating the overhead so we can be compatible with
  2888. * historical BSD practice is quite difficult in the face of
  2889. * clusters/bigalloc. This is because multiple metadata blocks from
  2890. * different block group can end up in the same allocation cluster.
  2891. * Calculating the exact overhead in the face of clustered allocation
  2892. * requires either O(all block bitmaps) in memory or O(number of block
  2893. * groups**2) in time. We will still calculate the superblock for
  2894. * older file systems --- and if we come across with a bigalloc file
  2895. * system with zero in s_overhead_clusters the estimate will be close to
  2896. * correct especially for very large cluster sizes --- but for newer
  2897. * file systems, it's better to calculate this figure once at mkfs
  2898. * time, and store it in the superblock. If the superblock value is
  2899. * present (even for non-bigalloc file systems), we will use it.
  2900. */
  2901. static int count_overhead(struct super_block *sb, ext4_group_t grp,
  2902. char *buf)
  2903. {
  2904. struct ext4_sb_info *sbi = EXT4_SB(sb);
  2905. struct ext4_group_desc *gdp;
  2906. ext4_fsblk_t first_block, last_block, b;
  2907. ext4_group_t i, ngroups = ext4_get_groups_count(sb);
  2908. int s, j, count = 0;
  2909. if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_BIGALLOC))
  2910. return (ext4_bg_has_super(sb, grp) + ext4_bg_num_gdb(sb, grp) +
  2911. sbi->s_itb_per_group + 2);
  2912. first_block = le32_to_cpu(sbi->s_es->s_first_data_block) +
  2913. (grp * EXT4_BLOCKS_PER_GROUP(sb));
  2914. last_block = first_block + EXT4_BLOCKS_PER_GROUP(sb) - 1;
  2915. for (i = 0; i < ngroups; i++) {
  2916. gdp = ext4_get_group_desc(sb, i, NULL);
  2917. b = ext4_block_bitmap(sb, gdp);
  2918. if (b >= first_block && b <= last_block) {
  2919. ext4_set_bit(EXT4_B2C(sbi, b - first_block), buf);
  2920. count++;
  2921. }
  2922. b = ext4_inode_bitmap(sb, gdp);
  2923. if (b >= first_block && b <= last_block) {
  2924. ext4_set_bit(EXT4_B2C(sbi, b - first_block), buf);
  2925. count++;
  2926. }
  2927. b = ext4_inode_table(sb, gdp);
  2928. if (b >= first_block && b + sbi->s_itb_per_group <= last_block)
  2929. for (j = 0; j < sbi->s_itb_per_group; j++, b++) {
  2930. int c = EXT4_B2C(sbi, b - first_block);
  2931. ext4_set_bit(c, buf);
  2932. count++;
  2933. }
  2934. if (i != grp)
  2935. continue;
  2936. s = 0;
  2937. if (ext4_bg_has_super(sb, grp)) {
  2938. ext4_set_bit(s++, buf);
  2939. count++;
  2940. }
  2941. for (j = ext4_bg_num_gdb(sb, grp); j > 0; j--) {
  2942. ext4_set_bit(EXT4_B2C(sbi, s++), buf);
  2943. count++;
  2944. }
  2945. }
  2946. if (!count)
  2947. return 0;
  2948. return EXT4_CLUSTERS_PER_GROUP(sb) -
  2949. ext4_count_free(buf, EXT4_CLUSTERS_PER_GROUP(sb) / 8);
  2950. }
  2951. /*
  2952. * Compute the overhead and stash it in sbi->s_overhead
  2953. */
  2954. int ext4_calculate_overhead(struct super_block *sb)
  2955. {
  2956. struct ext4_sb_info *sbi = EXT4_SB(sb);
  2957. struct ext4_super_block *es = sbi->s_es;
  2958. ext4_group_t i, ngroups = ext4_get_groups_count(sb);
  2959. ext4_fsblk_t overhead = 0;
  2960. char *buf = (char *) get_zeroed_page(GFP_NOFS);
  2961. if (!buf)
  2962. return -ENOMEM;
  2963. /*
  2964. * Compute the overhead (FS structures). This is constant
  2965. * for a given filesystem unless the number of block groups
  2966. * changes so we cache the previous value until it does.
  2967. */
  2968. /*
  2969. * All of the blocks before first_data_block are overhead
  2970. */
  2971. overhead = EXT4_B2C(sbi, le32_to_cpu(es->s_first_data_block));
  2972. /*
  2973. * Add the overhead found in each block group
  2974. */
  2975. for (i = 0; i < ngroups; i++) {
  2976. int blks;
  2977. blks = count_overhead(sb, i, buf);
  2978. overhead += blks;
  2979. if (blks)
  2980. memset(buf, 0, PAGE_SIZE);
  2981. cond_resched();
  2982. }
  2983. /* Add the internal journal blocks as well */
  2984. if (sbi->s_journal && !sbi->journal_bdev)
  2985. overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_maxlen);
  2986. sbi->s_overhead = overhead;
  2987. smp_wmb();
  2988. free_page((unsigned long) buf);
  2989. return 0;
  2990. }
  2991. static ext4_fsblk_t ext4_calculate_resv_clusters(struct super_block *sb)
  2992. {
  2993. ext4_fsblk_t resv_clusters;
  2994. /*
  2995. * There's no need to reserve anything when we aren't using extents.
  2996. * The space estimates are exact, there are no unwritten extents,
  2997. * hole punching doesn't need new metadata... This is needed especially
  2998. * to keep ext2/3 backward compatibility.
  2999. */
  3000. if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_EXTENTS))
  3001. return 0;
  3002. /*
  3003. * By default we reserve 2% or 4096 clusters, whichever is smaller.
  3004. * This should cover the situations where we can not afford to run
  3005. * out of space like for example punch hole, or converting
  3006. * unwritten extents in delalloc path. In most cases such
  3007. * allocation would require 1, or 2 blocks, higher numbers are
  3008. * very rare.
  3009. */
  3010. resv_clusters = ext4_blocks_count(EXT4_SB(sb)->s_es) >>
  3011. EXT4_SB(sb)->s_cluster_bits;
  3012. do_div(resv_clusters, 50);
  3013. resv_clusters = min_t(ext4_fsblk_t, resv_clusters, 4096);
  3014. return resv_clusters;
  3015. }
  3016. static int ext4_reserve_clusters(struct ext4_sb_info *sbi, ext4_fsblk_t count)
  3017. {
  3018. ext4_fsblk_t clusters = ext4_blocks_count(sbi->s_es) >>
  3019. sbi->s_cluster_bits;
  3020. if (count >= clusters)
  3021. return -EINVAL;
  3022. atomic64_set(&sbi->s_resv_clusters, count);
  3023. return 0;
  3024. }
  3025. static int ext4_fill_super(struct super_block *sb, void *data, int silent)
  3026. {
  3027. char *orig_data = kstrdup(data, GFP_KERNEL);
  3028. struct buffer_head *bh;
  3029. struct ext4_super_block *es = NULL;
  3030. struct ext4_sb_info *sbi;
  3031. ext4_fsblk_t block;
  3032. ext4_fsblk_t sb_block = get_sb_block(&data);
  3033. ext4_fsblk_t logical_sb_block;
  3034. unsigned long offset = 0;
  3035. unsigned long journal_devnum = 0;
  3036. unsigned long def_mount_opts;
  3037. struct inode *root;
  3038. char *cp;
  3039. const char *descr;
  3040. int ret = -ENOMEM;
  3041. int blocksize, clustersize;
  3042. unsigned int db_count;
  3043. unsigned int i;
  3044. int needs_recovery, has_huge_files, has_bigalloc;
  3045. __u64 blocks_count;
  3046. int err = 0;
  3047. unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO;
  3048. ext4_group_t first_not_zeroed;
  3049. sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
  3050. if (!sbi)
  3051. goto out_free_orig;
  3052. sbi->s_blockgroup_lock =
  3053. kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL);
  3054. if (!sbi->s_blockgroup_lock) {
  3055. kfree(sbi);
  3056. goto out_free_orig;
  3057. }
  3058. sb->s_fs_info = sbi;
  3059. sbi->s_sb = sb;
  3060. sbi->s_inode_readahead_blks = EXT4_DEF_INODE_READAHEAD_BLKS;
  3061. sbi->s_sb_block = sb_block;
  3062. if (sb->s_bdev->bd_part)
  3063. sbi->s_sectors_written_start =
  3064. part_stat_read(sb->s_bdev->bd_part, sectors[1]);
  3065. #ifdef CONFIG_EXT4_FS_ENCRYPTION
  3066. /* Modes of operations for file and directory encryption. */
  3067. sbi->s_file_encryption_mode = EXT4_ENCRYPTION_MODE_AES_256_XTS;
  3068. sbi->s_dir_encryption_mode = EXT4_ENCRYPTION_MODE_INVALID;
  3069. #endif
  3070. /* Cleanup superblock name */
  3071. for (cp = sb->s_id; (cp = strchr(cp, '/'));)
  3072. *cp = '!';
  3073. /* -EINVAL is default */
  3074. ret = -EINVAL;
  3075. blocksize = sb_min_blocksize(sb, EXT4_MIN_BLOCK_SIZE);
  3076. if (!blocksize) {
  3077. ext4_msg(sb, KERN_ERR, "unable to set blocksize");
  3078. goto out_fail;
  3079. }
  3080. /*
  3081. * The ext4 superblock will not be buffer aligned for other than 1kB
  3082. * block sizes. We need to calculate the offset from buffer start.
  3083. */
  3084. if (blocksize != EXT4_MIN_BLOCK_SIZE) {
  3085. logical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE;
  3086. offset = do_div(logical_sb_block, blocksize);
  3087. } else {
  3088. logical_sb_block = sb_block;
  3089. }
  3090. if (!(bh = sb_bread_unmovable(sb, logical_sb_block))) {
  3091. ext4_msg(sb, KERN_ERR, "unable to read superblock");
  3092. goto out_fail;
  3093. }
  3094. /*
  3095. * Note: s_es must be initialized as soon as possible because
  3096. * some ext4 macro-instructions depend on its value
  3097. */
  3098. es = (struct ext4_super_block *) (bh->b_data + offset);
  3099. sbi->s_es = es;
  3100. sb->s_magic = le16_to_cpu(es->s_magic);
  3101. if (sb->s_magic != EXT4_SUPER_MAGIC)
  3102. goto cantfind_ext4;
  3103. sbi->s_kbytes_written = le64_to_cpu(es->s_kbytes_written);
  3104. /* Warn if metadata_csum and gdt_csum are both set. */
  3105. if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
  3106. EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) &&
  3107. EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_GDT_CSUM))
  3108. ext4_warning(sb, "metadata_csum and uninit_bg are "
  3109. "redundant flags; please run fsck.");
  3110. /* Check for a known checksum algorithm */
  3111. if (!ext4_verify_csum_type(sb, es)) {
  3112. ext4_msg(sb, KERN_ERR, "VFS: Found ext4 filesystem with "
  3113. "unknown checksum algorithm.");
  3114. silent = 1;
  3115. goto cantfind_ext4;
  3116. }
  3117. /* Load the checksum driver */
  3118. if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
  3119. EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
  3120. sbi->s_chksum_driver = crypto_alloc_shash("crc32c", 0, 0);
  3121. if (IS_ERR(sbi->s_chksum_driver)) {
  3122. ext4_msg(sb, KERN_ERR, "Cannot load crc32c driver.");
  3123. ret = PTR_ERR(sbi->s_chksum_driver);
  3124. sbi->s_chksum_driver = NULL;
  3125. goto failed_mount;
  3126. }
  3127. }
  3128. /* Check superblock checksum */
  3129. if (!ext4_superblock_csum_verify(sb, es)) {
  3130. ext4_msg(sb, KERN_ERR, "VFS: Found ext4 filesystem with "
  3131. "invalid superblock checksum. Run e2fsck?");
  3132. silent = 1;
  3133. goto cantfind_ext4;
  3134. }
  3135. /* Precompute checksum seed for all metadata */
  3136. if (ext4_has_metadata_csum(sb))
  3137. sbi->s_csum_seed = ext4_chksum(sbi, ~0, es->s_uuid,
  3138. sizeof(es->s_uuid));
  3139. /* Set defaults before we parse the mount options */
  3140. def_mount_opts = le32_to_cpu(es->s_default_mount_opts);
  3141. set_opt(sb, INIT_INODE_TABLE);
  3142. if (def_mount_opts & EXT4_DEFM_DEBUG)
  3143. set_opt(sb, DEBUG);
  3144. if (def_mount_opts & EXT4_DEFM_BSDGROUPS)
  3145. set_opt(sb, GRPID);
  3146. if (def_mount_opts & EXT4_DEFM_UID16)
  3147. set_opt(sb, NO_UID32);
  3148. /* xattr user namespace & acls are now defaulted on */
  3149. set_opt(sb, XATTR_USER);
  3150. #ifdef CONFIG_EXT4_FS_POSIX_ACL
  3151. set_opt(sb, POSIX_ACL);
  3152. #endif
  3153. /* don't forget to enable journal_csum when metadata_csum is enabled. */
  3154. if (ext4_has_metadata_csum(sb))
  3155. set_opt(sb, JOURNAL_CHECKSUM);
  3156. if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_DATA)
  3157. set_opt(sb, JOURNAL_DATA);
  3158. else if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_ORDERED)
  3159. set_opt(sb, ORDERED_DATA);
  3160. else if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_WBACK)
  3161. set_opt(sb, WRITEBACK_DATA);
  3162. if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_PANIC)
  3163. set_opt(sb, ERRORS_PANIC);
  3164. else if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_CONTINUE)
  3165. set_opt(sb, ERRORS_CONT);
  3166. else
  3167. set_opt(sb, ERRORS_RO);
  3168. /* block_validity enabled by default; disable with noblock_validity */
  3169. set_opt(sb, BLOCK_VALIDITY);
  3170. if (def_mount_opts & EXT4_DEFM_DISCARD)
  3171. set_opt(sb, DISCARD);
  3172. sbi->s_resuid = make_kuid(&init_user_ns, le16_to_cpu(es->s_def_resuid));
  3173. sbi->s_resgid = make_kgid(&init_user_ns, le16_to_cpu(es->s_def_resgid));
  3174. sbi->s_commit_interval = JBD2_DEFAULT_MAX_COMMIT_AGE * HZ;
  3175. sbi->s_min_batch_time = EXT4_DEF_MIN_BATCH_TIME;
  3176. sbi->s_max_batch_time = EXT4_DEF_MAX_BATCH_TIME;
  3177. if ((def_mount_opts & EXT4_DEFM_NOBARRIER) == 0)
  3178. set_opt(sb, BARRIER);
  3179. /*
  3180. * enable delayed allocation by default
  3181. * Use -o nodelalloc to turn it off
  3182. */
  3183. if (!IS_EXT3_SB(sb) && !IS_EXT2_SB(sb) &&
  3184. ((def_mount_opts & EXT4_DEFM_NODELALLOC) == 0))
  3185. set_opt(sb, DELALLOC);
  3186. /*
  3187. * set default s_li_wait_mult for lazyinit, for the case there is
  3188. * no mount option specified.
  3189. */
  3190. sbi->s_li_wait_mult = EXT4_DEF_LI_WAIT_MULT;
  3191. if (!parse_options((char *) sbi->s_es->s_mount_opts, sb,
  3192. &journal_devnum, &journal_ioprio, 0)) {
  3193. ext4_msg(sb, KERN_WARNING,
  3194. "failed to parse options in superblock: %s",
  3195. sbi->s_es->s_mount_opts);
  3196. }
  3197. sbi->s_def_mount_opt = sbi->s_mount_opt;
  3198. if (!parse_options((char *) data, sb, &journal_devnum,
  3199. &journal_ioprio, 0))
  3200. goto failed_mount;
  3201. if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) {
  3202. printk_once(KERN_WARNING "EXT4-fs: Warning: mounting "
  3203. "with data=journal disables delayed "
  3204. "allocation and O_DIRECT support!\n");
  3205. if (test_opt2(sb, EXPLICIT_DELALLOC)) {
  3206. ext4_msg(sb, KERN_ERR, "can't mount with "
  3207. "both data=journal and delalloc");
  3208. goto failed_mount;
  3209. }
  3210. if (test_opt(sb, DIOREAD_NOLOCK)) {
  3211. ext4_msg(sb, KERN_ERR, "can't mount with "
  3212. "both data=journal and dioread_nolock");
  3213. goto failed_mount;
  3214. }
  3215. if (test_opt(sb, DAX)) {
  3216. ext4_msg(sb, KERN_ERR, "can't mount with "
  3217. "both data=journal and dax");
  3218. goto failed_mount;
  3219. }
  3220. if (test_opt(sb, DELALLOC))
  3221. clear_opt(sb, DELALLOC);
  3222. }
  3223. sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
  3224. (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
  3225. if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV &&
  3226. (EXT4_HAS_COMPAT_FEATURE(sb, ~0U) ||
  3227. EXT4_HAS_RO_COMPAT_FEATURE(sb, ~0U) ||
  3228. EXT4_HAS_INCOMPAT_FEATURE(sb, ~0U)))
  3229. ext4_msg(sb, KERN_WARNING,
  3230. "feature flags set on rev 0 fs, "
  3231. "running e2fsck is recommended");
  3232. if (es->s_creator_os == cpu_to_le32(EXT4_OS_HURD)) {
  3233. set_opt2(sb, HURD_COMPAT);
  3234. if (EXT4_HAS_INCOMPAT_FEATURE(sb,
  3235. EXT4_FEATURE_INCOMPAT_64BIT)) {
  3236. ext4_msg(sb, KERN_ERR,
  3237. "The Hurd can't support 64-bit file systems");
  3238. goto failed_mount;
  3239. }
  3240. }
  3241. if (IS_EXT2_SB(sb)) {
  3242. if (ext2_feature_set_ok(sb))
  3243. ext4_msg(sb, KERN_INFO, "mounting ext2 file system "
  3244. "using the ext4 subsystem");
  3245. else {
  3246. ext4_msg(sb, KERN_ERR, "couldn't mount as ext2 due "
  3247. "to feature incompatibilities");
  3248. goto failed_mount;
  3249. }
  3250. }
  3251. if (IS_EXT3_SB(sb)) {
  3252. if (ext3_feature_set_ok(sb))
  3253. ext4_msg(sb, KERN_INFO, "mounting ext3 file system "
  3254. "using the ext4 subsystem");
  3255. else {
  3256. ext4_msg(sb, KERN_ERR, "couldn't mount as ext3 due "
  3257. "to feature incompatibilities");
  3258. goto failed_mount;
  3259. }
  3260. }
  3261. /*
  3262. * Check feature flags regardless of the revision level, since we
  3263. * previously didn't change the revision level when setting the flags,
  3264. * so there is a chance incompat flags are set on a rev 0 filesystem.
  3265. */
  3266. if (!ext4_feature_set_ok(sb, (sb->s_flags & MS_RDONLY)))
  3267. goto failed_mount;
  3268. blocksize = BLOCK_SIZE << le32_to_cpu(es->s_log_block_size);
  3269. if (blocksize < EXT4_MIN_BLOCK_SIZE ||
  3270. blocksize > EXT4_MAX_BLOCK_SIZE) {
  3271. ext4_msg(sb, KERN_ERR,
  3272. "Unsupported filesystem blocksize %d", blocksize);
  3273. goto failed_mount;
  3274. }
  3275. if (sbi->s_mount_opt & EXT4_MOUNT_DAX) {
  3276. if (blocksize != PAGE_SIZE) {
  3277. ext4_msg(sb, KERN_ERR,
  3278. "error: unsupported blocksize for dax");
  3279. goto failed_mount;
  3280. }
  3281. if (!sb->s_bdev->bd_disk->fops->direct_access) {
  3282. ext4_msg(sb, KERN_ERR,
  3283. "error: device does not support dax");
  3284. goto failed_mount;
  3285. }
  3286. }
  3287. if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_ENCRYPT) &&
  3288. es->s_encryption_level) {
  3289. ext4_msg(sb, KERN_ERR, "Unsupported encryption level %d",
  3290. es->s_encryption_level);
  3291. goto failed_mount;
  3292. }
  3293. if (sb->s_blocksize != blocksize) {
  3294. /* Validate the filesystem blocksize */
  3295. if (!sb_set_blocksize(sb, blocksize)) {
  3296. ext4_msg(sb, KERN_ERR, "bad block size %d",
  3297. blocksize);
  3298. goto failed_mount;
  3299. }
  3300. brelse(bh);
  3301. logical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE;
  3302. offset = do_div(logical_sb_block, blocksize);
  3303. bh = sb_bread_unmovable(sb, logical_sb_block);
  3304. if (!bh) {
  3305. ext4_msg(sb, KERN_ERR,
  3306. "Can't read superblock on 2nd try");
  3307. goto failed_mount;
  3308. }
  3309. es = (struct ext4_super_block *)(bh->b_data + offset);
  3310. sbi->s_es = es;
  3311. if (es->s_magic != cpu_to_le16(EXT4_SUPER_MAGIC)) {
  3312. ext4_msg(sb, KERN_ERR,
  3313. "Magic mismatch, very weird!");
  3314. goto failed_mount;
  3315. }
  3316. }
  3317. has_huge_files = EXT4_HAS_RO_COMPAT_FEATURE(sb,
  3318. EXT4_FEATURE_RO_COMPAT_HUGE_FILE);
  3319. sbi->s_bitmap_maxbytes = ext4_max_bitmap_size(sb->s_blocksize_bits,
  3320. has_huge_files);
  3321. sb->s_maxbytes = ext4_max_size(sb->s_blocksize_bits, has_huge_files);
  3322. if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV) {
  3323. sbi->s_inode_size = EXT4_GOOD_OLD_INODE_SIZE;
  3324. sbi->s_first_ino = EXT4_GOOD_OLD_FIRST_INO;
  3325. } else {
  3326. sbi->s_inode_size = le16_to_cpu(es->s_inode_size);
  3327. sbi->s_first_ino = le32_to_cpu(es->s_first_ino);
  3328. if ((sbi->s_inode_size < EXT4_GOOD_OLD_INODE_SIZE) ||
  3329. (!is_power_of_2(sbi->s_inode_size)) ||
  3330. (sbi->s_inode_size > blocksize)) {
  3331. ext4_msg(sb, KERN_ERR,
  3332. "unsupported inode size: %d",
  3333. sbi->s_inode_size);
  3334. goto failed_mount;
  3335. }
  3336. if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE)
  3337. sb->s_time_gran = 1 << (EXT4_EPOCH_BITS - 2);
  3338. }
  3339. sbi->s_desc_size = le16_to_cpu(es->s_desc_size);
  3340. if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_64BIT)) {
  3341. if (sbi->s_desc_size < EXT4_MIN_DESC_SIZE_64BIT ||
  3342. sbi->s_desc_size > EXT4_MAX_DESC_SIZE ||
  3343. !is_power_of_2(sbi->s_desc_size)) {
  3344. ext4_msg(sb, KERN_ERR,
  3345. "unsupported descriptor size %lu",
  3346. sbi->s_desc_size);
  3347. goto failed_mount;
  3348. }
  3349. } else
  3350. sbi->s_desc_size = EXT4_MIN_DESC_SIZE;
  3351. sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group);
  3352. sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group);
  3353. if (EXT4_INODE_SIZE(sb) == 0 || EXT4_INODES_PER_GROUP(sb) == 0)
  3354. goto cantfind_ext4;
  3355. sbi->s_inodes_per_block = blocksize / EXT4_INODE_SIZE(sb);
  3356. if (sbi->s_inodes_per_block == 0)
  3357. goto cantfind_ext4;
  3358. sbi->s_itb_per_group = sbi->s_inodes_per_group /
  3359. sbi->s_inodes_per_block;
  3360. sbi->s_desc_per_block = blocksize / EXT4_DESC_SIZE(sb);
  3361. sbi->s_sbh = bh;
  3362. sbi->s_mount_state = le16_to_cpu(es->s_state);
  3363. sbi->s_addr_per_block_bits = ilog2(EXT4_ADDR_PER_BLOCK(sb));
  3364. sbi->s_desc_per_block_bits = ilog2(EXT4_DESC_PER_BLOCK(sb));
  3365. for (i = 0; i < 4; i++)
  3366. sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]);
  3367. sbi->s_def_hash_version = es->s_def_hash_version;
  3368. if (EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_DIR_INDEX)) {
  3369. i = le32_to_cpu(es->s_flags);
  3370. if (i & EXT2_FLAGS_UNSIGNED_HASH)
  3371. sbi->s_hash_unsigned = 3;
  3372. else if ((i & EXT2_FLAGS_SIGNED_HASH) == 0) {
  3373. #ifdef __CHAR_UNSIGNED__
  3374. if (!(sb->s_flags & MS_RDONLY))
  3375. es->s_flags |=
  3376. cpu_to_le32(EXT2_FLAGS_UNSIGNED_HASH);
  3377. sbi->s_hash_unsigned = 3;
  3378. #else
  3379. if (!(sb->s_flags & MS_RDONLY))
  3380. es->s_flags |=
  3381. cpu_to_le32(EXT2_FLAGS_SIGNED_HASH);
  3382. #endif
  3383. }
  3384. }
  3385. /* Handle clustersize */
  3386. clustersize = BLOCK_SIZE << le32_to_cpu(es->s_log_cluster_size);
  3387. has_bigalloc = EXT4_HAS_RO_COMPAT_FEATURE(sb,
  3388. EXT4_FEATURE_RO_COMPAT_BIGALLOC);
  3389. if (has_bigalloc) {
  3390. if (clustersize < blocksize) {
  3391. ext4_msg(sb, KERN_ERR,
  3392. "cluster size (%d) smaller than "
  3393. "block size (%d)", clustersize, blocksize);
  3394. goto failed_mount;
  3395. }
  3396. sbi->s_cluster_bits = le32_to_cpu(es->s_log_cluster_size) -
  3397. le32_to_cpu(es->s_log_block_size);
  3398. sbi->s_clusters_per_group =
  3399. le32_to_cpu(es->s_clusters_per_group);
  3400. if (sbi->s_clusters_per_group > blocksize * 8) {
  3401. ext4_msg(sb, KERN_ERR,
  3402. "#clusters per group too big: %lu",
  3403. sbi->s_clusters_per_group);
  3404. goto failed_mount;
  3405. }
  3406. if (sbi->s_blocks_per_group !=
  3407. (sbi->s_clusters_per_group * (clustersize / blocksize))) {
  3408. ext4_msg(sb, KERN_ERR, "blocks per group (%lu) and "
  3409. "clusters per group (%lu) inconsistent",
  3410. sbi->s_blocks_per_group,
  3411. sbi->s_clusters_per_group);
  3412. goto failed_mount;
  3413. }
  3414. } else {
  3415. if (clustersize != blocksize) {
  3416. ext4_warning(sb, "fragment/cluster size (%d) != "
  3417. "block size (%d)", clustersize,
  3418. blocksize);
  3419. clustersize = blocksize;
  3420. }
  3421. if (sbi->s_blocks_per_group > blocksize * 8) {
  3422. ext4_msg(sb, KERN_ERR,
  3423. "#blocks per group too big: %lu",
  3424. sbi->s_blocks_per_group);
  3425. goto failed_mount;
  3426. }
  3427. sbi->s_clusters_per_group = sbi->s_blocks_per_group;
  3428. sbi->s_cluster_bits = 0;
  3429. }
  3430. sbi->s_cluster_ratio = clustersize / blocksize;
  3431. if (sbi->s_inodes_per_group > blocksize * 8) {
  3432. ext4_msg(sb, KERN_ERR,
  3433. "#inodes per group too big: %lu",
  3434. sbi->s_inodes_per_group);
  3435. goto failed_mount;
  3436. }
  3437. /* Do we have standard group size of clustersize * 8 blocks ? */
  3438. if (sbi->s_blocks_per_group == clustersize << 3)
  3439. set_opt2(sb, STD_GROUP_SIZE);
  3440. /*
  3441. * Test whether we have more sectors than will fit in sector_t,
  3442. * and whether the max offset is addressable by the page cache.
  3443. */
  3444. err = generic_check_addressable(sb->s_blocksize_bits,
  3445. ext4_blocks_count(es));
  3446. if (err) {
  3447. ext4_msg(sb, KERN_ERR, "filesystem"
  3448. " too large to mount safely on this system");
  3449. if (sizeof(sector_t) < 8)
  3450. ext4_msg(sb, KERN_WARNING, "CONFIG_LBDAF not enabled");
  3451. goto failed_mount;
  3452. }
  3453. if (EXT4_BLOCKS_PER_GROUP(sb) == 0)
  3454. goto cantfind_ext4;
  3455. /* check blocks count against device size */
  3456. blocks_count = sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits;
  3457. if (blocks_count && ext4_blocks_count(es) > blocks_count) {
  3458. ext4_msg(sb, KERN_WARNING, "bad geometry: block count %llu "
  3459. "exceeds size of device (%llu blocks)",
  3460. ext4_blocks_count(es), blocks_count);
  3461. goto failed_mount;
  3462. }
  3463. /*
  3464. * It makes no sense for the first data block to be beyond the end
  3465. * of the filesystem.
  3466. */
  3467. if (le32_to_cpu(es->s_first_data_block) >= ext4_blocks_count(es)) {
  3468. ext4_msg(sb, KERN_WARNING, "bad geometry: first data "
  3469. "block %u is beyond end of filesystem (%llu)",
  3470. le32_to_cpu(es->s_first_data_block),
  3471. ext4_blocks_count(es));
  3472. goto failed_mount;
  3473. }
  3474. blocks_count = (ext4_blocks_count(es) -
  3475. le32_to_cpu(es->s_first_data_block) +
  3476. EXT4_BLOCKS_PER_GROUP(sb) - 1);
  3477. do_div(blocks_count, EXT4_BLOCKS_PER_GROUP(sb));
  3478. if (blocks_count > ((uint64_t)1<<32) - EXT4_DESC_PER_BLOCK(sb)) {
  3479. ext4_msg(sb, KERN_WARNING, "groups count too large: %u "
  3480. "(block count %llu, first data block %u, "
  3481. "blocks per group %lu)", sbi->s_groups_count,
  3482. ext4_blocks_count(es),
  3483. le32_to_cpu(es->s_first_data_block),
  3484. EXT4_BLOCKS_PER_GROUP(sb));
  3485. goto failed_mount;
  3486. }
  3487. sbi->s_groups_count = blocks_count;
  3488. sbi->s_blockfile_groups = min_t(ext4_group_t, sbi->s_groups_count,
  3489. (EXT4_MAX_BLOCK_FILE_PHYS / EXT4_BLOCKS_PER_GROUP(sb)));
  3490. db_count = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 1) /
  3491. EXT4_DESC_PER_BLOCK(sb);
  3492. sbi->s_group_desc = ext4_kvmalloc(db_count *
  3493. sizeof(struct buffer_head *),
  3494. GFP_KERNEL);
  3495. if (sbi->s_group_desc == NULL) {
  3496. ext4_msg(sb, KERN_ERR, "not enough memory");
  3497. ret = -ENOMEM;
  3498. goto failed_mount;
  3499. }
  3500. if (ext4_proc_root)
  3501. sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root);
  3502. if (sbi->s_proc)
  3503. proc_create_data("options", S_IRUGO, sbi->s_proc,
  3504. &ext4_seq_options_fops, sb);
  3505. bgl_lock_init(sbi->s_blockgroup_lock);
  3506. for (i = 0; i < db_count; i++) {
  3507. block = descriptor_loc(sb, logical_sb_block, i);
  3508. sbi->s_group_desc[i] = sb_bread_unmovable(sb, block);
  3509. if (!sbi->s_group_desc[i]) {
  3510. ext4_msg(sb, KERN_ERR,
  3511. "can't read group descriptor %d", i);
  3512. db_count = i;
  3513. goto failed_mount2;
  3514. }
  3515. }
  3516. if (!ext4_check_descriptors(sb, &first_not_zeroed)) {
  3517. ext4_msg(sb, KERN_ERR, "group descriptors corrupted!");
  3518. goto failed_mount2;
  3519. }
  3520. sbi->s_gdb_count = db_count;
  3521. get_random_bytes(&sbi->s_next_generation, sizeof(u32));
  3522. spin_lock_init(&sbi->s_next_gen_lock);
  3523. setup_timer(&sbi->s_err_report, print_daily_error_info,
  3524. (unsigned long) sb);
  3525. /* Register extent status tree shrinker */
  3526. if (ext4_es_register_shrinker(sbi))
  3527. goto failed_mount3;
  3528. sbi->s_stripe = ext4_get_stripe_size(sbi);
  3529. sbi->s_extent_max_zeroout_kb = 32;
  3530. /*
  3531. * set up enough so that it can read an inode
  3532. */
  3533. sb->s_op = &ext4_sops;
  3534. sb->s_export_op = &ext4_export_ops;
  3535. sb->s_xattr = ext4_xattr_handlers;
  3536. #ifdef CONFIG_QUOTA
  3537. sb->dq_op = &ext4_quota_operations;
  3538. if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_QUOTA))
  3539. sb->s_qcop = &dquot_quotactl_sysfile_ops;
  3540. else
  3541. sb->s_qcop = &ext4_qctl_operations;
  3542. sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP;
  3543. #endif
  3544. memcpy(sb->s_uuid, es->s_uuid, sizeof(es->s_uuid));
  3545. INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */
  3546. mutex_init(&sbi->s_orphan_lock);
  3547. sb->s_root = NULL;
  3548. needs_recovery = (es->s_last_orphan != 0 ||
  3549. EXT4_HAS_INCOMPAT_FEATURE(sb,
  3550. EXT4_FEATURE_INCOMPAT_RECOVER));
  3551. if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_MMP) &&
  3552. !(sb->s_flags & MS_RDONLY))
  3553. if (ext4_multi_mount_protect(sb, le64_to_cpu(es->s_mmp_block)))
  3554. goto failed_mount3a;
  3555. /*
  3556. * The first inode we look at is the journal inode. Don't try
  3557. * root first: it may be modified in the journal!
  3558. */
  3559. if (!test_opt(sb, NOLOAD) &&
  3560. EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) {
  3561. if (ext4_load_journal(sb, es, journal_devnum))
  3562. goto failed_mount3a;
  3563. } else if (test_opt(sb, NOLOAD) && !(sb->s_flags & MS_RDONLY) &&
  3564. EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) {
  3565. ext4_msg(sb, KERN_ERR, "required journal recovery "
  3566. "suppressed and not mounted read-only");
  3567. goto failed_mount_wq;
  3568. } else {
  3569. clear_opt(sb, DATA_FLAGS);
  3570. sbi->s_journal = NULL;
  3571. needs_recovery = 0;
  3572. goto no_journal;
  3573. }
  3574. if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_64BIT) &&
  3575. !jbd2_journal_set_features(EXT4_SB(sb)->s_journal, 0, 0,
  3576. JBD2_FEATURE_INCOMPAT_64BIT)) {
  3577. ext4_msg(sb, KERN_ERR, "Failed to set 64-bit journal feature");
  3578. goto failed_mount_wq;
  3579. }
  3580. if (!set_journal_csum_feature_set(sb)) {
  3581. ext4_msg(sb, KERN_ERR, "Failed to set journal checksum "
  3582. "feature set");
  3583. goto failed_mount_wq;
  3584. }
  3585. /* We have now updated the journal if required, so we can
  3586. * validate the data journaling mode. */
  3587. switch (test_opt(sb, DATA_FLAGS)) {
  3588. case 0:
  3589. /* No mode set, assume a default based on the journal
  3590. * capabilities: ORDERED_DATA if the journal can
  3591. * cope, else JOURNAL_DATA
  3592. */
  3593. if (jbd2_journal_check_available_features
  3594. (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE))
  3595. set_opt(sb, ORDERED_DATA);
  3596. else
  3597. set_opt(sb, JOURNAL_DATA);
  3598. break;
  3599. case EXT4_MOUNT_ORDERED_DATA:
  3600. case EXT4_MOUNT_WRITEBACK_DATA:
  3601. if (!jbd2_journal_check_available_features
  3602. (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE)) {
  3603. ext4_msg(sb, KERN_ERR, "Journal does not support "
  3604. "requested data journaling mode");
  3605. goto failed_mount_wq;
  3606. }
  3607. default:
  3608. break;
  3609. }
  3610. set_task_ioprio(sbi->s_journal->j_task, journal_ioprio);
  3611. sbi->s_journal->j_commit_callback = ext4_journal_commit_callback;
  3612. no_journal:
  3613. if (ext4_mballoc_ready) {
  3614. sbi->s_mb_cache = ext4_xattr_create_cache(sb->s_id);
  3615. if (!sbi->s_mb_cache) {
  3616. ext4_msg(sb, KERN_ERR, "Failed to create an mb_cache");
  3617. goto failed_mount_wq;
  3618. }
  3619. }
  3620. if (unlikely(sbi->s_mount_flags & EXT4_MF_TEST_DUMMY_ENCRYPTION) &&
  3621. !(sb->s_flags & MS_RDONLY) &&
  3622. !EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_ENCRYPT)) {
  3623. EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_ENCRYPT);
  3624. ext4_commit_super(sb, 1);
  3625. }
  3626. /*
  3627. * Get the # of file system overhead blocks from the
  3628. * superblock if present.
  3629. */
  3630. if (es->s_overhead_clusters)
  3631. sbi->s_overhead = le32_to_cpu(es->s_overhead_clusters);
  3632. else {
  3633. err = ext4_calculate_overhead(sb);
  3634. if (err)
  3635. goto failed_mount_wq;
  3636. }
  3637. /*
  3638. * The maximum number of concurrent works can be high and
  3639. * concurrency isn't really necessary. Limit it to 1.
  3640. */
  3641. EXT4_SB(sb)->rsv_conversion_wq =
  3642. alloc_workqueue("ext4-rsv-conversion", WQ_MEM_RECLAIM | WQ_UNBOUND, 1);
  3643. if (!EXT4_SB(sb)->rsv_conversion_wq) {
  3644. printk(KERN_ERR "EXT4-fs: failed to create workqueue\n");
  3645. ret = -ENOMEM;
  3646. goto failed_mount4;
  3647. }
  3648. /*
  3649. * The jbd2_journal_load will have done any necessary log recovery,
  3650. * so we can safely mount the rest of the filesystem now.
  3651. */
  3652. root = ext4_iget(sb, EXT4_ROOT_INO);
  3653. if (IS_ERR(root)) {
  3654. ext4_msg(sb, KERN_ERR, "get root inode failed");
  3655. ret = PTR_ERR(root);
  3656. root = NULL;
  3657. goto failed_mount4;
  3658. }
  3659. if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {
  3660. ext4_msg(sb, KERN_ERR, "corrupt root inode, run e2fsck");
  3661. iput(root);
  3662. goto failed_mount4;
  3663. }
  3664. sb->s_root = d_make_root(root);
  3665. if (!sb->s_root) {
  3666. ext4_msg(sb, KERN_ERR, "get root dentry failed");
  3667. ret = -ENOMEM;
  3668. goto failed_mount4;
  3669. }
  3670. if (ext4_setup_super(sb, es, sb->s_flags & MS_RDONLY))
  3671. sb->s_flags |= MS_RDONLY;
  3672. /* determine the minimum size of new large inodes, if present */
  3673. if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) {
  3674. sbi->s_want_extra_isize = sizeof(struct ext4_inode) -
  3675. EXT4_GOOD_OLD_INODE_SIZE;
  3676. if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
  3677. EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE)) {
  3678. if (sbi->s_want_extra_isize <
  3679. le16_to_cpu(es->s_want_extra_isize))
  3680. sbi->s_want_extra_isize =
  3681. le16_to_cpu(es->s_want_extra_isize);
  3682. if (sbi->s_want_extra_isize <
  3683. le16_to_cpu(es->s_min_extra_isize))
  3684. sbi->s_want_extra_isize =
  3685. le16_to_cpu(es->s_min_extra_isize);
  3686. }
  3687. }
  3688. /* Check if enough inode space is available */
  3689. if (EXT4_GOOD_OLD_INODE_SIZE + sbi->s_want_extra_isize >
  3690. sbi->s_inode_size) {
  3691. sbi->s_want_extra_isize = sizeof(struct ext4_inode) -
  3692. EXT4_GOOD_OLD_INODE_SIZE;
  3693. ext4_msg(sb, KERN_INFO, "required extra inode space not"
  3694. "available");
  3695. }
  3696. err = ext4_reserve_clusters(sbi, ext4_calculate_resv_clusters(sb));
  3697. if (err) {
  3698. ext4_msg(sb, KERN_ERR, "failed to reserve %llu clusters for "
  3699. "reserved pool", ext4_calculate_resv_clusters(sb));
  3700. goto failed_mount4a;
  3701. }
  3702. err = ext4_setup_system_zone(sb);
  3703. if (err) {
  3704. ext4_msg(sb, KERN_ERR, "failed to initialize system "
  3705. "zone (%d)", err);
  3706. goto failed_mount4a;
  3707. }
  3708. ext4_ext_init(sb);
  3709. err = ext4_mb_init(sb);
  3710. if (err) {
  3711. ext4_msg(sb, KERN_ERR, "failed to initialize mballoc (%d)",
  3712. err);
  3713. goto failed_mount5;
  3714. }
  3715. block = ext4_count_free_clusters(sb);
  3716. ext4_free_blocks_count_set(sbi->s_es,
  3717. EXT4_C2B(sbi, block));
  3718. err = percpu_counter_init(&sbi->s_freeclusters_counter, block,
  3719. GFP_KERNEL);
  3720. if (!err) {
  3721. unsigned long freei = ext4_count_free_inodes(sb);
  3722. sbi->s_es->s_free_inodes_count = cpu_to_le32(freei);
  3723. err = percpu_counter_init(&sbi->s_freeinodes_counter, freei,
  3724. GFP_KERNEL);
  3725. }
  3726. if (!err)
  3727. err = percpu_counter_init(&sbi->s_dirs_counter,
  3728. ext4_count_dirs(sb), GFP_KERNEL);
  3729. if (!err)
  3730. err = percpu_counter_init(&sbi->s_dirtyclusters_counter, 0,
  3731. GFP_KERNEL);
  3732. if (err) {
  3733. ext4_msg(sb, KERN_ERR, "insufficient memory");
  3734. goto failed_mount6;
  3735. }
  3736. if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG))
  3737. if (!ext4_fill_flex_info(sb)) {
  3738. ext4_msg(sb, KERN_ERR,
  3739. "unable to initialize "
  3740. "flex_bg meta info!");
  3741. goto failed_mount6;
  3742. }
  3743. err = ext4_register_li_request(sb, first_not_zeroed);
  3744. if (err)
  3745. goto failed_mount6;
  3746. sbi->s_kobj.kset = ext4_kset;
  3747. init_completion(&sbi->s_kobj_unregister);
  3748. err = kobject_init_and_add(&sbi->s_kobj, &ext4_ktype, NULL,
  3749. "%s", sb->s_id);
  3750. if (err)
  3751. goto failed_mount7;
  3752. #ifdef CONFIG_QUOTA
  3753. /* Enable quota usage during mount. */
  3754. if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_QUOTA) &&
  3755. !(sb->s_flags & MS_RDONLY)) {
  3756. err = ext4_enable_quotas(sb);
  3757. if (err)
  3758. goto failed_mount8;
  3759. }
  3760. #endif /* CONFIG_QUOTA */
  3761. EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS;
  3762. ext4_orphan_cleanup(sb, es);
  3763. EXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS;
  3764. if (needs_recovery) {
  3765. ext4_msg(sb, KERN_INFO, "recovery complete");
  3766. ext4_mark_recovery_complete(sb, es);
  3767. }
  3768. if (EXT4_SB(sb)->s_journal) {
  3769. if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)
  3770. descr = " journalled data mode";
  3771. else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA)
  3772. descr = " ordered data mode";
  3773. else
  3774. descr = " writeback data mode";
  3775. } else
  3776. descr = "out journal";
  3777. if (test_opt(sb, DISCARD)) {
  3778. struct request_queue *q = bdev_get_queue(sb->s_bdev);
  3779. if (!blk_queue_discard(q))
  3780. ext4_msg(sb, KERN_WARNING,
  3781. "mounting with \"discard\" option, but "
  3782. "the device does not support discard");
  3783. }
  3784. ext4_msg(sb, KERN_INFO, "mounted filesystem with%s. "
  3785. "Opts: %s%s%s", descr, sbi->s_es->s_mount_opts,
  3786. *sbi->s_es->s_mount_opts ? "; " : "", orig_data);
  3787. if (es->s_error_count)
  3788. mod_timer(&sbi->s_err_report, jiffies + 300*HZ); /* 5 minutes */
  3789. /* Enable message ratelimiting. Default is 10 messages per 5 secs. */
  3790. ratelimit_state_init(&sbi->s_err_ratelimit_state, 5 * HZ, 10);
  3791. ratelimit_state_init(&sbi->s_warning_ratelimit_state, 5 * HZ, 10);
  3792. ratelimit_state_init(&sbi->s_msg_ratelimit_state, 5 * HZ, 10);
  3793. kfree(orig_data);
  3794. return 0;
  3795. cantfind_ext4:
  3796. if (!silent)
  3797. ext4_msg(sb, KERN_ERR, "VFS: Can't find ext4 filesystem");
  3798. goto failed_mount;
  3799. #ifdef CONFIG_QUOTA
  3800. failed_mount8:
  3801. kobject_del(&sbi->s_kobj);
  3802. #endif
  3803. failed_mount7:
  3804. ext4_unregister_li_request(sb);
  3805. failed_mount6:
  3806. ext4_mb_release(sb);
  3807. if (sbi->s_flex_groups)
  3808. kvfree(sbi->s_flex_groups);
  3809. percpu_counter_destroy(&sbi->s_freeclusters_counter);
  3810. percpu_counter_destroy(&sbi->s_freeinodes_counter);
  3811. percpu_counter_destroy(&sbi->s_dirs_counter);
  3812. percpu_counter_destroy(&sbi->s_dirtyclusters_counter);
  3813. failed_mount5:
  3814. ext4_ext_release(sb);
  3815. ext4_release_system_zone(sb);
  3816. failed_mount4a:
  3817. dput(sb->s_root);
  3818. sb->s_root = NULL;
  3819. failed_mount4:
  3820. ext4_msg(sb, KERN_ERR, "mount failed");
  3821. if (EXT4_SB(sb)->rsv_conversion_wq)
  3822. destroy_workqueue(EXT4_SB(sb)->rsv_conversion_wq);
  3823. failed_mount_wq:
  3824. if (sbi->s_journal) {
  3825. jbd2_journal_destroy(sbi->s_journal);
  3826. sbi->s_journal = NULL;
  3827. }
  3828. failed_mount3a:
  3829. ext4_es_unregister_shrinker(sbi);
  3830. failed_mount3:
  3831. del_timer_sync(&sbi->s_err_report);
  3832. if (sbi->s_mmp_tsk)
  3833. kthread_stop(sbi->s_mmp_tsk);
  3834. failed_mount2:
  3835. for (i = 0; i < db_count; i++)
  3836. brelse(sbi->s_group_desc[i]);
  3837. kvfree(sbi->s_group_desc);
  3838. failed_mount:
  3839. if (sbi->s_chksum_driver)
  3840. crypto_free_shash(sbi->s_chksum_driver);
  3841. if (sbi->s_proc) {
  3842. remove_proc_entry("options", sbi->s_proc);
  3843. remove_proc_entry(sb->s_id, ext4_proc_root);
  3844. }
  3845. #ifdef CONFIG_QUOTA
  3846. for (i = 0; i < EXT4_MAXQUOTAS; i++)
  3847. kfree(sbi->s_qf_names[i]);
  3848. #endif
  3849. ext4_blkdev_remove(sbi);
  3850. brelse(bh);
  3851. out_fail:
  3852. sb->s_fs_info = NULL;
  3853. kfree(sbi->s_blockgroup_lock);
  3854. kfree(sbi);
  3855. out_free_orig:
  3856. kfree(orig_data);
  3857. return err ? err : ret;
  3858. }
  3859. /*
  3860. * Setup any per-fs journal parameters now. We'll do this both on
  3861. * initial mount, once the journal has been initialised but before we've
  3862. * done any recovery; and again on any subsequent remount.
  3863. */
  3864. static void ext4_init_journal_params(struct super_block *sb, journal_t *journal)
  3865. {
  3866. struct ext4_sb_info *sbi = EXT4_SB(sb);
  3867. journal->j_commit_interval = sbi->s_commit_interval;
  3868. journal->j_min_batch_time = sbi->s_min_batch_time;
  3869. journal->j_max_batch_time = sbi->s_max_batch_time;
  3870. write_lock(&journal->j_state_lock);
  3871. if (test_opt(sb, BARRIER))
  3872. journal->j_flags |= JBD2_BARRIER;
  3873. else
  3874. journal->j_flags &= ~JBD2_BARRIER;
  3875. if (test_opt(sb, DATA_ERR_ABORT))
  3876. journal->j_flags |= JBD2_ABORT_ON_SYNCDATA_ERR;
  3877. else
  3878. journal->j_flags &= ~JBD2_ABORT_ON_SYNCDATA_ERR;
  3879. write_unlock(&journal->j_state_lock);
  3880. }
  3881. static journal_t *ext4_get_journal(struct super_block *sb,
  3882. unsigned int journal_inum)
  3883. {
  3884. struct inode *journal_inode;
  3885. journal_t *journal;
  3886. BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL));
  3887. /* First, test for the existence of a valid inode on disk. Bad
  3888. * things happen if we iget() an unused inode, as the subsequent
  3889. * iput() will try to delete it. */
  3890. journal_inode = ext4_iget(sb, journal_inum);
  3891. if (IS_ERR(journal_inode)) {
  3892. ext4_msg(sb, KERN_ERR, "no journal found");
  3893. return NULL;
  3894. }
  3895. if (!journal_inode->i_nlink) {
  3896. make_bad_inode(journal_inode);
  3897. iput(journal_inode);
  3898. ext4_msg(sb, KERN_ERR, "journal inode is deleted");
  3899. return NULL;
  3900. }
  3901. jbd_debug(2, "Journal inode found at %p: %lld bytes\n",
  3902. journal_inode, journal_inode->i_size);
  3903. if (!S_ISREG(journal_inode->i_mode)) {
  3904. ext4_msg(sb, KERN_ERR, "invalid journal inode");
  3905. iput(journal_inode);
  3906. return NULL;
  3907. }
  3908. journal = jbd2_journal_init_inode(journal_inode);
  3909. if (!journal) {
  3910. ext4_msg(sb, KERN_ERR, "Could not load journal inode");
  3911. iput(journal_inode);
  3912. return NULL;
  3913. }
  3914. journal->j_private = sb;
  3915. ext4_init_journal_params(sb, journal);
  3916. return journal;
  3917. }
  3918. static journal_t *ext4_get_dev_journal(struct super_block *sb,
  3919. dev_t j_dev)
  3920. {
  3921. struct buffer_head *bh;
  3922. journal_t *journal;
  3923. ext4_fsblk_t start;
  3924. ext4_fsblk_t len;
  3925. int hblock, blocksize;
  3926. ext4_fsblk_t sb_block;
  3927. unsigned long offset;
  3928. struct ext4_super_block *es;
  3929. struct block_device *bdev;
  3930. BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL));
  3931. bdev = ext4_blkdev_get(j_dev, sb);
  3932. if (bdev == NULL)
  3933. return NULL;
  3934. blocksize = sb->s_blocksize;
  3935. hblock = bdev_logical_block_size(bdev);
  3936. if (blocksize < hblock) {
  3937. ext4_msg(sb, KERN_ERR,
  3938. "blocksize too small for journal device");
  3939. goto out_bdev;
  3940. }
  3941. sb_block = EXT4_MIN_BLOCK_SIZE / blocksize;
  3942. offset = EXT4_MIN_BLOCK_SIZE % blocksize;
  3943. set_blocksize(bdev, blocksize);
  3944. if (!(bh = __bread(bdev, sb_block, blocksize))) {
  3945. ext4_msg(sb, KERN_ERR, "couldn't read superblock of "
  3946. "external journal");
  3947. goto out_bdev;
  3948. }
  3949. es = (struct ext4_super_block *) (bh->b_data + offset);
  3950. if ((le16_to_cpu(es->s_magic) != EXT4_SUPER_MAGIC) ||
  3951. !(le32_to_cpu(es->s_feature_incompat) &
  3952. EXT4_FEATURE_INCOMPAT_JOURNAL_DEV)) {
  3953. ext4_msg(sb, KERN_ERR, "external journal has "
  3954. "bad superblock");
  3955. brelse(bh);
  3956. goto out_bdev;
  3957. }
  3958. if ((le32_to_cpu(es->s_feature_ro_compat) &
  3959. EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) &&
  3960. es->s_checksum != ext4_superblock_csum(sb, es)) {
  3961. ext4_msg(sb, KERN_ERR, "external journal has "
  3962. "corrupt superblock");
  3963. brelse(bh);
  3964. goto out_bdev;
  3965. }
  3966. if (memcmp(EXT4_SB(sb)->s_es->s_journal_uuid, es->s_uuid, 16)) {
  3967. ext4_msg(sb, KERN_ERR, "journal UUID does not match");
  3968. brelse(bh);
  3969. goto out_bdev;
  3970. }
  3971. len = ext4_blocks_count(es);
  3972. start = sb_block + 1;
  3973. brelse(bh); /* we're done with the superblock */
  3974. journal = jbd2_journal_init_dev(bdev, sb->s_bdev,
  3975. start, len, blocksize);
  3976. if (!journal) {
  3977. ext4_msg(sb, KERN_ERR, "failed to create device journal");
  3978. goto out_bdev;
  3979. }
  3980. journal->j_private = sb;
  3981. ll_rw_block(READ | REQ_META | REQ_PRIO, 1, &journal->j_sb_buffer);
  3982. wait_on_buffer(journal->j_sb_buffer);
  3983. if (!buffer_uptodate(journal->j_sb_buffer)) {
  3984. ext4_msg(sb, KERN_ERR, "I/O error on journal device");
  3985. goto out_journal;
  3986. }
  3987. if (be32_to_cpu(journal->j_superblock->s_nr_users) != 1) {
  3988. ext4_msg(sb, KERN_ERR, "External journal has more than one "
  3989. "user (unsupported) - %d",
  3990. be32_to_cpu(journal->j_superblock->s_nr_users));
  3991. goto out_journal;
  3992. }
  3993. EXT4_SB(sb)->journal_bdev = bdev;
  3994. ext4_init_journal_params(sb, journal);
  3995. return journal;
  3996. out_journal:
  3997. jbd2_journal_destroy(journal);
  3998. out_bdev:
  3999. ext4_blkdev_put(bdev);
  4000. return NULL;
  4001. }
  4002. static int ext4_load_journal(struct super_block *sb,
  4003. struct ext4_super_block *es,
  4004. unsigned long journal_devnum)
  4005. {
  4006. journal_t *journal;
  4007. unsigned int journal_inum = le32_to_cpu(es->s_journal_inum);
  4008. dev_t journal_dev;
  4009. int err = 0;
  4010. int really_read_only;
  4011. BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL));
  4012. if (journal_devnum &&
  4013. journal_devnum != le32_to_cpu(es->s_journal_dev)) {
  4014. ext4_msg(sb, KERN_INFO, "external journal device major/minor "
  4015. "numbers have changed");
  4016. journal_dev = new_decode_dev(journal_devnum);
  4017. } else
  4018. journal_dev = new_decode_dev(le32_to_cpu(es->s_journal_dev));
  4019. really_read_only = bdev_read_only(sb->s_bdev);
  4020. /*
  4021. * Are we loading a blank journal or performing recovery after a
  4022. * crash? For recovery, we need to check in advance whether we
  4023. * can get read-write access to the device.
  4024. */
  4025. if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) {
  4026. if (sb->s_flags & MS_RDONLY) {
  4027. ext4_msg(sb, KERN_INFO, "INFO: recovery "
  4028. "required on readonly filesystem");
  4029. if (really_read_only) {
  4030. ext4_msg(sb, KERN_ERR, "write access "
  4031. "unavailable, cannot proceed");
  4032. return -EROFS;
  4033. }
  4034. ext4_msg(sb, KERN_INFO, "write access will "
  4035. "be enabled during recovery");
  4036. }
  4037. }
  4038. if (journal_inum && journal_dev) {
  4039. ext4_msg(sb, KERN_ERR, "filesystem has both journal "
  4040. "and inode journals!");
  4041. return -EINVAL;
  4042. }
  4043. if (journal_inum) {
  4044. if (!(journal = ext4_get_journal(sb, journal_inum)))
  4045. return -EINVAL;
  4046. } else {
  4047. if (!(journal = ext4_get_dev_journal(sb, journal_dev)))
  4048. return -EINVAL;
  4049. }
  4050. if (!(journal->j_flags & JBD2_BARRIER))
  4051. ext4_msg(sb, KERN_INFO, "barriers disabled");
  4052. if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER))
  4053. err = jbd2_journal_wipe(journal, !really_read_only);
  4054. if (!err) {
  4055. char *save = kmalloc(EXT4_S_ERR_LEN, GFP_KERNEL);
  4056. if (save)
  4057. memcpy(save, ((char *) es) +
  4058. EXT4_S_ERR_START, EXT4_S_ERR_LEN);
  4059. err = jbd2_journal_load(journal);
  4060. if (save)
  4061. memcpy(((char *) es) + EXT4_S_ERR_START,
  4062. save, EXT4_S_ERR_LEN);
  4063. kfree(save);
  4064. }
  4065. if (err) {
  4066. ext4_msg(sb, KERN_ERR, "error loading journal");
  4067. jbd2_journal_destroy(journal);
  4068. return err;
  4069. }
  4070. EXT4_SB(sb)->s_journal = journal;
  4071. ext4_clear_journal_err(sb, es);
  4072. if (!really_read_only && journal_devnum &&
  4073. journal_devnum != le32_to_cpu(es->s_journal_dev)) {
  4074. es->s_journal_dev = cpu_to_le32(journal_devnum);
  4075. /* Make sure we flush the recovery flag to disk. */
  4076. ext4_commit_super(sb, 1);
  4077. }
  4078. return 0;
  4079. }
  4080. static int ext4_commit_super(struct super_block *sb, int sync)
  4081. {
  4082. struct ext4_super_block *es = EXT4_SB(sb)->s_es;
  4083. struct buffer_head *sbh = EXT4_SB(sb)->s_sbh;
  4084. int error = 0;
  4085. if (!sbh)
  4086. return error;
  4087. if (buffer_write_io_error(sbh)) {
  4088. /*
  4089. * Oh, dear. A previous attempt to write the
  4090. * superblock failed. This could happen because the
  4091. * USB device was yanked out. Or it could happen to
  4092. * be a transient write error and maybe the block will
  4093. * be remapped. Nothing we can do but to retry the
  4094. * write and hope for the best.
  4095. */
  4096. ext4_msg(sb, KERN_ERR, "previous I/O error to "
  4097. "superblock detected");
  4098. clear_buffer_write_io_error(sbh);
  4099. set_buffer_uptodate(sbh);
  4100. }
  4101. /*
  4102. * If the file system is mounted read-only, don't update the
  4103. * superblock write time. This avoids updating the superblock
  4104. * write time when we are mounting the root file system
  4105. * read/only but we need to replay the journal; at that point,
  4106. * for people who are east of GMT and who make their clock
  4107. * tick in localtime for Windows bug-for-bug compatibility,
  4108. * the clock is set in the future, and this will cause e2fsck
  4109. * to complain and force a full file system check.
  4110. */
  4111. if (!(sb->s_flags & MS_RDONLY))
  4112. es->s_wtime = cpu_to_le32(get_seconds());
  4113. if (sb->s_bdev->bd_part)
  4114. es->s_kbytes_written =
  4115. cpu_to_le64(EXT4_SB(sb)->s_kbytes_written +
  4116. ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) -
  4117. EXT4_SB(sb)->s_sectors_written_start) >> 1));
  4118. else
  4119. es->s_kbytes_written =
  4120. cpu_to_le64(EXT4_SB(sb)->s_kbytes_written);
  4121. if (percpu_counter_initialized(&EXT4_SB(sb)->s_freeclusters_counter))
  4122. ext4_free_blocks_count_set(es,
  4123. EXT4_C2B(EXT4_SB(sb), percpu_counter_sum_positive(
  4124. &EXT4_SB(sb)->s_freeclusters_counter)));
  4125. if (percpu_counter_initialized(&EXT4_SB(sb)->s_freeinodes_counter))
  4126. es->s_free_inodes_count =
  4127. cpu_to_le32(percpu_counter_sum_positive(
  4128. &EXT4_SB(sb)->s_freeinodes_counter));
  4129. BUFFER_TRACE(sbh, "marking dirty");
  4130. ext4_superblock_csum_set(sb);
  4131. mark_buffer_dirty(sbh);
  4132. if (sync) {
  4133. error = sync_dirty_buffer(sbh);
  4134. if (error)
  4135. return error;
  4136. error = buffer_write_io_error(sbh);
  4137. if (error) {
  4138. ext4_msg(sb, KERN_ERR, "I/O error while writing "
  4139. "superblock");
  4140. clear_buffer_write_io_error(sbh);
  4141. set_buffer_uptodate(sbh);
  4142. }
  4143. }
  4144. return error;
  4145. }
  4146. /*
  4147. * Have we just finished recovery? If so, and if we are mounting (or
  4148. * remounting) the filesystem readonly, then we will end up with a
  4149. * consistent fs on disk. Record that fact.
  4150. */
  4151. static void ext4_mark_recovery_complete(struct super_block *sb,
  4152. struct ext4_super_block *es)
  4153. {
  4154. journal_t *journal = EXT4_SB(sb)->s_journal;
  4155. if (!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) {
  4156. BUG_ON(journal != NULL);
  4157. return;
  4158. }
  4159. jbd2_journal_lock_updates(journal);
  4160. if (jbd2_journal_flush(journal) < 0)
  4161. goto out;
  4162. if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER) &&
  4163. sb->s_flags & MS_RDONLY) {
  4164. EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
  4165. ext4_commit_super(sb, 1);
  4166. }
  4167. out:
  4168. jbd2_journal_unlock_updates(journal);
  4169. }
  4170. /*
  4171. * If we are mounting (or read-write remounting) a filesystem whose journal
  4172. * has recorded an error from a previous lifetime, move that error to the
  4173. * main filesystem now.
  4174. */
  4175. static void ext4_clear_journal_err(struct super_block *sb,
  4176. struct ext4_super_block *es)
  4177. {
  4178. journal_t *journal;
  4179. int j_errno;
  4180. const char *errstr;
  4181. BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL));
  4182. journal = EXT4_SB(sb)->s_journal;
  4183. /*
  4184. * Now check for any error status which may have been recorded in the
  4185. * journal by a prior ext4_error() or ext4_abort()
  4186. */
  4187. j_errno = jbd2_journal_errno(journal);
  4188. if (j_errno) {
  4189. char nbuf[16];
  4190. errstr = ext4_decode_error(sb, j_errno, nbuf);
  4191. ext4_warning(sb, "Filesystem error recorded "
  4192. "from previous mount: %s", errstr);
  4193. ext4_warning(sb, "Marking fs in need of filesystem check.");
  4194. EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
  4195. es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
  4196. ext4_commit_super(sb, 1);
  4197. jbd2_journal_clear_err(journal);
  4198. jbd2_journal_update_sb_errno(journal);
  4199. }
  4200. }
  4201. /*
  4202. * Force the running and committing transactions to commit,
  4203. * and wait on the commit.
  4204. */
  4205. int ext4_force_commit(struct super_block *sb)
  4206. {
  4207. journal_t *journal;
  4208. if (sb->s_flags & MS_RDONLY)
  4209. return 0;
  4210. journal = EXT4_SB(sb)->s_journal;
  4211. return ext4_journal_force_commit(journal);
  4212. }
  4213. static int ext4_sync_fs(struct super_block *sb, int wait)
  4214. {
  4215. int ret = 0;
  4216. tid_t target;
  4217. bool needs_barrier = false;
  4218. struct ext4_sb_info *sbi = EXT4_SB(sb);
  4219. trace_ext4_sync_fs(sb, wait);
  4220. flush_workqueue(sbi->rsv_conversion_wq);
  4221. /*
  4222. * Writeback quota in non-journalled quota case - journalled quota has
  4223. * no dirty dquots
  4224. */
  4225. dquot_writeback_dquots(sb, -1);
  4226. /*
  4227. * Data writeback is possible w/o journal transaction, so barrier must
  4228. * being sent at the end of the function. But we can skip it if
  4229. * transaction_commit will do it for us.
  4230. */
  4231. if (sbi->s_journal) {
  4232. target = jbd2_get_latest_transaction(sbi->s_journal);
  4233. if (wait && sbi->s_journal->j_flags & JBD2_BARRIER &&
  4234. !jbd2_trans_will_send_data_barrier(sbi->s_journal, target))
  4235. needs_barrier = true;
  4236. if (jbd2_journal_start_commit(sbi->s_journal, &target)) {
  4237. if (wait)
  4238. ret = jbd2_log_wait_commit(sbi->s_journal,
  4239. target);
  4240. }
  4241. } else if (wait && test_opt(sb, BARRIER))
  4242. needs_barrier = true;
  4243. if (needs_barrier) {
  4244. int err;
  4245. err = blkdev_issue_flush(sb->s_bdev, GFP_KERNEL, NULL);
  4246. if (!ret)
  4247. ret = err;
  4248. }
  4249. return ret;
  4250. }
  4251. /*
  4252. * LVM calls this function before a (read-only) snapshot is created. This
  4253. * gives us a chance to flush the journal completely and mark the fs clean.
  4254. *
  4255. * Note that only this function cannot bring a filesystem to be in a clean
  4256. * state independently. It relies on upper layer to stop all data & metadata
  4257. * modifications.
  4258. */
  4259. static int ext4_freeze(struct super_block *sb)
  4260. {
  4261. int error = 0;
  4262. journal_t *journal;
  4263. if (sb->s_flags & MS_RDONLY)
  4264. return 0;
  4265. journal = EXT4_SB(sb)->s_journal;
  4266. if (journal) {
  4267. /* Now we set up the journal barrier. */
  4268. jbd2_journal_lock_updates(journal);
  4269. /*
  4270. * Don't clear the needs_recovery flag if we failed to
  4271. * flush the journal.
  4272. */
  4273. error = jbd2_journal_flush(journal);
  4274. if (error < 0)
  4275. goto out;
  4276. }
  4277. /* Journal blocked and flushed, clear needs_recovery flag. */
  4278. EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
  4279. error = ext4_commit_super(sb, 1);
  4280. out:
  4281. if (journal)
  4282. /* we rely on upper layer to stop further updates */
  4283. jbd2_journal_unlock_updates(journal);
  4284. return error;
  4285. }
  4286. /*
  4287. * Called by LVM after the snapshot is done. We need to reset the RECOVER
  4288. * flag here, even though the filesystem is not technically dirty yet.
  4289. */
  4290. static int ext4_unfreeze(struct super_block *sb)
  4291. {
  4292. if (sb->s_flags & MS_RDONLY)
  4293. return 0;
  4294. /* Reset the needs_recovery flag before the fs is unlocked. */
  4295. EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
  4296. ext4_commit_super(sb, 1);
  4297. return 0;
  4298. }
  4299. /*
  4300. * Structure to save mount options for ext4_remount's benefit
  4301. */
  4302. struct ext4_mount_options {
  4303. unsigned long s_mount_opt;
  4304. unsigned long s_mount_opt2;
  4305. kuid_t s_resuid;
  4306. kgid_t s_resgid;
  4307. unsigned long s_commit_interval;
  4308. u32 s_min_batch_time, s_max_batch_time;
  4309. #ifdef CONFIG_QUOTA
  4310. int s_jquota_fmt;
  4311. char *s_qf_names[EXT4_MAXQUOTAS];
  4312. #endif
  4313. };
  4314. static int ext4_remount(struct super_block *sb, int *flags, char *data)
  4315. {
  4316. struct ext4_super_block *es;
  4317. struct ext4_sb_info *sbi = EXT4_SB(sb);
  4318. unsigned long old_sb_flags;
  4319. struct ext4_mount_options old_opts;
  4320. int enable_quota = 0;
  4321. ext4_group_t g;
  4322. unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO;
  4323. int err = 0;
  4324. #ifdef CONFIG_QUOTA
  4325. int i, j;
  4326. #endif
  4327. char *orig_data = kstrdup(data, GFP_KERNEL);
  4328. /* Store the original options */
  4329. old_sb_flags = sb->s_flags;
  4330. old_opts.s_mount_opt = sbi->s_mount_opt;
  4331. old_opts.s_mount_opt2 = sbi->s_mount_opt2;
  4332. old_opts.s_resuid = sbi->s_resuid;
  4333. old_opts.s_resgid = sbi->s_resgid;
  4334. old_opts.s_commit_interval = sbi->s_commit_interval;
  4335. old_opts.s_min_batch_time = sbi->s_min_batch_time;
  4336. old_opts.s_max_batch_time = sbi->s_max_batch_time;
  4337. #ifdef CONFIG_QUOTA
  4338. old_opts.s_jquota_fmt = sbi->s_jquota_fmt;
  4339. for (i = 0; i < EXT4_MAXQUOTAS; i++)
  4340. if (sbi->s_qf_names[i]) {
  4341. old_opts.s_qf_names[i] = kstrdup(sbi->s_qf_names[i],
  4342. GFP_KERNEL);
  4343. if (!old_opts.s_qf_names[i]) {
  4344. for (j = 0; j < i; j++)
  4345. kfree(old_opts.s_qf_names[j]);
  4346. kfree(orig_data);
  4347. return -ENOMEM;
  4348. }
  4349. } else
  4350. old_opts.s_qf_names[i] = NULL;
  4351. #endif
  4352. if (sbi->s_journal && sbi->s_journal->j_task->io_context)
  4353. journal_ioprio = sbi->s_journal->j_task->io_context->ioprio;
  4354. if (!parse_options(data, sb, NULL, &journal_ioprio, 1)) {
  4355. err = -EINVAL;
  4356. goto restore_opts;
  4357. }
  4358. if ((old_opts.s_mount_opt & EXT4_MOUNT_JOURNAL_CHECKSUM) ^
  4359. test_opt(sb, JOURNAL_CHECKSUM)) {
  4360. ext4_msg(sb, KERN_ERR, "changing journal_checksum "
  4361. "during remount not supported; ignoring");
  4362. sbi->s_mount_opt ^= EXT4_MOUNT_JOURNAL_CHECKSUM;
  4363. }
  4364. if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) {
  4365. if (test_opt2(sb, EXPLICIT_DELALLOC)) {
  4366. ext4_msg(sb, KERN_ERR, "can't mount with "
  4367. "both data=journal and delalloc");
  4368. err = -EINVAL;
  4369. goto restore_opts;
  4370. }
  4371. if (test_opt(sb, DIOREAD_NOLOCK)) {
  4372. ext4_msg(sb, KERN_ERR, "can't mount with "
  4373. "both data=journal and dioread_nolock");
  4374. err = -EINVAL;
  4375. goto restore_opts;
  4376. }
  4377. if (test_opt(sb, DAX)) {
  4378. ext4_msg(sb, KERN_ERR, "can't mount with "
  4379. "both data=journal and dax");
  4380. err = -EINVAL;
  4381. goto restore_opts;
  4382. }
  4383. }
  4384. if ((sbi->s_mount_opt ^ old_opts.s_mount_opt) & EXT4_MOUNT_DAX) {
  4385. ext4_msg(sb, KERN_WARNING, "warning: refusing change of "
  4386. "dax flag with busy inodes while remounting");
  4387. sbi->s_mount_opt ^= EXT4_MOUNT_DAX;
  4388. }
  4389. if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
  4390. ext4_abort(sb, "Abort forced by user");
  4391. sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
  4392. (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
  4393. es = sbi->s_es;
  4394. if (sbi->s_journal) {
  4395. ext4_init_journal_params(sb, sbi->s_journal);
  4396. set_task_ioprio(sbi->s_journal->j_task, journal_ioprio);
  4397. }
  4398. if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
  4399. if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED) {
  4400. err = -EROFS;
  4401. goto restore_opts;
  4402. }
  4403. if (*flags & MS_RDONLY) {
  4404. err = sync_filesystem(sb);
  4405. if (err < 0)
  4406. goto restore_opts;
  4407. err = dquot_suspend(sb, -1);
  4408. if (err < 0)
  4409. goto restore_opts;
  4410. /*
  4411. * First of all, the unconditional stuff we have to do
  4412. * to disable replay of the journal when we next remount
  4413. */
  4414. sb->s_flags |= MS_RDONLY;
  4415. /*
  4416. * OK, test if we are remounting a valid rw partition
  4417. * readonly, and if so set the rdonly flag and then
  4418. * mark the partition as valid again.
  4419. */
  4420. if (!(es->s_state & cpu_to_le16(EXT4_VALID_FS)) &&
  4421. (sbi->s_mount_state & EXT4_VALID_FS))
  4422. es->s_state = cpu_to_le16(sbi->s_mount_state);
  4423. if (sbi->s_journal)
  4424. ext4_mark_recovery_complete(sb, es);
  4425. } else {
  4426. /* Make sure we can mount this feature set readwrite */
  4427. if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
  4428. EXT4_FEATURE_RO_COMPAT_READONLY) ||
  4429. !ext4_feature_set_ok(sb, 0)) {
  4430. err = -EROFS;
  4431. goto restore_opts;
  4432. }
  4433. /*
  4434. * Make sure the group descriptor checksums
  4435. * are sane. If they aren't, refuse to remount r/w.
  4436. */
  4437. for (g = 0; g < sbi->s_groups_count; g++) {
  4438. struct ext4_group_desc *gdp =
  4439. ext4_get_group_desc(sb, g, NULL);
  4440. if (!ext4_group_desc_csum_verify(sb, g, gdp)) {
  4441. ext4_msg(sb, KERN_ERR,
  4442. "ext4_remount: Checksum for group %u failed (%u!=%u)",
  4443. g, le16_to_cpu(ext4_group_desc_csum(sbi, g, gdp)),
  4444. le16_to_cpu(gdp->bg_checksum));
  4445. err = -EINVAL;
  4446. goto restore_opts;
  4447. }
  4448. }
  4449. /*
  4450. * If we have an unprocessed orphan list hanging
  4451. * around from a previously readonly bdev mount,
  4452. * require a full umount/remount for now.
  4453. */
  4454. if (es->s_last_orphan) {
  4455. ext4_msg(sb, KERN_WARNING, "Couldn't "
  4456. "remount RDWR because of unprocessed "
  4457. "orphan inode list. Please "
  4458. "umount/remount instead");
  4459. err = -EINVAL;
  4460. goto restore_opts;
  4461. }
  4462. /*
  4463. * Mounting a RDONLY partition read-write, so reread
  4464. * and store the current valid flag. (It may have
  4465. * been changed by e2fsck since we originally mounted
  4466. * the partition.)
  4467. */
  4468. if (sbi->s_journal)
  4469. ext4_clear_journal_err(sb, es);
  4470. sbi->s_mount_state = le16_to_cpu(es->s_state);
  4471. if (!ext4_setup_super(sb, es, 0))
  4472. sb->s_flags &= ~MS_RDONLY;
  4473. if (EXT4_HAS_INCOMPAT_FEATURE(sb,
  4474. EXT4_FEATURE_INCOMPAT_MMP))
  4475. if (ext4_multi_mount_protect(sb,
  4476. le64_to_cpu(es->s_mmp_block))) {
  4477. err = -EROFS;
  4478. goto restore_opts;
  4479. }
  4480. enable_quota = 1;
  4481. }
  4482. }
  4483. /*
  4484. * Reinitialize lazy itable initialization thread based on
  4485. * current settings
  4486. */
  4487. if ((sb->s_flags & MS_RDONLY) || !test_opt(sb, INIT_INODE_TABLE))
  4488. ext4_unregister_li_request(sb);
  4489. else {
  4490. ext4_group_t first_not_zeroed;
  4491. first_not_zeroed = ext4_has_uninit_itable(sb);
  4492. ext4_register_li_request(sb, first_not_zeroed);
  4493. }
  4494. ext4_setup_system_zone(sb);
  4495. if (sbi->s_journal == NULL && !(old_sb_flags & MS_RDONLY))
  4496. ext4_commit_super(sb, 1);
  4497. #ifdef CONFIG_QUOTA
  4498. /* Release old quota file names */
  4499. for (i = 0; i < EXT4_MAXQUOTAS; i++)
  4500. kfree(old_opts.s_qf_names[i]);
  4501. if (enable_quota) {
  4502. if (sb_any_quota_suspended(sb))
  4503. dquot_resume(sb, -1);
  4504. else if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
  4505. EXT4_FEATURE_RO_COMPAT_QUOTA)) {
  4506. err = ext4_enable_quotas(sb);
  4507. if (err)
  4508. goto restore_opts;
  4509. }
  4510. }
  4511. #endif
  4512. *flags = (*flags & ~MS_LAZYTIME) | (sb->s_flags & MS_LAZYTIME);
  4513. ext4_msg(sb, KERN_INFO, "re-mounted. Opts: %s", orig_data);
  4514. kfree(orig_data);
  4515. return 0;
  4516. restore_opts:
  4517. sb->s_flags = old_sb_flags;
  4518. sbi->s_mount_opt = old_opts.s_mount_opt;
  4519. sbi->s_mount_opt2 = old_opts.s_mount_opt2;
  4520. sbi->s_resuid = old_opts.s_resuid;
  4521. sbi->s_resgid = old_opts.s_resgid;
  4522. sbi->s_commit_interval = old_opts.s_commit_interval;
  4523. sbi->s_min_batch_time = old_opts.s_min_batch_time;
  4524. sbi->s_max_batch_time = old_opts.s_max_batch_time;
  4525. #ifdef CONFIG_QUOTA
  4526. sbi->s_jquota_fmt = old_opts.s_jquota_fmt;
  4527. for (i = 0; i < EXT4_MAXQUOTAS; i++) {
  4528. kfree(sbi->s_qf_names[i]);
  4529. sbi->s_qf_names[i] = old_opts.s_qf_names[i];
  4530. }
  4531. #endif
  4532. kfree(orig_data);
  4533. return err;
  4534. }
  4535. static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf)
  4536. {
  4537. struct super_block *sb = dentry->d_sb;
  4538. struct ext4_sb_info *sbi = EXT4_SB(sb);
  4539. struct ext4_super_block *es = sbi->s_es;
  4540. ext4_fsblk_t overhead = 0, resv_blocks;
  4541. u64 fsid;
  4542. s64 bfree;
  4543. resv_blocks = EXT4_C2B(sbi, atomic64_read(&sbi->s_resv_clusters));
  4544. if (!test_opt(sb, MINIX_DF))
  4545. overhead = sbi->s_overhead;
  4546. buf->f_type = EXT4_SUPER_MAGIC;
  4547. buf->f_bsize = sb->s_blocksize;
  4548. buf->f_blocks = ext4_blocks_count(es) - EXT4_C2B(sbi, overhead);
  4549. bfree = percpu_counter_sum_positive(&sbi->s_freeclusters_counter) -
  4550. percpu_counter_sum_positive(&sbi->s_dirtyclusters_counter);
  4551. /* prevent underflow in case that few free space is available */
  4552. buf->f_bfree = EXT4_C2B(sbi, max_t(s64, bfree, 0));
  4553. buf->f_bavail = buf->f_bfree -
  4554. (ext4_r_blocks_count(es) + resv_blocks);
  4555. if (buf->f_bfree < (ext4_r_blocks_count(es) + resv_blocks))
  4556. buf->f_bavail = 0;
  4557. buf->f_files = le32_to_cpu(es->s_inodes_count);
  4558. buf->f_ffree = percpu_counter_sum_positive(&sbi->s_freeinodes_counter);
  4559. buf->f_namelen = EXT4_NAME_LEN;
  4560. fsid = le64_to_cpup((void *)es->s_uuid) ^
  4561. le64_to_cpup((void *)es->s_uuid + sizeof(u64));
  4562. buf->f_fsid.val[0] = fsid & 0xFFFFFFFFUL;
  4563. buf->f_fsid.val[1] = (fsid >> 32) & 0xFFFFFFFFUL;
  4564. return 0;
  4565. }
  4566. /* Helper function for writing quotas on sync - we need to start transaction
  4567. * before quota file is locked for write. Otherwise the are possible deadlocks:
  4568. * Process 1 Process 2
  4569. * ext4_create() quota_sync()
  4570. * jbd2_journal_start() write_dquot()
  4571. * dquot_initialize() down(dqio_mutex)
  4572. * down(dqio_mutex) jbd2_journal_start()
  4573. *
  4574. */
  4575. #ifdef CONFIG_QUOTA
  4576. static inline struct inode *dquot_to_inode(struct dquot *dquot)
  4577. {
  4578. return sb_dqopt(dquot->dq_sb)->files[dquot->dq_id.type];
  4579. }
  4580. static int ext4_write_dquot(struct dquot *dquot)
  4581. {
  4582. int ret, err;
  4583. handle_t *handle;
  4584. struct inode *inode;
  4585. inode = dquot_to_inode(dquot);
  4586. handle = ext4_journal_start(inode, EXT4_HT_QUOTA,
  4587. EXT4_QUOTA_TRANS_BLOCKS(dquot->dq_sb));
  4588. if (IS_ERR(handle))
  4589. return PTR_ERR(handle);
  4590. ret = dquot_commit(dquot);
  4591. err = ext4_journal_stop(handle);
  4592. if (!ret)
  4593. ret = err;
  4594. return ret;
  4595. }
  4596. static int ext4_acquire_dquot(struct dquot *dquot)
  4597. {
  4598. int ret, err;
  4599. handle_t *handle;
  4600. handle = ext4_journal_start(dquot_to_inode(dquot), EXT4_HT_QUOTA,
  4601. EXT4_QUOTA_INIT_BLOCKS(dquot->dq_sb));
  4602. if (IS_ERR(handle))
  4603. return PTR_ERR(handle);
  4604. ret = dquot_acquire(dquot);
  4605. err = ext4_journal_stop(handle);
  4606. if (!ret)
  4607. ret = err;
  4608. return ret;
  4609. }
  4610. static int ext4_release_dquot(struct dquot *dquot)
  4611. {
  4612. int ret, err;
  4613. handle_t *handle;
  4614. handle = ext4_journal_start(dquot_to_inode(dquot), EXT4_HT_QUOTA,
  4615. EXT4_QUOTA_DEL_BLOCKS(dquot->dq_sb));
  4616. if (IS_ERR(handle)) {
  4617. /* Release dquot anyway to avoid endless cycle in dqput() */
  4618. dquot_release(dquot);
  4619. return PTR_ERR(handle);
  4620. }
  4621. ret = dquot_release(dquot);
  4622. err = ext4_journal_stop(handle);
  4623. if (!ret)
  4624. ret = err;
  4625. return ret;
  4626. }
  4627. static int ext4_mark_dquot_dirty(struct dquot *dquot)
  4628. {
  4629. struct super_block *sb = dquot->dq_sb;
  4630. struct ext4_sb_info *sbi = EXT4_SB(sb);
  4631. /* Are we journaling quotas? */
  4632. if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_QUOTA) ||
  4633. sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) {
  4634. dquot_mark_dquot_dirty(dquot);
  4635. return ext4_write_dquot(dquot);
  4636. } else {
  4637. return dquot_mark_dquot_dirty(dquot);
  4638. }
  4639. }
  4640. static int ext4_write_info(struct super_block *sb, int type)
  4641. {
  4642. int ret, err;
  4643. handle_t *handle;
  4644. /* Data block + inode block */
  4645. handle = ext4_journal_start(d_inode(sb->s_root), EXT4_HT_QUOTA, 2);
  4646. if (IS_ERR(handle))
  4647. return PTR_ERR(handle);
  4648. ret = dquot_commit_info(sb, type);
  4649. err = ext4_journal_stop(handle);
  4650. if (!ret)
  4651. ret = err;
  4652. return ret;
  4653. }
  4654. /*
  4655. * Turn on quotas during mount time - we need to find
  4656. * the quota file and such...
  4657. */
  4658. static int ext4_quota_on_mount(struct super_block *sb, int type)
  4659. {
  4660. return dquot_quota_on_mount(sb, EXT4_SB(sb)->s_qf_names[type],
  4661. EXT4_SB(sb)->s_jquota_fmt, type);
  4662. }
  4663. /*
  4664. * Standard function to be called on quota_on
  4665. */
  4666. static int ext4_quota_on(struct super_block *sb, int type, int format_id,
  4667. struct path *path)
  4668. {
  4669. int err;
  4670. if (!test_opt(sb, QUOTA))
  4671. return -EINVAL;
  4672. /* Quotafile not on the same filesystem? */
  4673. if (path->dentry->d_sb != sb)
  4674. return -EXDEV;
  4675. /* Journaling quota? */
  4676. if (EXT4_SB(sb)->s_qf_names[type]) {
  4677. /* Quotafile not in fs root? */
  4678. if (path->dentry->d_parent != sb->s_root)
  4679. ext4_msg(sb, KERN_WARNING,
  4680. "Quota file not on filesystem root. "
  4681. "Journaled quota will not work");
  4682. }
  4683. /*
  4684. * When we journal data on quota file, we have to flush journal to see
  4685. * all updates to the file when we bypass pagecache...
  4686. */
  4687. if (EXT4_SB(sb)->s_journal &&
  4688. ext4_should_journal_data(d_inode(path->dentry))) {
  4689. /*
  4690. * We don't need to lock updates but journal_flush() could
  4691. * otherwise be livelocked...
  4692. */
  4693. jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal);
  4694. err = jbd2_journal_flush(EXT4_SB(sb)->s_journal);
  4695. jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
  4696. if (err)
  4697. return err;
  4698. }
  4699. return dquot_quota_on(sb, type, format_id, path);
  4700. }
  4701. static int ext4_quota_enable(struct super_block *sb, int type, int format_id,
  4702. unsigned int flags)
  4703. {
  4704. int err;
  4705. struct inode *qf_inode;
  4706. unsigned long qf_inums[EXT4_MAXQUOTAS] = {
  4707. le32_to_cpu(EXT4_SB(sb)->s_es->s_usr_quota_inum),
  4708. le32_to_cpu(EXT4_SB(sb)->s_es->s_grp_quota_inum)
  4709. };
  4710. BUG_ON(!EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_QUOTA));
  4711. if (!qf_inums[type])
  4712. return -EPERM;
  4713. qf_inode = ext4_iget(sb, qf_inums[type]);
  4714. if (IS_ERR(qf_inode)) {
  4715. ext4_error(sb, "Bad quota inode # %lu", qf_inums[type]);
  4716. return PTR_ERR(qf_inode);
  4717. }
  4718. /* Don't account quota for quota files to avoid recursion */
  4719. qf_inode->i_flags |= S_NOQUOTA;
  4720. err = dquot_enable(qf_inode, type, format_id, flags);
  4721. iput(qf_inode);
  4722. return err;
  4723. }
  4724. /* Enable usage tracking for all quota types. */
  4725. static int ext4_enable_quotas(struct super_block *sb)
  4726. {
  4727. int type, err = 0;
  4728. unsigned long qf_inums[EXT4_MAXQUOTAS] = {
  4729. le32_to_cpu(EXT4_SB(sb)->s_es->s_usr_quota_inum),
  4730. le32_to_cpu(EXT4_SB(sb)->s_es->s_grp_quota_inum)
  4731. };
  4732. sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE;
  4733. for (type = 0; type < EXT4_MAXQUOTAS; type++) {
  4734. if (qf_inums[type]) {
  4735. err = ext4_quota_enable(sb, type, QFMT_VFS_V1,
  4736. DQUOT_USAGE_ENABLED);
  4737. if (err) {
  4738. ext4_warning(sb,
  4739. "Failed to enable quota tracking "
  4740. "(type=%d, err=%d). Please run "
  4741. "e2fsck to fix.", type, err);
  4742. return err;
  4743. }
  4744. }
  4745. }
  4746. return 0;
  4747. }
  4748. static int ext4_quota_off(struct super_block *sb, int type)
  4749. {
  4750. struct inode *inode = sb_dqopt(sb)->files[type];
  4751. handle_t *handle;
  4752. /* Force all delayed allocation blocks to be allocated.
  4753. * Caller already holds s_umount sem */
  4754. if (test_opt(sb, DELALLOC))
  4755. sync_filesystem(sb);
  4756. if (!inode)
  4757. goto out;
  4758. /* Update modification times of quota files when userspace can
  4759. * start looking at them */
  4760. handle = ext4_journal_start(inode, EXT4_HT_QUOTA, 1);
  4761. if (IS_ERR(handle))
  4762. goto out;
  4763. inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  4764. ext4_mark_inode_dirty(handle, inode);
  4765. ext4_journal_stop(handle);
  4766. out:
  4767. return dquot_quota_off(sb, type);
  4768. }
  4769. /* Read data from quotafile - avoid pagecache and such because we cannot afford
  4770. * acquiring the locks... As quota files are never truncated and quota code
  4771. * itself serializes the operations (and no one else should touch the files)
  4772. * we don't have to be afraid of races */
  4773. static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data,
  4774. size_t len, loff_t off)
  4775. {
  4776. struct inode *inode = sb_dqopt(sb)->files[type];
  4777. ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb);
  4778. int offset = off & (sb->s_blocksize - 1);
  4779. int tocopy;
  4780. size_t toread;
  4781. struct buffer_head *bh;
  4782. loff_t i_size = i_size_read(inode);
  4783. if (off > i_size)
  4784. return 0;
  4785. if (off+len > i_size)
  4786. len = i_size-off;
  4787. toread = len;
  4788. while (toread > 0) {
  4789. tocopy = sb->s_blocksize - offset < toread ?
  4790. sb->s_blocksize - offset : toread;
  4791. bh = ext4_bread(NULL, inode, blk, 0);
  4792. if (IS_ERR(bh))
  4793. return PTR_ERR(bh);
  4794. if (!bh) /* A hole? */
  4795. memset(data, 0, tocopy);
  4796. else
  4797. memcpy(data, bh->b_data+offset, tocopy);
  4798. brelse(bh);
  4799. offset = 0;
  4800. toread -= tocopy;
  4801. data += tocopy;
  4802. blk++;
  4803. }
  4804. return len;
  4805. }
  4806. /* Write to quotafile (we know the transaction is already started and has
  4807. * enough credits) */
  4808. static ssize_t ext4_quota_write(struct super_block *sb, int type,
  4809. const char *data, size_t len, loff_t off)
  4810. {
  4811. struct inode *inode = sb_dqopt(sb)->files[type];
  4812. ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb);
  4813. int err, offset = off & (sb->s_blocksize - 1);
  4814. struct buffer_head *bh;
  4815. handle_t *handle = journal_current_handle();
  4816. if (EXT4_SB(sb)->s_journal && !handle) {
  4817. ext4_msg(sb, KERN_WARNING, "Quota write (off=%llu, len=%llu)"
  4818. " cancelled because transaction is not started",
  4819. (unsigned long long)off, (unsigned long long)len);
  4820. return -EIO;
  4821. }
  4822. /*
  4823. * Since we account only one data block in transaction credits,
  4824. * then it is impossible to cross a block boundary.
  4825. */
  4826. if (sb->s_blocksize - offset < len) {
  4827. ext4_msg(sb, KERN_WARNING, "Quota write (off=%llu, len=%llu)"
  4828. " cancelled because not block aligned",
  4829. (unsigned long long)off, (unsigned long long)len);
  4830. return -EIO;
  4831. }
  4832. bh = ext4_bread(handle, inode, blk, 1);
  4833. if (IS_ERR(bh))
  4834. return PTR_ERR(bh);
  4835. if (!bh)
  4836. goto out;
  4837. BUFFER_TRACE(bh, "get write access");
  4838. err = ext4_journal_get_write_access(handle, bh);
  4839. if (err) {
  4840. brelse(bh);
  4841. return err;
  4842. }
  4843. lock_buffer(bh);
  4844. memcpy(bh->b_data+offset, data, len);
  4845. flush_dcache_page(bh->b_page);
  4846. unlock_buffer(bh);
  4847. err = ext4_handle_dirty_metadata(handle, NULL, bh);
  4848. brelse(bh);
  4849. out:
  4850. if (inode->i_size < off + len) {
  4851. i_size_write(inode, off + len);
  4852. EXT4_I(inode)->i_disksize = inode->i_size;
  4853. ext4_mark_inode_dirty(handle, inode);
  4854. }
  4855. return len;
  4856. }
  4857. #endif
  4858. static struct dentry *ext4_mount(struct file_system_type *fs_type, int flags,
  4859. const char *dev_name, void *data)
  4860. {
  4861. return mount_bdev(fs_type, flags, dev_name, data, ext4_fill_super);
  4862. }
  4863. #if !defined(CONFIG_EXT2_FS) && !defined(CONFIG_EXT2_FS_MODULE) && defined(CONFIG_EXT4_USE_FOR_EXT23)
  4864. static inline void register_as_ext2(void)
  4865. {
  4866. int err = register_filesystem(&ext2_fs_type);
  4867. if (err)
  4868. printk(KERN_WARNING
  4869. "EXT4-fs: Unable to register as ext2 (%d)\n", err);
  4870. }
  4871. static inline void unregister_as_ext2(void)
  4872. {
  4873. unregister_filesystem(&ext2_fs_type);
  4874. }
  4875. static inline int ext2_feature_set_ok(struct super_block *sb)
  4876. {
  4877. if (EXT4_HAS_INCOMPAT_FEATURE(sb, ~EXT2_FEATURE_INCOMPAT_SUPP))
  4878. return 0;
  4879. if (sb->s_flags & MS_RDONLY)
  4880. return 1;
  4881. if (EXT4_HAS_RO_COMPAT_FEATURE(sb, ~EXT2_FEATURE_RO_COMPAT_SUPP))
  4882. return 0;
  4883. return 1;
  4884. }
  4885. #else
  4886. static inline void register_as_ext2(void) { }
  4887. static inline void unregister_as_ext2(void) { }
  4888. static inline int ext2_feature_set_ok(struct super_block *sb) { return 0; }
  4889. #endif
  4890. #if !defined(CONFIG_EXT3_FS) && !defined(CONFIG_EXT3_FS_MODULE) && defined(CONFIG_EXT4_USE_FOR_EXT23)
  4891. static inline void register_as_ext3(void)
  4892. {
  4893. int err = register_filesystem(&ext3_fs_type);
  4894. if (err)
  4895. printk(KERN_WARNING
  4896. "EXT4-fs: Unable to register as ext3 (%d)\n", err);
  4897. }
  4898. static inline void unregister_as_ext3(void)
  4899. {
  4900. unregister_filesystem(&ext3_fs_type);
  4901. }
  4902. static inline int ext3_feature_set_ok(struct super_block *sb)
  4903. {
  4904. if (EXT4_HAS_INCOMPAT_FEATURE(sb, ~EXT3_FEATURE_INCOMPAT_SUPP))
  4905. return 0;
  4906. if (!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL))
  4907. return 0;
  4908. if (sb->s_flags & MS_RDONLY)
  4909. return 1;
  4910. if (EXT4_HAS_RO_COMPAT_FEATURE(sb, ~EXT3_FEATURE_RO_COMPAT_SUPP))
  4911. return 0;
  4912. return 1;
  4913. }
  4914. #else
  4915. static inline void register_as_ext3(void) { }
  4916. static inline void unregister_as_ext3(void) { }
  4917. static inline int ext3_feature_set_ok(struct super_block *sb) { return 0; }
  4918. #endif
  4919. static struct file_system_type ext4_fs_type = {
  4920. .owner = THIS_MODULE,
  4921. .name = "ext4",
  4922. .mount = ext4_mount,
  4923. .kill_sb = kill_block_super,
  4924. .fs_flags = FS_REQUIRES_DEV,
  4925. };
  4926. MODULE_ALIAS_FS("ext4");
  4927. static int __init ext4_init_feat_adverts(void)
  4928. {
  4929. struct ext4_features *ef;
  4930. int ret = -ENOMEM;
  4931. ef = kzalloc(sizeof(struct ext4_features), GFP_KERNEL);
  4932. if (!ef)
  4933. goto out;
  4934. ef->f_kobj.kset = ext4_kset;
  4935. init_completion(&ef->f_kobj_unregister);
  4936. ret = kobject_init_and_add(&ef->f_kobj, &ext4_feat_ktype, NULL,
  4937. "features");
  4938. if (ret) {
  4939. kfree(ef);
  4940. goto out;
  4941. }
  4942. ext4_feat = ef;
  4943. ret = 0;
  4944. out:
  4945. return ret;
  4946. }
  4947. static void ext4_exit_feat_adverts(void)
  4948. {
  4949. kobject_put(&ext4_feat->f_kobj);
  4950. wait_for_completion(&ext4_feat->f_kobj_unregister);
  4951. kfree(ext4_feat);
  4952. }
  4953. /* Shared across all ext4 file systems */
  4954. wait_queue_head_t ext4__ioend_wq[EXT4_WQ_HASH_SZ];
  4955. struct mutex ext4__aio_mutex[EXT4_WQ_HASH_SZ];
  4956. static int __init ext4_init_fs(void)
  4957. {
  4958. int i, err;
  4959. ext4_li_info = NULL;
  4960. mutex_init(&ext4_li_mtx);
  4961. /* Build-time check for flags consistency */
  4962. ext4_check_flag_values();
  4963. for (i = 0; i < EXT4_WQ_HASH_SZ; i++) {
  4964. mutex_init(&ext4__aio_mutex[i]);
  4965. init_waitqueue_head(&ext4__ioend_wq[i]);
  4966. }
  4967. err = ext4_init_es();
  4968. if (err)
  4969. return err;
  4970. err = ext4_init_pageio();
  4971. if (err)
  4972. goto out7;
  4973. err = ext4_init_system_zone();
  4974. if (err)
  4975. goto out6;
  4976. ext4_kset = kset_create_and_add("ext4", NULL, fs_kobj);
  4977. if (!ext4_kset) {
  4978. err = -ENOMEM;
  4979. goto out5;
  4980. }
  4981. ext4_proc_root = proc_mkdir("fs/ext4", NULL);
  4982. err = ext4_init_feat_adverts();
  4983. if (err)
  4984. goto out4;
  4985. err = ext4_init_mballoc();
  4986. if (err)
  4987. goto out2;
  4988. else
  4989. ext4_mballoc_ready = 1;
  4990. err = init_inodecache();
  4991. if (err)
  4992. goto out1;
  4993. register_as_ext3();
  4994. register_as_ext2();
  4995. err = register_filesystem(&ext4_fs_type);
  4996. if (err)
  4997. goto out;
  4998. return 0;
  4999. out:
  5000. unregister_as_ext2();
  5001. unregister_as_ext3();
  5002. destroy_inodecache();
  5003. out1:
  5004. ext4_mballoc_ready = 0;
  5005. ext4_exit_mballoc();
  5006. out2:
  5007. ext4_exit_feat_adverts();
  5008. out4:
  5009. if (ext4_proc_root)
  5010. remove_proc_entry("fs/ext4", NULL);
  5011. kset_unregister(ext4_kset);
  5012. out5:
  5013. ext4_exit_system_zone();
  5014. out6:
  5015. ext4_exit_pageio();
  5016. out7:
  5017. ext4_exit_es();
  5018. return err;
  5019. }
  5020. static void __exit ext4_exit_fs(void)
  5021. {
  5022. ext4_destroy_lazyinit_thread();
  5023. unregister_as_ext2();
  5024. unregister_as_ext3();
  5025. unregister_filesystem(&ext4_fs_type);
  5026. destroy_inodecache();
  5027. ext4_exit_mballoc();
  5028. ext4_exit_feat_adverts();
  5029. remove_proc_entry("fs/ext4", NULL);
  5030. kset_unregister(ext4_kset);
  5031. ext4_exit_system_zone();
  5032. ext4_exit_pageio();
  5033. ext4_exit_es();
  5034. }
  5035. MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others");
  5036. MODULE_DESCRIPTION("Fourth Extended Filesystem");
  5037. MODULE_LICENSE("GPL");
  5038. module_init(ext4_init_fs)
  5039. module_exit(ext4_exit_fs)