From 88de623dd26d4ecbdbbf4dff79551e282abdb443 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 20 Sep 2021 16:36:52 +0200 Subject: [PATCH] btrfs-progs: convert: allow to set a duplicate uuid Relax the condition about a unique uuid for convert, only print a warning. In case we copy the uuid, it's expected that at the time the conversion starts the uuid is not unique as it sill exists on the source filesystem. In case user sets the uuid manually but it's still the same one as on the source filesystem we should also allow that, so it warns in this case as well. Update the test so it creates a block device where the uuid would be also cached by blkid and lets the non-unique check succeed. Issue: #404 Signed-off-by: David Sterba --- convert/common.c | 9 ++++----- convert/main.c | 4 ++++ tests/convert-tests/021-uuid-fsid/test.sh | 7 ++++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/convert/common.c b/convert/common.c index dbf0c96d..5e7a1d6b 100644 --- a/convert/common.c +++ b/convert/common.c @@ -104,11 +104,10 @@ static int setup_temp_super(int fd, struct btrfs_mkfs_config *cfg, ret = -EINVAL; goto out; } - if (!test_uuid_unique(cfg->fs_uuid)) { - error("non-unique UUID: %s", cfg->fs_uuid); - ret = -EINVAL; - goto out; - } + /* + * Caller should make sure the uuid is either unique or OK to + * be duplicate in case it's copied from the source filesystem. + */ uuid_copy(super->metadata_uuid, super->fsid); } else { uuid_generate(super->fsid); diff --git a/convert/main.c b/convert/main.c index 68f85988..c162e8d8 100644 --- a/convert/main.c +++ b/convert/main.c @@ -1189,6 +1189,8 @@ static int do_convert(const char *devname, u32 convert_flags, u32 nodesize, if (convert_flags & CONVERT_FLAG_COPY_FSID) { uuid_unparse(cctx.fs_uuid, mkfs_cfg.fs_uuid); + if (!test_uuid_unique(mkfs_cfg.fs_uuid)) + warning("non-unique UUID (copy): %s", mkfs_cfg.fs_uuid); } else if (fsid[0] == 0) { uuid_t uuid; @@ -1196,6 +1198,8 @@ static int do_convert(const char *devname, u32 convert_flags, u32 nodesize, uuid_unparse(uuid, mkfs_cfg.fs_uuid); } else { memcpy(mkfs_cfg.fs_uuid, fsid, BTRFS_UUID_UNPARSED_SIZE); + if (!test_uuid_unique(mkfs_cfg.fs_uuid)) + warning("non-unique UUID (user set): %s", mkfs_cfg.fs_uuid); } printf("Source filesystem:\n"); diff --git a/tests/convert-tests/021-uuid-fsid/test.sh b/tests/convert-tests/021-uuid-fsid/test.sh index d663513f..692a667c 100755 --- a/tests/convert-tests/021-uuid-fsid/test.sh +++ b/tests/convert-tests/021-uuid-fsid/test.sh @@ -5,9 +5,12 @@ source "$TEST_TOP/common" source "$TEST_TOP/common.convert" setup_root_helper -prepare_test_dev check_prereq btrfs-convert check_global_prereq mke2fs +setup_loopdevs 1 +prepare_loopdevs +# Convert helpers need the backing file, can't pass ${loopdevs[1]} +TEST_DEV=${loopdev_prefix}1 convert_test_prep_fs ext4 mke2fs -t ext4 -b 4096 run_check_umount_test_dev @@ -55,3 +58,5 @@ run_check "$TOP/btrfs-convert" --rollback "$TEST_DEV" run_mustfail "invalid UUID passed" \ "$TOP/btrfs-convert" --uuid invalid "$TEST_DEV" + +cleanup_loopdevs