Skip to contentSkip to conversation

btrfs-progs: convert fixes + reiserfs support

PATCH In review [email protected] 4 participants 13 messages Jul 27, 2017 – Aug 22, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover btrfs-progs: convert fixes + reiserfs support

From: Jeff Mahoney <[email protected]>

Changes since v1:
- reiserfs conversion:
- use bool instead of int
- catch 'impossible' condition of multiple discontiguous tails
- properly handle hole followed by tail
- add testing for combinations of real blocks, tails, and holes
- print error indicating filename (and key) that caused a failure
- constify buffer arg to btrfs_insert_inline_extent
- add tails=on to reiserfs mount options
- fixed absence of libreiserfscore to be non-fatal unless specificially enabled

- btrfs-progs: convert: use search_cache_extent in migrate_one_reserved_range
- In testing, we would not be able to roll back to part of the 0-1MB range not being migrated.

- btrfs-progs: tests: fix typo in convert-tests/008-readonly-image
- The test used ext2_save instead of ext2_saved as the filename

---

Jeff Mahoney (5):
btrfs-progs: convert: properly handle reserved ranges while iterating
files
btrfs-progs: convert: add missing newlines for printfs
btrfs-progs: convert: use search_cache_extent in
migrate_one_reserved_range
btrfs-progs: tests: fix typo in convert-tests/008-readonly-image
btrfs-progs: convert: add support for converting reiserfs

 Makefile                                           |    3 +-
 Makefile.inc.in                                    |    3 +-
 configure.ac                                       |   15 +-
 convert/main.c                                     |   21 +-
 convert/source-fs.c                                |   25 +-
 convert/source-reiserfs.c                          | 1015 ++++++++++++++++++++
 convert/source-reiserfs.h                          |  105 ++
 ctree.h                                            |    2 +-
 file-item.c                                        |    2 +-
 tests/common.convert                               |   14 +-
 tests/convert-tests/008-readonly-image/test.sh     |    4 +-
 tests/convert-tests/010-reiserfs-basic/test.sh     |   16 +
 .../011-reiserfs-delete-all-rollback/test.sh       |   67 ++
 .../012-reiserfs-large-hole-extent/test.sh         |   23 +
 .../013-reiserfs-common-inode-flags/test.sh        |   35 +
 .../convert-tests/014-reiserfs-tail-handling/input |    1 +
 .../014-reiserfs-tail-handling/input2              |    1 +
 .../014-reiserfs-tail-handling/test.sh             |   69 ++
 18 files changed, 1391 insertions(+), 30 deletions(-)
 create mode 100644 convert/source-reiserfs.c
 create mode 100644 convert/source-reiserfs.h
 create mode 100755 tests/convert-tests/010-reiserfs-basic/test.sh
 create mode 100755 tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh
 create mode 100755 tests/convert-tests/012-reiserfs-large-hole-extent/test.sh
 create mode 100755 tests/convert-tests/013-reiserfs-common-inode-flags/test.sh
 create mode 100644 tests/convert-tests/014-reiserfs-tail-handling/input
 create mode 100644 tests/convert-tests/014-reiserfs-tail-handling/input2
 create mode 100755 tests/convert-tests/014-reiserfs-tail-handling/test.sh
Signature · 1 line
2.11.0
#1 lore raw

PATCH v2 1/5 btrfs-progs: convert: properly handle reserved ranges while iterating files

From: Jeff Mahoney <[email protected]>

Commit 522ef705e38 (btrfs-progs: convert: Introduce function to calculate the available space) changed how we handle migrating file data so that we never have btrfs space associated with the reserved ranges. This works pretty well and when we iterate over the file blocks, the associations are redirected to the migrated locations.

This commit missed the case in block_iterate_proc where we just check for intersection with a superblock location before looking up a block group. intersect_with_sb checks to see if the range intersects with a stripe containing a superblock but, in fact, we've reserved the full 0-1MB range at the start of the disk. So a file block located at e.g. 160kB will fall in the reserved region but won't be excepted in block_iterate_block. We ultimately hit a BUG_ON when we fail to look up the block group for that location.

This is reproducible using convert-tests/003-ext4-basic.

The fix is to have intersect_with_sb and block_iterate_proc understand the full size of the reserved ranges. Since we use the range to determine the boundary for the block iterator, let's just return the boundary. 0 isn't a valid boundary and means that we proceed normally with block group lookup.

---
 convert/source-fs.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)
convert/source-fs.c +11 -14
index 80e4e41..09f6995 100644
@@ -28,18 +28,16 @@ const struct simple_range btrfs_reserved_ranges[3] = {
 	{ BTRFS_SB_MIRROR_OFFSET(2), SZ_64K }
 };
 
