diff options
Diffstat (limited to 'fs/ext4/super.c')
-rw-r--r-- | fs/ext4/super.c | 215 |
1 files changed, 170 insertions, 45 deletions
diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 4550b83ab1c9..b11e9e2bcd01 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c | |||
@@ -37,12 +37,14 @@ | |||
37 | #include <linux/quotaops.h> | 37 | #include <linux/quotaops.h> |
38 | #include <linux/seq_file.h> | 38 | #include <linux/seq_file.h> |
39 | #include <linux/log2.h> | 39 | #include <linux/log2.h> |
40 | #include <linux/crc16.h> | ||
40 | 41 | ||
41 | #include <asm/uaccess.h> | 42 | #include <asm/uaccess.h> |
42 | 43 | ||
43 | #include "xattr.h" | 44 | #include "xattr.h" |
44 | #include "acl.h" | 45 | #include "acl.h" |
45 | #include "namei.h" | 46 | #include "namei.h" |
47 | #include "group.h" | ||
46 | 48 | ||
47 | static int ext4_load_journal(struct super_block *, struct ext4_super_block *, | 49 | static int ext4_load_journal(struct super_block *, struct ext4_super_block *, |
48 | unsigned long journal_devnum); | 50 | unsigned long journal_devnum); |
@@ -68,31 +70,31 @@ static void ext4_write_super_lockfs(struct super_block *sb); | |||
68 | ext4_fsblk_t ext4_block_bitmap(struct super_block *sb, | 70 | ext4_fsblk_t ext4_block_bitmap(struct super_block *sb, |
69 | struct ext4_group_desc *bg) | 71 | struct ext4_group_desc *bg) |
70 | { | 72 | { |
71 | return le32_to_cpu(bg->bg_block_bitmap) | | 73 | return le32_to_cpu(bg->bg_block_bitmap_lo) | |
72 | (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? | 74 | (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? |
73 | (ext4_fsblk_t)le32_to_cpu(bg->bg_block_bitmap_hi) << 32 : 0); | 75 | (ext4_fsblk_t)le32_to_cpu(bg->bg_block_bitmap_hi) << 32 : 0); |
74 | } | 76 | } |
75 | 77 | ||
76 | ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb, | 78 | ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb, |
77 | struct ext4_group_desc *bg) | 79 | struct ext4_group_desc *bg) |
78 | { | 80 | { |
79 | return le32_to_cpu(bg->bg_inode_bitmap) | | 81 | return le32_to_cpu(bg->bg_inode_bitmap_lo) | |
80 | (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? | 82 | (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? |
81 | (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_bitmap_hi) << 32 : 0); | 83 | (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_bitmap_hi) << 32 : 0); |
82 | } | 84 | } |
83 | 85 | ||
84 | ext4_fsblk_t ext4_inode_table(struct super_block *sb, | 86 | ext4_fsblk_t ext4_inode_table(struct super_block *sb, |
85 | struct ext4_group_desc *bg) | 87 | struct ext4_group_desc *bg) |
86 | { | 88 | { |
87 | return le32_to_cpu(bg->bg_inode_table) | | 89 | return le32_to_cpu(bg->bg_inode_table_lo) | |
88 | (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? | 90 | (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? |
89 | (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_table_hi) << 32 : 0); | 91 | (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_table_hi) << 32 : 0); |
90 | } | 92 | } |
91 | 93 | ||
92 | void ext4_block_bitmap_set(struct super_block *sb, | 94 | void ext4_block_bitmap_set(struct super_block *sb, |
93 | struct ext4_group_desc *bg, ext4_fsblk_t blk) | 95 | struct ext4_group_desc *bg, ext4_fsblk_t blk) |
94 | { | 96 | { |
95 | bg->bg_block_bitmap = cpu_to_le32((u32)blk); | 97 | bg->bg_block_bitmap_lo = cpu_to_le32((u32)blk); |
96 | if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) | 98 | if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) |
97 | bg->bg_block_bitmap_hi = cpu_to_le32(blk >> 32); | 99 | bg->bg_block_bitmap_hi = cpu_to_le32(blk >> 32); |
98 | } | 100 | } |
@@ -100,7 +102,7 @@ void ext4_block_bitmap_set(struct super_block *sb, | |||
100 | void ext4_inode_bitmap_set(struct super_block *sb, | 102 | void ext4_inode_bitmap_set(struct super_block *sb, |
101 | struct ext4_group_desc *bg, ext4_fsblk_t blk) | 103 | struct ext4_group_desc *bg, ext4_fsblk_t blk) |
102 | { | 104 | { |
103 | bg->bg_inode_bitmap = cpu_to_le32((u32)blk); | 105 | bg->bg_inode_bitmap_lo = cpu_to_le32((u32)blk); |
104 | if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) | 106 | if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) |
105 | bg->bg_inode_bitmap_hi = cpu_to_le32(blk >> 32); | 107 | bg->bg_inode_bitmap_hi = cpu_to_le32(blk >> 32); |
106 | } | 108 | } |
@@ -108,7 +110,7 @@ void ext4_inode_bitmap_set(struct super_block *sb, | |||
108 | void ext4_inode_table_set(struct super_block *sb, | 110 | void ext4_inode_table_set(struct super_block *sb, |
109 | struct ext4_group_desc *bg, ext4_fsblk_t blk) | 111 | struct ext4_group_desc *bg, ext4_fsblk_t blk) |
110 | { | 112 | { |
111 | bg->bg_inode_table = cpu_to_le32((u32)blk); | 113 | bg->bg_inode_table_lo = cpu_to_le32((u32)blk); |
112 | if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) | 114 | if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT) |
113 | bg->bg_inode_table_hi = cpu_to_le32(blk >> 32); | 115 | bg->bg_inode_table_hi = cpu_to_le32(blk >> 32); |
114 | } | 116 | } |
@@ -523,7 +525,7 @@ static void ext4_destroy_inode(struct inode *inode) | |||
523 | kmem_cache_free(ext4_inode_cachep, EXT4_I(inode)); | 525 | kmem_cache_free(ext4_inode_cachep, EXT4_I(inode)); |
524 | } | 526 | } |
525 | 527 | ||
526 | static void init_once(void * foo, struct kmem_cache * cachep, unsigned long flags) | 528 | static void init_once(struct kmem_cache *cachep, void *foo) |
527 | { | 529 | { |
528 | struct ext4_inode_info *ei = (struct ext4_inode_info *) foo; | 530 | struct ext4_inode_info *ei = (struct ext4_inode_info *) foo; |
529 | 531 | ||
@@ -596,9 +598,80 @@ static inline void ext4_show_quota_options(struct seq_file *seq, struct super_bl | |||
596 | #endif | 598 | #endif |
597 | } | 599 | } |
598 | 600 | ||
601 | /* | ||
602 | * Show an option if | ||
603 | * - it's set to a non-default value OR | ||
604 | * - if the per-sb default is different from the global default | ||
605 | */ | ||
599 | static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs) | 606 | static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs) |
600 | { | 607 | { |
601 | struct super_block *sb = vfs->mnt_sb; | 608 | struct super_block *sb = vfs->mnt_sb; |
609 | struct ext4_sb_info *sbi = EXT4_SB(sb); | ||
610 | struct ext4_super_block *es = sbi->s_es; | ||
611 | unsigned long def_mount_opts; | ||
612 | |||
613 | def_mount_opts = le32_to_cpu(es->s_default_mount_opts); | ||
614 | |||
615 | if (sbi->s_sb_block != 1) | ||
616 | seq_printf(seq, ",sb=%llu", sbi->s_sb_block); | ||
617 | if (test_opt(sb, MINIX_DF)) | ||
618 | seq_puts(seq, ",minixdf"); | ||
619 | if (test_opt(sb, GRPID)) | ||
620 | seq_puts(seq, ",grpid"); | ||
621 | if (!test_opt(sb, GRPID) && (def_mount_opts & EXT4_DEFM_BSDGROUPS)) | ||
622 | seq_puts(seq, ",nogrpid"); | ||
623 | if (sbi->s_resuid != EXT4_DEF_RESUID || | ||
624 | le16_to_cpu(es->s_def_resuid) != EXT4_DEF_RESUID) { | ||
625 | seq_printf(seq, ",resuid=%u", sbi->s_resuid); | ||
626 | } | ||
627 | if (sbi->s_resgid != EXT4_DEF_RESGID || | ||
628 | le16_to_cpu(es->s_def_resgid) != EXT4_DEF_RESGID) { | ||
629 | seq_printf(seq, ",resgid=%u", sbi->s_resgid); | ||
630 | } | ||
631 | if (test_opt(sb, ERRORS_CONT)) { | ||
632 | int def_errors = le16_to_cpu(es->s_errors); | ||
633 | |||
634 | if (def_errors == EXT4_ERRORS_PANIC || | ||
635 | def_errors == EXT4_ERRORS_RO) { | ||
636 | seq_puts(seq, ",errors=continue"); | ||
637 | } | ||
638 | } | ||
639 | if (test_opt(sb, ERRORS_RO)) | ||
640 | seq_puts(seq, ",errors=remount-ro"); | ||
641 | if (test_opt(sb, ERRORS_PANIC)) | ||
642 | seq_puts(seq, ",errors=panic"); | ||
643 | if (test_opt(sb, NO_UID32)) | ||
644 | seq_puts(seq, ",nouid32"); | ||
645 | if (test_opt(sb, DEBUG)) | ||
646 | seq_puts(seq, ",debug"); | ||
647 | if (test_opt(sb, OLDALLOC)) | ||
648 | seq_puts(seq, ",oldalloc"); | ||
649 | #ifdef CONFIG_EXT4_FS_XATTR | ||
650 | if (test_opt(sb, XATTR_USER)) | ||
651 | seq_puts(seq, ",user_xattr"); | ||
652 | if (!test_opt(sb, XATTR_USER) && | ||
653 | (def_mount_opts & EXT4_DEFM_XATTR_USER)) { | ||
654 | seq_puts(seq, ",nouser_xattr"); | ||
655 | } | ||
656 | #endif | ||
657 | #ifdef CONFIG_EXT4_FS_POSIX_ACL | ||
658 | if (test_opt(sb, POSIX_ACL)) | ||
659 | seq_puts(seq, ",acl"); | ||
660 | if (!test_opt(sb, POSIX_ACL) && (def_mount_opts & EXT4_DEFM_ACL)) | ||
661 | seq_puts(seq, ",noacl"); | ||
662 | #endif | ||
663 | if (!test_opt(sb, RESERVATION)) | ||
664 | seq_puts(seq, ",noreservation"); | ||
665 | if (sbi->s_commit_interval) { | ||
666 | seq_printf(seq, ",commit=%u", | ||
667 | (unsigned) (sbi->s_commit_interval / HZ)); | ||
668 | } | ||
669 | if (test_opt(sb, BARRIER)) | ||
670 | seq_puts(seq, ",barrier=1"); | ||
671 | if (test_opt(sb, NOBH)) | ||
672 | seq_puts(seq, ",nobh"); | ||
673 | if (!test_opt(sb, EXTENTS)) | ||
674 | seq_puts(seq, ",noextents"); | ||
602 | 675 | ||
603 | if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) | 676 | if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) |
604 | seq_puts(seq, ",data=journal"); | 677 | seq_puts(seq, ",data=journal"); |
@@ -966,7 +1039,7 @@ static int parse_options (char *options, struct super_block *sb, | |||
966 | if (option < 0) | 1039 | if (option < 0) |
967 | return 0; | 1040 | return 0; |
968 | if (option == 0) | 1041 | if (option == 0) |
969 | option = JBD_DEFAULT_MAX_COMMIT_AGE; | 1042 | option = JBD2_DEFAULT_MAX_COMMIT_AGE; |
970 | sbi->s_commit_interval = HZ * option; | 1043 | sbi->s_commit_interval = HZ * option; |
971 | break; | 1044 | break; |
972 | case Opt_data_journal: | 1045 | case Opt_data_journal: |
@@ -1237,6 +1310,43 @@ static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es, | |||
1237 | return res; | 1310 | return res; |
1238 | } | 1311 | } |
1239 | 1312 | ||
1313 | __le16 ext4_group_desc_csum(struct ext4_sb_info *sbi, __u32 block_group, | ||
1314 | struct ext4_group_desc *gdp) | ||
1315 | { | ||
1316 | __u16 crc = 0; | ||
1317 | |||
1318 | if (sbi->s_es->s_feature_ro_compat & | ||
1319 | cpu_to_le32(EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) { | ||
1320 | int offset = offsetof(struct ext4_group_desc, bg_checksum); | ||
1321 | __le32 le_group = cpu_to_le32(block_group); | ||
1322 | |||
1323 | crc = crc16(~0, sbi->s_es->s_uuid, sizeof(sbi->s_es->s_uuid)); | ||
1324 | crc = crc16(crc, (__u8 *)&le_group, sizeof(le_group)); | ||
1325 | crc = crc16(crc, (__u8 *)gdp, offset); | ||
1326 | offset += sizeof(gdp->bg_checksum); /* skip checksum */ | ||
1327 | /* for checksum of struct ext4_group_desc do the rest...*/ | ||
1328 | if ((sbi->s_es->s_feature_incompat & | ||
1329 | cpu_to_le32(EXT4_FEATURE_INCOMPAT_64BIT)) && | ||
1330 | offset < le16_to_cpu(sbi->s_es->s_desc_size)) | ||
1331 | crc = crc16(crc, (__u8 *)gdp + offset, | ||
1332 | le16_to_cpu(sbi->s_es->s_desc_size) - | ||
1333 | offset); | ||
1334 | } | ||
1335 | |||
1336 | return cpu_to_le16(crc); | ||
1337 | } | ||
1338 | |||
1339 | int ext4_group_desc_csum_verify(struct ext4_sb_info *sbi, __u32 block_group, | ||
1340 | struct ext4_group_desc *gdp) | ||
1341 | { | ||
1342 | if ((sbi->s_es->s_feature_ro_compat & | ||
1343 | cpu_to_le32(EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) && | ||
1344 | (gdp->bg_checksum != ext4_group_desc_csum(sbi, block_group, gdp))) | ||
1345 | return 0; | ||
1346 | |||
1347 | return 1; | ||
1348 | } | ||
1349 | |||
1240 | /* Called at mount-time, super-block is locked */ | 1350 | /* Called at mount-time, super-block is locked */ |
1241 | static int ext4_check_descriptors (struct super_block * sb) | 1351 | static int ext4_check_descriptors (struct super_block * sb) |
1242 | { | 1352 | { |
@@ -1248,13 +1358,17 @@ static int ext4_check_descriptors (struct super_block * sb) | |||
1248 | ext4_fsblk_t inode_table; | 1358 | ext4_fsblk_t inode_table; |
1249 | struct ext4_group_desc * gdp = NULL; | 1359 | struct ext4_group_desc * gdp = NULL; |
1250 | int desc_block = 0; | 1360 | int desc_block = 0; |
1361 | int flexbg_flag = 0; | ||
1251 | int i; | 1362 | int i; |
1252 | 1363 | ||
1364 | if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG)) | ||
1365 | flexbg_flag = 1; | ||
1366 | |||
1253 | ext4_debug ("Checking group descriptors"); | 1367 | ext4_debug ("Checking group descriptors"); |
1254 | 1368 | ||
1255 | for (i = 0; i < sbi->s_groups_count; i++) | 1369 | for (i = 0; i < sbi->s_groups_count; i++) |
1256 | { | 1370 | { |
1257 | if (i == sbi->s_groups_count - 1) | 1371 | if (i == sbi->s_groups_count - 1 || flexbg_flag) |
1258 | last_block = ext4_blocks_count(sbi->s_es) - 1; | 1372 | last_block = ext4_blocks_count(sbi->s_es) - 1; |
1259 | else | 1373 | else |
1260 | last_block = first_block + | 1374 | last_block = first_block + |
@@ -1291,7 +1405,16 @@ static int ext4_check_descriptors (struct super_block * sb) | |||
1291 | i, inode_table); | 1405 | i, inode_table); |
1292 | return 0; | 1406 | return 0; |
1293 | } | 1407 | } |
1294 | first_block += EXT4_BLOCKS_PER_GROUP(sb); | 1408 | if (!ext4_group_desc_csum_verify(sbi, i, gdp)) { |
1409 | ext4_error(sb, __FUNCTION__, | ||
1410 | "Checksum for group %d failed (%u!=%u)\n", i, | ||
1411 | le16_to_cpu(ext4_group_desc_csum(sbi, i, | ||
1412 | gdp)), | ||
1413 | le16_to_cpu(gdp->bg_checksum)); | ||
1414 | return 0; | ||
1415 | } | ||
1416 | if (!flexbg_flag) | ||
1417 | first_block += EXT4_BLOCKS_PER_GROUP(sb); | ||
1295 | gdp = (struct ext4_group_desc *) | 1418 | gdp = (struct ext4_group_desc *) |
1296 | ((__u8 *)gdp + EXT4_DESC_SIZE(sb)); | 1419 | ((__u8 *)gdp + EXT4_DESC_SIZE(sb)); |
1297 | } | 1420 | } |
@@ -1415,8 +1538,6 @@ static void ext4_orphan_cleanup (struct super_block * sb, | |||
1415 | sb->s_flags = s_flags; /* Restore MS_RDONLY status */ | 1538 | sb->s_flags = s_flags; /* Restore MS_RDONLY status */ |
1416 | } | 1539 | } |
1417 | 1540 | ||
1418 | #define log2(n) ffz(~(n)) | ||
1419 | |||
1420 | /* | 1541 | /* |
1421 | * Maximal file size. There is a direct, and {,double-,triple-}indirect | 1542 | * Maximal file size. There is a direct, and {,double-,triple-}indirect |
1422 | * block limit, and also a limit of (2^32 - 1) 512-byte sectors in i_blocks. | 1543 | * block limit, and also a limit of (2^32 - 1) 512-byte sectors in i_blocks. |
@@ -1479,6 +1600,7 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent) | |||
1479 | int needs_recovery; | 1600 | int needs_recovery; |
1480 | __le32 features; | 1601 | __le32 features; |
1481 | __u64 blocks_count; | 1602 | __u64 blocks_count; |
1603 | int err; | ||
1482 | 1604 | ||
1483 | sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); | 1605 | sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); |
1484 | if (!sbi) | 1606 | if (!sbi) |
@@ -1487,6 +1609,7 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent) | |||
1487 | sbi->s_mount_opt = 0; | 1609 | sbi->s_mount_opt = 0; |
1488 | sbi->s_resuid = EXT4_DEF_RESUID; | 1610 | sbi->s_resuid = EXT4_DEF_RESUID; |
1489 | sbi->s_resgid = EXT4_DEF_RESGID; | 1611 | sbi->s_resgid = EXT4_DEF_RESGID; |
1612 | sbi->s_sb_block = sb_block; | ||
1490 | 1613 | ||
1491 | unlock_kernel(); | 1614 | unlock_kernel(); |
1492 | 1615 | ||
@@ -1655,19 +1778,11 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent) | |||
1655 | if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) | 1778 | if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) |
1656 | sb->s_time_gran = 1 << (EXT4_EPOCH_BITS - 2); | 1779 | sb->s_time_gran = 1 << (EXT4_EPOCH_BITS - 2); |
1657 | } | 1780 | } |
1658 | sbi->s_frag_size = EXT4_MIN_FRAG_SIZE << | ||
1659 | le32_to_cpu(es->s_log_frag_size); | ||
1660 | if (blocksize != sbi->s_frag_size) { | ||
1661 | printk(KERN_ERR | ||
1662 | "EXT4-fs: fragsize %lu != blocksize %u (unsupported)\n", | ||
1663 | sbi->s_frag_size, blocksize); | ||
1664 | goto failed_mount; | ||
1665 | } | ||
1666 | sbi->s_desc_size = le16_to_cpu(es->s_desc_size); | 1781 | sbi->s_desc_size = le16_to_cpu(es->s_desc_size); |
1667 | if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_64BIT)) { | 1782 | if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_64BIT)) { |
1668 | if (sbi->s_desc_size < EXT4_MIN_DESC_SIZE_64BIT || | 1783 | if (sbi->s_desc_size < EXT4_MIN_DESC_SIZE_64BIT || |
1669 | sbi->s_desc_size > EXT4_MAX_DESC_SIZE || | 1784 | sbi->s_desc_size > EXT4_MAX_DESC_SIZE || |
1670 | sbi->s_desc_size & (sbi->s_desc_size - 1)) { | 1785 | !is_power_of_2(sbi->s_desc_size)) { |
1671 | printk(KERN_ERR | 1786 | printk(KERN_ERR |
1672 | "EXT4-fs: unsupported descriptor size %lu\n", | 1787 | "EXT4-fs: unsupported descriptor size %lu\n", |
1673 | sbi->s_desc_size); | 1788 | sbi->s_desc_size); |
@@ -1676,7 +1791,6 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent) | |||
1676 | } else | 1791 | } else |
1677 | sbi->s_desc_size = EXT4_MIN_DESC_SIZE; | 1792 | sbi->s_desc_size = EXT4_MIN_DESC_SIZE; |
1678 | sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group); | 1793 | sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group); |
1679 | sbi->s_frags_per_group = le32_to_cpu(es->s_frags_per_group); | ||
1680 | sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group); | 1794 | sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group); |
1681 | if (EXT4_INODE_SIZE(sb) == 0) | 1795 | if (EXT4_INODE_SIZE(sb) == 0) |
1682 | goto cantfind_ext4; | 1796 | goto cantfind_ext4; |
@@ -1688,8 +1802,8 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent) | |||
1688 | sbi->s_desc_per_block = blocksize / EXT4_DESC_SIZE(sb); | 1802 | sbi->s_desc_per_block = blocksize / EXT4_DESC_SIZE(sb); |
1689 | sbi->s_sbh = bh; | 1803 | sbi->s_sbh = bh; |
1690 | sbi->s_mount_state = le16_to_cpu(es->s_state); | 1804 | sbi->s_mount_state = le16_to_cpu(es->s_state); |
1691 | sbi->s_addr_per_block_bits = log2(EXT4_ADDR_PER_BLOCK(sb)); | 1805 | sbi->s_addr_per_block_bits = ilog2(EXT4_ADDR_PER_BLOCK(sb)); |
1692 | sbi->s_desc_per_block_bits = log2(EXT4_DESC_PER_BLOCK(sb)); | 1806 | sbi->s_desc_per_block_bits = ilog2(EXT4_DESC_PER_BLOCK(sb)); |
1693 | for (i=0; i < 4; i++) | 1807 | for (i=0; i < 4; i++) |
1694 | sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]); | 1808 | sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]); |
1695 | sbi->s_def_hash_version = es->s_def_hash_version; | 1809 | sbi->s_def_hash_version = es->s_def_hash_version; |
@@ -1700,12 +1814,6 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent) | |||
1700 | sbi->s_blocks_per_group); | 1814 | sbi->s_blocks_per_group); |
1701 | goto failed_mount; | 1815 | goto failed_mount; |
1702 | } | 1816 | } |
1703 | if (sbi->s_frags_per_group > blocksize * 8) { | ||
1704 | printk (KERN_ERR | ||
1705 | "EXT4-fs: #fragments per group too big: %lu\n", | ||
1706 | sbi->s_frags_per_group); | ||
1707 | goto failed_mount; | ||
1708 | } | ||
1709 | if (sbi->s_inodes_per_group > blocksize * 8) { | 1817 | if (sbi->s_inodes_per_group > blocksize * 8) { |
1710 | printk (KERN_ERR | 1818 | printk (KERN_ERR |
1711 | "EXT4-fs: #inodes per group too big: %lu\n", | 1819 | "EXT4-fs: #inodes per group too big: %lu\n", |
@@ -1759,12 +1867,20 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent) | |||
1759 | get_random_bytes(&sbi->s_next_generation, sizeof(u32)); | 1867 | get_random_bytes(&sbi->s_next_generation, sizeof(u32)); |
1760 | spin_lock_init(&sbi->s_next_gen_lock); | 1868 | spin_lock_init(&sbi->s_next_gen_lock); |
1761 | 1869 | ||
1762 | percpu_counter_init(&sbi->s_freeblocks_counter, | 1870 | err = percpu_counter_init(&sbi->s_freeblocks_counter, |
1763 | ext4_count_free_blocks(sb)); | 1871 | ext4_count_free_blocks(sb)); |
1764 | percpu_counter_init(&sbi->s_freeinodes_counter, | 1872 | if (!err) { |
1765 | ext4_count_free_inodes(sb)); | 1873 | err = percpu_counter_init(&sbi->s_freeinodes_counter, |
1766 | percpu_counter_init(&sbi->s_dirs_counter, | 1874 | ext4_count_free_inodes(sb)); |
1767 | ext4_count_dirs(sb)); | 1875 | } |
1876 | if (!err) { | ||
1877 | err = percpu_counter_init(&sbi->s_dirs_counter, | ||
1878 | ext4_count_dirs(sb)); | ||
1879 | } | ||
1880 | if (err) { | ||
1881 | printk(KERN_ERR "EXT4-fs: insufficient memory\n"); | ||
1882 | goto failed_mount3; | ||
1883 | } | ||
1768 | 1884 | ||
1769 | /* per fileystem reservation list head & lock */ | 1885 | /* per fileystem reservation list head & lock */ |
1770 | spin_lock_init(&sbi->s_rsv_window_lock); | 1886 | spin_lock_init(&sbi->s_rsv_window_lock); |
@@ -2551,7 +2667,7 @@ static int ext4_statfs (struct dentry * dentry, struct kstatfs * buf) | |||
2551 | 2667 | ||
2552 | if (test_opt(sb, MINIX_DF)) { | 2668 | if (test_opt(sb, MINIX_DF)) { |
2553 | sbi->s_overhead_last = 0; | 2669 | sbi->s_overhead_last = 0; |
2554 | } else if (sbi->s_blocks_last != le32_to_cpu(es->s_blocks_count)) { | 2670 | } else if (sbi->s_blocks_last != ext4_blocks_count(es)) { |
2555 | unsigned long ngroups = sbi->s_groups_count, i; | 2671 | unsigned long ngroups = sbi->s_groups_count, i; |
2556 | ext4_fsblk_t overhead = 0; | 2672 | ext4_fsblk_t overhead = 0; |
2557 | smp_rmb(); | 2673 | smp_rmb(); |
@@ -2586,19 +2702,19 @@ static int ext4_statfs (struct dentry * dentry, struct kstatfs * buf) | |||
2586 | overhead += ngroups * (2 + sbi->s_itb_per_group); | 2702 | overhead += ngroups * (2 + sbi->s_itb_per_group); |
2587 | sbi->s_overhead_last = overhead; | 2703 | sbi->s_overhead_last = overhead; |
2588 | smp_wmb(); | 2704 | smp_wmb(); |
2589 | sbi->s_blocks_last = le32_to_cpu(es->s_blocks_count); | 2705 | sbi->s_blocks_last = ext4_blocks_count(es); |
2590 | } | 2706 | } |
2591 | 2707 | ||
2592 | buf->f_type = EXT4_SUPER_MAGIC; | 2708 | buf->f_type = EXT4_SUPER_MAGIC; |
2593 | buf->f_bsize = sb->s_blocksize; | 2709 | buf->f_bsize = sb->s_blocksize; |
2594 | buf->f_blocks = ext4_blocks_count(es) - sbi->s_overhead_last; | 2710 | buf->f_blocks = ext4_blocks_count(es) - sbi->s_overhead_last; |
2595 | buf->f_bfree = percpu_counter_sum(&sbi->s_freeblocks_counter); | 2711 | buf->f_bfree = percpu_counter_sum_positive(&sbi->s_freeblocks_counter); |
2596 | es->s_free_blocks_count = cpu_to_le32(buf->f_bfree); | 2712 | ext4_free_blocks_count_set(es, buf->f_bfree); |
2597 | buf->f_bavail = buf->f_bfree - ext4_r_blocks_count(es); | 2713 | buf->f_bavail = buf->f_bfree - ext4_r_blocks_count(es); |
2598 | if (buf->f_bfree < ext4_r_blocks_count(es)) | 2714 | if (buf->f_bfree < ext4_r_blocks_count(es)) |
2599 | buf->f_bavail = 0; | 2715 | buf->f_bavail = 0; |
2600 | buf->f_files = le32_to_cpu(es->s_inodes_count); | 2716 | buf->f_files = le32_to_cpu(es->s_inodes_count); |
2601 | buf->f_ffree = percpu_counter_sum(&sbi->s_freeinodes_counter); | 2717 | buf->f_ffree = percpu_counter_sum_positive(&sbi->s_freeinodes_counter); |
2602 | es->s_free_inodes_count = cpu_to_le32(buf->f_ffree); | 2718 | es->s_free_inodes_count = cpu_to_le32(buf->f_ffree); |
2603 | buf->f_namelen = EXT4_NAME_LEN; | 2719 | buf->f_namelen = EXT4_NAME_LEN; |
2604 | fsid = le64_to_cpup((void *)es->s_uuid) ^ | 2720 | fsid = le64_to_cpup((void *)es->s_uuid) ^ |
@@ -2698,8 +2814,11 @@ static int ext4_release_dquot(struct dquot *dquot) | |||
2698 | 2814 | ||
2699 | handle = ext4_journal_start(dquot_to_inode(dquot), | 2815 | handle = ext4_journal_start(dquot_to_inode(dquot), |
2700 | EXT4_QUOTA_DEL_BLOCKS(dquot->dq_sb)); | 2816 | EXT4_QUOTA_DEL_BLOCKS(dquot->dq_sb)); |
2701 | if (IS_ERR(handle)) | 2817 | if (IS_ERR(handle)) { |
2818 | /* Release dquot anyway to avoid endless cycle in dqput() */ | ||
2819 | dquot_release(dquot); | ||
2702 | return PTR_ERR(handle); | 2820 | return PTR_ERR(handle); |
2821 | } | ||
2703 | ret = dquot_release(dquot); | 2822 | ret = dquot_release(dquot); |
2704 | err = ext4_journal_stop(handle); | 2823 | err = ext4_journal_stop(handle); |
2705 | if (!ret) | 2824 | if (!ret) |
@@ -2832,6 +2951,12 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type, | |||
2832 | struct buffer_head *bh; | 2951 | struct buffer_head *bh; |
2833 | handle_t *handle = journal_current_handle(); | 2952 | handle_t *handle = journal_current_handle(); |
2834 | 2953 | ||
2954 | if (!handle) { | ||
2955 | printk(KERN_WARNING "EXT4-fs: Quota write (off=%Lu, len=%Lu)" | ||
2956 | " cancelled because transaction is not started.\n", | ||
2957 | (unsigned long long)off, (unsigned long long)len); | ||
2958 | return -EIO; | ||
2959 | } | ||
2835 | mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA); | 2960 | mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA); |
2836 | while (towrite > 0) { | 2961 | while (towrite > 0) { |
2837 | tocopy = sb->s_blocksize - offset < towrite ? | 2962 | tocopy = sb->s_blocksize - offset < towrite ? |