Skip to content

Commit 4cd9921

Browse files
YHNdnzjbluca
authored andcommitted
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 bd3d361) (cherry picked from commit 01686c3) (cherry picked from commit a354987)
1 parent 6c4d03c commit 4cd9921

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/shared/hibernate-util.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,6 @@ int find_suitable_hibernation_device_full(HibernationDevice *ret_device, uint64_
358358
r = read_swap_entries(&entries);
359359
if (r < 0)
360360
return r;
361-
if (entries.n_swaps == 0)
362-
return log_debug_errno(SYNTHETIC_ERRNO(ENOSPC), "No swap space available for hibernation.");
363361

364362
FOREACH_ARRAY(swap, entries.swaps, entries.n_swaps) {
365363
r = swap_entry_get_resume_config(swap);
@@ -395,9 +393,10 @@ int find_suitable_hibernation_device_full(HibernationDevice *ret_device, uint64_
395393
}
396394

397395
if (!entry) {
398-
/* No need to check n_swaps == 0, since it's rejected early */
399-
assert(resume_config_devno > 0);
400-
return log_debug_errno(SYNTHETIC_ERRNO(ESTALE), "Cannot find swap entry corresponding to /sys/power/resume.");
396+
if (resume_config_devno > 0)
397+
return log_debug_errno(SYNTHETIC_ERRNO(ESTALE), "Cannot find swap entry corresponding to /sys/power/resume.");
398+
399+
return log_debug_errno(SYNTHETIC_ERRNO(ENOSPC), "No swap space available for hibernation.");
401400
}
402401

403402
if (ret_device) {

0 commit comments

Comments
 (0)