-static int intersect_with_sb(u64 bytenr, u64 num_bytes)
+static u64 intersect_with_reserved(u64 bytenr, u64 num_bytes)
 {
 	int i;
-	u64 offset;
 
-	for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) {
-		offset = btrfs_sb_offset(i);
-		offset &= ~((u64)BTRFS_STRIPE_LEN - 1);
+	for (i = 0; i < ARRAY_SIZE(btrfs_reserved_ranges); i++) {
+		const struct simple_range *range = &btrfs_reserved_ranges[i];
 
-		if (bytenr < offset + BTRFS_STRIPE_LEN &&
-		    bytenr + num_bytes > offset)
-			return 1;
+		if (bytenr < range_end(range) &&
+		    bytenr + num_bytes >= range->start)
+			return range_end(range);
 	}
 	return 0;
 }
@@ -64,14 +62,14 @@ int block_iterate_proc(u64 disk_block, u64 file_block,
 		              struct blk_iterate_data *idata)
 {
 	int ret = 0;
-	int sb_region;
+	u64 reserved_boundary;
 	int do_barrier;
 	struct btrfs_root *root = idata->root;
 	struct btrfs_block_group_cache *cache;
 	u64 bytenr = disk_block * root->sectorsize;
 
-	sb_region = intersect_with_sb(bytenr, root->sectorsize);
-	do_barrier = sb_region || disk_block >= idata->boundary;
+	reserved_boundary = intersect_with_reserved(bytenr, root->sectorsize);
+	do_barrier = reserved_boundary || disk_block >= idata->boundary;
 	if ((idata->num_blocks > 0 && do_barrier) ||
 	    (file_block > idata->first_block + idata->num_blocks) ||
 	    (disk_block != idata->disk_block + idata->num_blocks)) {
@@ -91,9 +89,8 @@ int block_iterate_proc(u64 disk_block, u64 file_block,
 				goto fail;
 		}
 
-		if (sb_region) {
-			bytenr += BTRFS_STRIPE_LEN - 1;
-			bytenr &= ~((u64)BTRFS_STRIPE_LEN - 1);
+		if (reserved_boundary) {
+			bytenr = reserved_boundary;
 		} else {
 			cache = btrfs_lookup_block_group(root->fs_info, bytenr);
 			BUG_ON(!cache);
Signature · 1 line
2.11.0
Reviewed-by on v2 1/5
#2 lore raw

Re: [PATCH 1/5] btrfs-progs: convert: properly handle reserved ranges while iterating files

Quoted 19 lines · On 2017年07月27日 23:47, [email protected] wrote:

From: Jeff Mahoney <[email protected]>

Commit 522ef705e38 (btrfs-progs: convert: Introduce function to calculate the available space) changed how we handle migrating file data so that we never have btrfs space associated with the reserved ranges. This works pretty well and when we iterate over the file blocks, the associations are redirected to the migrated locations.

This commit missed the case in block_iterate_proc where we just check for intersection with a superblock location before looking up a block group. intersect_with_sb checks to see if the range intersects with a stripe containing a superblock but, in fact, we've reserved the full 0-1MB range at the start of the disk. So a file block located at e.g. 160kB will fall in the reserved region but won't be excepted in block_iterate_block. We ultimately hit a BUG_ON when we fail to look up the block group for that location.

This is reproducible using convert-tests/003-ext4-basic.

Quoted 7 lines

The fix is to have intersect_with_sb and block_iterate_proc understand the full size of the reserved ranges. Since we use the range to determine the boundary for the block iterator, let's just return the boundary. 0 isn't a valid boundary and means that we proceed normally with block group lookup.

Thanks,
Qu

Quoted 64 lines
---
  convert/source-fs.c | 25 +++++++++++--------------
  1 file changed, 11 insertions(+), 14 deletions(-)
convert/source-fs.c +11 -14
index 80e4e41..09f6995 100644
@@ -28,18 +28,16 @@ const struct simple_range btrfs_reserved_ranges[3] = {
  	{ BTRFS_SB_MIRROR_OFFSET(2), SZ_64K }
  };
 
-static int intersect_with_sb(u64 bytenr, u64 num_bytes)
+static u64 intersect_with_reserved(u64 bytenr, u64 num_bytes)
  {
  	int i;
-	u64 offset;
 
-	for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) {
-		offset = btrfs_sb_offset(i);
-		offset &= ~((u64)BTRFS_STRIPE_LEN - 1);
+	for (i = 0; i < ARRAY_SIZE(btrfs_reserved_ranges); i++) {
+		const struct simple_range *range = &btrfs_reserved_ranges[i];
 
-		if (bytenr < offset + BTRFS_STRIPE_LEN &&
-		    bytenr + num_bytes > offset)
-			return 1;
+		if (bytenr < range_end(range) &&
+		    bytenr + num_bytes >= range->start)
+			return range_end(range);
  	}
  	return 0;
  }
@@ -64,14 +62,14 @@ int block_iterate_proc(u64 disk_block, u64 file_block,
  		              struct blk_iterate_data *idata)
  {
  	int ret = 0;
-	int sb_region;
+	u64 reserved_boundary;
  	int do_barrier;
  	struct btrfs_root *root = idata->root;
  	struct btrfs_block_group_cache *cache;
  	u64 bytenr = disk_block * root->sectorsize;
 
-	sb_region = intersect_with_sb(bytenr, root->sectorsize);
-	do_barrier = sb_region || disk_block >= idata->boundary;
+	reserved_boundary = intersect_with_reserved(bytenr, root->sectorsize);
+	do_barrier = reserved_boundary || disk_block >= idata->boundary;
  	if ((idata->num_blocks > 0 && do_barrier) ||
  	    (file_block > idata->first_block + idata->num_blocks) ||
  	    (disk_block != idata->disk_block + idata->num_blocks)) {
@@ -91,9 +89,8 @@ int block_iterate_proc(u64 disk_block, u64 file_block,
  				goto fail;
  		}
 
-		if (sb_region) {
-			bytenr += BTRFS_STRIPE_LEN - 1;
-			bytenr &= ~((u64)BTRFS_STRIPE_LEN - 1);
+		if (reserved_boundary) {
+			bytenr = reserved_boundary;
  		} else {
  			cache = btrfs_lookup_block_group(root->fs_info, bytenr);
  			BUG_ON(!cache);
#3 lore raw

PATCH v2 2/5 btrfs-progs: convert: add missing newlines for printfs

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

There are two printfs with missing newlines that end up making the output wonky.

---
 convert/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
convert/main.c +2 -2
index c56382e..01657a6 100644
@@ -1285,7 +1285,7 @@ static int do_convert(const char *devname, u32 convert_flags, u32 nodesize,
 		goto fail;
 	}
 
-	printf("creating btrfs metadata");
+	printf("creating btrfs metadata\n");
 	ctx.max_copy_inodes = (cctx.inodes_count - cctx.free_inodes_count);
 	ctx.cur_copy_inodes = 0;
 
@@ -1348,7 +1348,7 @@ static int do_convert(const char *devname, u32 convert_flags, u32 nodesize,
 	close_ctree(root);
 	close(fd);
 
-	printf("conversion complete");
+	printf("conversion complete\n");
 	return 0;
 fail:
 	clean_convert_context(&cctx);
Signature · 1 line
2.11.0
Reviewed-by on v2 2/5
#4 lore raw

Re: [PATCH 2/5] btrfs-progs: convert: add missing newlines for printfs

Quoted 6 lines · On 2017年07月27日 23:47, [email protected] wrote:

From: Jeff Mahoney <[email protected]>

There are two printfs with missing newlines that end up making the output wonky.

Those are the only two missing newline in convert/. No missing.

Thanks,
Qu

Quoted 27 lines
---
  convert/main.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
convert/main.c +2 -2
index c56382e..01657a6 100644
@@ -1285,7 +1285,7 @@ static int do_convert(const char *devname, u32 convert_flags, u32 nodesize,
  		goto fail;
  	}
 
-	printf("creating btrfs metadata");
+	printf("creating btrfs metadata\n");
  	ctx.max_copy_inodes = (cctx.inodes_count - cctx.free_inodes_count);
  	ctx.cur_copy_inodes = 0;
 
@@ -1348,7 +1348,7 @@ static int do_convert(const char *devname, u32 convert_flags, u32 nodesize,
  	close_ctree(root);
  	close(fd);
 
-	printf("conversion complete");
+	printf("conversion complete\n");
  	return 0;
  fail:
  	clean_convert_context(&cctx);
#5 lore raw

PATCH v2 3/5 btrfs-progs: convert: use search_cache_extent in migrate_one_reserved_range

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

When we are looking for extents in migrate_one_reserved_range, it's likely that there will be multiple extents that fall into the 0-1MB range.

If lookup_cache_extent is called with a range that covers multiple cache entries, it will return the first entry it encounters while searching from the top of the tree that happens to fall in that range. That means that we can end up skipping regions within that range, resulting in a file system image that can't be rolled back since it wasn't all migrated properly.

This is reproducible using convert-tests/008-readonly-image. There was a range from 0-160kB, but the only entry that was returned began at ~ 280kB.

The fix is to use search_cache_extent to iterate through multiple regions within that range.

---
 convert/main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
convert/main.c +3 -1
index 01657a6..24ed1de 100644
@@ -340,10 +340,12 @@ static int migrate_one_reserved_range(struct btrfs_trans_handle *trans,
 	 * migrate ranges that covered by old fs data.
 	 */
 	while (cur_off < range_end(range)) {
-		cache = lookup_cache_extent(used, cur_off, cur_len);
+		cache = search_cache_extent(used, cur_off);
 		if (!cache)
 			break;
 		cur_off = max(cache->start, cur_off);
+		if (cur_off >= range_end(range))
+			break;
 		cur_len = min(cache->start + cache->size, range_end(range)) -
 			  cur_off;
 		BUG_ON(cur_len < root->sectorsize);
Signature · 1 line
2.11.0
Reviewed-by on v2 3/5
#6 lore raw

Re: [PATCH 3/5] btrfs-progs: convert: use search_cache_extent in migrate_one_reserved_range

Quoted 11 lines · On 2017年07月27日 23:47, [email protected] wrote:

From: Jeff Mahoney <[email protected]>

When we are looking for extents in migrate_one_reserved_range, it's likely that there will be multiple extents that fall into the 0-1MB range.

If lookup_cache_extent is called with a range that covers multiple cache entries, it will return the first entry it encounters while searching from the top of the tree that happens to fall in that range. That means that we can end up skipping regions within that range, resulting in a file system image that can't be rolled back since it wasn't all migrated properly.

Thanks for catching this one.

Quoted 8 lines

This is reproducible using convert-tests/008-readonly-image. There was a range from 0-160kB, but the only entry that was returned began at ~ 280kB.

The fix is to use search_cache_extent to iterate through multiple regions within that range >

Thanks,
Qu

Quoted 23 lines
---
  convert/main.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
convert/main.c +3 -1
index 01657a6..24ed1de 100644
@@ -340,10 +340,12 @@ static int migrate_one_reserved_range(struct btrfs_trans_handle *trans,
  	 * migrate ranges that covered by old fs data.
  	 */
  	while (cur_off < range_end(range)) {
-		cache = lookup_cache_extent(used, cur_off, cur_len);
+		cache = search_cache_extent(used, cur_off);
  		if (!cache)
  			break;
  		cur_off = max(cache->start, cur_off);
+		if (cur_off >= range_end(range))
+			break;
  		cur_len = min(cache->start + cache->size, range_end(range)) -
  			  cur_off;
  		BUG_ON(cur_len < root->sectorsize);
#7 lore raw

PATCH v2 4/5 btrfs-progs: tests: fix typo in convert-tests/008-readonly-image

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

The dd in convert-tests/008-readonly-image is expected to fail, so there being a typo in the file name has gone unnoticed.

---
 tests/convert-tests/008-readonly-image/test.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tests/convert-tests/008-readonly-image/test.sh +3 -1
index 27c9373..cc846fa 100755
@@ -14,9 +14,10 @@ convert_test_prep_fs $default_mke2fs
 run_check_umount_test_dev
 convert_test_do_convert
 run_check_mount_test_dev
+run_check e2fsck -n "$TEST_MNT/ext2_saved/image"
 
 # It's expected to fail
-$SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/ext2_save/image" bs=1M count=1 \
+$SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/ext2_saved/image" bs=1M count=1 \
 	&> /dev/null
 if [ $? -ne 1 ]; then
 	echo "after convert ext2_save/image is not read-only"
@@ -24,3 +25,4 @@ if [ $? -ne 1 ]; then
 fi
 run_check_umount_test_dev
 convert_test_post_rollback
+
Signature · 1 line
2.11.0
#8 lore raw

Re: [PATCH 4/5] btrfs-progs: tests: fix typo in convert-tests/008-readonly-image

Quoted 4 lines · On 2017年07月27日 23:47, [email protected] wrote:

From: Jeff Mahoney <[email protected]>

The dd in convert-tests/008-readonly-image is expected to fail, so there being a typo in the file name has gone unnoticed.

Thanks for catching this.
This is very embarrassing.

Quoted 11 lines
---
  tests/convert-tests/008-readonly-image/test.sh | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
tests/convert-tests/008-readonly-image/test.sh +0 -0
index 27c9373..cc846fa 100755

tests/convert-tests/008-readonly-image/test.sh convert_test_prep_fs $default_mke2fs · line 21

Quoted 9 lines
tests/convert-tests/008-readonly-image/test.sh +2 -1
@@ -14,9 +14,10 @@ convert_test_prep_fs $default_mke2fs
  run_check_umount_test_dev
  convert_test_do_convert
  run_check_mount_test_dev
+run_check e2fsck -n "$TEST_MNT/ext2_saved/image"
 
  # It's expected to fail
-$SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/ext2_save/image" bs=1M count=1 \
+$SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/ext2_saved/image" bs=1M count=1 \
  	&> /dev/null

BTW, now we have run_mustfail() function, so we don't need to manually check the return value now.

Thanks,
Qu

Quoted 8 lines
tests/convert-tests/008-readonly-image/test.sh +1 -0
  if [ $? -ne 1 ]; then
  	echo "after convert ext2_save/image is not read-only"
@@ -24,3 +25,4 @@ if [ $? -ne 1 ]; then
  fi
  run_check_umount_test_dev
  convert_test_post_rollback
+
#9 lore raw

Re: [PATCH 4/5] btrfs-progs: tests: fix typo in convert-tests/008-readonly-image

Quoted 28 lines · Qu Wenruo
Quoted 4 lines · On 2017年07月27日 23:47, [email protected] wrote:

From: Jeff Mahoney <[email protected]>

The dd in convert-tests/008-readonly-image is expected to fail, so there being a typo in the file name has gone unnoticed.

Thanks for catching this.
This is very embarrassing.

Quoted 17 lines
---
  tests/convert-tests/008-readonly-image/test.sh | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
tests/convert-tests/008-readonly-image/test.sh +1 -0
index 27c9373..cc846fa 100755
@@ -14,9 +14,10 @@ convert_test_prep_fs $default_mke2fs
  run_check_umount_test_dev
  convert_test_do_convert
  run_check_mount_test_dev
+run_check e2fsck -n "$TEST_MNT/ext2_saved/image"
    # It's expected to fail
Quoted 8 lines

tests/convert-tests/008-readonly-image/test.sh convert_test_prep_fs $default_mke2fs · line 22

Quoted 5 lines
tests/convert-tests/008-readonly-image/test.sh +1 -1
-$SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/ext2_save/image" bs=1M
 count=1 \
+$SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/ext2_saved/image" bs=1M
 count=1 \
      &> /dev/null

BTW, now we have run_mustfail() function, so we don't need to manually check the return value now.

Ah, right. I'll incorporate this with Lakshmipathi's feedback.

-Jeff

Quoted 16 lines

Thanks,
Qu

Quoted 8 lines
tests/convert-tests/008-readonly-image/test.sh +0 -0
  if [ $? -ne 1 ]; then

echo "after convert ext2_save/image is not read-only"

tests/convert-tests/008-readonly-image/test.sh +1 -0
@@ -24,3 +25,4 @@ if [ $? -ne 1 ]; then
  fi
  run_check_umount_test_dev
  convert_test_post_rollback
+
Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#10 lore raw

Re: [PATCH 4/5] btrfs-progs: tests: fix typo in convert-tests/008-readonly-image

In reply to [email protected]
Quoted 2 lines

if [ $? -ne 1 ]; then
echo "after convert ext2_save/image is not read-only"

Though this mayn't affect test-script result, please change the typo in this location also. thanks.

Cheers.
Lakshmipathi.G

#11 lore raw

PATCH v2 5/5 btrfs-progs: convert: add support for converting reiserfs

In reply to [email protected]

From: Jeff Mahoney <[email protected]>

This patch adds support to convert reiserfs file systems in-place to btrfs.

It will convert extended attribute files to btrfs extended attributes, translate ACLs, coalesce tails that consist of multiple items into one item, and convert tails that are too big into indirect files.

This requires that libreiserfscore 3.6.27 be available.

Many of the test cases for convert apply regardless of what the source file system is and using ext4 is sufficient. I've included several test cases that are reiserfs-specific.

---
 Makefile                                           |    3 +-
 Makefile.inc.in                                    |    3 +-
 configure.ac                                       |   15 +-
 convert/main.c                                     |   13 +-
 convert/source-reiserfs.c                          | 1015 ++++++++++++++++++++
 convert/source-reiserfs.h                          |  105 ++
 ctree.h                                            |    2 +-
 file-item.c                                        |    2 +-
 tests/common.convert                               |   14 +-
 tests/convert-tests/010-reiserfs-basic/test.sh     |   16 +
 .../011-reiserfs-delete-all-rollback/test.sh       |   67 ++
 .../012-reiserfs-large-hole-extent/test.sh         |   23 +
 .../013-reiserfs-common-inode-flags/test.sh        |   35 +
 .../014-reiserfs-tail-handling/test.sh             |   74 ++
 14 files changed, 1375 insertions(+), 12 deletions(-)
 create mode 100644 convert/source-reiserfs.c
 create mode 100644 convert/source-reiserfs.h
 create mode 100755 tests/convert-tests/010-reiserfs-basic/test.sh
 create mode 100755 tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh
 create mode 100755 tests/convert-tests/012-reiserfs-large-hole-extent/test.sh
 create mode 100755 tests/convert-tests/013-reiserfs-common-inode-flags/test.sh
 create mode 100755 tests/convert-tests/014-reiserfs-tail-handling/test.sh
Makefile +2 -1
index 81598df..f7f6dab 100644
@@ -111,7 +111,7 @@ libbtrfs_headers = send-stream.h send-utils.h send.h kernel-lib/rbtree.h btrfs-l
 	       kernel-lib/radix-tree.h kernel-lib/sizes.h extent-cache.h \
 	       extent_io.h ioctl.h ctree.h btrfsck.h version.h
 convert_objects = convert/main.o convert/common.o convert/source-fs.o \
-		  convert/source-ext2.o
+		  convert/source-ext2.o convert/source-reiserfs.o
 mkfs_objects = mkfs/main.o mkfs/common.o
 
 TESTS = fsck-tests.sh convert-tests.sh
@@ -188,6 +188,7 @@ endif
 # external libs required by various binaries; for btrfs-foo,
 # specify btrfs_foo_libs = <list of libs>; see $($(subst...)) rules below
 btrfs_convert_cflags = -DBTRFSCONVERT_EXT2=$(BTRFSCONVERT_EXT2)
+btrfs_convert_cflags += -DBTRFSCONVERT_REISERFS=$(BTRFSCONVERT_REISERFS)
 btrfs_fragments_libs = -lgd -lpng -ljpeg -lfreetype
 btrfs_debug_tree_objects = cmds-inspect-dump-tree.o
 btrfs_show_super_objects = cmds-inspect-dump-super.o
Makefile.inc.in +2 -1
index 4e1b68c..3c7bc03 100644
@@ -12,6 +12,7 @@ INSTALL = @INSTALL@
 DISABLE_DOCUMENTATION = @DISABLE_DOCUMENTATION@
 DISABLE_BTRFSCONVERT = @DISABLE_BTRFSCONVERT@
 BTRFSCONVERT_EXT2 = @BTRFSCONVERT_EXT2@
+BTRFSCONVERT_REISERFS = @BTRFSCONVERT_REISERFS@
 
 SUBST_CFLAGS = @CFLAGS@
 SUBST_LDFLAGS = @LDFLAGS@
@@ -31,6 +32,6 @@ udevruledir = ${udevdir}/rules.d
 
 # external libs required by various binaries; for btrfs-foo,
 # specify btrfs_foo_libs = <list of libs>; see $($(subst...)) rules in Makefile
-btrfs_convert_libs = @EXT2FS_LIBS@ @COM_ERR_LIBS@
+btrfs_convert_libs = @EXT2FS_LIBS@ @COM_ERR_LIBS@ @REISERFS_LIBS@
 
 MAKEFILE_INC_INCLUDED = yes
configure.ac +14 -1
index 30055f8..27d875b 100644
@@ -120,6 +120,7 @@ fi
 
 convertfs=
 BTRFSCONVERT_EXT2=0
+BTRFSCONVERT_REISERFS=0
 if test "x$enable_convert" = xyes; then
 	if test "x$with_convert" = "xauto" || echo "$with_convert" | grep -q "ext2"; then
 		PKG_CHECK_MODULES(EXT2FS, [ext2fs >= 1.42],,
@@ -131,11 +132,23 @@ if test "x$enable_convert" = xyes; then
 		convertfs="${convertfs:+$convertfs,}ext2"
 		BTRFSCONVERT_EXT2=1
 	fi
+	if test "x$with_convert" = "xauto"; then
+		PKG_CHECK_MODULES(REISERFS, [reiserfscore >= 3.6.27],
+				  [BTRFSCONVERT_REISERFS=1],
+				  [BTRFSCONVERT_REISERFS=0])
+	elif echo "$with_convert" | grep -q "reiserfs"; then
+		PKG_CHECK_MODULES(REISERFS, [reiserfscore >= 3.6.27],
+				  [BTRFSCONVERT_REISERFS=1],[])
+	fi
+	if test "$BTRFSCONVERT_REISERFS" = 1; then
+		convertfs="${convertfs:+$convertfs,}reiserfs"
+	fi
 fi
 AC_SUBST([BTRFSCONVERT_EXT2])
+AC_SUBST([BTRFSCONVERT_REISERFS])
 
 # catch typos
-tmp=$(echo "$with_convert" | sed -e 's/auto//' | sed -e 's/ext2//' | sed -e 's/,\+/,/')
+tmp=$(echo "$with_convert" | sed -e 's/auto//' | sed -e 's/ext2//' | sed -e 's/reiserfs//' | sed -e 's/,\+/,/')
 if ! test "x$tmp" = "x"; then
 	AC_MSG_ERROR([unknown tokens for --with-convert: $tmp])
 fi
convert/main.c +9 -4
index 24ed1de..f83c945 100644
@@ -102,12 +102,16 @@
 #include "convert/source-fs.h"
 #include "fsfeatures.h"
 
-const struct btrfs_convert_operations ext2_convert_ops;
+extern const struct btrfs_convert_operations ext2_convert_ops;
+extern const struct btrfs_convert_operations reiserfs_convert_ops;
 
 static const struct btrfs_convert_operations *convert_operations[] = {
 #if BTRFSCONVERT_EXT2
 	&ext2_convert_ops,
 #endif
+#if BTRFSCONVERT_REISERFS
+	&reiserfs_convert_ops,
+#endif
 };
 
 static void *print_copied_inodes(void *p)
@@ -413,7 +417,7 @@ static int migrate_one_reserved_range(struct btrfs_trans_handle *trans,
 }
 
 /*
- * Relocate the used ext2 data in reserved ranges
+ * Relocate the used source fs data in reserved ranges
  */
 static int migrate_reserved_ranges(struct btrfs_trans_handle *trans,
 				   struct btrfs_root *root,
@@ -1657,11 +1661,11 @@ static int do_rollback(const char *devname)
 	ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, &path, 0, 0);
 	btrfs_release_path(&path);
 	if (ret > 0) {
-		error("unable to find ext2 image subvolume, is it deleted?");
+		error("unable to find source fs image subvolume, is it deleted?");
 		ret = -ENOENT;
 		goto close_fs;
 	} else if (ret < 0) {
-		error("failed to find ext2 image subvolume: %s",
+		error("failed to find source fs image subvolume: %s",
 			strerror(-ret));
 		goto close_fs;
 	}
@@ -1779,6 +1783,7 @@ static void print_usage(void)
 	printf("\n");
 	printf("Supported filesystems:\n");
 	printf("\text2/3/4: %s\n", BTRFSCONVERT_EXT2 ? "yes" : "no");
+	printf("\treiserfs: %s\n", BTRFSCONVERT_REISERFS ? "yes" : "no");
 }
 
 int main(int argc, char *argv[])
convert/source-reiserfs.c new file +1015 -0

1,015 lines not on this page · raw message

convert/source-reiserfs.h new file +105 -0

105 lines not on this page · raw message

ctree.h +1 -1
index 13cf3b0..e3c79fe 100644
@@ -2728,7 +2728,7 @@ int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
 			     u64 num_bytes);
 int btrfs_insert_inline_extent(struct btrfs_trans_handle *trans,
 				struct btrfs_root *root, u64 objectid,
-				u64 offset, char *buffer, size_t size);
+				u64 offset, const char *buffer, size_t size);
 int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
 			  struct btrfs_root *root, u64 alloc_end,
 			  u64 bytenr, char *data, size_t len);
file-item.c +1 -1
index 333fa33..03d6fd1 100644
@@ -86,7 +86,7 @@ out:
 
 int btrfs_insert_inline_extent(struct btrfs_trans_handle *trans,
 			       struct btrfs_root *root, u64 objectid,
-			       u64 offset, char *buffer, size_t size)
+			       u64 offset, const char *buffer, size_t size)
 {
 	struct btrfs_key key;
 	struct btrfs_path *path;
tests/common.convert +11 -3
index 8c9242e..90d721e 100644
@@ -17,7 +17,7 @@ convert_test_preamble() {
 	msg="$2"
 	shift 3
 	echo "    [TEST/conv]     $msg, btrfs" "${features:-defaults}"
-	echo "creating ext image with: $@" >> "$RESULTS"
+	echo "creating test image with: $@" >> "$RESULTS"
 }
 
 #  prepare TEST_DEV before conversion, create filesystem and mount it, image
@@ -29,10 +29,18 @@ convert_test_prep_fs() {
 	run_check truncate -s 0 "$TEST_DEV"
 	# 256MB is the smallest acceptable btrfs image.
 	run_check truncate -s 512M "$TEST_DEV"
-	run_check "$@" -F "$TEST_DEV"
+	force=
+	mountopts=
+	case "$@" in
+	*mke2fs*)
+		force=-F ;;
+	*mkreiserfs*)
+		force=-ff; mountopts="-o acl,user_xattr,attrs,tails=on" ;;
+	esac
+	run_check "$@" $force "$TEST_DEV"
 
 	# create a file to check btrfs-convert can convert regular file correct
-	run_check_mount_test_dev
+	run_check_mount_test_dev $mountopts
 
 	# create a file inside the fs before convert, to make sure there is
 	# data covering btrfs backup superblock range (64M)
tests/convert-tests/010-reiserfs-basic/test.sh new file +16 -0
new file mode 100755
index 0000000..8f80965
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+source "$TOP/tests/common"
+source "$TOP/tests/common.convert"
+
+setup_root_helper
+prepare_test_dev 512M
+check_prereq btrfs-convert
+
+for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do
+	convert_test "$feature" "reiserfs 4k nodesize" 4096 mkreiserfs -b 4096
+	convert_test "$feature" "reiserfs 8k nodesize" 8192 mkreiserfs -b 4096
+	convert_test "$feature" "reiserfs 16k nodesize" 16384 mkreiserfs -b 4096
+	convert_test "$feature" "reiserfs 32k nodesize" 32768 mkreiserfs -b 4096
+	convert_test "$feature" "reiserfs 64k nodesize" 65536 mkreiserfs -b 4096
+done
tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh new file +67 -0

67 lines not on this page · raw message

tests/convert-tests/012-reiserfs-large-hole-extent/test.sh new file +23 -0
new file mode 100755
index 0000000..4a2a8d5
@@ -0,0 +1,23 @@
+#!/bin/bash
+# Create a base image with large hole extent, then convert to btrfs,
+# check the converted image.
+# Check if btrfs-convert can handle such large hole.
+# Fast pinpoint regression test. No options combination nor checksum
+# verification
+
+source "$TOP/tests/common"
+source "$TOP/tests/common.convert"
+
+setup_root_helper
+prepare_test_dev 512M
+check_prereq btrfs-convert
+
+default_mkfs="mkreiserfs -b 4096"
+convert_test_preamble '' 'large hole extent test' 16k "$default_mkfs"
+convert_test_prep_fs $default_mkfs
+
+run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/file" bs=1M \
+	count=1 seek=1024 > /dev/null 2>&1
+
+run_check_umount_test_dev
+convert_test_do_convert
tests/convert-tests/013-reiserfs-common-inode-flags/test.sh new file +35 -0
new file mode 100755
index 0000000..b3948b3
@@ -0,0 +1,35 @@
+#!/bin/bash
+# Check if btrfs-convert can copy common inode flags like SYNC/IMMUTABLE
+
+source "$TOP/tests/common"
+source "$TOP/tests/common.convert"
+
+setup_root_helper
+prepare_test_dev 512M
+check_prereq btrfs-convert
+
+fail=0
+default_mkfs="mkreiserfs -b 4096"
+convert_test_preamble '' 'common inode flags test' 16k "$default_mkfs"
+convert_test_prep_fs $default_mkfs
+
+# create file with specific flags
+run_check $SUDO_HELPER touch "$TEST_MNT/flag_test"
+run_check $SUDO_HELPER chattr +aAdSi "$TEST_MNT/flag_test"
+run_check lsattr "$TEST_MNT/flag_test"
+
+run_check_umount_test_dev
+convert_test_do_convert
+run_check_mount_test_dev
+
+# Log the status
+run_check lsattr "$TEST_MNT/flag_test"
+# Above flags should be copied to btrfs flags, and lsattr should get them
+run_check_stdout lsattr "$TEST_MNT/flag_test" | cut -f1 -d\ | grep "[aAdiS]" -q
+if [ $? -ne 0 ]; then
+	rm tmp_output
+	_fail "no common inode flags are copied after convert"
+fi
+
+run_check_umount_test_dev
+convert_test_post_rollback
tests/convert-tests/014-reiserfs-tail-handling/test.sh new file +74 -0

74 lines not on this page · raw message

Signature · 1 line
2.11.0
#12 lore raw
In reply to [email protected]
Quoted 14 lines · On Thu, Jul 27, 2017 at 11:47:18AM -0400, [email protected] wrote:

From: Jeff Mahoney <[email protected]>

Changes since v1:
- reiserfs conversion:
- use bool instead of int
- catch 'impossible' condition of multiple discontiguous tails
- properly handle hole followed by tail
- add testing for combinations of real blocks, tails, and holes
- print error indicating filename (and key) that caused a failure
- constify buffer arg to btrfs_insert_inline_extent
- add tails=on to reiserfs mount options
- fixed absence of libreiserfscore to be non-fatal unless specificially enabled

Quoted 6 lines

- btrfs-progs: convert: use search_cache_extent in migrate_one_reserved_range
- In testing, we would not be able to roll back to part of the 0-1MB range not being migrated.

- btrfs-progs: tests: fix typo in convert-tests/008-readonly-image
- The test used ext2_save instead of ext2_saved as the filename

Oh crap, I noticed v2 after I had finished merging v1. The changes have been now transferred, so the version in devel is v2 + my fixups. The 2 new patches ("use search_cache_extent in migrate_one_reserved_range" and "tests: fix typo in convert-tests/008-readonly-image") have been also added.