linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Filipe Manana <fdmanana@gmail.com>
To: Anand Jain <anand.jain@oracle.com>
Cc: linux-btrfs <linux-btrfs@vger.kernel.org>
Subject: Re: [PATCH v2 1/3] btrfs: scrub: maintain the unlock order in scrub thread
Date: Thu, 29 Nov 2018 10:36:29 +0000	[thread overview]
Message-ID: <CAL3q7H667aumMBiyOQrcULVVNpiCP3FJ5W7FPjf_8-udSMn0Qg@mail.gmail.com> (raw)
In-Reply-To: <1543483513-16724-2-git-send-email-anand.jain@oracle.com>

On Thu, Nov 29, 2018 at 9:27 AM Anand Jain <anand.jain@oracle.com> wrote:
>
> The device_list_mutex and scrub_lock creates a nested locks in
> btrfs_scrub_dev().
>
> During lock the order is device_list_mutex and then scrub_lock, and during
> unlock, the order is device_list_mutex and then scrub_lock.
> Fix this to the lock order of scrub_lock and then device_list_mutex.
>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
> v1->v2: change the order of lock acquire first scrub_lock and then
>         device_list_mutex, which matches with the order of unlock.
>         The extra line which are now in the scrub_lock are ok to be
>         under the scrub_lock.

I don't get it.
What problem does this patch fixes?
Doesn't seem any functional fix to me, nor performance gain (by the
contrary, the scrub_lock is now held for a longer time than needed),
nor makes anything more readable or "beautiful".

>  fs/btrfs/scrub.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
> index 902819d3cf41..a9d6fc3b01d4 100644
> --- a/fs/btrfs/scrub.c
> +++ b/fs/btrfs/scrub.c
> @@ -3813,28 +3813,29 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
>                 return -EINVAL;
>         }
>
> -
> +       mutex_lock(&fs_info->scrub_lock);
>         mutex_lock(&fs_info->fs_devices->device_list_mutex);
>         dev = btrfs_find_device(fs_info, devid, NULL, NULL);
>         if (!dev || (test_bit(BTRFS_DEV_STATE_MISSING, &dev->dev_state) &&
>                      !is_dev_replace)) {
>                 mutex_unlock(&fs_info->fs_devices->device_list_mutex);
> +               mutex_unlock(&fs_info->scrub_lock);
>                 return -ENODEV;
>         }
>
>         if (!is_dev_replace && !readonly &&
>             !test_bit(BTRFS_DEV_STATE_WRITEABLE, &dev->dev_state)) {
>                 mutex_unlock(&fs_info->fs_devices->device_list_mutex);
> +               mutex_unlock(&fs_info->scrub_lock);
>                 btrfs_err_in_rcu(fs_info, "scrub: device %s is not writable",
>                                 rcu_str_deref(dev->name));
>                 return -EROFS;
>         }
>
> -       mutex_lock(&fs_info->scrub_lock);
>         if (!test_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &dev->dev_state) ||
>             test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &dev->dev_state)) {
> -               mutex_unlock(&fs_info->scrub_lock);
>                 mutex_unlock(&fs_info->fs_devices->device_list_mutex);
> +               mutex_unlock(&fs_info->scrub_lock);
>                 return -EIO;
>         }
>
> @@ -3843,23 +3844,23 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
>             (!is_dev_replace &&
>              btrfs_dev_replace_is_ongoing(&fs_info->dev_replace))) {
>                 btrfs_dev_replace_read_unlock(&fs_info->dev_replace);
> -               mutex_unlock(&fs_info->scrub_lock);
>                 mutex_unlock(&fs_info->fs_devices->device_list_mutex);
> +               mutex_unlock(&fs_info->scrub_lock);
>                 return -EINPROGRESS;
>         }
>         btrfs_dev_replace_read_unlock(&fs_info->dev_replace);
>
>         ret = scrub_workers_get(fs_info, is_dev_replace);
>         if (ret) {
> -               mutex_unlock(&fs_info->scrub_lock);
>                 mutex_unlock(&fs_info->fs_devices->device_list_mutex);
> +               mutex_unlock(&fs_info->scrub_lock);
>                 return ret;
>         }
>
>         sctx = scrub_setup_ctx(dev, is_dev_replace);
>         if (IS_ERR(sctx)) {
> -               mutex_unlock(&fs_info->scrub_lock);
>                 mutex_unlock(&fs_info->fs_devices->device_list_mutex);
> +               mutex_unlock(&fs_info->scrub_lock);
>                 scrub_workers_put(fs_info);
>                 return PTR_ERR(sctx);
>         }
> --
> 1.8.3.1



-- 
Filipe David Manana,

“Whether you think you can, or you think you can't — you're right.”

  reply	other threads:[~2018-11-29 10:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-29  9:25 [PATCH v2 0/3] btrfs: scrub: fix scrub_lock Anand Jain
2018-11-29  9:25 ` [PATCH v2 1/3] btrfs: scrub: maintain the unlock order in scrub thread Anand Jain
2018-11-29 10:36   ` Filipe Manana [this message]
2018-11-30  1:00     ` Anand Jain
2018-11-29  9:25 ` [PATCH v2 2/3] btrfs: scrub: fix circular locking dependency warning Anand Jain
2018-11-29  9:25 ` [PATCH v2 3/3] btrfs: scrub: add scrub_lock lockdep check in scrub_workers_get Anand Jain

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=CAL3q7H667aumMBiyOQrcULVVNpiCP3FJ5W7FPjf_8-udSMn0Qg@mail.gmail.com \
    --to=fdmanana@gmail.com \
    --cc=anand.jain@oracle.com \
    --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).