Skip to contentSkip to conversation

btrfs-progs: remove redundant fs uuid validation from make_btrf

PATCH Superseded Nikolay Borisov 3 participants 5 messages Dec 16, 2021 – Jan 6, 2022 Btrfs file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs-progs: remove redundant fs uuid validation from make_btrf

cfg->fs_uuid is either 0 or set to the value of the -U parameter passed to mkfs.btrfs. However the value of the latter is already being validated in the main mkfs function. Just remove the duplicated checks in make_btrfs as they effectively can never be executed.

---
 mkfs/common.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
mkfs/common.c +1 -12
index fec23e64b2b2..72e84bc01712 100644
@@ -260,18 +260,7 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
 	memset(&super, 0, sizeof(super));
 
 	num_bytes = (cfg->num_bytes / cfg->sectorsize) * cfg->sectorsize;
-	if (*cfg->fs_uuid) {
-		if (uuid_parse(cfg->fs_uuid, super.fsid) != 0) {
-			error("cannot not parse UUID: %s", cfg->fs_uuid);
-			ret = -EINVAL;
-			goto out;
-		}
-		if (!test_uuid_unique(cfg->fs_uuid)) {
-			error("non-unique UUID: %s", cfg->fs_uuid);
-			ret = -EBUSY;
-			goto out;
-		}
-	} else {
+	if (!*cfg->fs_uuid) {
 		uuid_generate(super.fsid);
 		uuid_unparse(super.fsid, cfg->fs_uuid);
 	}

--
2.17.1

Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Nikolay Borisov

cfg->fs_uuid is either 0 or set to the value of the -U parameter passed to mkfs.btrfs. However the value of the latter is already being validated in the main mkfs function. Just remove the duplicated checks in make_btrfs as they effectively can never be executed.

--Anand

Quoted 31 lines
---
  mkfs/common.c | 13 +------------
  1 file changed, 1 insertion(+), 12 deletions(-)
mkfs/common.c +1 -13
index fec23e64b2b2..72e84bc01712 100644
@@ -260,18 +260,7 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
  	memset(&super, 0, sizeof(super));
 
  	num_bytes = (cfg->num_bytes / cfg->sectorsize) * cfg->sectorsize;
-	if (*cfg->fs_uuid) {
-		if (uuid_parse(cfg->fs_uuid, super.fsid) != 0) {
-			error("cannot not parse UUID: %s", cfg->fs_uuid);
-			ret = -EINVAL;
-			goto out;
-		}
-		if (!test_uuid_unique(cfg->fs_uuid)) {
-			error("non-unique UUID: %s", cfg->fs_uuid);
-			ret = -EBUSY;
-			goto out;
-		}
-	} else {
+	if (!*cfg->fs_uuid) {
  		uuid_generate(super.fsid);
  		uuid_unparse(super.fsid, cfg->fs_uuid);
  	}
--

2.17.1

#2 lore raw
In reply to Nikolay Borisov
Quoted 4 lines · Nikolay Borisov

cfg->fs_uuid is either 0 or set to the value of the -U parameter passed to mkfs.btrfs. However the value of the latter is already being validated in the main mkfs function. Just remove the duplicated checks in make_btrfs as they effectively can never be executed.

Actually the checks are executed but can never fail because they've already succeeded before calling them for the 2nd time here :). David you might want to amend this when committing.

Quoted 33 lines
---
 mkfs/common.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
mkfs/common.c +1 -13
index fec23e64b2b2..72e84bc01712 100644
@@ -260,18 +260,7 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
 	memset(&super, 0, sizeof(super));
 
 	num_bytes = (cfg->num_bytes / cfg->sectorsize) * cfg->sectorsize;
-	if (*cfg->fs_uuid) {
-		if (uuid_parse(cfg->fs_uuid, super.fsid) != 0) {
-			error("cannot not parse UUID: %s", cfg->fs_uuid);
-			ret = -EINVAL;
-			goto out;
-		}
-		if (!test_uuid_unique(cfg->fs_uuid)) {
-			error("non-unique UUID: %s", cfg->fs_uuid);
-			ret = -EBUSY;
-			goto out;
-		}
-	} else {
+	if (!*cfg->fs_uuid) {
 		uuid_generate(super.fsid);
 		uuid_unparse(super.fsid, cfg->fs_uuid);
 	}
--

2.17.1

#3 lore raw
In reply to Nikolay Borisov
Quoted 6 lines · Nikolay Borisov

cfg->fs_uuid is either 0 or set to the value of the -U parameter passed to mkfs.btrfs. However the value of the latter is already being validated in the main mkfs function. Just remove the duplicated checks in make_btrfs as they effectively can never be executed.

Added to devel, thanks.

#4 lore raw
Quoted 9 lines · David Sterba
Quoted 6 lines · Nikolay Borisov

cfg->fs_uuid is either 0 or set to the value of the -U parameter passed to mkfs.btrfs. However the value of the latter is already being validated in the main mkfs function. Just remove the duplicated checks in make_btrfs as they effectively can never be executed.

Added to devel, thanks.

And removed again, tests don't pass:

 $ make TEST=002-uuid-rewrite test-misc
 FAIL: current UUID mismatch
 test failed for case 002-uuid-rewrite
 make: *** [Makefile:457: test-misc] Error 1