From 782b21a969abc1302fab2198101e692d3b6eff41 Mon Sep 17 00:00:00 2001 From: Arshad Hussain Date: Wed, 11 Sep 2024 03:17:19 -0400 Subject: [PATCH] LU-16796 ptlrpc: Change struct ptlrpc_reply_state to use kref This patch changes struct ptlrpc_reply_state to use kref instead of atomic_t Test-Parameters: trivial Signed-off-by: Arshad Hussain Change-Id: I15d4982e709fe420b1fade4108581fbc7669058e Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56364 Tested-by: jenkins Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Timothy Day Reviewed-by: Oleg Drokin --- lustre/include/lustre_net.h | 21 +++------------------ lustre/ldlm/ldlm_lib.c | 2 +- lustre/ptlrpc/events.c | 2 +- lustre/ptlrpc/layout.c | 2 +- lustre/ptlrpc/niobuf.c | 2 +- lustre/ptlrpc/pack_generic.c | 8 +++++--- lustre/ptlrpc/service.c | 2 +- 7 files changed, 13 insertions(+), 26 deletions(-) diff --git a/lustre/include/lustre_net.h b/lustre/include/lustre_net.h index b93f7dd..5049c6b 100644 --- a/lustre/include/lustre_net.h +++ b/lustre/include/lustre_net.h @@ -703,7 +703,7 @@ struct ptlrpc_reply_state { unsigned long rs_prealloc:1; /* rs from prealloc list */ /* transaction committed and rs dispatched by ptlrpc_commit_replies */ unsigned long rs_committed:1; - atomic_t rs_refcount; /* number of users */ + struct kref rs_refcount; /* number of users */ /** Number of locks awaiting client ACK */ int rs_nlocks; @@ -2324,7 +2324,7 @@ int lustre_pack_reply_flags(struct ptlrpc_request *, int count, __u32 *lens, int lustre_shrink_msg(struct lustre_msg *msg, int segment, unsigned int newlen, int move_data); int lustre_grow_msg(struct lustre_msg *msg, int segment, unsigned int newlen); -void lustre_free_reply_state(struct ptlrpc_reply_state *rs); +void lustre_free_reply_state(struct kref *kref); int __lustre_unpack_msg(struct lustre_msg *m, int len); __u32 lustre_msg_hdr_size(__u32 magic, __u32 count); __u32 lustre_msg_size(__u32 magic, int count, __u32 *lengths); @@ -2531,21 +2531,6 @@ ptlrpc_client_wake_req(struct ptlrpc_request *req) wake_up(&req->rq_set->set_waitq); } -static inline void -ptlrpc_rs_addref(struct ptlrpc_reply_state *rs) -{ - LASSERT(atomic_read(&rs->rs_refcount) > 0); - atomic_inc(&rs->rs_refcount); -} - -static inline void -ptlrpc_rs_decref(struct ptlrpc_reply_state *rs) -{ - LASSERT(atomic_read(&rs->rs_refcount) > 0); - if (atomic_dec_and_test(&rs->rs_refcount)) - lustre_free_reply_state(rs); -} - /* Should only be called once per req */ static inline void ptlrpc_req_drop_rs(struct ptlrpc_request *req) { @@ -2559,7 +2544,7 @@ static inline void ptlrpc_req_drop_rs(struct ptlrpc_request *req) req->rq_repmsg = NULL; spin_unlock(&req->rq_early_free_lock); - ptlrpc_rs_decref(req->rq_reply_state); + kref_put(&req->rq_reply_state->rs_refcount, lustre_free_reply_state); req->rq_reply_state = NULL; } diff --git a/lustre/ldlm/ldlm_lib.c b/lustre/ldlm/ldlm_lib.c index 119859a..f18c740 100644 --- a/lustre/ldlm/ldlm_lib.c +++ b/lustre/ldlm/ldlm_lib.c @@ -3349,7 +3349,7 @@ void target_send_reply(struct ptlrpc_request *req, int rc, int fail_id) */ rs->rs_sent = 1; rs->rs_unlinked = 1; - ptlrpc_rs_addref(rs); + kref_get(&rs->rs_refcount); } spin_lock(&rs->rs_lock); diff --git a/lustre/ptlrpc/events.c b/lustre/ptlrpc/events.c index 689b52b..556d38d 100644 --- a/lustre/ptlrpc/events.c +++ b/lustre/ptlrpc/events.c @@ -395,7 +395,7 @@ void reply_out_callback(struct lnet_event *ev) * net's ref on 'rs' */ LASSERT(ev->unlinked); - ptlrpc_rs_decref(rs); + kref_put(&rs->rs_refcount, lustre_free_reply_state); EXIT; return; } diff --git a/lustre/ptlrpc/layout.c b/lustre/ptlrpc/layout.c index e069d6a..6924ea4 100644 --- a/lustre/ptlrpc/layout.c +++ b/lustre/ptlrpc/layout.c @@ -2866,7 +2866,7 @@ int req_capsule_server_grow(struct req_capsule *pill, rs->rs_difficult = 0; rs->rs_no_ack = 0; } - ptlrpc_rs_decref(rs); + kref_put(&rs->rs_refcount, lustre_free_reply_state); return 0; } EXPORT_SYMBOL(req_capsule_server_grow); diff --git a/lustre/ptlrpc/niobuf.c b/lustre/ptlrpc/niobuf.c index 684b052..375d44c 100644 --- a/lustre/ptlrpc/niobuf.c +++ b/lustre/ptlrpc/niobuf.c @@ -729,7 +729,7 @@ int ptlrpc_send_reply(struct ptlrpc_request *req, int flags) CERROR("not replying on NULL connection\n"); /* bug 9635 */ return -ENOTCONN; } - ptlrpc_rs_addref(rs); /* +1 ref for the network */ + kref_get(&rs->rs_refcount); /* +1 ref for the network */ rc = sptlrpc_svc_wrap_reply(req); if (unlikely(rc)) diff --git a/lustre/ptlrpc/pack_generic.c b/lustre/ptlrpc/pack_generic.c index 8753b93..1343097 100644 --- a/lustre/ptlrpc/pack_generic.c +++ b/lustre/ptlrpc/pack_generic.c @@ -308,7 +308,7 @@ int lustre_pack_reply_v2(struct ptlrpc_request *req, int count, RETURN(rc); rs = req->rq_reply_state; - atomic_set(&rs->rs_refcount, 1); /* 1 ref for rq_reply_state */ + kref_init(&rs->rs_refcount); /* 1 ref for rq_reply_state */ rs->rs_cb_id.cbid_fn = reply_out_callback; rs->rs_cb_id.cbid_arg = rs; rs->rs_svcpt = req->rq_rqbd->rqbd_svcpt; @@ -520,11 +520,13 @@ int lustre_grow_msg(struct lustre_msg *msg, int segment, unsigned int newlen) } EXPORT_SYMBOL(lustre_grow_msg); -void lustre_free_reply_state(struct ptlrpc_reply_state *rs) +void lustre_free_reply_state(struct kref *kref) { + struct ptlrpc_reply_state *rs = container_of(kref, + struct ptlrpc_reply_state, + rs_refcount); PTLRPC_RS_DEBUG_LRU_DEL(rs); - LASSERT(atomic_read(&rs->rs_refcount) == 0); LASSERT(!rs->rs_difficult || rs->rs_handled); LASSERT(!rs->rs_difficult || rs->rs_unlinked); LASSERT(!rs->rs_scheduled); diff --git a/lustre/ptlrpc/service.c b/lustre/ptlrpc/service.c index 7e115b0..cf89bfe 100644 --- a/lustre/ptlrpc/service.c +++ b/lustre/ptlrpc/service.c @@ -2496,7 +2496,7 @@ static int ptlrpc_handle_rs(struct ptlrpc_reply_state *rs) class_export_put(exp); rs->rs_export = NULL; - ptlrpc_rs_decref(rs); + kref_put(&rs->rs_refcount, lustre_free_reply_state); if (atomic_dec_and_test(&svcpt->scp_nreps_difficult) && svc->srv_is_stopping) wake_up_all(&svcpt->scp_waitq); -- 1.8.3.1