Message ID | 20180731150747.27745-2-cgxu519@gmx.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [1/4] ceph: use type refcount_t for refcount of snap realm | expand |
i_filelock_ref is counter, not reference counter On Tue, Jul 31, 2018 at 11:10 PM Chengguang Xu <cgxu519@gmx.com> wrote: > > Use refcount_t to replace atomic_t when operating refcount. > > Signed-off-by: Chengguang Xu <cgxu519@gmx.com> > --- > fs/ceph/inode.c | 2 +- > fs/ceph/locks.c | 10 +++++----- > fs/ceph/mds_client.c | 4 ++-- > fs/ceph/super.h | 2 +- > 4 files changed, 9 insertions(+), 9 deletions(-) > > diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c > index 7a7b76ad876a..9c008c078dbf 100644 > --- a/fs/ceph/inode.c > +++ b/fs/ceph/inode.c > @@ -496,7 +496,7 @@ struct inode *ceph_alloc_inode(struct super_block *sb) > ci->i_wb_ref = 0; > ci->i_wrbuffer_ref = 0; > ci->i_wrbuffer_ref_head = 0; > - atomic_set(&ci->i_filelock_ref, 0); > + refcount_set(&ci->i_filelock_ref, 0); > atomic_set(&ci->i_shared_gen, 0); > ci->i_rdcache_gen = 0; > ci->i_rdcache_revoking = 0; > diff --git a/fs/ceph/locks.c b/fs/ceph/locks.c > index 9dae2ec7e1fa..ce01100ff948 100644 > --- a/fs/ceph/locks.c > +++ b/fs/ceph/locks.c > @@ -33,14 +33,14 @@ void __init ceph_flock_init(void) > static void ceph_fl_copy_lock(struct file_lock *dst, struct file_lock *src) > { > struct inode *inode = file_inode(src->fl_file); > - atomic_inc(&ceph_inode(inode)->i_filelock_ref); > + refcount_inc(&ceph_inode(inode)->i_filelock_ref); > } > > static void ceph_fl_release_lock(struct file_lock *fl) > { > struct inode *inode = file_inode(fl->fl_file); > struct ceph_inode_info *ci = ceph_inode(inode); > - if (atomic_dec_and_test(&ci->i_filelock_ref)) { > + if (refcount_dec_and_test(&ci->i_filelock_ref)) { > /* clear error when all locks are released */ > spin_lock(&ci->i_ceph_lock); > ci->i_ceph_flags &= ~CEPH_I_ERROR_FILELOCK; > @@ -73,7 +73,7 @@ static int ceph_lock_message(u8 lock_type, u16 operation, struct inode *inode, > * window. Caller function will decrease the counter. > */ > fl->fl_ops = &ceph_fl_lock_ops; > - atomic_inc(&ceph_inode(inode)->i_filelock_ref); > + refcount_inc(&ceph_inode(inode)->i_filelock_ref); > } > > if (operation != CEPH_MDS_OP_SETFILELOCK || cmd == CEPH_LOCK_UNLOCK) > @@ -245,7 +245,7 @@ int ceph_lock(struct file *file, int cmd, struct file_lock *fl) > * window. Caller function will decrease the counter. > */ > fl->fl_ops = &ceph_fl_lock_ops; > - atomic_inc(&ci->i_filelock_ref); > + refcount_inc(&ci->i_filelock_ref); > } > spin_unlock(&ci->i_ceph_lock); > if (err < 0) { > @@ -302,7 +302,7 @@ int ceph_flock(struct file *file, int cmd, struct file_lock *fl) > } else { > /* see comment in ceph_lock */ > fl->fl_ops = &ceph_fl_lock_ops; > - atomic_inc(&ci->i_filelock_ref); > + refcount_inc(&ci->i_filelock_ref); > } > spin_unlock(&ci->i_ceph_lock); > if (err < 0) { > diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c > index c65192102381..98e90b5715f0 100644 > --- a/fs/ceph/mds_client.c > +++ b/fs/ceph/mds_client.c > @@ -1277,7 +1277,7 @@ static int remove_session_caps_cb(struct inode *inode, struct ceph_cap *cap, > } > spin_unlock(&mdsc->cap_dirty_lock); > > - if (atomic_read(&ci->i_filelock_ref) > 0) { > + if (refcount_read(&ci->i_filelock_ref) > 0) { > /* make further file lock syscall return -EIO */ > ci->i_ceph_flags |= CEPH_I_ERROR_FILELOCK; > pr_warn_ratelimited(" dropping file locks for %p %lld\n", > @@ -1561,7 +1561,7 @@ static int trim_caps_cb(struct inode *inode, struct ceph_cap *cap, void *arg) > /* Note: it's possible that i_filelock_ref becomes non-zero > * after dropping auth caps. It doesn't hurt because reply > * of lock mds request will re-add auth caps. */ > - if (atomic_read(&ci->i_filelock_ref) > 0) > + if (refcount_read(&ci->i_filelock_ref) > 0) > goto out; > } > /* The inode has cached pages, but it's no longer used. > diff --git a/fs/ceph/super.h b/fs/ceph/super.h > index d4b0ca5d7a15..40c41f3a7025 100644 > --- a/fs/ceph/super.h > +++ b/fs/ceph/super.h > @@ -358,7 +358,7 @@ struct ceph_inode_info { > int i_pin_ref; > int i_rd_ref, i_rdcache_ref, i_wr_ref, i_wb_ref; > int i_wrbuffer_ref, i_wrbuffer_ref_head; > - atomic_t i_filelock_ref; > + refcount_t i_filelock_ref; > atomic_t i_shared_gen; /* increment each time we get FILE_SHARED */ > u32 i_rdcache_gen; /* incremented each time we get FILE_CACHE. */ > u32 i_rdcache_revoking; /* RDCACHE gen to async invalidate, if any */ > -- > 2.17.1 > > -- > To unsubscribe from this list: send the line "unsubscribe ceph-devel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html -- To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c index 7a7b76ad876a..9c008c078dbf 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c @@ -496,7 +496,7 @@ struct inode *ceph_alloc_inode(struct super_block *sb) ci->i_wb_ref = 0; ci->i_wrbuffer_ref = 0; ci->i_wrbuffer_ref_head = 0; - atomic_set(&ci->i_filelock_ref, 0); + refcount_set(&ci->i_filelock_ref, 0); atomic_set(&ci->i_shared_gen, 0); ci->i_rdcache_gen = 0; ci->i_rdcache_revoking = 0; diff --git a/fs/ceph/locks.c b/fs/ceph/locks.c index 9dae2ec7e1fa..ce01100ff948 100644 --- a/fs/ceph/locks.c +++ b/fs/ceph/locks.c @@ -33,14 +33,14 @@ void __init ceph_flock_init(void) static void ceph_fl_copy_lock(struct file_lock *dst, struct file_lock *src) { struct inode *inode = file_inode(src->fl_file); - atomic_inc(&ceph_inode(inode)->i_filelock_ref); + refcount_inc(&ceph_inode(inode)->i_filelock_ref); } static void ceph_fl_release_lock(struct file_lock *fl) { struct inode *inode = file_inode(fl->fl_file); struct ceph_inode_info *ci = ceph_inode(inode); - if (atomic_dec_and_test(&ci->i_filelock_ref)) { + if (refcount_dec_and_test(&ci->i_filelock_ref)) { /* clear error when all locks are released */ spin_lock(&ci->i_ceph_lock); ci->i_ceph_flags &= ~CEPH_I_ERROR_FILELOCK; @@ -73,7 +73,7 @@ static int ceph_lock_message(u8 lock_type, u16 operation, struct inode *inode, * window. Caller function will decrease the counter. */ fl->fl_ops = &ceph_fl_lock_ops; - atomic_inc(&ceph_inode(inode)->i_filelock_ref); + refcount_inc(&ceph_inode(inode)->i_filelock_ref); } if (operation != CEPH_MDS_OP_SETFILELOCK || cmd == CEPH_LOCK_UNLOCK) @@ -245,7 +245,7 @@ int ceph_lock(struct file *file, int cmd, struct file_lock *fl) * window. Caller function will decrease the counter. */ fl->fl_ops = &ceph_fl_lock_ops; - atomic_inc(&ci->i_filelock_ref); + refcount_inc(&ci->i_filelock_ref); } spin_unlock(&ci->i_ceph_lock); if (err < 0) { @@ -302,7 +302,7 @@ int ceph_flock(struct file *file, int cmd, struct file_lock *fl) } else { /* see comment in ceph_lock */ fl->fl_ops = &ceph_fl_lock_ops; - atomic_inc(&ci->i_filelock_ref); + refcount_inc(&ci->i_filelock_ref); } spin_unlock(&ci->i_ceph_lock); if (err < 0) { diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c index c65192102381..98e90b5715f0 100644 --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c @@ -1277,7 +1277,7 @@ static int remove_session_caps_cb(struct inode *inode, struct ceph_cap *cap, } spin_unlock(&mdsc->cap_dirty_lock); - if (atomic_read(&ci->i_filelock_ref) > 0) { + if (refcount_read(&ci->i_filelock_ref) > 0) { /* make further file lock syscall return -EIO */ ci->i_ceph_flags |= CEPH_I_ERROR_FILELOCK; pr_warn_ratelimited(" dropping file locks for %p %lld\n", @@ -1561,7 +1561,7 @@ static int trim_caps_cb(struct inode *inode, struct ceph_cap *cap, void *arg) /* Note: it's possible that i_filelock_ref becomes non-zero * after dropping auth caps. It doesn't hurt because reply * of lock mds request will re-add auth caps. */ - if (atomic_read(&ci->i_filelock_ref) > 0) + if (refcount_read(&ci->i_filelock_ref) > 0) goto out; } /* The inode has cached pages, but it's no longer used. diff --git a/fs/ceph/super.h b/fs/ceph/super.h index d4b0ca5d7a15..40c41f3a7025 100644 --- a/fs/ceph/super.h +++ b/fs/ceph/super.h @@ -358,7 +358,7 @@ struct ceph_inode_info { int i_pin_ref; int i_rd_ref, i_rdcache_ref, i_wr_ref, i_wb_ref; int i_wrbuffer_ref, i_wrbuffer_ref_head; - atomic_t i_filelock_ref; + refcount_t i_filelock_ref; atomic_t i_shared_gen; /* increment each time we get FILE_SHARED */ u32 i_rdcache_gen; /* incremented each time we get FILE_CACHE. */ u32 i_rdcache_revoking; /* RDCACHE gen to async invalidate, if any */
Use refcount_t to replace atomic_t when operating refcount. Signed-off-by: Chengguang Xu <cgxu519@gmx.com> --- fs/ceph/inode.c | 2 +- fs/ceph/locks.c | 10 +++++----- fs/ceph/mds_client.c | 4 ++-- fs/ceph/super.h | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-)