From: Miao Xie <miaox@cn.fujitsu.com>
To: linux-btrfs@vger.kernel.org
Cc: David Sterba <dsterba@suse.cz>
Subject: Re: [PATCH 1/4] Btrfs: remove unnecessary ->s_umount in cleaner_kthread()
Date: Tue, 14 May 2013 19:31:22 +0800 [thread overview]
Message-ID: <5192208A.4070802@cn.fujitsu.com> (raw)
In-Reply-To: <1368526843-18000-1-git-send-email-miaox@cn.fujitsu.com>
On tue, 14 May 2013 18:20:40 +0800, Miao Xie wrote:
> In order to avoid the R/O remount, we acquired ->s_umount lock during
> we deleted the dead snapshots and subvolumes. But it is unnecessary,
> because we have cleaner_mutex.
>
> We use cleaner_mutex to protect the process of the dead snapshots/subvolumes
> deletion. And when we remount the fs to be R/O, we also acquire this mutex to
> do cleanup after we change the status of the fs. That is this lock can serialize
> the above operations, the cleaner can be aware of the status of the fs, and if
> the cleaner is deleting the dead snapshots/subvolumes, the remount task will
> wait for it. So it is safe to remove ->s_umount in cleaner_kthread().
According to my test, this patch can also fix the deadlock problem which is caused
by the race between autodefragger and freeze(xfstest 068).
Thanks
Miao
>
> Cc: David Sterba <dsterba@suse.cz>
> Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
> ---
> fs/btrfs/disk-io.c | 40 ++++++++++++++++++++++++++++------------
> 1 file changed, 28 insertions(+), 12 deletions(-)
>
> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> index a9df562..cb2bfd1 100644
> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
> @@ -1676,24 +1676,40 @@ static void end_workqueue_fn(struct btrfs_work *work)
> bio_endio(bio, error);
> }
>
> +/*
> + * If we remount the fs to be R/O, the cleaner needn't do anything except
> + * sleeping. This function is used to check the status of the fs.
> + */
> +static inline int need_cleaner_sleep(struct btrfs_root *root)
> +{
> + return root->fs_info->sb->s_flags & MS_RDONLY;
> +}
> +
> static int cleaner_kthread(void *arg)
> {
> struct btrfs_root *root = arg;
> + int again;
>
> do {
> - int again = 0;
> -
> - if (!(root->fs_info->sb->s_flags & MS_RDONLY) &&
> - down_read_trylock(&root->fs_info->sb->s_umount)) {
> - if (mutex_trylock(&root->fs_info->cleaner_mutex)) {
> - btrfs_run_delayed_iputs(root);
> - again = btrfs_clean_one_deleted_snapshot(root);
> - mutex_unlock(&root->fs_info->cleaner_mutex);
> - }
> - btrfs_run_defrag_inodes(root->fs_info);
> - up_read(&root->fs_info->sb->s_umount);
> - }
> + again = 0;
>
> + /* Make the cleaner go to sleep early. */
> + if (need_cleaner_sleep(root))
> + goto sleep;
> +
> + if (!mutex_trylock(&root->fs_info->cleaner_mutex))
> + goto sleep;
> +
> + btrfs_run_delayed_iputs(root);
> + again = btrfs_clean_one_deleted_snapshot(root);
> + mutex_unlock(&root->fs_info->cleaner_mutex);
> +
> + /*
> + * The defragger has dealt with the R/O remount, needn't
> + * do anything special here.
> + */
> + btrfs_run_defrag_inodes(root->fs_info);
> +sleep:
> if (!try_to_freeze() && !again) {
> set_current_state(TASK_INTERRUPTIBLE);
> if (!kthread_should_stop())
>
prev parent reply other threads:[~2013-05-14 11:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-14 10:20 [PATCH 1/4] Btrfs: remove unnecessary ->s_umount in cleaner_kthread() Miao Xie
2013-05-14 10:20 ` [PATCH 2/4] Btrfs: make the cleaner complete early when the fs is going to be umounted Miao Xie
2013-05-14 10:20 ` [PATCH 3/4] Btrfs: move the R/O check out of btrfs_clean_one_deleted_snapshot() Miao Xie
2013-05-14 10:20 ` [PATCH 4/4] Btrfs: make the snap/subv deletion end more early when the fs is R/O Miao Xie
2013-05-14 11:31 ` Miao Xie [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5192208A.4070802@cn.fujitsu.com \
--to=miaox@cn.fujitsu.com \
--cc=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).