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); }