linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Thumshirn <Johannes.Thumshirn@wdc.com>
To: "dsterba@suse.cz" <dsterba@suse.cz>, Nikolay Borisov <nborisov@suse.com>
Cc: "linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>
Subject: Re: [PATCH 1/4] btrfs: Use rcu when iterating devices in btrfs_init_new_device
Date: Wed, 22 Jul 2020 14:53:51 +0000	[thread overview]
Message-ID: <SN4PR0401MB359831E99526FFD5E3546BDC9B790@SN4PR0401MB3598.namprd04.prod.outlook.com> (raw)
In-Reply-To: 20200722144750.GY3703@twin.jikos.cz

On 22/07/2020 16:48, David Sterba wrote:
> On Wed, Jul 22, 2020 at 01:36:15PM +0300, Nikolay Borisov wrote:
>>
>>
>> On 22.07.20 г. 12:17 ч., Johannes Thumshirn wrote:
>>> On 22/07/2020 10:09, Nikolay Borisov wrote:
>>>> When adding a new device there's a mandatory check to see if a device is
>>>> being duplicated to the filesystem it's added to. Since this is a
>>>> read-only operations not necessary to take device_list_mutex and can simply
>>>> make do with an rcu-readlock. No semantics changes.
>>>
>>> Hmm what are the actual locking rules for the device list? For instance looking
>>> at add_missing_dev() in volumes.c addition to the list is unprotected (both from
>>> read_one_chunk() and read_one_dev()). Others (i.e. btrfs_init_new_device()) do
>>> a list_add_rcu(). clone_fs_devices() takes the device_list_mutex and so on.
>>
>> Bummer, the locking rules are supposed to be those documented atop
>> volume.c, namely:
>>
>>  * fs_devices::device_list_mutex (per-fs, with RCU)
>>
>>     18  * ------------------------------------------------
>>
>>     17  * protects updates to fs_devices::devices, ie. adding and
>> deleting
>>     16  *
>>
>>     15  * simple list traversal with read-only actions can be done with
>> RCU protection
>>     14  *
>>
>>     13  * may be used to exclude some operations from running
>> concurrently without any
>>     12  * modifications to the list (see write_all_supers)
>>
>>
>>
>> However, your observations seem correct and rather annoying. Let me go
>> and try and figure this out...
> 
> For device list it's important to know from which context is the list
> used.
> 
> On unmoutned filesystems, the devices can be added by scanning ioctl.
> 
> On mounted filesystem, before the mount is finished, the devices cannot
> be concurrently used (single-threaded context) and uuid_mutex is
> temporarily protecting the devices agains scan ioctl.
> 
> On finished mount device list must be protected by device_list_mutex
> from the same filesystem changes (ioctls, superblock write). Device
> scanning is a no-op here, but still needs to use the uuid_mutex.
> 
> Enter RCU. For performance reasons we don't want to take
> device_list_mutex for read-only operations like show_devname or lookups
> of device id, where it's not critical that the returned information is
> stale.

OK I got confused by a) the mix of unlocked, device_list_mutex and 
uuid_mutex use and b) sometimes we use plain list_* operations and
sometimes rcu list ones.

 
> The mentioned helpers are used by various functions and the context is
> not obvious or documented, but it should be clear once the caller chain
> is known.
> 
> I can turn that into comments but please let me know if this is
> sufficient as explanation or if you need more.
> 

This would be great yes.

  reply	other threads:[~2020-07-22 14:53 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-22  8:09 [PATCH 0/4] Misc cleanups around device addition Nikolay Borisov
2020-07-22  8:09 ` [PATCH 1/4] btrfs: Use rcu when iterating devices in btrfs_init_new_device Nikolay Borisov
2020-07-22  9:17   ` Johannes Thumshirn
2020-07-22 10:36     ` Nikolay Borisov
2020-07-22 14:47       ` David Sterba
2020-07-22 14:53         ` Johannes Thumshirn [this message]
2020-07-23  7:45         ` Nikolay Borisov
2020-07-22  8:09 ` [PATCH 2/4] btrfs: Refactor locked condition " Nikolay Borisov
2020-07-30  4:31   ` Anand Jain
2020-07-22  8:09 ` [PATCH 3/4] btrfs: Remove redundant code from btrfs_free_stale_devices Nikolay Borisov
2020-07-30  5:01   ` Anand Jain
2020-07-22  8:09 ` [PATCH 4/4] btrfs: Don't opencode sync_blockdev Nikolay Borisov
2020-07-22  9:20   ` Johannes Thumshirn
2020-07-30  5:05   ` Anand Jain
2020-08-26 16:07 ` [PATCH 0/4] Misc cleanups around device addition Nikolay Borisov
2020-08-28 15:48 ` David Sterba

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=SN4PR0401MB359831E99526FFD5E3546BDC9B790@SN4PR0401MB3598.namprd04.prod.outlook.com \
    --to=johannes.thumshirn@wdc.com \
    --cc=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=nborisov@suse.com \
    /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).