Whamcloud - gitweb
LU-16796 lnet: Change struct srpc_client_rpc to use kref 42/56142/2
authorArshad Hussain <arshad.hussain@aeoncomputing.com>
Fri, 23 Aug 2024 18:13:18 +0000 (14:13 -0400)
committerOleg Drokin <green@whamcloud.com>
Mon, 16 Dec 2024 08:10:40 +0000 (08:10 +0000)
This patch changes struct lov_stripe_md to use
kref instead of atomic_t

Test-Parameters: trivial testlist=sanity-lnet
Signed-off-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Change-Id: I7dafb469aa6ad95e810f895654588a9a2114c7c6
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56142
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Chris Horn <chris.horn@hpe.com>
Reviewed-by: Timothy Day <timday@amazon.com>
Reviewed-by: Neil Brown <neilb@suse.de>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lnet/selftest/framework.c
lnet/selftest/selftest.h

index aa45e47..9bec7f5 100644 (file)
@@ -302,7 +302,6 @@ sfw_client_rpc_fini(struct srpc_client_rpc *rpc)
 {
        LASSERT(rpc->crpc_bulk.bk_niov == 0);
        LASSERT(list_empty(&rpc->crpc_list));
-       LASSERT(atomic_read(&rpc->crpc_refcount) == 0);
 
        CDEBUG(D_NET, "Outgoing framework RPC done: "
               "service %d, peer %s, status %s:%d:%d\n",
@@ -1572,7 +1571,6 @@ sfw_unpack_message(struct srpc_msg *msg)
 void
 sfw_abort_rpc(struct srpc_client_rpc *rpc)
 {
-       LASSERT(atomic_read(&rpc->crpc_refcount) > 0);
        LASSERT(rpc->crpc_service <= SRPC_FRAMEWORK_SERVICE_MAX_ID);
 
        spin_lock(&rpc->crpc_lock);
index 05788cc..1467e92 100644 (file)
@@ -263,7 +263,7 @@ struct srpc_client_rpc {
        struct list_head        crpc_list;      /* chain on user's lists */
        spinlock_t              crpc_lock;      /* serialize */
        int                     crpc_service;
-       atomic_t                crpc_refcount;
+       struct kref             crpc_refcount;
        /* # seconds to wait for reply */
        int                     crpc_timeout;
        struct stt_timer        crpc_timer;
@@ -299,19 +299,16 @@ offsetof(struct srpc_client_rpc, crpc_bulk.bk_iovs[(rpc)->crpc_bulk.bk_niov])
 do {                                                                    \
        CDEBUG(D_NET, "RPC[%p] -> %s (%d)++\n",                         \
               (rpc), libcfs_id2str((rpc)->crpc_dest),                  \
-              atomic_read(&(rpc)->crpc_refcount));                     \
-       LASSERT(atomic_read(&(rpc)->crpc_refcount) > 0);                \
-       atomic_inc(&(rpc)->crpc_refcount);                              \
+              kref_read(&(rpc)->crpc_refcount));                       \
+       kref_get(&(rpc)->crpc_refcount);                                \
 } while (0)
 
 #define srpc_client_rpc_decref(rpc)                                     \
 do {                                                                    \
        CDEBUG(D_NET, "RPC[%p] -> %s (%d)--\n",                         \
               (rpc), libcfs_id2str((rpc)->crpc_dest),                  \
-              atomic_read(&(rpc)->crpc_refcount));                     \
-       LASSERT(atomic_read(&(rpc)->crpc_refcount) > 0);                \
-       if (atomic_dec_and_test(&(rpc)->crpc_refcount))                 \
-               srpc_destroy_client_rpc(rpc);                           \
+              kref_read(&(rpc)->crpc_refcount));                       \
+       kref_put(&(rpc)->crpc_refcount, srpc_destroy_client_rpc);       \
 } while (0)
 
 #define srpc_event_pending(rpc)   ((rpc)->crpc_bulkev.ev_fired == 0 ||  \
@@ -578,11 +575,13 @@ void sfw_shutdown(void);
 void srpc_shutdown(void);
 
 static inline void
-srpc_destroy_client_rpc(struct srpc_client_rpc *rpc)
+srpc_destroy_client_rpc(struct kref *kref)
 {
+       struct srpc_client_rpc *rpc = container_of(kref, struct srpc_client_rpc,
+                                                  crpc_refcount);
+
        LASSERT(rpc != NULL);
        LASSERT(!srpc_event_pending(rpc));
-       LASSERT(atomic_read(&rpc->crpc_refcount) == 0);
 
        if (rpc->crpc_fini == NULL)
                LIBCFS_FREE(rpc, srpc_client_rpc_size(rpc));
@@ -605,7 +604,7 @@ srpc_init_client_rpc(struct srpc_client_rpc *rpc, struct lnet_process_id peer,
        swi_init_workitem(&rpc->crpc_wi, srpc_send_rpc,
                          lst_test_wq[lnet_cpt_of_nid(peer.nid, NULL)]);
        spin_lock_init(&rpc->crpc_lock);
-       atomic_set(&rpc->crpc_refcount, 1); /* 1 ref for caller */
+       kref_init(&rpc->crpc_refcount); /* 1 ref for caller */
 
        rpc->crpc_dest         = peer;
        rpc->crpc_priv         = priv;