teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/0420-make-sure-all-swap-units-are-ordered-before-the-swap.patch

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