From c1579c9bbed202ec3b4f511c9ecc189eb9db464b Mon Sep 17 00:00:00 2001 From: Darek Stojaczyk Date: Sun, 16 Dec 2018 23:53:59 +0100 Subject: [PATCH] vhost/scsi: allow scsi target hotremove even without F_HOTPLUG feature Failing the hotremove request will become more tricky once we allow creating multiple sessions per device, so we try to get rid of any unnecessary error checks. VIRTIO_SCSI_F_HOTPLUG tells us just if the host is capable of receiving hotplug events, but the scsi target can be hotremoved even without them. The hotremoval will be still reported through SCSI sense codes. All I/O to a hotremoved target will be failed with sense key ILLEGAL REQUEST, asc 0x25, ascq 0x00 (LOGICAL UNIT NOT SUPPORTED). Change-Id: I2be4e0167eb06804112758a5825cd91745128408 Signed-off-by: Darek Stojaczyk Reviewed-on: https://review.gerrithub.io/c/439316 Tested-by: SPDK CI Jenkins Chandler-Test-Pool: SPDK Automated Test System Reviewed-by: Ben Walker Reviewed-by: Shuhei Matsumoto Reviewed-by: Jim Harris --- include/spdk/vhost.h | 12 +++--------- lib/vhost/vhost_scsi.c | 12 +++++------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/include/spdk/vhost.h b/include/spdk/vhost.h index 1b0e80793..eaf8d966f 100644 --- a/include/spdk/vhost.h +++ b/include/spdk/vhost.h @@ -230,15 +230,9 @@ struct spdk_scsi_dev *spdk_vhost_scsi_dev_get_tgt(struct spdk_vhost_dev *vdev, u /** * Detach and destruct SCSI target from a vhost SCSI device. * - * If vhost SCSI device has an active socket connection, it is - * required that it has negotiated \c VIRTIO_SCSI_F_HOTPLUG feature - * flag.Otherwise an -ENOTSUP error code is returned. If the flag has - * been negotiated, the device will be marked to be deleted. Actual - * deletion is deferred until after all pending I/O to this device - * has finished. - * - * Once the target has been deleted (whether or not vhost SCSI - * device is in use) given callback will be called. + * The device will be deleted after all pending I/O is finished. + * If the driver supports VIRTIO_SCSI_F_HOTPLUG, then a hotremove + * notification will be sent. * * \param vdev vhost SCSI device * \param scsi_tgt_num slot id to delete target from diff --git a/lib/vhost/vhost_scsi.c b/lib/vhost/vhost_scsi.c index 4c1ec29f8..fd3f7a03d 100644 --- a/lib/vhost/vhost_scsi.c +++ b/lib/vhost/vhost_scsi.c @@ -923,12 +923,6 @@ spdk_vhost_scsi_dev_remove_tgt(struct spdk_vhost_dev *vdev, unsigned scsi_tgt_nu return rc; } - if (!spdk_vhost_dev_has_feature(vdev->session, VIRTIO_SCSI_F_HOTPLUG)) { - SPDK_WARNLOG("%s: 'Target %u' is in use and hot-detach is not enabled for this controller.\n", - svdev->vdev.name, scsi_tgt_num); - return -ENOTSUP; - } - scsi_dev_state = &svdev->scsi_dev_state[scsi_tgt_num]; if (scsi_dev_state->removed) { SPDK_WARNLOG("%s: 'Target %u' has been already marked to hotremove.\n", svdev->vdev.name, @@ -939,7 +933,11 @@ spdk_vhost_scsi_dev_remove_tgt(struct spdk_vhost_dev *vdev, unsigned scsi_tgt_nu scsi_dev_state->remove_cb = cb_fn; scsi_dev_state->remove_ctx = cb_arg; scsi_dev_state->removed = true; - eventq_enqueue(svdev, scsi_tgt_num, VIRTIO_SCSI_T_TRANSPORT_RESET, VIRTIO_SCSI_EVT_RESET_REMOVED); + + if (spdk_vhost_dev_has_feature(vdev->session, VIRTIO_SCSI_F_HOTPLUG)) { + eventq_enqueue(svdev, scsi_tgt_num, VIRTIO_SCSI_T_TRANSPORT_RESET, + VIRTIO_SCSI_EVT_RESET_REMOVED); + } SPDK_INFOLOG(SPDK_LOG_VHOST, "%s: queued 'Target %u' for hot-detach.\n", vdev->name, scsi_tgt_num); return 0;