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.
#include "sd-messages.h"
+#include "btrfs-util.h"
#include "def.h"
#include "exec-util.h"
#include "fd-util.h"
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);