From e5c3791c4e71b5157ea059cb024df5d9b482025d Mon Sep 17 00:00:00 2001 From: "Wu, Mengjin" Date: Wed, 7 Jul 2021 20:29:08 +0800 Subject: [PATCH] lib/nbd: Process NBD_CMD_DISC according to the NBD protocol After this patch, nbd will no longer receive any requests if NBD_CMD_DISC is received. But it will handle the requests already received. Previously we called spdk_bdev_abort() for NBD_CMD_DISC and it will reply to the rest requests in the channel of this bdev. But there should be no reply to NBD_CMD_DISC. Hence we silently discards requests after NBD_CMD_DISC. Signed-off-by: MengjinWu Change-Id: I551dea1887cb2d108ed5e0d621309f62cfaabbb9 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8038 Tested-by: SPDK CI Jenkins Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Reviewed-by: Ben Walker Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto Reviewed-by: Changpeng Liu Reviewed-by: Xiaodong Liu --- lib/nbd/nbd.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/nbd/nbd.c b/lib/nbd/nbd.c index 0448ed816..80d202850 100644 --- a/lib/nbd/nbd.c +++ b/lib/nbd/nbd.c @@ -544,16 +544,6 @@ nbd_submit_bdev_io(struct spdk_nbd_disk *nbd, struct nbd_io *io) from_be32(&io->req.len), nbd_io_done, io); break; #endif - case NBD_CMD_DISC: - nbd->is_closing = true; - rc = spdk_bdev_abort(desc, ch, io, nbd_io_done, io); - - /* when there begins to have executed_io to send, enable socket writable notice */ - if (nbd->interrupt_mode && TAILQ_EMPTY(&nbd->executed_io_list)) { - spdk_interrupt_set_event_types(nbd->intr, SPDK_INTERRUPT_EVENT_IN | SPDK_INTERRUPT_EVENT_OUT); - } - - break; default: rc = -1; } @@ -633,6 +623,17 @@ nbd_io_recv_internal(struct spdk_nbd_disk *nbd) return -EINVAL; } + if (from_be32(&io->req.type) == NBD_CMD_DISC) { + nbd->is_closing = true; + nbd->io_in_recv = NULL; + if (nbd->interrupt_mode && TAILQ_EMPTY(&nbd->executed_io_list)) { + spdk_interrupt_set_event_types(nbd->intr, SPDK_INTERRUPT_EVENT_IN | SPDK_INTERRUPT_EVENT_OUT); + } + nbd_put_io(nbd, io); + /* After receiving NBD_CMD_DISC, nbd will not receive any new commands */ + return received; + } + /* io except read/write should ignore payload */ if (from_be32(&io->req.type) == NBD_CMD_WRITE || from_be32(&io->req.type) == NBD_CMD_READ) { @@ -703,14 +704,13 @@ nbd_io_recv(struct spdk_nbd_disk *nbd) { int i, rc, ret = 0; - /* - * nbd server should not accept request after closing command - */ - if (nbd->is_closing) { - return 0; - } - for (i = 0; i < GET_IO_LOOP_COUNT; i++) { + /* + * nbd server should not accept requests after closing command + */ + if (nbd->is_closing) { + break; + } rc = nbd_io_recv_internal(nbd); if (rc < 0) { return rc;