summaryrefslogtreecommitdiffstats
path: root/fs/btrfs/super.c
diff options
context:
space:
mode:
authorJeff Mahoney2015-06-15 15:41:18 +0200
committerChris Mason2015-07-29 17:15:27 +0200
commite44163e177960ee60e32a73bffdd53c3a5827406 (patch)
treeffc55e93df052f4077f70ca996f2147dbb940237 /fs/btrfs/super.c
parentbtrfs: iterate over unused chunk space in FITRIM (diff)
downloadkernel-qcow2-linux-e44163e177960ee60e32a73bffdd53c3a5827406.tar.gz
kernel-qcow2-linux-e44163e177960ee60e32a73bffdd53c3a5827406.tar.xz
kernel-qcow2-linux-e44163e177960ee60e32a73bffdd53c3a5827406.zip
btrfs: explictly delete unused block groups in close_ctree and ro-remount
The cleaner thread may already be sleeping by the time we enter close_ctree. If that's the case, we'll skip removing any unused block groups queued for removal, even during a normal umount. They'll be cleaned up automatically at next mount, but users expect a umount to be a clean synchronization point, especially when used on thin-provisioned storage with -odiscard. We also explicitly remove unused block groups in the ro-remount path for the same reason. Signed-off-by: Jeff Mahoney <jeffm@suse.com> Reviewed-by: Filipe Manana <fdmanana@suse.com> Tested-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs/btrfs/super.c')
-rw-r--r--fs/btrfs/super.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index cd7ef34d2dce..a1077e0ffaa8 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1650,6 +1650,17 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
sb->s_flags |= MS_RDONLY;
+ /*
+ * Setting MS_RDONLY will put the cleaner thread to
+ * sleep at the next loop if it's already active.
+ * If it's already asleep, we'll leave unused block
+ * groups on disk until we're mounted read-write again
+ * unless we clean them up here.
+ */
+ mutex_lock(&root->fs_info->cleaner_mutex);
+ btrfs_delete_unused_bgs(fs_info);
+ mutex_unlock(&root->fs_info->cleaner_mutex);
+
btrfs_dev_replace_suspend_for_unmount(fs_info);
btrfs_scrub_cancel(fs_info);
btrfs_pause_balance(fs_info);