btrfs-progs: mkfs: testing cloned-device
cover btrfs-progs: mkfs: testing cloned-device
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(-)
Signature · 1 line
2.39.3
PATCH 1/2 btrfs-progs: allow duplicate fsid for single device
For single device btrfs filesystem, allow duplicate fsid to be created.
--- mkfs/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
mkfs/main.c +4 -1
@@ -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; }
Signature · 1 line
2.39.3
Re: [PATCH 1/2] btrfs-progs: allow duplicate fsid for single device
Quoted 3 lines · Anand Jain
For single device btrfs filesystem, allow duplicate fsid to be created.
Signed-off-by Anand Jain <[email protected]>
As this is trivial I'll add it to devel now, but the other patch needs updated.
PATCH 2/2 btrfs-progs: add mkfs -P option for dev_uuid
In reply to Anand JainAdd 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.
--- mkfs/common.c | 8 +++++++- mkfs/common.h | 1 + mkfs/main.c | 9 ++++++++- 3 files changed, 16 insertions(+), 2 deletions(-)
mkfs/common.c +7 -1
@@ -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++) {
mkfs/common.h +1 -0
@@ -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 */
mkfs/main.c +8 -1
@@ -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;
Signature · 1 line
2.39.3
Re: [PATCH 2/2] btrfs-progs: add mkfs -P option for dev_uuid
Quoted 42 lines · Anand Jain
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 <[email protected]>--- mkfs/common.c | 8 +++++++- mkfs/common.h | 1 + mkfs/main.c | 9 ++++++++- 3 files changed, 16 insertions(+), 2 deletions(-)mkfs/common.c +7
-1@@ -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++) {mkfs/common.h +0
-0
mkfs/common.h struct btrfs_mkfs_config { · line 94
Quoted 4 lines
mkfs/common.h +1
-0@@ -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.
Quoted 16 lines
mkfs/common.h +0
-0char chunk_uuid[BTRFS_UUID_UNPARSED_SIZE ];/* Superblock offset after make_btrfs */ mkfs/main.c +1
-0@@ -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 ;
mkfs/main.c int BOX_MAIN(mkfs)(int argc, char **argv) · line 1148
Quoted 4 lines
mkfs/main.c +1
-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.
Quoted 33 lines
mkfs/main.c +6
-1{ "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;Signature · 1 line
2.39.3
Re: [PATCH 2/2] btrfs-progs: add mkfs -P option for dev_uuid
Thanks for the comment. I have fixed them (+ more) in v2.