From: Anand Jain <anand.jain@oracle.com>
To: dsterba@suse.cz, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 2nd try v4] btrfs: drop uuid_mutex in btrfs_free_extra_devids()
Date: Mon, 16 Jul 2018 22:32:22 +0800 [thread overview]
Message-ID: <6924ea4b-0b20-a93d-dcca-1ed325e21635@oracle.com> (raw)
In-Reply-To: <20180529111929.GJ6649@twin.jikos.cz>
On 05/29/2018 07:19 PM, David Sterba wrote:
> On Tue, May 29, 2018 at 01:40:34PM +0800, Anand Jain wrote:
>>>>> v3->v4: As we traverse through the seed device, fs_device gets
>>>>> updated with
>>>>> the child seed fs_devices, so make sure we use the same fs_devices
>>>>> pointer for the mutex_unlock as used for the mutex_lock.
>>>>
>>>> Well, now that I see the change, shouldn't we always hold the
>>>> device_list_mutex of the fs_devices that's being processed? Ie. each
>>>> time it's switched, the previous is unlocked and new one locked.
>>>
>>> No David. That's because we organize seed device under its parent
>>> fs_devices ((fs_devices::seed)::seed)..so on, and they are a local
>>> cloned copy of the original seed fs_devices. So parent's
>>> fs_devices::device_list_mutex lock will suffice.
>>
>> On the 2nd thought, though theoretically you are right. But practically
>> there isn't any use case which can benefit by using the intricate
>> locking as you suggested above.
>
> I don't think it's intricate or complex, just lock the fs_devices that
> can be potentially modified in the following loop.
>
> Schematically:
>
> function called with some fs_devices
>
> again:
> lock fs_devices->device_list_mutex
> foreach device in fs_devices
> if ...
> fs_devices counters get changed after device
> deletion
> endfor
>
> if (fs_devices->seed)
> unlock fs_devices->device_list_mutex
> fs_devices = fs_devices->seed
> lock fs_devices->device_list_mutex <-- lock the new one
> goto again
> endif
>
> unlock fs_devices->device_list_mutex <-- correctly unlock
> endfunc
>
>> I am following the following method:-
>> By holding the parent fs_devices (which is also the mounted fs_devices
>> lock) it would imply to lock its dependent cloned seed fs_devices, as
>> to reach the cloned seed device, first we need to traverse from the
>> parent fs_devices.
>
> Locking the parent fs_devices might be the right scheme, but if any
> child fs_devices pointer gets passed to a random function that will
> change it, then the locking will not protect it.
If its not holding the parent fs_devices lock then it would a bug and
if its already holding the parent lock then child lock isn't necessary
at all.
Also sent the
[DOC] BTRFS Volume operations, Device Lists and Locks all in one page
to have a holistic vewi.
Its not too convincing to me the approach of using the per fs_devices
lock when fs_devices::seed is traversed its not necessary.
Thanks, Anand
> This might need a deeper audit how the seeding device is done and maybe
> add some helpers that eg. lock the whole chain so all of them are
> protected.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
prev parent reply other threads:[~2018-07-16 14:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-28 14:43 [PATCH 2nd try v4] btrfs: drop uuid_mutex in btrfs_free_extra_devids() Anand Jain
2018-05-28 15:40 ` David Sterba
2018-05-28 22:57 ` Anand Jain
2018-05-29 5:40 ` Anand Jain
2018-05-29 11:19 ` David Sterba
2018-07-16 14:32 ` Anand Jain [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=6924ea4b-0b20-a93d-dcca-1ed325e21635@oracle.com \
--to=anand.jain@oracle.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).