| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
/*** |
| 3 |
Copyright © 2018 Dell Inc. |
| 4 |
***/ |
| 5 |
|
| 6 |
#include <linux/fiemap.h> |
| 7 |
#include <linux/fs.h> |
| 8 |
#include <linux/magic.h> |
| 9 |
#include <sys/ioctl.h> |
| 10 |
|
| 11 |
#include "alloc-util.h" |
| 12 |
#include "blockdev-util.h" |
| 13 |
#include "btrfs-util.h" |
| 14 |
#include "devnum-util.h" |
| 15 |
#include "efivars.h" |
| 16 |
#include "env-util.h" |
| 17 |
#include "fd-util.h" |
| 18 |
#include "fileio.h" |
| 19 |
#include "hibernate-util.h" |
| 20 |
#include "log.h" |
| 21 |
#include "parse-util.h" |
| 22 |
#include "path-util.h" |
| 23 |
#include "proc-cmdline.h" |
| 24 |
#include "stat-util.h" |
| 25 |
|
| 26 |
#define HIBERNATION_SWAP_THRESHOLD 0.98 |
| 27 |
|
| 28 |
void hibernation_device_done(HibernationDevice *device) { |
| 29 |
assert(device); |
| 30 |
|
| 31 |
free(device->path); |
| 32 |
} |
| 33 |
|
| 34 |
int read_fiemap(int fd, struct fiemap **ret) { |
| 35 |
_cleanup_free_ struct fiemap *fiemap = NULL, *result_fiemap = NULL; |
| 36 |
struct stat statinfo; |
| 37 |
uint32_t result_extents = 0; |
| 38 |
uint64_t fiemap_start = 0, fiemap_length; |
| 39 |
const size_t n_extra = DIV_ROUND_UP(sizeof(struct fiemap), sizeof(struct fiemap_extent)); |
| 40 |
int r; |
| 41 |
|
| 42 |
assert(fd >= 0); |
| 43 |
assert(ret); |
| 44 |
|
| 45 |
if (fstat(fd, &statinfo) < 0) |
| 46 |
return log_debug_errno(errno, "Cannot determine file size: %m"); |
| 47 |
r = stat_verify_regular(&statinfo); |
| 48 |
if (r < 0) |
| 49 |
return r; |
| 50 |
fiemap_length = statinfo.st_size; |
| 51 |
|
| 52 |
/* Zero this out in case we run on a file with no extents */ |
| 53 |
fiemap = calloc(n_extra, sizeof(struct fiemap_extent)); |
| 54 |
if (!fiemap) |
| 55 |
return -ENOMEM; |
| 56 |
|
| 57 |
result_fiemap = malloc_multiply(n_extra, sizeof(struct fiemap_extent)); |
| 58 |
if (!result_fiemap) |
| 59 |
return -ENOMEM; |
| 60 |
|
| 61 |
/* XFS filesystem has incorrect implementation of fiemap ioctl and |
| 62 |
* returns extents for only one block-group at a time, so we need |
| 63 |
* to handle it manually, starting the next fiemap call from the end |
| 64 |
* of the last extent. */ |
| 65 |
while (fiemap_start < fiemap_length) { |
| 66 |
*fiemap = (struct fiemap) { |
| 67 |
.fm_start = fiemap_start, |
| 68 |
.fm_length = fiemap_length, |
| 69 |
.fm_flags = FIEMAP_FLAG_SYNC, |
| 70 |
}; |
| 71 |
|
| 72 |
/* Find out how many extents there are */ |
| 73 |
if (ioctl(fd, FS_IOC_FIEMAP, fiemap) < 0) |
| 74 |
return log_debug_errno(errno, "Failed to read extents: %m"); |
| 75 |
|
| 76 |
/* Nothing to process */ |
| 77 |
if (fiemap->fm_mapped_extents == 0) |
| 78 |
break; |
| 79 |
|
| 80 |
/* Resize fiemap to allow us to read in the extents, result fiemap has to hold all |
| 81 |
* the extents for the whole file. Add space for the initial struct fiemap. */ |
| 82 |
if (!greedy_realloc0((void**) &fiemap, n_extra + fiemap->fm_mapped_extents, sizeof(struct fiemap_extent))) |
| 83 |
return -ENOMEM; |
| 84 |
|
| 85 |
fiemap->fm_extent_count = fiemap->fm_mapped_extents; |
| 86 |
fiemap->fm_mapped_extents = 0; |
| 87 |
|
| 88 |
if (ioctl(fd, FS_IOC_FIEMAP, fiemap) < 0) |
| 89 |
return log_debug_errno(errno, "Failed to read extents: %m"); |
| 90 |
|
| 91 |
/* Resize result_fiemap to allow us to copy in the extents */ |
| 92 |
if (!greedy_realloc((void**) &result_fiemap, |
| 93 |
n_extra + result_extents + fiemap->fm_mapped_extents, sizeof(struct fiemap_extent))) |
| 94 |
return -ENOMEM; |
| 95 |
|
| 96 |
memcpy(result_fiemap->fm_extents + result_extents, |
| 97 |
fiemap->fm_extents, |
| 98 |
sizeof(struct fiemap_extent) * fiemap->fm_mapped_extents); |
| 99 |
|
| 100 |
result_extents += fiemap->fm_mapped_extents; |
| 101 |
|
| 102 |
/* Highly unlikely that it is zero */ |
| 103 |
if (_likely_(fiemap->fm_mapped_extents > 0)) { |
| 104 |
uint32_t i = fiemap->fm_mapped_extents - 1; |
| 105 |
|
| 106 |
fiemap_start = fiemap->fm_extents[i].fe_logical + |
| 107 |
fiemap->fm_extents[i].fe_length; |
| 108 |
|
| 109 |
if (fiemap->fm_extents[i].fe_flags & FIEMAP_EXTENT_LAST) |
| 110 |
break; |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
memcpy(result_fiemap, fiemap, sizeof(struct fiemap)); |
| 115 |
result_fiemap->fm_mapped_extents = result_extents; |
| 116 |
*ret = TAKE_PTR(result_fiemap); |
| 117 |
return 0; |
| 118 |
} |
| 119 |
|
| 120 |
static int read_resume_config(dev_t *ret_devno, uint64_t *ret_offset) { |
| 121 |
_cleanup_free_ char *devno_str = NULL, *offset_str = NULL; |
| 122 |
uint64_t offset; |
| 123 |
dev_t devno; |
| 124 |
int r; |
| 125 |
|
| 126 |
assert(ret_devno); |
| 127 |
assert(ret_offset); |
| 128 |
|
| 129 |
r = proc_cmdline_get_key("noresume", /* flags= */ 0, /* ret_value= */ NULL); |
| 130 |
if (r < 0) |
| 131 |
return log_debug_errno(r, "Failed to check if 'noresume' kernel command line option is set: %m"); |
| 132 |
if (r > 0) |
| 133 |
return log_debug_errno(SYNTHETIC_ERRNO(ENOTRECOVERABLE), |
| 134 |
"'noresume' kernel command line option is set, refusing hibernation device lookup."); |
| 135 |
|
| 136 |
r = read_one_line_file("/sys/power/resume", &devno_str); |
| 137 |
if (r < 0) |
| 138 |
return log_debug_errno(r, "Failed to read /sys/power/resume: %m"); |
| 139 |
|
| 140 |
r = parse_devnum(devno_str, &devno); |
| 141 |
if (r < 0) |
| 142 |
return log_debug_errno(r, "Failed to parse /sys/power/resume devno '%s': %m", devno_str); |
| 143 |
|
| 144 |
r = read_one_line_file("/sys/power/resume_offset", &offset_str); |
| 145 |
if (r < 0) |
| 146 |
return log_debug_errno(r, "Failed to read /sys/power/resume_offset: %m"); |
| 147 |
|
| 148 |
r = safe_atou64(offset_str, &offset); |
| 149 |
if (r < 0) |
| 150 |
return log_debug_errno(r, "Failed to parse /sys/power/resume_offset '%s': %m", offset_str); |
| 151 |
|
| 152 |
if (devno == 0 && offset > 0) |
| 153 |
return log_debug_errno(SYNTHETIC_ERRNO(ENOMEDIUM), |
| 154 |
"Found populated /sys/power/resume_offset (%" PRIu64 ") but /sys/power/resume is not set, refusing.", |
| 155 |
offset); |
| 156 |
|
| 157 |
*ret_devno = devno; |
| 158 |
*ret_offset = offset; |
| 159 |
|
| 160 |
return 0; |
| 161 |
} |
| 162 |
|
| 163 |
/* entry in /proc/swaps */ |
| 164 |
typedef struct SwapEntry { |
| 165 |
char *path; |
| 166 |
bool swapfile; |
| 167 |
|
| 168 |
uint64_t size; |
| 169 |
uint64_t used; |
| 170 |
int priority; |
| 171 |
|
| 172 |
/* Not present in original entry */ |
| 173 |
dev_t devno; |
| 174 |
uint64_t offset; |
| 175 |
} SwapEntry; |
| 176 |
|
| 177 |
typedef struct SwapEntries { |
| 178 |
SwapEntry *swaps; |
| 179 |
size_t n_swaps; |
| 180 |
} SwapEntries; |
| 181 |
|
| 182 |
static void swap_entry_done(SwapEntry *entry) { |
| 183 |
assert(entry); |
| 184 |
|
| 185 |
free(entry->path); |
| 186 |
} |
| 187 |
|
| 188 |
static void swap_entries_done(SwapEntries *entries) { |
| 189 |
assert(entries); |
| 190 |
|
| 191 |
FOREACH_ARRAY(i, entries->swaps, entries->n_swaps) |
| 192 |
swap_entry_done(i); |
| 193 |
|
| 194 |
free(entries->swaps); |
| 195 |
} |
| 196 |
|
| 197 |
static int swap_entry_get_resume_config(SwapEntry *swap) { |
| 198 |
_cleanup_close_ int fd = -EBADF; |
| 199 |
uint64_t offset_raw; |
| 200 |
struct stat st; |
| 201 |
int r; |
| 202 |
|
| 203 |
assert(swap); |
| 204 |
assert(swap->path); |
| 205 |
|
| 206 |
fd = open(swap->path, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY); |
| 207 |
if (fd < 0) |
| 208 |
return -errno; |
| 209 |
|
| 210 |
if (fstat(fd, &st) < 0) |
| 211 |
return -errno; |
| 212 |
|
| 213 |
if (!swap->swapfile) { |
| 214 |
r = stat_verify_block(&st); |
| 215 |
if (r < 0) |
| 216 |
return r; |
| 217 |
|
| 218 |
swap->devno = st.st_rdev; |
| 219 |
swap->offset = 0; |
| 220 |
return 0; |
| 221 |
} |
| 222 |
|
| 223 |
r = stat_verify_regular(&st); |
| 224 |
if (r < 0) |
| 225 |
return r; |
| 226 |
|
| 227 |
r = get_block_device_fd(fd, &swap->devno); |
| 228 |
if (r < 0) |
| 229 |
return r; |
| 230 |
if (r == 0) |
| 231 |
return -EMEDIUMTYPE; |
| 232 |
|
| 233 |
r = fd_is_fs_type(fd, BTRFS_SUPER_MAGIC); |
| 234 |
if (r < 0) |
| 235 |
return log_debug_errno(r, "Failed to check if swap file '%s' is on Btrfs: %m", swap->path); |
| 236 |
if (r > 0) { |
| 237 |
r = btrfs_get_file_physical_offset_fd(fd, &offset_raw); |
| 238 |
if (r < 0) |
| 239 |
return r; |
| 240 |
} else { |
| 241 |
_cleanup_free_ struct fiemap *fiemap = NULL; |
| 242 |
|
| 243 |
r = read_fiemap(fd, &fiemap); |
| 244 |
if (r < 0) |
| 245 |
return log_debug_errno(r, "Failed to read extent map for swap file '%s': %m", swap->path); |
| 246 |
|
| 247 |
offset_raw = fiemap->fm_extents[0].fe_physical; |
| 248 |
} |
| 249 |
|
| 250 |
swap->offset = offset_raw / page_size(); |
| 251 |
return 0; |
| 252 |
} |
| 253 |
|
| 254 |
static int read_swap_entries(SwapEntries *ret) { |
| 255 |
_cleanup_(swap_entries_done) SwapEntries entries = {}; |
| 256 |
_cleanup_fclose_ FILE *f = NULL; |
| 257 |
|
| 258 |
assert(ret); |
| 259 |
|
| 260 |
f = fopen("/proc/swaps", "re"); |
| 261 |
if (!f) |
| 262 |
return log_debug_errno(errno, "Failed to open %s: %m", "/proc/swaps"); |
| 263 |
|
| 264 |
/* Remove header */ |
| 265 |
(void) fscanf(f, "%*s %*s %*s %*s %*s\n"); |
| 266 |
|
| 267 |
for (unsigned i = 1;; i++) { |
| 268 |
_cleanup_(swap_entry_done) SwapEntry swap = {}; |
| 269 |
_cleanup_free_ char *type = NULL; |
| 270 |
int k; |
| 271 |
|
| 272 |
k = fscanf(f, |
| 273 |
"%ms " /* device/file path */ |
| 274 |
"%ms " /* type of swap */ |
| 275 |
"%" PRIu64 /* swap size */ |
| 276 |
"%" PRIu64 /* used */ |
| 277 |
"%i" /* priority */ |
| 278 |
"\n", |
| 279 |
&swap.path, &type, &swap.size, &swap.used, &swap.priority); |
| 280 |
if (k == EOF) |
| 281 |
break; |
| 282 |
if (k != 5) |
| 283 |
return log_debug_errno(SYNTHETIC_ERRNO(EIO), "Failed to parse /proc/swaps line %u.", i); |
| 284 |
|
| 285 |
if (streq(type, "file")) { |
| 286 |
if (endswith(swap.path, "\\040(deleted)")) { |
| 287 |
log_debug("Swap file '%s' has been deleted, ignoring.", swap.path); |
| 288 |
continue; |
| 289 |
} |
| 290 |
|
| 291 |
swap.swapfile = true; |
| 292 |
|
| 293 |
} else if (streq(type, "partition")) { |
| 294 |
const char *node; |
| 295 |
|
| 296 |
node = path_startswith(swap.path, "/dev/"); |
| 297 |
if (node && startswith(node, "zram")) { |
| 298 |
log_debug("Swap partition '%s' is a zram device, ignoring.", swap.path); |
| 299 |
continue; |
| 300 |
} |
| 301 |
|
| 302 |
swap.swapfile = false; |
| 303 |
|
| 304 |
} else { |
| 305 |
log_debug("Swap type %s is not supported for hibernation, ignoring device: %s", |
| 306 |
type, swap.path); |
| 307 |
continue; |
| 308 |
} |
| 309 |
|
| 310 |
if (!GREEDY_REALLOC(entries.swaps, entries.n_swaps + 1)) |
| 311 |
return log_oom_debug(); |
| 312 |
|
| 313 |
entries.swaps[entries.n_swaps++] = TAKE_STRUCT(swap); |
| 314 |
} |
| 315 |
|
| 316 |
*ret = TAKE_STRUCT(entries); |
| 317 |
return 0; |
| 318 |
} |
| 319 |
|
| 320 |
/* Attempt to find a suitable device for hibernation by parsing /proc/swaps, /sys/power/resume, and |
| 321 |
* /sys/power/resume_offset. |
| 322 |
* |
| 323 |
* Beware: |
| 324 |
* Never use a device or file that hasn't been somehow specified by a user who would also be entrusted |
| 325 |
* with full system memory access (for example via /sys/power/resume) or that isn't an already active |
| 326 |
* swap area! Otherwise various security attacks might become possible, for example an attacker could |
| 327 |
* silently attach such a device and circumvent full disk encryption when it would be automatically used |
| 328 |
* for hibernation. Also, having a swap area on top of encryption is not per se enough to protect from all |
| 329 |
* such attacks. |
| 330 |
* |
| 331 |
* Returns: |
| 332 |
* 1 - Values are set in /sys/power/resume and /sys/power/resume_offset. |
| 333 |
* |
| 334 |
* 0 - No values are set in /sys/power/resume and /sys/power/resume_offset. |
| 335 |
* ret will represent the highest priority swap with most remaining space discovered in /proc/swaps. |
| 336 |
* |
| 337 |
* Negative value in the case of error */ |
| 338 |
int find_suitable_hibernation_device_full(HibernationDevice *ret_device, uint64_t *ret_size, uint64_t *ret_used) { |
| 339 |
_cleanup_(swap_entries_done) SwapEntries entries = {}; |
| 340 |
SwapEntry *entry = NULL; |
| 341 |
uint64_t resume_config_offset; |
| 342 |
dev_t resume_config_devno; |
| 343 |
int r; |
| 344 |
|
| 345 |
assert(!ret_size == !ret_used); |
| 346 |
|
| 347 |
r = read_resume_config(&resume_config_devno, &resume_config_offset); |
| 348 |
if (r < 0) |
| 349 |
return r; |
| 350 |
|
| 351 |
r = read_swap_entries(&entries); |
| 352 |
if (r < 0) |
| 353 |
return r; |
| 354 |
|
| 355 |
FOREACH_ARRAY(swap, entries.swaps, entries.n_swaps) { |
| 356 |
r = swap_entry_get_resume_config(swap); |
| 357 |
if (r == -EMEDIUMTYPE) { |
| 358 |
assert(swap->swapfile); |
| 359 |
|
| 360 |
log_debug_errno(r, "Unable to acquire backing block device for swap file '%s' (maybe on a RAID btrfs?), ignoring.", |
| 361 |
swap->path); |
| 362 |
continue; |
| 363 |
} |
| 364 |
if (r < 0) |
| 365 |
return log_debug_errno(r, "Failed to get devno and offset for swap '%s': %m", swap->path); |
| 366 |
assert(swap->devno > 0); |
| 367 |
|
| 368 |
if (resume_config_devno > 0) { |
| 369 |
if (swap->devno == resume_config_devno && |
| 370 |
(!swap->swapfile || swap->offset == resume_config_offset)) { |
| 371 |
/* /sys/power/resume (resume=) is set, and the calculated swap file offset |
| 372 |
* matches with /sys/power/resume_offset. */ |
| 373 |
entry = swap; |
| 374 |
break; |
| 375 |
} |
| 376 |
|
| 377 |
/* If resume= is set, don't try to use other swap spaces. */ |
| 378 |
continue; |
| 379 |
} |
| 380 |
|
| 381 |
if (!entry || |
| 382 |
swap->priority > entry->priority || |
| 383 |
swap->size - swap->used > entry->size - entry->used) |
| 384 |
entry = swap; |
| 385 |
} |
| 386 |
|
| 387 |
if (!entry) { |
| 388 |
if (resume_config_devno > 0) |
| 389 |
return log_debug_errno(SYNTHETIC_ERRNO(ESTALE), "Cannot find swap entry corresponding to /sys/power/resume."); |
| 390 |
|
| 391 |
return log_debug_errno(SYNTHETIC_ERRNO(ENOSPC), "No swap space available for hibernation."); |
| 392 |
} |
| 393 |
|
| 394 |
if (ret_device) { |
| 395 |
char *path; |
| 396 |
|
| 397 |
if (entry->swapfile) { |
| 398 |
r = device_path_make_canonical(S_IFBLK, entry->devno, &path); |
| 399 |
if (r < 0) |
| 400 |
return log_debug_errno(r, |
| 401 |
"Failed to format canonical device path for devno '" DEVNUM_FORMAT_STR "': %m", |
| 402 |
DEVNUM_FORMAT_VAL(entry->devno)); |
| 403 |
} else |
| 404 |
path = TAKE_PTR(entry->path); |
| 405 |
|
| 406 |
*ret_device = (HibernationDevice) { |
| 407 |
.devno = entry->devno, |
| 408 |
.offset = entry->offset, |
| 409 |
.path = path, |
| 410 |
}; |
| 411 |
} |
| 412 |
|
| 413 |
if (ret_size) { |
| 414 |
*ret_size = entry->size; |
| 415 |
*ret_used = entry->used; |
| 416 |
} |
| 417 |
|
| 418 |
return resume_config_devno > 0; |
| 419 |
} |
| 420 |
|
| 421 |
static int get_proc_meminfo_active(unsigned long long *ret) { |
| 422 |
_cleanup_free_ char *active_str = NULL; |
| 423 |
unsigned long long active; |
| 424 |
int r; |
| 425 |
|
| 426 |
assert(ret); |
| 427 |
|
| 428 |
r = get_proc_field("/proc/meminfo", "Active(anon)", &active_str); |
| 429 |
if (r < 0) |
| 430 |
return log_debug_errno(r, "Failed to retrieve Active(anon) from /proc/meminfo: %m"); |
| 431 |
|
| 432 |
r = safe_atollu(active_str, &active); |
| 433 |
if (r < 0) |
| 434 |
return log_debug_errno(r, "Failed to parse Active(anon) '%s' from /proc/meminfo: %m", active_str); |
| 435 |
|
| 436 |
*ret = active; |
| 437 |
return 0; |
| 438 |
} |
| 439 |
|
| 440 |
int hibernation_is_safe(void) { |
| 441 |
unsigned long long active; |
| 442 |
uint64_t size, used; |
| 443 |
bool resume_set, bypass_space_check; |
| 444 |
int r; |
| 445 |
|
| 446 |
bypass_space_check = getenv_bool("SYSTEMD_BYPASS_HIBERNATION_MEMORY_CHECK") > 0; |
| 447 |
|
| 448 |
r = find_suitable_hibernation_device_full(NULL, &size, &used); |
| 449 |
if (IN_SET(r, -ENOSPC, -ESTALE) && bypass_space_check) |
| 450 |
/* If we don't have any available swap space at all, or the specified resume device is missing, |
| 451 |
* and $SYSTEMD_BYPASS_HIBERNATION_MEMORY_CHECK is set, skip all remaining checks since |
| 452 |
* we can't do that properly anyway. It is quite possible that the user is using a setup |
| 453 |
* similar to #30083. When we actually perform hibernation in sleep.c we'll check everything again. */ |
| 454 |
return 0; |
| 455 |
if (r < 0) |
| 456 |
return r; |
| 457 |
resume_set = r > 0; |
| 458 |
|
| 459 |
if (!resume_set && !is_efi_boot()) |
| 460 |
return log_debug_errno(SYNTHETIC_ERRNO(ENOTRECOVERABLE), |
| 461 |
"Not running on EFI and resume= is not set. Hibernation is not safe."); |
| 462 |
|
| 463 |
if (bypass_space_check) |
| 464 |
return 0; |
| 465 |
|
| 466 |
r = get_proc_meminfo_active(&active); |
| 467 |
if (r < 0) |
| 468 |
return r; |
| 469 |
|
| 470 |
r = active <= (size - used) * HIBERNATION_SWAP_THRESHOLD; |
| 471 |
log_debug("Detected %s swap for hibernation: Active(anon)=%llu kB, size=%" PRIu64 " kB, used=%" PRIu64 " kB, threshold=%.2g%%", |
| 472 |
r ? "enough" : "not enough", active, size, used, 100 * HIBERNATION_SWAP_THRESHOLD); |
| 473 |
if (!r) |
| 474 |
return -ENOSPC; |
| 475 |
|
| 476 |
return resume_set; |
| 477 |
} |
| 478 |
|
| 479 |
int write_resume_config(dev_t devno, uint64_t offset, const char *device) { |
| 480 |
char offset_str[DECIMAL_STR_MAX(uint64_t)]; |
| 481 |
const char *devno_str; |
| 482 |
int r; |
| 483 |
|
| 484 |
assert(devno > 0); |
| 485 |
assert(device); |
| 486 |
|
| 487 |
devno_str = FORMAT_DEVNUM(devno); |
| 488 |
xsprintf(offset_str, "%" PRIu64, offset); |
| 489 |
|
| 490 |
r = write_string_file("/sys/power/resume_offset", offset_str, WRITE_STRING_FILE_DISABLE_BUFFER); |
| 491 |
if (r < 0) |
| 492 |
return log_error_errno(r, "Failed to write swap file offset %s to /sys/power/resume_offset for device '%s': %m", |
| 493 |
offset_str, device); |
| 494 |
log_debug("Wrote resume_offset=%s for device '%s' to /sys/power/resume_offset.", |
| 495 |
offset_str, device); |
| 496 |
|
| 497 |
r = write_string_file("/sys/power/resume", devno_str, WRITE_STRING_FILE_DISABLE_BUFFER); |
| 498 |
if (r < 0) |
| 499 |
return log_error_errno(r, "Failed to write device '%s' (%s) to /sys/power/resume: %m", |
| 500 |
device, devno_str); |
| 501 |
log_debug("Wrote resume=%s for device '%s' to /sys/power/resume.", devno_str, device); |
| 502 |
|
| 503 |
return 0; |
| 504 |
} |
| 505 |
|
| 506 |
int clear_efi_hibernate_location_and_warn(void) { |
| 507 |
int r; |
| 508 |
|
| 509 |
if (!is_efi_boot()) |
| 510 |
return 0; |
| 511 |
|
| 512 |
r = efi_set_variable(EFI_SYSTEMD_VARIABLE_STR("HibernateLocation"), NULL, 0); |
| 513 |
if (r == -ENOENT) |
| 514 |
return 0; |
| 515 |
if (r < 0) |
| 516 |
return log_warning_errno(r, "Failed to clear HibernateLocation EFI variable: %m"); |
| 517 |
|
| 518 |
return 1; |
| 519 |
} |