]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mkfs-util: Add quiet argument to make_filesystem()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 7 May 2023 19:39:10 +0000 (21:39 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 12 May 2023 05:51:50 +0000 (07:51 +0200)
We default to quiet operation everywhere except for repart, where
we disable quiet and have the mkfs tools write to stdout.

We also make sure --quiet or equivalent is implemented for all mkfs
tools.

src/home/homework-luks.c
src/partition/makefs.c
src/partition/repart.c
src/shared/mkfs-util.c
src/shared/mkfs-util.h
src/test/test-loop-block.c

index a24e0a70b2a0011fdb97e481893298c7c0914c76..802d9bf6f95662044e805485f3656b867a291e75 100644 (file)
@@ -2356,7 +2356,15 @@ int home_create_luks(
         if (r < 0)
                 return log_error_errno(r, "Failed to determine mkfs command line options for '%s': %m", fstype);
 
-        r = make_filesystem(setup->dm_node, fstype, user_record_user_name_and_realm(h), NULL, fs_uuid, user_record_luks_discard(h), 0, extra_mkfs_options);
+        r = make_filesystem(setup->dm_node,
+                            fstype,
+                            user_record_user_name_and_realm(h),
+                            /* root = */ NULL,
+                            fs_uuid,
+                            user_record_luks_discard(h),
+                            /* quiet = */ true,
+                            /* sector_size = */ 0,
+                            extra_mkfs_options);
         if (r < 0)
                 return r;
 
index b37a3b90081e8209e2946397f5ecda13c1b379a5..53439a4bbc5f042602a0b66efed3709aed232c06 100644 (file)
@@ -70,7 +70,15 @@ static int run(int argc, char *argv[]) {
         if (r < 0)
                 return log_error_errno(r, "Failed to extract file name from '%s': %m", device);
 
-        return make_filesystem(device, fstype, label, NULL, uuid, true, 0, NULL);
+        return make_filesystem(device,
+                               fstype,
+                               label,
+                               /* root = */ NULL,
+                               uuid,
+                               /* discard = */ true,
+                               /* quiet = */ true,
+                               /* sector_size = */ 0,
+                               /* extra_mkfs_options = */ NULL);
 }
 
 DEFINE_MAIN_FUNCTION(run);
index 44b0e461f2f819f196f9d9b8c0da0f0ef95d6948..8766225d6f92cb35df7e5c81b2da358624a016d3 100644 (file)
@@ -4270,7 +4270,8 @@ static int context_mkfs(Context *context) {
                                                p->format);
 
                 r = make_filesystem(partition_target_path(t), p->format, strempty(p->new_label), root,
-                                    p->fs_uuid, arg_discard, context->sector_size, extra_mkfs_options);
+                                    p->fs_uuid, arg_discard, /* quiet = */ false, context->sector_size,
+                                    extra_mkfs_options);
                 if (r < 0)
                         return r;
 
@@ -5604,7 +5605,7 @@ static int context_minimize(Context *context) {
                                                p->format);
 
                 r = make_filesystem(d ? d->node : temp, p->format, strempty(p->new_label), root, fs_uuid,
-                                    arg_discard, context->sector_size, extra_mkfs_options);
+                                    arg_discard, /* quiet = */ false, context->sector_size, extra_mkfs_options);
                 if (r < 0)
                         return r;
 
@@ -5669,7 +5670,7 @@ static int context_minimize(Context *context) {
                         return log_error_errno(r, "Failed to make loopback device of %s: %m", temp);
 
                 r = make_filesystem(d ? d->node : temp, p->format, strempty(p->new_label), root, p->fs_uuid,
-                                    arg_discard, context->sector_size, extra_mkfs_options);
+                                    arg_discard, /* quiet = */ false, context->sector_size, extra_mkfs_options);
                 if (r < 0)
                         return r;
 
