Commit e5c3791c authored by Wu, Mengjin's avatar Wu, Mengjin Committed by Tomasz Zawadzki
Browse files

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: default avatarMengjinWu <mengjin.wu@intel.com>
Change-Id: I551dea1887cb2d108ed5e0d621309f62cfaabbb9
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8038


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarXiaodong Liu <xiaodong.liu@intel.com>
parent 0d1c7bf8
Loading
Loading
Loading
Loading
+17 −17
Original line number Diff line number Diff line
@@ -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;

	for (i = 0; i < GET_IO_LOOP_COUNT; i++) {
		/*
	 * nbd server should not accept request after closing command
		 * nbd server should not accept requests after closing command
		 */
		if (nbd->is_closing) {
		return 0;
			break;
		}

	for (i = 0; i < GET_IO_LOOP_COUNT; i++) {
		rc = nbd_io_recv_internal(nbd);
		if (rc < 0) {
			return rc;