Whamcloud - gitweb
LU-12678 o2iblnd: convert ibp_refcount to a kref 85/45685/4
authorJames Simmons <jsimmons@infradead.org>
Tue, 30 Nov 2021 18:21:49 +0000 (13:21 -0500)
committerOleg Drokin <green@whamcloud.com>
Thu, 23 Dec 2021 07:20:06 +0000 (07:20 +0000)
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.

Test-Parameters: trivial testlist=sanity-lnet
Signed-off-by: James Simmons <jsimmons@infradead.org>
Change-Id: I23ade8c2f768c70a1fd330e8c173e0d18f5ff976
Reviewed-on: https://review.whamcloud.com/45685
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Neil Brown <neilb@suse.de>
Reviewed-by: Chris Horn <chris.horn@hpe.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lnet/klnds/o2iblnd/o2iblnd.c
lnet/klnds/o2iblnd/o2iblnd.h

index e3a8845..d5c61ab 100644 (file)
@@ -338,7 +338,7 @@ 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);
@@ -359,12 +359,13 @@ kiblnd_create_peer(struct lnet_ni *ni, struct kib_peer_ni **peerp,
 }
 
 void
-kiblnd_destroy_peer(struct kib_peer_ni *peer_ni)
+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 != NULL);
-       LASSERT (atomic_read(&peer_ni->ibp_refcount) == 0);
        LASSERT(!kiblnd_peer_active(peer_ni));
        LASSERT(kiblnd_peer_idle(peer_ni));
        LASSERT(list_empty(&peer_ni->ibp_tx_queue));
@@ -404,7 +405,7 @@ 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;
        }
@@ -442,7 +443,7 @@ 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;
index f6d2a06..62a124d 100644 (file)
@@ -663,7 +663,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 */
@@ -784,23 +784,23 @@ do {                                                                      \
        }                                                               \
 } 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)
@@ -1130,7 +1130,6 @@ int  kiblnd_translate_mtu(int value);
 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);
 bool kiblnd_reconnect_peer(struct kib_peer_ni *peer);
 void kiblnd_destroy_dev(struct kib_dev *dev);
 void kiblnd_unlink_peer_locked(struct kib_peer_ni *peer_ni);