daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
Pablo Greco 48fc63
From 8fc26bd114d2aa997da261ac7c488d4c25116af3 Mon Sep 17 00:00:00 2001
Pablo Greco 48fc63
From: Andrew Jorgensen <ajorgens@amazon.com>
Pablo Greco 48fc63
Date: Wed, 25 Jul 2018 08:06:57 -0700
Pablo Greco 48fc63
Subject: [PATCH] shared/sleep-config: exclude zram devices from hibernation
Pablo Greco 48fc63
 candidates
Pablo Greco 48fc63
Pablo Greco 48fc63
On a host with sufficiently large zram but with no actual swap, logind will
Pablo Greco 48fc63
respond to CanHibernate() with yes. With this patch, it will correctly respond
Pablo Greco 48fc63
no, unless there are other swap devices to consider.
Pablo Greco 48fc63
Pablo Greco 48fc63
(cherry picked from commit 411ae92b407bd7b4549b205ad754bcd0e3dfd81f)
Pablo Greco 48fc63
Pablo Greco 48fc63
Resolves: #1609816
Pablo Greco 48fc63
---
Pablo Greco 48fc63
 src/shared/sleep-config.c | 17 ++++++++++++++---
Pablo Greco 48fc63
 1 file changed, 14 insertions(+), 3 deletions(-)
Pablo Greco 48fc63
Pablo Greco 48fc63
diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c
Pablo Greco 48fc63
index 1064fd5cbd..c4334652fc 100644
Pablo Greco 48fc63
--- a/src/shared/sleep-config.c
Pablo Greco 48fc63
+++ b/src/shared/sleep-config.c
Pablo Greco 48fc63
@@ -25,6 +25,7 @@
Pablo Greco 48fc63
 #include "sleep-config.h"
Pablo Greco 48fc63
 #include "fileio.h"
Pablo Greco 48fc63
 #include "log.h"
Pablo Greco 48fc63
+#include "path-util.h"
Pablo Greco 48fc63
 #include "strv.h"
Pablo Greco 48fc63
 #include "util.h"
Pablo Greco 48fc63
 
Pablo Greco 48fc63
@@ -202,9 +203,19 @@ static int hibernation_partition_size(size_t *size, size_t *used) {
Pablo Greco 48fc63
                         continue;
Pablo Greco 48fc63
                 }
Pablo Greco 48fc63
 
Pablo Greco 48fc63
-                if (streq(type, "partition") && endswith(dev, "\\040(deleted)")) {
Pablo Greco 48fc63
-                        log_warning("Ignoring deleted swapfile '%s'.", dev);
Pablo Greco 48fc63
-                        continue;
Pablo Greco 48fc63
+                if (streq(type, "partition")) {
Pablo Greco 48fc63
+                        const char *fn;
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+                        if (endswith(dev, "\\040(deleted)")) {
Pablo Greco 48fc63
+                                log_warning("Ignoring deleted swapfile '%s'.", dev);
Pablo Greco 48fc63
+                                continue;
Pablo Greco 48fc63
+                        }
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+                        fn = path_startswith(dev, "/dev/");
Pablo Greco 48fc63
+                        if (fn && startswith(fn, "zram")) {
Pablo Greco 48fc63
+                                log_debug("Ignoring compressed ram swap device '%s'.", dev);
Pablo Greco 48fc63
+                                continue;
Pablo Greco 48fc63
+                        }
Pablo Greco 48fc63
                 }
Pablo Greco 48fc63
 
Pablo Greco 48fc63
                 *size = size_field;