diff --git a/lib/bdev/virtio/bdev_virtio.c b/lib/bdev/virtio/bdev_virtio.c index dba028a4f4..c6935b3745 100644 --- a/lib/bdev/virtio/bdev_virtio.c +++ b/lib/bdev/virtio/bdev_virtio.c @@ -53,7 +53,7 @@ #define BDEV_VIRTIO_MAX_TARGET 64 #define BDEV_VIRTIO_SCAN_PAYLOAD_SIZE 256 -#define CTRLQ_POLL_PERIOD_US (1000 * 5) +#define MGMT_POLL_PERIOD_US (1000 * 5) #define CTRLQ_RING_SIZE 16 #define SCAN_REQUEST_RETRIES 5 @@ -77,6 +77,12 @@ struct virtio_scsi_dev { /** Context for the SCSI target scan. */ struct virtio_scsi_scan_base *scan_ctx; + /** Controlq poller. */ + struct spdk_poller *mgmt_poller; + + /** Controlq messages to be sent. */ + struct spdk_ring *ctrlq_ring; + /** Device marked for removal. */ bool removed; }; @@ -139,6 +145,9 @@ struct bdev_virtio_io_channel { /** Virtqueue exclusively assigned to this channel. */ struct virtqueue *vq; + + /** Virtio response poller. */ + struct spdk_poller *poller; }; /** Module finish in progress */ @@ -155,7 +164,6 @@ static int virtio_scsi_dev_init(struct virtio_scsi_dev *svdev) { struct virtio_dev *vdev = &svdev->vdev; - struct virtqueue *ctrlq; struct spdk_ring *ctrlq_ring; int rc; @@ -178,9 +186,9 @@ virtio_scsi_dev_init(struct virtio_scsi_dev *svdev) return -1; } - ctrlq = vdev->vqs[VIRTIO_SCSI_CONTROLQ]; - ctrlq->poller_ctx = ctrlq_ring; - ctrlq->poller = spdk_poller_register(bdev_virtio_ctrlq_poll, vdev, CTRLQ_POLL_PERIOD_US); + svdev->ctrlq_ring = ctrlq_ring; + svdev->mgmt_poller = spdk_poller_register(bdev_virtio_ctrlq_poll, svdev, + MGMT_POLL_PERIOD_US); TAILQ_INIT(&svdev->luns); svdev->scan_ctx = NULL; @@ -396,14 +404,13 @@ bdev_virtio_reset(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io) struct bdev_virtio_io_channel *virtio_ch = spdk_io_channel_get_ctx(ch); struct virtio_scsi_io_ctx *io_ctx = bdev_virtio_init_tmf_vreq(ch, bdev_io); struct virtio_scsi_ctrl_tmf_req *tmf_req = &io_ctx->tmf_req; - struct virtio_dev *vdev = &virtio_ch->svdev->vdev; - struct spdk_ring *ctrlq_send_ring = vdev->vqs[VIRTIO_SCSI_CONTROLQ]->poller_ctx; + struct virtio_scsi_dev *svdev = virtio_ch->svdev; size_t enqueued_count; tmf_req->type = VIRTIO_SCSI_T_TMF; tmf_req->subtype = VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET; - enqueued_count = spdk_ring_enqueue(ctrlq_send_ring, (void **)&bdev_io, 1); + enqueued_count = spdk_ring_enqueue(svdev->ctrlq_ring, (void **)&bdev_io, 1); if (spdk_likely(enqueued_count == 1)) { return; } else { @@ -691,9 +698,10 @@ bdev_virtio_send_tmf_io(struct virtqueue *ctrlq, struct spdk_bdev_io *bdev_io) static void bdev_virtio_ctrlq_poll(void *arg) { - struct virtio_dev *vdev = arg; + struct virtio_scsi_dev *svdev = arg; + struct virtio_dev *vdev = &svdev->vdev; struct virtqueue *ctrlq = vdev->vqs[VIRTIO_SCSI_CONTROLQ]; - struct spdk_ring *send_ring = ctrlq->poller_ctx; + struct spdk_ring *send_ring = svdev->ctrlq_ring; struct spdk_bdev_io *bdev_io[16]; uint32_t io_len[16]; uint16_t i, cnt; @@ -733,7 +741,7 @@ bdev_virtio_scsi_ch_create_cb(void *io_device, void *ctx_buf) ch->svdev = svdev; ch->vq = vq; - vq->poller = spdk_poller_register(bdev_virtio_poll, ch, 0); + ch->poller = spdk_poller_register(bdev_virtio_poll, ch, 0); return 0; } @@ -741,12 +749,12 @@ bdev_virtio_scsi_ch_create_cb(void *io_device, void *ctx_buf) static void bdev_virtio_scsi_ch_destroy_cb(void *io_device, void *ctx_buf) { - struct bdev_virtio_io_channel *io_channel = ctx_buf; - struct virtio_scsi_dev *svdev = io_channel->svdev; + struct bdev_virtio_io_channel *ch = ctx_buf; + struct virtio_scsi_dev *svdev = ch->svdev; struct virtio_dev *vdev = &svdev->vdev; - struct virtqueue *vq = io_channel->vq; + struct virtqueue *vq = ch->vq; - spdk_poller_unregister(&vq->poller); + spdk_poller_unregister(&ch->poller); virtio_dev_release_queue(vdev, vq->vq_queue_index); } @@ -1361,7 +1369,6 @@ virtio_scsi_dev_scan(struct virtio_scsi_dev *svdev, bdev_virtio_create_cb cb_fn, TAILQ_INIT(&base->found_disks); base->channel = spdk_io_channel_get_ctx(io_ch); - svdev->scan_ctx = base; rc = _virtio_scsi_dev_scan_next(base); if (rc) { @@ -1437,8 +1444,6 @@ virtio_scsi_dev_unregister_cb(void *io_device) { struct virtio_scsi_dev *svdev = io_device; struct virtio_dev *vdev = &svdev->vdev; - struct virtqueue *vq; - struct spdk_ring *send_ring; struct spdk_thread *thread; bool finish_module; @@ -1448,16 +1453,12 @@ virtio_scsi_dev_unregister_cb(void *io_device) return; } - if (virtio_dev_queue_is_acquired(vdev, VIRTIO_SCSI_CONTROLQ)) { - vq = vdev->vqs[VIRTIO_SCSI_CONTROLQ]; - spdk_poller_unregister(&vq->poller); - send_ring = vq->poller_ctx; - /* bdevs built on top of this vdev mustn't be destroyed with outstanding I/O. */ - assert(spdk_ring_count(send_ring) == 0); - spdk_ring_free(send_ring); - vq->poller_ctx = NULL; - virtio_dev_release_queue(vdev, VIRTIO_SCSI_CONTROLQ); - } + /* bdevs built on top of this vdev mustn't be destroyed with outstanding I/O. */ + assert(spdk_ring_count(svdev->ctrlq_ring) == 0); + spdk_ring_free(svdev->ctrlq_ring); + spdk_poller_unregister(&svdev->mgmt_poller); + + virtio_dev_release_queue(vdev, VIRTIO_SCSI_CONTROLQ); virtio_dev_stop(vdev); virtio_dev_destruct(vdev); diff --git a/lib/bdev/virtio/rte_virtio/virtio.c b/lib/bdev/virtio/rte_virtio/virtio.c index 2426ad1c37..c4936fcdd4 100644 --- a/lib/bdev/virtio/rte_virtio/virtio.c +++ b/lib/bdev/virtio/rte_virtio/virtio.c @@ -219,7 +219,6 @@ virtio_init_queue(struct virtio_dev *dev, uint16_t vtpci_queue_idx) virtio_init_vring(vq); vq->owner_thread = NULL; - vq->poller = NULL; if (virtio_dev_backend_ops(dev)->setup_queue(dev, vq) < 0) { SPDK_ERRLOG("setup_queue failed\n"); @@ -583,7 +582,6 @@ virtio_dev_acquire_queue(struct virtio_dev *vdev, uint16_t index) return -1; } - assert(vq->poller == NULL); vq->owner_thread = spdk_get_thread(); pthread_mutex_unlock(&vdev->mutex); return 0; @@ -609,7 +607,6 @@ virtio_dev_find_and_acquire_queue(struct virtio_dev *vdev, uint16_t start_index) return -1; } - assert(vq->poller == NULL); vq->owner_thread = spdk_get_thread(); pthread_mutex_unlock(&vdev->mutex); return i; @@ -662,7 +659,6 @@ virtio_dev_release_queue(struct virtio_dev *vdev, uint16_t index) return; } - assert(vq->poller == NULL); assert(vq->owner_thread == spdk_get_thread()); vq->owner_thread = NULL; pthread_mutex_unlock(&vdev->mutex); diff --git a/lib/bdev/virtio/rte_virtio/virtio.h b/lib/bdev/virtio/rte_virtio/virtio.h index 86734ee6ca..598ba180c4 100644 --- a/lib/bdev/virtio/rte_virtio/virtio.h +++ b/lib/bdev/virtio/rte_virtio/virtio.h @@ -163,12 +163,6 @@ struct virtqueue { /** Thread that's polling this queue. */ struct spdk_thread *owner_thread; - /** Response poller. */ - struct spdk_poller *poller; - - /** Context for response poller. */ - void *poller_ctx; - uint16_t req_start; uint16_t req_end;