Skip to contentSkip to conversation

mkfs.xfs: option for using a pre-defined filesystem UUID

PATCH In review Mika Eloranta 2 participants 2 messages Sep 22, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mkfs.xfs: option for using a pre-defined filesystem UUID

Usage: mkfs.xfs -m uuid=<uuid> <device>

The filesystem UUID can now be optionally specified during filesystem creation. The default behavior is still to generate a random UUID.

Allows using pre-generated UUIDs for identifying a filesystem based on the metadata stored inside the filesystem. Filesystem labels can be used for the same purpose, but are limited by their length (12 chars in the case of xfs) whereas the UUID field can store an entire 128bit UUID, which is plenty for e.g. random ID collision avoidance.

Random UUID generated during the creation of the filesystem is not always feasible when an external DB or other system is used to track the created filesystem, e.g. in automated VM provisioning systems, as this would require a feedback mechanism which is not always available. In these cases the best approach often is to generate a random UUID for the filesystem before the filesystem even exists, store it in the tracking DB and later create the filesystem directly with the correct UUID (instead of "mkfs.xfs + xfs_admin -U <new_uuid>").

---
 man/man8/mkfs.xfs.8 |  4 ++++
 mkfs/xfs_mkfs.c     | 15 +++++++++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)
man/man8/mkfs.xfs.8 +4 -0
index 6260e0c..e98b94d 100644
@@ -169,6 +169,10 @@ will create free inode btrees for filesystems created with the (default)
 option set. When the option
 .B \-m crc=0
 is used, the free inode btree feature is not supported and is disabled.
+.TP
+.BI uuid= value
+Use the given value as the filesystem UUID for the newly created filesystem.
+The default is to generate a random UUID.
 .RE
 .TP
 .BI \-d " data_section_options"
mkfs/xfs_mkfs.c +13 -2
index d993fc0..696c96d 100644
@@ -181,6 +181,8 @@ char	*mopts[] = {
 	"crc",
 #define M_FINOBT	1
 	"finobt",
+#define M_UUID		2
+	"uuid",
 	NULL
 };
 
@@ -948,6 +950,7 @@ main(
 	bool			finobtflag;
 	int			spinodes;
 
+	platform_uuid_clear(&uuid);
 	progname = basename(argv[0]);
 	setlocale(LC_ALL, "");
 	bindtextdomain(PACKAGE, LOCALEDIR);
@@ -1488,6 +1491,12 @@ main(
 					finobt = c;
 					finobtflag = true;
 					break;
+				case M_UUID:
+					if (!value || *value == '\0')
+						reqval('m', mopts, M_UUID);
+					if (platform_uuid_parse(value, &uuid))
+						illegal(optarg, "m uuid");
+					break;
 				default:
 					unknown('m', value);
 				}
@@ -2550,7 +2559,9 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
 	sbp->sb_dblocks = dblocks;
 	sbp->sb_rblocks = rtblocks;
 	sbp->sb_rextents = rtextents;
-	platform_uuid_generate(&uuid);
+	if (platform_uuid_is_null(&uuid)) {
+	    platform_uuid_generate(&uuid);
+	}
 	platform_uuid_copy(&sbp->sb_uuid, &uuid);
 	/* Only in memory; libxfs expects this as if read from disk */
 	platform_uuid_copy(&sbp->sb_meta_uuid, &uuid);
@@ -3163,7 +3174,7 @@ usage( void )
 {
 	fprintf(stderr, _("Usage: %s\n\
 /* blocksize */		[-b log=n|size=num]\n\
-/* metadata */		[-m crc=0|1,finobt=0|1]\n\
+/* metadata */		[-m crc=0|1,finobt=0|1,uuid=xxx]\n\
 /* data subvol */	[-d agcount=n,agsize=n,file,name=xxx,size=num,\n\
 			    (sunit=value,swidth=value|su=num,sw=num|noalign),\n\
 			    sectlog=n|sectsize=num\n\
Signature · 6 lines
2.3.5

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#1 lore raw
Quoted 12 lines · Mika Eloranta

Usage: mkfs.xfs -m uuid=<uuid> <device>

The filesystem UUID can now be optionally specified during filesystem creation. The default behavior is still to generate a random UUID.

Allows using pre-generated UUIDs for identifying a filesystem based on the metadata stored inside the filesystem. Filesystem labels can be used for the same purpose, but are limited by their length (12 chars in the case of xfs) whereas the UUID field can store an entire 128bit UUID, which is plenty for e.g. random ID collision avoidance.

Quoted 8 lines

Random UUID generated during the creation of the filesystem is not always feasible when an external DB or other system is used to track the created filesystem, e.g. in automated VM provisioning systems, as this would require a feedback mechanism which is not always available. In these cases the best approach often is to generate a random UUID for the filesystem before the filesystem even exists, store it in the tracking DB and later create the filesystem directly with the correct UUID (instead of "mkfs.xfs + xfs_admin -U <new_uuid>").

Much nicer! Just needs a signed-off-by tag now...

mkfs/xfs_mkfs.c main( · line 956

Quoted 8 lines
mkfs/xfs_mkfs.c +1 -0
@@ -948,6 +950,7 @@ main(
 	bool			finobtflag;
 	int			spinodes;
 
+	platform_uuid_clear(&uuid);
 	progname = basename(argv[0]);
 	setlocale(LC_ALL, "");
 	bindtextdomain(PACKAGE, LOCALEDIR);

You can just call platform_uuid_generate(&uuid) here.

mkfs/xfs_mkfs.c main( · line 1499

Quoted 10 lines
mkfs/xfs_mkfs.c +6 -0
@@ -1488,6 +1491,12 @@ main(
 					finobt = c;
 					finobtflag = true;
 					break;
+				case M_UUID:
+					if (!value || *value == '\0')
+						reqval('m', mopts, M_UUID);
+					if (platform_uuid_parse(value, &uuid))
+						illegal(optarg, "m uuid");
+					break;

This will overwrite the pre-generated uuid if it is specified.

mkfs/xfs_mkfs.c _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"), · line 2564

Quoted 11 lines
mkfs/xfs_mkfs.c +3 -1
 				default:
 					unknown('m', value);
 				}
@@ -2550,7 +2559,9 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
 	sbp->sb_dblocks = dblocks;
 	sbp->sb_rblocks = rtblocks;
 	sbp->sb_rextents = rtextents;
-	platform_uuid_generate(&uuid);
+	if (platform_uuid_is_null(&uuid)) {
+	    platform_uuid_generate(&uuid);
+	}

And this code can go away completely as we are guaranteed to have a valid uuid by this point.

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs