[Libguestfs] [PATCH] format, make-fs: specify the label on mkfs

Pino Toscano ptoscano at redhat.com
Tue Jan 13 09:38:10 UTC 2015


If specified, pass the label for the new filesystem directly to the
mkfs (or mkfs_btrfs) call.

This saves one set_label call, mostly.
---
 format/format.c   | 10 ++++++----
 make-fs/make-fs.c | 28 +++++++++++++++++-----------
 2 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/format/format.c b/format/format.c
index 4e6069f..cc371ab 100644
--- a/format/format.c
+++ b/format/format.c
@@ -434,13 +434,15 @@ do_format (void)
     }
 
     if (filesystem) {
-      if (guestfs_mkfs_opts (g, filesystem, dev, -1) == -1)
-        exit (EXIT_FAILURE);
+      struct guestfs_mkfs_opts_argv optargs = { .bitmask = 0 };
 
       if (label) {
-        if (guestfs_set_label (g, dev, label) == -1)
-          exit (EXIT_FAILURE);
+        optargs.label = label;
+        optargs.bitmask |= GUESTFS_MKFS_OPTS_LABEL_BITMASK;
       }
+
+      if (guestfs_mkfs_opts_argv (g, filesystem, dev, &optargs) == -1)
+        exit (EXIT_FAILURE);
     }
 
     if (free_dev)
diff --git a/make-fs/make-fs.c b/make-fs/make-fs.c
index 841c202..14729ad 100644
--- a/make-fs/make-fs.c
+++ b/make-fs/make-fs.c
@@ -755,9 +755,15 @@ do_make_fs (const char *input, const char *output_str)
   /* Create the filesystem. */
   if (STRNEQ (type, "btrfs")) {
     int r;
+    struct guestfs_mkfs_opts_argv optargs = { .bitmask = 0 };
+
+    if (label) {
+      optargs.label = label;
+      optargs.bitmask |= GUESTFS_MKFS_OPTS_LABEL_BITMASK;
+    }
 
     guestfs_push_error_handler (g, NULL, NULL);
-    r = guestfs_mkfs (g, type, dev);
+    r = guestfs_mkfs_opts_argv (g, type, dev, &optargs);
     guestfs_pop_error_handler (g);
 
     if (r == -1) {
@@ -774,17 +780,17 @@ do_make_fs (const char *input, const char *output_str)
   }
   else {
     const char *devs[] = { dev, NULL };
+    struct guestfs_mkfs_btrfs_argv optargs = { .bitmask = 0 };
+
+    optargs.datatype = "single";
+    optargs.metadata = "single";
+    optargs.bitmask |= GUESTFS_MKFS_BTRFS_DATATYPE_BITMASK | GUESTFS_MKFS_BTRFS_METADATA_BITMASK;
+    if (label) {
+      optargs.label = label;
+      optargs.bitmask |= GUESTFS_MKFS_BTRFS_LABEL_BITMASK;
+    }
 
-    if (guestfs_mkfs_btrfs (g, (char **) devs,
-                            GUESTFS_MKFS_BTRFS_DATATYPE, "single",
-                            GUESTFS_MKFS_BTRFS_METADATA, "single",
-                            -1) == -1)
-      return -1;
-  }
-
-  /* Set label. */
-  if (label) {
-    if (guestfs_set_label (g, dev, label) == -1)
+    if (guestfs_mkfs_btrfs_argv (g, (char **) devs, &optargs) == -1)
       return -1;
   }
 
-- 
1.9.3




More information about the Libguestfs mailing list