From patchwork Tue Jul 31 15:07:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengguang Xu X-Patchwork-Id: 10550889 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 9954914E2 for ; Tue, 31 Jul 2018 15:08:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B8A62B012 for ; Tue, 31 Jul 2018 15:08:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6D0682B015; Tue, 31 Jul 2018 15:08:16 +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 E9AFD2B012 for ; Tue, 31 Jul 2018 15:08:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732440AbeGaQs7 (ORCPT ); Tue, 31 Jul 2018 12:48:59 -0400 Received: from mout.gmx.net ([212.227.15.19]:33701 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732434AbeGaQs7 (ORCPT ); Tue, 31 Jul 2018 12:48:59 -0400 Received: from localhost.localdomain ([113.116.159.60]) by mail.gmx.com (mrgmx002 [212.227.17.184]) with ESMTPSA (Nemesis) id 0MF4eJ-1fj55H0LKF-00GHD8; Tue, 31 Jul 2018 17:08:09 +0200 From: Chengguang Xu To: ceph-devel@vger.kernel.org Cc: zyan@redhat.com, idryomov@gmail.com, Chengguang Xu Subject: [PATCH 1/4] ceph: use type refcount_t for refcount of snap realm Date: Tue, 31 Jul 2018 23:07:44 +0800 Message-Id: <20180731150747.27745-1-cgxu519@gmx.com> X-Mailer: git-send-email 2.17.1 X-Provags-ID: V03:K1:Ap9fZRSHjrpNyaso5uRFAwkjWHo4KsPTpt1J8p9a8c1DttaJ+q8 HcfnHRH9OmQANSasOKvgNqQccOGXaZEjlt6Q4Ize9qILDZn4hz4rcpY3LP0xJ/q7rIIt1Zb MsQX5CNkxjMuhL3ehH8z6jymZSJqYVpzeAEhXZSlibJwBnJEen46p9SVqF7Az4IcyLkVreb 2+0y1SEYnse4GvNLMVi/g== X-UI-Out-Filterresults: notjunk:1;V01:K0:ZIAUcM0y0DA=:wuJZsmmcjPnSQYf2j4oaor TJZ4GA1cmjncwK5syX0hRvX4bC26TERkcvh19O+PHs4t8xJRiw1kwWLttxLSVht3aiVwYz3RT uAn3pk4z0Cpv2TF+WHfFwBTpmFW2R0McmSw8OLnuUL7mwd2AaG7yE/Wcf7Pb+dNNQr7V286Qr AWIkB18nE9nyMzrVeO+BlKTldDPQsRGzV4osg/9UV7wR3GiofZQ03nMy7jeNV8sCO/Pa6EsNB DI/O3o7TZtodks2iURQuF2uKb1MgRwHnx9mi6TUTDbLpmD4rY8uqK+ijQ1wXhshvuYbyrkQUN 44SpBy0FuNozORUcBRa98w42zJ7SbaiJJVBV/kvnTDGE1T4kg5l6rt3gwEIRjnK+RY2eo/Ru6 zLjq3+LV+YRGQueqTf5kqXk6LTpvPkhAQslqvykkk6gKuTBZmJA98AAVsv5H1G64C2OUS39Hg ont3UqcaRS/tZTvB12AqsVFp8s8Jz04W//7nj3hirm3hdoLG8d9fzZoau5DBgQBQvhFaS6L1D PaHyXCATlEYcJCa/9fI9wlO4/RWW0HxmI/NydUwM88WnNI7BocI4wP57QieGjXyeUu+bbPHck BKYCfvjIcycPfBIJOhq9zgNF2UzXGI1XpeGBKP/PCE2VfNSZsHAWmdUiC31jjRbk5Vdh3dJ0n SK8K2wI3Ik/rFNdFVjwD1gkW9bgCNGRV3QyBnSnU/rUQMR0MW6usf/QBAnPAREpJ02oiKqkDr 7zAIdkvMHIsqzDT+cwph3GlrUtviyGxOMVr1/Dj49+rBPf9xTYm8GZOaw6E= 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. Meanwhile, introduce a variable to avoid calling refcount_read twice in debug message. Signed-off-by: Chengguang Xu --- fs/ceph/snap.c | 18 ++++++++++-------- fs/ceph/super.h | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c index 01b0144c0b73..b5cff23d9ea2 100644 --- a/fs/ceph/snap.c +++ b/fs/ceph/snap.c @@ -63,15 +63,15 @@ void ceph_get_snap_realm(struct ceph_mds_client *mdsc, struct ceph_snap_realm *realm) { - dout("get_realm %p %d -> %d\n", realm, - atomic_read(&realm->nref), atomic_read(&realm->nref)+1); /* * since we _only_ increment realm refs or empty the empty * list with snap_rwsem held, adjusting the empty list here is * safe. we do need to protect against concurrent empty list * additions, however. */ - if (atomic_inc_return(&realm->nref) == 1) { + if (refcount_inc_not_zero(&realm->nref)) { + unsigned int refcnt = refcount_read(&realm->nref); + dout("get_realm %p %d -> %d\n", realm, refcnt - 1, refcnt); spin_lock(&mdsc->snap_empty_lock); list_del_init(&realm->empty_item); spin_unlock(&mdsc->snap_empty_lock); @@ -115,7 +115,7 @@ static struct ceph_snap_realm *ceph_create_snap_realm( if (!realm) return ERR_PTR(-ENOMEM); - atomic_set(&realm->nref, 1); /* for caller */ + refcount_set(&realm->nref, 1); /* for caller */ realm->ino = ino; INIT_LIST_HEAD(&realm->children); INIT_LIST_HEAD(&realm->child_item); @@ -193,9 +193,10 @@ static void __destroy_snap_realm(struct ceph_mds_client *mdsc, static void __put_snap_realm(struct ceph_mds_client *mdsc, struct ceph_snap_realm *realm) { + unsigned int refcnt = refcount_read(&realm->nref); dout("__put_snap_realm %llx %p %d -> %d\n", realm->ino, realm, - atomic_read(&realm->nref), atomic_read(&realm->nref)-1); - if (atomic_dec_and_test(&realm->nref)) + refcnt, refcnt - 1); + if (refcount_dec_and_test(&realm->nref)) __destroy_snap_realm(mdsc, realm); } @@ -205,9 +206,10 @@ static void __put_snap_realm(struct ceph_mds_client *mdsc, void ceph_put_snap_realm(struct ceph_mds_client *mdsc, struct ceph_snap_realm *realm) { + unsigned int refcnt = refcount_read(&realm->nref); dout("put_snap_realm %llx %p %d -> %d\n", realm->ino, realm, - atomic_read(&realm->nref), atomic_read(&realm->nref)-1); - if (!atomic_dec_and_test(&realm->nref)) + refcnt, refcnt - 1); + if (!refcount_dec_and_test(&realm->nref)) return; if (down_write_trylock(&mdsc->snap_rwsem)) { diff --git a/fs/ceph/super.h b/fs/ceph/super.h index fe11d6903b29..d4b0ca5d7a15 100644 --- a/fs/ceph/super.h +++ b/fs/ceph/super.h @@ -761,7 +761,7 @@ struct ceph_readdir_cache_control { struct ceph_snap_realm { u64 ino; struct inode *inode; - atomic_t nref; + refcount_t nref; struct rb_node node; u64 created, seq; 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 */ From patchwork Tue Jul 31 15:07:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengguang Xu X-Patchwork-Id: 10550897 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 E2A8A14E0 for ; Tue, 31 Jul 2018 15:08:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D2B532B04D for ; Tue, 31 Jul 2018 15:08:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C71D42B055; Tue, 31 Jul 2018 15:08:34 +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 685872B04D for ; Tue, 31 Jul 2018 15:08:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732450AbeGaQtS (ORCPT ); Tue, 31 Jul 2018 12:49:18 -0400 Received: from mout.gmx.net ([212.227.15.15]:36859 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727397AbeGaQtS (ORCPT ); Tue, 31 Jul 2018 12:49:18 -0400 Received: from localhost.localdomain ([113.116.159.60]) by mail.gmx.com (mrgmx002 [212.227.17.184]) with ESMTPSA (Nemesis) id 0MaqeA-1fVafo3lZi-00KPul; Tue, 31 Jul 2018 17:08:19 +0200 From: Chengguang Xu To: ceph-devel@vger.kernel.org Cc: zyan@redhat.com, idryomov@gmail.com, Chengguang Xu Subject: [PATCH 3/4] ceph: use type refcount_t for refcount of ceph_snapid_map Date: Tue, 31 Jul 2018 23:07:46 +0800 Message-Id: <20180731150747.27745-3-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:tfMssGu68uTijJZv/ZdN4kZmUp0jXVYoVWv5X7tnnX3ezOvUyD0 pgYLLnjbvBYe+i+Y45T1IJpFBs3L9PtsIq2hOz99qK9U2vX9Riy8s6PhljpVp+xlG32iuqu RqOxiF/VwLMVaR74ccP2lWBS0lmqIWnmxRVsob08+q9lwwily/WbX7xA+F1tnBkDJXbzuZT qRAMaDdgrT8HR1ZS6br5g== X-UI-Out-Filterresults: notjunk:1;V01:K0:71MvhqG9uuU=:XkqJw3bCYfsxMukZ7hBI0X ADAibJoB6ZLQFHLQVuVgxqLBFDQM32DlLAH/QzrXsEf5qioh6//mxQl+AES0kudnJKDGDu1JA 678j1iuQLfHI0H48gnl0pjTsmyGxba5i9OTZTrYbwuC3hj+Zyu9adF5zKvrp45NXz9AbS7T8n nCdrwiSPQA71eZm7XpZ2y9dLOkNMZ8cJPbGI5V3LA6hIoEtuJS54QKhC9DrE0tb3M2+Dv7eLd cWhNtni+fq0iioqXZy/iiYDdI3OnWJPGKUFEYio8SRSvrt5oe59SzDmoaFVNw3Sf7STmf8OUG R8PZwXIC+rDtgSUFkmDMpHSQXwnBKyGWYERV+P2TIIhPrfsWugYDgTk/h8sqMWlLYctNOEYa3 0u8MQXrTYWla2IgnyLkaqcUFWkf6HkCbTsxUpGBiqW+XtxlAKDClDwCiekom82djzVmLiIbl3 MESNbDP/rVFvn0/PdD3E9Ed4vCQAStNUfrcWkkOeFfWewr8R2JOVEbGfCVn9jx6IaS1u3nnhe je3g3t6AdtQcpwweklsKzTTA/DWWODVULQWNM5+EzkGFeyXSysNtPe1/vvTgkN63cOBL+cMxn NvratLQPCBiDRnFc8Qz1I8cdSHhNjqSF8Men1WZ+AKbX1Sa9YyfgA0CuhOD6sXnRFGdX8zajk 4pfy6aThTxJKPFJ8GYUi0qUvlGCteWDosyau0cewHt93K6f4jPTzyuY/AnIQC/z5C1KOyNIGr K0t2tJAFfQpYin2G6jrsOf8Wx1zoKJKG7Sk5NIehstInX63t2uE1xBGnQsA= 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/mds_client.h | 2 +- fs/ceph/snap.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/ceph/mds_client.h b/fs/ceph/mds_client.h index 27f83dd55edb..a89f9c10729b 100644 --- a/fs/ceph/mds_client.h +++ b/fs/ceph/mds_client.h @@ -311,7 +311,7 @@ struct ceph_pool_perm { struct ceph_snapid_map { struct rb_node node; struct list_head lru; - atomic_t ref; + refcount_t ref; u64 snap; dev_t dev; unsigned long last_used; diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c index b5cff23d9ea2..6b34ccad9d75 100644 --- a/fs/ceph/snap.c +++ b/fs/ceph/snap.c @@ -1005,7 +1005,7 @@ struct ceph_snapid_map* ceph_get_snapid_map(struct ceph_mds_client *mdsc, } else if (snap < exist->snap) { p = &(*p)->rb_right; } else { - if (atomic_inc_return(&exist->ref) == 1) + if (refcount_inc_not_zero(&exist->ref)) list_del_init(&exist->lru); break; } @@ -1028,7 +1028,7 @@ struct ceph_snapid_map* ceph_get_snapid_map(struct ceph_mds_client *mdsc, } INIT_LIST_HEAD(&sm->lru); - atomic_set(&sm->ref, 1); + refcount_set(&sm->ref, 1); sm->snap = snap; exist = NULL; @@ -1047,7 +1047,7 @@ struct ceph_snapid_map* ceph_get_snapid_map(struct ceph_mds_client *mdsc, exist = NULL; } if (exist) { - if (atomic_inc_return(&exist->ref) == 1) + if (refcount_inc_not_zero(&exist->ref)) list_del_init(&exist->lru); } else { rb_link_node(&sm->node, parent, p); @@ -1070,7 +1070,7 @@ void ceph_put_snapid_map(struct ceph_mds_client* mdsc, { if (!sm) return; - if (atomic_dec_and_lock(&sm->ref, &mdsc->snapid_map_lock)) { + if (refcount_dec_and_lock(&sm->ref, &mdsc->snapid_map_lock)) { sm->last_used = jiffies; list_add_tail(&sm->lru, &mdsc->snapid_map_lru); spin_unlock(&mdsc->snapid_map_lock); @@ -1127,7 +1127,7 @@ void ceph_cleanup_snapid_map(struct ceph_mds_client *mdsc) sm = list_first_entry(&to_free, struct ceph_snapid_map, lru); list_del(&sm->lru); free_anon_bdev(sm->dev); - if (WARN_ON_ONCE(atomic_read(&sm->ref))) { + if (WARN_ON_ONCE(refcount_read(&sm->ref))) { pr_err("snapid map %llx -> %x still in use\n", sm->snap, sm->dev); } From patchwork Tue Jul 31 15:07:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengguang Xu X-Patchwork-Id: 10550893 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 656EE14E2 for ; Tue, 31 Jul 2018 15:08:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54F9F2B04F for ; Tue, 31 Jul 2018 15:08:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4986F2B055; Tue, 31 Jul 2018 15:08:29 +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 F00E82B04D for ; Tue, 31 Jul 2018 15:08:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732442AbeGaQtM (ORCPT ); Tue, 31 Jul 2018 12:49:12 -0400 Received: from mout.gmx.net ([212.227.15.18]:52297 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727397AbeGaQtM (ORCPT ); Tue, 31 Jul 2018 12:49:12 -0400 Received: from localhost.localdomain ([113.116.159.60]) by mail.gmx.com (mrgmx002 [212.227.17.184]) with ESMTPSA (Nemesis) id 0LfSeH-1gHrw71ijh-00p3zs; Tue, 31 Jul 2018 17:08:23 +0200 From: Chengguang Xu To: ceph-devel@vger.kernel.org Cc: zyan@redhat.com, idryomov@gmail.com, Chengguang Xu Subject: [PATCH 4/4] libceph: introudce a variable to avoid calling refcount_read() twice Date: Tue, 31 Jul 2018 23:07:47 +0800 Message-Id: <20180731150747.27745-4-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:mVsvZMFPEgj3XQRWjvKkkBuEPdU6LZ74K/StH7lE/ZJt62tY+45 3hHKCBbU3UAmVc2Z4S1IWuieke3DfrhDDJ/obPD+ydBYRisKzWEkyS4pTPXmVCLjZ9cxPc+ NzjOCUZidQXB/IvY2yB08DIzVAensRvNDPgUJrw/wyLm/dlcbq0RJzBZ7ZI2jksBWG2jmh9 wrjEXn8R+1mA4LnEOAotQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:JYADTb+NNb0=:cbjZicRfKE76jQ4YK5fAk3 RzYOQC1B03RXpSMYvuQq0BiTm9aH1iNaBDpx9xfkZ5p1T80h5eURt+Hn+j9YIyonexrXfOq0u VbqTIxlWDj6ZLN4vpsnmtjH8C1AWsXOfX9uppwZnjVWPwvVIQR0pTRkv7WTwIBZy42uI5due0 FgVGKHcUlizzWNqbhshzrXx9OTaN9FGz4ofMskBtnpiOkkjRiE1y2wQGlWvPNvRrPawfrXisU Dd3GGh/bs46cSweJitUQfZBWg1eSVl97V3+F5K6zI1QCle5M6fvMENpEJN7wUWdiah3CvIziP UswogKwNuddV9/bQMFQWjgXxGtlFmgjPn2BG+aZl6Fth0Obqe9T8PdwNhrSNwqnrXqMOHby+l vyAHr8KAvPuG4XATiEuBAhlrOMI+dItc4EJH/F+nnBGt0ARp5H3kH2OGO/jY9jDkZruFMw/OK d5Jo9N5/0xR2AXplMfzPTyABRYwzHANPNy5YKKvr4prRmPWoGlJQjKZM4iBxgwUQftRlEWcut qH8s4dHUkf/f3TJinGoNGo31hrvht19PU8ly7NcsEAgOCdhoDLpECRw0ygYwMODgvlFTtBlr7 IZB4WvGB1ek90obwUeFuT3ti/9UhLmmOuv7b1LbNax/R+PEgV9EhddVCdLVN1D+Rqb3ApeuSV LXYhImdC75FUJiRPVKPzUZ6wXY0r2sBvyYgqIUUUilp9LN6MLUHdpVeYCTedPfkX1dxDf3q9y p+ZsHl029M1QkdKDng4YVBNqz6Miz1CAO6ZWSG1tvumft7Ol3Z90uZdjFcs= 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 Calling refcount_read() twice may return different value each time, so introduce a variable to avoid it. Signed-off-by: Chengguang Xu --- net/ceph/osd_client.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c index 8002b8e9ce24..ee8eb99a06ae 100644 --- a/net/ceph/osd_client.c +++ b/net/ceph/osd_client.c @@ -1155,8 +1155,8 @@ static struct ceph_osd *create_osd(struct ceph_osd_client *osdc, int onum) static struct ceph_osd *get_osd(struct ceph_osd *osd) { if (refcount_inc_not_zero(&osd->o_ref)) { - dout("get_osd %p %d -> %d\n", osd, refcount_read(&osd->o_ref)-1, - refcount_read(&osd->o_ref)); + unsigned int refcnt = refcount_read(&osd->o_ref); + dout("get_osd %p %d -> %d\n", osd, refcnt - 1, refcnt); return osd; } else { dout("get_osd %p FAIL\n", osd); @@ -1166,8 +1166,8 @@ static struct ceph_osd *get_osd(struct ceph_osd *osd) static void put_osd(struct ceph_osd *osd) { - dout("put_osd %p %d -> %d\n", osd, refcount_read(&osd->o_ref), - refcount_read(&osd->o_ref) - 1); + unsigned int refcnt = refcount_read(&osd->o_ref); + dout("put_osd %p %d -> %d\n", osd, refcnt, refcnt - 1); if (refcount_dec_and_test(&osd->o_ref)) { osd_cleanup(osd); kfree(osd);