* [PATCH 0/2] btrfs-progs: mkfs: testing cloned-device @ 2023-09-28 1:09 Anand Jain 2023-09-28 1:09 ` [PATCH 1/2] btrfs-progs: allow duplicate fsid for single device Anand Jain 2023-09-28 1:09 ` [PATCH 2/2] btrfs-progs: add mkfs -P option for dev_uuid Anand Jain 0 siblings, 2 replies; 6+ messages in thread From: Anand Jain @ 2023-09-28 1:09 UTC (permalink / raw) To: linux-btrfs; +Cc: dsterba, gpiccoli This patchset adds support for testing cloned-device in mkfs. So using mkfs.btrfs both option -U and -P a new device can be created to match the FSID and UUID of an existing device. This is useful for testing cloned-device. Anand Jain (2): btrfs-progs: allow duplicate fsid for single device btrfs-progs: add mkfs -P option for dev_uuid mkfs/common.c | 8 +++++++- mkfs/common.h | 1 + mkfs/main.c | 14 ++++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) -- 2.39.3 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] btrfs-progs: allow duplicate fsid for single device 2023-09-28 1:09 [PATCH 0/2] btrfs-progs: mkfs: testing cloned-device Anand Jain @ 2023-09-28 1:09 ` Anand Jain 2023-10-02 15:22 ` David Sterba 2023-09-28 1:09 ` [PATCH 2/2] btrfs-progs: add mkfs -P option for dev_uuid Anand Jain 1 sibling, 1 reply; 6+ messages in thread From: Anand Jain @ 2023-09-28 1:09 UTC (permalink / raw) To: linux-btrfs; +Cc: dsterba, gpiccoli For single device btrfs filesystem, allow duplicate fsid to be created. Signed-off-by: Anand Jain <anand.jain@oracle.com> --- mkfs/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mkfs/main.c b/mkfs/main.c index 6b38f8079bb4..68ff5d7785d3 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -1321,7 +1321,10 @@ int BOX_MAIN(mkfs)(int argc, char **argv) error("could not parse UUID: %s", fs_uuid); goto error; } - if (!test_uuid_unique(fs_uuid)) { + /* + * We allow non unique fsid for single device btrfs filesystem. + */ + if (device_count != 1 && !test_uuid_unique(fs_uuid)) { error("non-unique UUID: %s", fs_uuid); goto error; } -- 2.39.3 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] btrfs-progs: allow duplicate fsid for single device 2023-09-28 1:09 ` [PATCH 1/2] btrfs-progs: allow duplicate fsid for single device Anand Jain @ 2023-10-02 15:22 ` David Sterba 0 siblings, 0 replies; 6+ messages in thread From: David Sterba @ 2023-10-02 15:22 UTC (permalink / raw) To: Anand Jain; +Cc: linux-btrfs, dsterba, gpiccoli On Thu, Sep 28, 2023 at 09:09:18AM +0800, Anand Jain wrote: > For single device btrfs filesystem, allow duplicate fsid to be created. > > Signed-off-by: Anand Jain <anand.jain@oracle.com> As this is trivial I'll add it to devel now, but the other patch needs updated. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/2] btrfs-progs: add mkfs -P option for dev_uuid 2023-09-28 1:09 [PATCH 0/2] btrfs-progs: mkfs: testing cloned-device Anand Jain 2023-09-28 1:09 ` [PATCH 1/2] btrfs-progs: allow duplicate fsid for single device Anand Jain @ 2023-09-28 1:09 ` Anand Jain 2023-10-02 15:21 ` David Sterba 1 sibling, 1 reply; 6+ messages in thread From: Anand Jain @ 2023-09-28 1:09 UTC (permalink / raw) To: linux-btrfs; +Cc: dsterba, gpiccoli Add an option to specify the device uuid for mkfs. This is useful for creating a filesystem with a specific device uuid. This is useful for testing. Signed-off-by: Anand Jain <anand.jain@oracle.com> --- mkfs/common.c | 8 +++++++- mkfs/common.h | 1 + mkfs/main.c | 9 ++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/mkfs/common.c b/mkfs/common.c index d400413c7d41..e9a2fd5e4d3e 100644 --- a/mkfs/common.c +++ b/mkfs/common.c @@ -340,6 +340,7 @@ static void mkfs_blocks_remove(enum btrfs_mkfs_block *blocks, int *blocks_nr, /* * @fs_uuid - if NULL, generates a UUID, returns back the new filesystem UUID + * @dev_uuid - if NULL, generates a UUID, returns back the new device UUID * * The superblock signature is not valid, denotes a partially created * filesystem, needs to be finalized. @@ -435,7 +436,12 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg) } else { uuid_parse(cfg->fs_uuid, super.fsid); } - uuid_generate(super.dev_item.uuid); + if (!*cfg->dev_uuid) { + uuid_generate(super.dev_item.uuid); + uuid_unparse(super.dev_item.uuid, cfg->dev_uuid); + } else { + uuid_parse(cfg->dev_uuid, super.dev_item.uuid); + } uuid_generate(chunk_tree_uuid); for (i = 0; i < blocks_nr; i++) { diff --git a/mkfs/common.h b/mkfs/common.h index 06ddc926390f..d512ed853987 100644 --- a/mkfs/common.h +++ b/mkfs/common.h @@ -91,6 +91,7 @@ struct btrfs_mkfs_config { /* Logical addresses of superblock [0] and other tree roots */ u64 blocks[MKFS_BLOCK_COUNT + 1]; char fs_uuid[BTRFS_UUID_UNPARSED_SIZE]; + char dev_uuid[BTRFS_UUID_UNPARSED_SIZE]; char chunk_uuid[BTRFS_UUID_UNPARSED_SIZE]; /* Superblock offset after make_btrfs */ diff --git a/mkfs/main.c b/mkfs/main.c index 68ff5d7785d3..f0ff1d6cc936 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -1097,6 +1097,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv) struct btrfs_mkfs_features features = btrfs_mkfs_default_features; enum btrfs_csum_type csum_type = BTRFS_CSUM_TYPE_CRC32; char fs_uuid[BTRFS_UUID_UNPARSED_SIZE] = { 0 }; + char dev_uuid[BTRFS_UUID_UNPARSED_SIZE] = { 0 }; u32 nodesize = 0; bool nodesize_forced = false; u32 sectorsize = 0; @@ -1144,6 +1145,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv) { "features", required_argument, NULL, 'O' }, { "runtime-features", required_argument, NULL, 'R' }, { "uuid", required_argument, NULL, 'U' }, + { "uuid", required_argument, NULL, 'P' }, { "quiet", 0, NULL, 'q' }, { "verbose", 0, NULL, 'v' }, { "shrink", no_argument, NULL, GETOPT_VAL_SHRINK }, @@ -1154,7 +1156,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv) { NULL, 0, NULL, 0} }; - c = getopt_long(argc, argv, "A:b:fl:n:s:m:d:L:R:O:r:U:VvMKq", + c = getopt_long(argc, argv, "A:b:fl:n:s:m:d:L:R:O:r:U:P:VvMKq", long_options, NULL); if (c < 0) break; @@ -1262,6 +1264,10 @@ int BOX_MAIN(mkfs)(int argc, char **argv) strncpy(fs_uuid, optarg, BTRFS_UUID_UNPARSED_SIZE - 1); break; + case 'P': + strncpy(dev_uuid, optarg, + BTRFS_UUID_UNPARSED_SIZE - 1); + break; case 'K': opt_discard = false; break; @@ -1667,6 +1673,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv) mkfs_cfg.label = label; memcpy(mkfs_cfg.fs_uuid, fs_uuid, sizeof(mkfs_cfg.fs_uuid)); + memcpy(mkfs_cfg.dev_uuid, dev_uuid, sizeof(mkfs_cfg.dev_uuid)); mkfs_cfg.num_bytes = dev_block_count; mkfs_cfg.nodesize = nodesize; mkfs_cfg.sectorsize = sectorsize; -- 2.39.3 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] btrfs-progs: add mkfs -P option for dev_uuid 2023-09-28 1:09 ` [PATCH 2/2] btrfs-progs: add mkfs -P option for dev_uuid Anand Jain @ 2023-10-02 15:21 ` David Sterba 2023-10-03 3:45 ` Anand Jain 0 siblings, 1 reply; 6+ messages in thread From: David Sterba @ 2023-10-02 15:21 UTC (permalink / raw) To: Anand Jain; +Cc: linux-btrfs, dsterba, gpiccoli On Thu, Sep 28, 2023 at 09:09:19AM +0800, Anand Jain wrote: > Add an option to specify the device uuid for mkfs. This is useful > for creating a filesystem with a specific device uuid. This is > useful for testing. > > Signed-off-by: Anand Jain <anand.jain@oracle.com> > --- > mkfs/common.c | 8 +++++++- > mkfs/common.h | 1 + > mkfs/main.c | 9 ++++++++- > 3 files changed, 16 insertions(+), 2 deletions(-) > > diff --git a/mkfs/common.c b/mkfs/common.c > index d400413c7d41..e9a2fd5e4d3e 100644 > --- a/mkfs/common.c > +++ b/mkfs/common.c > @@ -340,6 +340,7 @@ static void mkfs_blocks_remove(enum btrfs_mkfs_block *blocks, int *blocks_nr, > > /* > * @fs_uuid - if NULL, generates a UUID, returns back the new filesystem UUID > + * @dev_uuid - if NULL, generates a UUID, returns back the new device UUID > * > * The superblock signature is not valid, denotes a partially created > * filesystem, needs to be finalized. > @@ -435,7 +436,12 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg) > } else { > uuid_parse(cfg->fs_uuid, super.fsid); > } > - uuid_generate(super.dev_item.uuid); > + if (!*cfg->dev_uuid) { > + uuid_generate(super.dev_item.uuid); > + uuid_unparse(super.dev_item.uuid, cfg->dev_uuid); > + } else { > + uuid_parse(cfg->dev_uuid, super.dev_item.uuid); > + } > uuid_generate(chunk_tree_uuid); > > for (i = 0; i < blocks_nr; i++) { > diff --git a/mkfs/common.h b/mkfs/common.h > index 06ddc926390f..d512ed853987 100644 > --- a/mkfs/common.h > +++ b/mkfs/common.h > @@ -91,6 +91,7 @@ struct btrfs_mkfs_config { > /* Logical addresses of superblock [0] and other tree roots */ > u64 blocks[MKFS_BLOCK_COUNT + 1]; > char fs_uuid[BTRFS_UUID_UNPARSED_SIZE]; > + char dev_uuid[BTRFS_UUID_UNPARSED_SIZE]; Please add a comment what this uuid means. > char chunk_uuid[BTRFS_UUID_UNPARSED_SIZE]; > > /* Superblock offset after make_btrfs */ > diff --git a/mkfs/main.c b/mkfs/main.c > index 68ff5d7785d3..f0ff1d6cc936 100644 > --- a/mkfs/main.c > +++ b/mkfs/main.c > @@ -1097,6 +1097,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv) > struct btrfs_mkfs_features features = btrfs_mkfs_default_features; > enum btrfs_csum_type csum_type = BTRFS_CSUM_TYPE_CRC32; > char fs_uuid[BTRFS_UUID_UNPARSED_SIZE] = { 0 }; > + char dev_uuid[BTRFS_UUID_UNPARSED_SIZE] = { 0 }; > u32 nodesize = 0; > bool nodesize_forced = false; > u32 sectorsize = 0; > @@ -1144,6 +1145,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv) > { "features", required_argument, NULL, 'O' }, > { "runtime-features", required_argument, NULL, 'R' }, > { "uuid", required_argument, NULL, 'U' }, > + { "uuid", required_argument, NULL, 'P' }, You can't add 2 long optiosn with the same name, also, don't add the short option for now. And the help text is also missing. > { "quiet", 0, NULL, 'q' }, > { "verbose", 0, NULL, 'v' }, > { "shrink", no_argument, NULL, GETOPT_VAL_SHRINK }, > @@ -1154,7 +1156,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv) > { NULL, 0, NULL, 0} > }; > > - c = getopt_long(argc, argv, "A:b:fl:n:s:m:d:L:R:O:r:U:VvMKq", > + c = getopt_long(argc, argv, "A:b:fl:n:s:m:d:L:R:O:r:U:P:VvMKq", > long_options, NULL); > if (c < 0) > break; > @@ -1262,6 +1264,10 @@ int BOX_MAIN(mkfs)(int argc, char **argv) > strncpy(fs_uuid, optarg, > BTRFS_UUID_UNPARSED_SIZE - 1); > break; > + case 'P': > + strncpy(dev_uuid, optarg, > + BTRFS_UUID_UNPARSED_SIZE - 1); > + break; > case 'K': > opt_discard = false; > break; > @@ -1667,6 +1673,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv) > > mkfs_cfg.label = label; > memcpy(mkfs_cfg.fs_uuid, fs_uuid, sizeof(mkfs_cfg.fs_uuid)); > + memcpy(mkfs_cfg.dev_uuid, dev_uuid, sizeof(mkfs_cfg.dev_uuid)); > mkfs_cfg.num_bytes = dev_block_count; > mkfs_cfg.nodesize = nodesize; > mkfs_cfg.sectorsize = sectorsize; > -- > 2.39.3 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] btrfs-progs: add mkfs -P option for dev_uuid 2023-10-02 15:21 ` David Sterba @ 2023-10-03 3:45 ` Anand Jain 0 siblings, 0 replies; 6+ messages in thread From: Anand Jain @ 2023-10-03 3:45 UTC (permalink / raw) To: dsterba; +Cc: linux-btrfs, dsterba, gpiccoli Thanks for the comment. I have fixed them (+ more) in v2. ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-10-03 3:45 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-09-28 1:09 [PATCH 0/2] btrfs-progs: mkfs: testing cloned-device Anand Jain 2023-09-28 1:09 ` [PATCH 1/2] btrfs-progs: allow duplicate fsid for single device Anand Jain 2023-10-02 15:22 ` David Sterba 2023-09-28 1:09 ` [PATCH 2/2] btrfs-progs: add mkfs -P option for dev_uuid Anand Jain 2023-10-02 15:21 ` David Sterba 2023-10-03 3:45 ` Anand Jain
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).