vhost: sync controller creation with g_spdk_vhost_mutex
Controller creation RPC can't be done on controller's reactor (as there's obviously no controller yet...), so a special set of vhost_mutex_lock/unlock() functions to has been added to synchronise controller creation with the rest of ctrlr-enumerating code. Change-Id: Ib6e4b894a85ff1f70ebd047832c5a3568a00f1a7 Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com> Reviewed-on: https://review.gerrithub.io/377651 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
parent
1fc1068049
commit
a8599cd4f0
@ -901,4 +901,16 @@ spdk_vhost_call_external_event(const char *ctrlr_name, spdk_vhost_event_fn fn, v
|
|||||||
pthread_mutex_unlock(&g_spdk_vhost_mutex);
|
pthread_mutex_unlock(&g_spdk_vhost_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
spdk_vhost_lock(void)
|
||||||
|
{
|
||||||
|
pthread_mutex_lock(&g_spdk_vhost_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
spdk_vhost_unlock(void)
|
||||||
|
{
|
||||||
|
pthread_mutex_unlock(&g_spdk_vhost_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
SPDK_LOG_REGISTER_TRACE_FLAG("vhost_ring", SPDK_TRACE_VHOST_RING)
|
SPDK_LOG_REGISTER_TRACE_FLAG("vhost_ring", SPDK_TRACE_VHOST_RING)
|
||||||
|
@ -671,27 +671,31 @@ spdk_vhost_blk_controller_construct(void)
|
|||||||
int
|
int
|
||||||
spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *dev_name, bool readonly)
|
spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *dev_name, bool readonly)
|
||||||
{
|
{
|
||||||
struct spdk_vhost_blk_dev *bvdev;
|
struct spdk_vhost_blk_dev *bvdev = NULL;
|
||||||
struct spdk_bdev *bdev;
|
struct spdk_bdev *bdev;
|
||||||
int ret;
|
int ret = 0;
|
||||||
|
|
||||||
|
spdk_vhost_lock();
|
||||||
bdev = spdk_bdev_get_by_name(dev_name);
|
bdev = spdk_bdev_get_by_name(dev_name);
|
||||||
if (bdev == NULL) {
|
if (bdev == NULL) {
|
||||||
SPDK_ERRLOG("Controller %s: bdev '%s' not found\n",
|
SPDK_ERRLOG("Controller %s: bdev '%s' not found\n",
|
||||||
name, dev_name);
|
name, dev_name);
|
||||||
return -1;
|
ret = -1;
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
bvdev = spdk_dma_zmalloc(sizeof(*bvdev), SPDK_CACHE_LINE_SIZE, NULL);
|
bvdev = spdk_dma_zmalloc(sizeof(*bvdev), SPDK_CACHE_LINE_SIZE, NULL);
|
||||||
if (bvdev == NULL) {
|
if (bvdev == NULL) {
|
||||||
return -1;
|
ret = -1;
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = spdk_bdev_open(bdev, true, bdev_remove_cb, bvdev, &bvdev->bdev_desc);
|
ret = spdk_bdev_open(bdev, true, bdev_remove_cb, bvdev, &bvdev->bdev_desc);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
SPDK_ERRLOG("Controller %s: could not open bdev '%s', error=%d\n",
|
SPDK_ERRLOG("Controller %s: could not open bdev '%s', error=%d\n",
|
||||||
name, dev_name, ret);
|
name, dev_name, ret);
|
||||||
goto err;
|
ret = -1;
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
bvdev->bdev = bdev;
|
bvdev->bdev = bdev;
|
||||||
@ -700,7 +704,8 @@ spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *dev_
|
|||||||
&vhost_blk_device_backend);
|
&vhost_blk_device_backend);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
spdk_bdev_close(bvdev->bdev_desc);
|
spdk_bdev_close(bvdev->bdev_desc);
|
||||||
goto err;
|
ret = -1;
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (readonly && rte_vhost_driver_enable_features(bvdev->vdev.path, (1ULL << VIRTIO_BLK_F_RO))) {
|
if (readonly && rte_vhost_driver_enable_features(bvdev->vdev.path, (1ULL << VIRTIO_BLK_F_RO))) {
|
||||||
@ -711,17 +716,17 @@ spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *dev_
|
|||||||
SPDK_ERRLOG("Controller %s: failed to remove controller\n", name);
|
SPDK_ERRLOG("Controller %s: failed to remove controller\n", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
goto err;
|
ret = -1;
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
SPDK_NOTICELOG("Controller %s: using bdev '%s'\n",
|
SPDK_NOTICELOG("Controller %s: using bdev '%s'\n", name, dev_name);
|
||||||
name, dev_name);
|
out:
|
||||||
|
if (ret != 0 && bvdev) {
|
||||||
return 0;
|
|
||||||
|
|
||||||
err:
|
|
||||||
spdk_dma_free(bvdev);
|
spdk_dma_free(bvdev);
|
||||||
return -1;
|
}
|
||||||
|
spdk_vhost_unlock();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -149,5 +149,7 @@ int spdk_vhost_dev_remove(struct spdk_vhost_dev *vdev);
|
|||||||
int spdk_vhost_blk_controller_construct(void);
|
int spdk_vhost_blk_controller_construct(void);
|
||||||
void spdk_vhost_dump_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w);
|
void spdk_vhost_dump_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w);
|
||||||
void spdk_vhost_dev_backend_event_done(void *event_ctx, int response);
|
void spdk_vhost_dev_backend_event_done(void *event_ctx, int response);
|
||||||
|
void spdk_vhost_lock(void);
|
||||||
|
void spdk_vhost_unlock(void);
|
||||||
|
|
||||||
#endif /* SPDK_VHOST_INTERNAL_H */
|
#endif /* SPDK_VHOST_INTERNAL_H */
|
||||||
|
@ -715,16 +715,17 @@ spdk_vhost_scsi_dev_construct(const char *name, const char *cpumask)
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
spdk_vhost_lock();
|
||||||
rc = spdk_vhost_dev_construct(&svdev->vdev, name, cpumask, SPDK_VHOST_DEV_T_SCSI,
|
rc = spdk_vhost_dev_construct(&svdev->vdev, name, cpumask, SPDK_VHOST_DEV_T_SCSI,
|
||||||
&spdk_vhost_scsi_device_backend);
|
&spdk_vhost_scsi_device_backend);
|
||||||
|
|
||||||
if (rc) {
|
if (rc) {
|
||||||
spdk_ring_free(svdev->vhost_events);
|
spdk_ring_free(svdev->vhost_events);
|
||||||
spdk_dma_free(svdev);
|
spdk_dma_free(svdev);
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
spdk_vhost_unlock();
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -122,6 +122,8 @@ DEFINE_STUB_P(spdk_bdev_get_io_channel, struct spdk_io_channel, (struct spdk_bde
|
|||||||
DEFINE_STUB_V(spdk_vhost_call_external_event, (const char *ctrlr_name, spdk_vhost_event_fn fn,
|
DEFINE_STUB_V(spdk_vhost_call_external_event, (const char *ctrlr_name, spdk_vhost_event_fn fn,
|
||||||
void *arg));
|
void *arg));
|
||||||
DEFINE_STUB_V(spdk_vhost_dev_backend_event_done, (void *event_ctx, int response));
|
DEFINE_STUB_V(spdk_vhost_dev_backend_event_done, (void *event_ctx, int response));
|
||||||
|
DEFINE_STUB_V(spdk_vhost_lock, (void));
|
||||||
|
DEFINE_STUB_V(spdk_vhost_unlock, (void));
|
||||||
|
|
||||||
/* This sets spdk_vhost_dev_remove to either to fail or success */
|
/* This sets spdk_vhost_dev_remove to either to fail or success */
|
||||||
DEFINE_STUB(spdk_vhost_dev_remove_fail, bool, (void), false);
|
DEFINE_STUB(spdk_vhost_dev_remove_fail, bool, (void), false);
|
||||||
|
@ -118,6 +118,8 @@ DEFINE_STUB(spdk_json_write_array_begin, int, (struct spdk_json_write_ctx *w), 0
|
|||||||
DEFINE_STUB(spdk_json_write_object_end, int, (struct spdk_json_write_ctx *w), 0);
|
DEFINE_STUB(spdk_json_write_object_end, int, (struct spdk_json_write_ctx *w), 0);
|
||||||
DEFINE_STUB(spdk_json_write_array_end, int, (struct spdk_json_write_ctx *w), 0);
|
DEFINE_STUB(spdk_json_write_array_end, int, (struct spdk_json_write_ctx *w), 0);
|
||||||
DEFINE_STUB_V(spdk_vhost_dev_backend_event_done, (void *event_ctx, int response));
|
DEFINE_STUB_V(spdk_vhost_dev_backend_event_done, (void *event_ctx, int response));
|
||||||
|
DEFINE_STUB_V(spdk_vhost_lock, (void));
|
||||||
|
DEFINE_STUB_V(spdk_vhost_unlock, (void));
|
||||||
|
|
||||||
/* This sets spdk_vhost_dev_remove to either to fail or success */
|
/* This sets spdk_vhost_dev_remove to either to fail or success */
|
||||||
DEFINE_STUB(spdk_vhost_dev_remove_fail, bool, (void), false);
|
DEFINE_STUB(spdk_vhost_dev_remove_fail, bool, (void), false);
|
||||||
|
Loading…
Reference in New Issue
Block a user