]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemd-sleep: refuse to calculate swapfile offset on Btrfs 12760/head
authorZach Smith <z@zxmth.us>
Wed, 26 Jun 2019 13:55:37 +0000 (06:55 -0700)
committerZach Smith <z@zxmth.us>
Thu, 27 Jun 2019 05:04:59 +0000 (22:04 -0700)
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.

src/sleep/sleep.c

index 435e5592e624de6838d5d5fb5e5bcbdf6fd790d5..b9fe96635d22bc430b411310afb4f76377f774e9 100644 (file)
@@ -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);