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: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/394446
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Dariusz Stojaczyk 2018-01-11 19:42:04 +01:00 committed by Jim Harris
parent 37fb62224a
commit 225ef46bc0
2 changed files with 17 additions and 10 deletions

View File

@ -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 * detected - LUN0. Note that the bdev creation is run asynchronously in the
* background. After it's finished, the `cb_fn` callback is called. * 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 pci_addr PCI address of the device to attach
* \param cb_fn function to be called after scanning all targets on the virtio * \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. * 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. * \return zero on success (device scan is started) or negative error code.
* In case of error the \c cb_fn is not called. * 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); bdev_virtio_create_cb cb_fn, void *cb_arg);
/** /**

View File

@ -293,12 +293,12 @@ virtio_scsi_dev_init(struct virtio_scsi_dev *svdev, uint16_t max_queues)
} }
static struct virtio_scsi_dev * 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; static int pci_dev_counter = 0;
struct virtio_scsi_dev *svdev; struct virtio_scsi_dev *svdev;
struct virtio_dev *vdev; struct virtio_dev *vdev;
char *name; char *default_name = NULL;
uint32_t num_queues; uint32_t num_queues;
int rc; int rc;
@ -309,14 +309,17 @@ virtio_pci_scsi_dev_create(struct virtio_pci_ctx *pci_ctx)
} }
vdev = &svdev->vdev; vdev = &svdev->vdev;
name = spdk_sprintf_alloc("VirtioScsi%"PRIu32, pci_dev_counter++);
if (name == NULL) { if (name == NULL) {
free(vdev); default_name = spdk_sprintf_alloc("VirtioScsi%"PRIu32, pci_dev_counter++);
return NULL; if (default_name == NULL) {
free(vdev);
return NULL;
}
name = default_name;
} }
rc = virtio_pci_dev_init(vdev, name, pci_ctx); rc = virtio_pci_dev_init(vdev, name, pci_ctx);
free(name); free(default_name);
if (rc != 0) { if (rc != 0) {
free(svdev); 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; 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; 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 { struct bdev_virtio_pci_dev_create_ctx {
const char *name;
bdev_virtio_create_cb cb_fn; bdev_virtio_create_cb cb_fn;
void *cb_arg; 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; struct bdev_virtio_pci_dev_create_ctx *create_ctx = ctx;
int rc; int rc;
svdev = virtio_pci_scsi_dev_create(pci_ctx); svdev = virtio_pci_scsi_dev_create(create_ctx->name, pci_ctx);
if (svdev == NULL) { if (svdev == NULL) {
return -1; return -1;
} }
@ -1846,11 +1850,12 @@ bdev_virtio_pci_scsi_dev_create_cb(struct virtio_pci_ctx *pci_ctx, void *ctx)
} }
int 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) bdev_virtio_create_cb cb_fn, void *cb_arg)
{ {
struct bdev_virtio_pci_dev_create_ctx create_ctx; struct bdev_virtio_pci_dev_create_ctx create_ctx;
create_ctx.name = name;
create_ctx.cb_fn = cb_fn; create_ctx.cb_fn = cb_fn;
create_ctx.cb_arg = cb_arg; create_ctx.cb_arg = cb_arg;