Commit 225ef46b authored by Dariusz Stojaczyk's avatar Dariusz Stojaczyk Committed by Jim Harris
Browse files

bdev/virtio: allow specifying a name for virtio-pci devices



The default name remains as sprintf("VirtioScsi%d", counter++).

Change-Id: I244c1389f8dfac16f61aaf1d610a7888dd55e56c
Signed-off-by: default avatarDariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/394446


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 37fb6222
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -90,6 +90,8 @@ int bdev_virtio_user_scsi_dev_create(const char *name, const char *path,
 * detected - LUN0. Note that the bdev creation is run asynchronously in the
 * background. After it's finished, the `cb_fn` callback is called.
 *
 * \param name name for the virtio device. It will be inherited by all created
 * bdevs, which are named in the following format: <name>t<target_id>
 * \param pci_addr PCI address of the device to attach
 * \param cb_fn function to be called after scanning all targets on the virtio
 * device. It's optional, can be NULL. See \c bdev_virtio_create_cb.
@@ -97,7 +99,7 @@ int bdev_virtio_user_scsi_dev_create(const char *name, const char *path,
 * \return zero on success (device scan is started) or negative error code.
 * In case of error the \c cb_fn is not called.
 */
int bdev_virtio_pci_scsi_dev_create(struct spdk_pci_addr *pci_addr,
int bdev_virtio_pci_scsi_dev_create(const char *name, struct spdk_pci_addr *pci_addr,
				    bdev_virtio_create_cb cb_fn, void *cb_arg);

/**
+14 −9
Original line number Diff line number Diff line
@@ -293,12 +293,12 @@ virtio_scsi_dev_init(struct virtio_scsi_dev *svdev, uint16_t max_queues)
}

static struct virtio_scsi_dev *
virtio_pci_scsi_dev_create(struct virtio_pci_ctx *pci_ctx)
virtio_pci_scsi_dev_create(const char *name, struct virtio_pci_ctx *pci_ctx)
{
	static int pci_dev_counter = 0;
	struct virtio_scsi_dev *svdev;
	struct virtio_dev *vdev;
	char *name;
	char *default_name = NULL;
	uint32_t num_queues;
	int rc;

@@ -309,14 +309,17 @@ virtio_pci_scsi_dev_create(struct virtio_pci_ctx *pci_ctx)
	}

	vdev = &svdev->vdev;
	name = spdk_sprintf_alloc("VirtioScsi%"PRIu32, pci_dev_counter++);
	if (name == NULL) {
		default_name = spdk_sprintf_alloc("VirtioScsi%"PRIu32, pci_dev_counter++);
		if (default_name == NULL) {
			free(vdev);
			return NULL;
		}
		name = default_name;
	}

	rc = virtio_pci_dev_init(vdev, name, pci_ctx);
	free(name);
	free(default_name);

	if (rc != 0) {
		free(svdev);
@@ -1449,7 +1452,7 @@ virtio_pci_scsi_dev_enumerate_cb(struct virtio_pci_ctx *pci_ctx, void *ctx)
{
	struct virtio_scsi_dev *svdev;

	svdev = virtio_pci_scsi_dev_create(pci_ctx);
	svdev = virtio_pci_scsi_dev_create(NULL, pci_ctx);
	return svdev == NULL ? -1 : 0;
}

@@ -1821,6 +1824,7 @@ bdev_virtio_user_scsi_dev_create(const char *base_name, const char *path,
}

struct bdev_virtio_pci_dev_create_ctx {
	const char *name;
	bdev_virtio_create_cb cb_fn;
	void *cb_arg;
};
@@ -1832,7 +1836,7 @@ bdev_virtio_pci_scsi_dev_create_cb(struct virtio_pci_ctx *pci_ctx, void *ctx)
	struct bdev_virtio_pci_dev_create_ctx *create_ctx = ctx;
	int rc;

	svdev = virtio_pci_scsi_dev_create(pci_ctx);
	svdev = virtio_pci_scsi_dev_create(create_ctx->name, pci_ctx);
	if (svdev == NULL) {
		return -1;
	}
@@ -1846,11 +1850,12 @@ bdev_virtio_pci_scsi_dev_create_cb(struct virtio_pci_ctx *pci_ctx, void *ctx)
}

int
bdev_virtio_pci_scsi_dev_create(struct spdk_pci_addr *pci_addr,
bdev_virtio_pci_scsi_dev_create(const char *name, struct spdk_pci_addr *pci_addr,
				bdev_virtio_create_cb cb_fn, void *cb_arg)
{
	struct bdev_virtio_pci_dev_create_ctx create_ctx;

	create_ctx.name = name;
	create_ctx.cb_fn = cb_fn;
	create_ctx.cb_arg = cb_arg;