blob: 3b2c5541d8a686fe7c780a512c0acd3e6771b3ab [file] [log] [blame]
Dave Kleikampac27a0e2006-10-11 01:20:50 -07001/*
Mingming Cao617ba132006-10-11 01:20:53 -07002 * linux/fs/ext4/resize.c
Dave Kleikampac27a0e2006-10-11 01:20:50 -07003 *
Mingming Cao617ba132006-10-11 01:20:53 -07004 * Support for resizing an ext4 filesystem while it is mounted.
Dave Kleikampac27a0e2006-10-11 01:20:50 -07005 *
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
11
Mingming Cao617ba132006-10-11 01:20:53 -070012#define EXT4FS_DEBUG
Dave Kleikampac27a0e2006-10-11 01:20:50 -070013
Dave Kleikampac27a0e2006-10-11 01:20:50 -070014#include <linux/errno.h>
15#include <linux/slab.h>
16
Christoph Hellwig3dcf5452008-04-29 18:13:32 -040017#include "ext4_jbd2.h"
Dave Kleikampac27a0e2006-10-11 01:20:50 -070018
19#define outside(b, first, last) ((b) < (first) || (b) >= (last))
20#define inside(b, first, last) ((b) >= (first) && (b) < (last))
21
22static int verify_group_input(struct super_block *sb,
Mingming Cao617ba132006-10-11 01:20:53 -070023 struct ext4_new_group_data *input)
Dave Kleikampac27a0e2006-10-11 01:20:50 -070024{
Mingming Cao617ba132006-10-11 01:20:53 -070025 struct ext4_sb_info *sbi = EXT4_SB(sb);
26 struct ext4_super_block *es = sbi->s_es;
Laurent Vivierbd81d8e2006-10-11 01:21:10 -070027 ext4_fsblk_t start = ext4_blocks_count(es);
Mingming Cao617ba132006-10-11 01:20:53 -070028 ext4_fsblk_t end = start + input->blocks_count;
Avantika Mathurfd2d4292008-01-28 23:58:27 -050029 ext4_group_t group = input->group;
Mingming Cao617ba132006-10-11 01:20:53 -070030 ext4_fsblk_t itend = input->inode_table + sbi->s_itb_per_group;
31 unsigned overhead = ext4_bg_has_super(sb, group) ?
32 (1 + ext4_bg_num_gdb(sb, group) +
Dave Kleikampac27a0e2006-10-11 01:20:50 -070033 le16_to_cpu(es->s_reserved_gdt_blocks)) : 0;
Mingming Cao617ba132006-10-11 01:20:53 -070034 ext4_fsblk_t metaend = start + overhead;
Dave Kleikampac27a0e2006-10-11 01:20:50 -070035 struct buffer_head *bh = NULL;
Mingming Cao3a5b2ec2006-10-11 01:21:05 -070036 ext4_grpblk_t free_blocks_count, offset;
Dave Kleikampac27a0e2006-10-11 01:20:50 -070037 int err = -EINVAL;
38
39 input->free_blocks_count = free_blocks_count =
40 input->blocks_count - 2 - overhead - sbi->s_itb_per_group;
41
42 if (test_opt(sb, DEBUG))
Mingming Cao617ba132006-10-11 01:20:53 -070043 printk(KERN_DEBUG "EXT4-fs: adding %s group %u: %u blocks "
Dave Kleikampac27a0e2006-10-11 01:20:50 -070044 "(%d free, %u reserved)\n",
Mingming Cao617ba132006-10-11 01:20:53 -070045 ext4_bg_has_super(sb, input->group) ? "normal" :
Dave Kleikampac27a0e2006-10-11 01:20:50 -070046 "no-super", input->group, input->blocks_count,
47 free_blocks_count, input->reserved_blocks);
48
Mingming Cao3a5b2ec2006-10-11 01:21:05 -070049 ext4_get_group_no_and_offset(sb, start, NULL, &offset);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070050 if (group != sbi->s_groups_count)
Harvey Harrison46e665e2008-04-17 10:38:59 -040051 ext4_warning(sb, __func__,
Theodore Ts'oa9df9a42009-01-05 22:18:16 -050052 "Cannot add at group %u (only %u groups)",
Dave Kleikampac27a0e2006-10-11 01:20:50 -070053 input->group, sbi->s_groups_count);
Mingming Cao3a5b2ec2006-10-11 01:21:05 -070054 else if (offset != 0)
Harvey Harrison46e665e2008-04-17 10:38:59 -040055 ext4_warning(sb, __func__, "Last group not full");
Dave Kleikampac27a0e2006-10-11 01:20:50 -070056 else if (input->reserved_blocks > input->blocks_count / 5)
Harvey Harrison46e665e2008-04-17 10:38:59 -040057 ext4_warning(sb, __func__, "Reserved blocks too high (%u)",
Dave Kleikampac27a0e2006-10-11 01:20:50 -070058 input->reserved_blocks);
59 else if (free_blocks_count < 0)
Harvey Harrison46e665e2008-04-17 10:38:59 -040060 ext4_warning(sb, __func__, "Bad blocks count %u",
Dave Kleikampac27a0e2006-10-11 01:20:50 -070061 input->blocks_count);
62 else if (!(bh = sb_bread(sb, end - 1)))
Harvey Harrison46e665e2008-04-17 10:38:59 -040063 ext4_warning(sb, __func__,
Mingming Cao2ae02102006-10-11 01:21:11 -070064 "Cannot read last block (%llu)",
Dave Kleikampac27a0e2006-10-11 01:20:50 -070065 end - 1);
66 else if (outside(input->block_bitmap, start, end))
Harvey Harrison46e665e2008-04-17 10:38:59 -040067 ext4_warning(sb, __func__,
Laurent Vivierbd81d8e2006-10-11 01:21:10 -070068 "Block bitmap not in group (block %llu)",
Randy Dunlap1939e492006-10-28 10:38:26 -070069 (unsigned long long)input->block_bitmap);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070070 else if (outside(input->inode_bitmap, start, end))
Harvey Harrison46e665e2008-04-17 10:38:59 -040071 ext4_warning(sb, __func__,
Laurent Vivierbd81d8e2006-10-11 01:21:10 -070072 "Inode bitmap not in group (block %llu)",
Randy Dunlap1939e492006-10-28 10:38:26 -070073 (unsigned long long)input->inode_bitmap);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070074 else if (outside(input->inode_table, start, end) ||
Theodore Ts'o2b2d6d02008-07-26 16:15:44 -040075 outside(itend - 1, start, end))
Harvey Harrison46e665e2008-04-17 10:38:59 -040076 ext4_warning(sb, __func__,
Laurent Vivierbd81d8e2006-10-11 01:21:10 -070077 "Inode table not in group (blocks %llu-%llu)",
Randy Dunlap1939e492006-10-28 10:38:26 -070078 (unsigned long long)input->inode_table, itend - 1);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070079 else if (input->inode_bitmap == input->block_bitmap)
Harvey Harrison46e665e2008-04-17 10:38:59 -040080 ext4_warning(sb, __func__,
Laurent Vivierbd81d8e2006-10-11 01:21:10 -070081 "Block bitmap same as inode bitmap (%llu)",
Randy Dunlap1939e492006-10-28 10:38:26 -070082 (unsigned long long)input->block_bitmap);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070083 else if (inside(input->block_bitmap, input->inode_table, itend))
Harvey Harrison46e665e2008-04-17 10:38:59 -040084 ext4_warning(sb, __func__,
Laurent Vivierbd81d8e2006-10-11 01:21:10 -070085 "Block bitmap (%llu) in inode table (%llu-%llu)",
Randy Dunlap1939e492006-10-28 10:38:26 -070086 (unsigned long long)input->block_bitmap,
87 (unsigned long long)input->inode_table, itend - 1);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070088 else if (inside(input->inode_bitmap, input->inode_table, itend))
Harvey Harrison46e665e2008-04-17 10:38:59 -040089 ext4_warning(sb, __func__,
Laurent Vivierbd81d8e2006-10-11 01:21:10 -070090 "Inode bitmap (%llu) in inode table (%llu-%llu)",
Randy Dunlap1939e492006-10-28 10:38:26 -070091 (unsigned long long)input->inode_bitmap,
92 (unsigned long long)input->inode_table, itend - 1);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070093 else if (inside(input->block_bitmap, start, metaend))
Harvey Harrison46e665e2008-04-17 10:38:59 -040094 ext4_warning(sb, __func__,
Laurent Vivierbd81d8e2006-10-11 01:21:10 -070095 "Block bitmap (%llu) in GDT table"
Mingming Cao2ae02102006-10-11 01:21:11 -070096 " (%llu-%llu)",
Randy Dunlap1939e492006-10-28 10:38:26 -070097 (unsigned long long)input->block_bitmap,
98 start, metaend - 1);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070099 else if (inside(input->inode_bitmap, start, metaend))
Harvey Harrison46e665e2008-04-17 10:38:59 -0400100 ext4_warning(sb, __func__,
Laurent Vivierbd81d8e2006-10-11 01:21:10 -0700101 "Inode bitmap (%llu) in GDT table"
Mingming Cao2ae02102006-10-11 01:21:11 -0700102 " (%llu-%llu)",
Randy Dunlap1939e492006-10-28 10:38:26 -0700103 (unsigned long long)input->inode_bitmap,
104 start, metaend - 1);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700105 else if (inside(input->inode_table, start, metaend) ||
Theodore Ts'o2b2d6d02008-07-26 16:15:44 -0400106 inside(itend - 1, start, metaend))
Harvey Harrison46e665e2008-04-17 10:38:59 -0400107 ext4_warning(sb, __func__,
Mingming Cao2ae02102006-10-11 01:21:11 -0700108 "Inode table (%llu-%llu) overlaps"
109 "GDT table (%llu-%llu)",
Randy Dunlap1939e492006-10-28 10:38:26 -0700110 (unsigned long long)input->inode_table,
111 itend - 1, start, metaend - 1);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700112 else
113 err = 0;
114 brelse(bh);
115
116 return err;
117}
118
119static struct buffer_head *bclean(handle_t *handle, struct super_block *sb,
Mingming Cao617ba132006-10-11 01:20:53 -0700120 ext4_fsblk_t blk)
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700121{
122 struct buffer_head *bh;
123 int err;
124
125 bh = sb_getblk(sb, blk);
126 if (!bh)
127 return ERR_PTR(-EIO);
Mingming Cao617ba132006-10-11 01:20:53 -0700128 if ((err = ext4_journal_get_write_access(handle, bh))) {
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700129 brelse(bh);
130 bh = ERR_PTR(err);
131 } else {
132 lock_buffer(bh);
133 memset(bh->b_data, 0, sb->s_blocksize);
134 set_buffer_uptodate(bh);
135 unlock_buffer(bh);
136 }
137
138 return bh;
139}
140
141/*
Eric Sandeen14904102007-10-16 18:38:25 -0400142 * If we have fewer than thresh credits, extend by EXT4_MAX_TRANS_DATA.
143 * If that fails, restart the transaction & regain write access for the
144 * buffer head which is used for block_bitmap modifications.
145 */
146static int extend_or_restart_transaction(handle_t *handle, int thresh,
147 struct buffer_head *bh)
148{
149 int err;
150
Frank Mayhar03901312009-01-07 00:06:22 -0500151 if (ext4_handle_has_enough_credits(handle, thresh))
Eric Sandeen14904102007-10-16 18:38:25 -0400152 return 0;
153
154 err = ext4_journal_extend(handle, EXT4_MAX_TRANS_DATA);
155 if (err < 0)
156 return err;
157 if (err) {
158 if ((err = ext4_journal_restart(handle, EXT4_MAX_TRANS_DATA)))
159 return err;
Theodore Ts'o2b2d6d02008-07-26 16:15:44 -0400160 if ((err = ext4_journal_get_write_access(handle, bh)))
Eric Sandeen14904102007-10-16 18:38:25 -0400161 return err;
Theodore Ts'o2b2d6d02008-07-26 16:15:44 -0400162 }
Eric Sandeen14904102007-10-16 18:38:25 -0400163
164 return 0;
165}
166
167/*
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700168 * Set up the block and inode bitmaps, and the inode table for the new group.
169 * This doesn't need to be part of the main transaction, since we are only
170 * changing blocks outside the actual filesystem. We still do journaling to
171 * ensure the recovery is correct in case of a failure just after resize.
172 * If any part of this fails, we simply abort the resize.
173 */
174static int setup_new_group_blocks(struct super_block *sb,
Mingming Cao617ba132006-10-11 01:20:53 -0700175 struct ext4_new_group_data *input)
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700176{
Mingming Cao617ba132006-10-11 01:20:53 -0700177 struct ext4_sb_info *sbi = EXT4_SB(sb);
178 ext4_fsblk_t start = ext4_group_first_block_no(sb, input->group);
179 int reserved_gdb = ext4_bg_has_super(sb, input->group) ?
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700180 le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) : 0;
Mingming Cao617ba132006-10-11 01:20:53 -0700181 unsigned long gdblocks = ext4_bg_num_gdb(sb, input->group);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700182 struct buffer_head *bh;
183 handle_t *handle;
Mingming Cao617ba132006-10-11 01:20:53 -0700184 ext4_fsblk_t block;
185 ext4_grpblk_t bit;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700186 int i;
187 int err = 0, err2;
188
Eric Sandeen14904102007-10-16 18:38:25 -0400189 /* This transaction may be extended/restarted along the way */
190 handle = ext4_journal_start_sb(sb, EXT4_MAX_TRANS_DATA);
191
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700192 if (IS_ERR(handle))
193 return PTR_ERR(handle);
194
Theodore Ts'o32ed5052009-04-25 22:53:39 -0400195 mutex_lock(&sbi->s_resize_lock);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700196 if (input->group != sbi->s_groups_count) {
197 err = -EBUSY;
198 goto exit_journal;
199 }
200
201 if (IS_ERR(bh = bclean(handle, sb, input->block_bitmap))) {
202 err = PTR_ERR(bh);
203 goto exit_journal;
204 }
205
Mingming Cao617ba132006-10-11 01:20:53 -0700206 if (ext4_bg_has_super(sb, input->group)) {
Eric Sandeenc549a952008-01-28 23:58:27 -0500207 ext4_debug("mark backup superblock %#04llx (+0)\n", start);
Mingming Cao617ba132006-10-11 01:20:53 -0700208 ext4_set_bit(0, bh->b_data);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700209 }
210
211 /* Copy all of the GDT blocks into the backup in this group */
212 for (i = 0, bit = 1, block = start + 1;
213 i < gdblocks; i++, block++, bit++) {
214 struct buffer_head *gdb;
215
Eric Sandeenc549a952008-01-28 23:58:27 -0500216 ext4_debug("update backup group %#04llx (+%d)\n", block, bit);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700217
Eric Sandeen14904102007-10-16 18:38:25 -0400218 if ((err = extend_or_restart_transaction(handle, 1, bh)))
219 goto exit_bh;
220
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700221 gdb = sb_getblk(sb, block);
222 if (!gdb) {
223 err = -EIO;
224 goto exit_bh;
225 }
Mingming Cao617ba132006-10-11 01:20:53 -0700226 if ((err = ext4_journal_get_write_access(handle, gdb))) {
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700227 brelse(gdb);
228 goto exit_bh;
229 }
Eric Sandeen5b615282007-10-16 18:38:25 -0400230 lock_buffer(gdb);
231 memcpy(gdb->b_data, sbi->s_group_desc[i]->b_data, gdb->b_size);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700232 set_buffer_uptodate(gdb);
Eric Sandeen5b615282007-10-16 18:38:25 -0400233 unlock_buffer(gdb);
Frank Mayhar03901312009-01-07 00:06:22 -0500234 ext4_handle_dirty_metadata(handle, NULL, gdb);
Mingming Cao617ba132006-10-11 01:20:53 -0700235 ext4_set_bit(bit, bh->b_data);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700236 brelse(gdb);
237 }
238
239 /* Zero out all of the reserved backup group descriptor table blocks */
240 for (i = 0, bit = gdblocks + 1, block = start + bit;
241 i < reserved_gdb; i++, block++, bit++) {
242 struct buffer_head *gdb;
243
Eric Sandeenc549a952008-01-28 23:58:27 -0500244 ext4_debug("clear reserved block %#04llx (+%d)\n", block, bit);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700245
Eric Sandeen14904102007-10-16 18:38:25 -0400246 if ((err = extend_or_restart_transaction(handle, 1, bh)))
247 goto exit_bh;
248
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700249 if (IS_ERR(gdb = bclean(handle, sb, block))) {
Roel Kluinc09eef32009-12-07 10:38:16 -0500250 err = PTR_ERR(gdb);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700251 goto exit_bh;
252 }
Frank Mayhar03901312009-01-07 00:06:22 -0500253 ext4_handle_dirty_metadata(handle, NULL, gdb);
Mingming Cao617ba132006-10-11 01:20:53 -0700254 ext4_set_bit(bit, bh->b_data);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700255 brelse(gdb);
256 }
Eric Sandeenc549a952008-01-28 23:58:27 -0500257 ext4_debug("mark block bitmap %#04llx (+%llu)\n", input->block_bitmap,
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700258 input->block_bitmap - start);
Mingming Cao617ba132006-10-11 01:20:53 -0700259 ext4_set_bit(input->block_bitmap - start, bh->b_data);
Eric Sandeenc549a952008-01-28 23:58:27 -0500260 ext4_debug("mark inode bitmap %#04llx (+%llu)\n", input->inode_bitmap,
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700261 input->inode_bitmap - start);
Mingming Cao617ba132006-10-11 01:20:53 -0700262 ext4_set_bit(input->inode_bitmap - start, bh->b_data);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700263
264 /* Zero out all of the inode table blocks */
265 for (i = 0, block = input->inode_table, bit = block - start;
266 i < sbi->s_itb_per_group; i++, bit++, block++) {
267 struct buffer_head *it;
268
Eric Sandeenc549a952008-01-28 23:58:27 -0500269 ext4_debug("clear inode block %#04llx (+%d)\n", block, bit);
Eric Sandeen14904102007-10-16 18:38:25 -0400270
271 if ((err = extend_or_restart_transaction(handle, 1, bh)))
272 goto exit_bh;
273
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700274 if (IS_ERR(it = bclean(handle, sb, block))) {
275 err = PTR_ERR(it);
276 goto exit_bh;
277 }
Frank Mayhar03901312009-01-07 00:06:22 -0500278 ext4_handle_dirty_metadata(handle, NULL, it);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700279 brelse(it);
Mingming Cao617ba132006-10-11 01:20:53 -0700280 ext4_set_bit(bit, bh->b_data);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700281 }
Eric Sandeen14904102007-10-16 18:38:25 -0400282
283 if ((err = extend_or_restart_transaction(handle, 2, bh)))
284 goto exit_bh;
285
Aneesh Kumar K.V648f5872009-01-05 21:46:04 -0500286 mark_bitmap_end(input->blocks_count, sb->s_blocksize * 8, bh->b_data);
Frank Mayhar03901312009-01-07 00:06:22 -0500287 ext4_handle_dirty_metadata(handle, NULL, bh);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700288 brelse(bh);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700289 /* Mark unused entries in inode bitmap used */
Eric Sandeenc549a952008-01-28 23:58:27 -0500290 ext4_debug("clear inode bitmap %#04llx (+%llu)\n",
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700291 input->inode_bitmap, input->inode_bitmap - start);
292 if (IS_ERR(bh = bclean(handle, sb, input->inode_bitmap))) {
293 err = PTR_ERR(bh);
294 goto exit_journal;
295 }
296
Aneesh Kumar K.V648f5872009-01-05 21:46:04 -0500297 mark_bitmap_end(EXT4_INODES_PER_GROUP(sb), sb->s_blocksize * 8,
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700298 bh->b_data);
Frank Mayhar03901312009-01-07 00:06:22 -0500299 ext4_handle_dirty_metadata(handle, NULL, bh);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700300exit_bh:
301 brelse(bh);
302
303exit_journal:
Theodore Ts'o32ed5052009-04-25 22:53:39 -0400304 mutex_unlock(&sbi->s_resize_lock);
Mingming Cao617ba132006-10-11 01:20:53 -0700305 if ((err2 = ext4_journal_stop(handle)) && !err)
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700306 err = err2;
307
308 return err;
309}
310
311/*
312 * Iterate through the groups which hold BACKUP superblock/GDT copies in an
Mingming Cao617ba132006-10-11 01:20:53 -0700313 * ext4 filesystem. The counters should be initialized to 1, 5, and 7 before
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700314 * calling this for the first time. In a sparse filesystem it will be the
315 * sequence of powers of 3, 5, and 7: 1, 3, 5, 7, 9, 25, 27, 49, 81, ...
316 * For a non-sparse filesystem it will be every group: 1, 2, 3, 4, ...
317 */
Mingming Cao617ba132006-10-11 01:20:53 -0700318static unsigned ext4_list_backups(struct super_block *sb, unsigned *three,
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700319 unsigned *five, unsigned *seven)
320{
321 unsigned *min = three;
322 int mult = 3;
323 unsigned ret;
324
Mingming Cao617ba132006-10-11 01:20:53 -0700325 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
326 EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER)) {
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700327 ret = *min;
328 *min += 1;
329 return ret;
330 }
331
332 if (*five < *min) {
333 min = five;
334 mult = 5;
335 }
336 if (*seven < *min) {
337 min = seven;
338 mult = 7;
339 }
340
341 ret = *min;
342 *min *= mult;
343
344 return ret;
345}
346
347/*
348 * Check that all of the backup GDT blocks are held in the primary GDT block.
349 * It is assumed that they are stored in group order. Returns the number of
350 * groups in current filesystem that have BACKUPS, or -ve error code.
351 */
352static int verify_reserved_gdb(struct super_block *sb,
353 struct buffer_head *primary)
354{
Mingming Cao617ba132006-10-11 01:20:53 -0700355 const ext4_fsblk_t blk = primary->b_blocknr;
Avantika Mathurfd2d4292008-01-28 23:58:27 -0500356 const ext4_group_t end = EXT4_SB(sb)->s_groups_count;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700357 unsigned three = 1;
358 unsigned five = 5;
359 unsigned seven = 7;
360 unsigned grp;
361 __le32 *p = (__le32 *)primary->b_data;
362 int gdbackups = 0;
363
Mingming Cao617ba132006-10-11 01:20:53 -0700364 while ((grp = ext4_list_backups(sb, &three, &five, &seven)) < end) {
Laurent Vivierbd81d8e2006-10-11 01:21:10 -0700365 if (le32_to_cpu(*p++) !=
366 grp * EXT4_BLOCKS_PER_GROUP(sb) + blk){
Harvey Harrison46e665e2008-04-17 10:38:59 -0400367 ext4_warning(sb, __func__,
Mingming Cao2ae02102006-10-11 01:21:11 -0700368 "reserved GDT %llu"
369 " missing grp %d (%llu)",
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700370 blk, grp,
Laurent Vivierbd81d8e2006-10-11 01:21:10 -0700371 grp *
372 (ext4_fsblk_t)EXT4_BLOCKS_PER_GROUP(sb) +
373 blk);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700374 return -EINVAL;
375 }
Mingming Cao617ba132006-10-11 01:20:53 -0700376 if (++gdbackups > EXT4_ADDR_PER_BLOCK(sb))
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700377 return -EFBIG;
378 }
379
380 return gdbackups;
381}
382
383/*
384 * Called when we need to bring a reserved group descriptor table block into
385 * use from the resize inode. The primary copy of the new GDT block currently
386 * is an indirect block (under the double indirect block in the resize inode).
387 * The new backup GDT blocks will be stored as leaf blocks in this indirect
388 * block, in group order. Even though we know all the block numbers we need,
389 * we check to ensure that the resize inode has actually reserved these blocks.
390 *
391 * Don't need to update the block bitmaps because the blocks are still in use.
392 *
393 * We get all of the error cases out of the way, so that we are sure to not
394 * fail once we start modifying the data on disk, because JBD has no rollback.
395 */
396static int add_new_gdb(handle_t *handle, struct inode *inode,
Mingming Cao617ba132006-10-11 01:20:53 -0700397 struct ext4_new_group_data *input,
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700398 struct buffer_head **primary)
399{
400 struct super_block *sb = inode->i_sb;
Mingming Cao617ba132006-10-11 01:20:53 -0700401 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
402 unsigned long gdb_num = input->group / EXT4_DESC_PER_BLOCK(sb);
403 ext4_fsblk_t gdblock = EXT4_SB(sb)->s_sbh->b_blocknr + 1 + gdb_num;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700404 struct buffer_head **o_group_desc, **n_group_desc;
405 struct buffer_head *dind;
406 int gdbackups;
Mingming Cao617ba132006-10-11 01:20:53 -0700407 struct ext4_iloc iloc;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700408 __le32 *data;
409 int err;
410
411 if (test_opt(sb, DEBUG))
412 printk(KERN_DEBUG
Mingming Cao617ba132006-10-11 01:20:53 -0700413 "EXT4-fs: ext4_add_new_gdb: adding group block %lu\n",
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700414 gdb_num);
415
Theodore Ts'oaf5bc922008-09-08 22:25:24 -0400416 /*
417 * If we are not using the primary superblock/GDT copy don't resize,
Theodore Ts'o2b2d6d02008-07-26 16:15:44 -0400418 * because the user tools have no way of handling this. Probably a
419 * bad time to do it anyways.
420 */
Mingming Cao617ba132006-10-11 01:20:53 -0700421 if (EXT4_SB(sb)->s_sbh->b_blocknr !=
422 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block)) {
Harvey Harrison46e665e2008-04-17 10:38:59 -0400423 ext4_warning(sb, __func__,
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700424 "won't resize using backup superblock at %llu",
Mingming Cao617ba132006-10-11 01:20:53 -0700425 (unsigned long long)EXT4_SB(sb)->s_sbh->b_blocknr);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700426 return -EPERM;
427 }
428
429 *primary = sb_bread(sb, gdblock);
430 if (!*primary)
431 return -EIO;
432
433 if ((gdbackups = verify_reserved_gdb(sb, *primary)) < 0) {
434 err = gdbackups;
435 goto exit_bh;
436 }
437
Mingming Cao617ba132006-10-11 01:20:53 -0700438 data = EXT4_I(inode)->i_data + EXT4_DIND_BLOCK;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700439 dind = sb_bread(sb, le32_to_cpu(*data));
440 if (!dind) {
441 err = -EIO;
442 goto exit_bh;
443 }
444
445 data = (__le32 *)dind->b_data;
Mingming Cao617ba132006-10-11 01:20:53 -0700446 if (le32_to_cpu(data[gdb_num % EXT4_ADDR_PER_BLOCK(sb)]) != gdblock) {
Harvey Harrison46e665e2008-04-17 10:38:59 -0400447 ext4_warning(sb, __func__,
Mingming Cao2ae02102006-10-11 01:21:11 -0700448 "new group %u GDT block %llu not reserved",
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700449 input->group, gdblock);
450 err = -EINVAL;
451 goto exit_dind;
452 }
453
Mingming Cao617ba132006-10-11 01:20:53 -0700454 if ((err = ext4_journal_get_write_access(handle, EXT4_SB(sb)->s_sbh)))
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700455 goto exit_dind;
456
Mingming Cao617ba132006-10-11 01:20:53 -0700457 if ((err = ext4_journal_get_write_access(handle, *primary)))
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700458 goto exit_sbh;
459
Mingming Cao617ba132006-10-11 01:20:53 -0700460 if ((err = ext4_journal_get_write_access(handle, dind)))
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700461 goto exit_primary;
462
Mingming Cao617ba132006-10-11 01:20:53 -0700463 /* ext4_reserve_inode_write() gets a reference on the iloc */
464 if ((err = ext4_reserve_inode_write(handle, inode, &iloc)))
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700465 goto exit_dindj;
466
467 n_group_desc = kmalloc((gdb_num + 1) * sizeof(struct buffer_head *),
Josef Bacik216553c2008-04-29 22:02:02 -0400468 GFP_NOFS);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700469 if (!n_group_desc) {
470 err = -ENOMEM;
Harvey Harrison46e665e2008-04-17 10:38:59 -0400471 ext4_warning(sb, __func__,
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700472 "not enough memory for %lu groups", gdb_num + 1);
473 goto exit_inode;
474 }
475
476 /*
477 * Finally, we have all of the possible failures behind us...
478 *
479 * Remove new GDT block from inode double-indirect block and clear out
480 * the new GDT block for use (which also "frees" the backup GDT blocks
481 * from the reserved inode). We don't need to change the bitmaps for
482 * these blocks, because they are marked as in-use from being in the
483 * reserved inode, and will become GDT blocks (primary and backup).
484 */
Mingming Cao617ba132006-10-11 01:20:53 -0700485 data[gdb_num % EXT4_ADDR_PER_BLOCK(sb)] = 0;
Frank Mayhar03901312009-01-07 00:06:22 -0500486 ext4_handle_dirty_metadata(handle, NULL, dind);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700487 brelse(dind);
488 inode->i_blocks -= (gdbackups + 1) * sb->s_blocksize >> 9;
Mingming Cao617ba132006-10-11 01:20:53 -0700489 ext4_mark_iloc_dirty(handle, inode, &iloc);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700490 memset((*primary)->b_data, 0, sb->s_blocksize);
Frank Mayhar03901312009-01-07 00:06:22 -0500491 ext4_handle_dirty_metadata(handle, NULL, *primary);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700492
Mingming Cao617ba132006-10-11 01:20:53 -0700493 o_group_desc = EXT4_SB(sb)->s_group_desc;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700494 memcpy(n_group_desc, o_group_desc,
Mingming Cao617ba132006-10-11 01:20:53 -0700495 EXT4_SB(sb)->s_gdb_count * sizeof(struct buffer_head *));
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700496 n_group_desc[gdb_num] = *primary;
Mingming Cao617ba132006-10-11 01:20:53 -0700497 EXT4_SB(sb)->s_group_desc = n_group_desc;
498 EXT4_SB(sb)->s_gdb_count++;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700499 kfree(o_group_desc);
500
Marcin Slusarze8546d02008-04-17 10:38:59 -0400501 le16_add_cpu(&es->s_reserved_gdt_blocks, -1);
Frank Mayhar03901312009-01-07 00:06:22 -0500502 ext4_handle_dirty_metadata(handle, NULL, EXT4_SB(sb)->s_sbh);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700503
504 return 0;
505
506exit_inode:
Theodore Ts'o2b2d6d02008-07-26 16:15:44 -0400507 /* ext4_journal_release_buffer(handle, iloc.bh); */
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700508 brelse(iloc.bh);
509exit_dindj:
Theodore Ts'o2b2d6d02008-07-26 16:15:44 -0400510 /* ext4_journal_release_buffer(handle, dind); */
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700511exit_primary:
Theodore Ts'o2b2d6d02008-07-26 16:15:44 -0400512 /* ext4_journal_release_buffer(handle, *primary); */
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700513exit_sbh:
Theodore Ts'o2b2d6d02008-07-26 16:15:44 -0400514 /* ext4_journal_release_buffer(handle, *primary); */
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700515exit_dind:
516 brelse(dind);
517exit_bh:
518 brelse(*primary);
519
Mingming Cao617ba132006-10-11 01:20:53 -0700520 ext4_debug("leaving with error %d\n", err);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700521 return err;
522}
523
524/*
525 * Called when we are adding a new group which has a backup copy of each of
526 * the GDT blocks (i.e. sparse group) and there are reserved GDT blocks.
527 * We need to add these reserved backup GDT blocks to the resize inode, so
528 * that they are kept for future resizing and not allocated to files.
529 *
530 * Each reserved backup GDT block will go into a different indirect block.
531 * The indirect blocks are actually the primary reserved GDT blocks,
532 * so we know in advance what their block numbers are. We only get the
533 * double-indirect block to verify it is pointing to the primary reserved
534 * GDT blocks so we don't overwrite a data block by accident. The reserved
535 * backup GDT blocks are stored in their reserved primary GDT block.
536 */
537static int reserve_backup_gdb(handle_t *handle, struct inode *inode,
Mingming Cao617ba132006-10-11 01:20:53 -0700538 struct ext4_new_group_data *input)
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700539{
540 struct super_block *sb = inode->i_sb;
Mingming Cao617ba132006-10-11 01:20:53 -0700541 int reserved_gdb =le16_to_cpu(EXT4_SB(sb)->s_es->s_reserved_gdt_blocks);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700542 struct buffer_head **primary;
543 struct buffer_head *dind;
Mingming Cao617ba132006-10-11 01:20:53 -0700544 struct ext4_iloc iloc;
545 ext4_fsblk_t blk;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700546 __le32 *data, *end;
547 int gdbackups = 0;
548 int res, i;
549 int err;
550
Josef Bacik216553c2008-04-29 22:02:02 -0400551 primary = kmalloc(reserved_gdb * sizeof(*primary), GFP_NOFS);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700552 if (!primary)
553 return -ENOMEM;
554
Mingming Cao617ba132006-10-11 01:20:53 -0700555 data = EXT4_I(inode)->i_data + EXT4_DIND_BLOCK;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700556 dind = sb_bread(sb, le32_to_cpu(*data));
557 if (!dind) {
558 err = -EIO;
559 goto exit_free;
560 }
561
Mingming Cao617ba132006-10-11 01:20:53 -0700562 blk = EXT4_SB(sb)->s_sbh->b_blocknr + 1 + EXT4_SB(sb)->s_gdb_count;
Josef Bacik94460092008-06-06 18:05:52 -0400563 data = (__le32 *)dind->b_data + (EXT4_SB(sb)->s_gdb_count %
564 EXT4_ADDR_PER_BLOCK(sb));
Mingming Cao617ba132006-10-11 01:20:53 -0700565 end = (__le32 *)dind->b_data + EXT4_ADDR_PER_BLOCK(sb);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700566
567 /* Get each reserved primary GDT block and verify it holds backups */
568 for (res = 0; res < reserved_gdb; res++, blk++) {
569 if (le32_to_cpu(*data) != blk) {
Harvey Harrison46e665e2008-04-17 10:38:59 -0400570 ext4_warning(sb, __func__,
Mingming Cao2ae02102006-10-11 01:21:11 -0700571 "reserved block %llu"
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700572 " not at offset %ld",
573 blk,
574 (long)(data - (__le32 *)dind->b_data));
575 err = -EINVAL;
576 goto exit_bh;
577 }
578 primary[res] = sb_bread(sb, blk);
579 if (!primary[res]) {
580 err = -EIO;
581 goto exit_bh;
582 }
583 if ((gdbackups = verify_reserved_gdb(sb, primary[res])) < 0) {
584 brelse(primary[res]);
585 err = gdbackups;
586 goto exit_bh;
587 }
588 if (++data >= end)
589 data = (__le32 *)dind->b_data;
590 }
591
592 for (i = 0; i < reserved_gdb; i++) {
Mingming Cao617ba132006-10-11 01:20:53 -0700593 if ((err = ext4_journal_get_write_access(handle, primary[i]))) {
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700594 /*
595 int j;
596 for (j = 0; j < i; j++)
Mingming Cao617ba132006-10-11 01:20:53 -0700597 ext4_journal_release_buffer(handle, primary[j]);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700598 */
599 goto exit_bh;
600 }
601 }
602
Mingming Cao617ba132006-10-11 01:20:53 -0700603 if ((err = ext4_reserve_inode_write(handle, inode, &iloc)))
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700604 goto exit_bh;
605
606 /*
607 * Finally we can add each of the reserved backup GDT blocks from
608 * the new group to its reserved primary GDT block.
609 */
Mingming Cao617ba132006-10-11 01:20:53 -0700610 blk = input->group * EXT4_BLOCKS_PER_GROUP(sb);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700611 for (i = 0; i < reserved_gdb; i++) {
612 int err2;
613 data = (__le32 *)primary[i]->b_data;
614 /* printk("reserving backup %lu[%u] = %lu\n",
615 primary[i]->b_blocknr, gdbackups,
616 blk + primary[i]->b_blocknr); */
617 data[gdbackups] = cpu_to_le32(blk + primary[i]->b_blocknr);
Frank Mayhar03901312009-01-07 00:06:22 -0500618 err2 = ext4_handle_dirty_metadata(handle, NULL, primary[i]);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700619 if (!err)
620 err = err2;
621 }
622 inode->i_blocks += reserved_gdb * sb->s_blocksize >> 9;
Mingming Cao617ba132006-10-11 01:20:53 -0700623 ext4_mark_iloc_dirty(handle, inode, &iloc);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700624
625exit_bh:
626 while (--res >= 0)
627 brelse(primary[res]);
628 brelse(dind);
629
630exit_free:
631 kfree(primary);
632
633 return err;
634}
635
636/*
Mingming Cao617ba132006-10-11 01:20:53 -0700637 * Update the backup copies of the ext4 metadata. These don't need to be part
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700638 * of the main resize transaction, because e2fsck will re-write them if there
639 * is a problem (basically only OOM will cause a problem). However, we
640 * _should_ update the backups if possible, in case the primary gets trashed
641 * for some reason and we need to run e2fsck from a backup superblock. The
642 * important part is that the new block and inode counts are in the backup
643 * superblocks, and the location of the new group metadata in the GDT backups.
644 *
Theodore Ts'o32ed5052009-04-25 22:53:39 -0400645 * We do not need take the s_resize_lock for this, because these
646 * blocks are not otherwise touched by the filesystem code when it is
647 * mounted. We don't need to worry about last changing from
648 * sbi->s_groups_count, because the worst that can happen is that we
649 * do not copy the full number of backups at this time. The resize
650 * which changed s_groups_count will backup again.
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700651 */
652static void update_backups(struct super_block *sb,
653 int blk_off, char *data, int size)
654{
Mingming Cao617ba132006-10-11 01:20:53 -0700655 struct ext4_sb_info *sbi = EXT4_SB(sb);
Avantika Mathurfd2d4292008-01-28 23:58:27 -0500656 const ext4_group_t last = sbi->s_groups_count;
Mingming Cao617ba132006-10-11 01:20:53 -0700657 const int bpg = EXT4_BLOCKS_PER_GROUP(sb);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700658 unsigned three = 1;
659 unsigned five = 5;
660 unsigned seven = 7;
Avantika Mathurfd2d4292008-01-28 23:58:27 -0500661 ext4_group_t group;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700662 int rest = sb->s_blocksize - size;
663 handle_t *handle;
664 int err = 0, err2;
665
Mingming Cao617ba132006-10-11 01:20:53 -0700666 handle = ext4_journal_start_sb(sb, EXT4_MAX_TRANS_DATA);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700667 if (IS_ERR(handle)) {
668 group = 1;
669 err = PTR_ERR(handle);
670 goto exit_err;
671 }
672
Mingming Cao617ba132006-10-11 01:20:53 -0700673 while ((group = ext4_list_backups(sb, &three, &five, &seven)) < last) {
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700674 struct buffer_head *bh;
675
676 /* Out of journal space, and can't get more - abort - so sad */
Frank Mayhar03901312009-01-07 00:06:22 -0500677 if (ext4_handle_valid(handle) &&
678 handle->h_buffer_credits == 0 &&
Mingming Cao617ba132006-10-11 01:20:53 -0700679 ext4_journal_extend(handle, EXT4_MAX_TRANS_DATA) &&
680 (err = ext4_journal_restart(handle, EXT4_MAX_TRANS_DATA)))
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700681 break;
682
683 bh = sb_getblk(sb, group * bpg + blk_off);
684 if (!bh) {
685 err = -EIO;
686 break;
687 }
Mingming Cao617ba132006-10-11 01:20:53 -0700688 ext4_debug("update metadata backup %#04lx\n",
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700689 (unsigned long)bh->b_blocknr);
Mingming Cao617ba132006-10-11 01:20:53 -0700690 if ((err = ext4_journal_get_write_access(handle, bh)))
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700691 break;
692 lock_buffer(bh);
693 memcpy(bh->b_data, data, size);
694 if (rest)
695 memset(bh->b_data + size, 0, rest);
696 set_buffer_uptodate(bh);
697 unlock_buffer(bh);
Frank Mayhar03901312009-01-07 00:06:22 -0500698 ext4_handle_dirty_metadata(handle, NULL, bh);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700699 brelse(bh);
700 }
Mingming Cao617ba132006-10-11 01:20:53 -0700701 if ((err2 = ext4_journal_stop(handle)) && !err)
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700702 err = err2;
703
704 /*
705 * Ugh! Need to have e2fsck write the backup copies. It is too
706 * late to revert the resize, we shouldn't fail just because of
707 * the backup copies (they are only needed in case of corruption).
708 *
709 * However, if we got here we have a journal problem too, so we
710 * can't really start a transaction to mark the superblock.
711 * Chicken out and just set the flag on the hope it will be written
712 * to disk, and if not - we will simply wait until next fsck.
713 */
714exit_err:
715 if (err) {
Harvey Harrison46e665e2008-04-17 10:38:59 -0400716 ext4_warning(sb, __func__,
Theodore Ts'oa9df9a42009-01-05 22:18:16 -0500717 "can't update backup for group %u (err %d), "
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700718 "forcing fsck on next reboot", group, err);
Mingming Cao617ba132006-10-11 01:20:53 -0700719 sbi->s_mount_state &= ~EXT4_VALID_FS;
720 sbi->s_es->s_state &= cpu_to_le16(~EXT4_VALID_FS);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700721 mark_buffer_dirty(sbi->s_sbh);
722 }
723}
724
725/* Add group descriptor data to an existing or new group descriptor block.
726 * Ensure we handle all possible error conditions _before_ we start modifying
727 * the filesystem, because we cannot abort the transaction and not have it
728 * write the data to disk.
729 *
730 * If we are on a GDT block boundary, we need to get the reserved GDT block.
731 * Otherwise, we may need to add backup GDT blocks for a sparse group.
732 *
733 * We only need to hold the superblock lock while we are actually adding
734 * in the new group's counts to the superblock. Prior to that we have
735 * not really "added" the group at all. We re-check that we are still
736 * adding in the last group in case things have changed since verifying.
737 */
Mingming Cao617ba132006-10-11 01:20:53 -0700738int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input)
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700739{
Mingming Cao617ba132006-10-11 01:20:53 -0700740 struct ext4_sb_info *sbi = EXT4_SB(sb);
741 struct ext4_super_block *es = sbi->s_es;
742 int reserved_gdb = ext4_bg_has_super(sb, input->group) ?
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700743 le16_to_cpu(es->s_reserved_gdt_blocks) : 0;
744 struct buffer_head *primary = NULL;
Mingming Cao617ba132006-10-11 01:20:53 -0700745 struct ext4_group_desc *gdp;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700746 struct inode *inode = NULL;
747 handle_t *handle;
748 int gdb_off, gdb_num;
749 int err, err2;
750
Mingming Cao617ba132006-10-11 01:20:53 -0700751 gdb_num = input->group / EXT4_DESC_PER_BLOCK(sb);
752 gdb_off = input->group % EXT4_DESC_PER_BLOCK(sb);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700753
Mingming Cao617ba132006-10-11 01:20:53 -0700754 if (gdb_off == 0 && !EXT4_HAS_RO_COMPAT_FEATURE(sb,
755 EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER)) {
Harvey Harrison46e665e2008-04-17 10:38:59 -0400756 ext4_warning(sb, __func__,
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700757 "Can't resize non-sparse filesystem further");
758 return -EPERM;
759 }
760
Laurent Vivierbd81d8e2006-10-11 01:21:10 -0700761 if (ext4_blocks_count(es) + input->blocks_count <
762 ext4_blocks_count(es)) {
Theodore Ts'ofde4d952009-01-05 22:17:35 -0500763 ext4_warning(sb, __func__, "blocks_count overflow");
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700764 return -EINVAL;
765 }
766
Mingming Cao617ba132006-10-11 01:20:53 -0700767 if (le32_to_cpu(es->s_inodes_count) + EXT4_INODES_PER_GROUP(sb) <
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700768 le32_to_cpu(es->s_inodes_count)) {
Theodore Ts'ofde4d952009-01-05 22:17:35 -0500769 ext4_warning(sb, __func__, "inodes_count overflow");
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700770 return -EINVAL;
771 }
772
773 if (reserved_gdb || gdb_off == 0) {
Mingming Cao617ba132006-10-11 01:20:53 -0700774 if (!EXT4_HAS_COMPAT_FEATURE(sb,
Josef Bacik37609fd2008-08-19 22:13:41 -0400775 EXT4_FEATURE_COMPAT_RESIZE_INODE)
776 || !le16_to_cpu(es->s_reserved_gdt_blocks)) {
Harvey Harrison46e665e2008-04-17 10:38:59 -0400777 ext4_warning(sb, __func__,
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700778 "No reserved GDT blocks, can't resize");
779 return -EPERM;
780 }
David Howells1d1fe1e2008-02-07 00:15:37 -0800781 inode = ext4_iget(sb, EXT4_RESIZE_INO);
782 if (IS_ERR(inode)) {
Harvey Harrison46e665e2008-04-17 10:38:59 -0400783 ext4_warning(sb, __func__,
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700784 "Error opening resize inode");
David Howells1d1fe1e2008-02-07 00:15:37 -0800785 return PTR_ERR(inode);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700786 }
787 }
788
Aneesh Kumar K.V920313a2009-01-05 21:36:19 -0500789
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700790 if ((err = verify_group_input(sb, input)))
791 goto exit_put;
792
793 if ((err = setup_new_group_blocks(sb, input)))
794 goto exit_put;
795
796 /*
797 * We will always be modifying at least the superblock and a GDT
798 * block. If we are adding a group past the last current GDT block,
799 * we will also modify the inode and the dindirect block. If we
800 * are adding a group with superblock/GDT backups we will also
801 * modify each of the reserved GDT dindirect blocks.
802 */
Mingming Cao617ba132006-10-11 01:20:53 -0700803 handle = ext4_journal_start_sb(sb,
804 ext4_bg_has_super(sb, input->group) ?
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700805 3 + reserved_gdb : 4);
806 if (IS_ERR(handle)) {
807 err = PTR_ERR(handle);
808 goto exit_put;
809 }
810
Theodore Ts'o32ed5052009-04-25 22:53:39 -0400811 mutex_lock(&sbi->s_resize_lock);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700812 if (input->group != sbi->s_groups_count) {
Harvey Harrison46e665e2008-04-17 10:38:59 -0400813 ext4_warning(sb, __func__,
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700814 "multiple resizers run on filesystem!");
815 err = -EBUSY;
816 goto exit_journal;
817 }
818
Mingming Cao617ba132006-10-11 01:20:53 -0700819 if ((err = ext4_journal_get_write_access(handle, sbi->s_sbh)))
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700820 goto exit_journal;
821
Theodore Ts'o2b2d6d02008-07-26 16:15:44 -0400822 /*
823 * We will only either add reserved group blocks to a backup group
824 * or remove reserved blocks for the first group in a new group block.
825 * Doing both would be mean more complex code, and sane people don't
826 * use non-sparse filesystems anymore. This is already checked above.
827 */
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700828 if (gdb_off) {
829 primary = sbi->s_group_desc[gdb_num];
Mingming Cao617ba132006-10-11 01:20:53 -0700830 if ((err = ext4_journal_get_write_access(handle, primary)))
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700831 goto exit_journal;
832
Mingming Cao617ba132006-10-11 01:20:53 -0700833 if (reserved_gdb && ext4_bg_num_gdb(sb, input->group) &&
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700834 (err = reserve_backup_gdb(handle, inode, input)))
835 goto exit_journal;
836 } else if ((err = add_new_gdb(handle, inode, input, &primary)))
837 goto exit_journal;
838
Theodore Ts'o2b2d6d02008-07-26 16:15:44 -0400839 /*
840 * OK, now we've set up the new group. Time to make it active.
841 *
Theodore Ts'o32ed5052009-04-25 22:53:39 -0400842 * We do not lock all allocations via s_resize_lock
Theodore Ts'o2b2d6d02008-07-26 16:15:44 -0400843 * so we have to be safe wrt. concurrent accesses the group
844 * data. So we need to be careful to set all of the relevant
845 * group descriptor data etc. *before* we enable the group.
846 *
847 * The key field here is sbi->s_groups_count: as long as
848 * that retains its old value, nobody is going to access the new
849 * group.
850 *
851 * So first we update all the descriptor metadata for the new
852 * group; then we update the total disk blocks count; then we
853 * update the groups count to enable the group; then finally we
854 * update the free space counts so that the system can start
855 * using the new disk blocks.
856 */
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700857
858 /* Update group descriptor block for new group */
Frederic Bohe28569222008-06-20 11:48:48 -0400859 gdp = (struct ext4_group_desc *)((char *)primary->b_data +
860 gdb_off * EXT4_DESC_SIZE(sb));
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700861
Theodore Ts'ofdff73f2009-01-26 19:06:41 -0500862 memset(gdp, 0, EXT4_DESC_SIZE(sb));
Alexandre Ratchov8fadc142006-10-11 01:21:15 -0700863 ext4_block_bitmap_set(sb, gdp, input->block_bitmap); /* LV FIXME */
864 ext4_inode_bitmap_set(sb, gdp, input->inode_bitmap); /* LV FIXME */
865 ext4_inode_table_set(sb, gdp, input->inode_table); /* LV FIXME */
Aneesh Kumar K.V560671a2009-01-05 22:20:24 -0500866 ext4_free_blks_set(sb, gdp, input->free_blocks_count);
867 ext4_free_inodes_set(sb, gdp, EXT4_INODES_PER_GROUP(sb));
Theodore Ts'ofdff73f2009-01-26 19:06:41 -0500868 gdp->bg_flags = cpu_to_le16(EXT4_BG_INODE_ZEROED);
Andreas Dilger717d50e2007-10-16 18:38:25 -0400869 gdp->bg_checksum = ext4_group_desc_csum(sbi, input->group, gdp);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700870
871 /*
Frederic Bohe5f21b0e2008-07-11 19:27:31 -0400872 * We can allocate memory for mb_alloc based on the new group
873 * descriptor
874 */
Aneesh Kumar K.V920313a2009-01-05 21:36:19 -0500875 err = ext4_mb_add_groupinfo(sb, input->group, gdp);
Aneesh Kumar K.V08c3a812009-09-09 23:50:17 -0400876 if (err)
Theodore Ts'oc2ea3fd2008-10-10 09:40:52 -0400877 goto exit_journal;
878
Frederic Bohe5f21b0e2008-07-11 19:27:31 -0400879 /*
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700880 * Make the new blocks and inodes valid next. We do this before
881 * increasing the group count so that once the group is enabled,
882 * all of its blocks and inodes are already valid.
883 *
884 * We always allocate group-by-group, then block-by-block or
885 * inode-by-inode within a group, so enabling these
886 * blocks/inodes before the group is live won't actually let us
887 * allocate the new space yet.
888 */
Laurent Vivierbd81d8e2006-10-11 01:21:10 -0700889 ext4_blocks_count_set(es, ext4_blocks_count(es) +
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700890 input->blocks_count);
Marcin Slusarze8546d02008-04-17 10:38:59 -0400891 le32_add_cpu(&es->s_inodes_count, EXT4_INODES_PER_GROUP(sb));
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700892
893 /*
894 * We need to protect s_groups_count against other CPUs seeing
895 * inconsistent state in the superblock.
896 *
897 * The precise rules we use are:
898 *
Theodore Ts'o32ed5052009-04-25 22:53:39 -0400899 * * Writers of s_groups_count *must* hold s_resize_lock
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700900 * AND
901 * * Writers must perform a smp_wmb() after updating all dependent
902 * data and before modifying the groups count
903 *
Theodore Ts'o32ed5052009-04-25 22:53:39 -0400904 * * Readers must hold s_resize_lock over the access
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700905 * OR
906 * * Readers must perform an smp_rmb() after reading the groups count
907 * and before reading any dependent data.
908 *
909 * NB. These rules can be relaxed when checking the group count
910 * while freeing data, as we can only allocate from a block
911 * group after serialising against the group count, and we can
912 * only then free after serialising in turn against that
913 * allocation.
914 */
915 smp_wmb();
916
917 /* Update the global fs size fields */
918 sbi->s_groups_count++;
919
Frank Mayhar03901312009-01-07 00:06:22 -0500920 ext4_handle_dirty_metadata(handle, NULL, primary);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700921
922 /* Update the reserved block counts only once the new group is
923 * active. */
Laurent Vivierbd81d8e2006-10-11 01:21:10 -0700924 ext4_r_blocks_count_set(es, ext4_r_blocks_count(es) +
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700925 input->reserved_blocks);
926
927 /* Update the free space counts */
Peter Zijlstraaa0dff22007-10-16 23:25:42 -0700928 percpu_counter_add(&sbi->s_freeblocks_counter,
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700929 input->free_blocks_count);
Peter Zijlstraaa0dff22007-10-16 23:25:42 -0700930 percpu_counter_add(&sbi->s_freeinodes_counter,
Mingming Cao617ba132006-10-11 01:20:53 -0700931 EXT4_INODES_PER_GROUP(sb));
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700932
Frederic Bohec62a11f2008-09-08 10:20:24 -0400933 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG)) {
934 ext4_group_t flex_group;
935 flex_group = ext4_flex_group(sbi, input->group);
Theodore Ts'o9f24e422009-03-04 19:09:10 -0500936 atomic_add(input->free_blocks_count,
937 &sbi->s_flex_groups[flex_group].free_blocks);
938 atomic_add(EXT4_INODES_PER_GROUP(sb),
939 &sbi->s_flex_groups[flex_group].free_inodes);
Frederic Bohec62a11f2008-09-08 10:20:24 -0400940 }
941
Frank Mayhar03901312009-01-07 00:06:22 -0500942 ext4_handle_dirty_metadata(handle, NULL, sbi->s_sbh);
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700943 sb->s_dirt = 1;
944
945exit_journal:
Theodore Ts'o32ed5052009-04-25 22:53:39 -0400946 mutex_unlock(&sbi->s_resize_lock);
Mingming Cao617ba132006-10-11 01:20:53 -0700947 if ((err2 = ext4_journal_stop(handle)) && !err)
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700948 err = err2;
949 if (!err) {
950 update_backups(sb, sbi->s_sbh->b_blocknr, (char *)es,
Mingming Cao617ba132006-10-11 01:20:53 -0700951 sizeof(struct ext4_super_block));
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700952 update_backups(sb, primary->b_blocknr, primary->b_data,
953 primary->b_size);
954 }
955exit_put:
956 iput(inode);
957 return err;
Mingming Cao617ba132006-10-11 01:20:53 -0700958} /* ext4_group_add */
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700959
Theodore Ts'o2b2d6d02008-07-26 16:15:44 -0400960/*
961 * Extend the filesystem to the new number of blocks specified. This entry
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700962 * point is only used to extend the current filesystem to the end of the last
963 * existing group. It can be accessed via ioctl, or by "remount,resize=<size>"
964 * for emergencies (because it has no dependencies on reserved blocks).
965 *
Mingming Cao617ba132006-10-11 01:20:53 -0700966 * If we _really_ wanted, we could use default values to call ext4_group_add()
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700967 * allow the "remount" trick to work for arbitrary resizing, assuming enough
968 * GDT blocks are reserved to grow to the desired size.
969 */
Mingming Cao617ba132006-10-11 01:20:53 -0700970int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es,
971 ext4_fsblk_t n_blocks_count)
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700972{
Mingming Cao617ba132006-10-11 01:20:53 -0700973 ext4_fsblk_t o_blocks_count;
Avantika Mathurfd2d4292008-01-28 23:58:27 -0500974 ext4_group_t o_groups_count;
Mingming Cao617ba132006-10-11 01:20:53 -0700975 ext4_grpblk_t last;
976 ext4_grpblk_t add;
Theodore Ts'oaf5bc922008-09-08 22:25:24 -0400977 struct buffer_head *bh;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700978 handle_t *handle;
979 int err;
Frederic Bohe5f21b0e2008-07-11 19:27:31 -0400980 ext4_group_t group;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700981
982 /* We don't need to worry about locking wrt other resizers just
983 * yet: we're going to revalidate es->s_blocks_count after
Theodore Ts'o32ed5052009-04-25 22:53:39 -0400984 * taking the s_resize_lock below. */
Laurent Vivierbd81d8e2006-10-11 01:21:10 -0700985 o_blocks_count = ext4_blocks_count(es);
Mingming Cao617ba132006-10-11 01:20:53 -0700986 o_groups_count = EXT4_SB(sb)->s_groups_count;
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700987
988 if (test_opt(sb, DEBUG))
Mingming Cao2ae02102006-10-11 01:21:11 -0700989 printk(KERN_DEBUG "EXT4-fs: extending last group from %llu uto %llu blocks\n",
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700990 o_blocks_count, n_blocks_count);
991
992 if (n_blocks_count == 0 || n_blocks_count == o_blocks_count)
993 return 0;
994
995 if (n_blocks_count > (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) {
Mingming Cao617ba132006-10-11 01:20:53 -0700996 printk(KERN_ERR "EXT4-fs: filesystem on %s:"
Mingming Cao2ae02102006-10-11 01:21:11 -0700997 " too large to resize to %llu blocks safely\n",
Dave Kleikampac27a0e2006-10-11 01:20:50 -0700998 sb->s_id, n_blocks_count);
999 if (sizeof(sector_t) < 8)
Bartlomiej Zolnierkiewicz90c699a2009-06-19 08:08:50 +02001000 ext4_warning(sb, __func__, "CONFIG_LBDAF not enabled");
Dave Kleikampac27a0e2006-10-11 01:20:50 -07001001 return -EINVAL;
1002 }
1003
1004 if (n_blocks_count < o_blocks_count) {
Harvey Harrison46e665e2008-04-17 10:38:59 -04001005 ext4_warning(sb, __func__,
Dave Kleikampac27a0e2006-10-11 01:20:50 -07001006 "can't shrink FS - resize aborted");
1007 return -EBUSY;
1008 }
1009
1010 /* Handle the remaining blocks in the last group only. */
Frederic Bohe5f21b0e2008-07-11 19:27:31 -04001011 ext4_get_group_no_and_offset(sb, o_blocks_count, &group, &last);
Dave Kleikampac27a0e2006-10-11 01:20:50 -07001012
1013 if (last == 0) {
Harvey Harrison46e665e2008-04-17 10:38:59 -04001014 ext4_warning(sb, __func__,
Dave Kleikampac27a0e2006-10-11 01:20:50 -07001015 "need to use ext2online to resize further");
1016 return -EPERM;
1017 }
1018
Mingming Cao617ba132006-10-11 01:20:53 -07001019 add = EXT4_BLOCKS_PER_GROUP(sb) - last;
Dave Kleikampac27a0e2006-10-11 01:20:50 -07001020
1021 if (o_blocks_count + add < o_blocks_count) {
Harvey Harrison46e665e2008-04-17 10:38:59 -04001022 ext4_warning(sb, __func__, "blocks_count overflow");
Dave Kleikampac27a0e2006-10-11 01:20:50 -07001023 return -EINVAL;
1024 }
1025
1026 if (o_blocks_count + add > n_blocks_count)
1027 add = n_blocks_count - o_blocks_count;
1028
1029 if (o_blocks_count + add < n_blocks_count)
Harvey Harrison46e665e2008-04-17 10:38:59 -04001030 ext4_warning(sb, __func__,
Mingming Cao2ae02102006-10-11 01:21:11 -07001031 "will only finish group (%llu"
Dave Kleikampac27a0e2006-10-11 01:20:50 -07001032 " blocks, %u new)",
1033 o_blocks_count + add, add);
1034
1035 /* See if the device is actually as big as what was requested */
Theodore Ts'o2b2d6d02008-07-26 16:15:44 -04001036 bh = sb_bread(sb, o_blocks_count + add - 1);
Dave Kleikampac27a0e2006-10-11 01:20:50 -07001037 if (!bh) {
Harvey Harrison46e665e2008-04-17 10:38:59 -04001038 ext4_warning(sb, __func__,
Dave Kleikampac27a0e2006-10-11 01:20:50 -07001039 "can't read last block, resize aborted");
1040 return -ENOSPC;
1041 }
1042 brelse(bh);
1043
1044 /* We will update the superblock, one block bitmap, and
Mingming Cao617ba132006-10-11 01:20:53 -07001045 * one group descriptor via ext4_free_blocks().
Dave Kleikampac27a0e2006-10-11 01:20:50 -07001046 */
Mingming Cao617ba132006-10-11 01:20:53 -07001047 handle = ext4_journal_start_sb(sb, 3);
Dave Kleikampac27a0e2006-10-11 01:20:50 -07001048 if (IS_ERR(handle)) {
1049 err = PTR_ERR(handle);
Harvey Harrison46e665e2008-04-17 10:38:59 -04001050 ext4_warning(sb, __func__, "error %d on journal start", err);
Dave Kleikampac27a0e2006-10-11 01:20:50 -07001051 goto exit_put;
1052 }
1053
Theodore Ts'o32ed5052009-04-25 22:53:39 -04001054 mutex_lock(&EXT4_SB(sb)->s_resize_lock);
Laurent Vivierbd81d8e2006-10-11 01:21:10 -07001055 if (o_blocks_count != ext4_blocks_count(es)) {
Harvey Harrison46e665e2008-04-17 10:38:59 -04001056 ext4_warning(sb, __func__,
Dave Kleikampac27a0e2006-10-11 01:20:50 -07001057 "multiple resizers run on filesystem!");
Theodore Ts'o32ed5052009-04-25 22:53:39 -04001058 mutex_unlock(&EXT4_SB(sb)->s_resize_lock);
Akinobu Mita5606bf52008-02-25 15:37:42 -05001059 ext4_journal_stop(handle);
Dave Kleikampac27a0e2006-10-11 01:20:50 -07001060 err = -EBUSY;
1061 goto exit_put;
1062 }
1063
Mingming Cao617ba132006-10-11 01:20:53 -07001064 if ((err = ext4_journal_get_write_access(handle,
1065 EXT4_SB(sb)->s_sbh))) {
Harvey Harrison46e665e2008-04-17 10:38:59 -04001066 ext4_warning(sb, __func__,
Dave Kleikampac27a0e2006-10-11 01:20:50 -07001067 "error %d on journal write access", err);
Theodore Ts'o32ed5052009-04-25 22:53:39 -04001068 mutex_unlock(&EXT4_SB(sb)->s_resize_lock);
Mingming Cao617ba132006-10-11 01:20:53 -07001069 ext4_journal_stop(handle);
Dave Kleikampac27a0e2006-10-11 01:20:50 -07001070 goto exit_put;
1071 }
Laurent Vivierbd81d8e2006-10-11 01:21:10 -07001072 ext4_blocks_count_set(es, o_blocks_count + add);
Frank Mayhar03901312009-01-07 00:06:22 -05001073 ext4_handle_dirty_metadata(handle, NULL, EXT4_SB(sb)->s_sbh);
Dave Kleikampac27a0e2006-10-11 01:20:50 -07001074 sb->s_dirt = 1;
Theodore Ts'o32ed5052009-04-25 22:53:39 -04001075 mutex_unlock(&EXT4_SB(sb)->s_resize_lock);
Eric Sandeenc549a952008-01-28 23:58:27 -05001076 ext4_debug("freeing blocks %llu through %llu\n", o_blocks_count,
Dave Kleikampac27a0e2006-10-11 01:20:50 -07001077 o_blocks_count + add);
Aneesh Kumar K.Ve21675d2009-01-05 21:36:02 -05001078 /* We add the blocks to the bitmap and set the group need init bit */
1079 ext4_add_groupblocks(handle, sb, o_blocks_count, add);
Mingming Cao2ae02102006-10-11 01:21:11 -07001080 ext4_debug("freed blocks %llu through %llu\n", o_blocks_count,
Dave Kleikampac27a0e2006-10-11 01:20:50 -07001081 o_blocks_count + add);
Mingming Cao617ba132006-10-11 01:20:53 -07001082 if ((err = ext4_journal_stop(handle)))
Dave Kleikampac27a0e2006-10-11 01:20:50 -07001083 goto exit_put;
Frederic Bohe5f21b0e2008-07-11 19:27:31 -04001084
Dave Kleikampac27a0e2006-10-11 01:20:50 -07001085 if (test_opt(sb, DEBUG))
Laurent Vivierbd81d8e2006-10-11 01:21:10 -07001086 printk(KERN_DEBUG "EXT4-fs: extended group to %llu blocks\n",
1087 ext4_blocks_count(es));
Mingming Cao617ba132006-10-11 01:20:53 -07001088 update_backups(sb, EXT4_SB(sb)->s_sbh->b_blocknr, (char *)es,
1089 sizeof(struct ext4_super_block));
Dave Kleikampac27a0e2006-10-11 01:20:50 -07001090exit_put:
1091 return err;
Mingming Cao617ba132006-10-11 01:20:53 -07001092} /* ext4_group_extend */