summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZach Smith <z@zxmth.us>2019-06-26 06:55:37 -0700
committerZach Smith <z@zxmth.us>2019-06-26 22:04:59 -0700
commit64602c843beb228be919e5f0639427b60d589ec6 (patch)
tree73437a58c7a801c963d604455d298707f16b42d5
parent2002d8cdaee105a7ab6bc89d480a9ded2198247a (diff)
downloadsystemd-64602c843beb228be919e5f0639427b60d589ec6.tar.gz
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.
-rw-r--r--src/sleep/sleep.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c
index 435e5592e6..b9fe96635d 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);