daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
c2dfb7
From b89a1a9d19aa806feb984c8dba25116b5b5a52bc Mon Sep 17 00:00:00 2001
c2dfb7
From: HATAYAMA Daisuke <d.hatayama@fujitsu.com>
c2dfb7
Date: Wed, 24 Jul 2019 23:54:48 -0400
c2dfb7
Subject: [PATCH] swap: finish the secondary swap units' jobs if deactivation
c2dfb7
 of the primary swap unit fails
c2dfb7
c2dfb7
Currently, if deactivation of the primary swap unit fails:
c2dfb7
c2dfb7
    # LANG=C systemctl --no-pager stop dev-mapper-fedora\\x2dswap.swap
c2dfb7
    Job for dev-mapper-fedora\x2dswap.swap failed.
c2dfb7
    See "systemctl status "dev-mapper-fedora\\x2dswap.swap"" and "journalctl -xe" for details.
c2dfb7
c2dfb7
then there are still the running stop jobs for all the secondary swap units
c2dfb7
that follow the primary one:
c2dfb7
c2dfb7
    # systemctl list-jobs
c2dfb7
     JOB UNIT                                                                                                         TYPE STATE
c2dfb7
     3233 dev-disk-by\x2duuid-2dc8b9b1\x2da0a5\x2d44d8\x2d89c4\x2d6cdd26cd5ce0.swap                                    stop running
c2dfb7
     3232 dev-dm\x2d1.swap                                                                                             stop running
c2dfb7
     3231 dev-disk-by\x2did-dm\x2duuid\x2dLVM\x2dyuXWpCCIurGzz2nkGCVnUFSi7GH6E3ZcQjkKLnF0Fil0RJmhoLN8fcOnDybWCMTj.swap stop running
c2dfb7
     3230 dev-disk-by\x2did-dm\x2dname\x2dfedora\x2dswap.swap                                                          stop running
c2dfb7
     3234 dev-fedora-swap.swap                                                                                         stop running
c2dfb7
c2dfb7
    5 jobs listed.
c2dfb7
c2dfb7
This remains endlessly because their JobTimeoutUSec is infinity:
c2dfb7
c2dfb7
    # LANG=C systemctl show -p JobTimeoutUSec dev-fedora-swap.swap
c2dfb7
    JobTimeoutUSec=infinity
c2dfb7
c2dfb7
If this issue happens during system shutdown, the system shutdown appears to
c2dfb7
get hang and the system will be forcibly shutdown or rebooted 30 minutes later
c2dfb7
by the following configuration:
c2dfb7
c2dfb7
    # grep -E "^JobTimeout" /usr/lib/systemd/system/reboot.target
c2dfb7
    JobTimeoutSec=30min
c2dfb7
    JobTimeoutAction=reboot-force
c2dfb7
c2dfb7
The scenario in the real world seems that there is some service unit with
c2dfb7
KillMode=none, processes whose memory is being swapped out are not killed
c2dfb7
during stop operation in the service unit and then swapoff command fails.
c2dfb7
c2dfb7
On the other hand, it works well in successful case of swapoff command because
c2dfb7
the secondary jobs monitor /proc/swaps file and can detect deletion of the
c2dfb7
corresponding swap file.
c2dfb7
c2dfb7
This commit fixes the issue by finishing the secondary swap units' jobs if
c2dfb7
deactivation of the primary swap unit fails.
c2dfb7
c2dfb7
Fixes: #11577
c2dfb7
(cherry picked from commit 9c1f969d40f84d5cc98d810bab8b24148b2d8928)
c2dfb7
c2dfb7
Resolves: #1749622
c2dfb7
---
c2dfb7
 src/core/swap.c | 10 ++++++++--
c2dfb7
 1 file changed, 8 insertions(+), 2 deletions(-)
c2dfb7
c2dfb7
diff --git a/src/core/swap.c b/src/core/swap.c
c2dfb7
index e717dbb54a..66a62d8a37 100644
c2dfb7
--- a/src/core/swap.c
c2dfb7
+++ b/src/core/swap.c
c2dfb7
@@ -682,9 +682,15 @@ static void swap_enter_active(Swap *s, SwapResult f) {
c2dfb7
 static void swap_enter_dead_or_active(Swap *s, SwapResult f) {
c2dfb7
         assert(s);
c2dfb7
 
c2dfb7
-        if (s->from_proc_swaps)
c2dfb7
+        if (s->from_proc_swaps) {
c2dfb7
+                Swap *other;
c2dfb7
+
c2dfb7
                 swap_enter_active(s, f);
c2dfb7
-        else
c2dfb7
+
c2dfb7
+                LIST_FOREACH_OTHERS(same_devnode, other, s)
c2dfb7
+                        if (UNIT(other)->job)
c2dfb7
+                                swap_enter_dead_or_active(other, f);
c2dfb7
+        } else
c2dfb7
                 swap_enter_dead(s, f);
c2dfb7
 }
c2dfb7