super.c 89 KB

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