super.c 105 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735
  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/jbd2.h>
  23. #include <linux/slab.h>
  24. #include <linux/init.h>
  25. #include <linux/blkdev.h>
  26. #include <linux/parser.h>
  27. #include <linux/smp_lock.h>
  28. #include <linux/buffer_head.h>
  29. #include <linux/exportfs.h>
  30. #include <linux/vfs.h>
  31. #include <linux/random.h>
  32. #include <linux/mount.h>
  33. #include <linux/namei.h>
  34. #include <linux/quotaops.h>
  35. #include <linux/seq_file.h>
  36. #include <linux/proc_fs.h>
  37. #include <linux/marker.h>
  38. #include <linux/log2.h>
  39. #include <linux/crc16.h>
  40. #include <asm/uaccess.h>
  41. #include "ext4.h"
  42. #include "ext4_jbd2.h"
  43. #include "xattr.h"
  44. #include "acl.h"
  45. #include "namei.h"
  46. #include "group.h"
  47. struct proc_dir_entry *ext4_proc_root;
  48. static int ext4_load_journal(struct super_block *, struct ext4_super_block *,
  49. unsigned long journal_devnum);
  50. static int ext4_create_journal(struct super_block *, struct ext4_super_block *,
  51. unsigned int);
  52. static void ext4_commit_super(struct super_block *sb,
  53. struct ext4_super_block *es, int sync);
  54. static void ext4_mark_recovery_complete(struct super_block *sb,
  55. struct ext4_super_block *es);
  56. static void ext4_clear_journal_err(struct super_block *sb,
  57. struct ext4_super_block *es);
  58. static int ext4_sync_fs(struct super_block *sb, int wait);
  59. static const char *ext4_decode_error(struct super_block *sb, int errno,
  60. char nbuf[16]);
  61. static int ext4_remount(struct super_block *sb, int *flags, char *data);
  62. static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf);
  63. static void ext4_unlockfs(struct super_block *sb);
  64. static void ext4_write_super(struct super_block *sb);
  65. static void ext4_write_super_lockfs(struct super_block *sb);
  66. ext4_fsblk_t ext4_block_bitmap(struct super_block *sb,
  67. struct ext4_group_desc *bg)
  68. {
  69. return le32_to_cpu(bg->bg_block_bitmap_lo) |
  70. (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
  71. (ext4_fsblk_t)le32_to_cpu(bg->bg_block_bitmap_hi) << 32 : 0);
  72. }
  73. ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb,
  74. struct ext4_group_desc *bg)
  75. {
  76. return le32_to_cpu(bg->bg_inode_bitmap_lo) |
  77. (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
  78. (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_bitmap_hi) << 32 : 0);
  79. }
  80. ext4_fsblk_t ext4_inode_table(struct super_block *sb,
  81. struct ext4_group_desc *bg)
  82. {
  83. return le32_to_cpu(bg->bg_inode_table_lo) |
  84. (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
  85. (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_table_hi) << 32 : 0);
  86. }
  87. void ext4_block_bitmap_set(struct super_block *sb,
  88. struct ext4_group_desc *bg, ext4_fsblk_t blk)
  89. {
  90. bg->bg_block_bitmap_lo = cpu_to_le32((u32)blk);
  91. if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
  92. bg->bg_block_bitmap_hi = cpu_to_le32(blk >> 32);
  93. }
  94. void ext4_inode_bitmap_set(struct super_block *sb,
  95. struct ext4_group_desc *bg, ext4_fsblk_t blk)
  96. {
  97. bg->bg_inode_bitmap_lo = cpu_to_le32((u32)blk);
  98. if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
  99. bg->bg_inode_bitmap_hi = cpu_to_le32(blk >> 32);
  100. }
  101. void ext4_inode_table_set(struct super_block *sb,
  102. struct ext4_group_desc *bg, ext4_fsblk_t blk)
  103. {
  104. bg->bg_inode_table_lo = cpu_to_le32((u32)blk);
  105. if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
  106. bg->bg_inode_table_hi = cpu_to_le32(blk >> 32);
  107. }
  108. /*
  109. * Wrappers for jbd2_journal_start/end.
  110. *
  111. * The only special thing we need to do here is to make sure that all
  112. * journal_end calls result in the superblock being marked dirty, so
  113. * that sync() will call the filesystem's write_super callback if
  114. * appropriate.
  115. */
  116. handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks)
  117. {
  118. journal_t *journal;
  119. if (sb->s_flags & MS_RDONLY)
  120. return ERR_PTR(-EROFS);
  121. /* Special case here: if the journal has aborted behind our
  122. * backs (eg. EIO in the commit thread), then we still need to
  123. * take the FS itself readonly cleanly. */
  124. journal = EXT4_SB(sb)->s_journal;
  125. if (journal) {
  126. if (is_journal_aborted(journal)) {
  127. ext4_abort(sb, __func__,
  128. "Detected aborted journal");
  129. return ERR_PTR(-EROFS);
  130. }
  131. return jbd2_journal_start(journal, nblocks);
  132. }
  133. /*
  134. * We're not journaling, return the appropriate indication.
  135. */
  136. current->journal_info = EXT4_NOJOURNAL_HANDLE;
  137. return current->journal_info;
  138. }
  139. /*
  140. * The only special thing we need to do here is to make sure that all
  141. * jbd2_journal_stop calls result in the superblock being marked dirty, so
  142. * that sync() will call the filesystem's write_super callback if
  143. * appropriate.
  144. */
  145. int __ext4_journal_stop(const char *where, handle_t *handle)
  146. {
  147. struct super_block *sb;
  148. int err;
  149. int rc;
  150. if (!ext4_handle_valid(handle)) {
  151. /*
  152. * Do this here since we don't call jbd2_journal_stop() in
  153. * no-journal mode.
  154. */
  155. current->journal_info = NULL;
  156. return 0;
  157. }
  158. sb = handle->h_transaction->t_journal->j_private;
  159. err = handle->h_err;
  160. rc = jbd2_journal_stop(handle);
  161. if (!err)
  162. err = rc;
  163. if (err)
  164. __ext4_std_error(sb, where, err);
  165. return err;
  166. }
  167. void ext4_journal_abort_handle(const char *caller, const char *err_fn,
  168. struct buffer_head *bh, handle_t *handle, int err)
  169. {
  170. char nbuf[16];
  171. const char *errstr = ext4_decode_error(NULL, err, nbuf);
  172. BUG_ON(!ext4_handle_valid(handle));
  173. if (bh)
  174. BUFFER_TRACE(bh, "abort");
  175. if (!handle->h_err)
  176. handle->h_err = err;
  177. if (is_handle_aborted(handle))
  178. return;
  179. printk(KERN_ERR "%s: aborting transaction: %s in %s\n",
  180. caller, errstr, err_fn);
  181. jbd2_journal_abort_handle(handle);
  182. }
  183. /* Deal with the reporting of failure conditions on a filesystem such as
  184. * inconsistencies detected or read IO failures.
  185. *
  186. * On ext2, we can store the error state of the filesystem in the
  187. * superblock. That is not possible on ext4, because we may have other
  188. * write ordering constraints on the superblock which prevent us from
  189. * writing it out straight away; and given that the journal is about to
  190. * be aborted, we can't rely on the current, or future, transactions to
  191. * write out the superblock safely.
  192. *
  193. * We'll just use the jbd2_journal_abort() error code to record an error in
  194. * the journal instead. On recovery, the journal will compain about
  195. * that error until we've noted it down and cleared it.
  196. */
  197. static void ext4_handle_error(struct super_block *sb)
  198. {
  199. struct ext4_super_block *es = EXT4_SB(sb)->s_es;
  200. EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
  201. es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
  202. if (sb->s_flags & MS_RDONLY)
  203. return;
  204. if (!test_opt(sb, ERRORS_CONT)) {
  205. journal_t *journal = EXT4_SB(sb)->s_journal;
  206. EXT4_SB(sb)->s_mount_opt |= EXT4_MOUNT_ABORT;
  207. if (journal)
  208. jbd2_journal_abort(journal, -EIO);
  209. }
  210. if (test_opt(sb, ERRORS_RO)) {
  211. printk(KERN_CRIT "Remounting filesystem read-only\n");
  212. sb->s_flags |= MS_RDONLY;
  213. }
  214. ext4_commit_super(sb, es, 1);
  215. if (test_opt(sb, ERRORS_PANIC))
  216. panic("EXT4-fs (device %s): panic forced after error\n",
  217. sb->s_id);
  218. }
  219. void ext4_error(struct super_block *sb, const char *function,
  220. const char *fmt, ...)
  221. {
  222. va_list args;
  223. va_start(args, fmt);
  224. printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function);
  225. vprintk(fmt, args);
  226. printk("\n");
  227. va_end(args);
  228. ext4_handle_error(sb);
  229. }
  230. static const char *ext4_decode_error(struct super_block *sb, int errno,
  231. char nbuf[16])
  232. {
  233. char *errstr = NULL;
  234. switch (errno) {
  235. case -EIO:
  236. errstr = "IO failure";
  237. break;
  238. case -ENOMEM:
  239. errstr = "Out of memory";
  240. break;
  241. case -EROFS:
  242. if (!sb || EXT4_SB(sb)->s_journal->j_flags & JBD2_ABORT)
  243. errstr = "Journal has aborted";
  244. else
  245. errstr = "Readonly filesystem";
  246. break;
  247. default:
  248. /* If the caller passed in an extra buffer for unknown
  249. * errors, textualise them now. Else we just return
  250. * NULL. */
  251. if (nbuf) {
  252. /* Check for truncated error codes... */
  253. if (snprintf(nbuf, 16, "error %d", -errno) >= 0)
  254. errstr = nbuf;
  255. }
  256. break;
  257. }
  258. return errstr;
  259. }
  260. /* __ext4_std_error decodes expected errors from journaling functions
  261. * automatically and invokes the appropriate error response. */
  262. void __ext4_std_error(struct super_block *sb, const char *function, int errno)
  263. {
  264. char nbuf[16];
  265. const char *errstr;
  266. /* Special case: if the error is EROFS, and we're not already
  267. * inside a transaction, then there's really no point in logging
  268. * an error. */
  269. if (errno == -EROFS && journal_current_handle() == NULL &&
  270. (sb->s_flags & MS_RDONLY))
  271. return;
  272. errstr = ext4_decode_error(sb, errno, nbuf);
  273. printk(KERN_CRIT "EXT4-fs error (device %s) in %s: %s\n",
  274. sb->s_id, function, errstr);
  275. ext4_handle_error(sb);
  276. }
  277. /*
  278. * ext4_abort is a much stronger failure handler than ext4_error. The
  279. * abort function may be used to deal with unrecoverable failures such
  280. * as journal IO errors or ENOMEM at a critical moment in log management.
  281. *
  282. * We unconditionally force the filesystem into an ABORT|READONLY state,
  283. * unless the error response on the fs has been set to panic in which
  284. * case we take the easy way out and panic immediately.
  285. */
  286. void ext4_abort(struct super_block *sb, const char *function,
  287. const char *fmt, ...)
  288. {
  289. va_list args;
  290. printk(KERN_CRIT "ext4_abort called.\n");
  291. va_start(args, fmt);
  292. printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function);
  293. vprintk(fmt, args);
  294. printk("\n");
  295. va_end(args);
  296. if (test_opt(sb, ERRORS_PANIC))
  297. panic("EXT4-fs panic from previous error\n");
  298. if (sb->s_flags & MS_RDONLY)
  299. return;
  300. printk(KERN_CRIT "Remounting filesystem read-only\n");
  301. EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
  302. sb->s_flags |= MS_RDONLY;
  303. EXT4_SB(sb)->s_mount_opt |= EXT4_MOUNT_ABORT;
  304. if (EXT4_SB(sb)->s_journal)
  305. jbd2_journal_abort(EXT4_SB(sb)->s_journal, -EIO);
  306. }
  307. void ext4_warning(struct super_block *sb, const char *function,
  308. const char *fmt, ...)
  309. {
  310. va_list args;
  311. va_start(args, fmt);
  312. printk(KERN_WARNING "EXT4-fs warning (device %s): %s: ",
  313. sb->s_id, function);
  314. vprintk(fmt, args);
  315. printk("\n");
  316. va_end(args);
  317. }
  318. void ext4_update_dynamic_rev(struct super_block *sb)
  319. {
  320. struct ext4_super_block *es = EXT4_SB(sb)->s_es;
  321. if (le32_to_cpu(es->s_rev_level) > EXT4_GOOD_OLD_REV)
  322. return;
  323. ext4_warning(sb, __func__,
  324. "updating to rev %d because of new feature flag, "
  325. "running e2fsck is recommended",
  326. EXT4_DYNAMIC_REV);
  327. es->s_first_ino = cpu_to_le32(EXT4_GOOD_OLD_FIRST_INO);
  328. es->s_inode_size = cpu_to_le16(EXT4_GOOD_OLD_INODE_SIZE);
  329. es->s_rev_level = cpu_to_le32(EXT4_DYNAMIC_REV);
  330. /* leave es->s_feature_*compat flags alone */
  331. /* es->s_uuid will be set by e2fsck if empty */
  332. /*
  333. * The rest of the superblock fields should be zero, and if not it
  334. * means they are likely already in use, so leave them alone. We
  335. * can leave it up to e2fsck to clean up any inconsistencies there.
  336. */
  337. }
  338. /*
  339. * Open the external journal device
  340. */
  341. static struct block_device *ext4_blkdev_get(dev_t dev)
  342. {
  343. struct block_device *bdev;
  344. char b[BDEVNAME_SIZE];
  345. bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE);
  346. if (IS_ERR(bdev))
  347. goto fail;
  348. return bdev;
  349. fail:
  350. printk(KERN_ERR "EXT4: failed to open journal device %s: %ld\n",
  351. __bdevname(dev, b), PTR_ERR(bdev));
  352. return NULL;
  353. }
  354. /*
  355. * Release the journal device
  356. */
  357. static int ext4_blkdev_put(struct block_device *bdev)
  358. {
  359. bd_release(bdev);
  360. return blkdev_put(bdev, FMODE_READ|FMODE_WRITE);
  361. }
  362. static int ext4_blkdev_remove(struct ext4_sb_info *sbi)
  363. {
  364. struct block_device *bdev;
  365. int ret = -ENODEV;
  366. bdev = sbi->journal_bdev;
  367. if (bdev) {
  368. ret = ext4_blkdev_put(bdev);
  369. sbi->journal_bdev = NULL;
  370. }
  371. return ret;
  372. }
  373. static inline struct inode *orphan_list_entry(struct list_head *l)
  374. {
  375. return &list_entry(l, struct ext4_inode_info, i_orphan)->vfs_inode;
  376. }
  377. static void dump_orphan_list(struct super_block *sb, struct ext4_sb_info *sbi)
  378. {
  379. struct list_head *l;
  380. printk(KERN_ERR "sb orphan head is %d\n",
  381. le32_to_cpu(sbi->s_es->s_last_orphan));
  382. printk(KERN_ERR "sb_info orphan list:\n");
  383. list_for_each(l, &sbi->s_orphan) {
  384. struct inode *inode = orphan_list_entry(l);
  385. printk(KERN_ERR " "
  386. "inode %s:%lu at %p: mode %o, nlink %d, next %d\n",
  387. inode->i_sb->s_id, inode->i_ino, inode,
  388. inode->i_mode, inode->i_nlink,
  389. NEXT_ORPHAN(inode));
  390. }
  391. }
  392. static void ext4_put_super(struct super_block *sb)
  393. {
  394. struct ext4_sb_info *sbi = EXT4_SB(sb);
  395. struct ext4_super_block *es = sbi->s_es;
  396. int i, err;
  397. ext4_mb_release(sb);
  398. ext4_ext_release(sb);
  399. ext4_xattr_put_super(sb);
  400. if (sbi->s_journal) {
  401. err = jbd2_journal_destroy(sbi->s_journal);
  402. sbi->s_journal = NULL;
  403. if (err < 0)
  404. ext4_abort(sb, __func__,
  405. "Couldn't clean up the journal");
  406. }
  407. if (!(sb->s_flags & MS_RDONLY)) {
  408. EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
  409. es->s_state = cpu_to_le16(sbi->s_mount_state);
  410. ext4_commit_super(sb, es, 1);
  411. }
  412. if (sbi->s_proc) {
  413. remove_proc_entry("inode_readahead_blks", sbi->s_proc);
  414. remove_proc_entry(sb->s_id, ext4_proc_root);
  415. }
  416. for (i = 0; i < sbi->s_gdb_count; i++)
  417. brelse(sbi->s_group_desc[i]);
  418. kfree(sbi->s_group_desc);
  419. kfree(sbi->s_flex_groups);
  420. percpu_counter_destroy(&sbi->s_freeblocks_counter);
  421. percpu_counter_destroy(&sbi->s_freeinodes_counter);
  422. percpu_counter_destroy(&sbi->s_dirs_counter);
  423. percpu_counter_destroy(&sbi->s_dirtyblocks_counter);
  424. brelse(sbi->s_sbh);
  425. #ifdef CONFIG_QUOTA
  426. for (i = 0; i < MAXQUOTAS; i++)
  427. kfree(sbi->s_qf_names[i]);
  428. #endif
  429. /* Debugging code just in case the in-memory inode orphan list
  430. * isn't empty. The on-disk one can be non-empty if we've
  431. * detected an error and taken the fs readonly, but the
  432. * in-memory list had better be clean by this point. */
  433. if (!list_empty(&sbi->s_orphan))
  434. dump_orphan_list(sb, sbi);
  435. J_ASSERT(list_empty(&sbi->s_orphan));
  436. invalidate_bdev(sb->s_bdev);
  437. if (sbi->journal_bdev && sbi->journal_bdev != sb->s_bdev) {
  438. /*
  439. * Invalidate the journal device's buffers. We don't want them
  440. * floating about in memory - the physical journal device may
  441. * hotswapped, and it breaks the `ro-after' testing code.
  442. */
  443. sync_blockdev(sbi->journal_bdev);
  444. invalidate_bdev(sbi->journal_bdev);
  445. ext4_blkdev_remove(sbi);
  446. }
  447. sb->s_fs_info = NULL;
  448. kfree(sbi);
  449. return;
  450. }
  451. static struct kmem_cache *ext4_inode_cachep;
  452. /*
  453. * Called inside transaction, so use GFP_NOFS
  454. */
  455. static struct inode *ext4_alloc_inode(struct super_block *sb)
  456. {
  457. struct ext4_inode_info *ei;
  458. ei = kmem_cache_alloc(ext4_inode_cachep, GFP_NOFS);
  459. if (!ei)
  460. return NULL;
  461. #ifdef CONFIG_EXT4_FS_POSIX_ACL
  462. ei->i_acl = EXT4_ACL_NOT_CACHED;
  463. ei->i_default_acl = EXT4_ACL_NOT_CACHED;
  464. #endif
  465. ei->vfs_inode.i_version = 1;
  466. ei->vfs_inode.i_data.writeback_index = 0;
  467. memset(&ei->i_cached_extent, 0, sizeof(struct ext4_ext_cache));
  468. INIT_LIST_HEAD(&ei->i_prealloc_list);
  469. spin_lock_init(&ei->i_prealloc_lock);
  470. /*
  471. * Note: We can be called before EXT4_SB(sb)->s_journal is set,
  472. * therefore it can be null here. Don't check it, just initialize
  473. * jinode.
  474. */
  475. jbd2_journal_init_jbd_inode(&ei->jinode, &ei->vfs_inode);
  476. ei->i_reserved_data_blocks = 0;
  477. ei->i_reserved_meta_blocks = 0;
  478. ei->i_allocated_meta_blocks = 0;
  479. ei->i_delalloc_reserved_flag = 0;
  480. spin_lock_init(&(ei->i_block_reservation_lock));
  481. return &ei->vfs_inode;
  482. }
  483. static void ext4_destroy_inode(struct inode *inode)
  484. {
  485. if (!list_empty(&(EXT4_I(inode)->i_orphan))) {
  486. printk("EXT4 Inode %p: orphan list check failed!\n",
  487. EXT4_I(inode));
  488. print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, 16, 4,
  489. EXT4_I(inode), sizeof(struct ext4_inode_info),
  490. true);
  491. dump_stack();
  492. }
  493. kmem_cache_free(ext4_inode_cachep, EXT4_I(inode));
  494. }
  495. static void init_once(void *foo)
  496. {
  497. struct ext4_inode_info *ei = (struct ext4_inode_info *) foo;
  498. INIT_LIST_HEAD(&ei->i_orphan);
  499. #ifdef CONFIG_EXT4_FS_XATTR
  500. init_rwsem(&ei->xattr_sem);
  501. #endif
  502. init_rwsem(&ei->i_data_sem);
  503. inode_init_once(&ei->vfs_inode);
  504. }
  505. static int init_inodecache(void)
  506. {
  507. ext4_inode_cachep = kmem_cache_create("ext4_inode_cache",
  508. sizeof(struct ext4_inode_info),
  509. 0, (SLAB_RECLAIM_ACCOUNT|
  510. SLAB_MEM_SPREAD),
  511. init_once);
  512. if (ext4_inode_cachep == NULL)
  513. return -ENOMEM;
  514. return 0;
  515. }
  516. static void destroy_inodecache(void)
  517. {
  518. kmem_cache_destroy(ext4_inode_cachep);
  519. }
  520. static void ext4_clear_inode(struct inode *inode)
  521. {
  522. #ifdef CONFIG_EXT4_FS_POSIX_ACL
  523. if (EXT4_I(inode)->i_acl &&
  524. EXT4_I(inode)->i_acl != EXT4_ACL_NOT_CACHED) {
  525. posix_acl_release(EXT4_I(inode)->i_acl);
  526. EXT4_I(inode)->i_acl = EXT4_ACL_NOT_CACHED;
  527. }
  528. if (EXT4_I(inode)->i_default_acl &&
  529. EXT4_I(inode)->i_default_acl != EXT4_ACL_NOT_CACHED) {
  530. posix_acl_release(EXT4_I(inode)->i_default_acl);
  531. EXT4_I(inode)->i_default_acl = EXT4_ACL_NOT_CACHED;
  532. }
  533. #endif
  534. ext4_discard_preallocations(inode);
  535. if (EXT4_JOURNAL(inode))
  536. jbd2_journal_release_jbd_inode(EXT4_SB(inode->i_sb)->s_journal,
  537. &EXT4_I(inode)->jinode);
  538. }
  539. static inline void ext4_show_quota_options(struct seq_file *seq,
  540. struct super_block *sb)
  541. {
  542. #if defined(CONFIG_QUOTA)
  543. struct ext4_sb_info *sbi = EXT4_SB(sb);
  544. if (sbi->s_jquota_fmt)
  545. seq_printf(seq, ",jqfmt=%s",
  546. (sbi->s_jquota_fmt == QFMT_VFS_OLD) ? "vfsold" : "vfsv0");
  547. if (sbi->s_qf_names[USRQUOTA])
  548. seq_printf(seq, ",usrjquota=%s", sbi->s_qf_names[USRQUOTA]);
  549. if (sbi->s_qf_names[GRPQUOTA])
  550. seq_printf(seq, ",grpjquota=%s", sbi->s_qf_names[GRPQUOTA]);
  551. if (sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA)
  552. seq_puts(seq, ",usrquota");
  553. if (sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA)
  554. seq_puts(seq, ",grpquota");
  555. #endif
  556. }
  557. /*
  558. * Show an option if
  559. * - it's set to a non-default value OR
  560. * - if the per-sb default is different from the global default
  561. */
  562. static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)
  563. {
  564. int def_errors;
  565. unsigned long def_mount_opts;
  566. struct super_block *sb = vfs->mnt_sb;
  567. struct ext4_sb_info *sbi = EXT4_SB(sb);
  568. struct ext4_super_block *es = sbi->s_es;
  569. def_mount_opts = le32_to_cpu(es->s_default_mount_opts);
  570. def_errors = le16_to_cpu(es->s_errors);
  571. if (sbi->s_sb_block != 1)
  572. seq_printf(seq, ",sb=%llu", sbi->s_sb_block);
  573. if (test_opt(sb, MINIX_DF))
  574. seq_puts(seq, ",minixdf");
  575. if (test_opt(sb, GRPID) && !(def_mount_opts & EXT4_DEFM_BSDGROUPS))
  576. seq_puts(seq, ",grpid");
  577. if (!test_opt(sb, GRPID) && (def_mount_opts & EXT4_DEFM_BSDGROUPS))
  578. seq_puts(seq, ",nogrpid");
  579. if (sbi->s_resuid != EXT4_DEF_RESUID ||
  580. le16_to_cpu(es->s_def_resuid) != EXT4_DEF_RESUID) {
  581. seq_printf(seq, ",resuid=%u", sbi->s_resuid);
  582. }
  583. if (sbi->s_resgid != EXT4_DEF_RESGID ||
  584. le16_to_cpu(es->s_def_resgid) != EXT4_DEF_RESGID) {
  585. seq_printf(seq, ",resgid=%u", sbi->s_resgid);
  586. }
  587. if (test_opt(sb, ERRORS_RO)) {
  588. if (def_errors == EXT4_ERRORS_PANIC ||
  589. def_errors == EXT4_ERRORS_CONTINUE) {
  590. seq_puts(seq, ",errors=remount-ro");
  591. }
  592. }
  593. if (test_opt(sb, ERRORS_CONT) && def_errors != EXT4_ERRORS_CONTINUE)
  594. seq_puts(seq, ",errors=continue");
  595. if (test_opt(sb, ERRORS_PANIC) && def_errors != EXT4_ERRORS_PANIC)
  596. seq_puts(seq, ",errors=panic");
  597. if (test_opt(sb, NO_UID32) && !(def_mount_opts & EXT4_DEFM_UID16))
  598. seq_puts(seq, ",nouid32");
  599. if (test_opt(sb, DEBUG) && !(def_mount_opts & EXT4_DEFM_DEBUG))
  600. seq_puts(seq, ",debug");
  601. if (test_opt(sb, OLDALLOC))
  602. seq_puts(seq, ",oldalloc");
  603. #ifdef CONFIG_EXT4_FS_XATTR
  604. if (test_opt(sb, XATTR_USER) &&
  605. !(def_mount_opts & EXT4_DEFM_XATTR_USER))
  606. seq_puts(seq, ",user_xattr");
  607. if (!test_opt(sb, XATTR_USER) &&
  608. (def_mount_opts & EXT4_DEFM_XATTR_USER)) {
  609. seq_puts(seq, ",nouser_xattr");
  610. }
  611. #endif
  612. #ifdef CONFIG_EXT4_FS_POSIX_ACL
  613. if (test_opt(sb, POSIX_ACL) && !(def_mount_opts & EXT4_DEFM_ACL))
  614. seq_puts(seq, ",acl");
  615. if (!test_opt(sb, POSIX_ACL) && (def_mount_opts & EXT4_DEFM_ACL))
  616. seq_puts(seq, ",noacl");
  617. #endif
  618. if (!test_opt(sb, RESERVATION))
  619. seq_puts(seq, ",noreservation");
  620. if (sbi->s_commit_interval != JBD2_DEFAULT_MAX_COMMIT_AGE*HZ) {
  621. seq_printf(seq, ",commit=%u",
  622. (unsigned) (sbi->s_commit_interval / HZ));
  623. }
  624. if (sbi->s_min_batch_time != EXT4_DEF_MIN_BATCH_TIME) {
  625. seq_printf(seq, ",min_batch_time=%u",
  626. (unsigned) sbi->s_min_batch_time);
  627. }
  628. if (sbi->s_max_batch_time != EXT4_DEF_MAX_BATCH_TIME) {
  629. seq_printf(seq, ",max_batch_time=%u",
  630. (unsigned) sbi->s_min_batch_time);
  631. }
  632. /*
  633. * We're changing the default of barrier mount option, so
  634. * let's always display its mount state so it's clear what its
  635. * status is.
  636. */
  637. seq_puts(seq, ",barrier=");
  638. seq_puts(seq, test_opt(sb, BARRIER) ? "1" : "0");
  639. if (test_opt(sb, JOURNAL_ASYNC_COMMIT))
  640. seq_puts(seq, ",journal_async_commit");
  641. if (test_opt(sb, NOBH))
  642. seq_puts(seq, ",nobh");
  643. if (!test_opt(sb, EXTENTS))
  644. seq_puts(seq, ",noextents");
  645. if (test_opt(sb, I_VERSION))
  646. seq_puts(seq, ",i_version");
  647. if (!test_opt(sb, DELALLOC))
  648. seq_puts(seq, ",nodelalloc");
  649. if (sbi->s_stripe)
  650. seq_printf(seq, ",stripe=%lu", sbi->s_stripe);
  651. /*
  652. * journal mode get enabled in different ways
  653. * So just print the value even if we didn't specify it
  654. */
  655. if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)
  656. seq_puts(seq, ",data=journal");
  657. else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA)
  658. seq_puts(seq, ",data=ordered");
  659. else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)
  660. seq_puts(seq, ",data=writeback");
  661. if (sbi->s_inode_readahead_blks != EXT4_DEF_INODE_READAHEAD_BLKS)
  662. seq_printf(seq, ",inode_readahead_blks=%u",
  663. sbi->s_inode_readahead_blks);
  664. if (test_opt(sb, DATA_ERR_ABORT))
  665. seq_puts(seq, ",data_err=abort");
  666. ext4_show_quota_options(seq, sb);
  667. return 0;
  668. }
  669. static struct inode *ext4_nfs_get_inode(struct super_block *sb,
  670. u64 ino, u32 generation)
  671. {
  672. struct inode *inode;
  673. if (ino < EXT4_FIRST_INO(sb) && ino != EXT4_ROOT_INO)
  674. return ERR_PTR(-ESTALE);
  675. if (ino > le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count))
  676. return ERR_PTR(-ESTALE);
  677. /* iget isn't really right if the inode is currently unallocated!!
  678. *
  679. * ext4_read_inode will return a bad_inode if the inode had been
  680. * deleted, so we should be safe.
  681. *
  682. * Currently we don't know the generation for parent directory, so
  683. * a generation of 0 means "accept any"
  684. */
  685. inode = ext4_iget(sb, ino);
  686. if (IS_ERR(inode))
  687. return ERR_CAST(inode);
  688. if (generation && inode->i_generation != generation) {
  689. iput(inode);
  690. return ERR_PTR(-ESTALE);
  691. }
  692. return inode;
  693. }
  694. static struct dentry *ext4_fh_to_dentry(struct super_block *sb, struct fid *fid,
  695. int fh_len, int fh_type)
  696. {
  697. return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
  698. ext4_nfs_get_inode);
  699. }
  700. static struct dentry *ext4_fh_to_parent(struct super_block *sb, struct fid *fid,
  701. int fh_len, int fh_type)
  702. {
  703. return generic_fh_to_parent(sb, fid, fh_len, fh_type,
  704. ext4_nfs_get_inode);
  705. }
  706. #ifdef CONFIG_QUOTA
  707. #define QTYPE2NAME(t) ((t) == USRQUOTA ? "user" : "group")
  708. #define QTYPE2MOPT(on, t) ((t) == USRQUOTA?((on)##USRJQUOTA):((on)##GRPJQUOTA))
  709. static int ext4_dquot_initialize(struct inode *inode, int type);
  710. static int ext4_dquot_drop(struct inode *inode);
  711. static int ext4_write_dquot(struct dquot *dquot);
  712. static int ext4_acquire_dquot(struct dquot *dquot);
  713. static int ext4_release_dquot(struct dquot *dquot);
  714. static int ext4_mark_dquot_dirty(struct dquot *dquot);
  715. static int ext4_write_info(struct super_block *sb, int type);
  716. static int ext4_quota_on(struct super_block *sb, int type, int format_id,
  717. char *path, int remount);
  718. static int ext4_quota_on_mount(struct super_block *sb, int type);
  719. static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data,
  720. size_t len, loff_t off);
  721. static ssize_t ext4_quota_write(struct super_block *sb, int type,
  722. const char *data, size_t len, loff_t off);
  723. static struct dquot_operations ext4_quota_operations = {
  724. .initialize = ext4_dquot_initialize,
  725. .drop = ext4_dquot_drop,
  726. .alloc_space = dquot_alloc_space,
  727. .alloc_inode = dquot_alloc_inode,
  728. .free_space = dquot_free_space,
  729. .free_inode = dquot_free_inode,
  730. .transfer = dquot_transfer,
  731. .write_dquot = ext4_write_dquot,
  732. .acquire_dquot = ext4_acquire_dquot,
  733. .release_dquot = ext4_release_dquot,
  734. .mark_dirty = ext4_mark_dquot_dirty,
  735. .write_info = ext4_write_info
  736. };
  737. static struct quotactl_ops ext4_qctl_operations = {
  738. .quota_on = ext4_quota_on,
  739. .quota_off = vfs_quota_off,
  740. .quota_sync = vfs_quota_sync,
  741. .get_info = vfs_get_dqinfo,
  742. .set_info = vfs_set_dqinfo,
  743. .get_dqblk = vfs_get_dqblk,
  744. .set_dqblk = vfs_set_dqblk
  745. };
  746. #endif
  747. static const struct super_operations ext4_sops = {
  748. .alloc_inode = ext4_alloc_inode,
  749. .destroy_inode = ext4_destroy_inode,
  750. .write_inode = ext4_write_inode,
  751. .dirty_inode = ext4_dirty_inode,
  752. .delete_inode = ext4_delete_inode,
  753. .put_super = ext4_put_super,
  754. .write_super = ext4_write_super,
  755. .sync_fs = ext4_sync_fs,
  756. .write_super_lockfs = ext4_write_super_lockfs,
  757. .unlockfs = ext4_unlockfs,
  758. .statfs = ext4_statfs,
  759. .remount_fs = ext4_remount,
  760. .clear_inode = ext4_clear_inode,
  761. .show_options = ext4_show_options,
  762. #ifdef CONFIG_QUOTA
  763. .quota_read = ext4_quota_read,
  764. .quota_write = ext4_quota_write,
  765. #endif
  766. };
  767. static const struct export_operations ext4_export_ops = {
  768. .fh_to_dentry = ext4_fh_to_dentry,
  769. .fh_to_parent = ext4_fh_to_parent,
  770. .get_parent = ext4_get_parent,
  771. };
  772. enum {
  773. Opt_bsd_df, Opt_minix_df, Opt_grpid, Opt_nogrpid,
  774. Opt_resgid, Opt_resuid, Opt_sb, Opt_err_cont, Opt_err_panic, Opt_err_ro,
  775. Opt_nouid32, Opt_debug, Opt_oldalloc, Opt_orlov,
  776. Opt_user_xattr, Opt_nouser_xattr, Opt_acl, Opt_noacl,
  777. Opt_reservation, Opt_noreservation, Opt_noload, Opt_nobh, Opt_bh,
  778. Opt_commit, Opt_min_batch_time, Opt_max_batch_time,
  779. Opt_journal_update, Opt_journal_inum, Opt_journal_dev,
  780. Opt_journal_checksum, Opt_journal_async_commit,
  781. Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback,
  782. Opt_data_err_abort, Opt_data_err_ignore,
  783. Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
  784. Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
  785. Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
  786. Opt_grpquota, Opt_extents, Opt_noextents, Opt_i_version,
  787. Opt_stripe, Opt_delalloc, Opt_nodelalloc,
  788. Opt_inode_readahead_blks
  789. };
  790. static const match_table_t tokens = {
  791. {Opt_bsd_df, "bsddf"},
  792. {Opt_minix_df, "minixdf"},
  793. {Opt_grpid, "grpid"},
  794. {Opt_grpid, "bsdgroups"},
  795. {Opt_nogrpid, "nogrpid"},
  796. {Opt_nogrpid, "sysvgroups"},
  797. {Opt_resgid, "resgid=%u"},
  798. {Opt_resuid, "resuid=%u"},
  799. {Opt_sb, "sb=%u"},
  800. {Opt_err_cont, "errors=continue"},
  801. {Opt_err_panic, "errors=panic"},
  802. {Opt_err_ro, "errors=remount-ro"},
  803. {Opt_nouid32, "nouid32"},
  804. {Opt_debug, "debug"},
  805. {Opt_oldalloc, "oldalloc"},
  806. {Opt_orlov, "orlov"},
  807. {Opt_user_xattr, "user_xattr"},
  808. {Opt_nouser_xattr, "nouser_xattr"},
  809. {Opt_acl, "acl"},
  810. {Opt_noacl, "noacl"},
  811. {Opt_reservation, "reservation"},
  812. {Opt_noreservation, "noreservation"},
  813. {Opt_noload, "noload"},
  814. {Opt_nobh, "nobh"},
  815. {Opt_bh, "bh"},
  816. {Opt_commit, "commit=%u"},
  817. {Opt_min_batch_time, "min_batch_time=%u"},
  818. {Opt_max_batch_time, "max_batch_time=%u"},
  819. {Opt_journal_update, "journal=update"},
  820. {Opt_journal_inum, "journal=%u"},
  821. {Opt_journal_dev, "journal_dev=%u"},
  822. {Opt_journal_checksum, "journal_checksum"},
  823. {Opt_journal_async_commit, "journal_async_commit"},
  824. {Opt_abort, "abort"},
  825. {Opt_data_journal, "data=journal"},
  826. {Opt_data_ordered, "data=ordered"},
  827. {Opt_data_writeback, "data=writeback"},
  828. {Opt_data_err_abort, "data_err=abort"},
  829. {Opt_data_err_ignore, "data_err=ignore"},
  830. {Opt_offusrjquota, "usrjquota="},
  831. {Opt_usrjquota, "usrjquota=%s"},
  832. {Opt_offgrpjquota, "grpjquota="},
  833. {Opt_grpjquota, "grpjquota=%s"},
  834. {Opt_jqfmt_vfsold, "jqfmt=vfsold"},
  835. {Opt_jqfmt_vfsv0, "jqfmt=vfsv0"},
  836. {Opt_grpquota, "grpquota"},
  837. {Opt_noquota, "noquota"},
  838. {Opt_quota, "quota"},
  839. {Opt_usrquota, "usrquota"},
  840. {Opt_barrier, "barrier=%u"},
  841. {Opt_extents, "extents"},
  842. {Opt_noextents, "noextents"},
  843. {Opt_i_version, "i_version"},
  844. {Opt_stripe, "stripe=%u"},
  845. {Opt_resize, "resize"},
  846. {Opt_delalloc, "delalloc"},
  847. {Opt_nodelalloc, "nodelalloc"},
  848. {Opt_inode_readahead_blks, "inode_readahead_blks=%u"},
  849. {Opt_err, NULL},
  850. };
  851. static ext4_fsblk_t get_sb_block(void **data)
  852. {
  853. ext4_fsblk_t sb_block;
  854. char *options = (char *) *data;
  855. if (!options || strncmp(options, "sb=", 3) != 0)
  856. return 1; /* Default location */
  857. options += 3;
  858. /*todo: use simple_strtoll with >32bit ext4 */
  859. sb_block = simple_strtoul(options, &options, 0);
  860. if (*options && *options != ',') {
  861. printk(KERN_ERR "EXT4-fs: Invalid sb specification: %s\n",
  862. (char *) *data);
  863. return 1;
  864. }
  865. if (*options == ',')
  866. options++;
  867. *data = (void *) options;
  868. return sb_block;
  869. }
  870. static int parse_options(char *options, struct super_block *sb,
  871. unsigned int *inum, unsigned long *journal_devnum,
  872. ext4_fsblk_t *n_blocks_count, int is_remount)
  873. {
  874. struct ext4_sb_info *sbi = EXT4_SB(sb);
  875. char *p;
  876. substring_t args[MAX_OPT_ARGS];
  877. int data_opt = 0;
  878. int option;
  879. #ifdef CONFIG_QUOTA
  880. int qtype, qfmt;
  881. char *qname;
  882. #endif
  883. ext4_fsblk_t last_block;
  884. if (!options)
  885. return 1;
  886. while ((p = strsep(&options, ",")) != NULL) {
  887. int token;
  888. if (!*p)
  889. continue;
  890. token = match_token(p, tokens, args);
  891. switch (token) {
  892. case Opt_bsd_df:
  893. clear_opt(sbi->s_mount_opt, MINIX_DF);
  894. break;
  895. case Opt_minix_df:
  896. set_opt(sbi->s_mount_opt, MINIX_DF);
  897. break;
  898. case Opt_grpid:
  899. set_opt(sbi->s_mount_opt, GRPID);
  900. break;
  901. case Opt_nogrpid:
  902. clear_opt(sbi->s_mount_opt, GRPID);
  903. break;
  904. case Opt_resuid:
  905. if (match_int(&args[0], &option))
  906. return 0;
  907. sbi->s_resuid = option;
  908. break;
  909. case Opt_resgid:
  910. if (match_int(&args[0], &option))
  911. return 0;
  912. sbi->s_resgid = option;
  913. break;
  914. case Opt_sb:
  915. /* handled by get_sb_block() instead of here */
  916. /* *sb_block = match_int(&args[0]); */
  917. break;
  918. case Opt_err_panic:
  919. clear_opt(sbi->s_mount_opt, ERRORS_CONT);
  920. clear_opt(sbi->s_mount_opt, ERRORS_RO);
  921. set_opt(sbi->s_mount_opt, ERRORS_PANIC);
  922. break;
  923. case Opt_err_ro:
  924. clear_opt(sbi->s_mount_opt, ERRORS_CONT);
  925. clear_opt(sbi->s_mount_opt, ERRORS_PANIC);
  926. set_opt(sbi->s_mount_opt, ERRORS_RO);
  927. break;
  928. case Opt_err_cont:
  929. clear_opt(sbi->s_mount_opt, ERRORS_RO);
  930. clear_opt(sbi->s_mount_opt, ERRORS_PANIC);
  931. set_opt(sbi->s_mount_opt, ERRORS_CONT);
  932. break;
  933. case Opt_nouid32:
  934. set_opt(sbi->s_mount_opt, NO_UID32);
  935. break;
  936. case Opt_debug:
  937. set_opt(sbi->s_mount_opt, DEBUG);
  938. break;
  939. case Opt_oldalloc:
  940. set_opt(sbi->s_mount_opt, OLDALLOC);
  941. break;
  942. case Opt_orlov:
  943. clear_opt(sbi->s_mount_opt, OLDALLOC);
  944. break;
  945. #ifdef CONFIG_EXT4_FS_XATTR
  946. case Opt_user_xattr:
  947. set_opt(sbi->s_mount_opt, XATTR_USER);
  948. break;
  949. case Opt_nouser_xattr:
  950. clear_opt(sbi->s_mount_opt, XATTR_USER);
  951. break;
  952. #else
  953. case Opt_user_xattr:
  954. case Opt_nouser_xattr:
  955. printk(KERN_ERR "EXT4 (no)user_xattr options "
  956. "not supported\n");
  957. break;
  958. #endif
  959. #ifdef CONFIG_EXT4_FS_POSIX_ACL
  960. case Opt_acl:
  961. set_opt(sbi->s_mount_opt, POSIX_ACL);
  962. break;
  963. case Opt_noacl:
  964. clear_opt(sbi->s_mount_opt, POSIX_ACL);
  965. break;
  966. #else
  967. case Opt_acl:
  968. case Opt_noacl:
  969. printk(KERN_ERR "EXT4 (no)acl options "
  970. "not supported\n");
  971. break;
  972. #endif
  973. case Opt_reservation:
  974. set_opt(sbi->s_mount_opt, RESERVATION);
  975. break;
  976. case Opt_noreservation:
  977. clear_opt(sbi->s_mount_opt, RESERVATION);
  978. break;
  979. case Opt_journal_update:
  980. /* @@@ FIXME */
  981. /* Eventually we will want to be able to create
  982. a journal file here. For now, only allow the
  983. user to specify an existing inode to be the
  984. journal file. */
  985. if (is_remount) {
  986. printk(KERN_ERR "EXT4-fs: cannot specify "
  987. "journal on remount\n");
  988. return 0;
  989. }
  990. set_opt(sbi->s_mount_opt, UPDATE_JOURNAL);
  991. break;
  992. case Opt_journal_inum:
  993. if (is_remount) {
  994. printk(KERN_ERR "EXT4-fs: cannot specify "
  995. "journal on remount\n");
  996. return 0;
  997. }
  998. if (match_int(&args[0], &option))
  999. return 0;
  1000. *inum = option;
  1001. break;
  1002. case Opt_journal_dev:
  1003. if (is_remount) {
  1004. printk(KERN_ERR "EXT4-fs: cannot specify "
  1005. "journal on remount\n");
  1006. return 0;
  1007. }
  1008. if (match_int(&args[0], &option))
  1009. return 0;
  1010. *journal_devnum = option;
  1011. break;
  1012. case Opt_journal_checksum:
  1013. set_opt(sbi->s_mount_opt, JOURNAL_CHECKSUM);
  1014. break;
  1015. case Opt_journal_async_commit:
  1016. set_opt(sbi->s_mount_opt, JOURNAL_ASYNC_COMMIT);
  1017. set_opt(sbi->s_mount_opt, JOURNAL_CHECKSUM);
  1018. break;
  1019. case Opt_noload:
  1020. set_opt(sbi->s_mount_opt, NOLOAD);
  1021. break;
  1022. case Opt_commit:
  1023. if (match_int(&args[0], &option))
  1024. return 0;
  1025. if (option < 0)
  1026. return 0;
  1027. if (option == 0)
  1028. option = JBD2_DEFAULT_MAX_COMMIT_AGE;
  1029. sbi->s_commit_interval = HZ * option;
  1030. break;
  1031. case Opt_max_batch_time:
  1032. if (match_int(&args[0], &option))
  1033. return 0;
  1034. if (option < 0)
  1035. return 0;
  1036. if (option == 0)
  1037. option = EXT4_DEF_MAX_BATCH_TIME;
  1038. sbi->s_max_batch_time = option;
  1039. break;
  1040. case Opt_min_batch_time:
  1041. if (match_int(&args[0], &option))
  1042. return 0;
  1043. if (option < 0)
  1044. return 0;
  1045. sbi->s_min_batch_time = option;
  1046. break;
  1047. case Opt_data_journal:
  1048. data_opt = EXT4_MOUNT_JOURNAL_DATA;
  1049. goto datacheck;
  1050. case Opt_data_ordered:
  1051. data_opt = EXT4_MOUNT_ORDERED_DATA;
  1052. goto datacheck;
  1053. case Opt_data_writeback:
  1054. data_opt = EXT4_MOUNT_WRITEBACK_DATA;
  1055. datacheck:
  1056. if (is_remount) {
  1057. if ((sbi->s_mount_opt & EXT4_MOUNT_DATA_FLAGS)
  1058. != data_opt) {
  1059. printk(KERN_ERR
  1060. "EXT4-fs: cannot change data "
  1061. "mode on remount\n");
  1062. return 0;
  1063. }
  1064. } else {
  1065. sbi->s_mount_opt &= ~EXT4_MOUNT_DATA_FLAGS;
  1066. sbi->s_mount_opt |= data_opt;
  1067. }
  1068. break;
  1069. case Opt_data_err_abort:
  1070. set_opt(sbi->s_mount_opt, DATA_ERR_ABORT);
  1071. break;
  1072. case Opt_data_err_ignore:
  1073. clear_opt(sbi->s_mount_opt, DATA_ERR_ABORT);
  1074. break;
  1075. #ifdef CONFIG_QUOTA
  1076. case Opt_usrjquota:
  1077. qtype = USRQUOTA;
  1078. goto set_qf_name;
  1079. case Opt_grpjquota:
  1080. qtype = GRPQUOTA;
  1081. set_qf_name:
  1082. if ((sb_any_quota_enabled(sb) ||
  1083. sb_any_quota_suspended(sb)) &&
  1084. !sbi->s_qf_names[qtype]) {
  1085. printk(KERN_ERR
  1086. "EXT4-fs: Cannot change journaled "
  1087. "quota options when quota turned on.\n");
  1088. return 0;
  1089. }
  1090. qname = match_strdup(&args[0]);
  1091. if (!qname) {
  1092. printk(KERN_ERR
  1093. "EXT4-fs: not enough memory for "
  1094. "storing quotafile name.\n");
  1095. return 0;
  1096. }
  1097. if (sbi->s_qf_names[qtype] &&
  1098. strcmp(sbi->s_qf_names[qtype], qname)) {
  1099. printk(KERN_ERR
  1100. "EXT4-fs: %s quota file already "
  1101. "specified.\n", QTYPE2NAME(qtype));
  1102. kfree(qname);
  1103. return 0;
  1104. }
  1105. sbi->s_qf_names[qtype] = qname;
  1106. if (strchr(sbi->s_qf_names[qtype], '/')) {
  1107. printk(KERN_ERR
  1108. "EXT4-fs: quotafile must be on "
  1109. "filesystem root.\n");
  1110. kfree(sbi->s_qf_names[qtype]);
  1111. sbi->s_qf_names[qtype] = NULL;
  1112. return 0;
  1113. }
  1114. set_opt(sbi->s_mount_opt, QUOTA);
  1115. break;
  1116. case Opt_offusrjquota:
  1117. qtype = USRQUOTA;
  1118. goto clear_qf_name;
  1119. case Opt_offgrpjquota:
  1120. qtype = GRPQUOTA;
  1121. clear_qf_name:
  1122. if ((sb_any_quota_enabled(sb) ||
  1123. sb_any_quota_suspended(sb)) &&
  1124. sbi->s_qf_names[qtype]) {
  1125. printk(KERN_ERR "EXT4-fs: Cannot change "
  1126. "journaled quota options when "
  1127. "quota turned on.\n");
  1128. return 0;
  1129. }
  1130. /*
  1131. * The space will be released later when all options
  1132. * are confirmed to be correct
  1133. */
  1134. sbi->s_qf_names[qtype] = NULL;
  1135. break;
  1136. case Opt_jqfmt_vfsold:
  1137. qfmt = QFMT_VFS_OLD;
  1138. goto set_qf_format;
  1139. case Opt_jqfmt_vfsv0:
  1140. qfmt = QFMT_VFS_V0;
  1141. set_qf_format:
  1142. if ((sb_any_quota_enabled(sb) ||
  1143. sb_any_quota_suspended(sb)) &&
  1144. sbi->s_jquota_fmt != qfmt) {
  1145. printk(KERN_ERR "EXT4-fs: Cannot change "
  1146. "journaled quota options when "
  1147. "quota turned on.\n");
  1148. return 0;
  1149. }
  1150. sbi->s_jquota_fmt = qfmt;
  1151. break;
  1152. case Opt_quota:
  1153. case Opt_usrquota:
  1154. set_opt(sbi->s_mount_opt, QUOTA);
  1155. set_opt(sbi->s_mount_opt, USRQUOTA);
  1156. break;
  1157. case Opt_grpquota:
  1158. set_opt(sbi->s_mount_opt, QUOTA);
  1159. set_opt(sbi->s_mount_opt, GRPQUOTA);
  1160. break;
  1161. case Opt_noquota:
  1162. if (sb_any_quota_enabled(sb)) {
  1163. printk(KERN_ERR "EXT4-fs: Cannot change quota "
  1164. "options when quota turned on.\n");
  1165. return 0;
  1166. }
  1167. clear_opt(sbi->s_mount_opt, QUOTA);
  1168. clear_opt(sbi->s_mount_opt, USRQUOTA);
  1169. clear_opt(sbi->s_mount_opt, GRPQUOTA);
  1170. break;
  1171. #else
  1172. case Opt_quota:
  1173. case Opt_usrquota:
  1174. case Opt_grpquota:
  1175. printk(KERN_ERR
  1176. "EXT4-fs: quota options not supported.\n");
  1177. break;
  1178. case Opt_usrjquota:
  1179. case Opt_grpjquota:
  1180. case Opt_offusrjquota:
  1181. case Opt_offgrpjquota:
  1182. case Opt_jqfmt_vfsold:
  1183. case Opt_jqfmt_vfsv0:
  1184. printk(KERN_ERR
  1185. "EXT4-fs: journaled quota options not "
  1186. "supported.\n");
  1187. break;
  1188. case Opt_noquota:
  1189. break;
  1190. #endif
  1191. case Opt_abort:
  1192. set_opt(sbi->s_mount_opt, ABORT);
  1193. break;
  1194. case Opt_barrier:
  1195. if (match_int(&args[0], &option))
  1196. return 0;
  1197. if (option)
  1198. set_opt(sbi->s_mount_opt, BARRIER);
  1199. else
  1200. clear_opt(sbi->s_mount_opt, BARRIER);
  1201. break;
  1202. case Opt_ignore:
  1203. break;
  1204. case Opt_resize:
  1205. if (!is_remount) {
  1206. printk("EXT4-fs: resize option only available "
  1207. "for remount\n");
  1208. return 0;
  1209. }
  1210. if (match_int(&args[0], &option) != 0)
  1211. return 0;
  1212. *n_blocks_count = option;
  1213. break;
  1214. case Opt_nobh:
  1215. set_opt(sbi->s_mount_opt, NOBH);
  1216. break;
  1217. case Opt_bh:
  1218. clear_opt(sbi->s_mount_opt, NOBH);
  1219. break;
  1220. case Opt_extents:
  1221. if (!EXT4_HAS_INCOMPAT_FEATURE(sb,
  1222. EXT4_FEATURE_INCOMPAT_EXTENTS)) {
  1223. ext4_warning(sb, __func__,
  1224. "extents feature not enabled "
  1225. "on this filesystem, use tune2fs");
  1226. return 0;
  1227. }
  1228. set_opt(sbi->s_mount_opt, EXTENTS);
  1229. break;
  1230. case Opt_noextents:
  1231. /*
  1232. * When e2fsprogs support resizing an already existing
  1233. * ext3 file system to greater than 2**32 we need to
  1234. * add support to block allocator to handle growing
  1235. * already existing block mapped inode so that blocks
  1236. * allocated for them fall within 2**32
  1237. */
  1238. last_block = ext4_blocks_count(sbi->s_es) - 1;
  1239. if (last_block > 0xffffffffULL) {
  1240. printk(KERN_ERR "EXT4-fs: Filesystem too "
  1241. "large to mount with "
  1242. "-o noextents options\n");
  1243. return 0;
  1244. }
  1245. clear_opt(sbi->s_mount_opt, EXTENTS);
  1246. break;
  1247. case Opt_i_version:
  1248. set_opt(sbi->s_mount_opt, I_VERSION);
  1249. sb->s_flags |= MS_I_VERSION;
  1250. break;
  1251. case Opt_nodelalloc:
  1252. clear_opt(sbi->s_mount_opt, DELALLOC);
  1253. break;
  1254. case Opt_stripe:
  1255. if (match_int(&args[0], &option))
  1256. return 0;
  1257. if (option < 0)
  1258. return 0;
  1259. sbi->s_stripe = option;
  1260. break;
  1261. case Opt_delalloc:
  1262. set_opt(sbi->s_mount_opt, DELALLOC);
  1263. break;
  1264. case Opt_inode_readahead_blks:
  1265. if (match_int(&args[0], &option))
  1266. return 0;
  1267. if (option < 0 || option > (1 << 30))
  1268. return 0;
  1269. sbi->s_inode_readahead_blks = option;
  1270. break;
  1271. default:
  1272. printk(KERN_ERR
  1273. "EXT4-fs: Unrecognized mount option \"%s\" "
  1274. "or missing value\n", p);
  1275. return 0;
  1276. }
  1277. }
  1278. #ifdef CONFIG_QUOTA
  1279. if (sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) {
  1280. if ((sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA) &&
  1281. sbi->s_qf_names[USRQUOTA])
  1282. clear_opt(sbi->s_mount_opt, USRQUOTA);
  1283. if ((sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA) &&
  1284. sbi->s_qf_names[GRPQUOTA])
  1285. clear_opt(sbi->s_mount_opt, GRPQUOTA);
  1286. if ((sbi->s_qf_names[USRQUOTA] &&
  1287. (sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA)) ||
  1288. (sbi->s_qf_names[GRPQUOTA] &&
  1289. (sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA))) {
  1290. printk(KERN_ERR "EXT4-fs: old and new quota "
  1291. "format mixing.\n");
  1292. return 0;
  1293. }
  1294. if (!sbi->s_jquota_fmt) {
  1295. printk(KERN_ERR "EXT4-fs: journaled quota format "
  1296. "not specified.\n");
  1297. return 0;
  1298. }
  1299. } else {
  1300. if (sbi->s_jquota_fmt) {
  1301. printk(KERN_ERR "EXT4-fs: journaled quota format "
  1302. "specified with no journaling "
  1303. "enabled.\n");
  1304. return 0;
  1305. }
  1306. }
  1307. #endif
  1308. return 1;
  1309. }
  1310. static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
  1311. int read_only)
  1312. {
  1313. struct ext4_sb_info *sbi = EXT4_SB(sb);
  1314. int res = 0;
  1315. if (le32_to_cpu(es->s_rev_level) > EXT4_MAX_SUPP_REV) {
  1316. printk(KERN_ERR "EXT4-fs warning: revision level too high, "
  1317. "forcing read-only mode\n");
  1318. res = MS_RDONLY;
  1319. }
  1320. if (read_only)
  1321. return res;
  1322. if (!(sbi->s_mount_state & EXT4_VALID_FS))
  1323. printk(KERN_WARNING "EXT4-fs warning: mounting unchecked fs, "
  1324. "running e2fsck is recommended\n");
  1325. else if ((sbi->s_mount_state & EXT4_ERROR_FS))
  1326. printk(KERN_WARNING
  1327. "EXT4-fs warning: mounting fs with errors, "
  1328. "running e2fsck is recommended\n");
  1329. else if ((__s16) le16_to_cpu(es->s_max_mnt_count) >= 0 &&
  1330. le16_to_cpu(es->s_mnt_count) >=
  1331. (unsigned short) (__s16) le16_to_cpu(es->s_max_mnt_count))
  1332. printk(KERN_WARNING
  1333. "EXT4-fs warning: maximal mount count reached, "
  1334. "running e2fsck is recommended\n");
  1335. else if (le32_to_cpu(es->s_checkinterval) &&
  1336. (le32_to_cpu(es->s_lastcheck) +
  1337. le32_to_cpu(es->s_checkinterval) <= get_seconds()))
  1338. printk(KERN_WARNING
  1339. "EXT4-fs warning: checktime reached, "
  1340. "running e2fsck is recommended\n");
  1341. if (!sbi->s_journal)
  1342. es->s_state &= cpu_to_le16(~EXT4_VALID_FS);
  1343. if (!(__s16) le16_to_cpu(es->s_max_mnt_count))
  1344. es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT);
  1345. le16_add_cpu(&es->s_mnt_count, 1);
  1346. es->s_mtime = cpu_to_le32(get_seconds());
  1347. ext4_update_dynamic_rev(sb);
  1348. if (sbi->s_journal)
  1349. EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
  1350. ext4_commit_super(sb, es, 1);
  1351. if (test_opt(sb, DEBUG))
  1352. printk(KERN_INFO "[EXT4 FS bs=%lu, gc=%u, "
  1353. "bpg=%lu, ipg=%lu, mo=%04lx]\n",
  1354. sb->s_blocksize,
  1355. sbi->s_groups_count,
  1356. EXT4_BLOCKS_PER_GROUP(sb),
  1357. EXT4_INODES_PER_GROUP(sb),
  1358. sbi->s_mount_opt);
  1359. if (EXT4_SB(sb)->s_journal) {
  1360. printk(KERN_INFO "EXT4 FS on %s, %s journal on %s\n",
  1361. sb->s_id, EXT4_SB(sb)->s_journal->j_inode ? "internal" :
  1362. "external", EXT4_SB(sb)->s_journal->j_devname);
  1363. } else {
  1364. printk(KERN_INFO "EXT4 FS on %s, no journal\n", sb->s_id);
  1365. }
  1366. return res;
  1367. }
  1368. static int ext4_fill_flex_info(struct super_block *sb)
  1369. {
  1370. struct ext4_sb_info *sbi = EXT4_SB(sb);
  1371. struct ext4_group_desc *gdp = NULL;
  1372. struct buffer_head *bh;
  1373. ext4_group_t flex_group_count;
  1374. ext4_group_t flex_group;
  1375. int groups_per_flex = 0;
  1376. int i;
  1377. if (!sbi->s_es->s_log_groups_per_flex) {
  1378. sbi->s_log_groups_per_flex = 0;
  1379. return 1;
  1380. }
  1381. sbi->s_log_groups_per_flex = sbi->s_es->s_log_groups_per_flex;
  1382. groups_per_flex = 1 << sbi->s_log_groups_per_flex;
  1383. /* We allocate both existing and potentially added groups */
  1384. flex_group_count = ((sbi->s_groups_count + groups_per_flex - 1) +
  1385. ((le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) + 1) <<
  1386. EXT4_DESC_PER_BLOCK_BITS(sb))) / groups_per_flex;
  1387. sbi->s_flex_groups = kzalloc(flex_group_count *
  1388. sizeof(struct flex_groups), GFP_KERNEL);
  1389. if (sbi->s_flex_groups == NULL) {
  1390. printk(KERN_ERR "EXT4-fs: not enough memory for "
  1391. "%u flex groups\n", flex_group_count);
  1392. goto failed;
  1393. }
  1394. for (i = 0; i < sbi->s_groups_count; i++) {
  1395. gdp = ext4_get_group_desc(sb, i, &bh);
  1396. flex_group = ext4_flex_group(sbi, i);
  1397. sbi->s_flex_groups[flex_group].free_inodes +=
  1398. le16_to_cpu(gdp->bg_free_inodes_count);
  1399. sbi->s_flex_groups[flex_group].free_blocks +=
  1400. le16_to_cpu(gdp->bg_free_blocks_count);
  1401. }
  1402. return 1;
  1403. failed:
  1404. return 0;
  1405. }
  1406. __le16 ext4_group_desc_csum(struct ext4_sb_info *sbi, __u32 block_group,
  1407. struct ext4_group_desc *gdp)
  1408. {
  1409. __u16 crc = 0;
  1410. if (sbi->s_es->s_feature_ro_compat &
  1411. cpu_to_le32(EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
  1412. int offset = offsetof(struct ext4_group_desc, bg_checksum);
  1413. __le32 le_group = cpu_to_le32(block_group);
  1414. crc = crc16(~0, sbi->s_es->s_uuid, sizeof(sbi->s_es->s_uuid));
  1415. crc = crc16(crc, (__u8 *)&le_group, sizeof(le_group));
  1416. crc = crc16(crc, (__u8 *)gdp, offset);
  1417. offset += sizeof(gdp->bg_checksum); /* skip checksum */
  1418. /* for checksum of struct ext4_group_desc do the rest...*/
  1419. if ((sbi->s_es->s_feature_incompat &
  1420. cpu_to_le32(EXT4_FEATURE_INCOMPAT_64BIT)) &&
  1421. offset < le16_to_cpu(sbi->s_es->s_desc_size))
  1422. crc = crc16(crc, (__u8 *)gdp + offset,
  1423. le16_to_cpu(sbi->s_es->s_desc_size) -
  1424. offset);
  1425. }
  1426. return cpu_to_le16(crc);
  1427. }
  1428. int ext4_group_desc_csum_verify(struct ext4_sb_info *sbi, __u32 block_group,
  1429. struct ext4_group_desc *gdp)
  1430. {
  1431. if ((sbi->s_es->s_feature_ro_compat &
  1432. cpu_to_le32(EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) &&
  1433. (gdp->bg_checksum != ext4_group_desc_csum(sbi, block_group, gdp)))
  1434. return 0;
  1435. return 1;
  1436. }
  1437. /* Called at mount-time, super-block is locked */
  1438. static int ext4_check_descriptors(struct super_block *sb)
  1439. {
  1440. struct ext4_sb_info *sbi = EXT4_SB(sb);
  1441. ext4_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block);
  1442. ext4_fsblk_t last_block;
  1443. ext4_fsblk_t block_bitmap;
  1444. ext4_fsblk_t inode_bitmap;
  1445. ext4_fsblk_t inode_table;
  1446. int flexbg_flag = 0;
  1447. ext4_group_t i;
  1448. if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG))
  1449. flexbg_flag = 1;
  1450. ext4_debug("Checking group descriptors");
  1451. for (i = 0; i < sbi->s_groups_count; i++) {
  1452. struct ext4_group_desc *gdp = ext4_get_group_desc(sb, i, NULL);
  1453. if (i == sbi->s_groups_count - 1 || flexbg_flag)
  1454. last_block = ext4_blocks_count(sbi->s_es) - 1;
  1455. else
  1456. last_block = first_block +
  1457. (EXT4_BLOCKS_PER_GROUP(sb) - 1);
  1458. block_bitmap = ext4_block_bitmap(sb, gdp);
  1459. if (block_bitmap < first_block || block_bitmap > last_block) {
  1460. printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: "
  1461. "Block bitmap for group %u not in group "
  1462. "(block %llu)!\n", i, block_bitmap);
  1463. return 0;
  1464. }
  1465. inode_bitmap = ext4_inode_bitmap(sb, gdp);
  1466. if (inode_bitmap < first_block || inode_bitmap > last_block) {
  1467. printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: "
  1468. "Inode bitmap for group %u not in group "
  1469. "(block %llu)!\n", i, inode_bitmap);
  1470. return 0;
  1471. }
  1472. inode_table = ext4_inode_table(sb, gdp);
  1473. if (inode_table < first_block ||
  1474. inode_table + sbi->s_itb_per_group - 1 > last_block) {
  1475. printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: "
  1476. "Inode table for group %u not in group "
  1477. "(block %llu)!\n", i, inode_table);
  1478. return 0;
  1479. }
  1480. spin_lock(sb_bgl_lock(sbi, i));
  1481. if (!ext4_group_desc_csum_verify(sbi, i, gdp)) {
  1482. printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: "
  1483. "Checksum for group %u failed (%u!=%u)\n",
  1484. i, le16_to_cpu(ext4_group_desc_csum(sbi, i,
  1485. gdp)), le16_to_cpu(gdp->bg_checksum));
  1486. if (!(sb->s_flags & MS_RDONLY)) {
  1487. spin_unlock(sb_bgl_lock(sbi, i));
  1488. return 0;
  1489. }
  1490. }
  1491. spin_unlock(sb_bgl_lock(sbi, i));
  1492. if (!flexbg_flag)
  1493. first_block += EXT4_BLOCKS_PER_GROUP(sb);
  1494. }
  1495. ext4_free_blocks_count_set(sbi->s_es, ext4_count_free_blocks(sb));
  1496. sbi->s_es->s_free_inodes_count = cpu_to_le32(ext4_count_free_inodes(sb));
  1497. return 1;
  1498. }
  1499. /* ext4_orphan_cleanup() walks a singly-linked list of inodes (starting at
  1500. * the superblock) which were deleted from all directories, but held open by
  1501. * a process at the time of a crash. We walk the list and try to delete these
  1502. * inodes at recovery time (only with a read-write filesystem).
  1503. *
  1504. * In order to keep the orphan inode chain consistent during traversal (in
  1505. * case of crash during recovery), we link each inode into the superblock
  1506. * orphan list_head and handle it the same way as an inode deletion during
  1507. * normal operation (which journals the operations for us).
  1508. *
  1509. * We only do an iget() and an iput() on each inode, which is very safe if we
  1510. * accidentally point at an in-use or already deleted inode. The worst that
  1511. * can happen in this case is that we get a "bit already cleared" message from
  1512. * ext4_free_inode(). The only reason we would point at a wrong inode is if
  1513. * e2fsck was run on this filesystem, and it must have already done the orphan
  1514. * inode cleanup for us, so we can safely abort without any further action.
  1515. */
  1516. static void ext4_orphan_cleanup(struct super_block *sb,
  1517. struct ext4_super_block *es)
  1518. {
  1519. unsigned int s_flags = sb->s_flags;
  1520. int nr_orphans = 0, nr_truncates = 0;
  1521. #ifdef CONFIG_QUOTA
  1522. int i;
  1523. #endif
  1524. if (!es->s_last_orphan) {
  1525. jbd_debug(4, "no orphan inodes to clean up\n");
  1526. return;
  1527. }
  1528. if (bdev_read_only(sb->s_bdev)) {
  1529. printk(KERN_ERR "EXT4-fs: write access "
  1530. "unavailable, skipping orphan cleanup.\n");
  1531. return;
  1532. }
  1533. if (EXT4_SB(sb)->s_mount_state & EXT4_ERROR_FS) {
  1534. if (es->s_last_orphan)
  1535. jbd_debug(1, "Errors on filesystem, "
  1536. "clearing orphan list.\n");
  1537. es->s_last_orphan = 0;
  1538. jbd_debug(1, "Skipping orphan recovery on fs with errors.\n");
  1539. return;
  1540. }
  1541. if (s_flags & MS_RDONLY) {
  1542. printk(KERN_INFO "EXT4-fs: %s: orphan cleanup on readonly fs\n",
  1543. sb->s_id);
  1544. sb->s_flags &= ~MS_RDONLY;
  1545. }
  1546. #ifdef CONFIG_QUOTA
  1547. /* Needed for iput() to work correctly and not trash data */
  1548. sb->s_flags |= MS_ACTIVE;
  1549. /* Turn on quotas so that they are updated correctly */
  1550. for (i = 0; i < MAXQUOTAS; i++) {
  1551. if (EXT4_SB(sb)->s_qf_names[i]) {
  1552. int ret = ext4_quota_on_mount(sb, i);
  1553. if (ret < 0)
  1554. printk(KERN_ERR
  1555. "EXT4-fs: Cannot turn on journaled "
  1556. "quota: error %d\n", ret);
  1557. }
  1558. }
  1559. #endif
  1560. while (es->s_last_orphan) {
  1561. struct inode *inode;
  1562. inode = ext4_orphan_get(sb, le32_to_cpu(es->s_last_orphan));
  1563. if (IS_ERR(inode)) {
  1564. es->s_last_orphan = 0;
  1565. break;
  1566. }
  1567. list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan);
  1568. DQUOT_INIT(inode);
  1569. if (inode->i_nlink) {
  1570. printk(KERN_DEBUG
  1571. "%s: truncating inode %lu to %lld bytes\n",
  1572. __func__, inode->i_ino, inode->i_size);
  1573. jbd_debug(2, "truncating inode %lu to %lld bytes\n",
  1574. inode->i_ino, inode->i_size);
  1575. ext4_truncate(inode);
  1576. nr_truncates++;
  1577. } else {
  1578. printk(KERN_DEBUG
  1579. "%s: deleting unreferenced inode %lu\n",
  1580. __func__, inode->i_ino);
  1581. jbd_debug(2, "deleting unreferenced inode %lu\n",
  1582. inode->i_ino);
  1583. nr_orphans++;
  1584. }
  1585. iput(inode); /* The delete magic happens here! */
  1586. }
  1587. #define PLURAL(x) (x), ((x) == 1) ? "" : "s"
  1588. if (nr_orphans)
  1589. printk(KERN_INFO "EXT4-fs: %s: %d orphan inode%s deleted\n",
  1590. sb->s_id, PLURAL(nr_orphans));
  1591. if (nr_truncates)
  1592. printk(KERN_INFO "EXT4-fs: %s: %d truncate%s cleaned up\n",
  1593. sb->s_id, PLURAL(nr_truncates));
  1594. #ifdef CONFIG_QUOTA
  1595. /* Turn quotas off */
  1596. for (i = 0; i < MAXQUOTAS; i++) {
  1597. if (sb_dqopt(sb)->files[i])
  1598. vfs_quota_off(sb, i, 0);
  1599. }
  1600. #endif
  1601. sb->s_flags = s_flags; /* Restore MS_RDONLY status */
  1602. }
  1603. /*
  1604. * Maximal extent format file size.
  1605. * Resulting logical blkno at s_maxbytes must fit in our on-disk
  1606. * extent format containers, within a sector_t, and within i_blocks
  1607. * in the vfs. ext4 inode has 48 bits of i_block in fsblock units,
  1608. * so that won't be a limiting factor.
  1609. *
  1610. * Note, this does *not* consider any metadata overhead for vfs i_blocks.
  1611. */
  1612. static loff_t ext4_max_size(int blkbits, int has_huge_files)
  1613. {
  1614. loff_t res;
  1615. loff_t upper_limit = MAX_LFS_FILESIZE;
  1616. /* small i_blocks in vfs inode? */
  1617. if (!has_huge_files || sizeof(blkcnt_t) < sizeof(u64)) {
  1618. /*
  1619. * CONFIG_LBD is not enabled implies the inode
  1620. * i_block represent total blocks in 512 bytes
  1621. * 32 == size of vfs inode i_blocks * 8
  1622. */
  1623. upper_limit = (1LL << 32) - 1;
  1624. /* total blocks in file system block size */
  1625. upper_limit >>= (blkbits - 9);
  1626. upper_limit <<= blkbits;
  1627. }
  1628. /* 32-bit extent-start container, ee_block */
  1629. res = 1LL << 32;
  1630. res <<= blkbits;
  1631. res -= 1;
  1632. /* Sanity check against vm- & vfs- imposed limits */
  1633. if (res > upper_limit)
  1634. res = upper_limit;
  1635. return res;
  1636. }
  1637. /*
  1638. * Maximal bitmap file size. There is a direct, and {,double-,triple-}indirect
  1639. * block limit, and also a limit of (2^48 - 1) 512-byte sectors in i_blocks.
  1640. * We need to be 1 filesystem block less than the 2^48 sector limit.
  1641. */
  1642. static loff_t ext4_max_bitmap_size(int bits, int has_huge_files)
  1643. {
  1644. loff_t res = EXT4_NDIR_BLOCKS;
  1645. int meta_blocks;
  1646. loff_t upper_limit;
  1647. /* This is calculated to be the largest file size for a
  1648. * dense, bitmapped file such that the total number of
  1649. * sectors in the file, including data and all indirect blocks,
  1650. * does not exceed 2^48 -1
  1651. * __u32 i_blocks_lo and _u16 i_blocks_high representing the
  1652. * total number of 512 bytes blocks of the file
  1653. */
  1654. if (!has_huge_files || sizeof(blkcnt_t) < sizeof(u64)) {
  1655. /*
  1656. * !has_huge_files or CONFIG_LBD is not enabled
  1657. * implies the inode i_block represent total blocks in
  1658. * 512 bytes 32 == size of vfs inode i_blocks * 8
  1659. */
  1660. upper_limit = (1LL << 32) - 1;
  1661. /* total blocks in file system block size */
  1662. upper_limit >>= (bits - 9);
  1663. } else {
  1664. /*
  1665. * We use 48 bit ext4_inode i_blocks
  1666. * With EXT4_HUGE_FILE_FL set the i_blocks
  1667. * represent total number of blocks in
  1668. * file system block size
  1669. */
  1670. upper_limit = (1LL << 48) - 1;
  1671. }
  1672. /* indirect blocks */
  1673. meta_blocks = 1;
  1674. /* double indirect blocks */
  1675. meta_blocks += 1 + (1LL << (bits-2));
  1676. /* tripple indirect blocks */
  1677. meta_blocks += 1 + (1LL << (bits-2)) + (1LL << (2*(bits-2)));
  1678. upper_limit -= meta_blocks;
  1679. upper_limit <<= bits;
  1680. res += 1LL << (bits-2);
  1681. res += 1LL << (2*(bits-2));
  1682. res += 1LL << (3*(bits-2));
  1683. res <<= bits;
  1684. if (res > upper_limit)
  1685. res = upper_limit;
  1686. if (res > MAX_LFS_FILESIZE)
  1687. res = MAX_LFS_FILESIZE;
  1688. return res;
  1689. }
  1690. static ext4_fsblk_t descriptor_loc(struct super_block *sb,
  1691. ext4_fsblk_t logical_sb_block, int nr)
  1692. {
  1693. struct ext4_sb_info *sbi = EXT4_SB(sb);
  1694. ext4_group_t bg, first_meta_bg;
  1695. int has_super = 0;
  1696. first_meta_bg = le32_to_cpu(sbi->s_es->s_first_meta_bg);
  1697. if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_META_BG) ||
  1698. nr < first_meta_bg)
  1699. return logical_sb_block + nr + 1;
  1700. bg = sbi->s_desc_per_block * nr;
  1701. if (ext4_bg_has_super(sb, bg))
  1702. has_super = 1;
  1703. return (has_super + ext4_group_first_block_no(sb, bg));
  1704. }
  1705. /**
  1706. * ext4_get_stripe_size: Get the stripe size.
  1707. * @sbi: In memory super block info
  1708. *
  1709. * If we have specified it via mount option, then
  1710. * use the mount option value. If the value specified at mount time is
  1711. * greater than the blocks per group use the super block value.
  1712. * If the super block value is greater than blocks per group return 0.
  1713. * Allocator needs it be less than blocks per group.
  1714. *
  1715. */
  1716. static unsigned long ext4_get_stripe_size(struct ext4_sb_info *sbi)
  1717. {
  1718. unsigned long stride = le16_to_cpu(sbi->s_es->s_raid_stride);
  1719. unsigned long stripe_width =
  1720. le32_to_cpu(sbi->s_es->s_raid_stripe_width);
  1721. if (sbi->s_stripe && sbi->s_stripe <= sbi->s_blocks_per_group)
  1722. return sbi->s_stripe;
  1723. if (stripe_width <= sbi->s_blocks_per_group)
  1724. return stripe_width;
  1725. if (stride <= sbi->s_blocks_per_group)
  1726. return stride;
  1727. return 0;
  1728. }
  1729. static int ext4_fill_super(struct super_block *sb, void *data, int silent)
  1730. __releases(kernel_lock)
  1731. __acquires(kernel_lock)
  1732. {
  1733. struct buffer_head *bh;
  1734. struct ext4_super_block *es = NULL;
  1735. struct ext4_sb_info *sbi;
  1736. ext4_fsblk_t block;
  1737. ext4_fsblk_t sb_block = get_sb_block(&data);
  1738. ext4_fsblk_t logical_sb_block;
  1739. unsigned long offset = 0;
  1740. unsigned int journal_inum = 0;
  1741. unsigned long journal_devnum = 0;
  1742. unsigned long def_mount_opts;
  1743. struct inode *root;
  1744. char *cp;
  1745. const char *descr;
  1746. int ret = -EINVAL;
  1747. int blocksize;
  1748. int db_count;
  1749. int i;
  1750. int needs_recovery, has_huge_files;
  1751. int features;
  1752. __u64 blocks_count;
  1753. int err;
  1754. sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
  1755. if (!sbi)
  1756. return -ENOMEM;
  1757. sb->s_fs_info = sbi;
  1758. sbi->s_mount_opt = 0;
  1759. sbi->s_resuid = EXT4_DEF_RESUID;
  1760. sbi->s_resgid = EXT4_DEF_RESGID;
  1761. sbi->s_inode_readahead_blks = EXT4_DEF_INODE_READAHEAD_BLKS;
  1762. sbi->s_sb_block = sb_block;
  1763. unlock_kernel();
  1764. /* Cleanup superblock name */
  1765. for (cp = sb->s_id; (cp = strchr(cp, '/'));)
  1766. *cp = '!';
  1767. blocksize = sb_min_blocksize(sb, EXT4_MIN_BLOCK_SIZE);
  1768. if (!blocksize) {
  1769. printk(KERN_ERR "EXT4-fs: unable to set blocksize\n");
  1770. goto out_fail;
  1771. }
  1772. /*
  1773. * The ext4 superblock will not be buffer aligned for other than 1kB
  1774. * block sizes. We need to calculate the offset from buffer start.
  1775. */
  1776. if (blocksize != EXT4_MIN_BLOCK_SIZE) {
  1777. logical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE;
  1778. offset = do_div(logical_sb_block, blocksize);
  1779. } else {
  1780. logical_sb_block = sb_block;
  1781. }
  1782. if (!(bh = sb_bread(sb, logical_sb_block))) {
  1783. printk(KERN_ERR "EXT4-fs: unable to read superblock\n");
  1784. goto out_fail;
  1785. }
  1786. /*
  1787. * Note: s_es must be initialized as soon as possible because
  1788. * some ext4 macro-instructions depend on its value
  1789. */
  1790. es = (struct ext4_super_block *) (((char *)bh->b_data) + offset);
  1791. sbi->s_es = es;
  1792. sb->s_magic = le16_to_cpu(es->s_magic);
  1793. if (sb->s_magic != EXT4_SUPER_MAGIC)
  1794. goto cantfind_ext4;
  1795. /* Set defaults before we parse the mount options */
  1796. def_mount_opts = le32_to_cpu(es->s_default_mount_opts);
  1797. if (def_mount_opts & EXT4_DEFM_DEBUG)
  1798. set_opt(sbi->s_mount_opt, DEBUG);
  1799. if (def_mount_opts & EXT4_DEFM_BSDGROUPS)
  1800. set_opt(sbi->s_mount_opt, GRPID);
  1801. if (def_mount_opts & EXT4_DEFM_UID16)
  1802. set_opt(sbi->s_mount_opt, NO_UID32);
  1803. #ifdef CONFIG_EXT4_FS_XATTR
  1804. if (def_mount_opts & EXT4_DEFM_XATTR_USER)
  1805. set_opt(sbi->s_mount_opt, XATTR_USER);
  1806. #endif
  1807. #ifdef CONFIG_EXT4_FS_POSIX_ACL
  1808. if (def_mount_opts & EXT4_DEFM_ACL)
  1809. set_opt(sbi->s_mount_opt, POSIX_ACL);
  1810. #endif
  1811. if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_DATA)
  1812. sbi->s_mount_opt |= EXT4_MOUNT_JOURNAL_DATA;
  1813. else if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_ORDERED)
  1814. sbi->s_mount_opt |= EXT4_MOUNT_ORDERED_DATA;
  1815. else if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_WBACK)
  1816. sbi->s_mount_opt |= EXT4_MOUNT_WRITEBACK_DATA;
  1817. if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_PANIC)
  1818. set_opt(sbi->s_mount_opt, ERRORS_PANIC);
  1819. else if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_CONTINUE)
  1820. set_opt(sbi->s_mount_opt, ERRORS_CONT);
  1821. else
  1822. set_opt(sbi->s_mount_opt, ERRORS_RO);
  1823. sbi->s_resuid = le16_to_cpu(es->s_def_resuid);
  1824. sbi->s_resgid = le16_to_cpu(es->s_def_resgid);
  1825. sbi->s_commit_interval = JBD2_DEFAULT_MAX_COMMIT_AGE * HZ;
  1826. sbi->s_min_batch_time = EXT4_DEF_MIN_BATCH_TIME;
  1827. sbi->s_max_batch_time = EXT4_DEF_MAX_BATCH_TIME;
  1828. set_opt(sbi->s_mount_opt, RESERVATION);
  1829. set_opt(sbi->s_mount_opt, BARRIER);
  1830. /*
  1831. * turn on extents feature by default in ext4 filesystem
  1832. * only if feature flag already set by mkfs or tune2fs.
  1833. * Use -o noextents to turn it off
  1834. */
  1835. if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_EXTENTS))
  1836. set_opt(sbi->s_mount_opt, EXTENTS);
  1837. else
  1838. ext4_warning(sb, __func__,
  1839. "extents feature not enabled on this filesystem, "
  1840. "use tune2fs.");
  1841. /*
  1842. * enable delayed allocation by default
  1843. * Use -o nodelalloc to turn it off
  1844. */
  1845. set_opt(sbi->s_mount_opt, DELALLOC);
  1846. if (!parse_options((char *) data, sb, &journal_inum, &journal_devnum,
  1847. NULL, 0))
  1848. goto failed_mount;
  1849. sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
  1850. ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
  1851. if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV &&
  1852. (EXT4_HAS_COMPAT_FEATURE(sb, ~0U) ||
  1853. EXT4_HAS_RO_COMPAT_FEATURE(sb, ~0U) ||
  1854. EXT4_HAS_INCOMPAT_FEATURE(sb, ~0U)))
  1855. printk(KERN_WARNING
  1856. "EXT4-fs warning: feature flags set on rev 0 fs, "
  1857. "running e2fsck is recommended\n");
  1858. /*
  1859. * Check feature flags regardless of the revision level, since we
  1860. * previously didn't change the revision level when setting the flags,
  1861. * so there is a chance incompat flags are set on a rev 0 filesystem.
  1862. */
  1863. features = EXT4_HAS_INCOMPAT_FEATURE(sb, ~EXT4_FEATURE_INCOMPAT_SUPP);
  1864. if (features) {
  1865. printk(KERN_ERR "EXT4-fs: %s: couldn't mount because of "
  1866. "unsupported optional features (%x).\n", sb->s_id,
  1867. (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_incompat) &
  1868. ~EXT4_FEATURE_INCOMPAT_SUPP));
  1869. goto failed_mount;
  1870. }
  1871. features = EXT4_HAS_RO_COMPAT_FEATURE(sb, ~EXT4_FEATURE_RO_COMPAT_SUPP);
  1872. if (!(sb->s_flags & MS_RDONLY) && features) {
  1873. printk(KERN_ERR "EXT4-fs: %s: couldn't mount RDWR because of "
  1874. "unsupported optional features (%x).\n", sb->s_id,
  1875. (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_ro_compat) &
  1876. ~EXT4_FEATURE_RO_COMPAT_SUPP));
  1877. goto failed_mount;
  1878. }
  1879. has_huge_files = EXT4_HAS_RO_COMPAT_FEATURE(sb,
  1880. EXT4_FEATURE_RO_COMPAT_HUGE_FILE);
  1881. if (has_huge_files) {
  1882. /*
  1883. * Large file size enabled file system can only be
  1884. * mount if kernel is build with CONFIG_LBD
  1885. */
  1886. if (sizeof(root->i_blocks) < sizeof(u64) &&
  1887. !(sb->s_flags & MS_RDONLY)) {
  1888. printk(KERN_ERR "EXT4-fs: %s: Filesystem with huge "
  1889. "files cannot be mounted read-write "
  1890. "without CONFIG_LBD.\n", sb->s_id);
  1891. goto failed_mount;
  1892. }
  1893. }
  1894. blocksize = BLOCK_SIZE << le32_to_cpu(es->s_log_block_size);
  1895. if (blocksize < EXT4_MIN_BLOCK_SIZE ||
  1896. blocksize > EXT4_MAX_BLOCK_SIZE) {
  1897. printk(KERN_ERR
  1898. "EXT4-fs: Unsupported filesystem blocksize %d on %s.\n",
  1899. blocksize, sb->s_id);
  1900. goto failed_mount;
  1901. }
  1902. if (sb->s_blocksize != blocksize) {
  1903. /* Validate the filesystem blocksize */
  1904. if (!sb_set_blocksize(sb, blocksize)) {
  1905. printk(KERN_ERR "EXT4-fs: bad block size %d.\n",
  1906. blocksize);
  1907. goto failed_mount;
  1908. }
  1909. brelse(bh);
  1910. logical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE;
  1911. offset = do_div(logical_sb_block, blocksize);
  1912. bh = sb_bread(sb, logical_sb_block);
  1913. if (!bh) {
  1914. printk(KERN_ERR
  1915. "EXT4-fs: Can't read superblock on 2nd try.\n");
  1916. goto failed_mount;
  1917. }
  1918. es = (struct ext4_super_block *)(((char *)bh->b_data) + offset);
  1919. sbi->s_es = es;
  1920. if (es->s_magic != cpu_to_le16(EXT4_SUPER_MAGIC)) {
  1921. printk(KERN_ERR
  1922. "EXT4-fs: Magic mismatch, very weird !\n");
  1923. goto failed_mount;
  1924. }
  1925. }
  1926. sbi->s_bitmap_maxbytes = ext4_max_bitmap_size(sb->s_blocksize_bits,
  1927. has_huge_files);
  1928. sb->s_maxbytes = ext4_max_size(sb->s_blocksize_bits, has_huge_files);
  1929. if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV) {
  1930. sbi->s_inode_size = EXT4_GOOD_OLD_INODE_SIZE;
  1931. sbi->s_first_ino = EXT4_GOOD_OLD_FIRST_INO;
  1932. } else {
  1933. sbi->s_inode_size = le16_to_cpu(es->s_inode_size);
  1934. sbi->s_first_ino = le32_to_cpu(es->s_first_ino);
  1935. if ((sbi->s_inode_size < EXT4_GOOD_OLD_INODE_SIZE) ||
  1936. (!is_power_of_2(sbi->s_inode_size)) ||
  1937. (sbi->s_inode_size > blocksize)) {
  1938. printk(KERN_ERR
  1939. "EXT4-fs: unsupported inode size: %d\n",
  1940. sbi->s_inode_size);
  1941. goto failed_mount;
  1942. }
  1943. if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE)
  1944. sb->s_time_gran = 1 << (EXT4_EPOCH_BITS - 2);
  1945. }
  1946. sbi->s_desc_size = le16_to_cpu(es->s_desc_size);
  1947. if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_64BIT)) {
  1948. if (sbi->s_desc_size < EXT4_MIN_DESC_SIZE_64BIT ||
  1949. sbi->s_desc_size > EXT4_MAX_DESC_SIZE ||
  1950. !is_power_of_2(sbi->s_desc_size)) {
  1951. printk(KERN_ERR
  1952. "EXT4-fs: unsupported descriptor size %lu\n",
  1953. sbi->s_desc_size);
  1954. goto failed_mount;
  1955. }
  1956. } else
  1957. sbi->s_desc_size = EXT4_MIN_DESC_SIZE;
  1958. sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group);
  1959. sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group);
  1960. if (EXT4_INODE_SIZE(sb) == 0 || EXT4_INODES_PER_GROUP(sb) == 0)
  1961. goto cantfind_ext4;
  1962. sbi->s_inodes_per_block = blocksize / EXT4_INODE_SIZE(sb);
  1963. if (sbi->s_inodes_per_block == 0)
  1964. goto cantfind_ext4;
  1965. sbi->s_itb_per_group = sbi->s_inodes_per_group /
  1966. sbi->s_inodes_per_block;
  1967. sbi->s_desc_per_block = blocksize / EXT4_DESC_SIZE(sb);
  1968. sbi->s_sbh = bh;
  1969. sbi->s_mount_state = le16_to_cpu(es->s_state);
  1970. sbi->s_addr_per_block_bits = ilog2(EXT4_ADDR_PER_BLOCK(sb));
  1971. sbi->s_desc_per_block_bits = ilog2(EXT4_DESC_PER_BLOCK(sb));
  1972. for (i = 0; i < 4; i++)
  1973. sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]);
  1974. sbi->s_def_hash_version = es->s_def_hash_version;
  1975. i = le32_to_cpu(es->s_flags);
  1976. if (i & EXT2_FLAGS_UNSIGNED_HASH)
  1977. sbi->s_hash_unsigned = 3;
  1978. else if ((i & EXT2_FLAGS_SIGNED_HASH) == 0) {
  1979. #ifdef __CHAR_UNSIGNED__
  1980. es->s_flags |= cpu_to_le32(EXT2_FLAGS_UNSIGNED_HASH);
  1981. sbi->s_hash_unsigned = 3;
  1982. #else
  1983. es->s_flags |= cpu_to_le32(EXT2_FLAGS_SIGNED_HASH);
  1984. #endif
  1985. sb->s_dirt = 1;
  1986. }
  1987. if (sbi->s_blocks_per_group > blocksize * 8) {
  1988. printk(KERN_ERR
  1989. "EXT4-fs: #blocks per group too big: %lu\n",
  1990. sbi->s_blocks_per_group);
  1991. goto failed_mount;
  1992. }
  1993. if (sbi->s_inodes_per_group > blocksize * 8) {
  1994. printk(KERN_ERR
  1995. "EXT4-fs: #inodes per group too big: %lu\n",
  1996. sbi->s_inodes_per_group);
  1997. goto failed_mount;
  1998. }
  1999. if (ext4_blocks_count(es) >
  2000. (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) {
  2001. printk(KERN_ERR "EXT4-fs: filesystem on %s:"
  2002. " too large to mount safely\n", sb->s_id);
  2003. if (sizeof(sector_t) < 8)
  2004. printk(KERN_WARNING "EXT4-fs: CONFIG_LBD not "
  2005. "enabled\n");
  2006. goto failed_mount;
  2007. }
  2008. if (EXT4_BLOCKS_PER_GROUP(sb) == 0)
  2009. goto cantfind_ext4;
  2010. /* ensure blocks_count calculation below doesn't sign-extend */
  2011. if (ext4_blocks_count(es) + EXT4_BLOCKS_PER_GROUP(sb) <
  2012. le32_to_cpu(es->s_first_data_block) + 1) {
  2013. printk(KERN_WARNING "EXT4-fs: bad geometry: block count %llu, "
  2014. "first data block %u, blocks per group %lu\n",
  2015. ext4_blocks_count(es),
  2016. le32_to_cpu(es->s_first_data_block),
  2017. EXT4_BLOCKS_PER_GROUP(sb));
  2018. goto failed_mount;
  2019. }
  2020. blocks_count = (ext4_blocks_count(es) -
  2021. le32_to_cpu(es->s_first_data_block) +
  2022. EXT4_BLOCKS_PER_GROUP(sb) - 1);
  2023. do_div(blocks_count, EXT4_BLOCKS_PER_GROUP(sb));
  2024. sbi->s_groups_count = blocks_count;
  2025. db_count = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 1) /
  2026. EXT4_DESC_PER_BLOCK(sb);
  2027. sbi->s_group_desc = kmalloc(db_count * sizeof(struct buffer_head *),
  2028. GFP_KERNEL);
  2029. if (sbi->s_group_desc == NULL) {
  2030. printk(KERN_ERR "EXT4-fs: not enough memory\n");
  2031. goto failed_mount;
  2032. }
  2033. #ifdef CONFIG_PROC_FS
  2034. if (ext4_proc_root)
  2035. sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root);
  2036. if (sbi->s_proc)
  2037. proc_create_data("inode_readahead_blks", 0644, sbi->s_proc,
  2038. &ext4_ui_proc_fops,
  2039. &sbi->s_inode_readahead_blks);
  2040. #endif
  2041. bgl_lock_init(&sbi->s_blockgroup_lock);
  2042. for (i = 0; i < db_count; i++) {
  2043. block = descriptor_loc(sb, logical_sb_block, i);
  2044. sbi->s_group_desc[i] = sb_bread(sb, block);
  2045. if (!sbi->s_group_desc[i]) {
  2046. printk(KERN_ERR "EXT4-fs: "
  2047. "can't read group descriptor %d\n", i);
  2048. db_count = i;
  2049. goto failed_mount2;
  2050. }
  2051. }
  2052. if (!ext4_check_descriptors(sb)) {
  2053. printk(KERN_ERR "EXT4-fs: group descriptors corrupted!\n");
  2054. goto failed_mount2;
  2055. }
  2056. if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG))
  2057. if (!ext4_fill_flex_info(sb)) {
  2058. printk(KERN_ERR
  2059. "EXT4-fs: unable to initialize "
  2060. "flex_bg meta info!\n");
  2061. goto failed_mount2;
  2062. }
  2063. sbi->s_gdb_count = db_count;
  2064. get_random_bytes(&sbi->s_next_generation, sizeof(u32));
  2065. spin_lock_init(&sbi->s_next_gen_lock);
  2066. err = percpu_counter_init(&sbi->s_freeblocks_counter,
  2067. ext4_count_free_blocks(sb));
  2068. if (!err) {
  2069. err = percpu_counter_init(&sbi->s_freeinodes_counter,
  2070. ext4_count_free_inodes(sb));
  2071. }
  2072. if (!err) {
  2073. err = percpu_counter_init(&sbi->s_dirs_counter,
  2074. ext4_count_dirs(sb));
  2075. }
  2076. if (!err) {
  2077. err = percpu_counter_init(&sbi->s_dirtyblocks_counter, 0);
  2078. }
  2079. if (err) {
  2080. printk(KERN_ERR "EXT4-fs: insufficient memory\n");
  2081. goto failed_mount3;
  2082. }
  2083. sbi->s_stripe = ext4_get_stripe_size(sbi);
  2084. /*
  2085. * set up enough so that it can read an inode
  2086. */
  2087. sb->s_op = &ext4_sops;
  2088. sb->s_export_op = &ext4_export_ops;
  2089. sb->s_xattr = ext4_xattr_handlers;
  2090. #ifdef CONFIG_QUOTA
  2091. sb->s_qcop = &ext4_qctl_operations;
  2092. sb->dq_op = &ext4_quota_operations;
  2093. #endif
  2094. INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */
  2095. sb->s_root = NULL;
  2096. needs_recovery = (es->s_last_orphan != 0 ||
  2097. EXT4_HAS_INCOMPAT_FEATURE(sb,
  2098. EXT4_FEATURE_INCOMPAT_RECOVER));
  2099. /*
  2100. * The first inode we look at is the journal inode. Don't try
  2101. * root first: it may be modified in the journal!
  2102. */
  2103. if (!test_opt(sb, NOLOAD) &&
  2104. EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) {
  2105. if (ext4_load_journal(sb, es, journal_devnum))
  2106. goto failed_mount3;
  2107. if (!(sb->s_flags & MS_RDONLY) &&
  2108. EXT4_SB(sb)->s_journal->j_failed_commit) {
  2109. printk(KERN_CRIT "EXT4-fs error (device %s): "
  2110. "ext4_fill_super: Journal transaction "
  2111. "%u is corrupt\n", sb->s_id,
  2112. EXT4_SB(sb)->s_journal->j_failed_commit);
  2113. if (test_opt(sb, ERRORS_RO)) {
  2114. printk(KERN_CRIT
  2115. "Mounting filesystem read-only\n");
  2116. sb->s_flags |= MS_RDONLY;
  2117. EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
  2118. es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
  2119. }
  2120. if (test_opt(sb, ERRORS_PANIC)) {
  2121. EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
  2122. es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
  2123. ext4_commit_super(sb, es, 1);
  2124. goto failed_mount4;
  2125. }
  2126. }
  2127. } else if (journal_inum) {
  2128. if (ext4_create_journal(sb, es, journal_inum))
  2129. goto failed_mount3;
  2130. } else if (test_opt(sb, NOLOAD) && !(sb->s_flags & MS_RDONLY) &&
  2131. EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) {
  2132. printk(KERN_ERR "EXT4-fs: required journal recovery "
  2133. "suppressed and not mounted read-only\n");
  2134. goto failed_mount4;
  2135. } else {
  2136. clear_opt(sbi->s_mount_opt, DATA_FLAGS);
  2137. set_opt(sbi->s_mount_opt, WRITEBACK_DATA);
  2138. sbi->s_journal = NULL;
  2139. needs_recovery = 0;
  2140. goto no_journal;
  2141. }
  2142. if (ext4_blocks_count(es) > 0xffffffffULL &&
  2143. !jbd2_journal_set_features(EXT4_SB(sb)->s_journal, 0, 0,
  2144. JBD2_FEATURE_INCOMPAT_64BIT)) {
  2145. printk(KERN_ERR "ext4: Failed to set 64-bit journal feature\n");
  2146. goto failed_mount4;
  2147. }
  2148. if (test_opt(sb, JOURNAL_ASYNC_COMMIT)) {
  2149. jbd2_journal_set_features(sbi->s_journal,
  2150. JBD2_FEATURE_COMPAT_CHECKSUM, 0,
  2151. JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
  2152. } else if (test_opt(sb, JOURNAL_CHECKSUM)) {
  2153. jbd2_journal_set_features(sbi->s_journal,
  2154. JBD2_FEATURE_COMPAT_CHECKSUM, 0, 0);
  2155. jbd2_journal_clear_features(sbi->s_journal, 0, 0,
  2156. JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
  2157. } else {
  2158. jbd2_journal_clear_features(sbi->s_journal,
  2159. JBD2_FEATURE_COMPAT_CHECKSUM, 0,
  2160. JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
  2161. }
  2162. /* We have now updated the journal if required, so we can
  2163. * validate the data journaling mode. */
  2164. switch (test_opt(sb, DATA_FLAGS)) {
  2165. case 0:
  2166. /* No mode set, assume a default based on the journal
  2167. * capabilities: ORDERED_DATA if the journal can
  2168. * cope, else JOURNAL_DATA
  2169. */
  2170. if (jbd2_journal_check_available_features
  2171. (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE))
  2172. set_opt(sbi->s_mount_opt, ORDERED_DATA);
  2173. else
  2174. set_opt(sbi->s_mount_opt, JOURNAL_DATA);
  2175. break;
  2176. case EXT4_MOUNT_ORDERED_DATA:
  2177. case EXT4_MOUNT_WRITEBACK_DATA:
  2178. if (!jbd2_journal_check_available_features
  2179. (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE)) {
  2180. printk(KERN_ERR "EXT4-fs: Journal does not support "
  2181. "requested data journaling mode\n");
  2182. goto failed_mount4;
  2183. }
  2184. default:
  2185. break;
  2186. }
  2187. no_journal:
  2188. if (test_opt(sb, NOBH)) {
  2189. if (!(test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)) {
  2190. printk(KERN_WARNING "EXT4-fs: Ignoring nobh option - "
  2191. "its supported only with writeback mode\n");
  2192. clear_opt(sbi->s_mount_opt, NOBH);
  2193. }
  2194. }
  2195. /*
  2196. * The jbd2_journal_load will have done any necessary log recovery,
  2197. * so we can safely mount the rest of the filesystem now.
  2198. */
  2199. root = ext4_iget(sb, EXT4_ROOT_INO);
  2200. if (IS_ERR(root)) {
  2201. printk(KERN_ERR "EXT4-fs: get root inode failed\n");
  2202. ret = PTR_ERR(root);
  2203. goto failed_mount4;
  2204. }
  2205. if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {
  2206. iput(root);
  2207. printk(KERN_ERR "EXT4-fs: corrupt root inode, run e2fsck\n");
  2208. goto failed_mount4;
  2209. }
  2210. sb->s_root = d_alloc_root(root);
  2211. if (!sb->s_root) {
  2212. printk(KERN_ERR "EXT4-fs: get root dentry failed\n");
  2213. iput(root);
  2214. ret = -ENOMEM;
  2215. goto failed_mount4;
  2216. }
  2217. ext4_setup_super(sb, es, sb->s_flags & MS_RDONLY);
  2218. /* determine the minimum size of new large inodes, if present */
  2219. if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) {
  2220. sbi->s_want_extra_isize = sizeof(struct ext4_inode) -
  2221. EXT4_GOOD_OLD_INODE_SIZE;
  2222. if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
  2223. EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE)) {
  2224. if (sbi->s_want_extra_isize <
  2225. le16_to_cpu(es->s_want_extra_isize))
  2226. sbi->s_want_extra_isize =
  2227. le16_to_cpu(es->s_want_extra_isize);
  2228. if (sbi->s_want_extra_isize <
  2229. le16_to_cpu(es->s_min_extra_isize))
  2230. sbi->s_want_extra_isize =
  2231. le16_to_cpu(es->s_min_extra_isize);
  2232. }
  2233. }
  2234. /* Check if enough inode space is available */
  2235. if (EXT4_GOOD_OLD_INODE_SIZE + sbi->s_want_extra_isize >
  2236. sbi->s_inode_size) {
  2237. sbi->s_want_extra_isize = sizeof(struct ext4_inode) -
  2238. EXT4_GOOD_OLD_INODE_SIZE;
  2239. printk(KERN_INFO "EXT4-fs: required extra inode space not"
  2240. "available.\n");
  2241. }
  2242. if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) {
  2243. printk(KERN_WARNING "EXT4-fs: Ignoring delalloc option - "
  2244. "requested data journaling mode\n");
  2245. clear_opt(sbi->s_mount_opt, DELALLOC);
  2246. } else if (test_opt(sb, DELALLOC))
  2247. printk(KERN_INFO "EXT4-fs: delayed allocation enabled\n");
  2248. ext4_ext_init(sb);
  2249. err = ext4_mb_init(sb, needs_recovery);
  2250. if (err) {
  2251. printk(KERN_ERR "EXT4-fs: failed to initalize mballoc (%d)\n",
  2252. err);
  2253. goto failed_mount4;
  2254. }
  2255. /*
  2256. * akpm: core read_super() calls in here with the superblock locked.
  2257. * That deadlocks, because orphan cleanup needs to lock the superblock
  2258. * in numerous places. Here we just pop the lock - it's relatively
  2259. * harmless, because we are now ready to accept write_super() requests,
  2260. * and aviro says that's the only reason for hanging onto the
  2261. * superblock lock.
  2262. */
  2263. EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS;
  2264. ext4_orphan_cleanup(sb, es);
  2265. EXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS;
  2266. if (needs_recovery) {
  2267. printk(KERN_INFO "EXT4-fs: recovery complete.\n");
  2268. ext4_mark_recovery_complete(sb, es);
  2269. }
  2270. if (EXT4_SB(sb)->s_journal) {
  2271. if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)
  2272. descr = " journalled data mode";
  2273. else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA)
  2274. descr = " ordered data mode";
  2275. else
  2276. descr = " writeback data mode";
  2277. } else
  2278. descr = "out journal";
  2279. printk(KERN_INFO "EXT4-fs: mounted filesystem %s with%s\n",
  2280. sb->s_id, descr);
  2281. lock_kernel();
  2282. return 0;
  2283. cantfind_ext4:
  2284. if (!silent)
  2285. printk(KERN_ERR "VFS: Can't find ext4 filesystem on dev %s.\n",
  2286. sb->s_id);
  2287. goto failed_mount;
  2288. failed_mount4:
  2289. printk(KERN_ERR "EXT4-fs (device %s): mount failed\n", sb->s_id);
  2290. if (sbi->s_journal) {
  2291. jbd2_journal_destroy(sbi->s_journal);
  2292. sbi->s_journal = NULL;
  2293. }
  2294. failed_mount3:
  2295. percpu_counter_destroy(&sbi->s_freeblocks_counter);
  2296. percpu_counter_destroy(&sbi->s_freeinodes_counter);
  2297. percpu_counter_destroy(&sbi->s_dirs_counter);
  2298. percpu_counter_destroy(&sbi->s_dirtyblocks_counter);
  2299. failed_mount2:
  2300. for (i = 0; i < db_count; i++)
  2301. brelse(sbi->s_group_desc[i]);
  2302. kfree(sbi->s_group_desc);
  2303. failed_mount:
  2304. if (sbi->s_proc) {
  2305. remove_proc_entry("inode_readahead_blks", sbi->s_proc);
  2306. remove_proc_entry(sb->s_id, ext4_proc_root);
  2307. }
  2308. #ifdef CONFIG_QUOTA
  2309. for (i = 0; i < MAXQUOTAS; i++)
  2310. kfree(sbi->s_qf_names[i]);
  2311. #endif
  2312. ext4_blkdev_remove(sbi);
  2313. brelse(bh);
  2314. out_fail:
  2315. sb->s_fs_info = NULL;
  2316. kfree(sbi);
  2317. lock_kernel();
  2318. return ret;
  2319. }
  2320. /*
  2321. * Setup any per-fs journal parameters now. We'll do this both on
  2322. * initial mount, once the journal has been initialised but before we've
  2323. * done any recovery; and again on any subsequent remount.
  2324. */
  2325. static void ext4_init_journal_params(struct super_block *sb, journal_t *journal)
  2326. {
  2327. struct ext4_sb_info *sbi = EXT4_SB(sb);
  2328. journal->j_commit_interval = sbi->s_commit_interval;
  2329. journal->j_min_batch_time = sbi->s_min_batch_time;
  2330. journal->j_max_batch_time = sbi->s_max_batch_time;
  2331. spin_lock(&journal->j_state_lock);
  2332. if (test_opt(sb, BARRIER))
  2333. journal->j_flags |= JBD2_BARRIER;
  2334. else
  2335. journal->j_flags &= ~JBD2_BARRIER;
  2336. if (test_opt(sb, DATA_ERR_ABORT))
  2337. journal->j_flags |= JBD2_ABORT_ON_SYNCDATA_ERR;
  2338. else
  2339. journal->j_flags &= ~JBD2_ABORT_ON_SYNCDATA_ERR;
  2340. spin_unlock(&journal->j_state_lock);
  2341. }
  2342. static journal_t *ext4_get_journal(struct super_block *sb,
  2343. unsigned int journal_inum)
  2344. {
  2345. struct inode *journal_inode;
  2346. journal_t *journal;
  2347. BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL));
  2348. /* First, test for the existence of a valid inode on disk. Bad
  2349. * things happen if we iget() an unused inode, as the subsequent
  2350. * iput() will try to delete it. */
  2351. journal_inode = ext4_iget(sb, journal_inum);
  2352. if (IS_ERR(journal_inode)) {
  2353. printk(KERN_ERR "EXT4-fs: no journal found.\n");
  2354. return NULL;
  2355. }
  2356. if (!journal_inode->i_nlink) {
  2357. make_bad_inode(journal_inode);
  2358. iput(journal_inode);
  2359. printk(KERN_ERR "EXT4-fs: journal inode is deleted.\n");
  2360. return NULL;
  2361. }
  2362. jbd_debug(2, "Journal inode found at %p: %lld bytes\n",
  2363. journal_inode, journal_inode->i_size);
  2364. if (!S_ISREG(journal_inode->i_mode)) {
  2365. printk(KERN_ERR "EXT4-fs: invalid journal inode.\n");
  2366. iput(journal_inode);
  2367. return NULL;
  2368. }
  2369. journal = jbd2_journal_init_inode(journal_inode);
  2370. if (!journal) {
  2371. printk(KERN_ERR "EXT4-fs: Could not load journal inode\n");
  2372. iput(journal_inode);
  2373. return NULL;
  2374. }
  2375. journal->j_private = sb;
  2376. ext4_init_journal_params(sb, journal);
  2377. return journal;
  2378. }
  2379. static journal_t *ext4_get_dev_journal(struct super_block *sb,
  2380. dev_t j_dev)
  2381. {
  2382. struct buffer_head *bh;
  2383. journal_t *journal;
  2384. ext4_fsblk_t start;
  2385. ext4_fsblk_t len;
  2386. int hblock, blocksize;
  2387. ext4_fsblk_t sb_block;
  2388. unsigned long offset;
  2389. struct ext4_super_block *es;
  2390. struct block_device *bdev;
  2391. BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL));
  2392. bdev = ext4_blkdev_get(j_dev);
  2393. if (bdev == NULL)
  2394. return NULL;
  2395. if (bd_claim(bdev, sb)) {
  2396. printk(KERN_ERR
  2397. "EXT4: failed to claim external journal device.\n");
  2398. blkdev_put(bdev, FMODE_READ|FMODE_WRITE);
  2399. return NULL;
  2400. }
  2401. blocksize = sb->s_blocksize;
  2402. hblock = bdev_hardsect_size(bdev);
  2403. if (blocksize < hblock) {
  2404. printk(KERN_ERR
  2405. "EXT4-fs: blocksize too small for journal device.\n");
  2406. goto out_bdev;
  2407. }
  2408. sb_block = EXT4_MIN_BLOCK_SIZE / blocksize;
  2409. offset = EXT4_MIN_BLOCK_SIZE % blocksize;
  2410. set_blocksize(bdev, blocksize);
  2411. if (!(bh = __bread(bdev, sb_block, blocksize))) {
  2412. printk(KERN_ERR "EXT4-fs: couldn't read superblock of "
  2413. "external journal\n");
  2414. goto out_bdev;
  2415. }
  2416. es = (struct ext4_super_block *) (((char *)bh->b_data) + offset);
  2417. if ((le16_to_cpu(es->s_magic) != EXT4_SUPER_MAGIC) ||
  2418. !(le32_to_cpu(es->s_feature_incompat) &
  2419. EXT4_FEATURE_INCOMPAT_JOURNAL_DEV)) {
  2420. printk(KERN_ERR "EXT4-fs: external journal has "
  2421. "bad superblock\n");
  2422. brelse(bh);
  2423. goto out_bdev;
  2424. }
  2425. if (memcmp(EXT4_SB(sb)->s_es->s_journal_uuid, es->s_uuid, 16)) {
  2426. printk(KERN_ERR "EXT4-fs: journal UUID does not match\n");
  2427. brelse(bh);
  2428. goto out_bdev;
  2429. }
  2430. len = ext4_blocks_count(es);
  2431. start = sb_block + 1;
  2432. brelse(bh); /* we're done with the superblock */
  2433. journal = jbd2_journal_init_dev(bdev, sb->s_bdev,
  2434. start, len, blocksize);
  2435. if (!journal) {
  2436. printk(KERN_ERR "EXT4-fs: failed to create device journal\n");
  2437. goto out_bdev;
  2438. }
  2439. journal->j_private = sb;
  2440. ll_rw_block(READ, 1, &journal->j_sb_buffer);
  2441. wait_on_buffer(journal->j_sb_buffer);
  2442. if (!buffer_uptodate(journal->j_sb_buffer)) {
  2443. printk(KERN_ERR "EXT4-fs: I/O error on journal device\n");
  2444. goto out_journal;
  2445. }
  2446. if (be32_to_cpu(journal->j_superblock->s_nr_users) != 1) {
  2447. printk(KERN_ERR "EXT4-fs: External journal has more than one "
  2448. "user (unsupported) - %d\n",
  2449. be32_to_cpu(journal->j_superblock->s_nr_users));
  2450. goto out_journal;
  2451. }
  2452. EXT4_SB(sb)->journal_bdev = bdev;
  2453. ext4_init_journal_params(sb, journal);
  2454. return journal;
  2455. out_journal:
  2456. jbd2_journal_destroy(journal);
  2457. out_bdev:
  2458. ext4_blkdev_put(bdev);
  2459. return NULL;
  2460. }
  2461. static int ext4_load_journal(struct super_block *sb,
  2462. struct ext4_super_block *es,
  2463. unsigned long journal_devnum)
  2464. {
  2465. journal_t *journal;
  2466. unsigned int journal_inum = le32_to_cpu(es->s_journal_inum);
  2467. dev_t journal_dev;
  2468. int err = 0;
  2469. int really_read_only;
  2470. BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL));
  2471. if (journal_devnum &&
  2472. journal_devnum != le32_to_cpu(es->s_journal_dev)) {
  2473. printk(KERN_INFO "EXT4-fs: external journal device major/minor "
  2474. "numbers have changed\n");
  2475. journal_dev = new_decode_dev(journal_devnum);
  2476. } else
  2477. journal_dev = new_decode_dev(le32_to_cpu(es->s_journal_dev));
  2478. really_read_only = bdev_read_only(sb->s_bdev);
  2479. /*
  2480. * Are we loading a blank journal or performing recovery after a
  2481. * crash? For recovery, we need to check in advance whether we
  2482. * can get read-write access to the device.
  2483. */
  2484. if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) {
  2485. if (sb->s_flags & MS_RDONLY) {
  2486. printk(KERN_INFO "EXT4-fs: INFO: recovery "
  2487. "required on readonly filesystem.\n");
  2488. if (really_read_only) {
  2489. printk(KERN_ERR "EXT4-fs: write access "
  2490. "unavailable, cannot proceed.\n");
  2491. return -EROFS;
  2492. }
  2493. printk(KERN_INFO "EXT4-fs: write access will "
  2494. "be enabled during recovery.\n");
  2495. }
  2496. }
  2497. if (journal_inum && journal_dev) {
  2498. printk(KERN_ERR "EXT4-fs: filesystem has both journal "
  2499. "and inode journals!\n");
  2500. return -EINVAL;
  2501. }
  2502. if (journal_inum) {
  2503. if (!(journal = ext4_get_journal(sb, journal_inum)))
  2504. return -EINVAL;
  2505. } else {
  2506. if (!(journal = ext4_get_dev_journal(sb, journal_dev)))
  2507. return -EINVAL;
  2508. }
  2509. if (journal->j_flags & JBD2_BARRIER)
  2510. printk(KERN_INFO "EXT4-fs: barriers enabled\n");
  2511. else
  2512. printk(KERN_INFO "EXT4-fs: barriers disabled\n");
  2513. if (!really_read_only && test_opt(sb, UPDATE_JOURNAL)) {
  2514. err = jbd2_journal_update_format(journal);
  2515. if (err) {
  2516. printk(KERN_ERR "EXT4-fs: error updating journal.\n");
  2517. jbd2_journal_destroy(journal);
  2518. return err;
  2519. }
  2520. }
  2521. if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER))
  2522. err = jbd2_journal_wipe(journal, !really_read_only);
  2523. if (!err)
  2524. err = jbd2_journal_load(journal);
  2525. if (err) {
  2526. printk(KERN_ERR "EXT4-fs: error loading journal.\n");
  2527. jbd2_journal_destroy(journal);
  2528. return err;
  2529. }
  2530. EXT4_SB(sb)->s_journal = journal;
  2531. ext4_clear_journal_err(sb, es);
  2532. if (journal_devnum &&
  2533. journal_devnum != le32_to_cpu(es->s_journal_dev)) {
  2534. es->s_journal_dev = cpu_to_le32(journal_devnum);
  2535. sb->s_dirt = 1;
  2536. /* Make sure we flush the recovery flag to disk. */
  2537. ext4_commit_super(sb, es, 1);
  2538. }
  2539. return 0;
  2540. }
  2541. static int ext4_create_journal(struct super_block *sb,
  2542. struct ext4_super_block *es,
  2543. unsigned int journal_inum)
  2544. {
  2545. journal_t *journal;
  2546. int err;
  2547. if (sb->s_flags & MS_RDONLY) {
  2548. printk(KERN_ERR "EXT4-fs: readonly filesystem when trying to "
  2549. "create journal.\n");
  2550. return -EROFS;
  2551. }
  2552. journal = ext4_get_journal(sb, journal_inum);
  2553. if (!journal)
  2554. return -EINVAL;
  2555. printk(KERN_INFO "EXT4-fs: creating new journal on inode %u\n",
  2556. journal_inum);
  2557. err = jbd2_journal_create(journal);
  2558. if (err) {
  2559. printk(KERN_ERR "EXT4-fs: error creating journal.\n");
  2560. jbd2_journal_destroy(journal);
  2561. return -EIO;
  2562. }
  2563. EXT4_SB(sb)->s_journal = journal;
  2564. ext4_update_dynamic_rev(sb);
  2565. EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
  2566. EXT4_SET_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL);
  2567. es->s_journal_inum = cpu_to_le32(journal_inum);
  2568. sb->s_dirt = 1;
  2569. /* Make sure we flush the recovery flag to disk. */
  2570. ext4_commit_super(sb, es, 1);
  2571. return 0;
  2572. }
  2573. static void ext4_commit_super(struct super_block *sb,
  2574. struct ext4_super_block *es, int sync)
  2575. {
  2576. struct buffer_head *sbh = EXT4_SB(sb)->s_sbh;
  2577. if (!sbh)
  2578. return;
  2579. if (buffer_write_io_error(sbh)) {
  2580. /*
  2581. * Oh, dear. A previous attempt to write the
  2582. * superblock failed. This could happen because the
  2583. * USB device was yanked out. Or it could happen to
  2584. * be a transient write error and maybe the block will
  2585. * be remapped. Nothing we can do but to retry the
  2586. * write and hope for the best.
  2587. */
  2588. printk(KERN_ERR "ext4: previous I/O error to "
  2589. "superblock detected for %s.\n", sb->s_id);
  2590. clear_buffer_write_io_error(sbh);
  2591. set_buffer_uptodate(sbh);
  2592. }
  2593. es->s_wtime = cpu_to_le32(get_seconds());
  2594. ext4_free_blocks_count_set(es, ext4_count_free_blocks(sb));
  2595. es->s_free_inodes_count = cpu_to_le32(ext4_count_free_inodes(sb));
  2596. BUFFER_TRACE(sbh, "marking dirty");
  2597. mark_buffer_dirty(sbh);
  2598. if (sync) {
  2599. sync_dirty_buffer(sbh);
  2600. if (buffer_write_io_error(sbh)) {
  2601. printk(KERN_ERR "ext4: I/O error while writing "
  2602. "superblock for %s.\n", sb->s_id);
  2603. clear_buffer_write_io_error(sbh);
  2604. set_buffer_uptodate(sbh);
  2605. }
  2606. }
  2607. }
  2608. /*
  2609. * Have we just finished recovery? If so, and if we are mounting (or
  2610. * remounting) the filesystem readonly, then we will end up with a
  2611. * consistent fs on disk. Record that fact.
  2612. */
  2613. static void ext4_mark_recovery_complete(struct super_block *sb,
  2614. struct ext4_super_block *es)
  2615. {
  2616. journal_t *journal = EXT4_SB(sb)->s_journal;
  2617. if (!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) {
  2618. BUG_ON(journal != NULL);
  2619. return;
  2620. }
  2621. jbd2_journal_lock_updates(journal);
  2622. if (jbd2_journal_flush(journal) < 0)
  2623. goto out;
  2624. lock_super(sb);
  2625. if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER) &&
  2626. sb->s_flags & MS_RDONLY) {
  2627. EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
  2628. sb->s_dirt = 0;
  2629. ext4_commit_super(sb, es, 1);
  2630. }
  2631. unlock_super(sb);
  2632. out:
  2633. jbd2_journal_unlock_updates(journal);
  2634. }
  2635. /*
  2636. * If we are mounting (or read-write remounting) a filesystem whose journal
  2637. * has recorded an error from a previous lifetime, move that error to the
  2638. * main filesystem now.
  2639. */
  2640. static void ext4_clear_journal_err(struct super_block *sb,
  2641. struct ext4_super_block *es)
  2642. {
  2643. journal_t *journal;
  2644. int j_errno;
  2645. const char *errstr;
  2646. BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL));
  2647. journal = EXT4_SB(sb)->s_journal;
  2648. /*
  2649. * Now check for any error status which may have been recorded in the
  2650. * journal by a prior ext4_error() or ext4_abort()
  2651. */
  2652. j_errno = jbd2_journal_errno(journal);
  2653. if (j_errno) {
  2654. char nbuf[16];
  2655. errstr = ext4_decode_error(sb, j_errno, nbuf);
  2656. ext4_warning(sb, __func__, "Filesystem error recorded "
  2657. "from previous mount: %s", errstr);
  2658. ext4_warning(sb, __func__, "Marking fs in need of "
  2659. "filesystem check.");
  2660. EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
  2661. es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
  2662. ext4_commit_super(sb, es, 1);
  2663. jbd2_journal_clear_err(journal);
  2664. }
  2665. }
  2666. /*
  2667. * Force the running and committing transactions to commit,
  2668. * and wait on the commit.
  2669. */
  2670. int ext4_force_commit(struct super_block *sb)
  2671. {
  2672. journal_t *journal;
  2673. int ret = 0;
  2674. if (sb->s_flags & MS_RDONLY)
  2675. return 0;
  2676. journal = EXT4_SB(sb)->s_journal;
  2677. if (journal) {
  2678. sb->s_dirt = 0;
  2679. ret = ext4_journal_force_commit(journal);
  2680. }
  2681. return ret;
  2682. }
  2683. /*
  2684. * Ext4 always journals updates to the superblock itself, so we don't
  2685. * have to propagate any other updates to the superblock on disk at this
  2686. * point. (We can probably nuke this function altogether, and remove
  2687. * any mention to sb->s_dirt in all of fs/ext4; eventual cleanup...)
  2688. */
  2689. static void ext4_write_super(struct super_block *sb)
  2690. {
  2691. if (EXT4_SB(sb)->s_journal) {
  2692. if (mutex_trylock(&sb->s_lock) != 0)
  2693. BUG();
  2694. sb->s_dirt = 0;
  2695. } else {
  2696. ext4_commit_super(sb, EXT4_SB(sb)->s_es, 1);
  2697. }
  2698. }
  2699. static int ext4_sync_fs(struct super_block *sb, int wait)
  2700. {
  2701. int ret = 0;
  2702. trace_mark(ext4_sync_fs, "dev %s wait %d", sb->s_id, wait);
  2703. sb->s_dirt = 0;
  2704. if (EXT4_SB(sb)->s_journal) {
  2705. if (wait)
  2706. ret = ext4_force_commit(sb);
  2707. else
  2708. jbd2_journal_start_commit(EXT4_SB(sb)->s_journal, NULL);
  2709. } else {
  2710. ext4_commit_super(sb, EXT4_SB(sb)->s_es, wait);
  2711. }
  2712. return ret;
  2713. }
  2714. /*
  2715. * LVM calls this function before a (read-only) snapshot is created. This
  2716. * gives us a chance to flush the journal completely and mark the fs clean.
  2717. */
  2718. static void ext4_write_super_lockfs(struct super_block *sb)
  2719. {
  2720. sb->s_dirt = 0;
  2721. if (!(sb->s_flags & MS_RDONLY)) {
  2722. journal_t *journal = EXT4_SB(sb)->s_journal;
  2723. if (journal) {
  2724. /* Now we set up the journal barrier. */
  2725. jbd2_journal_lock_updates(journal);
  2726. /*
  2727. * We don't want to clear needs_recovery flag when we
  2728. * failed to flush the journal.
  2729. */
  2730. if (jbd2_journal_flush(journal) < 0)
  2731. return;
  2732. }
  2733. /* Journal blocked and flushed, clear needs_recovery flag. */
  2734. EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
  2735. ext4_commit_super(sb, EXT4_SB(sb)->s_es, 1);
  2736. }
  2737. }
  2738. /*
  2739. * Called by LVM after the snapshot is done. We need to reset the RECOVER
  2740. * flag here, even though the filesystem is not technically dirty yet.
  2741. */
  2742. static void ext4_unlockfs(struct super_block *sb)
  2743. {
  2744. if (EXT4_SB(sb)->s_journal && !(sb->s_flags & MS_RDONLY)) {
  2745. lock_super(sb);
  2746. /* Reser the needs_recovery flag before the fs is unlocked. */
  2747. EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
  2748. ext4_commit_super(sb, EXT4_SB(sb)->s_es, 1);
  2749. unlock_super(sb);
  2750. jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
  2751. }
  2752. }
  2753. static int ext4_remount(struct super_block *sb, int *flags, char *data)
  2754. {
  2755. struct ext4_super_block *es;
  2756. struct ext4_sb_info *sbi = EXT4_SB(sb);
  2757. ext4_fsblk_t n_blocks_count = 0;
  2758. unsigned long old_sb_flags;
  2759. struct ext4_mount_options old_opts;
  2760. ext4_group_t g;
  2761. int err;
  2762. #ifdef CONFIG_QUOTA
  2763. int i;
  2764. #endif
  2765. /* Store the original options */
  2766. old_sb_flags = sb->s_flags;
  2767. old_opts.s_mount_opt = sbi->s_mount_opt;
  2768. old_opts.s_resuid = sbi->s_resuid;
  2769. old_opts.s_resgid = sbi->s_resgid;
  2770. old_opts.s_commit_interval = sbi->s_commit_interval;
  2771. old_opts.s_min_batch_time = sbi->s_min_batch_time;
  2772. old_opts.s_max_batch_time = sbi->s_max_batch_time;
  2773. #ifdef CONFIG_QUOTA
  2774. old_opts.s_jquota_fmt = sbi->s_jquota_fmt;
  2775. for (i = 0; i < MAXQUOTAS; i++)
  2776. old_opts.s_qf_names[i] = sbi->s_qf_names[i];
  2777. #endif
  2778. /*
  2779. * Allow the "check" option to be passed as a remount option.
  2780. */
  2781. if (!parse_options(data, sb, NULL, NULL, &n_blocks_count, 1)) {
  2782. err = -EINVAL;
  2783. goto restore_opts;
  2784. }
  2785. if (sbi->s_mount_opt & EXT4_MOUNT_ABORT)
  2786. ext4_abort(sb, __func__, "Abort forced by user");
  2787. sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
  2788. ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
  2789. es = sbi->s_es;
  2790. if (sbi->s_journal)
  2791. ext4_init_journal_params(sb, sbi->s_journal);
  2792. if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY) ||
  2793. n_blocks_count > ext4_blocks_count(es)) {
  2794. if (sbi->s_mount_opt & EXT4_MOUNT_ABORT) {
  2795. err = -EROFS;
  2796. goto restore_opts;
  2797. }
  2798. if (*flags & MS_RDONLY) {
  2799. /*
  2800. * First of all, the unconditional stuff we have to do
  2801. * to disable replay of the journal when we next remount
  2802. */
  2803. sb->s_flags |= MS_RDONLY;
  2804. /*
  2805. * OK, test if we are remounting a valid rw partition
  2806. * readonly, and if so set the rdonly flag and then
  2807. * mark the partition as valid again.
  2808. */
  2809. if (!(es->s_state & cpu_to_le16(EXT4_VALID_FS)) &&
  2810. (sbi->s_mount_state & EXT4_VALID_FS))
  2811. es->s_state = cpu_to_le16(sbi->s_mount_state);
  2812. /*
  2813. * We have to unlock super so that we can wait for
  2814. * transactions.
  2815. */
  2816. if (sbi->s_journal) {
  2817. unlock_super(sb);
  2818. ext4_mark_recovery_complete(sb, es);
  2819. lock_super(sb);
  2820. }
  2821. } else {
  2822. int ret;
  2823. if ((ret = EXT4_HAS_RO_COMPAT_FEATURE(sb,
  2824. ~EXT4_FEATURE_RO_COMPAT_SUPP))) {
  2825. printk(KERN_WARNING "EXT4-fs: %s: couldn't "
  2826. "remount RDWR because of unsupported "
  2827. "optional features (%x).\n", sb->s_id,
  2828. (le32_to_cpu(sbi->s_es->s_feature_ro_compat) &
  2829. ~EXT4_FEATURE_RO_COMPAT_SUPP));
  2830. err = -EROFS;
  2831. goto restore_opts;
  2832. }
  2833. /*
  2834. * Make sure the group descriptor checksums
  2835. * are sane. If they aren't, refuse to
  2836. * remount r/w.
  2837. */
  2838. for (g = 0; g < sbi->s_groups_count; g++) {
  2839. struct ext4_group_desc *gdp =
  2840. ext4_get_group_desc(sb, g, NULL);
  2841. if (!ext4_group_desc_csum_verify(sbi, g, gdp)) {
  2842. printk(KERN_ERR
  2843. "EXT4-fs: ext4_remount: "
  2844. "Checksum for group %u failed (%u!=%u)\n",
  2845. g, le16_to_cpu(ext4_group_desc_csum(sbi, g, gdp)),
  2846. le16_to_cpu(gdp->bg_checksum));
  2847. err = -EINVAL;
  2848. goto restore_opts;
  2849. }
  2850. }
  2851. /*
  2852. * If we have an unprocessed orphan list hanging
  2853. * around from a previously readonly bdev mount,
  2854. * require a full umount/remount for now.
  2855. */
  2856. if (es->s_last_orphan) {
  2857. printk(KERN_WARNING "EXT4-fs: %s: couldn't "
  2858. "remount RDWR because of unprocessed "
  2859. "orphan inode list. Please "
  2860. "umount/remount instead.\n",
  2861. sb->s_id);
  2862. err = -EINVAL;
  2863. goto restore_opts;
  2864. }
  2865. /*
  2866. * Mounting a RDONLY partition read-write, so reread
  2867. * and store the current valid flag. (It may have
  2868. * been changed by e2fsck since we originally mounted
  2869. * the partition.)
  2870. */
  2871. if (sbi->s_journal)
  2872. ext4_clear_journal_err(sb, es);
  2873. sbi->s_mount_state = le16_to_cpu(es->s_state);
  2874. if ((err = ext4_group_extend(sb, es, n_blocks_count)))
  2875. goto restore_opts;
  2876. if (!ext4_setup_super(sb, es, 0))
  2877. sb->s_flags &= ~MS_RDONLY;
  2878. }
  2879. }
  2880. if (sbi->s_journal == NULL)
  2881. ext4_commit_super(sb, es, 1);
  2882. #ifdef CONFIG_QUOTA
  2883. /* Release old quota file names */
  2884. for (i = 0; i < MAXQUOTAS; i++)
  2885. if (old_opts.s_qf_names[i] &&
  2886. old_opts.s_qf_names[i] != sbi->s_qf_names[i])
  2887. kfree(old_opts.s_qf_names[i]);
  2888. #endif
  2889. return 0;
  2890. restore_opts:
  2891. sb->s_flags = old_sb_flags;
  2892. sbi->s_mount_opt = old_opts.s_mount_opt;
  2893. sbi->s_resuid = old_opts.s_resuid;
  2894. sbi->s_resgid = old_opts.s_resgid;
  2895. sbi->s_commit_interval = old_opts.s_commit_interval;
  2896. sbi->s_min_batch_time = old_opts.s_min_batch_time;
  2897. sbi->s_max_batch_time = old_opts.s_max_batch_time;
  2898. #ifdef CONFIG_QUOTA
  2899. sbi->s_jquota_fmt = old_opts.s_jquota_fmt;
  2900. for (i = 0; i < MAXQUOTAS; i++) {
  2901. if (sbi->s_qf_names[i] &&
  2902. old_opts.s_qf_names[i] != sbi->s_qf_names[i])
  2903. kfree(sbi->s_qf_names[i]);
  2904. sbi->s_qf_names[i] = old_opts.s_qf_names[i];
  2905. }
  2906. #endif
  2907. return err;
  2908. }
  2909. static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf)
  2910. {
  2911. struct super_block *sb = dentry->d_sb;
  2912. struct ext4_sb_info *sbi = EXT4_SB(sb);
  2913. struct ext4_super_block *es = sbi->s_es;
  2914. u64 fsid;
  2915. if (test_opt(sb, MINIX_DF)) {
  2916. sbi->s_overhead_last = 0;
  2917. } else if (sbi->s_blocks_last != ext4_blocks_count(es)) {
  2918. ext4_group_t ngroups = sbi->s_groups_count, i;
  2919. ext4_fsblk_t overhead = 0;
  2920. smp_rmb();
  2921. /*
  2922. * Compute the overhead (FS structures). This is constant
  2923. * for a given filesystem unless the number of block groups
  2924. * changes so we cache the previous value until it does.
  2925. */
  2926. /*
  2927. * All of the blocks before first_data_block are
  2928. * overhead
  2929. */
  2930. overhead = le32_to_cpu(es->s_first_data_block);
  2931. /*
  2932. * Add the overhead attributed to the superblock and
  2933. * block group descriptors. If the sparse superblocks
  2934. * feature is turned on, then not all groups have this.
  2935. */
  2936. for (i = 0; i < ngroups; i++) {
  2937. overhead += ext4_bg_has_super(sb, i) +
  2938. ext4_bg_num_gdb(sb, i);
  2939. cond_resched();
  2940. }
  2941. /*
  2942. * Every block group has an inode bitmap, a block
  2943. * bitmap, and an inode table.
  2944. */
  2945. overhead += ngroups * (2 + sbi->s_itb_per_group);
  2946. sbi->s_overhead_last = overhead;
  2947. smp_wmb();
  2948. sbi->s_blocks_last = ext4_blocks_count(es);
  2949. }
  2950. buf->f_type = EXT4_SUPER_MAGIC;
  2951. buf->f_bsize = sb->s_blocksize;
  2952. buf->f_blocks = ext4_blocks_count(es) - sbi->s_overhead_last;
  2953. buf->f_bfree = percpu_counter_sum_positive(&sbi->s_freeblocks_counter) -
  2954. percpu_counter_sum_positive(&sbi->s_dirtyblocks_counter);
  2955. ext4_free_blocks_count_set(es, buf->f_bfree);
  2956. buf->f_bavail = buf->f_bfree - ext4_r_blocks_count(es);
  2957. if (buf->f_bfree < ext4_r_blocks_count(es))
  2958. buf->f_bavail = 0;
  2959. buf->f_files = le32_to_cpu(es->s_inodes_count);
  2960. buf->f_ffree = percpu_counter_sum_positive(&sbi->s_freeinodes_counter);
  2961. es->s_free_inodes_count = cpu_to_le32(buf->f_ffree);
  2962. buf->f_namelen = EXT4_NAME_LEN;
  2963. fsid = le64_to_cpup((void *)es->s_uuid) ^
  2964. le64_to_cpup((void *)es->s_uuid + sizeof(u64));
  2965. buf->f_fsid.val[0] = fsid & 0xFFFFFFFFUL;
  2966. buf->f_fsid.val[1] = (fsid >> 32) & 0xFFFFFFFFUL;
  2967. return 0;
  2968. }
  2969. /* Helper function for writing quotas on sync - we need to start transaction before quota file
  2970. * is locked for write. Otherwise the are possible deadlocks:
  2971. * Process 1 Process 2
  2972. * ext4_create() quota_sync()
  2973. * jbd2_journal_start() write_dquot()
  2974. * DQUOT_INIT() down(dqio_mutex)
  2975. * down(dqio_mutex) jbd2_journal_start()
  2976. *
  2977. */
  2978. #ifdef CONFIG_QUOTA
  2979. static inline struct inode *dquot_to_inode(struct dquot *dquot)
  2980. {
  2981. return sb_dqopt(dquot->dq_sb)->files[dquot->dq_type];
  2982. }
  2983. static int ext4_dquot_initialize(struct inode *inode, int type)
  2984. {
  2985. handle_t *handle;
  2986. int ret, err;
  2987. /* We may create quota structure so we need to reserve enough blocks */
  2988. handle = ext4_journal_start(inode, 2*EXT4_QUOTA_INIT_BLOCKS(inode->i_sb));
  2989. if (IS_ERR(handle))
  2990. return PTR_ERR(handle);
  2991. ret = dquot_initialize(inode, type);
  2992. err = ext4_journal_stop(handle);
  2993. if (!ret)
  2994. ret = err;
  2995. return ret;
  2996. }
  2997. static int ext4_dquot_drop(struct inode *inode)
  2998. {
  2999. handle_t *handle;
  3000. int ret, err;
  3001. /* We may delete quota structure so we need to reserve enough blocks */
  3002. handle = ext4_journal_start(inode, 2*EXT4_QUOTA_DEL_BLOCKS(inode->i_sb));
  3003. if (IS_ERR(handle)) {
  3004. /*
  3005. * We call dquot_drop() anyway to at least release references
  3006. * to quota structures so that umount does not hang.
  3007. */
  3008. dquot_drop(inode);
  3009. return PTR_ERR(handle);
  3010. }
  3011. ret = dquot_drop(inode);
  3012. err = ext4_journal_stop(handle);
  3013. if (!ret)
  3014. ret = err;
  3015. return ret;
  3016. }
  3017. static int ext4_write_dquot(struct dquot *dquot)
  3018. {
  3019. int ret, err;
  3020. handle_t *handle;
  3021. struct inode *inode;
  3022. inode = dquot_to_inode(dquot);
  3023. handle = ext4_journal_start(inode,
  3024. EXT4_QUOTA_TRANS_BLOCKS(dquot->dq_sb));
  3025. if (IS_ERR(handle))
  3026. return PTR_ERR(handle);
  3027. ret = dquot_commit(dquot);
  3028. err = ext4_journal_stop(handle);
  3029. if (!ret)
  3030. ret = err;
  3031. return ret;
  3032. }
  3033. static int ext4_acquire_dquot(struct dquot *dquot)
  3034. {
  3035. int ret, err;
  3036. handle_t *handle;
  3037. handle = ext4_journal_start(dquot_to_inode(dquot),
  3038. EXT4_QUOTA_INIT_BLOCKS(dquot->dq_sb));
  3039. if (IS_ERR(handle))
  3040. return PTR_ERR(handle);
  3041. ret = dquot_acquire(dquot);
  3042. err = ext4_journal_stop(handle);
  3043. if (!ret)
  3044. ret = err;
  3045. return ret;
  3046. }
  3047. static int ext4_release_dquot(struct dquot *dquot)
  3048. {
  3049. int ret, err;
  3050. handle_t *handle;
  3051. handle = ext4_journal_start(dquot_to_inode(dquot),
  3052. EXT4_QUOTA_DEL_BLOCKS(dquot->dq_sb));
  3053. if (IS_ERR(handle)) {
  3054. /* Release dquot anyway to avoid endless cycle in dqput() */
  3055. dquot_release(dquot);
  3056. return PTR_ERR(handle);
  3057. }
  3058. ret = dquot_release(dquot);
  3059. err = ext4_journal_stop(handle);
  3060. if (!ret)
  3061. ret = err;
  3062. return ret;
  3063. }
  3064. static int ext4_mark_dquot_dirty(struct dquot *dquot)
  3065. {
  3066. /* Are we journaling quotas? */
  3067. if (EXT4_SB(dquot->dq_sb)->s_qf_names[USRQUOTA] ||
  3068. EXT4_SB(dquot->dq_sb)->s_qf_names[GRPQUOTA]) {
  3069. dquot_mark_dquot_dirty(dquot);
  3070. return ext4_write_dquot(dquot);
  3071. } else {
  3072. return dquot_mark_dquot_dirty(dquot);
  3073. }
  3074. }
  3075. static int ext4_write_info(struct super_block *sb, int type)
  3076. {
  3077. int ret, err;
  3078. handle_t *handle;
  3079. /* Data block + inode block */
  3080. handle = ext4_journal_start(sb->s_root->d_inode, 2);
  3081. if (IS_ERR(handle))
  3082. return PTR_ERR(handle);
  3083. ret = dquot_commit_info(sb, type);
  3084. err = ext4_journal_stop(handle);
  3085. if (!ret)
  3086. ret = err;
  3087. return ret;
  3088. }
  3089. /*
  3090. * Turn on quotas during mount time - we need to find
  3091. * the quota file and such...
  3092. */
  3093. static int ext4_quota_on_mount(struct super_block *sb, int type)
  3094. {
  3095. return vfs_quota_on_mount(sb, EXT4_SB(sb)->s_qf_names[type],
  3096. EXT4_SB(sb)->s_jquota_fmt, type);
  3097. }
  3098. /*
  3099. * Standard function to be called on quota_on
  3100. */
  3101. static int ext4_quota_on(struct super_block *sb, int type, int format_id,
  3102. char *name, int remount)
  3103. {
  3104. int err;
  3105. struct path path;
  3106. if (!test_opt(sb, QUOTA))
  3107. return -EINVAL;
  3108. /* When remounting, no checks are needed and in fact, name is NULL */
  3109. if (remount)
  3110. return vfs_quota_on(sb, type, format_id, name, remount);
  3111. err = kern_path(name, LOOKUP_FOLLOW, &path);
  3112. if (err)
  3113. return err;
  3114. /* Quotafile not on the same filesystem? */
  3115. if (path.mnt->mnt_sb != sb) {
  3116. path_put(&path);
  3117. return -EXDEV;
  3118. }
  3119. /* Journaling quota? */
  3120. if (EXT4_SB(sb)->s_qf_names[type]) {
  3121. /* Quotafile not in fs root? */
  3122. if (path.dentry->d_parent != sb->s_root)
  3123. printk(KERN_WARNING
  3124. "EXT4-fs: Quota file not on filesystem root. "
  3125. "Journaled quota will not work.\n");
  3126. }
  3127. /*
  3128. * When we journal data on quota file, we have to flush journal to see
  3129. * all updates to the file when we bypass pagecache...
  3130. */
  3131. if (EXT4_SB(sb)->s_journal &&
  3132. ext4_should_journal_data(path.dentry->d_inode)) {
  3133. /*
  3134. * We don't need to lock updates but journal_flush() could
  3135. * otherwise be livelocked...
  3136. */
  3137. jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal);
  3138. err = jbd2_journal_flush(EXT4_SB(sb)->s_journal);
  3139. jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
  3140. if (err) {
  3141. path_put(&path);
  3142. return err;
  3143. }
  3144. }
  3145. err = vfs_quota_on_path(sb, type, format_id, &path);
  3146. path_put(&path);
  3147. return err;
  3148. }
  3149. /* Read data from quotafile - avoid pagecache and such because we cannot afford
  3150. * acquiring the locks... As quota files are never truncated and quota code
  3151. * itself serializes the operations (and noone else should touch the files)
  3152. * we don't have to be afraid of races */
  3153. static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data,
  3154. size_t len, loff_t off)
  3155. {
  3156. struct inode *inode = sb_dqopt(sb)->files[type];
  3157. ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb);
  3158. int err = 0;
  3159. int offset = off & (sb->s_blocksize - 1);
  3160. int tocopy;
  3161. size_t toread;
  3162. struct buffer_head *bh;
  3163. loff_t i_size = i_size_read(inode);
  3164. if (off > i_size)
  3165. return 0;
  3166. if (off+len > i_size)
  3167. len = i_size-off;
  3168. toread = len;
  3169. while (toread > 0) {
  3170. tocopy = sb->s_blocksize - offset < toread ?
  3171. sb->s_blocksize - offset : toread;
  3172. bh = ext4_bread(NULL, inode, blk, 0, &err);
  3173. if (err)
  3174. return err;
  3175. if (!bh) /* A hole? */
  3176. memset(data, 0, tocopy);
  3177. else
  3178. memcpy(data, bh->b_data+offset, tocopy);
  3179. brelse(bh);
  3180. offset = 0;
  3181. toread -= tocopy;
  3182. data += tocopy;
  3183. blk++;
  3184. }
  3185. return len;
  3186. }
  3187. /* Write to quotafile (we know the transaction is already started and has
  3188. * enough credits) */
  3189. static ssize_t ext4_quota_write(struct super_block *sb, int type,
  3190. const char *data, size_t len, loff_t off)
  3191. {
  3192. struct inode *inode = sb_dqopt(sb)->files[type];
  3193. ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb);
  3194. int err = 0;
  3195. int offset = off & (sb->s_blocksize - 1);
  3196. int tocopy;
  3197. int journal_quota = EXT4_SB(sb)->s_qf_names[type] != NULL;
  3198. size_t towrite = len;
  3199. struct buffer_head *bh;
  3200. handle_t *handle = journal_current_handle();
  3201. if (EXT4_SB(sb)->s_journal && !handle) {
  3202. printk(KERN_WARNING "EXT4-fs: Quota write (off=%llu, len=%llu)"
  3203. " cancelled because transaction is not started.\n",
  3204. (unsigned long long)off, (unsigned long long)len);
  3205. return -EIO;
  3206. }
  3207. mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA);
  3208. while (towrite > 0) {
  3209. tocopy = sb->s_blocksize - offset < towrite ?
  3210. sb->s_blocksize - offset : towrite;
  3211. bh = ext4_bread(handle, inode, blk, 1, &err);
  3212. if (!bh)
  3213. goto out;
  3214. if (journal_quota) {
  3215. err = ext4_journal_get_write_access(handle, bh);
  3216. if (err) {
  3217. brelse(bh);
  3218. goto out;
  3219. }
  3220. }
  3221. lock_buffer(bh);
  3222. memcpy(bh->b_data+offset, data, tocopy);
  3223. flush_dcache_page(bh->b_page);
  3224. unlock_buffer(bh);
  3225. if (journal_quota)
  3226. err = ext4_handle_dirty_metadata(handle, NULL, bh);
  3227. else {
  3228. /* Always do at least ordered writes for quotas */
  3229. err = ext4_jbd2_file_inode(handle, inode);
  3230. mark_buffer_dirty(bh);
  3231. }
  3232. brelse(bh);
  3233. if (err)
  3234. goto out;
  3235. offset = 0;
  3236. towrite -= tocopy;
  3237. data += tocopy;
  3238. blk++;
  3239. }
  3240. out:
  3241. if (len == towrite) {
  3242. mutex_unlock(&inode->i_mutex);
  3243. return err;
  3244. }
  3245. if (inode->i_size < off+len-towrite) {
  3246. i_size_write(inode, off+len-towrite);
  3247. EXT4_I(inode)->i_disksize = inode->i_size;
  3248. }
  3249. inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  3250. ext4_mark_inode_dirty(handle, inode);
  3251. mutex_unlock(&inode->i_mutex);
  3252. return len - towrite;
  3253. }
  3254. #endif
  3255. static int ext4_get_sb(struct file_system_type *fs_type,
  3256. int flags, const char *dev_name, void *data, struct vfsmount *mnt)
  3257. {
  3258. return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super, mnt);
  3259. }
  3260. #ifdef CONFIG_PROC_FS
  3261. static int ext4_ui_proc_show(struct seq_file *m, void *v)
  3262. {
  3263. unsigned int *p = m->private;
  3264. seq_printf(m, "%u\n", *p);
  3265. return 0;
  3266. }
  3267. static int ext4_ui_proc_open(struct inode *inode, struct file *file)
  3268. {
  3269. return single_open(file, ext4_ui_proc_show, PDE(inode)->data);
  3270. }
  3271. static ssize_t ext4_ui_proc_write(struct file *file, const char __user *buf,
  3272. size_t cnt, loff_t *ppos)
  3273. {
  3274. unsigned long *p = PDE(file->f_path.dentry->d_inode)->data;
  3275. char str[32];
  3276. if (cnt >= sizeof(str))
  3277. return -EINVAL;
  3278. if (copy_from_user(str, buf, cnt))
  3279. return -EFAULT;
  3280. *p = simple_strtoul(str, NULL, 0);
  3281. return cnt;
  3282. }
  3283. const struct file_operations ext4_ui_proc_fops = {
  3284. .owner = THIS_MODULE,
  3285. .open = ext4_ui_proc_open,
  3286. .read = seq_read,
  3287. .llseek = seq_lseek,
  3288. .release = single_release,
  3289. .write = ext4_ui_proc_write,
  3290. };
  3291. #endif
  3292. static struct file_system_type ext4_fs_type = {
  3293. .owner = THIS_MODULE,
  3294. .name = "ext4",
  3295. .get_sb = ext4_get_sb,
  3296. .kill_sb = kill_block_super,
  3297. .fs_flags = FS_REQUIRES_DEV,
  3298. };
  3299. #ifdef CONFIG_EXT4DEV_COMPAT
  3300. static int ext4dev_get_sb(struct file_system_type *fs_type,
  3301. int flags, const char *dev_name, void *data, struct vfsmount *mnt)
  3302. {
  3303. printk(KERN_WARNING "EXT4-fs: Update your userspace programs "
  3304. "to mount using ext4\n");
  3305. printk(KERN_WARNING "EXT4-fs: ext4dev backwards compatibility "
  3306. "will go away by 2.6.31\n");
  3307. return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super, mnt);
  3308. }
  3309. static struct file_system_type ext4dev_fs_type = {
  3310. .owner = THIS_MODULE,
  3311. .name = "ext4dev",
  3312. .get_sb = ext4dev_get_sb,
  3313. .kill_sb = kill_block_super,
  3314. .fs_flags = FS_REQUIRES_DEV,
  3315. };
  3316. MODULE_ALIAS("ext4dev");
  3317. #endif
  3318. static int __init init_ext4_fs(void)
  3319. {
  3320. int err;
  3321. ext4_proc_root = proc_mkdir("fs/ext4", NULL);
  3322. err = init_ext4_mballoc();
  3323. if (err)
  3324. return err;
  3325. err = init_ext4_xattr();
  3326. if (err)
  3327. goto out2;
  3328. err = init_inodecache();
  3329. if (err)
  3330. goto out1;
  3331. err = register_filesystem(&ext4_fs_type);
  3332. if (err)
  3333. goto out;
  3334. #ifdef CONFIG_EXT4DEV_COMPAT
  3335. err = register_filesystem(&ext4dev_fs_type);
  3336. if (err) {
  3337. unregister_filesystem(&ext4_fs_type);
  3338. goto out;
  3339. }
  3340. #endif
  3341. return 0;
  3342. out:
  3343. destroy_inodecache();
  3344. out1:
  3345. exit_ext4_xattr();
  3346. out2:
  3347. exit_ext4_mballoc();
  3348. return err;
  3349. }
  3350. static void __exit exit_ext4_fs(void)
  3351. {
  3352. unregister_filesystem(&ext4_fs_type);
  3353. #ifdef CONFIG_EXT4DEV_COMPAT
  3354. unregister_filesystem(&ext4dev_fs_type);
  3355. #endif
  3356. destroy_inodecache();
  3357. exit_ext4_xattr();
  3358. exit_ext4_mballoc();
  3359. remove_proc_entry("fs/ext4", NULL);
  3360. }
  3361. MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others");
  3362. MODULE_DESCRIPTION("Fourth Extended Filesystem with extents");
  3363. MODULE_LICENSE("GPL");
  3364. module_init(init_ext4_fs)
  3365. module_exit(exit_ext4_fs)