lustre-devel-lustre.org archive mirror
 help / color / mirror / Atom feed
From: James Simmons <jsimmons@infradead.org>
To: Andreas Dilger <adilger@whamcloud.com>,
	Oleg Drokin <green@whamcloud.com>, NeilBrown <neilb@suse.de>
Cc: Lustre Development List <lustre-devel@lists.lustre.org>
Subject: [lustre-devel] [PATCH 12/13] lnet: o2iblnd: convert ibp_refcount to a kref
Date: Wed, 29 Dec 2021 09:51:26 -0500	[thread overview]
Message-ID: <1640789487-22279-13-git-send-email-jsimmons@infradead.org> (raw)
In-Reply-To: <1640789487-22279-1-git-send-email-jsimmons@infradead.org>

This refcount is used exactly like a kref.  So change it to one.
kref uses refcount_t which will warn on increment-from-zero and
similar problems (which enabled with CONFIG option), so we don't
need the LASSERT calls.

WC-bug-id: https://jira.whamcloud.com/browse/LU-12678
Lustre-commit: 2968a40a163aa1b0f ("LU-12678 o2iblnd: convert ibp_refcount to a kref")
Signed-off-by: James Simmons <jsimmons@infradead.org>
Reviewed-on: https://review.whamcloud.com/45685
Reviewed-by: Neil Brown <neilb@suse.de>
Reviewed-by: Chris Horn <chris.horn@hpe.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
---
 net/lnet/klnds/o2iblnd/o2iblnd.c | 11 ++++++-----
 net/lnet/klnds/o2iblnd/o2iblnd.h | 35 +++++++++++++++++------------------
 2 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/net/lnet/klnds/o2iblnd/o2iblnd.c b/net/lnet/klnds/o2iblnd/o2iblnd.c