index 16d2fb651fca2faea6822eaef1231e71e20c8a83..3d8c16b7b973bc9b4cd6cec761b61df5ed95c8fd 100644 (file)
@@ -264,6 +264,7 @@ int make_filesystem(
                 const char *root,
                 sd_id128_t uuid,
                 bool discard,
+                bool quiet,
                 uint64_t sector_size,
                 char * const *extra_mkfs_args) {
 
@@ -355,7 +356,6 @@ int make_filesystem(
         /* When changing this conditional, also adjust the log statement below. */
         if (STR_IN_SET(fstype, "ext2", "ext3", "ext4")) {
                 argv = strv_new(mkfs,
-                                "-q",
                                 "-L", label,
                                 "-U", vol_id,
                                 "-I", "256",
@@ -368,9 +368,11 @@ int make_filesystem(
                 if (root && strv_extend_strv(&argv, STRV_MAKE("-d", root), false) < 0)
                         return log_oom();
 
+                if (quiet && strv_extend(&argv, "-q") < 0)
+                        return log_oom();
+
         } else if (streq(fstype, "btrfs")) {
                 argv = strv_new(mkfs,
-                                "-q",
                                 "-L", label,
                                 "-U", vol_id,
                                 node);
@@ -383,9 +385,11 @@ int make_filesystem(
                 if (root && strv_extend_strv(&argv, STRV_MAKE("-r", root), false) < 0)
                         return log_oom();
 
+                if (quiet && strv_extend(&argv, "-q") < 0)
+                        return log_oom();
+
         } else if (streq(fstype, "f2fs")) {
                 argv = strv_new(mkfs,
-                                "-q",
                                 "-g",  /* "default options" */
                                 "-f",  /* force override, without this it doesn't seem to want to write to an empty partition */
                                 "-l", label,
@@ -393,13 +397,15 @@ int make_filesystem(
                                 "-t", one_zero(discard),
                                 node);
 
+                if (quiet && strv_extend(&argv, "-q") < 0)
+                        return log_oom();
+
         } else if (streq(fstype, "xfs")) {
                 const char *j;
 
                 j = strjoina("uuid=", vol_id);
 
                 argv = strv_new(mkfs,
-                                "-q",
                                 "-L", label,
                                 "-m", j,
                                 "-m", "reflink=1",
@@ -427,6 +433,9 @@ int make_filesystem(
                                 return log_oom();
                 }
 
+                if (quiet && strv_extend(&argv, "-q") < 0)
+                        return log_oom();
+
         } else if (streq(fstype, "vfat")) {
 
                 argv = strv_new(mkfs,
@@ -444,32 +453,40 @@ int make_filesystem(
                 }
 
                 /* mkfs.vfat does not have a --quiet option so let's redirect stdout to /dev/null instead. */
-                stdio_fds[1] = -EBADF;
+                if (quiet)
+                        stdio_fds[1] = -EBADF;
 
-        } else if (streq(fstype, "swap"))
-                /* TODO: add --quiet here if
-                 * https://github.com/util-linux/util-linux/issues/1499 resolved. */
+        } else if (streq(fstype, "swap")) {
+                /* TODO: add --quiet once util-linux v2.38 is available everywhere. */
 
                 argv = strv_new(mkfs,
                                 "-L", label,
                                 "-U", vol_id,
                                 node);
 
-        else if (streq(fstype, "squashfs")) {
+                if (quiet)
+                        stdio_fds[1] = -EBADF;
+
+        } else if (streq(fstype, "squashfs")) {
 
                 argv = strv_new(mkfs,
                                 root, node,
                                 "-noappend");
 
                 /* mksquashfs -quiet option is pretty new so let's redirect stdout to /dev/null instead. */
-                stdio_fds[1] = -EBADF;
+                if (quiet)
+                        stdio_fds[1] = -EBADF;
 
-        } else if (streq(fstype, "erofs"))
+        } else if (streq(fstype, "erofs")) {
 
                 argv = strv_new(mkfs,
                                 "-U", vol_id,
                                 node, root);
-        else
+
+                if (quiet && strv_extend(&argv, "--quiet") < 0)
+                        return log_oom();
+
+        } else
                 /* Generic fallback for all other file systems */
                 argv = strv_new(mkfs, node);
 
index 75ea58543a1e4c51f5122cfb68719bebaa892e25..9a1cb585d6cec3abcfc9fdbc977ca0b60e25e9f2 100644 (file)
@@ -18,6 +18,7 @@ int make_filesystem(
                 const char *root,
                 sd_id128_t uuid,
                 bool discard,
+                bool quiet,
                 uint64_t sector_size,
                 char * const *extra_mkfs_args);
 
index d8f48798cb0dcb9cd1ccba0a3b1ce2d754ba4c17..fad5496052a1d177d1973d747e77c999b4be55d0 100644 (file)
@@ -245,16 +245,16 @@ static int run(int argc, char *argv[]) {
         assert_se(r >= 0);
 
         assert_se(sd_id128_randomize(&id) >= 0);
-        assert_se(make_filesystem(dissected->partitions[PARTITION_ESP].node, "vfat", "EFI", NULL, id, true, 0, NULL) >= 0);
+        assert_se(make_filesystem(dissected->partitions[PARTITION_ESP].node, "vfat", "EFI", NULL, id, true, false, 0, NULL) >= 0);
 
         assert_se(sd_id128_randomize(&id) >= 0);
-        assert_se(make_filesystem(dissected->partitions[PARTITION_XBOOTLDR].node, "vfat", "xbootldr", NULL, id, true, 0, NULL) >= 0);
+        assert_se(make_filesystem(dissected->partitions[PARTITION_XBOOTLDR].node, "vfat", "xbootldr", NULL, id, true, false, 0, NULL) >= 0);
 
         assert_se(sd_id128_randomize(&id) >= 0);
-        assert_se(make_filesystem(dissected->partitions[PARTITION_ROOT].node, "ext4", "root", NULL, id, true, 0, NULL) >= 0);
+        assert_se(make_filesystem(dissected->partitions[PARTITION_ROOT].node, "ext4", "root", NULL, id, true, false, 0, NULL) >= 0);
 
         assert_se(sd_id128_randomize(&id) >= 0);
-        assert_se(make_filesystem(dissected->partitions[PARTITION_HOME].node, "ext4", "home", NULL, id, true, 0, NULL) >= 0);
+        assert_se(make_filesystem(dissected->partitions[PARTITION_HOME].node, "ext4", "home", NULL, id, true, false, 0, NULL) >= 0);
 
         dissected = dissected_image_unref(dissected);