ceph: refactor wake_up_bit() pattern of calling
Subsystems (2)
Viacheslav Dubeyko
maintainerPATCH 1/1 ceph: refactor wake_up_bit() pattern of calling
From: Viacheslav Dubeyko <[email protected]>
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.
--- fs/ceph/dir.c | 4 +++- fs/ceph/file.c | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-)
fs/ceph/dir.c +3 -1
@@ -1261,7 +1261,9 @@ 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 ; +clear_bit (CEPH_DENTRY_ASYNC_UNLINK_BIT , &di->flags); +/* ensure modified bit is visible */ +smp_mb__after_atomic ();wake_up_bit (&di->flags,CEPH_DENTRY_ASYNC_UNLINK_BIT );spin_unlock (&dentry->d_lock);
fs/ceph/file.c +6 -2
@@ -580,7 +580,9 @@ 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 ; +clear_bit (CEPH_ASYNC_CREATE_BIT , &ci->i_ceph_flags); +/* ensure modified bit is visible */ +smp_mb__after_atomic ();wake_up_bit (&ci->i_ceph_flags,CEPH_ASYNC_CREATE_BIT );if (ci->i_ceph_flags &CEPH_I_ASYNC_CHECK_CAPS ) {
@@ -765,7 +767,9 @@ static int ceph_finish_async_create(struct inode *dir, struct inode *inode, }spin_lock (&dentry->d_lock); - di->flags &= ~CEPH_DENTRY_ASYNC_CREATE ; +clear_bit (CEPH_DENTRY_ASYNC_CREATE_BIT , &di->flags); +/* ensure modified bit is visible */ +smp_mb__after_atomic ();wake_up_bit (&di->flags,CEPH_DENTRY_ASYNC_CREATE_BIT );spin_unlock (&dentry->d_lock);
Signature · 1 line
2.49.0
fs/ceph/dir.c static void ceph_async_unlink_cb(struct ceph_mds_client *mdsc, · line 1267
Quoted 6 lines · Viacheslav Dubeyko
fs/ceph/dir.c +3
-1spin_lock (&dentry->d_lock); - di->flags &= ~CEPH_DENTRY_ASYNC_UNLINK ; +clear_bit (CEPH_DENTRY_ASYNC_UNLINK_BIT , &di->flags); +/* ensure modified bit is visible */ +smp_mb__after_atomic ();wake_up_bit (&di->flags,CEPH_DENTRY_ASYNC_UNLINK_BIT );
Seems like you're open-coding clear_and_wake_up_bit()?
Quoted 9 lines · Matthew Wilcox
fs/ceph/dir.c static void ceph_async_unlink_cb(struct ceph_mds_client *mdsc, · line 1267
Quoted 6 lines · Viacheslav Dubeyko
fs/ceph/dir.c +3
-1spin_lock (&dentry->d_lock); - di->flags &= ~CEPH_DENTRY_ASYNC_UNLINK ; +clear_bit (CEPH_DENTRY_ASYNC_UNLINK_BIT , &di->flags); +/* ensure modified bit is visible */ +smp_mb__after_atomic ();wake_up_bit (&di->flags,CEPH_DENTRY_ASYNC_UNLINK_BIT );Seems like you're open-coding
clear_and_wake_up_bit()?
Damn, we already have this primitive. :) Makes sense to rework the patch.
Thanks,
Slava.