]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fstab-generator: call add_swap() earlier
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 12 May 2023 07:08:32 +0000 (16:08 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 23 May 2023 23:23:22 +0000 (08:23 +0900)
As 'where' field will be ignored for swap entry.

src/fstab-generator/fstab-generator.c

index 149bd5daf6934e97b18df962d688cee52b46c7a4..042cce1ffafec0e1590368329d9b21c00295d837 100644 (file)
@@ -131,6 +131,11 @@ static int add_swap(
                 return true;
         }
 
+        log_debug("Found swap entry what=%s makefs=%s growfs=%s pcrfs=%s noauto=%s nofail=%s",
+                  what,
+                  yes_no(flags & MOUNT_MAKEFS), yes_no(flags & MOUNT_GROWFS), yes_no(flags & MOUNT_PCRFS),
+                  yes_no(flags & MOUNT_NOAUTO), yes_no(flags & MOUNT_NOFAIL));
+
         r = unit_name_from_path(what, ".swap", &name);
         if (r < 0)
                 return log_error_errno(r, "Failed to generate unit name: %m");
@@ -702,16 +707,18 @@ static int parse_fstab_one(
 
         _cleanup_free_ char *what = NULL, *where = NULL, *canonical_where = NULL;
         MountPointFlags flags;
+        bool is_swap;
         int r;
 
         assert(what_original);
-        assert(where_original);
         assert(fstype);
         assert(options);
 
         if (initrd && !mount_in_initrd(where_original, options))
                 return 0;
 
+        is_swap = streq_ptr(fstype, "swap");
+
         what = fstab_node_to_udev_node(what_original);
         if (!what)
                 return log_oom();
@@ -723,6 +730,13 @@ static int parse_fstab_one(
                 return 0;
         }
 
+        flags = fstab_options_to_flags(options, is_swap);
+
+        if (is_swap)
+                return add_swap(source, what, options, flags);
+
+        assert(where_original); /* 'where' is not necessary for swap entry. */
+
         where = strdup(where_original);
         if (!where)
                 return log_oom();
@@ -757,16 +771,11 @@ static int parse_fstab_one(
                         log_debug("Canonicalized what=%s where=%s to %s", what, where, canonical_where);
         }
 
-        flags = fstab_options_to_flags(options, streq_ptr(fstype, "swap"));
-
         log_debug("Found entry what=%s where=%s type=%s makefs=%s growfs=%s pcrfs=%s noauto=%s nofail=%s",
                   what, where, strna(fstype),
                   yes_no(flags & MOUNT_MAKEFS), yes_no(flags & MOUNT_GROWFS), yes_no(flags & MOUNT_PCRFS),
                   yes_no(flags & MOUNT_NOAUTO), yes_no(flags & MOUNT_NOFAIL));
 
-        if (streq_ptr(fstype, "swap"))
-                return add_swap(source, what, options, flags);
-
         bool is_sysroot = in_initrd() && path_equal(where, "/sysroot");
         /* See comment from add_sysroot_usr_mount() about the need for extra indirection in case /usr needs
          * to be mounted in order for the root fs to be synthesized based on configuration included in /usr/,