From 5a4c9a319c1a376ee100e2ccd40ac8e5c10bfe09 Mon Sep 17 00:00:00 2001 From: Arshad Hussain Date: Fri, 23 Aug 2024 14:13:18 -0400 Subject: [PATCH] LU-16796 lnet: Change struct srpc_client_rpc to use kref 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 Change-Id: I7dafb469aa6ad95e810f895654588a9a2114c7c6 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56142 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Chris Horn Reviewed-by: Timothy Day Reviewed-by: Neil Brown Reviewed-by: Oleg Drokin --- lnet/selftest/framework.c | 2 -- lnet/selftest/selftest.h | 21 ++++++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/lnet/selftest/framework.c b/lnet/selftest/framework.c index aa45e47..9bec7f5 100644 --- a/lnet/selftest/framework.c +++ b/lnet/selftest/framework.c @@ -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); diff --git a/lnet/selftest/selftest.h b/lnet/selftest/selftest.h index 05788cc..1467e926 100644 --- a/lnet/selftest/selftest.h +++ b/lnet/selftest/selftest.h @@ -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; -- 1.8.3.1