Re: [PATCH 1/4] btrfs: Use rcu when iterating devices in btrfs_init_new_device

Nikolay Borisov
2020-07-22T10:36:19Z

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...

>
> Thanks,
> Johannes
>