gpt-auto-generator: disable gpt auto logic for swaps if at least one is defined in...
authorFranck Bui <fbui@suse.com>
Mon, 26 Jun 2017 13:23:35 +0000 (15:23 +0200)
committerFranck Bui <fbui@suse.com>
Tue, 27 Jun 2017 08:06:36 +0000 (10:06 +0200)
If a swap partition is created on a disk using GPT then the unit generated by
the gpt-generator can shadow the one generated by the fstab-generator.

This can be an issue if the fstab entry for the swap has options since they are
simply ignored if PID1 decides to use the unit created by the gpt-generator
since this unit carries no information about the swap options.

This patch simply disables the GPT auto logic for swaps if at least one entry
for swap is defined in /etc/fstab.

Fixes: #6192

src/gpt-auto-generator/gpt-auto-generator.c

index a6cd8af..c531916 100644 (file)
@@ -305,6 +305,15 @@ static int add_swap(const char *path) {
 
         assert(path);
 
+        /* Disable the swap auto logic if at least one swap is defined in /etc/fstab, see #6192. */
+        r = fstab_has_fstype("swap");
+        if (r < 0)
+                return log_error_errno(r, "Failed to parse fstab: %m");
+        if (r == 0) {
+                log_debug("swap specified in fstab, ignoring.");
+                return 0;
+        }
+
         log_debug("Adding swap: %s", path);
 
         r = unit_name_from_path(path, ".swap", &name);