Merge pull request #27330 from YHNdnzj/hibernate-resume-auto

sleep/hibernate-resume: pass hibernate location through efivar for resume without kernel cmdline
This commit is contained in:
Lennart Poettering
2023-06-23 23:03:32 +02:00
committed by GitHub
14 changed files with 356 additions and 144 deletions
+46
View File
@@ -1028,6 +1028,52 @@ int read_fiemap(int fd, struct fiemap **ret) {
return 0;
}
int write_resume_config(dev_t devno, uint64_t offset, const char *device) {
char offset_str[DECIMAL_STR_MAX(uint64_t)];
_cleanup_free_ char *path = NULL;
const char *devno_str;
int r;
devno_str = FORMAT_DEVNUM(devno);
xsprintf(offset_str, "%" PRIu64, offset);
if (!device) {
r = device_path_make_canonical(S_IFBLK, devno, &path);
if (r < 0)
return log_error_errno(r,
"Failed to format canonical device path for devno '" DEVNUM_FORMAT_STR "': %m",
DEVNUM_FORMAT_VAL(devno));
device = path;
}
/* We write the offset first since it's safer. Note that this file is only available in 4.17+, so
* fail gracefully if it doesn't exist and we're only overwriting it with 0. */
r = write_string_file("/sys/power/resume_offset", offset_str, WRITE_STRING_FILE_DISABLE_BUFFER);
if (r == -ENOENT) {
if (offset != 0)
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"Can't configure hibernation offset %" PRIu64 ", kernel does not support /sys/power/resume_offset. Refusing.",
offset);
log_warning_errno(r, "/sys/power/resume_offset is unavailable, skipping writing swap file offset.");
} else if (r < 0)
return log_error_errno(r,
"Failed to write swap file offset %s to /sys/power/resume_offset for device '%s': %m",
offset_str, device);
else
log_debug("Wrote resume_offset=%s for device '%s' to /sys/power/resume_offset.",
offset_str, device);
r = write_string_file("/sys/power/resume", devno_str, WRITE_STRING_FILE_DISABLE_BUFFER);
if (r < 0)
return log_error_errno(r,
"Failed to write device '%s' (%s) to /sys/power/resume: %m",
device, devno_str);
log_debug("Wrote resume=%s for device '%s' to /sys/power/resume.", devno_str, device);
return 0;
}
static int can_sleep_internal(const SleepConfig *sleep_config, SleepOperation operation, bool check_allowed);
static bool can_s2h(const SleepConfig *sleep_config) {
+2
View File
@@ -2,6 +2,7 @@
#pragma once
#include <linux/fiemap.h>
#include <sys/types.h>
#include "hashmap.h"
#include "time-util.h"
@@ -63,6 +64,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(HibernateLocation*, hibernate_location_free);
int read_fiemap(int fd, struct fiemap **ret);
int parse_sleep_config(SleepConfig **sleep_config);
int find_hibernate_location(HibernateLocation **ret_hibernate_location);
int write_resume_config(dev_t devno, uint64_t offset, const char *device);
int can_sleep(SleepOperation operation);
int can_sleep_disk(char **types);