Whamcloud - gitweb
LU-16796 ptlrpc: Change struct ptlrpc_reply_state to use kref 64/56364/3
authorArshad Hussain <arshad.hussain@aeoncomputing.com>
Wed, 11 Sep 2024 07:17:19 +0000 (03:17 -0400)
committerOleg Drokin <green@whamcloud.com>
Thu, 13 Mar 2025 17:06:07 +0000 (17:06 +0000)
This patch changes struct ptlrpc_reply_state to use
kref instead of atomic_t

Test-Parameters: trivial
Signed-off-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Change-Id: I15d4982e709fe420b1fade4108581fbc7669058e
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56364
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Timothy Day <timday@amazon.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/lustre_net.h
lustre/ldlm/ldlm_lib.c
lustre/ptlrpc/events.c
lustre/ptlrpc/layout.c
lustre/ptlrpc/niobuf.c
lustre/ptlrpc/pack_generic.c
lustre/ptlrpc/service.c

index b93f7dd..5049c6b 100644 (file)
@@ -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;
 }
 
index 119859a..f18c740 100644 (file)
@@ -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);
index 689b52b..556d38d 100644 (file)
@@ -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;
        }
index e069d6a..6924ea4 100644 (file)
@@ -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);
index 684b052..375d44c 100644 (file)
@@ -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))
index 8753b93..1343097 100644 (file)
@@ -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);
index 7e115b0..cf89bfe 100644 (file)
@@ -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);