From 9f3d2cbd0a37862408825c3dda773465a9377a01 Mon Sep 17 00:00:00 2001 From: liuzerun Date: Thu, 28 Mar 2024 09:52:25 +0000 Subject: [PATCH] response Signed-off-by: liuzerun --- fs/hmdfs/comm/connection.c | 10 +++++++--- fs/hmdfs/comm/connection.h | 5 +++-- fs/hmdfs/comm/protocol.h | 1 + fs/hmdfs/comm/socket_adapter.c | 16 +++++++++------- fs/hmdfs/comm/transport.c | 2 +- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/fs/hmdfs/comm/connection.c b/fs/hmdfs/comm/connection.c index aec9cabf6931..046688747d83 100644 --- a/fs/hmdfs/comm/connection.c +++ b/fs/hmdfs/comm/connection.c @@ -1241,21 +1241,24 @@ void head_put(struct hmdfs_msg_idr_head *head) kref_put_lock(&head->ref, head_release, &head->peer->idr_lock); } -struct hmdfs_msg_idr_head *hmdfs_find_msg_head(struct hmdfs_peer *peer, int id) +struct hmdfs_msg_idr_head *hmdfs_find_msg_head(struct hmdfs_peer *peer, + int id, struct hmdfs_cmd operations) { struct hmdfs_msg_idr_head *head = NULL; spin_lock(&peer->idr_lock); head = idr_find(&peer->msg_idr, id); - if (head) + if (head && head->send_cmd_operations.command == operations.command) kref_get(&head->ref); + else + head = NULL; spin_unlock(&peer->idr_lock); return head; } int hmdfs_alloc_msg_idr(struct hmdfs_peer *peer, enum MSG_IDR_TYPE type, - void *ptr) + void *ptr, struct hmdfs_cmd operations) { int ret = -EAGAIN; struct hmdfs_msg_idr_head *head = ptr; @@ -1270,6 +1273,7 @@ int hmdfs_alloc_msg_idr(struct hmdfs_peer *peer, enum MSG_IDR_TYPE type, head->msg_id = ret; head->type = type; head->peer = peer; + head->send_cmd_operations = operations; peer->msg_idr_process++; ret = 0; } diff --git a/fs/hmdfs/comm/connection.h b/fs/hmdfs/comm/connection.h index 8178590d4e3d..1988e99f7808 100644 --- a/fs/hmdfs/comm/connection.h +++ b/fs/hmdfs/comm/connection.h @@ -331,8 +331,9 @@ void hmdfs_disconnect_node(struct hmdfs_peer *node); void connection_to_working(struct hmdfs_peer *node); int hmdfs_alloc_msg_idr(struct hmdfs_peer *peer, enum MSG_IDR_TYPE type, - void *ptr); -struct hmdfs_msg_idr_head *hmdfs_find_msg_head(struct hmdfs_peer *peer, int id); + void *ptr, struct hmdfs_cmd operations); +struct hmdfs_msg_idr_head *hmdfs_find_msg_head(struct hmdfs_peer *peer, int id, + struct hmdfs_cmd operations); static inline void hmdfs_start_process_offline(struct hmdfs_peer *peer) { diff --git a/fs/hmdfs/comm/protocol.h b/fs/hmdfs/comm/protocol.h index e140963989de..beaa5adf4ba1 100644 --- a/fs/hmdfs/comm/protocol.h +++ b/fs/hmdfs/comm/protocol.h @@ -60,6 +60,7 @@ enum MSG_IDR_TYPE { struct hmdfs_msg_idr_head { __u32 type; __u32 msg_id; + struct hmdfs_cmd send_cmd_operations; struct kref ref; struct hmdfs_peer *peer; }; diff --git a/fs/hmdfs/comm/socket_adapter.c b/fs/hmdfs/comm/socket_adapter.c index e6b340b4ee72..794409933a19 100644 --- a/fs/hmdfs/comm/socket_adapter.c +++ b/fs/hmdfs/comm/socket_adapter.c @@ -96,12 +96,13 @@ static void recv_info_init(struct file_recv_info *recv_info) atomic_set(&recv_info->state, FILE_RECV_PROCESS); } -static int msg_init(struct hmdfs_peer *con, struct sendmsg_wait_queue *msg_wq) +static int msg_init(struct hmdfs_peer *con, struct sendmsg_wait_queue *msg_wq, + struct hmdfs_cmd operations) { int ret = 0; struct file_recv_info *recv_info = &msg_wq->recv_info; - ret = hmdfs_alloc_msg_idr(con, MSG_IDR_MESSAGE_SYNC, msg_wq); + ret = hmdfs_alloc_msg_idr(con, MSG_IDR_MESSAGE_SYNC, msg_wq, operations); if (unlikely(ret)) return ret; @@ -279,7 +280,8 @@ static struct hmdfs_msg_parasite *mp_alloc(struct hmdfs_peer *peer, if (unlikely(!mp)) return ERR_PTR(-ENOMEM); - ret = hmdfs_alloc_msg_idr(peer, MSG_IDR_MESSAGE_ASYNC, mp); + ret = hmdfs_alloc_msg_idr(peer, MSG_IDR_MESSAGE_ASYNC, mp, + mp->head.send_cmd_operations); if (unlikely(ret)) { kfree(mp); return ERR_PTR(ret); @@ -437,7 +439,7 @@ int hmdfs_sendmessage_request(struct hmdfs_peer *con, ret = -ENOMEM; goto free_filp; } - ret = msg_init(con, msg_wq); + ret = msg_init(con, msg_wq, sm->operations); if (ret) { kfree(msg_wq); msg_wq = NULL; @@ -674,7 +676,7 @@ int hmdfs_sendpage_request(struct hmdfs_peer *con, goto unlock; } async_work->start = start; - ret = hmdfs_alloc_msg_idr(con, MSG_IDR_PAGE, async_work); + ret = hmdfs_alloc_msg_idr(con, MSG_IDR_PAGE, async_work, sm->operations); if (ret) { hmdfs_err("alloc msg_id failed, err %d", ret); goto unlock; @@ -911,7 +913,7 @@ static void hmdfs_file_response_work_fn(struct work_struct *ptr) hmdfs_override_creds(desp->peer->sbi->cred); msg_info = (struct sendmsg_wait_queue *)hmdfs_find_msg_head(desp->peer, - le32_to_cpu(desp->head->msg_id)); + le32_to_cpu(desp->head->msg_id), desp->head->operations); if (!msg_info || atomic_read(&msg_info->valid) != MSG_Q_SEND) { hmdfs_client_resp_statis(desp->peer->sbi, cmd, HMDFS_RESP_DELAY, 0, 0); @@ -963,7 +965,7 @@ int hmdfs_response_handle_sync(struct hmdfs_peer *con, bool woke = false; u8 cmd = head->operations.command; - msg_head = hmdfs_find_msg_head(con, msg_id); + msg_head = hmdfs_find_msg_head(con, msg_id, head->operations); if (!msg_head) goto out; diff --git a/fs/hmdfs/comm/transport.c b/fs/hmdfs/comm/transport.c index 1b52f46b69b8..bb6bc0e3e7ad 100644 --- a/fs/hmdfs/comm/transport.c +++ b/fs/hmdfs/comm/transport.c @@ -235,7 +235,7 @@ static int tcp_recvpage_tls(struct connection *connect, node->device_id, rd_err); async_work = (struct hmdfs_async_work *)hmdfs_find_msg_head(node, - le32_to_cpu(recv->msg_id)); + le32_to_cpu(recv->msg_id), recv->operations); if (!async_work || !cancel_delayed_work(&async_work->d_work)) goto out; -- Gitee