From: Zach Smith Date: Wed, 26 Jun 2019 13:55:37 +0000 (-0700) Subject: systemd-sleep: refuse to calculate swapfile offset on Btrfs X-Git-Tag: v243-rc1~223^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F12760%2Fhead;p=thirdparty%2Fsystemd.git systemd-sleep: refuse to calculate swapfile offset on Btrfs If hibernation is requested but /sys/power/resume and /sys/power/resume_offset are not configured correctly, systemd-sleep attempts to calculate swapfile offset using fstat and fiemap. Btrfs returns virtual device number for stat and a virtual offset for fiemap which results in incorrect offset calculations. In the case where offset would be calculated and the user is using Btrfs, log a debug message and fail to write device and offset values. --- diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index 435e5592e62..b9fe96635d2 100644 --- a/src/sleep/sleep.c +++ b/src/sleep/sleep.c @@ -17,6 +17,7 @@ #include "sd-messages.h" +#include "btrfs-util.h" #include "def.h" #include "exec-util.h" #include "fd-util.h" @@ -80,7 +81,14 @@ static int write_hibernate_location_info(void) { if (r < 0) return log_debug_errno(errno, "Unable to stat %s: %m", device); - // TODO check for btrfs and fail if offset is not provided; calculation will fail + r = btrfs_is_filesystem(fd); + if (r < 0) + return log_error_errno(r, "Error checking %s for Btrfs filesystem: %m", device); + + if (r) + return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), + "Unable to calculate swapfile offset when using Btrfs: %s", device); + r = read_fiemap(fd, &fiemap); if (r < 0) return log_debug_errno(r, "Unable to read extent map for '%s': %m", device);