Skip to content

Commit f6e98c5

Browse files
dubeykoSasha Levin
authored andcommitted
ceph: refactor wake_up_bit() pattern of calling
[ Upstream commit 53db6f2 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 20a216e commit f6e98c5

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

fs/ceph/dir.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,8 +1260,7 @@ static void ceph_async_unlink_cb(struct ceph_mds_client *mdsc,
12601260
spin_unlock(&fsc->async_unlink_conflict_lock);
12611261

12621262
spin_lock(&dentry->d_lock);
1263-
di->flags &= ~CEPH_DENTRY_ASYNC_UNLINK;
1264-
wake_up_bit(&di->flags, CEPH_DENTRY_ASYNC_UNLINK_BIT);
1263+
clear_and_wake_up_bit(CEPH_DENTRY_ASYNC_UNLINK_BIT, &di->flags);
12651264
spin_unlock(&dentry->d_lock);
12661265

12671266
synchronize_rcu();

fs/ceph/file.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,7 @@ static void wake_async_create_waiters(struct inode *inode,
579579

580580
spin_lock(&ci->i_ceph_lock);
581581
if (ci->i_ceph_flags & CEPH_I_ASYNC_CREATE) {
582-
ci->i_ceph_flags &= ~CEPH_I_ASYNC_CREATE;
583-
wake_up_bit(&ci->i_ceph_flags, CEPH_ASYNC_CREATE_BIT);
582+
clear_and_wake_up_bit(CEPH_ASYNC_CREATE_BIT, &ci->i_ceph_flags);
584583

585584
if (ci->i_ceph_flags & CEPH_I_ASYNC_CHECK_CAPS) {
586585
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,
762761
}
763762

764763
spin_lock(&dentry->d_lock);
765-
di->flags &= ~CEPH_DENTRY_ASYNC_CREATE;
766-
wake_up_bit(&di->flags, CEPH_DENTRY_ASYNC_CREATE_BIT);
764+
clear_and_wake_up_bit(CEPH_DENTRY_ASYNC_CREATE_BIT, &di->flags);
767765
spin_unlock(&dentry->d_lock);
768766

769767
return ret;

0 commit comments

Comments
 (0)