From patchwork Tue Jul 31 15:07:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengguang Xu X-Patchwork-Id: 10550891 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C99AA14E0 for ; Tue, 31 Jul 2018 15:08:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B87462B04D for ; Tue, 31 Jul 2018 15:08:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC76C2B055; Tue, 31 Jul 2018 15:08:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E5992B04D for ; Tue, 31 Jul 2018 15:08:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732434AbeGaQtF (ORCPT ); Tue, 31 Jul 2018 12:49:05 -0400 Received: from mout.gmx.net ([212.227.15.18]:33943 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727397AbeGaQtF (ORCPT ); Tue, 31 Jul 2018 12:49:05 -0400 Received: from localhost.localdomain ([113.116.159.60]) by mail.gmx.com (mrgmx002 [212.227.17.184]) with ESMTPSA (Nemesis) id 0Md3ZK-1fTOoO3Hnu-00IE3f; Tue, 31 Jul 2018 17:08:15 +0200 From: Chengguang Xu To: ceph-devel@vger.kernel.org Cc: zyan@redhat.com, idryomov@gmail.com, Chengguang Xu Subject: [PATCH 2/4] ceph: use type refcount_t for refcount of filelock Date: Tue, 31 Jul 2018 23:07:45 +0800 Message-Id: <20180731150747.27745-2-cgxu519@gmx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180731150747.27745-1-cgxu519@gmx.com> References: <20180731150747.27745-1-cgxu519@gmx.com> X-Provags-ID: V03:K1:5+6EL0PVfRgnpPoXWtFnQz7P/HcC+4KxS1RLoBWDmlphzf3Edrt vAPJu1QBNmhvhhB8t0MyIHvQx1I2sBn9Hv3f1mhvsZUkQJ/a4/PAoY/orlMDdGzzyTK4BJd c2eHgmSl4eCrzA9vFq8kR2HLIqAumCquQQjtQ9x+X4T9++MohVc3UCx89QjK2790oc0HcgC 7hkJYOjnch9+4/B5AFrNw== X-UI-Out-Filterresults: notjunk:1;V01:K0:qdPcWQLOCJY=:KSKMf21XsWKID01E88NSKW f6Gh2vHlZVBd2BYRJrCXlbX+uDzg5y+Fwt8+7eSs2cHvF521L2zxyJcAO5Z2vwKOUp32R11au f8TEV0BvzkXpu29qCG/PMrqQj7vFJP7zEOBW2ZTfn2o+jMQ9DtkCNMGalW7J3StC+Z3VEpJiw LgVL+ksPhxaRZQXB1A35C22rMBf0yNCZVkkdNGd9tQSzJa2y4NSs0gI/R/D+gOsVwXMV9cqY/ TLq0ZrspyN8QpDN92KgaIFT6wHySgfFOAX2TZEYcfXzLLjB3kTHZlF2wWdH5vZa5pRRsiDO3Z WYY5DrvuqFnfSlrq5EgCqjKVtY6iTQlb8UinH7fz3MsIdARtn+iQaGrjPR1ywdPXV6j5DcPxP ujenvoyaIbYXOTzn+bHuwenIVrvrSH5TBLzLSytmLm53eza7cjmyZYMGFnlkZf0LHHkhfB9Lr OK1d++0Iz7/1VpVgGljeNvxdvvoPmtk+/MoXe93m7S/9yEPrMzTnZ4hs/z0iJKe5LRCVyKNZu G9/8Ydq9ApsWLz2G/ODk8KogBqfDKG2fryQVJ+Oz3+GnpfRAeoaKgEMtRdhM+gBk0J3es9Hy0 bFoGmOExxarYfZ+myZWkgw4EmybX1hORxL2Hyku/p6HbNkcQZpsfyvrBGGSphChNUiACyuCzf RzOCSLSiP4EcuGJb/iO+Wfkiz7iv+sO7qnkC0lC/s6RShJwr9CmSpvZZlqsVG8Bttd2sU8WJz oN6ikvbBVA1L/2717NvPF9hV1Yjq6knVngCg7GGS49owt6Ln9fa6pdHDGP0= Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use refcount_t to replace atomic_t when operating refcount. Signed-off-by: Chengguang Xu --- 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 */