virtio: move vdev->name allocation to generic virtio
Previously vdev->name was being allocated/freed separately in virtio_pci and virtio_user backends. Now it's all done in generic virtio library and cleans up some code. Change-Id: I810e976d09781c0c9b25c6f7fd957a83aad6c7b8 Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com> Reviewed-on: https://review.gerrithub.io/394704 Reviewed-by: <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com> Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
e6da08c28a
commit
fb12bbecd2
@ -256,11 +256,13 @@ void virtqueue_req_add_iovs(struct virtqueue *vq, struct iovec *iovs, uint16_t i
|
||||
* Before doing any I/O, it has to be manually started via \c virtio_dev_restart.
|
||||
*
|
||||
* \param vdev memory for virtio device, must be zeroed
|
||||
* \param name name for the virtio device
|
||||
* \param ops backend callbacks
|
||||
* \param ctx argument for the backend callbacks
|
||||
* \param ops_ctx argument for the backend callbacks
|
||||
* \return zero on success, or negative error code otherwise
|
||||
*/
|
||||
int virtio_dev_construct(struct virtio_dev *vdev, const struct virtio_dev_ops *ops,
|
||||
void *ctx);
|
||||
int virtio_dev_construct(struct virtio_dev *vdev, const char *name,
|
||||
const struct virtio_dev_ops *ops, void *ops_ctx);
|
||||
|
||||
/**
|
||||
* Reset the device and prepare it to be `virtio_dev_start`ed. This call
|
||||
|
@ -325,9 +325,22 @@ virtio_negotiate_features(struct virtio_dev *dev, uint64_t req_features)
|
||||
}
|
||||
|
||||
int
|
||||
virtio_dev_construct(struct virtio_dev *vdev, const struct virtio_dev_ops *ops, void *ctx)
|
||||
virtio_dev_construct(struct virtio_dev *vdev, const char *name,
|
||||
const struct virtio_dev_ops *ops, void *ctx)
|
||||
{
|
||||
pthread_mutex_init(&vdev->mutex, NULL);
|
||||
int rc;
|
||||
|
||||
vdev->name = strdup(name);
|
||||
if (vdev->name == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
rc = pthread_mutex_init(&vdev->mutex, NULL);
|
||||
if (rc != 0) {
|
||||
free(vdev->name);
|
||||
return -rc;
|
||||
}
|
||||
|
||||
vdev->backend_ops = ops;
|
||||
vdev->ctx = ctx;
|
||||
|
||||
@ -370,6 +383,7 @@ virtio_dev_destruct(struct virtio_dev *dev)
|
||||
{
|
||||
virtio_dev_backend_ops(dev)->destruct_dev(dev);
|
||||
pthread_mutex_destroy(&dev->mutex);
|
||||
free(dev->name);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -210,7 +210,6 @@ modern_destruct_dev(struct virtio_dev *vdev)
|
||||
struct spdk_pci_device *pci_dev = hw->pci_dev;
|
||||
|
||||
free_virtio_hw(hw);
|
||||
free(vdev->name);
|
||||
spdk_pci_device_detach(pci_dev);
|
||||
}
|
||||
|
||||
@ -533,20 +532,12 @@ virtio_pci_dev_init(struct virtio_dev *vdev, const char *name,
|
||||
struct virtio_pci_ctx *pci_ctx)
|
||||
{
|
||||
int rc;
|
||||
char *name_dup;
|
||||
|
||||
name_dup = strdup(name);
|
||||
if (name_dup == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = virtio_dev_construct(vdev, &modern_ops, pci_ctx);
|
||||
rc = virtio_dev_construct(vdev, name, &modern_ops, pci_ctx);
|
||||
if (rc != 0) {
|
||||
free(name_dup);
|
||||
return -1;
|
||||
}
|
||||
|
||||
vdev->name = name_dup;
|
||||
vdev->is_hw = 1;
|
||||
vdev->modern = 1;
|
||||
|
||||
|
@ -362,7 +362,6 @@ virtio_user_destroy(struct virtio_dev *vdev)
|
||||
struct virtio_user_dev *dev = vdev->ctx;
|
||||
|
||||
close(dev->vhostfd);
|
||||
free(vdev->name);
|
||||
free(dev);
|
||||
}
|
||||
|
||||
@ -410,7 +409,7 @@ virtio_user_dev_init(struct virtio_dev *vdev, const char *name, const char *path
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = virtio_dev_construct(vdev, &virtio_user_ops, dev);
|
||||
rc = virtio_dev_construct(vdev, name, &virtio_user_ops, dev);
|
||||
if (rc != 0) {
|
||||
SPDK_ERRLOG("Failed to init device: %s\n", path);
|
||||
free(dev);
|
||||
@ -418,11 +417,6 @@ virtio_user_dev_init(struct virtio_dev *vdev, const char *name, const char *path
|
||||
}
|
||||
|
||||
vdev->is_hw = 0;
|
||||
vdev->name = strdup(name);
|
||||
if (!vdev->name) {
|
||||
SPDK_ERRLOG("Failed to reserve memory for controller name: %s\n", path);
|
||||
goto err;
|
||||
}
|
||||
|
||||
snprintf(dev->path, PATH_MAX, "%s", path);
|
||||
dev->queue_size = queue_size;
|
||||
|
Loading…
x
Reference in New Issue
Block a user