* [PATCH 0/2 v2] btrfs-progs: mkfs: testing cloned-device
@ 2023-10-03 3:46 Anand Jain
2023-10-03 3:46 ` [PATCH 1/2] btrfs-progs: document allowing duplicate fsid Anand Jain
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Anand Jain @ 2023-10-03 3:46 UTC (permalink / raw)
To: linux-btrfs; +Cc: dsterba, gpiccoli
v2:
Worked on review comments from David.
--- v1 ---
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: document allowing duplicate fsid
btrfs-progs: add mkfs option for dev_uuid
Documentation/mkfs.btrfs.rst | 10 ++++++++--
mkfs/common.c | 8 +++++++-
mkfs/common.h | 5 +++++
mkfs/main.c | 16 +++++++++++++++-
4 files changed, 35 insertions(+), 4 deletions(-)
--
2.39.3
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] btrfs-progs: document allowing duplicate fsid
2023-10-03 3:46 [PATCH 0/2 v2] btrfs-progs: mkfs: testing cloned-device Anand Jain
@ 2023-10-03 3:46 ` Anand Jain
2023-10-03 3:46 ` [PATCH 2/2 v2] btrfs-progs: add mkfs option for dev_uuid Anand Jain
2023-10-17 23:49 ` [PATCH 0/2 v2] btrfs-progs: mkfs: testing cloned-device David Sterba
2 siblings, 0 replies; 6+ messages in thread
From: Anand Jain @ 2023-10-03 3:46 UTC (permalink / raw)
To: linux-btrfs; +Cc: dsterba, gpiccoli
The commit ("btrfs-progs: allow duplicate fsid for single device
filesystems") lets the duplicate fsid used for a new mkfs document this.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
David,
This patch can be folded into patch:
ff4c4a3a00db btrfs-progs: allow duplicate fsid for single device filesystems
in your devel.
Documentation/mkfs.btrfs.rst | 5 +++--
mkfs/main.c | 2 +-
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/Documentation/mkfs.btrfs.rst b/Documentation/mkfs.btrfs.rst
index 2ff3ed241533..95ddc5399090 100644
--- a/Documentation/mkfs.btrfs.rst
+++ b/Documentation/mkfs.btrfs.rst
@@ -179,8 +179,9 @@ OPTIONS
Resets any previous effects of *--verbose*.
-U|--uuid <UUID>
- Create the filesystem with the given *UUID*. The UUID must not exist on any
- filesystem currently present.
+ Create the filesystem with the given *UUID*. For a single-device filesystem,
+ you can duplicate the UUID; however, for a multi-device filesystem, the UUID
+ must not already exist on any currently present filesystem.
-v|--verbose
Increase verbosity level, default is 1.
diff --git a/mkfs/main.c b/mkfs/main.c
index ead1edded9bf..ccab3c31b2f5 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -430,7 +430,7 @@ static const char * const mkfs_usage[] = {
OPTLINE("-s|--sectorsize SIZE", "data block size (may not be mountable by current kernel)"),
OPTLINE("-O|--features LIST", "comma separated list of filesystem features (use '-O list-all' to list features)"),
OPTLINE("-L|--label LABEL", "set the filesystem label"),
- OPTLINE("-U|--uuid UUID", "specify the filesystem UUID (must be unique)"),
+ OPTLINE("-U|--uuid UUID", "Specify the filesystem UUID (must be unique for a filesystem with multiple devices)"),
"Creation:",
OPTLINE("-b|--byte-count SIZE", "set size of each device to SIZE (filesystem size is sum of all device sizes)"),
OPTLINE("-r|--rootdir DIR", "copy files from DIR to the image root directory"),
--
2.39.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2 v2] btrfs-progs: add mkfs option for dev_uuid
2023-10-03 3:46 [PATCH 0/2 v2] btrfs-progs: mkfs: testing cloned-device Anand Jain
2023-10-03 3:46 ` [PATCH 1/2] btrfs-progs: document allowing duplicate fsid Anand Jain
@ 2023-10-03 3:46 ` Anand Jain
2023-10-17 23:49 ` [PATCH 0/2 v2] btrfs-progs: mkfs: testing cloned-device David Sterba
2 siblings, 0 replies; 6+ messages in thread
From: Anand Jain @ 2023-10-03 3:46 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>
---
v2:
Added --help.
Added comments for the dev_uuid and fs_uuid.
Removed short -P option instead using only long option --device-uuid.
Add error if --device-uuid is used with multi-device.
For example:
$ mkfs.btrfs -f --device-uuid 29e708ad-6fe5-447d-8910-a9b9f79854b5 /dev/sdc5 /dev/sdc6
btrfs-progs v6.5.1
See https://btrfs.readthedocs.io for more information.
ERROR: the option --device-uuid is limited to a single device
Documentation/mkfs.btrfs.rst | 5 +++++
mkfs/common.c | 8 +++++++-
mkfs/common.h | 5 +++++
mkfs/main.c | 14 ++++++++++++++
4 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/Documentation/mkfs.btrfs.rst b/Documentation/mkfs.btrfs.rst
index 95ddc5399090..919bb19c3e0a 100644
--- a/Documentation/mkfs.btrfs.rst
+++ b/Documentation/mkfs.btrfs.rst
@@ -183,6 +183,11 @@ OPTIONS
you can duplicate the UUID; however, for a multi-device filesystem, the UUID
must not already exist on any currently present filesystem.
+--device-uuid <UUID>
+ Create the filesystem with the given device-uuid (also known as sub-uuid) *UUID*.
+ For a single-device filesystem, you can duplicate the device-uuid; however, used
+ for a multi-device filesystem this option will not apply presently.
+
-v|--verbose
Increase verbosity level, default is 1.
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..554693b52aff 100644
--- a/mkfs/common.h
+++ b/mkfs/common.h
@@ -90,7 +90,12 @@ struct btrfs_mkfs_config {
/* Logical addresses of superblock [0] and other tree roots */
u64 blocks[MKFS_BLOCK_COUNT + 1];
+
+ /* btrfs_super_block filesystem uuid */
char fs_uuid[BTRFS_UUID_UNPARSED_SIZE];
+
+ /* btrfs_dev_item device uuid */
+ 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 ccab3c31b2f5..e92b43846217 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -431,6 +431,7 @@ static const char * const mkfs_usage[] = {
OPTLINE("-O|--features LIST", "comma separated list of filesystem features (use '-O list-all' to list features)"),
OPTLINE("-L|--label LABEL", "set the filesystem label"),
OPTLINE("-U|--uuid UUID", "Specify the filesystem UUID (must be unique for a filesystem with multiple devices)"),
+ OPTLINE("--device-uuid UUID", "Specify the filesystem device UUID (a.k.a sub-uuid) (for single device filesystem only)"),
"Creation:",
OPTLINE("-b|--byte-count SIZE", "set size of each device to SIZE (filesystem size is sum of all device sizes)"),
OPTLINE("-r|--rootdir DIR", "copy files from DIR to the image root directory"),
@@ -1161,6 +1162,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;
@@ -1187,6 +1189,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
GETOPT_VAL_SHRINK = GETOPT_VAL_FIRST,
GETOPT_VAL_CHECKSUM,
GETOPT_VAL_GLOBAL_ROOTS,
+ GETOPT_VAL_DEVICE_UUID,
};
static const struct option long_options[] = {
{ "byte-count", required_argument, NULL, 'b' },
@@ -1208,6 +1211,8 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
{ "features", required_argument, NULL, 'O' },
{ "runtime-features", required_argument, NULL, 'R' },
{ "uuid", required_argument, NULL, 'U' },
+ { "device-uuid", required_argument, NULL, \
+ GETOPT_VAL_DEVICE_UUID },
{ "quiet", 0, NULL, 'q' },
{ "verbose", 0, NULL, 'v' },
{ "shrink", no_argument, NULL, GETOPT_VAL_SHRINK },
@@ -1331,6 +1336,10 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
case 'q':
bconf_be_quiet();
break;
+ case GETOPT_VAL_DEVICE_UUID:
+ strncpy(dev_uuid, optarg,
+ BTRFS_UUID_UNPARSED_SIZE - 1);
+ break;
case GETOPT_VAL_SHRINK:
shrink_rootdir = true;
break;
@@ -1372,6 +1381,10 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
error("the option -r is limited to a single device");
goto error;
}
+ if (strlen(dev_uuid) != 0 && device_count > 1) {
+ error("the option --device-uuid is limited to a single device");
+ goto error;
+ }
if (shrink_rootdir && source_dir == NULL) {
error("the option --shrink must be used with --rootdir");
goto error;
@@ -1730,6 +1743,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 0/2 v2] btrfs-progs: mkfs: testing cloned-device
2023-10-03 3:46 [PATCH 0/2 v2] btrfs-progs: mkfs: testing cloned-device Anand Jain
2023-10-03 3:46 ` [PATCH 1/2] btrfs-progs: document allowing duplicate fsid Anand Jain
2023-10-03 3:46 ` [PATCH 2/2 v2] btrfs-progs: add mkfs option for dev_uuid Anand Jain
@ 2023-10-17 23:49 ` David Sterba
2023-10-19 1:32 ` Anand Jain
2 siblings, 1 reply; 6+ messages in thread
From: David Sterba @ 2023-10-17 23:49 UTC (permalink / raw)
To: Anand Jain; +Cc: linux-btrfs, dsterba, gpiccoli
On Tue, Oct 03, 2023 at 11:46:12AM +0800, Anand Jain wrote:
> v2:
> Worked on review comments from David.
>
> --- v1 ---
> 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: document allowing duplicate fsid
> btrfs-progs: add mkfs option for dev_uuid
Added to devel, thanks. I did some fixups, the device uuid is printed in
the summary and validation of the device uuid.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2 v2] btrfs-progs: mkfs: testing cloned-device
2023-10-17 23:49 ` [PATCH 0/2 v2] btrfs-progs: mkfs: testing cloned-device David Sterba
@ 2023-10-19 1:32 ` Anand Jain
2023-10-19 11:59 ` David Sterba
0 siblings, 1 reply; 6+ messages in thread
From: Anand Jain @ 2023-10-19 1:32 UTC (permalink / raw)
To: dsterba; +Cc: linux-btrfs, dsterba, gpiccoli
On 10/18/23 05:19, David Sterba wrote:
> On Tue, Oct 03, 2023 at 11:46:12AM +0800, Anand Jain wrote:
>> v2:
>> Worked on review comments from David.
>>
>> --- v1 ---
>> 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: document allowing duplicate fsid
+ must not already exist on any currently present filesystem.
There is a white-space error at the end of the line mentioned above in
the devel branch.
>> btrfs-progs: add mkfs option for dev_uuid
>
> Added to devel, thanks. I did some fixups, the device uuid is printed in
> the summary and validation of the device uuid.
Looks good. Thanks.
- Anand
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2 v2] btrfs-progs: mkfs: testing cloned-device
2023-10-19 1:32 ` Anand Jain
@ 2023-10-19 11:59 ` David Sterba
0 siblings, 0 replies; 6+ messages in thread
From: David Sterba @ 2023-10-19 11:59 UTC (permalink / raw)
To: Anand Jain; +Cc: dsterba, linux-btrfs, dsterba, gpiccoli
On Thu, Oct 19, 2023 at 07:02:45AM +0530, Anand Jain wrote:
>
>
> On 10/18/23 05:19, David Sterba wrote:
> > On Tue, Oct 03, 2023 at 11:46:12AM +0800, Anand Jain wrote:
> >> v2:
> >> Worked on review comments from David.
> >>
> >> --- v1 ---
> >> 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: document allowing duplicate fsid
>
>
>
> + must not already exist on any currently present filesystem.
Fixed.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-10-19 12:09 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-03 3:46 [PATCH 0/2 v2] btrfs-progs: mkfs: testing cloned-device Anand Jain
2023-10-03 3:46 ` [PATCH 1/2] btrfs-progs: document allowing duplicate fsid Anand Jain
2023-10-03 3:46 ` [PATCH 2/2 v2] btrfs-progs: add mkfs option for dev_uuid Anand Jain
2023-10-17 23:49 ` [PATCH 0/2 v2] btrfs-progs: mkfs: testing cloned-device David Sterba
2023-10-19 1:32 ` Anand Jain
2023-10-19 11:59 ` David Sterba
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).