OSDN Git Service

btrfs: merge blocking_writers branches in btrfs_tree_read_lock
authorDavid Sterba <dsterba@suse.com>
Thu, 10 Oct 2019 21:29:21 +0000 (23:29 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 18 Nov 2019 16:51:50 +0000 (17:51 +0100)
commitf5c2a52590858d18f4a736d8062fe70f11988fa9
treeafab71dc2a492eee2af86e6512baf0e3c5d99edd
parent9c907446dce311dc7e7b8958425e92ac03d3d00c
btrfs: merge blocking_writers branches in btrfs_tree_read_lock

There are two ifs that use eb::blocking_writers. As this is a variable
modified inside and outside of locks, we could minimize number of
accesses to avoid problems with getting different results at different
times.

The access here is locked so this can only race with btrfs_tree_unlock
that sets blocking_writers to 0 without lock and unsets the lock owner.

The first branch is taken only if the same thread already holds the
lock, the second if checks for blocking writers. Here we'd either unlock
and wait, or proceed. Both are valid states of the locking protocol.

Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/locking.c