]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/hibernate-util: handle the case where no swap has available backing dev
authorMike Yuan <me@yhndnzj.com>
Thu, 2 Jan 2025 03:17:47 +0000 (04:17 +0100)
committerMike Yuan <me@yhndnzj.com>
Thu, 2 Jan 2025 14:29:34 +0000 (15:29 +0100)
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

src/shared/hibernate-util.c

index 49ce787d02e7a5a762a3499ea0cb6f0ba7075739..25d742ed1f80662f037edacbbaeb8300768450e7 100644 (file)
@@ -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) {