diff options
author | Yongqiang Yang <xiaoqiangnk@gmail.com> | 2012-01-03 23:37:31 -0500 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2012-01-03 23:37:31 -0500 |
commit | 083f5b24cc55448e0602a807a5c2872e1f3796e2 (patch) | |
tree | 43a6245a1eb674584c2573dce24290d84bae3eed /fs/ext4 | |
parent | 33afdcc5402d0abf70ef2dfb96d0b901d20bcc37 (diff) |
ext4: add a function which sets up a block group descriptors of a flex bg
This patch adds a function named ext4_setup_new_descs which sets up the
block group descriptors of a flex bg.
Signed-off-by: Yongqiang Yang <xiaoqiangnk@gmail.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'fs/ext4')
-rw-r--r-- | fs/ext4/resize.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c index e8ccb2f8f45..098bdb8e97c 100644 --- a/fs/ext4/resize.c +++ b/fs/ext4/resize.c | |||
@@ -1086,6 +1086,62 @@ static int ext4_add_new_descs(handle_t *handle, struct super_block *sb, | |||
1086 | return err; | 1086 | return err; |
1087 | } | 1087 | } |
1088 | 1088 | ||
1089 | /* | ||
1090 | * ext4_setup_new_descs() will set up the group descriptor descriptors of a flex bg | ||
1091 | */ | ||
1092 | static int ext4_setup_new_descs(handle_t *handle, struct super_block *sb, | ||
1093 | struct ext4_new_flex_group_data *flex_gd) | ||
1094 | { | ||
1095 | struct ext4_new_group_data *group_data = flex_gd->groups; | ||
1096 | struct ext4_group_desc *gdp; | ||
1097 | struct ext4_sb_info *sbi = EXT4_SB(sb); | ||
1098 | struct buffer_head *gdb_bh; | ||
1099 | ext4_group_t group; | ||
1100 | __u16 *bg_flags = flex_gd->bg_flags; | ||
1101 | int i, gdb_off, gdb_num, err = 0; | ||
1102 | |||
1103 | |||
1104 | for (i = 0; i < flex_gd->count; i++, group_data++, bg_flags++) { | ||
1105 | group = group_data->group; | ||
1106 | |||
1107 | gdb_off = group % EXT4_DESC_PER_BLOCK(sb); | ||
1108 | gdb_num = group / EXT4_DESC_PER_BLOCK(sb); | ||
1109 | |||
1110 | /* | ||
1111 | * get_write_access() has been called on gdb_bh by ext4_add_new_desc(). | ||
1112 | */ | ||
1113 | gdb_bh = sbi->s_group_desc[gdb_num]; | ||
1114 | /* Update group descriptor block for new group */ | ||
1115 | gdp = (struct ext4_group_desc *)((char *)gdb_bh->b_data + | ||
1116 | gdb_off * EXT4_DESC_SIZE(sb)); | ||
1117 | |||
1118 | memset(gdp, 0, EXT4_DESC_SIZE(sb)); | ||
1119 | ext4_block_bitmap_set(sb, gdp, group_data->block_bitmap); | ||
1120 | ext4_inode_bitmap_set(sb, gdp, group_data->inode_bitmap); | ||
1121 | ext4_inode_table_set(sb, gdp, group_data->inode_table); | ||
1122 | ext4_free_group_clusters_set(sb, gdp, | ||
1123 | EXT4_B2C(sbi, group_data->free_blocks_count)); | ||
1124 | ext4_free_inodes_set(sb, gdp, EXT4_INODES_PER_GROUP(sb)); | ||
1125 | gdp->bg_flags = cpu_to_le16(*bg_flags); | ||
1126 | gdp->bg_checksum = ext4_group_desc_csum(sbi, group, gdp); | ||
1127 | |||
1128 | err = ext4_handle_dirty_metadata(handle, NULL, gdb_bh); | ||
1129 | if (unlikely(err)) { | ||
1130 | ext4_std_error(sb, err); | ||
1131 | break; | ||
1132 | } | ||
1133 | |||
1134 | /* | ||
1135 | * We can allocate memory for mb_alloc based on the new group | ||
1136 | * descriptor | ||
1137 | */ | ||
1138 | err = ext4_mb_add_groupinfo(sb, group, gdp); | ||
1139 | if (err) | ||
1140 | break; | ||
1141 | } | ||
1142 | return err; | ||
1143 | } | ||
1144 | |||
1089 | /* Add group descriptor data to an existing or new group descriptor block. | 1145 | /* Add group descriptor data to an existing or new group descriptor block. |
1090 | * Ensure we handle all possible error conditions _before_ we start modifying | 1146 | * Ensure we handle all possible error conditions _before_ we start modifying |
1091 | * the filesystem, because we cannot abort the transaction and not have it | 1147 | * the filesystem, because we cannot abort the transaction and not have it |