valeriyvdovin / rpms / systemd

Forked from rpms/systemd 4 years ago
Clone
803fb7
From 4fec67c88f7ddd02fecf711996f42ed4c9d24da6 Mon Sep 17 00:00:00 2001
803fb7
From: Franck Bui <fbui@suse.com>
803fb7
Date: Mon, 23 Nov 2015 11:14:10 +0100
803fb7
Subject: [PATCH] make sure all swap units are ordered before the swap target
803fb7
803fb7
When shutting down the system, the swap devices can be disabled long
803fb7
time before the swap target is stopped. They're actually the first
803fb7
units systemd turns off on my system.
803fb7
803fb7
This is incorrect and due to swap devices having multiple associated
803fb7
swap unit files. The main one is usually created by the fstab
803fb7
generator and is used to start the swap device.
803fb7
803fb7
Once done, systemd creates some 'alias' units for the same swap
803fb7
device, one for each swap dev link. But those units are missing an
803fb7
ordering dependencies which was created by the fstab generator for the
803fb7
main swap unit.
803fb7
803fb7
Therefore during shutdown those 'alias' units can be stopped at
803fb7
anytime before unmount.target target.
803fb7
803fb7
This patch makes sure that all swap units are stopped after the
803fb7
swap.target target.
803fb7
803fb7
Cherry-picked from: 8bf23dc757dacaaf5a8d2c21aabf71aee08d1a04
803fb7
Resolves: #1298355
803fb7
---
803fb7
 src/core/swap.c | 8 ++++++++
803fb7
 1 file changed, 8 insertions(+)
803fb7
803fb7
diff --git a/src/core/swap.c b/src/core/swap.c
803fb7
index 42f995990..984be2d9a 100644
803fb7
--- a/src/core/swap.c
803fb7
+++ b/src/core/swap.c
803fb7
@@ -210,6 +210,8 @@ static int swap_add_device_links(Swap *s) {
803fb7
 }
803fb7
 
803fb7
 static int swap_add_default_dependencies(Swap *s) {
803fb7
+        int r;
803fb7
+
803fb7
         assert(s);
803fb7
 
803fb7
         if (UNIT(s)->manager->running_as != SYSTEMD_SYSTEM)
803fb7
@@ -218,6 +220,12 @@ static int swap_add_default_dependencies(Swap *s) {
803fb7
         if (detect_container(NULL) > 0)
803fb7
                 return 0;
803fb7
 
803fb7
+        /* swap units generated for the swap dev links are missing the
803fb7
+         * ordering dep against the swap target. */
803fb7
+        r = unit_add_dependency_by_name(UNIT(s), UNIT_BEFORE, SPECIAL_SWAP_TARGET, NULL, true);
803fb7
+        if (r < 0)
803fb7
+                return r;
803fb7
+
803fb7
         return unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_UMOUNT_TARGET, NULL, true);
803fb7
 }
803fb7