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