index 9cdc12a..7d28acd 100644
--- a/net/lnet/klnds/o2iblnd/o2iblnd.c
+++ b/net/lnet/klnds/o2iblnd/o2iblnd.c
@@ -337,7 +337,7 @@ int kiblnd_create_peer(struct lnet_ni *ni, struct kib_peer_ni **peerp,
 	peer_ni->ibp_max_frags = IBLND_MAX_RDMA_FRAGS;
 	peer_ni->ibp_queue_depth = ni->ni_net->net_tunables.lct_peer_tx_credits;
 	peer_ni->ibp_queue_depth_mod = 0;	/* try to use the default */
-	atomic_set(&peer_ni->ibp_refcount, 1);  /* 1 ref for caller */
+	kref_init(&peer_ni->ibp_kref);
 
 	INIT_HLIST_NODE(&peer_ni->ibp_list);
 	INIT_LIST_HEAD(&peer_ni->ibp_conns);
@@ -357,12 +357,13 @@ int kiblnd_create_peer(struct lnet_ni *ni, struct kib_peer_ni **peerp,
 	return 0;
 }
 
-void kiblnd_destroy_peer(struct kib_peer_ni *peer_ni)
+void kiblnd_destroy_peer(struct kref *kref)
 {
+	struct kib_peer_ni *peer_ni = container_of(kref, struct kib_peer_ni,
+						   ibp_kref);
 	struct kib_net *net = peer_ni->ibp_ni->ni_data;
 
 	LASSERT(net);
-	LASSERT(!atomic_read(&peer_ni->ibp_refcount));
 	LASSERT(!kiblnd_peer_active(peer_ni));
 	LASSERT(kiblnd_peer_idle(peer_ni));
 	LASSERT(list_empty(&peer_ni->ibp_tx_queue));
@@ -403,7 +404,7 @@ struct kib_peer_ni *kiblnd_find_peer_locked(struct lnet_ni *ni, lnet_nid_t nid)
 
 		CDEBUG(D_NET, "got peer_ni [%p] -> %s (%d) version: %x\n",
 		       peer_ni, libcfs_nid2str(nid),
-		       atomic_read(&peer_ni->ibp_refcount),
+		       kref_read(&peer_ni->ibp_kref),
 		       peer_ni->ibp_version);
 		return peer_ni;
 	}
@@ -439,7 +440,7 @@ static int kiblnd_get_peer_info(struct lnet_ni *ni, int index,
 			continue;
 
 		*nidp = peer_ni->ibp_nid;
-		*count = atomic_read(&peer_ni->ibp_refcount);
+		*count = kref_read(&peer_ni->ibp_kref);
 
 		read_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
 		return 0;
diff --git a/net/lnet/klnds/o2iblnd/o2iblnd.h b/net/lnet/klnds/o2iblnd/o2iblnd.h
index 21f8981..4fb651e 100644
--- a/net/lnet/klnds/o2iblnd/o2iblnd.h
+++ b/net/lnet/klnds/o2iblnd/o2iblnd.h
@@ -499,7 +499,7 @@ struct kib_peer_ni {
 	/* when (in seconds) I was last alive */
 	time64_t		ibp_last_alive;
 	/* # users */
-	atomic_t		ibp_refcount;
+	struct kref		ibp_kref;
 	/* version of peer_ni */
 	u16			ibp_version;
 	/* current passive connection attempts */
@@ -607,23 +607,23 @@ static inline int kiblnd_timeout(void)
 	}								\
 } while (0)
 
-#define kiblnd_peer_addref(peer_ni)					\
-do {									\
-	CDEBUG(D_NET, "peer_ni[%p] -> %s (%d)++\n",			\
-	       (peer_ni), libcfs_nid2str((peer_ni)->ibp_nid),		\
-	       atomic_read(&(peer_ni)->ibp_refcount));			\
-	atomic_inc(&(peer_ni)->ibp_refcount);				\
-} while (0)
+void kiblnd_destroy_peer(struct kref *kref);
 
-#define kiblnd_peer_decref(peer_ni)					\
-do {									\
-	CDEBUG(D_NET, "peer_ni[%p] -> %s (%d)--\n",			\
-	       (peer_ni), libcfs_nid2str((peer_ni)->ibp_nid),		\
-	       atomic_read(&(peer_ni)->ibp_refcount));			\
-	LASSERT_ATOMIC_POS(&(peer_ni)->ibp_refcount);			\
-	if (atomic_dec_and_test(&(peer_ni)->ibp_refcount))		\
-		kiblnd_destroy_peer(peer_ni);				\
-} while (0)
+static inline void kiblnd_peer_addref(struct kib_peer_ni *peer_ni)
+{
+	CDEBUG(D_NET, "peer_ni[%p] -> %s (%d)++\n",
+	       peer_ni, libcfs_nid2str(peer_ni->ibp_nid),
+	       kref_read(&peer_ni->ibp_kref));
+	kref_get(&(peer_ni)->ibp_kref);
+}
+
+static inline void kiblnd_peer_decref(struct kib_peer_ni *peer_ni)
+{
+	CDEBUG(D_NET, "peer_ni[%p] -> %s (%d)--\n",
+	       peer_ni, libcfs_nid2str(peer_ni->ibp_nid),
+	       kref_read(&peer_ni->ibp_kref));
+	kref_put(&peer_ni->ibp_kref, kiblnd_destroy_peer);
+}
 
 static inline bool
 kiblnd_peer_connecting(struct kib_peer_ni *peer_ni)
@@ -929,7 +929,6 @@ int kiblnd_cm_callback(struct rdma_cm_id *cmid,
 int kiblnd_dev_failover(struct kib_dev *dev, struct net *ns);
 int kiblnd_create_peer(struct lnet_ni *ni, struct kib_peer_ni **peerp,
 		       lnet_nid_t nid);
-void kiblnd_destroy_peer(struct kib_peer_ni *peer_ni);
 bool kiblnd_reconnect_peer(struct kib_peer_ni *peer_ni);
 void kiblnd_destroy_dev(struct kib_dev *dev);
 void kiblnd_unlink_peer_locked(struct kib_peer_ni *peer_ni);
-- 
1.8.3.1

_______________________________________________
lustre-devel mailing list
lustre-devel@lists.lustre.org
http://lists.lustre.org/listinfo.cgi/lustre-devel-lustre.org

  parent reply	other threads:[~2021-12-29 14:52 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-29 14:51 [lustre-devel] [PATCH 00/13] lustre: port OpenSFS updates Dec 29, 2021 James Simmons
2021-12-29 14:51 ` [lustre-devel] [PATCH 01/13] lustre: sec: filename encryption - digest support James Simmons
2021-12-29 14:51 ` [lustre-devel] [PATCH 02/13] lnet: Revert "lnet: Lock primary NID logic" James Simmons
2021-12-29 14:51 ` [lustre-devel] [PATCH 03/13] lustre: quota: fallocate send UID/GID for quota James Simmons
2021-12-29 14:51 ` [lustre-devel] [PATCH 04/13] lustre: mdc: add client tunable to disable LSOM update James Simmons
2021-12-29 14:51 ` [lustre-devel] [PATCH 05/13] lustre: dne: dir migration in non-recursive mode James Simmons
2021-12-29 14:51 ` [lustre-devel] [PATCH 06/13] lustre: update version to 2.14.56 James Simmons
2021-12-29 14:51 ` [lustre-devel] [PATCH 07/13] lustre: sec: no encryption key migrate/extend/resync/split James Simmons
2021-12-29 14:51 ` [lustre-devel] [PATCH 08/13] lustre: sec: fix handling of encrypted file with long name James Simmons
2021-12-29 14:51 ` [lustre-devel] [PATCH 09/13] lnet: socklnd: expect two control connections maximum James Simmons
2021-12-29 14:51 ` [lustre-devel] [PATCH 10/13] lustre: ptlrpc: use a cached value James Simmons
2021-12-29 14:51 ` [lustre-devel] [PATCH 11/13] lnet: Race on discovery queue James Simmons
2021-12-29 14:51 ` James Simmons [this message]
2021-12-29 14:51 ` [lustre-devel] [PATCH 13/13] lustre: llite: set ra_pages of backing_dev_info with 0 James Simmons

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1640789487-22279-13-git-send-email-jsimmons@infradead.org \
    --to=jsimmons@infradead.org \
    --cc=adilger@whamcloud.com \
    --cc=green@whamcloud.com \
    --cc=lustre-devel@lists.lustre.org \
    --cc=neilb@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).