systemd/0093-shared-hibernate-util-handle-the-case-where-no-swap-.patch
Jan Macku e20fafc72a systemd-257-3
Resolves: RHEL-44417, RHEL-71409, RHEL-72798
2025-01-08 09:25:36 +01:00

46 lines
1.9 KiB
Diff

From 01686c36cd564f8fd77386ae69808f498c32be83 Mon Sep 17 00:00:00 2001
From: Mike Yuan <me@yhndnzj.com>
Date: Thu, 2 Jan 2025 04:17:47 +0100
Subject: [PATCH] shared/hibernate-util: handle the case where no swap has
available backing dev
This also makes find_suitable_hibernation_device() report
more accurate error (ENOSPC -> ESTALE) if there's
no swap space on the system at all but resume= is set.
Fixes #35798
Replaces #35801
(cherry picked from commit bd3d361580715c7a6204c74df9185cc81d67f0c2)
---
src/shared/hibernate-util.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/src/shared/hibernate-util.c b/src/shared/hibernate-util.c
index 49ce787d02..25d742ed1f 100644
--- a/src/shared/hibernate-util.c
+++ b/src/shared/hibernate-util.c
@@ -359,8 +359,6 @@ int find_suitable_hibernation_device_full(HibernationDevice *ret_device, uint64_
r = read_swap_entries(&entries);
if (r < 0)
return r;
- if (entries.n_swaps == 0)
- return log_debug_errno(SYNTHETIC_ERRNO(ENOSPC), "No swap space available for hibernation.");
FOREACH_ARRAY(swap, entries.swaps, entries.n_swaps) {
r = swap_entry_get_resume_config(swap);
@@ -396,9 +394,10 @@ int find_suitable_hibernation_device_full(HibernationDevice *ret_device, uint64_
}
if (!entry) {
- /* No need to check n_swaps == 0, since it's rejected early */
- assert(resume_config_devno > 0);
- return log_debug_errno(SYNTHETIC_ERRNO(ESTALE), "Cannot find swap entry corresponding to /sys/power/resume.");
+ if (resume_config_devno > 0)
+ return log_debug_errno(SYNTHETIC_ERRNO(ESTALE), "Cannot find swap entry corresponding to /sys/power/resume.");
+
+ return log_debug_errno(SYNTHETIC_ERRNO(ENOSPC), "No swap space available for hibernation.");
}
if (ret_device) {