]> git.apps.os.sepia.ceph.com Git - ceph-client.git/commitdiff
ceph: refactor wake_up_bit() pattern of calling
authorViacheslav Dubeyko <Slava.Dubeyko@ibm.com>
Tue, 8 Jul 2025 19:20:57 +0000 (12:20 -0700)
committerIlya Dryomov <idryomov@gmail.com>
Wed, 8 Oct 2025 21:30:46 +0000 (23:30 +0200)
The wake_up_bit() is called in ceph_async_unlink_cb(),
wake_async_create_waiters(), and ceph_finish_async_create().
It makes sense to switch on clear_bit() function, because
it makes the code much cleaner and easier to understand.
More important rework is the adding of smp_mb__after_atomic()
memory barrier after the bit modification and before
wake_up_bit() call. It can prevent potential race condition
of accessing the modified bit in other threads. Luckily,
clear_and_wake_up_bit() already implements the required
functionality pattern:

static inline void clear_and_wake_up_bit(int bit, unsigned long *word)
{
clear_bit_unlock(bit, word);
/* See wake_up_bit() for which memory barrier you need to use. */
smp_mb__after_atomic();
wake_up_bit(word, bit);
}

Signed-off-by: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
Reviewed-by: Alex Markuze <amarkuze@redhat.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
fs/ceph/dir.c
fs/ceph/file.c

index 32973c62c1a230ed3d46bd0915825349f97ea678..d18c0eaef9b7e7be7eb517c701d6c4af08fd78ac 100644 (file)
@@ -1260,8 +1260,7 @@ static void ceph_async_unlink_cb(struct ceph_mds_client *mdsc,
        spin_unlock(&fsc->async_unlink_conflict_lock);
 
        spin_lock(&dentry->d_lock);
-       di->flags &= ~CEPH_DENTRY_ASYNC_UNLINK;
-       wake_up_bit(&di->flags, CEPH_DENTRY_ASYNC_UNLINK_BIT);
+       clear_and_wake_up_bit(CEPH_DENTRY_ASYNC_UNLINK_BIT, &di->flags);
        spin_unlock(&dentry->d_lock);
 
        synchronize_rcu();
index 07052f331611847b2fafafd4d70438223e556718..99b30f784ee244db05e5fa4f246d8fd0d64c7d43 100644 (file)
@@ -579,8 +579,7 @@ static void wake_async_create_waiters(struct inode *inode,
 
        spin_lock(&ci->i_ceph_lock);
        if (ci->i_ceph_flags & CEPH_I_ASYNC_CREATE) {
-               ci->i_ceph_flags &= ~CEPH_I_ASYNC_CREATE;
-               wake_up_bit(&ci->i_ceph_flags, CEPH_ASYNC_CREATE_BIT);
+               clear_and_wake_up_bit(CEPH_ASYNC_CREATE_BIT, &ci->i_ceph_flags);
 
                if (ci->i_ceph_flags & CEPH_I_ASYNC_CHECK_CAPS) {
                        ci->i_ceph_flags &= ~CEPH_I_ASYNC_CHECK_CAPS;
@@ -762,8 +761,7 @@ static int ceph_finish_async_create(struct inode *dir, struct inode *inode,
        }
 
        spin_lock(&dentry->d_lock);
-       di->flags &= ~CEPH_DENTRY_ASYNC_CREATE;
-       wake_up_bit(&di->flags, CEPH_DENTRY_ASYNC_CREATE_BIT);
+       clear_and_wake_up_bit(CEPH_DENTRY_ASYNC_CREATE_BIT, &di->flags);
        spin_unlock(&dentry->d_lock);
 
        return ret;