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;