1 From 0236d3437909ff888e5c79228e2d5a851651c4c6 Mon Sep 17 00:00:00 2001
2 From: Sagi Grimberg <sagi@grimberg.me>
3 Date: Mon, 18 May 2020 10:47:48 -0700
4 Subject: nvmet-tcp: move send/recv error handling in the send/recv methods instead of call-sites
6 From: Sagi Grimberg <sagi@grimberg.me>
8 commit 0236d3437909ff888e5c79228e2d5a851651c4c6 upstream.
10 Have routines handle errors and just bail out of the poll loop.
11 This simplifies the code and will help as we may enhance the poll
12 loop logic and these are somewhat in the way.
14 Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
15 Signed-off-by: Christoph Hellwig <hch@lst.de>
16 Signed-off-by: Dragos-Marian Panait <dragos.panait@windriver.com>
17 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
19 drivers/nvme/target/tcp.c | 43 ++++++++++++++++++++++++-------------------
20 1 file changed, 24 insertions(+), 19 deletions(-)
22 --- a/drivers/nvme/target/tcp.c
23 +++ b/drivers/nvme/target/tcp.c
24 @@ -321,6 +321,14 @@ static void nvmet_tcp_fatal_error(struct
25 kernel_sock_shutdown(queue->sock, SHUT_RDWR);
28 +static void nvmet_tcp_socket_error(struct nvmet_tcp_queue *queue, int status)
30 + if (status == -EPIPE || status == -ECONNRESET)
31 + kernel_sock_shutdown(queue->sock, SHUT_RDWR);
33 + nvmet_tcp_fatal_error(queue);
36 static int nvmet_tcp_map_data(struct nvmet_tcp_cmd *cmd)
38 struct nvme_sgl_desc *sgl = &cmd->req.cmd->common.dptr.sgl;
39 @@ -714,11 +722,15 @@ static int nvmet_tcp_try_send(struct nvm
41 for (i = 0; i < budget; i++) {
42 ret = nvmet_tcp_try_send_one(queue, i == budget - 1);
44 + if (unlikely(ret < 0)) {
45 + nvmet_tcp_socket_error(queue, ret);
47 + } else if (ret == 0) {
57 @@ -1167,11 +1179,15 @@ static int nvmet_tcp_try_recv(struct nvm
59 for (i = 0; i < budget; i++) {
60 ret = nvmet_tcp_try_recv_one(queue);
62 + if (unlikely(ret < 0)) {
63 + nvmet_tcp_socket_error(queue, ret);
65 + } else if (ret == 0) {
75 @@ -1196,27 +1212,16 @@ static void nvmet_tcp_io_work(struct wor
78 ret = nvmet_tcp_try_recv(queue, NVMET_TCP_RECV_BUDGET, &ops);
82 - } else if (ret < 0) {
83 - if (ret == -EPIPE || ret == -ECONNRESET)
84 - kernel_sock_shutdown(queue->sock, SHUT_RDWR);
86 - nvmet_tcp_fatal_error(queue);
91 ret = nvmet_tcp_try_send(queue, NVMET_TCP_SEND_BUDGET, &ops);
93 - /* transmitted message/data */
96 - } else if (ret < 0) {
97 - if (ret == -EPIPE || ret == -ECONNRESET)
98 - kernel_sock_shutdown(queue->sock, SHUT_RDWR);
100 - nvmet_tcp_fatal_error(queue);
105 } while (pending && ops < NVMET_TCP_IO_WORK_BUDGET);