]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
mkfs.xfs: option for using a pre-defined filesystem UUID
authorMika Eloranta <mel@ohmu.fi>
Tue, 13 Oct 2015 23:58:24 +0000 (10:58 +1100)
committerDave Chinner <david@fromorbit.com>
Tue, 13 Oct 2015 23:58:24 +0000 (10:58 +1100)
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>").

Signed-off-by: Mika Eloranta <mel@ohmu.fi>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
man/man8/mkfs.xfs.8
mkfs/xfs_mkfs.c

index 6260e0c6b9ba84745df6b611bc7177aba21938d8..e98b94d5d457b8064e0db776359193ad96ddeeb8 100644 (file)
@@ -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"
index 5964eaf2f189199f54fec83a14a1902c4c355321..903911175a73a16530b53f5b31cc65e109fdadb3 100644 (file)
@@ -183,6 +183,8 @@ char        *mopts[] = {
        "crc",
 #define M_FINOBT       1
        "finobt",
+#define M_UUID         2
+       "uuid",
        NULL
 };
 
@@ -983,6 +985,7 @@ main(
        bool                    finobtflag;
        int                     spinodes;
 
+       platform_uuid_generate(&uuid);
        progname = basename(argv[0]);
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
@@ -1523,6 +1526,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);
                                }
@@ -2585,7 +2594,6 @@ _("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);
        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);
@@ -3198,7 +3206,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\