linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com>
To: dsterba@suse.cz, linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: Re: [PATCH 1/5] btrfs: check rw_devices, not num_devices for restriping
Date: Thu, 16 Jan 2020 11:25:00 -0500	[thread overview]
Message-ID: <fe1af903-631c-5a4a-d67c-eece281a6def@toxicpanda.com> (raw)
In-Reply-To: <20200116155955.GY3929@twin.jikos.cz>

On 1/16/20 10:59 AM, David Sterba wrote:
> On Tue, Jan 14, 2020 at 01:07:22PM -0800, Josef Bacik wrote:
>>>> -	num_devices = btrfs_num_devices(fs_info);
>>>> +	/*
>>>> +	 * rw_devices can be messed with by rm_device and device replace, so
>>>> +	 * take the chunk_mutex to make sure we have a relatively consistent
>>>> +	 * view of the fs at this point.
>>>
>>> Well, what does 'relatively consistent' mean here? There are enough
>>> locks and exclusion that device remove or replace should not change the
>>> value until btrfs_balance ends, no?
>>>
>>
>> Again I don't have the code in front of me, but there's nothing at this point to
>> stop us from running in at the tail end of device replace or device rm.
> 
> This should be prevented by the EXCL_OP mechanism, so even the end of
> device remove or replace will not be running at this time because it
> cannot even start.
> 
>> The
>> mutex keeps us from getting weirdly inflated values when we increment and
>> decrement at the end of device replace, but there's nothing (that I can
>> remember) that will stop rw devices from changing right after we check it, thus
>> relatively.
> 
> rw_devices is changed in a handful of places on a mounted filesystem,
> not counting device open/close. Device remove and replace are excluded
> from running at that time, rw_devices can't change at this point of
> balance.
> 
> btrfs_dev_replace_finishing
>   - when removing srcdev, rw_devices--
>   - when adding the target device as new, rw_devices++
> 
> btrfs_rm_device
>   - rw_devices--
> 
> btrfs_init_new_device (called by device add)
>   - rw_devices++
> 
> So the chunk mutex is either redundant or there's something I'm missing.
> 

Nope you're right, I missed the EXCL_OP thing, so we can just read rw_devices 
normally.  Thanks,

Josef

  reply	other threads:[~2020-01-16 16:25 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-10 16:11 [PATCH 0/5][v3] clean up how we mark block groups read only Josef Bacik
2020-01-10 16:11 ` [PATCH 1/5] btrfs: check rw_devices, not num_devices for restriping Josef Bacik
2020-01-11  9:24   ` Qu Wenruo
2020-01-14 20:56   ` David Sterba
2020-01-14 21:07     ` Josef Bacik
2020-01-16 15:59       ` David Sterba
2020-01-16 16:25         ` Josef Bacik [this message]
2020-01-10 16:11 ` [PATCH 2/5] btrfs: don't pass system_chunk into can_overcommit Josef Bacik
2020-01-14 19:56   ` David Sterba
2020-01-10 16:11 ` [PATCH 3/5] btrfs: kill min_allocable_bytes in inc_block_group_ro Josef Bacik
2020-01-10 16:11 ` [PATCH 4/5] btrfs: fix force usage " Josef Bacik
2020-01-11  6:15   ` Qu Wenruo
2020-01-10 16:11 ` [PATCH 5/5] btrfs: use btrfs_can_overcommit " Josef Bacik

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=fe1af903-631c-5a4a-d67c-eece281a6def@toxicpanda.com \
    --to=josef@toxicpanda.com \
    --cc=dsterba@suse.cz \
    --cc=kernel-team@fb.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).