17 #define outside(b, first, last) ((b) < (first) || (b) >= (last))
18 #define inside(b, first, last) ((b) >= (first) && (b) < (last))
33 struct buffer_head *bh =
NULL;
42 "(%d free, %u reserved)\n",
49 "Cannot add at group %u (only %lu groups)",
55 ext3_warning(sb, __func__,
"Reserved blocks too high (%u)",
57 else if (free_blocks_count < 0)
60 else if (!(bh = sb_bread(sb, end - 1)))
62 "Cannot read last block ("E3FSBLK")",
66 "Block bitmap not in group (block %u)",
70 "Inode bitmap not in group (block %u)",
75 "Inode table not in group (blocks %u-"E3FSBLK")",
79 "Block bitmap same as inode bitmap (%u)",
83 "Block bitmap (%u) in inode table (%u-"E3FSBLK")",
87 "Inode bitmap (%u) in inode table (%u-"E3FSBLK")",
91 "Block bitmap (%u) in GDT table"
96 "Inode bitmap (%u) in GDT table"
97 " ("E3FSBLK
"-"E3FSBLK
")",
100 inside(itend - 1, start, metaend))
102 "Inode table (%u-"E3FSBLK
") overlaps"
103 "GDT table ("E3FSBLK
"-"E3FSBLK
")",
104 input->
inode_table, itend - 1, start, metaend - 1);
115 struct buffer_head *bh;
118 bh = sb_getblk(sb, blk);
120 return ERR_PTR(-
EIO);
127 set_buffer_uptodate(bh);
143 if (start_bit >= end_bit)
146 ext3_debug(
"mark end bits +%d through +%d used\n", start_bit, end_bit);
147 for (i = start_bit; i < ((start_bit + 7) & ~7
UL); i++)
150 memset(bitmap + (i >> 3), 0xff, (end_bit - i) >> 3);
158 static int extend_or_restart_transaction(handle_t *handle,
int thresh,
159 struct buffer_head *bh)
163 if (handle->h_buffer_credits >= thresh)
188 static int setup_new_group_blocks(
struct super_block *sb,
196 struct buffer_head *bh;
207 return PTR_ERR(handle);
215 if (IS_ERR(bh = bclean(handle, sb, input->
block_bitmap))) {
221 ext3_debug(
"mark backup superblock %#04lx (+0)\n", start);
226 for (i = 0, bit = 1, block = start + 1;
227 i < gdblocks; i++, block++, bit++) {
228 struct buffer_head *gdb;
230 ext3_debug(
"update backup group %#04lx (+%d)\n", block, bit);
232 err = extend_or_restart_transaction(handle, 1, bh);
236 gdb = sb_getblk(sb, block);
247 set_buffer_uptodate(gdb);
259 for (i = 0, bit = gdblocks + 1, block = start + bit;
260 i < reserved_gdb; i++, block++, bit++) {
261 struct buffer_head *gdb;
263 ext3_debug(
"clear reserved block %#04lx (+%d)\n", block, bit);
265 err = extend_or_restart_transaction(handle, 1, bh);
269 if (IS_ERR(gdb = bclean(handle, sb, block))) {
289 for (i = 0, block = input->
inode_table, bit = block - start;
290 i < sbi->s_itb_per_group; i++, bit++, block++) {
291 struct buffer_head *it;
293 ext3_debug(
"clear inode block %#04lx (+%d)\n", block, bit);
295 err = extend_or_restart_transaction(handle, 1, bh);
299 if (IS_ERR(it = bclean(handle, sb, block))) {
312 err = extend_or_restart_transaction(handle, 2, bh);
324 ext3_debug(
"clear inode bitmap %#04x (+%ld)\n",
326 if (IS_ERR(bh = bclean(handle, sb, input->
inode_bitmap))) {
352 static unsigned ext3_list_backups(
struct super_block *sb,
unsigned *three,
353 unsigned *five,
unsigned *seven)
355 unsigned *
min = three;
386 static int verify_reserved_gdb(
struct super_block *sb,
390 const unsigned long end = EXT3_SB(sb)->s_groups_count;
398 while ((grp = ext3_list_backups(sb, &three, &five, &seven)) <
end) {
427 static int add_new_gdb(handle_t *handle,
struct inode *
inode,
429 struct buffer_head **primary)
434 ext3_fsblk_t gdblock = EXT3_SB(sb)->s_sbh->b_blocknr + 1 + gdb_num;
435 struct buffer_head **o_group_desc, **n_group_desc;
436 struct buffer_head *dind;
444 "EXT3-fs: ext3_add_new_gdb: adding group block %lu\n",
452 if (EXT3_SB(sb)->s_sbh->b_blocknr !=
453 le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block)) {
455 "won't resize using backup superblock at %llu",
456 (
unsigned long long)EXT3_SB(sb)->s_sbh->b_blocknr);
460 *primary = sb_bread(sb, gdblock);
464 if ((gdbackups = verify_reserved_gdb(sb, *primary)) < 0) {
476 data = (
__le32 *)dind->b_data;
479 "new group %u GDT block "E3FSBLK" not reserved",
480 input->
group, gdblock);
498 n_group_desc =
kmalloc((gdb_num + 1) *
sizeof(
struct buffer_head *),
503 "not enough memory for %lu groups", gdb_num + 1);
519 goto exit_group_desc;
525 goto exit_group_desc;
529 goto exit_group_desc;
531 o_group_desc = EXT3_SB(sb)->s_group_desc;
532 memcpy(n_group_desc, o_group_desc,
533 EXT3_SB(sb)->s_gdb_count *
sizeof(
struct buffer_head *));
534 n_group_desc[gdb_num] = *
primary;
535 EXT3_SB(sb)->s_group_desc = n_group_desc;
536 EXT3_SB(sb)->s_gdb_count++;
579 static int reserve_backup_gdb(handle_t *handle,
struct inode *inode,
583 int reserved_gdb =
le16_to_cpu(EXT3_SB(sb)->s_es->s_reserved_gdt_blocks);
585 struct buffer_head *dind;
604 blk = EXT3_SB(sb)->s_sbh->b_blocknr + 1 + EXT3_SB(sb)->s_gdb_count;
605 data = (
__le32 *)dind->b_data + (EXT3_SB(sb)->s_gdb_count %
610 for (res = 0; res < reserved_gdb; res++, blk++) {
614 " not at offset %ld",
616 (
long)(data - (
__le32 *)dind->b_data));
620 primary[
res] = sb_bread(sb, blk);
625 if ((gdbackups = verify_reserved_gdb(sb, primary[res])) < 0) {
626 brelse(primary[res]);
631 data = (
__le32 *)dind->b_data;
634 for (i = 0; i < reserved_gdb; i++) {
653 for (i = 0; i < reserved_gdb; i++) {
655 data = (
__le32 *)primary[i]->b_data;
659 data[gdbackups] =
cpu_to_le32(blk + primary[i]->b_blocknr);
669 brelse(primary[res]);
695 int blk_off,
char *data,
int size)
709 if (IS_ERR(handle)) {
711 err = PTR_ERR(handle);
715 while ((group = ext3_list_backups(sb, &three, &five, &seven)) < last) {
716 struct buffer_head *bh;
719 if (handle->h_buffer_credits == 0 &&
724 bh = sb_getblk(sb, group * bpg + blk_off);
730 (
unsigned long)bh->b_blocknr);
736 memcpy(bh->b_data, data, size);
738 memset(bh->b_data + size, 0, rest);
739 set_buffer_uptodate(bh);
762 "can't update backup for group %d (err %d), "
763 "forcing fsck on next reboot", group, err);
789 struct buffer_head *primary =
NULL;
791 struct inode *inode =
NULL;
793 int gdb_off, gdb_num;
802 "Can't resize non-sparse filesystem further");
818 if (reserved_gdb || gdb_off == 0) {
823 "No reserved GDT blocks, can't resize");
829 "Error opening resize inode");
830 return PTR_ERR(inode);
834 if ((err = verify_group_input(sb, input)))
837 if ((err = setup_new_group_blocks(sb, input)))
849 3 + reserved_gdb : 4);
850 if (IS_ERR(handle)) {
851 err = PTR_ERR(handle);
858 "multiple resizers run on filesystem!");
878 (err = reserve_backup_gdb(handle, inode, input)))
880 }
else if ((err = add_new_gdb(handle, inode, input, &primary)))
972 update_backups(sb, sbi->
s_sbh->b_blocknr, (
char *)es,
974 update_backups(sb, primary->b_blocknr, primary->b_data,
997 struct buffer_head * bh;
1000 unsigned long freed_blocks;
1010 o_blocks_count, n_blocks_count);
1012 if (n_blocks_count == 0 || n_blocks_count == o_blocks_count)
1017 " too large to resize to "E3FSBLK
" blocks safely\n",
1018 sb->
s_id, n_blocks_count);
1021 "CONFIG_LBDAF not enabled\n");
1025 if (n_blocks_count < o_blocks_count) {
1027 "can't shrink FS - resize aborted");
1037 "need to use ext2online to resize further");
1043 if (o_blocks_count + add < o_blocks_count) {
1048 if (o_blocks_count + add > n_blocks_count)
1049 add = n_blocks_count - o_blocks_count;
1051 if (o_blocks_count + add < n_blocks_count)
1053 "will only finish group ("E3FSBLK
1055 o_blocks_count + add, add);
1058 bh = sb_bread(sb, o_blocks_count + add -1);
1061 "can't read last block, resize aborted");
1070 if (IS_ERR(handle)) {
1071 err = PTR_ERR(handle);
1072 ext3_warning(sb, __func__,
"error %d on journal start",err);
1079 "multiple resizers run on filesystem!");
1087 EXT3_SB(sb)->s_sbh))) {
1089 "error %d on journal write access", err);
1099 "error %d on journal dirty metadata", err);
1103 ext3_debug(
"freeing blocks "E3FSBLK
" through "E3FSBLK
"\n",
1104 o_blocks_count, o_blocks_count + add);
1106 ext3_debug(
"freed blocks "E3FSBLK
" through "E3FSBLK
"\n",
1107 o_blocks_count, o_blocks_count + add);
1113 update_backups(sb, EXT3_SB(sb)->s_sbh->b_blocknr, (
char *)es,