19 #include <linux/module.h>
20 #include <linux/string.h>
22 #include <linux/time.h>
25 #include <linux/slab.h>
32 #include <linux/random.h>
38 #include <linux/ctype.h>
42 #include <asm/uaccess.h>
54 #define CREATE_TRACE_POINTS
58 static struct kset *ext4_kset;
59 static struct ext4_lazy_init *ext4_li_info;
60 static struct mutex ext4_li_mtx;
61 static struct ext4_features *ext4_feat;
64 unsigned long journal_devnum);
65 static int ext4_show_options(
struct seq_file *seq,
struct dentry *root);
67 static void ext4_mark_recovery_complete(
struct super_block *
sb,
72 static const char *ext4_decode_error(
struct super_block *
sb,
int errno,
79 const char *dev_name,
void *
data);
80 static inline int ext2_feature_set_ok(
struct super_block *
sb);
81 static inline int ext3_feature_set_ok(
struct super_block *
sb);
83 static void ext4_destroy_lazyinit_thread(
void);
84 static void ext4_unregister_li_request(
struct super_block *
sb);
85 static void ext4_clear_request_list(
void);
87 #if !defined(CONFIG_EXT2_FS) && !defined(CONFIG_EXT2_FS_MODULE) && defined(CONFIG_EXT4_USE_FOR_EXT23)
95 #define IS_EXT2_SB(sb) ((sb)->s_bdev->bd_holder == &ext2_fs_type)
97 #define IS_EXT2_SB(sb) (0)
101 #if !defined(CONFIG_EXT3_FS) && !defined(CONFIG_EXT3_FS_MODULE) && defined(CONFIG_EXT4_USE_FOR_EXT23)
109 #define IS_EXT3_SB(sb) ((sb)->s_bdev->bd_holder == &ext3_fs_type)
111 #define IS_EXT3_SB(sb) (0)
127 struct ext4_sb_info *sbi =
EXT4_SB(sb);
131 csum = ext4_chksum(sbi, ~0, (
char *)es, offset);
143 return es->
s_checksum == ext4_superblock_csum(sb, es);
154 es->
s_checksum = ext4_superblock_csum(sb, es);
171 ret = kzalloc(size, flags);
179 if (is_vmalloc_addr(ptr))
300 static handle_t *ext4_get_nojournal(
void)
308 handle = (handle_t *)ref_cnt;
316 static void ext4_put_nojournal(handle_t *
handle)
323 handle = (handle_t *)ref_cnt;
335 trace_ext4_journal_start(sb, nblocks,
_RET_IP_);
337 return ERR_PTR(-
EROFS);
340 journal =
EXT4_SB(sb)->s_journal;
342 return ext4_get_nojournal();
348 if (is_journal_aborted(journal)) {
349 ext4_abort(sb,
"Detected aborted journal");
350 return ERR_PTR(-
EROFS);
361 if (!ext4_handle_valid(handle)) {
362 ext4_put_nojournal(handle);
365 sb = handle->h_transaction->t_journal->j_private;
377 const char *err_fn,
struct buffer_head *bh,
381 const char *
errstr = ext4_decode_error(
NULL, err, nbuf);
383 BUG_ON(!ext4_handle_valid(handle));
386 BUFFER_TRACE(bh,
"abort");
391 if (is_handle_aborted(handle))
394 printk(
KERN_ERR "EXT4-fs: %s:%d: aborting transaction: %s in %s\n",
395 caller, line, errstr, err_fn);
397 jbd2_journal_abort_handle(handle);
400 static void __save_error_info(
struct super_block *sb,
const char *
func,
427 static void save_error_info(
struct super_block *sb,
const char *func,
430 __save_error_info(sb, func, line);
431 ext4_commit_super(sb, 1);
442 static int block_device_ejected(
struct super_block *sb)
450 static void ext4_journal_commit_callback(journal_t *journal,
transaction_t *txn)
453 struct ext4_sb_info *sbi =
EXT4_SB(sb);
454 int error = is_journal_aborted(journal);
457 spin_lock(&sbi->s_md_lock);
460 spin_unlock(&sbi->s_md_lock);
462 spin_lock(&sbi->s_md_lock);
464 spin_unlock(&sbi->s_md_lock);
482 static void ext4_handle_error(
struct super_block *sb)
488 journal_t *journal =
EXT4_SB(sb)->s_journal;
490 EXT4_SB(sb)->s_mount_flags |= EXT4_MF_FS_ABORTED;
499 panic(
"EXT4-fs (device %s): panic forced after error\n",
504 unsigned int line,
const char *
fmt, ...)
515 save_error_info(sb,
function, line);
517 ext4_handle_error(sb);
522 const char *
fmt, ...)
530 save_error_info(inode->
i_sb,
function, line);
536 "inode #%lu: block %llu: comm %s: %pV\n",
537 inode->
i_sb->s_id,
function, line, inode->
i_ino,
541 "inode #%lu: comm %s: %pV\n",
542 inode->
i_sb->s_id,
function, line, inode->
i_ino,
546 ext4_handle_error(inode->
i_sb);
551 const char *
fmt, ...)
556 struct inode *
inode = file->f_dentry->d_inode;
561 save_error_info(inode->
i_sb,
function, line);
562 path =
d_path(&(file->
f_path), pathname,
sizeof(pathname));
570 "EXT4-fs error (device %s): %s:%d: inode #%lu: "
571 "block %llu: comm %s: path %s: %pV\n",
572 inode->
i_sb->s_id,
function, line, inode->
i_ino,
573 block,
current->comm, path, &vaf);
576 "EXT4-fs error (device %s): %s:%d: inode #%lu: "
577 "comm %s: path %s: %pV\n",
578 inode->
i_sb->s_id,
function, line, inode->
i_ino,
582 ext4_handle_error(inode->
i_sb);
585 static const char *ext4_decode_error(
struct super_block *sb,
int errno,
592 errstr =
"IO failure";
595 errstr =
"Out of memory";
600 errstr =
"Journal has aborted";
602 errstr =
"Readonly filesystem";
610 if (
snprintf(nbuf, 16,
"error %d", -errno) >= 0)
623 unsigned int line,
int errno)
631 if (errno == -
EROFS && journal_current_handle() ==
NULL &&
635 errstr = ext4_decode_error(sb, errno, nbuf);
637 sb->
s_id,
function, line, errstr);
638 save_error_info(sb,
function, line);
640 ext4_handle_error(sb);
654 unsigned int line,
const char *
fmt, ...)
658 save_error_info(sb,
function, line);
669 EXT4_SB(sb)->s_mount_flags |= EXT4_MF_FS_ABORTED;
672 save_error_info(sb,
function, line);
675 panic(
"EXT4-fs panic from previous error\n");
686 printk(
"%sEXT4-fs (%s): %pV\n", prefix, sb->
s_id, &vaf);
691 unsigned int line,
const char *
fmt, ...)
700 sb->
s_id,
function, line, &vaf);
707 const char *
fmt, ...)
717 __save_error_info(sb,
function, line);
724 sb->
s_id,
function, line, grp);
733 ext4_commit_super(sb, 0);
737 ext4_unlock_group(sb, grp);
738 ext4_handle_error(sb);
750 ext4_lock_group(sb, grp);
762 "updating to rev %d because of new feature flag, "
763 "running e2fsck is recommended",
806 static int ext4_blkdev_remove(
struct ext4_sb_info *sbi)
811 bdev = sbi->journal_bdev;
813 ret = ext4_blkdev_put(bdev);
814 sbi->journal_bdev =
NULL;
824 static void dump_orphan_list(
struct super_block *sb,
struct ext4_sb_info *sbi)
835 "inode %s:%lu at %p: mode %o, nlink %d, next %d\n",
844 struct ext4_sb_info *sbi =
EXT4_SB(sb);
848 ext4_unregister_li_request(sb);
854 if (sbi->s_journal) {
856 sbi->s_journal =
NULL;
858 ext4_abort(sb,
"Couldn't clean up the journal");
872 ext4_commit_super(sb, 1);
880 for (i = 0; i < sbi->s_gdb_count; i++)
881 brelse(sbi->s_group_desc[i]);
891 kfree(sbi->s_qf_names[i]);
898 if (!list_empty(&sbi->s_orphan))
899 dump_orphan_list(sb, sbi);
900 J_ASSERT(list_empty(&sbi->s_orphan));
903 if (sbi->journal_bdev && sbi->journal_bdev != sb->
s_bdev) {
911 ext4_blkdev_remove(sbi);
922 if (sbi->s_chksum_driver)
923 crypto_free_shash(sbi->s_chksum_driver);
924 kfree(sbi->s_blockgroup_lock);
942 ei->
vfs_inode.i_data.writeback_index = 0;
953 ei->i_reserved_quota = 0;
966 static int ext4_drop_inode(
struct inode *
inode)
968 int drop = generic_drop_inode(inode);
970 trace_ext4_drop_inode(inode, drop);
980 static void ext4_destroy_inode(
struct inode *inode)
982 if (!list_empty(&(
EXT4_I(inode)->i_orphan))) {
984 "Inode %lu (%p): orphan list check failed!",
994 static void init_once(
void *
foo)
999 #ifdef CONFIG_EXT4_FS_XATTR
1006 static int init_inodecache(
void)
1013 if (ext4_inode_cachep ==
NULL)
1018 static void destroy_inodecache(
void)
1042 static struct inode *ext4_nfs_get_inode(
struct super_block *sb,
1045 struct inode *
inode;
1062 return ERR_CAST(inode);
1072 int fh_len,
int fh_type)
1075 ext4_nfs_get_inode);
1079 int fh_len,
int fh_type)
1082 ext4_nfs_get_inode);
1094 journal_t *journal =
EXT4_SB(sb)->s_journal;
1097 if (!page_has_buffers(page))
1106 #define QTYPE2NAME(t) ((t) == USRQUOTA ? "user" : "group")
1107 #define QTYPE2MOPT(on, t) ((t) == USRQUOTA?((on)##USRJQUOTA):((on)##GRPJQUOTA))
1109 static int ext4_write_dquot(
struct dquot *
dquot);
1110 static int ext4_acquire_dquot(
struct dquot *
dquot);
1111 static int ext4_release_dquot(
struct dquot *
dquot);
1112 static int ext4_mark_dquot_dirty(
struct dquot *
dquot);
1122 size_t len, loff_t off);
1124 const char *
data,
size_t len, loff_t off);
1126 unsigned int flags);
1127 static int ext4_enable_quotas(
struct super_block *sb);
1131 .write_dquot = ext4_write_dquot,
1132 .acquire_dquot = ext4_acquire_dquot,
1133 .release_dquot = ext4_release_dquot,
1134 .mark_dirty = ext4_mark_dquot_dirty,
1135 .write_info = ext4_write_info,
1140 static const struct quotactl_ops ext4_qctl_operations = {
1142 .quota_off = ext4_quota_off,
1150 static const struct quotactl_ops ext4_qctl_sysfile_operations = {
1152 .quota_off = ext4_quota_off_sysfile,
1162 .alloc_inode = ext4_alloc_inode,
1163 .destroy_inode = ext4_destroy_inode,
1166 .drop_inode = ext4_drop_inode,
1168 .put_super = ext4_put_super,
1169 .sync_fs = ext4_sync_fs,
1170 .freeze_fs = ext4_freeze,
1171 .unfreeze_fs = ext4_unfreeze,
1172 .statfs = ext4_statfs,
1173 .remount_fs = ext4_remount,
1174 .show_options = ext4_show_options,
1176 .quota_read = ext4_quota_read,
1177 .quota_write = ext4_quota_write,
1183 .alloc_inode = ext4_alloc_inode,
1184 .destroy_inode = ext4_destroy_inode,
1187 .drop_inode = ext4_drop_inode,
1189 .put_super = ext4_put_super,
1190 .statfs = ext4_statfs,
1191 .remount_fs = ext4_remount,
1192 .show_options = ext4_show_options,
1194 .quota_read = ext4_quota_read,
1195 .quota_write = ext4_quota_write,
1201 .fh_to_dentry = ext4_fh_to_dentry,
1202 .fh_to_parent = ext4_fh_to_parent,
1311 char *
options = (
char *) *data;
1313 if (!options ||
strncmp(options,
"sb=", 3) != 0)
1319 if (*options && *options !=
',') {
1324 if (*options ==
',')
1326 *data = (
void *) options;
1331 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
1332 static char deprecated_msg[] =
"Mount option \"%s\" will be removed by %s\n"
1338 struct ext4_sb_info *sbi =
EXT4_SB(sb);
1341 if (sb_any_quota_loaded(sb) &&
1342 !sbi->s_qf_names[qtype]) {
1344 "Cannot change journaled "
1345 "quota options when quota turned on");
1351 "Not enough memory for storing quotafile name");
1354 if (sbi->s_qf_names[qtype] &&
1355 strcmp(sbi->s_qf_names[qtype], qname)) {
1357 "%s quota file already specified", QTYPE2NAME(qtype));
1361 sbi->s_qf_names[qtype] = qname;
1362 if (
strchr(sbi->s_qf_names[qtype],
'/')) {
1364 "quotafile must be on filesystem root");
1365 kfree(sbi->s_qf_names[qtype]);
1366 sbi->s_qf_names[qtype] =
NULL;
1373 static int clear_qf_name(
struct super_block *sb,
int qtype)
1376 struct ext4_sb_info *sbi =
EXT4_SB(sb);
1378 if (sb_any_quota_loaded(sb) &&
1379 sbi->s_qf_names[qtype]) {
1381 " when quota turned on");
1388 sbi->s_qf_names[qtype] =
NULL;
1393 #define MOPT_SET 0x0001
1394 #define MOPT_CLEAR 0x0002
1395 #define MOPT_NOSUPPORT 0x0004
1396 #define MOPT_EXPLICIT 0x0008
1397 #define MOPT_CLEAR_ERR 0x0010
1398 #define MOPT_GTE0 0x0020
1401 #define MOPT_QFMT 0x0040
1403 #define MOPT_Q MOPT_NOSUPPORT
1404 #define MOPT_QFMT MOPT_NOSUPPORT
1406 #define MOPT_DATAJ 0x0080
1408 static const struct mount_opts {
1412 } ext4_mount_opts[] = {
1450 #ifdef CONFIG_EXT4_FS_XATTR
1457 #ifdef CONFIG_EXT4_FS_POSIX_ACL
1486 unsigned int *journal_ioprio,
int is_remount)
1488 struct ext4_sb_info *sbi =
EXT4_SB(sb);
1489 const struct mount_opts *
m;
1496 return set_qf_name(sb,
USRQUOTA, &args[0]);
1498 return set_qf_name(sb,
GRPQUOTA, &args[0]);
1500 return clear_qf_name(sb,
USRQUOTA);
1502 return clear_qf_name(sb,
GRPQUOTA);
1515 "Ignoring removed %s option", opt);
1519 if (!uid_valid(uid)) {
1523 sbi->s_resuid =
uid;
1527 if (!gid_valid(gid)) {
1531 sbi->s_resgid =
gid;
1534 sbi->s_mount_flags |= EXT4_MF_FS_ABORTED;
1542 "Cannot specify journal on remount");
1545 *journal_devnum =
arg;
1548 if (arg < 0 || arg > 7)
1554 for (m = ext4_mount_opts; m->token !=
Opt_err; m++) {
1555 if (token != m->token)
1563 if (token ==
Opt_noquota && sb_any_quota_loaded(sb)) {
1565 "options when quota turned on");
1574 sbi->s_commit_interval =
HZ *
arg;
1578 sbi->s_max_batch_time =
arg;
1580 sbi->s_min_batch_time =
arg;
1582 if (arg > (1 << 30))
1586 "EXT4-fs: inode_readahead_blks"
1587 " must be a power of 2");
1590 sbi->s_inode_readahead_blks =
arg;
1592 set_opt(sb, INIT_INODE_TABLE);
1594 arg = EXT4_DEF_LI_WAIT_MULT;
1595 sbi->s_li_wait_mult =
arg;
1597 sbi->s_max_dir_size_kb =
arg;
1599 sbi->s_stripe =
arg;
1602 if (!sbi->s_journal)
1603 ext4_msg(sb,
KERN_WARNING,
"Remounting file system with no journal so ignoring journalled data option");
1604 else if (
test_opt(sb, DATA_FLAGS) !=
1607 "Cannot change data mode on remount");
1612 sbi->s_mount_opt |= m->mount_opt;
1616 if (sb_any_quota_loaded(sb) &&
1617 sbi->s_jquota_fmt != m->mount_opt) {
1619 "change journaled quota options "
1620 "when quota turned on");
1623 sbi->s_jquota_fmt = m->mount_opt;
1632 "buggy handling of option %s", opt);
1637 sbi->s_mount_opt |= m->mount_opt;
1639 sbi->s_mount_opt &= ~m->mount_opt;
1644 "or missing value", opt);
1648 static int parse_options(
char *options,
struct super_block *sb,
1649 unsigned long *journal_devnum,
1650 unsigned int *journal_ioprio,
1654 struct ext4_sb_info *sbi =
EXT4_SB(sb);
1663 while ((p =
strsep(&options,
",")) !=
NULL) {
1672 if (handle_mount_opt(sb, p, token, args, journal_devnum,
1673 journal_ioprio, is_remount) < 0)
1690 if (!sbi->s_jquota_fmt) {
1696 if (sbi->s_jquota_fmt) {
1698 "specified with no journaling "
1707 static inline void ext4_show_quota_options(
struct seq_file *seq,
1710 #if defined(CONFIG_QUOTA)
1711 struct ext4_sb_info *sbi =
EXT4_SB(sb);
1713 if (sbi->s_jquota_fmt) {
1716 switch (sbi->s_jquota_fmt) {
1744 static const char *token2str(
int token)
1762 struct ext4_sb_info *sbi =
EXT4_SB(sb);
1764 int def_errors, def_mount_opt = nodefs ? 0 : sbi->s_def_mount_opt;
1765 const struct mount_opts *
m;
1766 char sep = nodefs ?
'\n' :
',';
1768 #define SEQ_OPTS_PUTS(str) seq_printf(seq, "%c" str, sep)
1769 #define SEQ_OPTS_PRINT(str, arg) seq_printf(seq, "%c" str, sep, arg)
1771 if (sbi->s_sb_block != 1)
1774 for (m = ext4_mount_opts; m->token !=
Opt_err; m++) {
1775 int want_set = m->flags &
MOPT_SET;
1779 if (!(m->mount_opt & (sbi->s_mount_opt ^ def_mount_opt)))
1782 (sbi->s_mount_opt & m->mount_opt) != m->mount_opt) ||
1783 (!want_set && (sbi->s_mount_opt & m->mount_opt)))
1811 if (nodefs || sbi->s_stripe)
1824 sbi->s_inode_readahead_blks);
1826 if (nodefs || (
test_opt(sb, INIT_INODE_TABLE) &&
1827 (sbi->s_li_wait_mult != EXT4_DEF_LI_WAIT_MULT)))
1829 if (nodefs || sbi->s_max_dir_size_kb)
1832 ext4_show_quota_options(seq, sb);
1836 static int ext4_show_options(
struct seq_file *seq,
struct dentry *root)
1838 return _ext4_show_options(seq, root->
d_sb, 0);
1841 static int options_seq_show(
struct seq_file *seq,
void *offset)
1847 rc = _ext4_show_options(seq, sb, 1);
1852 static int options_open_fs(
struct inode *inode,
struct file *
file)
1854 return single_open(file, options_seq_show, PDE(inode)->data);
1859 .open = options_open_fs,
1868 struct ext4_sb_info *sbi =
EXT4_SB(sb);
1873 "forcing read-only mode");
1880 "running e2fsck is recommended");
1883 "warning: mounting fs with errors, "
1884 "running e2fsck is recommended");
1889 "warning: maximal mount count reached, "
1890 "running e2fsck is recommended");
1895 "warning: checktime reached, "
1896 "running e2fsck is recommended");
1897 if (!sbi->s_journal)
1907 ext4_commit_super(sb, 1);
1911 "bpg=%lu, ipg=%lu, mo=%04x, mo2=%04x]\n",
1913 sbi->s_groups_count,
1916 sbi->s_mount_opt, sbi->s_mount_opt2);
1918 cleancache_init_fs(sb);
1924 struct ext4_sb_info *sbi =
EXT4_SB(sb);
1928 if (!sbi->s_log_groups_per_flex)
1931 size = ext4_flex_group(sbi, ngroup - 1) + 1;
1932 if (size <= sbi->s_flex_groups_allocated)
1943 if (sbi->s_flex_groups) {
1944 memcpy(new_groups, sbi->s_flex_groups,
1945 (sbi->s_flex_groups_allocated *
1949 sbi->s_flex_groups = new_groups;
1950 sbi->s_flex_groups_allocated = size /
sizeof(
struct flex_groups);
1954 static int ext4_fill_flex_info(
struct super_block *sb)
1956 struct ext4_sb_info *sbi =
EXT4_SB(sb);
1959 unsigned int groups_per_flex = 0;
1962 sbi->s_log_groups_per_flex = sbi->s_es->s_log_groups_per_flex;
1963 if (sbi->s_log_groups_per_flex < 1 || sbi->s_log_groups_per_flex > 31) {
1964 sbi->s_log_groups_per_flex = 0;
1967 groups_per_flex = 1
U << sbi->s_log_groups_per_flex;
1973 for (i = 0; i < sbi->s_groups_count; i++) {
1976 flex_group = ext4_flex_group(sbi, i);
1978 &sbi->s_flex_groups[flex_group].free_inodes);
1980 &sbi->s_flex_groups[flex_group].free_clusters);
1982 &sbi->s_flex_groups[flex_group].used_dirs);
1997 if ((sbi->s_es->s_feature_ro_compat &
2005 csum32 = ext4_chksum(sbi, sbi->s_csum_seed, (
__u8 *)&le_group,
2007 csum32 = ext4_chksum(sbi, csum32, (
__u8 *)gdp,
2011 crc = csum32 & 0xFFFF;
2018 crc =
crc16(~0, sbi->s_es->s_uuid,
sizeof(sbi->s_es->s_uuid));
2019 crc =
crc16(crc, (
__u8 *)&le_group,
sizeof(le_group));
2023 if ((sbi->s_es->s_feature_incompat &
2037 if (ext4_has_group_desc_csum(sb) &&
2048 if (!ext4_has_group_desc_csum(sb))
2054 static int ext4_check_descriptors(
struct super_block *sb,
2057 struct ext4_sb_info *sbi =
EXT4_SB(sb);
2063 int flexbg_flag = 0;
2071 for (i = 0; i < sbi->s_groups_count; i++) {
2074 if (i == sbi->s_groups_count - 1 || flexbg_flag)
2075 last_block = ext4_blocks_count(sbi->s_es) - 1;
2077 last_block = first_block +
2080 if ((grp == sbi->s_groups_count) &&
2085 if (block_bitmap < first_block || block_bitmap > last_block) {
2087 "Block bitmap for group %u not in group "
2088 "(block %llu)!", i, block_bitmap);
2092 if (inode_bitmap < first_block || inode_bitmap > last_block) {
2094 "Inode bitmap for group %u not in group "
2095 "(block %llu)!", i, inode_bitmap);
2099 if (inode_table < first_block ||
2100 inode_table + sbi->s_itb_per_group - 1 > last_block) {
2102 "Inode table for group %u not in group "
2103 "(block %llu)!", i, inode_table);
2106 ext4_lock_group(sb, i);
2109 "Checksum for group %u failed (%u!=%u)",
2113 ext4_unlock_group(sb, i);
2117 ext4_unlock_group(sb, i);
2121 if (
NULL != first_not_zeroed)
2122 *first_not_zeroed = grp;
2124 ext4_free_blocks_count_set(sbi->s_es,
2147 static void ext4_orphan_cleanup(
struct super_block *sb,
2151 int nr_orphans = 0, nr_truncates = 0;
2156 jbd_debug(4,
"no orphan inodes to clean up\n");
2162 "unavailable, skipping orphan cleanup");
2167 if (!ext4_feature_set_ok(sb, 0)) {
2169 "unknown ROCOMPAT features");
2177 "clearing orphan list.\n");
2180 jbd_debug(1,
"Skipping orphan recovery on fs with errors.\n");
2193 if (
EXT4_SB(sb)->s_qf_names[i]) {
2194 int ret = ext4_quota_on_mount(sb, i);
2197 "Cannot turn on journaled "
2198 "quota: error %d", ret);
2204 struct inode *
inode;
2207 if (IS_ERR(inode)) {
2216 "%s: truncating inode %lu to %lld bytes",
2218 jbd_debug(2,
"truncating inode %lu to %lld bytes\n",
2224 "%s: deleting unreferenced inode %lu",
2225 __func__, inode->
i_ino);
2226 jbd_debug(2,
"deleting unreferenced inode %lu\n",
2233 #define PLURAL(x) (x), ((x) == 1) ? "" : "s"
2244 if (sb_dqopt(sb)->
files[i])
2266 static loff_t ext4_max_size(
int blkbits,
int has_huge_files)
2269 loff_t upper_limit = MAX_LFS_FILESIZE;
2272 if (!has_huge_files ||
sizeof(
blkcnt_t) <
sizeof(
u64)) {
2278 upper_limit = (1
LL << 32) - 1;
2281 upper_limit >>= (blkbits - 9);
2282 upper_limit <<= blkbits;
2290 res = (1
LL << 32) - 1;
2294 if (res > upper_limit)
2305 static loff_t ext4_max_bitmap_size(
int bits,
int has_huge_files)
2318 if (!has_huge_files ||
sizeof(
blkcnt_t) <
sizeof(
u64)) {
2324 upper_limit = (1
LL << 32) - 1;
2327 upper_limit >>= (bits - 9);
2336 upper_limit = (1
LL << 48) - 1;
2343 meta_blocks += 1 + (1
LL << (bits-2));
2345 meta_blocks += 1 + (1
LL << (bits-2)) + (1
LL << (2*(bits-2)));
2347 upper_limit -= meta_blocks;
2348 upper_limit <<=
bits;
2350 res += 1
LL << (bits-2);
2351 res += 1
LL << (2*(bits-2));
2352 res += 1
LL << (3*(bits-2));
2354 if (res > upper_limit)
2357 if (res > MAX_LFS_FILESIZE)
2358 res = MAX_LFS_FILESIZE;
2366 struct ext4_sb_info *sbi =
EXT4_SB(sb);
2370 first_meta_bg =
le32_to_cpu(sbi->s_es->s_first_meta_bg);
2374 return logical_sb_block + nr + 1;
2375 bg = sbi->s_desc_per_block *
nr;
2379 return (has_super + ext4_group_first_block_no(sb, bg));
2393 static unsigned long ext4_get_stripe_size(
struct ext4_sb_info *sbi)
2395 unsigned long stride =
le16_to_cpu(sbi->s_es->s_raid_stride);
2396 unsigned long stripe_width =
2400 if (sbi->s_stripe && sbi->s_stripe <= sbi->s_blocks_per_group)
2401 ret = sbi->s_stripe;
2402 else if (stripe_width <= sbi->s_blocks_per_group)
2404 else if (stride <= sbi->s_blocks_per_group)
2429 static int parse_strtoul(
const char *
buf,
2430 unsigned long max,
unsigned long *
value)
2436 if (*endp || *value > max)
2443 struct ext4_sb_info *sbi,
2448 percpu_counter_sum(&sbi->s_dirtyclusters_counter)));
2452 struct ext4_sb_info *sbi,
char *buf)
2454 struct super_block *sb = sbi->s_buddy_cache->i_sb;
2456 if (!sb->
s_bdev->bd_part)
2460 sbi->s_sectors_written_start) >> 1);
2464 struct ext4_sb_info *sbi,
char *buf)
2466 struct super_block *sb = sbi->s_buddy_cache->i_sb;
2468 if (!sb->
s_bdev->bd_part)
2471 (
unsigned long long)(sbi->s_kbytes_written +
2473 EXT4_SB(sb)->s_sectors_written_start) >> 1)));
2477 struct ext4_sb_info *sbi,
2478 const char *buf,
size_t count)
2482 if (parse_strtoul(buf, 0x40000000, &t))
2488 sbi->s_inode_readahead_blks =
t;
2493 struct ext4_sb_info *sbi,
char *buf)
2495 unsigned int *ui = (
unsigned int *) (((
char *) sbi) + a->
offset);
2501 struct ext4_sb_info *sbi,
2502 const char *buf,
size_t count)
2504 unsigned int *ui = (
unsigned int *) (((
char *) sbi) + a->
offset);
2507 if (parse_strtoul(buf, 0xffffffff, &t))
2514 struct ext4_sb_info *sbi,
2515 const char *buf,
size_t count)
2522 if (len && buf[len-1] ==
'\n')
2526 ext4_error(sbi->s_sb,
"%.*s", len, buf);
2530 #define EXT4_ATTR_OFFSET(_name,_mode,_show,_store,_elname) \
2531 static struct ext4_attr ext4_attr_##_name = { \
2532 .attr = {.name = __stringify(_name), .mode = _mode }, \
2535 .offset = offsetof(struct ext4_sb_info, _elname), \
2537 #define EXT4_ATTR(name, mode, show, store) \
2538 static struct ext4_attr ext4_attr_##name = __ATTR(name, mode, show, store)
2540 #define EXT4_INFO_ATTR(name) EXT4_ATTR(name, 0444, NULL, NULL)
2541 #define EXT4_RO_ATTR(name) EXT4_ATTR(name, 0444, name##_show, NULL)
2542 #define EXT4_RW_ATTR(name) EXT4_ATTR(name, 0644, name##_show, name##_store)
2543 #define EXT4_RW_ATTR_SBI_UI(name, elname) \
2544 EXT4_ATTR_OFFSET(name, 0644, sbi_ui_show, sbi_ui_store, elname)
2545 #define ATTR_LIST(name) &ext4_attr_##name.attr
2551 inode_readahead_blks_store, s_inode_readahead_blks);
2561 EXT4_ATTR(trigger_fs_error, 0200,
NULL, trigger_test_error);
2563 static struct attribute *ext4_attrs[] = {
2586 static struct attribute *ext4_feat_attrs[] = {
2596 struct ext4_sb_info *sbi =
container_of(kobj,
struct ext4_sb_info,
2600 return a->
show ? a->
show(a, sbi, buf) : 0;
2605 const char *buf,
size_t len)
2607 struct ext4_sb_info *sbi =
container_of(kobj,
struct ext4_sb_info,
2611 return a->
store ? a->
store(a, sbi, buf, len) : 0;
2614 static void ext4_sb_release(
struct kobject *kobj)
2616 struct ext4_sb_info *sbi =
container_of(kobj,
struct ext4_sb_info,
2621 static const struct sysfs_ops ext4_attr_ops = {
2622 .show = ext4_attr_show,
2623 .store = ext4_attr_store,
2627 .default_attrs = ext4_attrs,
2628 .sysfs_ops = &ext4_attr_ops,
2629 .release = ext4_sb_release,
2632 static void ext4_feat_release(
struct kobject *kobj)
2634 complete(&ext4_feat->f_kobj_unregister);
2637 static struct kobj_type ext4_feat_ktype = {
2638 .default_attrs = ext4_feat_attrs,
2639 .sysfs_ops = &ext4_attr_ops,
2640 .release = ext4_feat_release,
2653 "Couldn't mount because of "
2654 "unsupported optional features (%x)",
2666 "unsupported optional features (%x)",
2678 "cannot be mounted RDWR without "
2686 "Can't support bigalloc feature without "
2687 "extents feature\n");
2691 #ifndef CONFIG_QUOTA
2695 "Filesystem with quota feature cannot be mounted RDWR "
2696 "without CONFIG_QUOTA");
2707 static void print_daily_error_info(
unsigned long arg)
2710 struct ext4_sb_info *sbi;
2729 printk(
": block %llu", (
unsigned long long)
2743 printk(
": block %llu", (
unsigned long long)
2747 mod_timer(&sbi->s_err_report, jiffies + 24*60*60*HZ);
2751 static int ext4_run_li_request(
struct ext4_li_request *elr)
2760 ngroups =
EXT4_SB(sb)->s_groups_count;
2763 for (group = elr->lr_next_group; group < ngroups; group++) {
2774 if (group == ngroups)
2780 elr->lr_timeout ? 0 : 1);
2781 if (elr->lr_timeout == 0) {
2782 timeout = (
jiffies - timeout) *
2783 elr->lr_sbi->s_li_wait_mult;
2784 elr->lr_timeout = timeout;
2786 elr->lr_next_sched =
jiffies + elr->lr_timeout;
2787 elr->lr_next_group = group + 1;
2798 static void ext4_remove_li_request(
struct ext4_li_request *elr)
2800 struct ext4_sb_info *sbi;
2808 sbi->s_li_request =
NULL;
2812 static void ext4_unregister_li_request(
struct super_block *sb)
2815 if (!ext4_li_info) {
2821 ext4_remove_li_request(
EXT4_SB(sb)->s_li_request);
2837 static int ext4_lazyinit_thread(
void *arg)
2839 struct ext4_lazy_init *eli = (
struct ext4_lazy_init *)arg;
2841 struct ext4_li_request *elr;
2842 unsigned long next_wakeup,
cur;
2851 if (list_empty(&eli->li_request_list)) {
2857 elr =
list_entry(pos,
struct ext4_li_request,
2861 if (ext4_run_li_request(elr) != 0) {
2863 ext4_remove_li_request(elr);
2869 next_wakeup = elr->lr_next_sched;
2885 ext4_clear_request_list();
2901 if (!list_empty(&eli->li_request_list)) {
2907 kfree(ext4_li_info);
2908 ext4_li_info =
NULL;
2914 static void ext4_clear_request_list(
void)
2917 struct ext4_li_request *elr;
2921 elr =
list_entry(pos,
struct ext4_li_request,
2923 ext4_remove_li_request(elr);
2928 static int ext4_run_lazyinit_thread(
void)
2930 ext4_lazyinit_task =
kthread_run(ext4_lazyinit_thread,
2931 ext4_li_info,
"ext4lazyinit");
2932 if (IS_ERR(ext4_lazyinit_task)) {
2933 int err = PTR_ERR(ext4_lazyinit_task);
2934 ext4_clear_request_list();
2935 kfree(ext4_li_info);
2936 ext4_li_info =
NULL;
2938 "initialization thread\n",
2942 ext4_li_info->li_state |= EXT4_LAZYINIT_RUNNING;
2957 for (group = 0; group < ngroups; group++) {
2969 static int ext4_li_info_new(
void)
2971 struct ext4_lazy_init *eli =
NULL;
2977 INIT_LIST_HEAD(&eli->li_request_list);
2980 eli->li_state |= EXT4_LAZYINIT_QUIT;
2987 static struct ext4_li_request *ext4_li_request_new(
struct super_block *sb,
2990 struct ext4_sb_info *sbi =
EXT4_SB(sb);
2991 struct ext4_li_request *elr;
3000 elr->lr_next_group =
start;
3008 elr->lr_next_sched =
jiffies + (
unsigned long)rnd %
3009 (EXT4_DEF_LI_MAX_START_DELAY * HZ);
3014 static int ext4_register_li_request(
struct super_block *sb,
3017 struct ext4_sb_info *sbi =
EXT4_SB(sb);
3018 struct ext4_li_request *elr;
3022 if (sbi->s_li_request !=
NULL) {
3027 sbi->s_li_request->lr_timeout = 0;
3031 if (first_not_zeroed == ngroups ||
3036 elr = ext4_li_request_new(sb, first_not_zeroed);
3042 if (
NULL == ext4_li_info) {
3043 ret = ext4_li_info_new();
3049 list_add(&elr->lr_request, &ext4_li_info->li_request_list);
3052 sbi->s_li_request = elr;
3060 if (!(ext4_li_info->li_state & EXT4_LAZYINIT_RUNNING)) {
3061 ret = ext4_run_lazyinit_thread();
3076 static void ext4_destroy_lazyinit_thread(
void)
3082 if (!ext4_li_info || !ext4_lazyinit_task)
3088 static int set_journal_csum_feature_set(
struct super_block *sb)
3091 int compat, incompat;
3092 struct ext4_sb_info *sbi =
EXT4_SB(sb);
3105 if (
test_opt(sb, JOURNAL_ASYNC_COMMIT)) {
3110 }
else if (
test_opt(sb, JOURNAL_CHECKSUM)) {
3144 struct ext4_sb_info *sbi =
EXT4_SB(sb);
3148 int s,
j, count = 0;
3152 sbi->s_itb_per_group + 2);
3154 first_block =
le32_to_cpu(sbi->s_es->s_first_data_block) +
3157 for (i = 0; i < ngroups; i++) {
3160 if (b >= first_block && b <= last_block) {
3165 if (b >= first_block && b <= last_block) {
3170 if (b >= first_block && b + sbi->s_itb_per_group <= last_block)
3171 for (j = 0; j < sbi->s_itb_per_group; j++, b++) {
3190 return EXT4_CLUSTERS_PER_GROUP(sb) -
3199 struct ext4_sb_info *sbi =
EXT4_SB(sb);
3223 for (i = 0; i < ngroups; i++) {
3226 blks = count_overhead(sb, i, buf);
3232 sbi->s_overhead = overhead;
3238 static int ext4_fill_super(
struct super_block *sb,
void *data,
int silent)
3241 struct buffer_head *bh;
3243 struct ext4_sb_info *sbi;
3247 unsigned long offset = 0;
3248 unsigned long journal_devnum = 0;
3249 unsigned long def_mount_opts;
3254 int blocksize, clustersize;
3255 unsigned int db_count;
3257 int needs_recovery, has_huge_files, has_bigalloc;
3267 sbi->s_blockgroup_lock =
3269 if (!sbi->s_blockgroup_lock) {
3275 sbi->s_mount_opt = 0;
3279 sbi->s_sb_block = sb_block;
3281 sbi->s_sectors_written_start =
3301 offset =
do_div(logical_sb_block, blocksize);
3303 logical_sb_block = sb_block;
3306 if (!(bh = sb_bread(sb, logical_sb_block))) {
3325 ext4_warning(sb,
KERN_INFO "metadata_csum and uninit_bg are "
3326 "redundant flags; please run fsck.");
3329 if (!ext4_verify_csum_type(sb, es)) {
3331 "unknown checksum algorithm.");
3340 if (IS_ERR(sbi->s_chksum_driver)) {
3342 ret = PTR_ERR(sbi->s_chksum_driver);
3343 sbi->s_chksum_driver =
NULL;
3351 "invalid superblock checksum. Run e2fsck?");
3359 sbi->s_csum_seed = ext4_chksum(sbi, ~0, es->
s_uuid,
3364 set_opt(sb, INIT_INODE_TABLE);
3372 #ifdef CONFIG_EXT4_FS_XATTR
3375 #ifdef CONFIG_EXT4_FS_POSIX_ACL
3418 sbi->s_li_wait_mult = EXT4_DEF_LI_WAIT_MULT;
3420 if (!parse_options((
char *) sbi->s_es->s_mount_opts, sb,
3421 &journal_devnum, &journal_ioprio, 0)) {
3423 "failed to parse options in superblock: %s",
3424 sbi->s_es->s_mount_opts);
3426 sbi->s_def_mount_opt = sbi->s_mount_opt;
3427 if (!parse_options((
char *) data, sb, &journal_devnum,
3428 &journal_ioprio, 0))
3433 "with data=journal disables delayed "
3434 "allocation and O_DIRECT support!\n");
3437 "both data=journal and delalloc");
3440 if (
test_opt(sb, DIOREAD_NOLOCK)) {
3442 "both data=journal and delalloc");
3450 if (
test_opt(sb, DIOREAD_NOLOCK)) {
3453 "dioread_nolock if block size != PAGE_SIZE");
3466 "feature flags set on rev 0 fs, "
3467 "running e2fsck is recommended");
3470 if (ext2_feature_set_ok(sb))
3472 "using the ext4 subsystem");
3475 "to feature incompatibilities");
3481 if (ext3_feature_set_ok(sb))
3483 "using the ext4 subsystem");
3486 "to feature incompatibilities");
3496 if (!ext4_feature_set_ok(sb, (sb->
s_flags & MS_RDONLY)))
3502 "Unsupported filesystem blocksize %d", blocksize);
3516 offset =
do_div(logical_sb_block, blocksize);
3517 bh = sb_bread(sb, logical_sb_block);
3520 "Can't read superblock on 2nd try");
3527 "Magic mismatch, very weird!");
3546 (sbi->s_inode_size > blocksize)) {
3548 "unsupported inode size: %d",
3562 "unsupported descriptor size %lu",
3575 if (sbi->s_inodes_per_block == 0)
3577 sbi->s_itb_per_group = sbi->s_inodes_per_group /
3578 sbi->s_inodes_per_block;
3585 for (i = 0; i < 4; i++)
3590 sbi->s_hash_unsigned = 3;
3592 #ifdef __CHAR_UNSIGNED__
3594 sbi->s_hash_unsigned = 3;
3605 if (clustersize < blocksize) {
3607 "cluster size (%d) smaller than "
3608 "block size (%d)", clustersize, blocksize);
3613 sbi->s_clusters_per_group =
3615 if (sbi->s_clusters_per_group > blocksize * 8) {
3617 "#clusters per group too big: %lu",
3618 sbi->s_clusters_per_group);
3621 if (sbi->s_blocks_per_group !=
3622 (sbi->s_clusters_per_group * (clustersize / blocksize))) {
3624 "clusters per group (%lu) inconsistent",
3625 sbi->s_blocks_per_group,
3626 sbi->s_clusters_per_group);
3630 if (clustersize != blocksize) {
3631 ext4_warning(sb,
"fragment/cluster size (%d) != "
3632 "block size (%d)", clustersize,
3634 clustersize = blocksize;
3636 if (sbi->s_blocks_per_group > blocksize * 8) {
3638 "#blocks per group too big: %lu",
3639 sbi->s_blocks_per_group);
3642 sbi->s_clusters_per_group = sbi->s_blocks_per_group;
3643 sbi->s_cluster_bits = 0;
3645 sbi->s_cluster_ratio = clustersize / blocksize;
3647 if (sbi->s_inodes_per_group > blocksize * 8) {
3649 "#inodes per group too big: %lu",
3650 sbi->s_inodes_per_group);
3659 ext4_blocks_count(es));
3662 " too large to mount safely on this system");
3674 if (blocks_count && ext4_blocks_count(es) > blocks_count) {
3676 "exceeds size of device (%llu blocks)",
3677 ext4_blocks_count(es), blocks_count);
3687 "block %u is beyond end of filesystem (%llu)",
3689 ext4_blocks_count(es));
3692 blocks_count = (ext4_blocks_count(es) -
3698 "(block count %llu, first data block %u, "
3699 "blocks per group %lu)", sbi->s_groups_count,
3700 ext4_blocks_count(es),
3705 sbi->s_groups_count = blocks_count;
3711 sizeof(
struct buffer_head *),
3713 if (sbi->s_group_desc ==
NULL) {
3724 &ext4_seq_options_fops, sb);
3726 bgl_lock_init(sbi->s_blockgroup_lock);
3728 for (i = 0; i < db_count; i++) {
3729 block = descriptor_loc(sb, logical_sb_block, i);
3730 sbi->s_group_desc[
i] = sb_bread(sb, block);
3731 if (!sbi->s_group_desc[i]) {
3733 "can't read group descriptor %d", i);
3738 if (!ext4_check_descriptors(sb, &first_not_zeroed)) {
3743 if (!ext4_fill_flex_info(sb)) {
3745 "unable to initialize "
3746 "flex_bg meta info!");
3750 sbi->s_gdb_count = db_count;
3755 sbi->s_err_report.function = print_daily_error_info;
3756 sbi->s_err_report.data = (
unsigned long) sb;
3758 err = percpu_counter_init(&sbi->s_freeclusters_counter,
3761 err = percpu_counter_init(&sbi->s_freeinodes_counter,
3765 err = percpu_counter_init(&sbi->s_dirs_counter,
3769 err = percpu_counter_init(&sbi->s_dirtyclusters_counter, 0);
3777 sbi->s_stripe = ext4_get_stripe_size(sbi);
3778 sbi->s_max_writeback_mb_bump = 128;
3779 sbi->s_extent_max_zeroout_kb = 32;
3786 sb->
s_op = &ext4_sops;
3788 sb->
s_op = &ext4_nojournal_sops;
3792 sb->
s_qcop = &ext4_qctl_operations;
3793 sb->
dq_op = &ext4_quota_operations;
3797 sb->
s_qcop = &ext4_qctl_sysfile_operations;
3802 INIT_LIST_HEAD(&sbi->s_orphan);
3804 sbi->s_resize_flags = 0;
3823 if (ext4_load_journal(sb, es, journal_devnum))
3828 "suppressed and not mounted read-only");
3829 goto failed_mount_wq;
3832 sbi->s_journal =
NULL;
3841 goto failed_mount_wq;
3844 if (!set_journal_csum_feature_set(sb)) {
3847 goto failed_mount_wq;
3852 switch (
test_opt(sb, DATA_FLAGS)) {
3870 "requested data journaling mode");
3871 goto failed_mount_wq;
3878 sbi->s_journal->j_commit_callback = ext4_journal_commit_callback;
3902 goto failed_mount_wq;
3909 EXT4_SB(sb)->dio_unwritten_wq =
3911 if (!
EXT4_SB(sb)->dio_unwritten_wq) {
3913 goto failed_mount_wq;
3924 ret = PTR_ERR(root);
3940 if (ext4_setup_super(sb, es, sb->
s_flags & MS_RDONLY))
3945 sbi->s_want_extra_isize =
sizeof(
struct ext4_inode) -
3949 if (sbi->s_want_extra_isize <
3951 sbi->s_want_extra_isize =
3953 if (sbi->s_want_extra_isize <
3955 sbi->s_want_extra_isize =
3961 sbi->s_inode_size) {
3962 sbi->s_want_extra_isize =
sizeof(
struct ext4_inode) -
3972 goto failed_mount4a;
3983 err = ext4_register_li_request(sb, first_not_zeroed);
3987 sbi->s_kobj.kset = ext4_kset;
3988 init_completion(&sbi->s_kobj_unregister);
3995 ext4_orphan_cleanup(sb, es);
3997 if (needs_recovery) {
3999 ext4_mark_recovery_complete(sb, es);
4003 descr =
" journalled data mode";
4005 descr =
" ordered data mode";
4007 descr =
" writeback data mode";
4009 descr =
"out journal";
4015 ret = ext4_enable_quotas(sb);
4022 "Opts: %s%s%s", descr, sbi->s_es->s_mount_opts,
4023 *sbi->s_es->s_mount_opts ?
"; " :
"", orig_data);
4026 mod_timer(&sbi->s_err_report, jiffies + 300*HZ);
4037 ext4_unregister_li_request(sb);
4050 if (sbi->s_journal) {
4052 sbi->s_journal =
NULL;
4056 if (sbi->s_flex_groups)
4065 for (i = 0; i < db_count; i++)
4066 brelse(sbi->s_group_desc[i]);
4069 if (sbi->s_chksum_driver)
4070 crypto_free_shash(sbi->s_chksum_driver);
4077 kfree(sbi->s_qf_names[i]);
4079 ext4_blkdev_remove(sbi);
4083 kfree(sbi->s_blockgroup_lock);
4095 static void ext4_init_journal_params(
struct super_block *sb, journal_t *journal)
4097 struct ext4_sb_info *sbi =
EXT4_SB(sb);
4099 journal->j_commit_interval = sbi->s_commit_interval;
4100 journal->j_min_batch_time = sbi->s_min_batch_time;
4101 journal->j_max_batch_time = sbi->s_max_batch_time;
4105 journal->j_flags |= JBD2_BARRIER;
4107 journal->j_flags &= ~JBD2_BARRIER;
4109 journal->j_flags |= JBD2_ABORT_ON_SYNCDATA_ERR;
4111 journal->j_flags &= ~JBD2_ABORT_ON_SYNCDATA_ERR;
4115 static journal_t *ext4_get_journal(
struct super_block *sb,
4116 unsigned int journal_inum)
4118 struct inode *journal_inode;
4127 journal_inode =
ext4_iget(sb, journal_inum);
4128 if (IS_ERR(journal_inode)) {
4132 if (!journal_inode->
i_nlink) {
4134 iput(journal_inode);
4139 jbd_debug(2,
"Journal inode found at %p: %lld bytes\n",
4140 journal_inode, journal_inode->
i_size);
4143 iput(journal_inode);
4150 iput(journal_inode);
4153 journal->j_private =
sb;
4154 ext4_init_journal_params(sb, journal);
4158 static journal_t *ext4_get_dev_journal(
struct super_block *sb,
4161 struct buffer_head *bh;
4165 int hblock, blocksize;
4173 bdev = ext4_blkdev_get(j_dev, sb);
4178 hblock = bdev_logical_block_size(bdev);
4179 if (blocksize < hblock) {
4181 "blocksize too small for journal device");
4185 sb_block = EXT4_MIN_BLOCK_SIZE / blocksize;
4186 offset = EXT4_MIN_BLOCK_SIZE % blocksize;
4188 if (!(bh =
__bread(bdev, sb_block, blocksize))) {
4190 "external journal");
4210 len = ext4_blocks_count(es);
4211 start = sb_block + 1;
4215 start, len, blocksize);
4220 journal->j_private =
sb;
4222 wait_on_buffer(journal->j_sb_buffer);
4223 if (!buffer_uptodate(journal->j_sb_buffer)) {
4227 if (
be32_to_cpu(journal->j_superblock->s_nr_users) != 1) {
4229 "user (unsupported) - %d",
4233 EXT4_SB(sb)->journal_bdev = bdev;
4234 ext4_init_journal_params(sb, journal);
4240 ext4_blkdev_put(bdev);
4244 static int ext4_load_journal(
struct super_block *sb,
4246 unsigned long journal_devnum)
4252 int really_read_only;
4256 if (journal_devnum &&
4259 "numbers have changed");
4260 journal_dev = new_decode_dev(journal_devnum);
4272 if (sb->
s_flags & MS_RDONLY) {
4274 "required on readonly filesystem");
4275 if (really_read_only) {
4277 "unavailable, cannot proceed");
4281 "be enabled during recovery");
4285 if (journal_inum && journal_dev) {
4287 "and inode journals!");
4292 if (!(journal = ext4_get_journal(sb, journal_inum)))
4295 if (!(journal = ext4_get_dev_journal(sb, journal_dev)))
4299 if (!(journal->j_flags & JBD2_BARRIER))
4307 memcpy(save, ((
char *) es) +
4322 EXT4_SB(sb)->s_journal = journal;
4323 ext4_clear_journal_err(sb, es);
4325 if (!really_read_only && journal_devnum &&
4330 ext4_commit_super(sb, 1);
4339 struct buffer_head *sbh =
EXT4_SB(sb)->s_sbh;
4342 if (!sbh || block_device_ejected(sb))
4344 if (buffer_write_io_error(sbh)) {
4354 "superblock detected");
4355 clear_buffer_write_io_error(sbh);
4356 set_buffer_uptodate(sbh);
4368 if (!(sb->
s_flags & MS_RDONLY))
4374 EXT4_SB(sb)->s_sectors_written_start) >> 1));
4378 ext4_free_blocks_count_set(es,
4380 &
EXT4_SB(sb)->s_freeclusters_counter)));
4383 &
EXT4_SB(sb)->s_freeinodes_counter));
4384 BUFFER_TRACE(sbh,
"marking dirty");
4392 error = buffer_write_io_error(sbh);
4396 clear_buffer_write_io_error(sbh);
4397 set_buffer_uptodate(sbh);
4408 static void ext4_mark_recovery_complete(
struct super_block *sb,
4411 journal_t *journal =
EXT4_SB(sb)->s_journal;
4424 ext4_commit_super(sb, 1);
4436 static void ext4_clear_journal_err(
struct super_block *sb,
4445 journal =
EXT4_SB(sb)->s_journal;
4456 errstr = ext4_decode_error(sb, j_errno, nbuf);
4457 ext4_warning(sb,
"Filesystem error recorded "
4458 "from previous mount: %s", errstr);
4459 ext4_warning(sb,
"Marking fs in need of filesystem check.");
4463 ext4_commit_super(sb, 1);
4482 journal =
EXT4_SB(sb)->s_journal;
4484 ret = ext4_journal_force_commit(journal);
4489 static int ext4_sync_fs(
struct super_block *sb,
int wait)
4493 struct ext4_sb_info *sbi =
EXT4_SB(sb);
4495 trace_ext4_sync_fs(sb, wait);
4525 journal =
EXT4_SB(sb)->s_journal;
4540 error = ext4_commit_super(sb, 1);
4558 ext4_commit_super(sb, 1);
4581 struct ext4_sb_info *sbi =
EXT4_SB(sb);
4582 unsigned long old_sb_flags;
4584 int enable_quota = 0;
4603 old_opts.s_jquota_fmt = sbi->s_jquota_fmt;
4605 old_opts.s_qf_names[i] = sbi->s_qf_names[i];
4607 if (sbi->s_journal && sbi->s_journal->j_task->io_context)
4608 journal_ioprio = sbi->s_journal->j_task->io_context->ioprio;
4613 if (!parse_options(data, sb,
NULL, &journal_ioprio, 1)) {
4618 if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
4619 ext4_abort(sb,
"Abort forced by user");
4626 if (sbi->s_journal) {
4627 ext4_init_journal_params(sb, sbi->s_journal);
4631 if ((*flags & MS_RDONLY) != (sb->
s_flags & MS_RDONLY)) {
4632 if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED) {
4637 if (*flags & MS_RDONLY) {
4638 err = dquot_suspend(sb, -1);
4658 ext4_mark_recovery_complete(sb, es);
4661 if (!ext4_feature_set_ok(sb, 0)) {
4669 for (g = 0; g < sbi->s_groups_count; g++) {
4675 "ext4_remount: Checksum for group %u failed (%u!=%u)",
4676 g,
le16_to_cpu(ext4_group_desc_csum(sbi, g, gdp)),
4690 "remount RDWR because of unprocessed "
4691 "orphan inode list. Please "
4692 "umount/remount instead");
4704 ext4_clear_journal_err(sb, es);
4706 if (!ext4_setup_super(sb, es, 0))
4724 ext4_unregister_li_request(sb);
4727 first_not_zeroed = ext4_has_uninit_itable(sb);
4728 ext4_register_li_request(sb, first_not_zeroed);
4732 if (sbi->s_journal ==
NULL)
4733 ext4_commit_super(sb, 1);
4738 if (old_opts.s_qf_names[i] &&
4739 old_opts.s_qf_names[i] != sbi->s_qf_names[i])
4740 kfree(old_opts.s_qf_names[i]);
4742 if (sb_any_quota_suspended(sb))
4746 err = ext4_enable_quotas(sb);
4767 sbi->s_jquota_fmt = old_opts.s_jquota_fmt;
4769 if (sbi->s_qf_names[i] &&
4770 old_opts.s_qf_names[i] != sbi->s_qf_names[i])
4771 kfree(sbi->s_qf_names[i]);
4772 sbi->s_qf_names[
i] = old_opts.s_qf_names[
i];
4782 struct ext4_sb_info *sbi =
EXT4_SB(sb);
4789 overhead = sbi->s_overhead;
4794 bfree = percpu_counter_sum_positive(&sbi->s_freeclusters_counter) -
4795 percpu_counter_sum_positive(&sbi->s_dirtyclusters_counter);
4799 if (buf->
f_bfree < ext4_r_blocks_count(es))
4802 buf->
f_ffree = percpu_counter_sum_positive(&sbi->s_freeinodes_counter);
4807 buf->
f_fsid.
val[1] = (fsid >> 32) & 0xFFFFFFFFUL;
4824 static inline struct inode *dquot_to_inode(
struct dquot *
dquot)
4826 return sb_dqopt(dquot->
dq_sb)->files[dquot->
dq_id.type];
4829 static int ext4_write_dquot(
struct dquot *
dquot)
4833 struct inode *
inode;
4835 inode = dquot_to_inode(dquot);
4836 handle = ext4_journal_start(inode,
4839 return PTR_ERR(handle);
4847 static int ext4_acquire_dquot(
struct dquot *dquot)
4852 handle = ext4_journal_start(dquot_to_inode(dquot),
4855 return PTR_ERR(handle);
4863 static int ext4_release_dquot(
struct dquot *dquot)
4868 handle = ext4_journal_start(dquot_to_inode(dquot),
4870 if (IS_ERR(handle)) {
4873 return PTR_ERR(handle);
4882 static int ext4_mark_dquot_dirty(
struct dquot *dquot)
4888 return ext4_write_dquot(dquot);
4900 handle = ext4_journal_start(sb->
s_root->d_inode, 2);
4902 return PTR_ERR(handle);
4914 static int ext4_quota_on_mount(
struct super_block *sb,
int type)
4917 EXT4_SB(sb)->s_jquota_fmt, type);
4932 if (path->
dentry->d_sb != sb)
4935 if (
EXT4_SB(sb)->s_qf_names[type]) {
4939 "Quota file not on filesystem root. "
4940 "Journaled quota will not work");
4948 ext4_should_journal_data(path->
dentry->d_inode)) {
4963 static int ext4_quota_enable(
struct super_block *sb,
int type,
int format_id,
4967 struct inode *qf_inode;
4975 if (!qf_inums[type])
4978 qf_inode =
ext4_iget(sb, qf_inums[type]);
4979 if (IS_ERR(qf_inode)) {
4980 ext4_error(sb,
"Bad quota inode # %lu", qf_inums[type]);
4981 return PTR_ERR(qf_inode);
4991 static int ext4_enable_quotas(
struct super_block *sb)
5000 for (type = 0; type <
MAXQUOTAS; type++) {
5001 if (qf_inums[type]) {
5006 "Failed to enable quota (type=%d) "
5007 "tracking. Please run e2fsck to fix.",
5019 static int ext4_quota_on_sysfile(
struct super_block *sb,
int type,
5031 static int ext4_quota_off(
struct super_block *sb,
int type)
5033 struct inode *inode = sb_dqopt(sb)->files[
type];
5046 handle = ext4_journal_start(inode, 1);
5060 static int ext4_quota_off_sysfile(
struct super_block *sb,
int type)
5074 size_t len, loff_t off)
5076 struct inode *inode = sb_dqopt(sb)->files[
type];
5082 struct buffer_head *bh;
5083 loff_t i_size = i_size_read(inode);
5087 if (off+len > i_size)
5090 while (toread > 0) {
5099 memcpy(data, bh->b_data+offset, tocopy);
5112 const char *data,
size_t len, loff_t off)
5114 struct inode *inode = sb_dqopt(sb)->files[
type];
5118 struct buffer_head *bh;
5119 handle_t *handle = journal_current_handle();
5123 " cancelled because transaction is not started",
5124 (
unsigned long long)off, (
unsigned long long)len);
5133 " cancelled because not block aligned",
5134 (
unsigned long long)off, (
unsigned long long)len);
5138 bh =
ext4_bread(handle, inode, blk, 1, &err);
5147 memcpy(bh->b_data+offset, data, len);
5155 if (inode->
i_size < off + len) {
5156 i_size_write(inode, off + len);
5165 static struct dentry *ext4_mount(
struct file_system_type *fs_type,
int flags,
5166 const char *dev_name,
void *data)
5168 return mount_bdev(fs_type, flags, dev_name, data, ext4_fill_super);
5171 #if !defined(CONFIG_EXT2_FS) && !defined(CONFIG_EXT2_FS_MODULE) && defined(CONFIG_EXT4_USE_FOR_EXT23)
5172 static inline void register_as_ext2(
void)
5177 "EXT4-fs: Unable to register as ext2 (%d)\n", err);
5180 static inline void unregister_as_ext2(
void)
5185 static inline int ext2_feature_set_ok(
struct super_block *sb)
5197 static inline void register_as_ext2(
void) { }
5198 static inline void unregister_as_ext2(
void) { }
5199 static inline int ext2_feature_set_ok(
struct super_block *sb) {
return 0; }
5202 #if !defined(CONFIG_EXT3_FS) && !defined(CONFIG_EXT3_FS_MODULE) && defined(CONFIG_EXT4_USE_FOR_EXT23)
5203 static inline void register_as_ext3(
void)
5208 "EXT4-fs: Unable to register as ext3 (%d)\n", err);
5211 static inline void unregister_as_ext3(
void)
5216 static inline int ext3_feature_set_ok(
struct super_block *sb)
5230 static inline void register_as_ext3(
void) { }
5231 static inline void unregister_as_ext3(
void) { }
5232 static inline int ext3_feature_set_ok(
struct super_block *sb) {
return 0; }
5238 .mount = ext4_mount,
5243 static int __init ext4_init_feat_adverts(
void)
5245 struct ext4_features *ef;
5248 ef = kzalloc(
sizeof(
struct ext4_features),
GFP_KERNEL);
5252 ef->f_kobj.kset = ext4_kset;
5253 init_completion(&ef->f_kobj_unregister);
5267 static void ext4_exit_feat_adverts(
void)
5278 static int __init ext4_init_fs(
void)
5282 ext4_li_info =
NULL;
5285 ext4_check_flag_values();
5287 for (i = 0; i < EXT4_WQ_HASH_SZ; i++) {
5305 err = ext4_init_feat_adverts();
5316 err = init_inodecache();
5327 unregister_as_ext2();
5328 unregister_as_ext3();
5329 destroy_inodecache();
5335 ext4_exit_feat_adverts();
5347 static void __exit ext4_exit_fs(
void)
5349 ext4_destroy_lazyinit_thread();
5350 unregister_as_ext2();
5351 unregister_as_ext3();
5353 destroy_inodecache();
5356 ext4_exit_feat_adverts();
5363 MODULE_AUTHOR(
"Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others");