From patchwork Tue Feb 19 00:09:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 10819061 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 48C7A6C2 for ; Tue, 19 Feb 2019 00:13:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 338C72BDE4 for ; Tue, 19 Feb 2019 00:13:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 267F42BDEC; Tue, 19 Feb 2019 00:13:04 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from pdx1-mailman02.dreamhost.com (pdx1-mailman02.dreamhost.com [64.90.62.194]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C581F2BDE4 for ; Tue, 19 Feb 2019 00:13:03 +0000 (UTC) Received: from pdx1-mailman02.dreamhost.com (localhost [IPv6:::1]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id 6361A4E19AF; Mon, 18 Feb 2019 16:13:03 -0800 (PST) X-Original-To: lustre-devel@lists.lustre.org Delivered-To: lustre-devel-lustre.org@pdx1-mailman02.dreamhost.com Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id 083DC4E1F88 for ; Mon, 18 Feb 2019 16:13:01 -0800 (PST) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 47A1FAF57; Tue, 19 Feb 2019 00:13:00 +0000 (UTC) From: NeilBrown To: James Simmons , Andreas Dilger , Oleg Drokin Date: Tue, 19 Feb 2019 11:09:05 +1100 Message-ID: <155053494563.24125.5471194386420442456.stgit@noble.brown> In-Reply-To: <155053473693.24125.6976971762921761309.stgit@noble.brown> References: <155053473693.24125.6976971762921761309.stgit@noble.brown> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [lustre-devel] [PATCH 15/37] lustre: llog_obd: Convert loc_refcount to refcount_t X-BeenThere: lustre-devel@lists.lustre.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "For discussing Lustre software development." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lustre Development List Errors-To: lustre-devel-bounces@lists.lustre.org Sender: "lustre-devel" X-Virus-Scanned: ClamAV using ClamSMTP Make this a refcount_t for clarity, and also use refcount_dec_and_lock() rather than having separate lock and dec calls. Signed-off-by: NeilBrown Reviewed-by: Andreas Dilger --- drivers/staging/lustre/lustre/include/lustre_log.h | 11 ++++++----- drivers/staging/lustre/lustre/obdclass/llog_obd.c | 12 +++++------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/drivers/staging/lustre/lustre/include/lustre_log.h b/drivers/staging/lustre/lustre/include/lustre_log.h index 83fc9374d7f0..ab0262c20278 100644 --- a/drivers/staging/lustre/lustre/include/lustre_log.h +++ b/drivers/staging/lustre/lustre/include/lustre_log.h @@ -243,7 +243,7 @@ struct llog_ctxt { struct llog_operations *loc_logops; struct llog_handle *loc_handle; struct mutex loc_mutex; /* protect loc_imp */ - atomic_t loc_refcount; + refcount_t loc_refcount; long loc_flags; /* flags, see above defines */ /* * llog chunk size, and llog record size can not be bigger than @@ -267,9 +267,9 @@ static inline int llog_handle2ops(struct llog_handle *loghandle, static inline struct llog_ctxt *llog_ctxt_get(struct llog_ctxt *ctxt) { - atomic_inc(&ctxt->loc_refcount); + refcount_inc(&ctxt->loc_refcount); CDEBUG(D_INFO, "GETting ctxt %p : new refcount %d\n", ctxt, - atomic_read(&ctxt->loc_refcount)); + refcount_read(&ctxt->loc_refcount)); return ctxt; } @@ -277,9 +277,10 @@ static inline void llog_ctxt_put(struct llog_ctxt *ctxt) { if (!ctxt) return; - LASSERT_ATOMIC_GT_LT(&ctxt->loc_refcount, 0, LI_POISON); + LASSERT(refcount_read(&ctxt->loc_refcount) > 0); + LASSERT(refcount_read(&ctxt->loc_refcount) < LI_POISON); CDEBUG(D_INFO, "PUTting ctxt %p : new refcount %d\n", ctxt, - atomic_read(&ctxt->loc_refcount) - 1); + refcount_read(&ctxt->loc_refcount) - 1); __llog_ctxt_put(NULL, ctxt); } diff --git a/drivers/staging/lustre/lustre/obdclass/llog_obd.c b/drivers/staging/lustre/lustre/obdclass/llog_obd.c index e074b6ee50e6..2b6489e2632d 100644 --- a/drivers/staging/lustre/lustre/obdclass/llog_obd.c +++ b/drivers/staging/lustre/lustre/obdclass/llog_obd.c @@ -47,7 +47,7 @@ static struct llog_ctxt *llog_new_ctxt(struct obd_device *obd) return NULL; ctxt->loc_obd = obd; - atomic_set(&ctxt->loc_refcount, 1); + refcount_set(&ctxt->loc_refcount, 1); return ctxt; } @@ -71,11 +71,9 @@ int __llog_ctxt_put(const struct lu_env *env, struct llog_ctxt *ctxt) struct obd_device *obd; int rc = 0; - spin_lock(&olg->olg_lock); - if (!atomic_dec_and_test(&ctxt->loc_refcount)) { - spin_unlock(&olg->olg_lock); + if (!refcount_dec_and_lock(&ctxt->loc_refcount, &olg->olg_lock)) return rc; - } + olg->olg_ctxts[ctxt->loc_idx] = NULL; spin_unlock(&olg->olg_lock); @@ -116,8 +114,8 @@ int llog_cleanup(const struct lu_env *env, struct llog_ctxt *ctxt) /* * Banlance the ctxt get when calling llog_cleanup() */ - LASSERT(atomic_read(&ctxt->loc_refcount) < LI_POISON); - LASSERT(atomic_read(&ctxt->loc_refcount) > 1); + LASSERT(refcount_read(&ctxt->loc_refcount) < LI_POISON); + LASSERT(refcount_read(&ctxt->loc_refcount) > 1); llog_ctxt_put(ctxt); /*