]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
make sure all swap units are ordered before the swap target 1997/head
authorFranck Bui <fbui@suse.com>
Mon, 23 Nov 2015 10:14:10 +0000 (11:14 +0100)
committerFranck Bui <fbui@suse.com>
Mon, 23 Nov 2015 10:23:44 +0000 (11:23 +0100)
When shutting down the system, the swap devices can be disabled long
time before the swap target is stopped. They're actually the first
units systemd turns off on my system.

This is incorrect and due to swap devices having multiple associated
swap unit files. The main one is usually created by the fstab
generator and is used to start the swap device.

Once done, systemd creates some 'alias' units for the same swap
device, one for each swap dev link. But those units are missing an
ordering dependencies which was created by the fstab generator for the
main swap unit.

Therefore during shutdown those 'alias' units can be stopped at
anytime before unmount.target target.

This patch makes sure that all swap units are stopped after the
swap.target target.

src/core/swap.c

index ee0838e6762faf7a3435c3b5b9824b9cf90d9409..b6e4372fc0fbd15a2f92f51baaa852ff88a92503 100644 (file)
@@ -211,6 +211,8 @@ static int swap_add_device_links(Swap *s) {
 }
 
 static int swap_add_default_dependencies(Swap *s) {
+        int r;
+
         assert(s);
 
         if (!UNIT(s)->default_dependencies)
@@ -222,6 +224,12 @@ static int swap_add_default_dependencies(Swap *s) {
         if (detect_container() > 0)
                 return 0;
 
+        /* swap units generated for the swap dev links are missing the
+         * ordering dep against the swap target. */
+        r = unit_add_dependency_by_name(UNIT(s), UNIT_BEFORE, SPECIAL_SWAP_TARGET, NULL, true);
+        if (r < 0)
+                return r;
+
         return unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_UMOUNT_TARGET, NULL, true);
 }