aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2013-01-20 00:25:00 -0500
committerTheodore Ts'o <tytso@mit.edu>2013-01-20 00:25:00 -0500
commitd1a1a583c13dd43e828f28c9c93cc53df715c891 (patch)
tree2bb235399b3b3e46dc663a39495ec5ca2342390c
parent1773c87c7e9ee5c4b8753919320d6d06910ea25b (diff)
downloade2fsprogs-d1a1a583c13dd43e828f28c9c93cc53df715c891.tar.gz
e2fsprogs-d1a1a583c13dd43e828f28c9c93cc53df715c891.tar.xz
e2fsprogs-d1a1a583c13dd43e828f28c9c93cc53df715c891.zip
resize2fs: move a cluster at a time with bigalloc file systems
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
-rw-r--r--resize/resize2fs.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/resize/resize2fs.c b/resize/resize2fs.c
index 6885aeb2..c9458ea6 100644
--- a/resize/resize2fs.c
+++ b/resize/resize2fs.c
@@ -1178,8 +1178,9 @@ static errcode_t block_mover(ext2_resize_t rfs)
*/
to_move = moved = 0;
init_block_alloc(rfs);
- for (blk = old_fs->super->s_first_data_block;
- blk < ext2fs_blocks_count(old_fs->super); blk++) {
+ for (blk = B2C(old_fs->super->s_first_data_block);
+ blk < ext2fs_blocks_count(old_fs->super);
+ blk += EXT2FS_CLUSTER_RATIO(fs)) {
if (!ext2fs_test_block_bitmap2(old_fs->block_map, blk))
continue;
if (!ext2fs_test_block_bitmap2(rfs->move_blocks, blk))
@@ -1196,7 +1197,7 @@ static errcode_t block_mover(ext2_resize_t rfs)
goto errout;
}
ext2fs_block_alloc_stats2(fs, new_blk, +1);
- ext2fs_add_extent_entry(rfs->bmap, blk, new_blk);
+ ext2fs_add_extent_entry(rfs->bmap, B2C(blk), B2C(new_blk));
to_move++;
}
@@ -1226,6 +1227,9 @@ static errcode_t block_mover(ext2_resize_t rfs)
if (retval) goto errout;
if (!size)
break;
+ old_blk = C2B(old_blk);
+ new_blk = C2B(new_blk);
+ size = C2B(size);
#ifdef RESIZE2FS_DEBUG
if (rfs->flags & RESIZE_DEBUG_BMOVE)
printf("Moving %llu blocks %llu->%llu\n",
@@ -1276,6 +1280,20 @@ errout:
*/
+/*
+ * The extent translation table is stored in clusters so we need to
+ * take special care when mapping a source block number to its
+ * destination block number.
+ */
+__u64 extent_translate(ext2_filsys fs, ext2_extent extent, __u64 old_loc)
+{
+ __u64 new_block = C2B(ext2fs_extent_translate(extent, B2C(old_loc)));
+
+ if (new_block != 0)
+ new_block += old_loc & (EXT2FS_CLUSTER_RATIO(fs) - 1);
+ return new_block;
+}
+
struct process_block_struct {
ext2_resize_t rfs;
ext2_ino_t ino;
@@ -1298,7 +1316,7 @@ static int process_block(ext2_filsys fs, blk64_t *block_nr,
pb = (struct process_block_struct *) priv_data;
block = *block_nr;
if (pb->rfs->bmap) {
- new_block = ext2fs_extent_translate(pb->rfs->bmap, block);
+ new_block = extent_translate(fs, pb->rfs->bmap, block);
if (new_block) {
*block_nr = new_block;
ret |= BLOCK_CHANGED;
@@ -1424,7 +1442,7 @@ static errcode_t inode_scan_and_fix(ext2_resize_t rfs)
pb.changed = 0;
if (ext2fs_file_acl_block(rfs->old_fs, inode) && rfs->bmap) {
- new_block = ext2fs_extent_translate(rfs->bmap,
+ new_block = extent_translate(rfs->old_fs, rfs->bmap,
ext2fs_file_acl_block(rfs->old_fs, inode));
if (new_block) {
ext2fs_file_acl_block_set(rfs->old_fs, inode,