Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/ext3/resize.c |
| 3 | * |
| 4 | * Support for resizing an ext3 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. |
| 9 | */ |
| 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
| 12 | #define EXT3FS_DEBUG |
| 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/ext3_jbd.h> |
| 15 | |
| 16 | #include <linux/errno.h> |
| 17 | #include <linux/slab.h> |
| 18 | |
| 19 | |
| 20 | #define outside(b, first, last) ((b) < (first) || (b) >= (last)) |
| 21 | #define inside(b, first, last) ((b) >= (first) && (b) < (last)) |
| 22 | |
| 23 | static int verify_group_input(struct super_block *sb, |
| 24 | struct ext3_new_group_data *input) |
| 25 | { |
| 26 | struct ext3_sb_info *sbi = EXT3_SB(sb); |
| 27 | struct ext3_super_block *es = sbi->s_es; |
Mingming Cao | 1c2bf37 | 2006-06-25 05:48:06 -0700 | [diff] [blame] | 28 | ext3_fsblk_t start = le32_to_cpu(es->s_blocks_count); |
| 29 | ext3_fsblk_t end = start + input->blocks_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | unsigned group = input->group; |
Mingming Cao | 1c2bf37 | 2006-06-25 05:48:06 -0700 | [diff] [blame] | 31 | ext3_fsblk_t itend = input->inode_table + sbi->s_itb_per_group; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | unsigned overhead = ext3_bg_has_super(sb, group) ? |
| 33 | (1 + ext3_bg_num_gdb(sb, group) + |
| 34 | le16_to_cpu(es->s_reserved_gdt_blocks)) : 0; |
Mingming Cao | 1c2bf37 | 2006-06-25 05:48:06 -0700 | [diff] [blame] | 35 | ext3_fsblk_t metaend = start + overhead; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | struct buffer_head *bh = NULL; |
Mingming Cao | 1c2bf37 | 2006-06-25 05:48:06 -0700 | [diff] [blame] | 37 | ext3_grpblk_t free_blocks_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | int err = -EINVAL; |
| 39 | |
| 40 | input->free_blocks_count = free_blocks_count = |
| 41 | input->blocks_count - 2 - overhead - sbi->s_itb_per_group; |
| 42 | |
| 43 | if (test_opt(sb, DEBUG)) |
| 44 | printk(KERN_DEBUG "EXT3-fs: adding %s group %u: %u blocks " |
| 45 | "(%d free, %u reserved)\n", |
| 46 | ext3_bg_has_super(sb, input->group) ? "normal" : |
| 47 | "no-super", input->group, input->blocks_count, |
| 48 | free_blocks_count, input->reserved_blocks); |
| 49 | |
| 50 | if (group != sbi->s_groups_count) |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 51 | ext3_warning(sb, __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | "Cannot add at group %u (only %lu groups)", |
| 53 | input->group, sbi->s_groups_count); |
| 54 | else if ((start - le32_to_cpu(es->s_first_data_block)) % |
| 55 | EXT3_BLOCKS_PER_GROUP(sb)) |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 56 | ext3_warning(sb, __func__, "Last group not full"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | else if (input->reserved_blocks > input->blocks_count / 5) |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 58 | ext3_warning(sb, __func__, "Reserved blocks too high (%u)", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | input->reserved_blocks); |
| 60 | else if (free_blocks_count < 0) |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 61 | ext3_warning(sb, __func__, "Bad blocks count %u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | input->blocks_count); |
| 63 | else if (!(bh = sb_bread(sb, end - 1))) |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 64 | ext3_warning(sb, __func__, |
Mingming Cao | 1c2bf37 | 2006-06-25 05:48:06 -0700 | [diff] [blame] | 65 | "Cannot read last block ("E3FSBLK")", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | end - 1); |
| 67 | else if (outside(input->block_bitmap, start, end)) |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 68 | ext3_warning(sb, __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | "Block bitmap not in group (block %u)", |
| 70 | input->block_bitmap); |
| 71 | else if (outside(input->inode_bitmap, start, end)) |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 72 | ext3_warning(sb, __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | "Inode bitmap not in group (block %u)", |
| 74 | input->inode_bitmap); |
| 75 | else if (outside(input->inode_table, start, end) || |
| 76 | outside(itend - 1, start, end)) |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 77 | ext3_warning(sb, __func__, |
Mingming Cao | 1c2bf37 | 2006-06-25 05:48:06 -0700 | [diff] [blame] | 78 | "Inode table not in group (blocks %u-"E3FSBLK")", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | input->inode_table, itend - 1); |
| 80 | else if (input->inode_bitmap == input->block_bitmap) |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 81 | ext3_warning(sb, __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | "Block bitmap same as inode bitmap (%u)", |
| 83 | input->block_bitmap); |
| 84 | else if (inside(input->block_bitmap, input->inode_table, itend)) |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 85 | ext3_warning(sb, __func__, |
Mingming Cao | 1c2bf37 | 2006-06-25 05:48:06 -0700 | [diff] [blame] | 86 | "Block bitmap (%u) in inode table (%u-"E3FSBLK")", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | input->block_bitmap, input->inode_table, itend-1); |
| 88 | else if (inside(input->inode_bitmap, input->inode_table, itend)) |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 89 | ext3_warning(sb, __func__, |
Mingming Cao | 1c2bf37 | 2006-06-25 05:48:06 -0700 | [diff] [blame] | 90 | "Inode bitmap (%u) in inode table (%u-"E3FSBLK")", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | input->inode_bitmap, input->inode_table, itend-1); |
| 92 | else if (inside(input->block_bitmap, start, metaend)) |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 93 | ext3_warning(sb, __func__, |
Mingming Cao | 1c2bf37 | 2006-06-25 05:48:06 -0700 | [diff] [blame] | 94 | "Block bitmap (%u) in GDT table" |
| 95 | " ("E3FSBLK"-"E3FSBLK")", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | input->block_bitmap, start, metaend - 1); |
| 97 | else if (inside(input->inode_bitmap, start, metaend)) |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 98 | ext3_warning(sb, __func__, |
Mingming Cao | 1c2bf37 | 2006-06-25 05:48:06 -0700 | [diff] [blame] | 99 | "Inode bitmap (%u) in GDT table" |
| 100 | " ("E3FSBLK"-"E3FSBLK")", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | input->inode_bitmap, start, metaend - 1); |
| 102 | else if (inside(input->inode_table, start, metaend) || |
| 103 | inside(itend - 1, start, metaend)) |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 104 | ext3_warning(sb, __func__, |
Mingming Cao | 1c2bf37 | 2006-06-25 05:48:06 -0700 | [diff] [blame] | 105 | "Inode table (%u-"E3FSBLK") overlaps" |
| 106 | "GDT table ("E3FSBLK"-"E3FSBLK")", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | input->inode_table, itend - 1, start, metaend - 1); |
| 108 | else |
| 109 | err = 0; |
| 110 | brelse(bh); |
| 111 | |
| 112 | return err; |
| 113 | } |
| 114 | |
| 115 | static struct buffer_head *bclean(handle_t *handle, struct super_block *sb, |
Mingming Cao | 43d23f9 | 2006-06-25 05:48:07 -0700 | [diff] [blame] | 116 | ext3_fsblk_t blk) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | { |
| 118 | struct buffer_head *bh; |
| 119 | int err; |
| 120 | |
| 121 | bh = sb_getblk(sb, blk); |
Glauber de Oliveira Costa | 2973dfd | 2005-10-30 15:03:05 -0800 | [diff] [blame] | 122 | if (!bh) |
| 123 | return ERR_PTR(-EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | if ((err = ext3_journal_get_write_access(handle, bh))) { |
| 125 | brelse(bh); |
| 126 | bh = ERR_PTR(err); |
| 127 | } else { |
| 128 | lock_buffer(bh); |
| 129 | memset(bh->b_data, 0, sb->s_blocksize); |
| 130 | set_buffer_uptodate(bh); |
| 131 | unlock_buffer(bh); |
| 132 | } |
| 133 | |
| 134 | return bh; |
| 135 | } |
| 136 | |
| 137 | /* |
| 138 | * To avoid calling the atomic setbit hundreds or thousands of times, we only |
| 139 | * need to use it within a single byte (to ensure we get endianness right). |
| 140 | * We can use memset for the rest of the bitmap as there are no other users. |
| 141 | */ |
| 142 | static void mark_bitmap_end(int start_bit, int end_bit, char *bitmap) |
| 143 | { |
| 144 | int i; |
| 145 | |
| 146 | if (start_bit >= end_bit) |
| 147 | return; |
| 148 | |
| 149 | ext3_debug("mark end bits +%d through +%d used\n", start_bit, end_bit); |
| 150 | for (i = start_bit; i < ((start_bit + 7) & ~7UL); i++) |
| 151 | ext3_set_bit(i, bitmap); |
| 152 | if (i < end_bit) |
| 153 | memset(bitmap + (i >> 3), 0xff, (end_bit - i) >> 3); |
| 154 | } |
| 155 | |
| 156 | /* |
Eric Sandeen | 1ad6ecf | 2007-10-16 23:30:28 -0700 | [diff] [blame] | 157 | * If we have fewer than thresh credits, extend by EXT3_MAX_TRANS_DATA. |
| 158 | * If that fails, restart the transaction & regain write access for the |
| 159 | * buffer head which is used for block_bitmap modifications. |
| 160 | */ |
| 161 | static int extend_or_restart_transaction(handle_t *handle, int thresh, |
| 162 | struct buffer_head *bh) |
| 163 | { |
| 164 | int err; |
| 165 | |
| 166 | if (handle->h_buffer_credits >= thresh) |
| 167 | return 0; |
| 168 | |
| 169 | err = ext3_journal_extend(handle, EXT3_MAX_TRANS_DATA); |
| 170 | if (err < 0) |
| 171 | return err; |
| 172 | if (err) { |
| 173 | err = ext3_journal_restart(handle, EXT3_MAX_TRANS_DATA); |
| 174 | if (err) |
| 175 | return err; |
| 176 | err = ext3_journal_get_write_access(handle, bh); |
| 177 | if (err) |
| 178 | return err; |
| 179 | } |
| 180 | |
| 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | * Set up the block and inode bitmaps, and the inode table for the new group. |
| 186 | * This doesn't need to be part of the main transaction, since we are only |
| 187 | * changing blocks outside the actual filesystem. We still do journaling to |
| 188 | * ensure the recovery is correct in case of a failure just after resize. |
| 189 | * If any part of this fails, we simply abort the resize. |
| 190 | */ |
| 191 | static int setup_new_group_blocks(struct super_block *sb, |
| 192 | struct ext3_new_group_data *input) |
| 193 | { |
| 194 | struct ext3_sb_info *sbi = EXT3_SB(sb); |
Mingming Cao | 43d23f9 | 2006-06-25 05:48:07 -0700 | [diff] [blame] | 195 | ext3_fsblk_t start = ext3_group_first_block_no(sb, input->group); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | int reserved_gdb = ext3_bg_has_super(sb, input->group) ? |
| 197 | le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) : 0; |
| 198 | unsigned long gdblocks = ext3_bg_num_gdb(sb, input->group); |
| 199 | struct buffer_head *bh; |
| 200 | handle_t *handle; |
Mingming Cao | 43d23f9 | 2006-06-25 05:48:07 -0700 | [diff] [blame] | 201 | ext3_fsblk_t block; |
Mingming Cao | 1c2bf37 | 2006-06-25 05:48:06 -0700 | [diff] [blame] | 202 | ext3_grpblk_t bit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | int i; |
| 204 | int err = 0, err2; |
| 205 | |
Eric Sandeen | 1ad6ecf | 2007-10-16 23:30:28 -0700 | [diff] [blame] | 206 | /* This transaction may be extended/restarted along the way */ |
| 207 | handle = ext3_journal_start_sb(sb, EXT3_MAX_TRANS_DATA); |
| 208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | if (IS_ERR(handle)) |
| 210 | return PTR_ERR(handle); |
| 211 | |
| 212 | lock_super(sb); |
| 213 | if (input->group != sbi->s_groups_count) { |
| 214 | err = -EBUSY; |
| 215 | goto exit_journal; |
| 216 | } |
| 217 | |
| 218 | if (IS_ERR(bh = bclean(handle, sb, input->block_bitmap))) { |
| 219 | err = PTR_ERR(bh); |
| 220 | goto exit_journal; |
| 221 | } |
| 222 | |
| 223 | if (ext3_bg_has_super(sb, input->group)) { |
| 224 | ext3_debug("mark backup superblock %#04lx (+0)\n", start); |
| 225 | ext3_set_bit(0, bh->b_data); |
| 226 | } |
| 227 | |
| 228 | /* Copy all of the GDT blocks into the backup in this group */ |
| 229 | for (i = 0, bit = 1, block = start + 1; |
| 230 | i < gdblocks; i++, block++, bit++) { |
| 231 | struct buffer_head *gdb; |
| 232 | |
| 233 | ext3_debug("update backup group %#04lx (+%d)\n", block, bit); |
| 234 | |
Eric Sandeen | 1ad6ecf | 2007-10-16 23:30:28 -0700 | [diff] [blame] | 235 | err = extend_or_restart_transaction(handle, 1, bh); |
| 236 | if (err) |
| 237 | goto exit_bh; |
| 238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | gdb = sb_getblk(sb, block); |
Glauber de Oliveira Costa | 2973dfd | 2005-10-30 15:03:05 -0800 | [diff] [blame] | 240 | if (!gdb) { |
| 241 | err = -EIO; |
| 242 | goto exit_bh; |
| 243 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | if ((err = ext3_journal_get_write_access(handle, gdb))) { |
| 245 | brelse(gdb); |
| 246 | goto exit_bh; |
| 247 | } |
Eric Sandeen | 42a2b6a | 2007-10-18 03:06:57 -0700 | [diff] [blame] | 248 | lock_buffer(gdb); |
| 249 | memcpy(gdb->b_data, sbi->s_group_desc[i]->b_data, gdb->b_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | set_buffer_uptodate(gdb); |
Eric Sandeen | 42a2b6a | 2007-10-18 03:06:57 -0700 | [diff] [blame] | 251 | unlock_buffer(gdb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | ext3_journal_dirty_metadata(handle, gdb); |
| 253 | ext3_set_bit(bit, bh->b_data); |
| 254 | brelse(gdb); |
| 255 | } |
| 256 | |
| 257 | /* Zero out all of the reserved backup group descriptor table blocks */ |
| 258 | for (i = 0, bit = gdblocks + 1, block = start + bit; |
| 259 | i < reserved_gdb; i++, block++, bit++) { |
| 260 | struct buffer_head *gdb; |
| 261 | |
| 262 | ext3_debug("clear reserved block %#04lx (+%d)\n", block, bit); |
| 263 | |
Eric Sandeen | 1ad6ecf | 2007-10-16 23:30:28 -0700 | [diff] [blame] | 264 | err = extend_or_restart_transaction(handle, 1, bh); |
| 265 | if (err) |
| 266 | goto exit_bh; |
| 267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | if (IS_ERR(gdb = bclean(handle, sb, block))) { |
| 269 | err = PTR_ERR(bh); |
| 270 | goto exit_bh; |
| 271 | } |
| 272 | ext3_journal_dirty_metadata(handle, gdb); |
| 273 | ext3_set_bit(bit, bh->b_data); |
| 274 | brelse(gdb); |
| 275 | } |
| 276 | ext3_debug("mark block bitmap %#04x (+%ld)\n", input->block_bitmap, |
| 277 | input->block_bitmap - start); |
| 278 | ext3_set_bit(input->block_bitmap - start, bh->b_data); |
| 279 | ext3_debug("mark inode bitmap %#04x (+%ld)\n", input->inode_bitmap, |
| 280 | input->inode_bitmap - start); |
| 281 | ext3_set_bit(input->inode_bitmap - start, bh->b_data); |
| 282 | |
| 283 | /* Zero out all of the inode table blocks */ |
| 284 | for (i = 0, block = input->inode_table, bit = block - start; |
| 285 | i < sbi->s_itb_per_group; i++, bit++, block++) { |
| 286 | struct buffer_head *it; |
| 287 | |
Glauber de Oliveira Costa | 8bdac5d | 2005-09-22 21:44:26 -0700 | [diff] [blame] | 288 | ext3_debug("clear inode block %#04lx (+%d)\n", block, bit); |
Eric Sandeen | 1ad6ecf | 2007-10-16 23:30:28 -0700 | [diff] [blame] | 289 | |
| 290 | err = extend_or_restart_transaction(handle, 1, bh); |
| 291 | if (err) |
| 292 | goto exit_bh; |
| 293 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | if (IS_ERR(it = bclean(handle, sb, block))) { |
| 295 | err = PTR_ERR(it); |
| 296 | goto exit_bh; |
| 297 | } |
| 298 | ext3_journal_dirty_metadata(handle, it); |
| 299 | brelse(it); |
| 300 | ext3_set_bit(bit, bh->b_data); |
| 301 | } |
Eric Sandeen | 1ad6ecf | 2007-10-16 23:30:28 -0700 | [diff] [blame] | 302 | |
| 303 | err = extend_or_restart_transaction(handle, 2, bh); |
| 304 | if (err) |
| 305 | goto exit_bh; |
| 306 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | mark_bitmap_end(input->blocks_count, EXT3_BLOCKS_PER_GROUP(sb), |
| 308 | bh->b_data); |
| 309 | ext3_journal_dirty_metadata(handle, bh); |
| 310 | brelse(bh); |
| 311 | |
| 312 | /* Mark unused entries in inode bitmap used */ |
| 313 | ext3_debug("clear inode bitmap %#04x (+%ld)\n", |
| 314 | input->inode_bitmap, input->inode_bitmap - start); |
| 315 | if (IS_ERR(bh = bclean(handle, sb, input->inode_bitmap))) { |
| 316 | err = PTR_ERR(bh); |
| 317 | goto exit_journal; |
| 318 | } |
| 319 | |
| 320 | mark_bitmap_end(EXT3_INODES_PER_GROUP(sb), EXT3_BLOCKS_PER_GROUP(sb), |
| 321 | bh->b_data); |
| 322 | ext3_journal_dirty_metadata(handle, bh); |
| 323 | exit_bh: |
| 324 | brelse(bh); |
| 325 | |
| 326 | exit_journal: |
| 327 | unlock_super(sb); |
| 328 | if ((err2 = ext3_journal_stop(handle)) && !err) |
| 329 | err = err2; |
| 330 | |
| 331 | return err; |
| 332 | } |
| 333 | |
| 334 | /* |
| 335 | * Iterate through the groups which hold BACKUP superblock/GDT copies in an |
| 336 | * ext3 filesystem. The counters should be initialized to 1, 5, and 7 before |
| 337 | * calling this for the first time. In a sparse filesystem it will be the |
| 338 | * sequence of powers of 3, 5, and 7: 1, 3, 5, 7, 9, 25, 27, 49, 81, ... |
| 339 | * For a non-sparse filesystem it will be every group: 1, 2, 3, 4, ... |
| 340 | */ |
| 341 | static unsigned ext3_list_backups(struct super_block *sb, unsigned *three, |
| 342 | unsigned *five, unsigned *seven) |
| 343 | { |
| 344 | unsigned *min = three; |
| 345 | int mult = 3; |
| 346 | unsigned ret; |
| 347 | |
| 348 | if (!EXT3_HAS_RO_COMPAT_FEATURE(sb, |
| 349 | EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER)) { |
| 350 | ret = *min; |
| 351 | *min += 1; |
| 352 | return ret; |
| 353 | } |
| 354 | |
| 355 | if (*five < *min) { |
| 356 | min = five; |
| 357 | mult = 5; |
| 358 | } |
| 359 | if (*seven < *min) { |
| 360 | min = seven; |
| 361 | mult = 7; |
| 362 | } |
| 363 | |
| 364 | ret = *min; |
| 365 | *min *= mult; |
| 366 | |
| 367 | return ret; |
| 368 | } |
| 369 | |
| 370 | /* |
| 371 | * Check that all of the backup GDT blocks are held in the primary GDT block. |
| 372 | * It is assumed that they are stored in group order. Returns the number of |
| 373 | * groups in current filesystem that have BACKUPS, or -ve error code. |
| 374 | */ |
| 375 | static int verify_reserved_gdb(struct super_block *sb, |
| 376 | struct buffer_head *primary) |
| 377 | { |
Mingming Cao | 43d23f9 | 2006-06-25 05:48:07 -0700 | [diff] [blame] | 378 | const ext3_fsblk_t blk = primary->b_blocknr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | const unsigned long end = EXT3_SB(sb)->s_groups_count; |
| 380 | unsigned three = 1; |
| 381 | unsigned five = 5; |
| 382 | unsigned seven = 7; |
| 383 | unsigned grp; |
Dave Kleikamp | a4e4de3 | 2006-09-27 01:49:36 -0700 | [diff] [blame] | 384 | __le32 *p = (__le32 *)primary->b_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | int gdbackups = 0; |
| 386 | |
| 387 | while ((grp = ext3_list_backups(sb, &three, &five, &seven)) < end) { |
| 388 | if (le32_to_cpu(*p++) != grp * EXT3_BLOCKS_PER_GROUP(sb) + blk){ |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 389 | ext3_warning(sb, __func__, |
Mingming Cao | 43d23f9 | 2006-06-25 05:48:07 -0700 | [diff] [blame] | 390 | "reserved GDT "E3FSBLK |
| 391 | " missing grp %d ("E3FSBLK")", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | blk, grp, |
| 393 | grp * EXT3_BLOCKS_PER_GROUP(sb) + blk); |
| 394 | return -EINVAL; |
| 395 | } |
| 396 | if (++gdbackups > EXT3_ADDR_PER_BLOCK(sb)) |
| 397 | return -EFBIG; |
| 398 | } |
| 399 | |
| 400 | return gdbackups; |
| 401 | } |
| 402 | |
| 403 | /* |
| 404 | * Called when we need to bring a reserved group descriptor table block into |
| 405 | * use from the resize inode. The primary copy of the new GDT block currently |
| 406 | * is an indirect block (under the double indirect block in the resize inode). |
| 407 | * The new backup GDT blocks will be stored as leaf blocks in this indirect |
| 408 | * block, in group order. Even though we know all the block numbers we need, |
| 409 | * we check to ensure that the resize inode has actually reserved these blocks. |
| 410 | * |
| 411 | * Don't need to update the block bitmaps because the blocks are still in use. |
| 412 | * |
| 413 | * We get all of the error cases out of the way, so that we are sure to not |
| 414 | * fail once we start modifying the data on disk, because JBD has no rollback. |
| 415 | */ |
| 416 | static int add_new_gdb(handle_t *handle, struct inode *inode, |
| 417 | struct ext3_new_group_data *input, |
| 418 | struct buffer_head **primary) |
| 419 | { |
| 420 | struct super_block *sb = inode->i_sb; |
| 421 | struct ext3_super_block *es = EXT3_SB(sb)->s_es; |
| 422 | unsigned long gdb_num = input->group / EXT3_DESC_PER_BLOCK(sb); |
Mingming Cao | 43d23f9 | 2006-06-25 05:48:07 -0700 | [diff] [blame] | 423 | ext3_fsblk_t gdblock = EXT3_SB(sb)->s_sbh->b_blocknr + 1 + gdb_num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | struct buffer_head **o_group_desc, **n_group_desc; |
| 425 | struct buffer_head *dind; |
| 426 | int gdbackups; |
| 427 | struct ext3_iloc iloc; |
Dave Kleikamp | a4e4de3 | 2006-09-27 01:49:36 -0700 | [diff] [blame] | 428 | __le32 *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | int err; |
| 430 | |
| 431 | if (test_opt(sb, DEBUG)) |
| 432 | printk(KERN_DEBUG |
| 433 | "EXT3-fs: ext3_add_new_gdb: adding group block %lu\n", |
| 434 | gdb_num); |
| 435 | |
| 436 | /* |
| 437 | * If we are not using the primary superblock/GDT copy don't resize, |
| 438 | * because the user tools have no way of handling this. Probably a |
| 439 | * bad time to do it anyways. |
| 440 | */ |
| 441 | if (EXT3_SB(sb)->s_sbh->b_blocknr != |
| 442 | le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block)) { |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 443 | ext3_warning(sb, __func__, |
Glauber de Oliveira Costa | 9f40668 | 2006-01-08 01:03:22 -0800 | [diff] [blame] | 444 | "won't resize using backup superblock at %llu", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | (unsigned long long)EXT3_SB(sb)->s_sbh->b_blocknr); |
| 446 | return -EPERM; |
| 447 | } |
| 448 | |
| 449 | *primary = sb_bread(sb, gdblock); |
| 450 | if (!*primary) |
| 451 | return -EIO; |
| 452 | |
| 453 | if ((gdbackups = verify_reserved_gdb(sb, *primary)) < 0) { |
| 454 | err = gdbackups; |
| 455 | goto exit_bh; |
| 456 | } |
| 457 | |
| 458 | data = EXT3_I(inode)->i_data + EXT3_DIND_BLOCK; |
| 459 | dind = sb_bread(sb, le32_to_cpu(*data)); |
| 460 | if (!dind) { |
| 461 | err = -EIO; |
| 462 | goto exit_bh; |
| 463 | } |
| 464 | |
Dave Kleikamp | a4e4de3 | 2006-09-27 01:49:36 -0700 | [diff] [blame] | 465 | data = (__le32 *)dind->b_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | if (le32_to_cpu(data[gdb_num % EXT3_ADDR_PER_BLOCK(sb)]) != gdblock) { |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 467 | ext3_warning(sb, __func__, |
Mingming Cao | 43d23f9 | 2006-06-25 05:48:07 -0700 | [diff] [blame] | 468 | "new group %u GDT block "E3FSBLK" not reserved", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | input->group, gdblock); |
| 470 | err = -EINVAL; |
| 471 | goto exit_dind; |
| 472 | } |
| 473 | |
| 474 | if ((err = ext3_journal_get_write_access(handle, EXT3_SB(sb)->s_sbh))) |
| 475 | goto exit_dind; |
| 476 | |
| 477 | if ((err = ext3_journal_get_write_access(handle, *primary))) |
| 478 | goto exit_sbh; |
| 479 | |
| 480 | if ((err = ext3_journal_get_write_access(handle, dind))) |
| 481 | goto exit_primary; |
| 482 | |
| 483 | /* ext3_reserve_inode_write() gets a reference on the iloc */ |
| 484 | if ((err = ext3_reserve_inode_write(handle, inode, &iloc))) |
| 485 | goto exit_dindj; |
| 486 | |
Panagiotis Issaris | f52720c | 2006-09-27 01:49:39 -0700 | [diff] [blame] | 487 | n_group_desc = kmalloc((gdb_num + 1) * sizeof(struct buffer_head *), |
Josef Bacik | c587f0c | 2008-03-19 17:00:49 -0700 | [diff] [blame] | 488 | GFP_NOFS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | if (!n_group_desc) { |
| 490 | err = -ENOMEM; |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 491 | ext3_warning (sb, __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | "not enough memory for %lu groups", gdb_num + 1); |
| 493 | goto exit_inode; |
| 494 | } |
| 495 | |
| 496 | /* |
| 497 | * Finally, we have all of the possible failures behind us... |
| 498 | * |
| 499 | * Remove new GDT block from inode double-indirect block and clear out |
| 500 | * the new GDT block for use (which also "frees" the backup GDT blocks |
| 501 | * from the reserved inode). We don't need to change the bitmaps for |
| 502 | * these blocks, because they are marked as in-use from being in the |
| 503 | * reserved inode, and will become GDT blocks (primary and backup). |
| 504 | */ |
| 505 | data[gdb_num % EXT3_ADDR_PER_BLOCK(sb)] = 0; |
| 506 | ext3_journal_dirty_metadata(handle, dind); |
| 507 | brelse(dind); |
| 508 | inode->i_blocks -= (gdbackups + 1) * sb->s_blocksize >> 9; |
| 509 | ext3_mark_iloc_dirty(handle, inode, &iloc); |
| 510 | memset((*primary)->b_data, 0, sb->s_blocksize); |
| 511 | ext3_journal_dirty_metadata(handle, *primary); |
| 512 | |
| 513 | o_group_desc = EXT3_SB(sb)->s_group_desc; |
| 514 | memcpy(n_group_desc, o_group_desc, |
| 515 | EXT3_SB(sb)->s_gdb_count * sizeof(struct buffer_head *)); |
| 516 | n_group_desc[gdb_num] = *primary; |
| 517 | EXT3_SB(sb)->s_group_desc = n_group_desc; |
| 518 | EXT3_SB(sb)->s_gdb_count++; |
| 519 | kfree(o_group_desc); |
| 520 | |
Marcin Slusarz | 50e8a28 | 2008-02-08 04:20:13 -0800 | [diff] [blame] | 521 | le16_add_cpu(&es->s_reserved_gdt_blocks, -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh); |
| 523 | |
| 524 | return 0; |
| 525 | |
| 526 | exit_inode: |
| 527 | //ext3_journal_release_buffer(handle, iloc.bh); |
| 528 | brelse(iloc.bh); |
| 529 | exit_dindj: |
| 530 | //ext3_journal_release_buffer(handle, dind); |
| 531 | exit_primary: |
| 532 | //ext3_journal_release_buffer(handle, *primary); |
| 533 | exit_sbh: |
| 534 | //ext3_journal_release_buffer(handle, *primary); |
| 535 | exit_dind: |
| 536 | brelse(dind); |
| 537 | exit_bh: |
| 538 | brelse(*primary); |
| 539 | |
| 540 | ext3_debug("leaving with error %d\n", err); |
| 541 | return err; |
| 542 | } |
| 543 | |
| 544 | /* |
| 545 | * Called when we are adding a new group which has a backup copy of each of |
| 546 | * the GDT blocks (i.e. sparse group) and there are reserved GDT blocks. |
| 547 | * We need to add these reserved backup GDT blocks to the resize inode, so |
| 548 | * that they are kept for future resizing and not allocated to files. |
| 549 | * |
| 550 | * Each reserved backup GDT block will go into a different indirect block. |
| 551 | * The indirect blocks are actually the primary reserved GDT blocks, |
| 552 | * so we know in advance what their block numbers are. We only get the |
| 553 | * double-indirect block to verify it is pointing to the primary reserved |
| 554 | * GDT blocks so we don't overwrite a data block by accident. The reserved |
| 555 | * backup GDT blocks are stored in their reserved primary GDT block. |
| 556 | */ |
| 557 | static int reserve_backup_gdb(handle_t *handle, struct inode *inode, |
| 558 | struct ext3_new_group_data *input) |
| 559 | { |
| 560 | struct super_block *sb = inode->i_sb; |
| 561 | int reserved_gdb =le16_to_cpu(EXT3_SB(sb)->s_es->s_reserved_gdt_blocks); |
| 562 | struct buffer_head **primary; |
| 563 | struct buffer_head *dind; |
| 564 | struct ext3_iloc iloc; |
Mingming Cao | 43d23f9 | 2006-06-25 05:48:07 -0700 | [diff] [blame] | 565 | ext3_fsblk_t blk; |
Dave Kleikamp | a4e4de3 | 2006-09-27 01:49:36 -0700 | [diff] [blame] | 566 | __le32 *data, *end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | int gdbackups = 0; |
| 568 | int res, i; |
| 569 | int err; |
| 570 | |
Josef Bacik | c587f0c | 2008-03-19 17:00:49 -0700 | [diff] [blame] | 571 | primary = kmalloc(reserved_gdb * sizeof(*primary), GFP_NOFS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | if (!primary) |
| 573 | return -ENOMEM; |
| 574 | |
| 575 | data = EXT3_I(inode)->i_data + EXT3_DIND_BLOCK; |
| 576 | dind = sb_bread(sb, le32_to_cpu(*data)); |
| 577 | if (!dind) { |
| 578 | err = -EIO; |
| 579 | goto exit_free; |
| 580 | } |
| 581 | |
| 582 | blk = EXT3_SB(sb)->s_sbh->b_blocknr + 1 + EXT3_SB(sb)->s_gdb_count; |
Josef Bacik | 9bb9178 | 2008-06-05 22:46:47 -0700 | [diff] [blame] | 583 | data = (__le32 *)dind->b_data + (EXT3_SB(sb)->s_gdb_count % |
| 584 | EXT3_ADDR_PER_BLOCK(sb)); |
Dave Kleikamp | a4e4de3 | 2006-09-27 01:49:36 -0700 | [diff] [blame] | 585 | end = (__le32 *)dind->b_data + EXT3_ADDR_PER_BLOCK(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | |
| 587 | /* Get each reserved primary GDT block and verify it holds backups */ |
| 588 | for (res = 0; res < reserved_gdb; res++, blk++) { |
| 589 | if (le32_to_cpu(*data) != blk) { |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 590 | ext3_warning(sb, __func__, |
Mingming Cao | 43d23f9 | 2006-06-25 05:48:07 -0700 | [diff] [blame] | 591 | "reserved block "E3FSBLK |
| 592 | " not at offset %ld", |
Dave Kleikamp | a4e4de3 | 2006-09-27 01:49:36 -0700 | [diff] [blame] | 593 | blk, |
| 594 | (long)(data - (__le32 *)dind->b_data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | err = -EINVAL; |
| 596 | goto exit_bh; |
| 597 | } |
| 598 | primary[res] = sb_bread(sb, blk); |
| 599 | if (!primary[res]) { |
| 600 | err = -EIO; |
| 601 | goto exit_bh; |
| 602 | } |
| 603 | if ((gdbackups = verify_reserved_gdb(sb, primary[res])) < 0) { |
| 604 | brelse(primary[res]); |
| 605 | err = gdbackups; |
| 606 | goto exit_bh; |
| 607 | } |
| 608 | if (++data >= end) |
Dave Kleikamp | a4e4de3 | 2006-09-27 01:49:36 -0700 | [diff] [blame] | 609 | data = (__le32 *)dind->b_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | for (i = 0; i < reserved_gdb; i++) { |
| 613 | if ((err = ext3_journal_get_write_access(handle, primary[i]))) { |
| 614 | /* |
| 615 | int j; |
| 616 | for (j = 0; j < i; j++) |
| 617 | ext3_journal_release_buffer(handle, primary[j]); |
| 618 | */ |
| 619 | goto exit_bh; |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | if ((err = ext3_reserve_inode_write(handle, inode, &iloc))) |
| 624 | goto exit_bh; |
| 625 | |
| 626 | /* |
| 627 | * Finally we can add each of the reserved backup GDT blocks from |
| 628 | * the new group to its reserved primary GDT block. |
| 629 | */ |
| 630 | blk = input->group * EXT3_BLOCKS_PER_GROUP(sb); |
| 631 | for (i = 0; i < reserved_gdb; i++) { |
| 632 | int err2; |
Dave Kleikamp | a4e4de3 | 2006-09-27 01:49:36 -0700 | [diff] [blame] | 633 | data = (__le32 *)primary[i]->b_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | /* printk("reserving backup %lu[%u] = %lu\n", |
| 635 | primary[i]->b_blocknr, gdbackups, |
| 636 | blk + primary[i]->b_blocknr); */ |
| 637 | data[gdbackups] = cpu_to_le32(blk + primary[i]->b_blocknr); |
| 638 | err2 = ext3_journal_dirty_metadata(handle, primary[i]); |
| 639 | if (!err) |
| 640 | err = err2; |
| 641 | } |
| 642 | inode->i_blocks += reserved_gdb * sb->s_blocksize >> 9; |
| 643 | ext3_mark_iloc_dirty(handle, inode, &iloc); |
| 644 | |
| 645 | exit_bh: |
| 646 | while (--res >= 0) |
| 647 | brelse(primary[res]); |
| 648 | brelse(dind); |
| 649 | |
| 650 | exit_free: |
| 651 | kfree(primary); |
| 652 | |
| 653 | return err; |
| 654 | } |
| 655 | |
| 656 | /* |
| 657 | * Update the backup copies of the ext3 metadata. These don't need to be part |
| 658 | * of the main resize transaction, because e2fsck will re-write them if there |
| 659 | * is a problem (basically only OOM will cause a problem). However, we |
| 660 | * _should_ update the backups if possible, in case the primary gets trashed |
| 661 | * for some reason and we need to run e2fsck from a backup superblock. The |
| 662 | * important part is that the new block and inode counts are in the backup |
| 663 | * superblocks, and the location of the new group metadata in the GDT backups. |
| 664 | * |
| 665 | * We do not need lock_super() for this, because these blocks are not |
| 666 | * otherwise touched by the filesystem code when it is mounted. We don't |
| 667 | * need to worry about last changing from sbi->s_groups_count, because the |
| 668 | * worst that can happen is that we do not copy the full number of backups |
| 669 | * at this time. The resize which changed s_groups_count will backup again. |
| 670 | */ |
| 671 | static void update_backups(struct super_block *sb, |
| 672 | int blk_off, char *data, int size) |
| 673 | { |
| 674 | struct ext3_sb_info *sbi = EXT3_SB(sb); |
| 675 | const unsigned long last = sbi->s_groups_count; |
| 676 | const int bpg = EXT3_BLOCKS_PER_GROUP(sb); |
| 677 | unsigned three = 1; |
| 678 | unsigned five = 5; |
| 679 | unsigned seven = 7; |
| 680 | unsigned group; |
| 681 | int rest = sb->s_blocksize - size; |
| 682 | handle_t *handle; |
| 683 | int err = 0, err2; |
| 684 | |
| 685 | handle = ext3_journal_start_sb(sb, EXT3_MAX_TRANS_DATA); |
| 686 | if (IS_ERR(handle)) { |
| 687 | group = 1; |
| 688 | err = PTR_ERR(handle); |
| 689 | goto exit_err; |
| 690 | } |
| 691 | |
| 692 | while ((group = ext3_list_backups(sb, &three, &five, &seven)) < last) { |
| 693 | struct buffer_head *bh; |
| 694 | |
| 695 | /* Out of journal space, and can't get more - abort - so sad */ |
| 696 | if (handle->h_buffer_credits == 0 && |
| 697 | ext3_journal_extend(handle, EXT3_MAX_TRANS_DATA) && |
| 698 | (err = ext3_journal_restart(handle, EXT3_MAX_TRANS_DATA))) |
| 699 | break; |
| 700 | |
| 701 | bh = sb_getblk(sb, group * bpg + blk_off); |
Glauber de Oliveira Costa | 2973dfd | 2005-10-30 15:03:05 -0800 | [diff] [blame] | 702 | if (!bh) { |
| 703 | err = -EIO; |
| 704 | break; |
| 705 | } |
Glauber de Oliveira Costa | 8bdac5d | 2005-09-22 21:44:26 -0700 | [diff] [blame] | 706 | ext3_debug("update metadata backup %#04lx\n", |
| 707 | (unsigned long)bh->b_blocknr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | if ((err = ext3_journal_get_write_access(handle, bh))) |
| 709 | break; |
| 710 | lock_buffer(bh); |
| 711 | memcpy(bh->b_data, data, size); |
| 712 | if (rest) |
| 713 | memset(bh->b_data + size, 0, rest); |
| 714 | set_buffer_uptodate(bh); |
| 715 | unlock_buffer(bh); |
| 716 | ext3_journal_dirty_metadata(handle, bh); |
| 717 | brelse(bh); |
| 718 | } |
| 719 | if ((err2 = ext3_journal_stop(handle)) && !err) |
| 720 | err = err2; |
| 721 | |
| 722 | /* |
| 723 | * Ugh! Need to have e2fsck write the backup copies. It is too |
| 724 | * late to revert the resize, we shouldn't fail just because of |
| 725 | * the backup copies (they are only needed in case of corruption). |
| 726 | * |
| 727 | * However, if we got here we have a journal problem too, so we |
| 728 | * can't really start a transaction to mark the superblock. |
| 729 | * Chicken out and just set the flag on the hope it will be written |
| 730 | * to disk, and if not - we will simply wait until next fsck. |
| 731 | */ |
| 732 | exit_err: |
| 733 | if (err) { |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 734 | ext3_warning(sb, __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | "can't update backup for group %d (err %d), " |
Glauber de Oliveira Costa | 9f40668 | 2006-01-08 01:03:22 -0800 | [diff] [blame] | 736 | "forcing fsck on next reboot", group, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | sbi->s_mount_state &= ~EXT3_VALID_FS; |
Dave Kleikamp | a4e4de3 | 2006-09-27 01:49:36 -0700 | [diff] [blame] | 738 | sbi->s_es->s_state &= cpu_to_le16(~EXT3_VALID_FS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | mark_buffer_dirty(sbi->s_sbh); |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | /* Add group descriptor data to an existing or new group descriptor block. |
| 744 | * Ensure we handle all possible error conditions _before_ we start modifying |
| 745 | * the filesystem, because we cannot abort the transaction and not have it |
| 746 | * write the data to disk. |
| 747 | * |
| 748 | * If we are on a GDT block boundary, we need to get the reserved GDT block. |
| 749 | * Otherwise, we may need to add backup GDT blocks for a sparse group. |
| 750 | * |
| 751 | * We only need to hold the superblock lock while we are actually adding |
| 752 | * in the new group's counts to the superblock. Prior to that we have |
| 753 | * not really "added" the group at all. We re-check that we are still |
| 754 | * adding in the last group in case things have changed since verifying. |
| 755 | */ |
| 756 | int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input) |
| 757 | { |
| 758 | struct ext3_sb_info *sbi = EXT3_SB(sb); |
| 759 | struct ext3_super_block *es = sbi->s_es; |
| 760 | int reserved_gdb = ext3_bg_has_super(sb, input->group) ? |
| 761 | le16_to_cpu(es->s_reserved_gdt_blocks) : 0; |
| 762 | struct buffer_head *primary = NULL; |
| 763 | struct ext3_group_desc *gdp; |
| 764 | struct inode *inode = NULL; |
| 765 | handle_t *handle; |
| 766 | int gdb_off, gdb_num; |
| 767 | int err, err2; |
| 768 | |
| 769 | gdb_num = input->group / EXT3_DESC_PER_BLOCK(sb); |
| 770 | gdb_off = input->group % EXT3_DESC_PER_BLOCK(sb); |
| 771 | |
| 772 | if (gdb_off == 0 && !EXT3_HAS_RO_COMPAT_FEATURE(sb, |
| 773 | EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER)) { |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 774 | ext3_warning(sb, __func__, |
Glauber de Oliveira Costa | 9f40668 | 2006-01-08 01:03:22 -0800 | [diff] [blame] | 775 | "Can't resize non-sparse filesystem further"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | return -EPERM; |
| 777 | } |
| 778 | |
Eric Sandeen | 32c2d2b | 2006-09-27 01:49:36 -0700 | [diff] [blame] | 779 | if (le32_to_cpu(es->s_blocks_count) + input->blocks_count < |
| 780 | le32_to_cpu(es->s_blocks_count)) { |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 781 | ext3_warning(sb, __func__, "blocks_count overflow\n"); |
Eric Sandeen | 32c2d2b | 2006-09-27 01:49:36 -0700 | [diff] [blame] | 782 | return -EINVAL; |
| 783 | } |
| 784 | |
| 785 | if (le32_to_cpu(es->s_inodes_count) + EXT3_INODES_PER_GROUP(sb) < |
| 786 | le32_to_cpu(es->s_inodes_count)) { |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 787 | ext3_warning(sb, __func__, "inodes_count overflow\n"); |
Eric Sandeen | 32c2d2b | 2006-09-27 01:49:36 -0700 | [diff] [blame] | 788 | return -EINVAL; |
| 789 | } |
| 790 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | if (reserved_gdb || gdb_off == 0) { |
| 792 | if (!EXT3_HAS_COMPAT_FEATURE(sb, |
Josef Bacik | 972fbf7 | 2008-10-18 20:27:55 -0700 | [diff] [blame] | 793 | EXT3_FEATURE_COMPAT_RESIZE_INODE) |
| 794 | || !le16_to_cpu(es->s_reserved_gdt_blocks)) { |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 795 | ext3_warning(sb, __func__, |
Glauber de Oliveira Costa | 9f40668 | 2006-01-08 01:03:22 -0800 | [diff] [blame] | 796 | "No reserved GDT blocks, can't resize"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | return -EPERM; |
| 798 | } |
David Howells | 473043d | 2008-02-07 00:15:36 -0800 | [diff] [blame] | 799 | inode = ext3_iget(sb, EXT3_RESIZE_INO); |
| 800 | if (IS_ERR(inode)) { |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 801 | ext3_warning(sb, __func__, |
Glauber de Oliveira Costa | 9f40668 | 2006-01-08 01:03:22 -0800 | [diff] [blame] | 802 | "Error opening resize inode"); |
David Howells | 473043d | 2008-02-07 00:15:36 -0800 | [diff] [blame] | 803 | return PTR_ERR(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | } |
| 805 | } |
| 806 | |
| 807 | if ((err = verify_group_input(sb, input))) |
| 808 | goto exit_put; |
| 809 | |
| 810 | if ((err = setup_new_group_blocks(sb, input))) |
| 811 | goto exit_put; |
| 812 | |
| 813 | /* |
| 814 | * We will always be modifying at least the superblock and a GDT |
| 815 | * block. If we are adding a group past the last current GDT block, |
| 816 | * we will also modify the inode and the dindirect block. If we |
| 817 | * are adding a group with superblock/GDT backups we will also |
| 818 | * modify each of the reserved GDT dindirect blocks. |
| 819 | */ |
| 820 | handle = ext3_journal_start_sb(sb, |
| 821 | ext3_bg_has_super(sb, input->group) ? |
| 822 | 3 + reserved_gdb : 4); |
| 823 | if (IS_ERR(handle)) { |
| 824 | err = PTR_ERR(handle); |
| 825 | goto exit_put; |
| 826 | } |
| 827 | |
| 828 | lock_super(sb); |
Glauber de Oliveira Costa | 29ba172 | 2006-01-08 01:03:23 -0800 | [diff] [blame] | 829 | if (input->group != sbi->s_groups_count) { |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 830 | ext3_warning(sb, __func__, |
Glauber de Oliveira Costa | 9f40668 | 2006-01-08 01:03:22 -0800 | [diff] [blame] | 831 | "multiple resizers run on filesystem!"); |
Glauber de Oliveira Costa | aa877b3 | 2005-11-28 13:44:02 -0800 | [diff] [blame] | 832 | err = -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | goto exit_journal; |
| 834 | } |
| 835 | |
| 836 | if ((err = ext3_journal_get_write_access(handle, sbi->s_sbh))) |
| 837 | goto exit_journal; |
| 838 | |
| 839 | /* |
| 840 | * We will only either add reserved group blocks to a backup group |
| 841 | * or remove reserved blocks for the first group in a new group block. |
| 842 | * Doing both would be mean more complex code, and sane people don't |
| 843 | * use non-sparse filesystems anymore. This is already checked above. |
| 844 | */ |
| 845 | if (gdb_off) { |
| 846 | primary = sbi->s_group_desc[gdb_num]; |
| 847 | if ((err = ext3_journal_get_write_access(handle, primary))) |
| 848 | goto exit_journal; |
| 849 | |
| 850 | if (reserved_gdb && ext3_bg_num_gdb(sb, input->group) && |
| 851 | (err = reserve_backup_gdb(handle, inode, input))) |
| 852 | goto exit_journal; |
| 853 | } else if ((err = add_new_gdb(handle, inode, input, &primary))) |
| 854 | goto exit_journal; |
| 855 | |
| 856 | /* |
| 857 | * OK, now we've set up the new group. Time to make it active. |
| 858 | * |
| 859 | * Current kernels don't lock all allocations via lock_super(), |
| 860 | * so we have to be safe wrt. concurrent accesses the group |
| 861 | * data. So we need to be careful to set all of the relevant |
| 862 | * group descriptor data etc. *before* we enable the group. |
| 863 | * |
Glauber de Oliveira Costa | 29ba172 | 2006-01-08 01:03:23 -0800 | [diff] [blame] | 864 | * The key field here is sbi->s_groups_count: as long as |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | * that retains its old value, nobody is going to access the new |
| 866 | * group. |
| 867 | * |
| 868 | * So first we update all the descriptor metadata for the new |
| 869 | * group; then we update the total disk blocks count; then we |
| 870 | * update the groups count to enable the group; then finally we |
| 871 | * update the free space counts so that the system can start |
| 872 | * using the new disk blocks. |
| 873 | */ |
| 874 | |
| 875 | /* Update group descriptor block for new group */ |
| 876 | gdp = (struct ext3_group_desc *)primary->b_data + gdb_off; |
| 877 | |
| 878 | gdp->bg_block_bitmap = cpu_to_le32(input->block_bitmap); |
| 879 | gdp->bg_inode_bitmap = cpu_to_le32(input->inode_bitmap); |
| 880 | gdp->bg_inode_table = cpu_to_le32(input->inode_table); |
| 881 | gdp->bg_free_blocks_count = cpu_to_le16(input->free_blocks_count); |
| 882 | gdp->bg_free_inodes_count = cpu_to_le16(EXT3_INODES_PER_GROUP(sb)); |
| 883 | |
| 884 | /* |
| 885 | * Make the new blocks and inodes valid next. We do this before |
| 886 | * increasing the group count so that once the group is enabled, |
| 887 | * all of its blocks and inodes are already valid. |
| 888 | * |
| 889 | * We always allocate group-by-group, then block-by-block or |
| 890 | * inode-by-inode within a group, so enabling these |
| 891 | * blocks/inodes before the group is live won't actually let us |
| 892 | * allocate the new space yet. |
| 893 | */ |
Marcin Slusarz | 50e8a28 | 2008-02-08 04:20:13 -0800 | [diff] [blame] | 894 | le32_add_cpu(&es->s_blocks_count, input->blocks_count); |
| 895 | le32_add_cpu(&es->s_inodes_count, EXT3_INODES_PER_GROUP(sb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | |
| 897 | /* |
| 898 | * We need to protect s_groups_count against other CPUs seeing |
| 899 | * inconsistent state in the superblock. |
| 900 | * |
| 901 | * The precise rules we use are: |
| 902 | * |
| 903 | * * Writers of s_groups_count *must* hold lock_super |
| 904 | * AND |
| 905 | * * Writers must perform a smp_wmb() after updating all dependent |
| 906 | * data and before modifying the groups count |
| 907 | * |
| 908 | * * Readers must hold lock_super() over the access |
| 909 | * OR |
| 910 | * * Readers must perform an smp_rmb() after reading the groups count |
| 911 | * and before reading any dependent data. |
| 912 | * |
| 913 | * NB. These rules can be relaxed when checking the group count |
| 914 | * while freeing data, as we can only allocate from a block |
| 915 | * group after serialising against the group count, and we can |
| 916 | * only then free after serialising in turn against that |
| 917 | * allocation. |
| 918 | */ |
| 919 | smp_wmb(); |
| 920 | |
| 921 | /* Update the global fs size fields */ |
Glauber de Oliveira Costa | 29ba172 | 2006-01-08 01:03:23 -0800 | [diff] [blame] | 922 | sbi->s_groups_count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | |
| 924 | ext3_journal_dirty_metadata(handle, primary); |
| 925 | |
| 926 | /* Update the reserved block counts only once the new group is |
| 927 | * active. */ |
Marcin Slusarz | 50e8a28 | 2008-02-08 04:20:13 -0800 | [diff] [blame] | 928 | le32_add_cpu(&es->s_r_blocks_count, input->reserved_blocks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | |
| 930 | /* Update the free space counts */ |
Peter Zijlstra | aa0dff2 | 2007-10-16 23:25:42 -0700 | [diff] [blame] | 931 | percpu_counter_add(&sbi->s_freeblocks_counter, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | input->free_blocks_count); |
Peter Zijlstra | aa0dff2 | 2007-10-16 23:25:42 -0700 | [diff] [blame] | 933 | percpu_counter_add(&sbi->s_freeinodes_counter, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | EXT3_INODES_PER_GROUP(sb)); |
| 935 | |
Glauber de Oliveira Costa | 29ba172 | 2006-01-08 01:03:23 -0800 | [diff] [blame] | 936 | ext3_journal_dirty_metadata(handle, sbi->s_sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | |
| 938 | exit_journal: |
| 939 | unlock_super(sb); |
| 940 | if ((err2 = ext3_journal_stop(handle)) && !err) |
| 941 | err = err2; |
| 942 | if (!err) { |
| 943 | update_backups(sb, sbi->s_sbh->b_blocknr, (char *)es, |
| 944 | sizeof(struct ext3_super_block)); |
| 945 | update_backups(sb, primary->b_blocknr, primary->b_data, |
| 946 | primary->b_size); |
| 947 | } |
| 948 | exit_put: |
| 949 | iput(inode); |
| 950 | return err; |
| 951 | } /* ext3_group_add */ |
| 952 | |
| 953 | /* Extend the filesystem to the new number of blocks specified. This entry |
| 954 | * point is only used to extend the current filesystem to the end of the last |
| 955 | * existing group. It can be accessed via ioctl, or by "remount,resize=<size>" |
| 956 | * for emergencies (because it has no dependencies on reserved blocks). |
| 957 | * |
| 958 | * If we _really_ wanted, we could use default values to call ext3_group_add() |
| 959 | * allow the "remount" trick to work for arbitrary resizing, assuming enough |
| 960 | * GDT blocks are reserved to grow to the desired size. |
| 961 | */ |
| 962 | int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es, |
Mingming Cao | 43d23f9 | 2006-06-25 05:48:07 -0700 | [diff] [blame] | 963 | ext3_fsblk_t n_blocks_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | { |
Mingming Cao | 43d23f9 | 2006-06-25 05:48:07 -0700 | [diff] [blame] | 965 | ext3_fsblk_t o_blocks_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | unsigned long o_groups_count; |
Mingming Cao | 1c2bf37 | 2006-06-25 05:48:06 -0700 | [diff] [blame] | 967 | ext3_grpblk_t last; |
| 968 | ext3_grpblk_t add; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | struct buffer_head * bh; |
| 970 | handle_t *handle; |
Mingming Cao | 1c2bf37 | 2006-06-25 05:48:06 -0700 | [diff] [blame] | 971 | int err; |
| 972 | unsigned long freed_blocks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | |
| 974 | /* We don't need to worry about locking wrt other resizers just |
| 975 | * yet: we're going to revalidate es->s_blocks_count after |
| 976 | * taking lock_super() below. */ |
| 977 | o_blocks_count = le32_to_cpu(es->s_blocks_count); |
| 978 | o_groups_count = EXT3_SB(sb)->s_groups_count; |
| 979 | |
| 980 | if (test_opt(sb, DEBUG)) |
Mingming Cao | 43d23f9 | 2006-06-25 05:48:07 -0700 | [diff] [blame] | 981 | printk(KERN_DEBUG "EXT3-fs: extending last group from "E3FSBLK" uto "E3FSBLK" blocks\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | o_blocks_count, n_blocks_count); |
| 983 | |
| 984 | if (n_blocks_count == 0 || n_blocks_count == o_blocks_count) |
| 985 | return 0; |
| 986 | |
Mingming Cao | fcd5df3 | 2006-06-25 05:47:50 -0700 | [diff] [blame] | 987 | if (n_blocks_count > (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) { |
| 988 | printk(KERN_ERR "EXT3-fs: filesystem on %s:" |
| 989 | " too large to resize to %lu blocks safely\n", |
| 990 | sb->s_id, n_blocks_count); |
| 991 | if (sizeof(sector_t) < 8) |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 992 | ext3_warning(sb, __func__, |
Bartlomiej Zolnierkiewicz | 90c699a | 2009-06-19 08:08:50 +0200 | [diff] [blame] | 993 | "CONFIG_LBDAF not enabled\n"); |
Mingming Cao | fcd5df3 | 2006-06-25 05:47:50 -0700 | [diff] [blame] | 994 | return -EINVAL; |
| 995 | } |
| 996 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | if (n_blocks_count < o_blocks_count) { |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 998 | ext3_warning(sb, __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | "can't shrink FS - resize aborted"); |
| 1000 | return -EBUSY; |
| 1001 | } |
| 1002 | |
| 1003 | /* Handle the remaining blocks in the last group only. */ |
| 1004 | last = (o_blocks_count - le32_to_cpu(es->s_first_data_block)) % |
| 1005 | EXT3_BLOCKS_PER_GROUP(sb); |
| 1006 | |
| 1007 | if (last == 0) { |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 1008 | ext3_warning(sb, __func__, |
Glauber de Oliveira Costa | 9f40668 | 2006-01-08 01:03:22 -0800 | [diff] [blame] | 1009 | "need to use ext2online to resize further"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | return -EPERM; |
| 1011 | } |
| 1012 | |
| 1013 | add = EXT3_BLOCKS_PER_GROUP(sb) - last; |
| 1014 | |
Eric Sandeen | 32c2d2b | 2006-09-27 01:49:36 -0700 | [diff] [blame] | 1015 | if (o_blocks_count + add < o_blocks_count) { |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 1016 | ext3_warning(sb, __func__, "blocks_count overflow"); |
Eric Sandeen | 32c2d2b | 2006-09-27 01:49:36 -0700 | [diff] [blame] | 1017 | return -EINVAL; |
| 1018 | } |
| 1019 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | if (o_blocks_count + add > n_blocks_count) |
| 1021 | add = n_blocks_count - o_blocks_count; |
| 1022 | |
| 1023 | if (o_blocks_count + add < n_blocks_count) |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 1024 | ext3_warning(sb, __func__, |
Mingming Cao | 43d23f9 | 2006-06-25 05:48:07 -0700 | [diff] [blame] | 1025 | "will only finish group ("E3FSBLK |
| 1026 | " blocks, %u new)", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | o_blocks_count + add, add); |
| 1028 | |
| 1029 | /* See if the device is actually as big as what was requested */ |
| 1030 | bh = sb_bread(sb, o_blocks_count + add -1); |
| 1031 | if (!bh) { |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 1032 | ext3_warning(sb, __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | "can't read last block, resize aborted"); |
| 1034 | return -ENOSPC; |
| 1035 | } |
| 1036 | brelse(bh); |
| 1037 | |
| 1038 | /* We will update the superblock, one block bitmap, and |
| 1039 | * one group descriptor via ext3_free_blocks(). |
| 1040 | */ |
| 1041 | handle = ext3_journal_start_sb(sb, 3); |
| 1042 | if (IS_ERR(handle)) { |
| 1043 | err = PTR_ERR(handle); |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 1044 | ext3_warning(sb, __func__, "error %d on journal start",err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | goto exit_put; |
| 1046 | } |
| 1047 | |
| 1048 | lock_super(sb); |
| 1049 | if (o_blocks_count != le32_to_cpu(es->s_blocks_count)) { |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 1050 | ext3_warning(sb, __func__, |
Glauber de Oliveira Costa | 9f40668 | 2006-01-08 01:03:22 -0800 | [diff] [blame] | 1051 | "multiple resizers run on filesystem!"); |
Ananiev, Leonid I | 389ed39 | 2006-04-10 22:54:38 -0700 | [diff] [blame] | 1052 | unlock_super(sb); |
Akinobu Mita | 22a5daf | 2008-04-28 02:16:07 -0700 | [diff] [blame] | 1053 | ext3_journal_stop(handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | err = -EBUSY; |
| 1055 | goto exit_put; |
| 1056 | } |
| 1057 | |
| 1058 | if ((err = ext3_journal_get_write_access(handle, |
| 1059 | EXT3_SB(sb)->s_sbh))) { |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 1060 | ext3_warning(sb, __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | "error %d on journal write access", err); |
| 1062 | unlock_super(sb); |
| 1063 | ext3_journal_stop(handle); |
| 1064 | goto exit_put; |
| 1065 | } |
| 1066 | es->s_blocks_count = cpu_to_le32(o_blocks_count + add); |
| 1067 | ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | unlock_super(sb); |
Mingming Cao | 43d23f9 | 2006-06-25 05:48:07 -0700 | [diff] [blame] | 1069 | ext3_debug("freeing blocks %lu through "E3FSBLK"\n", o_blocks_count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | o_blocks_count + add); |
| 1071 | ext3_free_blocks_sb(handle, sb, o_blocks_count, add, &freed_blocks); |
Mingming Cao | 43d23f9 | 2006-06-25 05:48:07 -0700 | [diff] [blame] | 1072 | ext3_debug("freed blocks "E3FSBLK" through "E3FSBLK"\n", o_blocks_count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | o_blocks_count + add); |
| 1074 | if ((err = ext3_journal_stop(handle))) |
| 1075 | goto exit_put; |
| 1076 | if (test_opt(sb, DEBUG)) |
| 1077 | printk(KERN_DEBUG "EXT3-fs: extended group to %u blocks\n", |
| 1078 | le32_to_cpu(es->s_blocks_count)); |
| 1079 | update_backups(sb, EXT3_SB(sb)->s_sbh->b_blocknr, (char *)es, |
| 1080 | sizeof(struct ext3_super_block)); |
| 1081 | exit_put: |
| 1082 | return err; |
| 1083 | } /* ext3_group_extend */ |