From de89949a71bee17e4b432ac5928376b8347892c4 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 24 Sep 2018 19:44:06 +0200 Subject: [PATCH 1/2] btrfs: fix loopback resizing code This corrects the block device to use, to the right path, as it was before 553e15f21bd7b1ecb709edfb5686d5768fe942f2. Replaces: #10153 --- src/basic/btrfs-util.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/basic/btrfs-util.c b/src/basic/btrfs-util.c index 376844b7b17..0308048b7f8 100644 --- a/src/basic/btrfs-util.c +++ b/src/basic/btrfs-util.c @@ -877,7 +877,7 @@ int btrfs_subvol_set_subtree_quota_limit(const char *path, uint64_t subvol_id, u int btrfs_resize_loopback_fd(int fd, uint64_t new_size, bool grow_only) { struct btrfs_ioctl_vol_args args = {}; - char p[SYS_BLOCK_PATH_MAX("/loop/backing_file")]; + char p[SYS_BLOCK_PATH_MAX("/loop/backing_file")], q[DEV_NUM_PATH_MAX]; _cleanup_free_ char *backing = NULL; _cleanup_close_ int loop_fd = -1, backing_fd = -1; struct stat st; @@ -922,8 +922,8 @@ int btrfs_resize_loopback_fd(int fd, uint64_t new_size, bool grow_only) { if (grow_only && new_size < (uint64_t) st.st_size) return -EINVAL; - xsprintf_sys_block_path(p, NULL, dev); - loop_fd = open(p, O_RDWR|O_CLOEXEC|O_NOCTTY); + xsprintf_dev_num_path(q, "block", dev); + loop_fd = open(q, O_RDWR|O_CLOEXEC|O_NOCTTY); if (loop_fd < 0) return -errno; From 7e6912787106a0354f199d620959982f090dd14b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 24 Sep 2018 19:47:42 +0200 Subject: [PATCH 2/2] btrfs: log at debug log when we ignore errors This stuff is likely to fail in many setups (for example when quota is not supported by the btrfs version), hence only log at debug level. Previously we'd silently ignore things altogether which makes things pretty hard to debug. --- src/shared/machine-pool.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/shared/machine-pool.c b/src/shared/machine-pool.c index 4fedeb17e36..df56492e7b0 100644 --- a/src/shared/machine-pool.c +++ b/src/shared/machine-pool.c @@ -378,14 +378,21 @@ int grow_machine_directory(void) { new_size = old_size + max_add; r = btrfs_resize_loopback("/var/lib/machines", new_size, true); - if (r <= 0) - return r; + if (r < 0) + return log_debug_errno(r, "Failed to resize loopback: %m"); + if (r == 0) + return 0; /* Also bump the quota, of both the subvolume leaf qgroup, as * well as of any subtree quota group by the same id but a * higher level, if it exists. */ - (void) btrfs_qgroup_set_limit("/var/lib/machines", 0, new_size); - (void) btrfs_subvol_set_subtree_quota_limit("/var/lib/machines", 0, new_size); + r = btrfs_qgroup_set_limit("/var/lib/machines", 0, new_size); + if (r < 0) + log_debug_errno(r, "Failed to set btrfs limit: %m"); + + r = btrfs_subvol_set_subtree_quota_limit("/var/lib/machines", 0, new_size); + if (r < 0) + log_debug_errno(r, "Failed to set btrfs subtree limit: %m"); log_info("Grew /var/lib/machines btrfs loopback file system to %s.", format_bytes(buf, sizeof(buf), new_size)); return 1;