resize.c (31881d74b6dd1a6c530cff61248def4f2da38bee) resize.c (6ca792edc13c409e8d4eb9001e048264c6a2eb64)
1/*
2 * linux/fs/ext4/resize.c
3 *
4 * Support for resizing an ext4 filesystem while it is mounted.
5 *
6 * Copyright (C) 2001, 2002 Andreas Dilger <adilger@clusterfs.com>
7 *
8 * This could probably be made into a module, because it is not often in use.

--- 65 unchanged lines hidden (view full) ---

74 struct ext4_new_group_data *input)
75{
76 struct ext4_sb_info *sbi = EXT4_SB(sb);
77 struct ext4_super_block *es = sbi->s_es;
78 ext4_fsblk_t start = ext4_blocks_count(es);
79 ext4_fsblk_t end = start + input->blocks_count;
80 ext4_group_t group = input->group;
81 ext4_fsblk_t itend = input->inode_table + sbi->s_itb_per_group;
1/*
2 * linux/fs/ext4/resize.c
3 *
4 * Support for resizing an ext4 filesystem while it is mounted.
5 *
6 * Copyright (C) 2001, 2002 Andreas Dilger <adilger@clusterfs.com>
7 *
8 * This could probably be made into a module, because it is not often in use.

--- 65 unchanged lines hidden (view full) ---

74 struct ext4_new_group_data *input)
75{
76 struct ext4_sb_info *sbi = EXT4_SB(sb);
77 struct ext4_super_block *es = sbi->s_es;
78 ext4_fsblk_t start = ext4_blocks_count(es);
79 ext4_fsblk_t end = start + input->blocks_count;
80 ext4_group_t group = input->group;
81 ext4_fsblk_t itend = input->inode_table + sbi->s_itb_per_group;
82 unsigned overhead = ext4_group_overhead_blocks(sb, group);
83 ext4_fsblk_t metaend = start + overhead;
82 unsigned overhead;
83 ext4_fsblk_t metaend;
84 struct buffer_head *bh = NULL;
85 ext4_grpblk_t free_blocks_count, offset;
86 int err = -EINVAL;
87
84 struct buffer_head *bh = NULL;
85 ext4_grpblk_t free_blocks_count, offset;
86 int err = -EINVAL;
87
88 if (group != sbi->s_groups_count) {
89 ext4_warning(sb, "Cannot add at group %u (only %u groups)",
90 input->group, sbi->s_groups_count);
91 return -EINVAL;
92 }
93
94 overhead = ext4_group_overhead_blocks(sb, group);
95 metaend = start + overhead;
88 input->free_blocks_count = free_blocks_count =
89 input->blocks_count - 2 - overhead - sbi->s_itb_per_group;
90
91 if (test_opt(sb, DEBUG))
92 printk(KERN_DEBUG "EXT4-fs: adding %s group %u: %u blocks "
93 "(%d free, %u reserved)\n",
94 ext4_bg_has_super(sb, input->group) ? "normal" :
95 "no-super", input->group, input->blocks_count,
96 free_blocks_count, input->reserved_blocks);
97
98 ext4_get_group_no_and_offset(sb, start, NULL, &offset);
96 input->free_blocks_count = free_blocks_count =
97 input->blocks_count - 2 - overhead - sbi->s_itb_per_group;
98
99 if (test_opt(sb, DEBUG))
100 printk(KERN_DEBUG "EXT4-fs: adding %s group %u: %u blocks "
101 "(%d free, %u reserved)\n",
102 ext4_bg_has_super(sb, input->group) ? "normal" :
103 "no-super", input->group, input->blocks_count,
104 free_blocks_count, input->reserved_blocks);
105
106 ext4_get_group_no_and_offset(sb, start, NULL, &offset);
99 if (group != sbi->s_groups_count)
100 ext4_warning(sb, "Cannot add at group %u (only %u groups)",
101 input->group, sbi->s_groups_count);
102 else if (offset != 0)
107 if (offset != 0)
103 ext4_warning(sb, "Last group not full");
104 else if (input->reserved_blocks > input->blocks_count / 5)
105 ext4_warning(sb, "Reserved blocks too high (%u)",
106 input->reserved_blocks);
107 else if (free_blocks_count < 0)
108 ext4_warning(sb, "Bad blocks count %u",
109 input->blocks_count);
110 else if (!(bh = sb_bread(sb, end - 1)))

--- 1435 unchanged lines hidden (view full) ---

1546int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input)
1547{
1548 struct ext4_new_flex_group_data flex_gd;
1549 struct ext4_sb_info *sbi = EXT4_SB(sb);
1550 struct ext4_super_block *es = sbi->s_es;
1551 int reserved_gdb = ext4_bg_has_super(sb, input->group) ?
1552 le16_to_cpu(es->s_reserved_gdt_blocks) : 0;
1553 struct inode *inode = NULL;
108 ext4_warning(sb, "Last group not full");
109 else if (input->reserved_blocks > input->blocks_count / 5)
110 ext4_warning(sb, "Reserved blocks too high (%u)",
111 input->reserved_blocks);
112 else if (free_blocks_count < 0)
113 ext4_warning(sb, "Bad blocks count %u",
114 input->blocks_count);
115 else if (!(bh = sb_bread(sb, end - 1)))

--- 1435 unchanged lines hidden (view full) ---

1551int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input)
1552{
1553 struct ext4_new_flex_group_data flex_gd;
1554 struct ext4_sb_info *sbi = EXT4_SB(sb);
1555 struct ext4_super_block *es = sbi->s_es;
1556 int reserved_gdb = ext4_bg_has_super(sb, input->group) ?
1557 le16_to_cpu(es->s_reserved_gdt_blocks) : 0;
1558 struct inode *inode = NULL;
1554 int gdb_off, gdb_num;
1559 int gdb_off;
1555 int err;
1556 __u16 bg_flags = 0;
1557
1560 int err;
1561 __u16 bg_flags = 0;
1562
1558 gdb_num = input->group / EXT4_DESC_PER_BLOCK(sb);
1559 gdb_off = input->group % EXT4_DESC_PER_BLOCK(sb);
1560
1561 if (gdb_off == 0 && !EXT4_HAS_RO_COMPAT_FEATURE(sb,
1562 EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER)) {
1563 ext4_warning(sb, "Can't resize non-sparse filesystem further");
1564 return -EPERM;
1565 }
1566

--- 84 unchanged lines hidden (view full) ---

1651 ext4_debug("freed blocks %llu through %llu\n", o_blocks_count,
1652 o_blocks_count + add);
1653errout:
1654 err2 = ext4_journal_stop(handle);
1655 if (err2 && !err)
1656 err = err2;
1657
1658 if (!err) {
1563 gdb_off = input->group % EXT4_DESC_PER_BLOCK(sb);
1564
1565 if (gdb_off == 0 && !EXT4_HAS_RO_COMPAT_FEATURE(sb,
1566 EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER)) {
1567 ext4_warning(sb, "Can't resize non-sparse filesystem further");
1568 return -EPERM;
1569 }
1570

--- 84 unchanged lines hidden (view full) ---

1655 ext4_debug("freed blocks %llu through %llu\n", o_blocks_count,
1656 o_blocks_count + add);
1657errout:
1658 err2 = ext4_journal_stop(handle);
1659 if (err2 && !err)
1660 err = err2;
1661
1662 if (!err) {
1659 ext4_fsblk_t first_block;
1660 first_block = ext4_group_first_block_no(sb, 0);
1661 if (test_opt(sb, DEBUG))
1662 printk(KERN_DEBUG "EXT4-fs: extended group to %llu "
1663 "blocks\n", ext4_blocks_count(es));
1663 if (test_opt(sb, DEBUG))
1664 printk(KERN_DEBUG "EXT4-fs: extended group to %llu "
1665 "blocks\n", ext4_blocks_count(es));
1664 update_backups(sb, EXT4_SB(sb)->s_sbh->b_blocknr - first_block,
1666 update_backups(sb, EXT4_SB(sb)->s_sbh->b_blocknr,
1665 (char *)es, sizeof(struct ext4_super_block), 0);
1666 }
1667 return err;
1668}
1669
1670/*
1671 * Extend the filesystem to the new number of blocks specified. This entry
1672 * point is only used to extend the current filesystem to the end of the last

--- 325 unchanged lines hidden ---
1667 (char *)es, sizeof(struct ext4_super_block), 0);
1668 }
1669 return err;
1670}
1671
1672/*
1673 * Extend the filesystem to the new number of blocks specified. This entry
1674 * point is only used to extend the current filesystem to the end of the last

--- 325 unchanged lines hidden ---