[PATCH 05/11] nfs: use clear_and_wake_up_bit() in pnfs code

NeilBrown
2024-12-06T02:19:29Z

The wake_up_bit() interface is fragile as it sometimes needs an explicit
barrier before it is called. It is generally better to use the combined
interfaces which have all necessary barriers.

The usage of wake_up_bit() in NFS/pnfs IS safe as the required barriers
are included. But it is ugly to need that explicit barrier.

This patch changes to use clear_and_wake_up_bit() which transparently
includes the required barrier. Also use test_and_clear_wake_up_bit() in
one case.

Signed-off-by: NeilBrown <neilb@suse.de>
---
fs/nfs/pnfs.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index 5963c0440e23..445ba09ba324 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -2034,9 +2034,8 @@ static void nfs_layoutget_begin(struct pnfs_layout_hdr *lo)

static void nfs_layoutget_end(struct pnfs_layout_hdr *lo)
{
- if (atomic_dec_and_test(&lo->plh_outstanding) &&
- test_and_clear_bit(NFS_LAYOUT_DRAIN, &lo->plh_flags))
- wake_up_bit(&lo->plh_flags, NFS_LAYOUT_DRAIN);
+ if (atomic_dec_and_test(&lo->plh_outstanding))
+ test_and_clear_wake_up_bit(NFS_LAYOUT_DRAIN, &lo->plh_flags);
}

static bool pnfs_is_first_layoutget(struct pnfs_layout_hdr *lo)
@@ -2048,9 +2047,7 @@ static void pnfs_clear_first_layoutget(struct pnfs_layout_hdr *lo)
{
unsigned long *bitlock = &lo->plh_flags;

- clear_bit_unlock(NFS_LAYOUT_FIRST_LAYOUTGET, bitlock);
- smp_mb__after_atomic();
- wake_up_bit(bitlock, NFS_LAYOUT_FIRST_LAYOUTGET);
+ clear_and_wake_up_bit(NFS_LAYOUT_FIRST_LAYOUTGET, bitlock);
}

static void _add_to_server_list(struct pnfs_layout_hdr *lo,
@@ -3221,9 +3218,7 @@ static void pnfs_clear_layoutcommitting(struct inode *inode)
{
unsigned long *bitlock = &NFS_I(inode)->flags;

- clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock);
- smp_mb__after_atomic();
- wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING);
+ clear_and_wake_up_bit(NFS_INO_LAYOUTCOMMITTING, bitlock);
}

/*
--
2.47.0