From a8c375ad77cb750de6046d70267627881c5644ca Mon Sep 17 00:00:00 2001 From: Dariusz Stojaczyk Date: Thu, 2 Nov 2017 15:04:21 +0100 Subject: [PATCH] rte_virtio: remove vtpci_internal Now that legacy PCI support has been dropped, we can safely assume there's only one backend type per device. So the vtpci_internal - containing process-local data - can be removed. Change-Id: I15d87a280b74318c7a44ee60ce3408756d1f5a69 Signed-off-by: Dariusz Stojaczyk Reviewed-on: https://review.gerrithub.io/385423 Reviewed-by: Daniel Verkamp Tested-by: SPDK Automated Test System Reviewed-by: Jim Harris --- lib/bdev/virtio/rte_virtio/virtio_dev.c | 3 --- lib/bdev/virtio/rte_virtio/virtio_dev.h | 3 +++ lib/bdev/virtio/rte_virtio/virtio_pci.c | 23 ++++------------------- lib/bdev/virtio/rte_virtio/virtio_pci.h | 17 +++-------------- 4 files changed, 10 insertions(+), 36 deletions(-) diff --git a/lib/bdev/virtio/rte_virtio/virtio_dev.c b/lib/bdev/virtio/rte_virtio/virtio_dev.c index 2b33bfb34..a03efd4ea 100644 --- a/lib/bdev/virtio/rte_virtio/virtio_dev.c +++ b/lib/bdev/virtio/rte_virtio/virtio_dev.c @@ -287,11 +287,8 @@ virtio_dev_init(struct virtio_dev *dev, uint64_t req_features) void virtio_dev_free(struct virtio_dev *dev) { - uint32_t vdev_id = dev->id; - virtio_free_queues(dev); vtpci_ops(dev)->free_vdev(dev); - vtpci_deinit(vdev_id); pthread_mutex_destroy(&dev->mutex); free(dev); } diff --git a/lib/bdev/virtio/rte_virtio/virtio_dev.h b/lib/bdev/virtio/rte_virtio/virtio_dev.h index 566393250..18920f901 100644 --- a/lib/bdev/virtio/rte_virtio/virtio_dev.h +++ b/lib/bdev/virtio/rte_virtio/virtio_dev.h @@ -98,6 +98,9 @@ struct virtio_dev { /** Mutex for asynchronous virtqueue-changing operations. */ pthread_mutex_t mutex; + /** Backend-specific callbacks. */ + const struct virtio_pci_ops *backend_ops; + /** Context for the backend ops */ void *ctx; diff --git a/lib/bdev/virtio/rte_virtio/virtio_pci.c b/lib/bdev/virtio/rte_virtio/virtio_pci.c index 7c381916f..f6da36ac6 100644 --- a/lib/bdev/virtio/rte_virtio/virtio_pci.c +++ b/lib/bdev/virtio/rte_virtio/virtio_pci.c @@ -43,6 +43,7 @@ struct virtio_driver g_virtio_driver = { .init_ctrlrs = TAILQ_HEAD_INITIALIZER(g_virtio_driver.init_ctrlrs), .attached_ctrlrs = TAILQ_HEAD_INITIALIZER(g_virtio_driver.attached_ctrlrs), + .ctrlr_counter = 0, }; /* @@ -519,27 +520,17 @@ struct virtio_dev * struct virtio_dev *vdev; unsigned vdev_num; - for (vdev_num = 0; vdev_num < VIRTIO_MAX_DEVICES; vdev_num++) { - if (g_virtio_driver.internal[vdev_num].vtpci_ops == NULL) { - break; - } - } - - if (vdev_num == VIRTIO_MAX_DEVICES) { - SPDK_ERRLOG("Max vhost device limit reached (%u).\n", VIRTIO_MAX_DEVICES); - return NULL; - } - vdev = calloc(1, sizeof(*vdev)); if (vdev == NULL) { SPDK_ERRLOG("virtio device calloc failed\n"); return NULL; } + vdev_num = __sync_add_and_fetch(&g_virtio_driver.ctrlr_counter, 1); vdev->id = vdev_num; pthread_mutex_init(&vdev->mutex, NULL); + vdev->backend_ops = ops; vdev->ctx = ctx; - g_virtio_driver.internal[vdev_num].vtpci_ops = ops; return vdev; } @@ -558,13 +549,7 @@ vtpci_enumerate_pci(void) const struct virtio_pci_ops * vtpci_ops(struct virtio_dev *dev) { - return g_virtio_driver.internal[dev->id].vtpci_ops; -} - -void -vtpci_deinit(uint32_t id) -{ - g_virtio_driver.internal[id].vtpci_ops = NULL; + return dev->backend_ops; } void diff --git a/lib/bdev/virtio/rte_virtio/virtio_pci.h b/lib/bdev/virtio/rte_virtio/virtio_pci.h index e83490983..dc4295122 100644 --- a/lib/bdev/virtio/rte_virtio/virtio_pci.h +++ b/lib/bdev/virtio/rte_virtio/virtio_pci.h @@ -45,8 +45,6 @@ struct virtqueue; -#define VIRTIO_MAX_DEVICES 128 - /* Extra status define for readability */ #define VIRTIO_CONFIG_S_RESET 0 @@ -104,19 +102,12 @@ struct virtio_hw { struct virtio_scsi_config *dev_cfg; }; -/* - * While virtio_hw is stored in shared memory, this structure stores - * some infos that may vary in the multiple process model locally. - * For example, the vtpci_ops pointer. - */ -struct vtpci_internal { - const struct virtio_pci_ops *vtpci_ops; -}; - struct virtio_driver { - struct vtpci_internal internal[VIRTIO_MAX_DEVICES]; TAILQ_HEAD(, virtio_dev) init_ctrlrs; TAILQ_HEAD(, virtio_dev) attached_ctrlrs; + + /* Increment-only virtio_dev counter */ + unsigned ctrlr_counter; }; extern struct virtio_driver g_virtio_driver; @@ -145,8 +136,6 @@ void vtpci_read_dev_config(struct virtio_dev *, size_t, void *, int); const struct virtio_pci_ops *vtpci_ops(struct virtio_dev *dev); -void vtpci_deinit(uint32_t id); - void vtpci_dump_json_config(struct virtio_dev *hw, struct spdk_json_write_ctx *w); extern const struct virtio_pci_ops virtio_user_ops;