* [PATCH 3/5] Btrfs: pause/recover the space balance when doing remount
@ 2012-05-17 11:57 Miao Xie
2012-05-17 15:08 ` Ilya Dryomov
0 siblings, 1 reply; 2+ messages in thread
From: Miao Xie @ 2012-05-17 11:57 UTC (permalink / raw)
To: Linux Btrfs
pause the space balance threads when remounting the fs to be readonly,
and recover it when remounting it from r/o to r/w
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
---
fs/btrfs/super.c | 9 ++++++++-
fs/btrfs/volumes.c | 8 +++++++-
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 7deb00e..ea17f0a 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1148,6 +1148,9 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
if (*flags & MS_RDONLY) {
sb->s_flags |= MS_RDONLY;
+ /* pause restriper - we want to resume on remount to r/w */
+ btrfs_pause_balance(root->fs_info);
+
ret = btrfs_commit_super(root);
if (ret)
goto restore;
@@ -1174,7 +1177,10 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
if (ret)
goto restore;
- sb->s_flags &= ~MS_RDONLY;
+ if (sb->s_flags & MS_RDONLY) {
+ sb->s_flags &= ~MS_RDONLY;
+ btrfs_recover_balance(fs_info->tree_root);
+ }
}
return 0;
@@ -1190,6 +1196,7 @@ restore:
fs_info->alloc_start = old_alloc_start;
fs_info->thread_pool_size = old_thread_pool_size;
fs_info->metadata_ratio = old_metadata_ratio;
+
return ret;
}
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 91da8a2..c536d52 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2833,7 +2833,13 @@ static int balance_kthread(void *data)
mutex_lock(&fs_info->volume_mutex);
mutex_lock(&fs_info->balance_mutex);
- set_balance_control(bctl);
+ if (fs_info->balance_ctl) {
+ kfree(bctl);
+ bctl = fs_info->balance_ctl;
+ bctl->flags = bctl->flags | BTRFS_BALANCE_RESUME;
+ } else {
+ set_balance_control(bctl);
+ }
if (btrfs_test_opt(fs_info->tree_root, SKIP_BALANCE)) {
printk(KERN_INFO "btrfs: force skipping balance\n");
--
1.7.6.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 3/5] Btrfs: pause/recover the space balance when doing remount
2012-05-17 11:57 [PATCH 3/5] Btrfs: pause/recover the space balance when doing remount Miao Xie
@ 2012-05-17 15:08 ` Ilya Dryomov
0 siblings, 0 replies; 2+ messages in thread
From: Ilya Dryomov @ 2012-05-17 15:08 UTC (permalink / raw)
To: Miao Xie; +Cc: Linux Btrfs
On Thu, May 17, 2012 at 07:57:40PM +0800, Miao Xie wrote:
> pause the space balance threads when remounting the fs to be readonly,
> and recover it when remounting it from r/o to r/w
>
> Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
> ---
> fs/btrfs/super.c | 9 ++++++++-
> fs/btrfs/volumes.c | 8 +++++++-
> 2 files changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
> index 7deb00e..ea17f0a 100644
> --- a/fs/btrfs/super.c
> +++ b/fs/btrfs/super.c
> @@ -1148,6 +1148,9 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
> if (*flags & MS_RDONLY) {
> sb->s_flags |= MS_RDONLY;
>
> + /* pause restriper - we want to resume on remount to r/w */
> + btrfs_pause_balance(root->fs_info);
> +
> ret = btrfs_commit_super(root);
> if (ret)
> goto restore;
> @@ -1174,7 +1177,10 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
> if (ret)
> goto restore;
>
> - sb->s_flags &= ~MS_RDONLY;
> + if (sb->s_flags & MS_RDONLY) {
> + sb->s_flags &= ~MS_RDONLY;
> + btrfs_recover_balance(fs_info->tree_root);
> + }
> }
>
> return 0;
> @@ -1190,6 +1196,7 @@ restore:
> fs_info->alloc_start = old_alloc_start;
> fs_info->thread_pool_size = old_thread_pool_size;
> fs_info->metadata_ratio = old_metadata_ratio;
> +
> return ret;
> }
>
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 91da8a2..c536d52 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -2833,7 +2833,13 @@ static int balance_kthread(void *data)
> mutex_lock(&fs_info->volume_mutex);
> mutex_lock(&fs_info->balance_mutex);
>
> - set_balance_control(bctl);
> + if (fs_info->balance_ctl) {
> + kfree(bctl);
> + bctl = fs_info->balance_ctl;
> + bctl->flags = bctl->flags | BTRFS_BALANCE_RESUME;
> + } else {
> + set_balance_control(bctl);
> + }
>
> if (btrfs_test_opt(fs_info->tree_root, SKIP_BALANCE)) {
> printk(KERN_INFO "btrfs: force skipping balance\n");
This is a known bug. There is a deeper problem here, related to the
fact that we restore balancing state not early enough and that we don't
restore it on ro mounts at all. I have a patch in the works to fix that
problem, and it also fixes this one the right way. I'm backed up with
other things right now, but I'll post it as soon as I get a chance.
Thanks,
Ilya
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-05-17 15:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-17 11:57 [PATCH 3/5] Btrfs: pause/recover the space balance when doing remount Miao Xie
2012-05-17 15:08 ` Ilya Dryomov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox