vhost: unaffinitize rte_vhost thread

rte_vhost_driver_start() can start a new posix thread
that polls for incoming socket connections and calls
backend->start/stop_device. Soon we're going to put
more work on this thread, so we need to make sure it
doesn't collide with SPDK reactors.

This patch also fixes vdev memory leaks in case the
rte_vhost_driver_start() fails.

Change-Id: I16fdff228176a245c478251b39aa244a49bd124b
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/406959
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Dariusz Stojaczyk 2018-04-09 18:15:01 +02:00 committed by Jim Harris
parent e9ee09f153
commit ffb4d54a79
2 changed files with 31 additions and 7 deletions

View File

@ -594,6 +594,18 @@ spdk_vhost_parse_core_mask(const char *mask, struct spdk_cpuset *cpumask)
return 0;
}
static void *
_start_rte_driver(void *arg)
{
char *path = arg;
if (rte_vhost_driver_start(path) != 0) {
return NULL;
}
return path;
}
int
spdk_vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const char *mask_str,
const struct spdk_vhost_dev_backend *backend)
@ -686,6 +698,19 @@ spdk_vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const cha
goto out;
}
/* The following might start a POSIX thread that polls for incoming
* socket connections and calls backend->start/stop_device. These backend
* callbacks are also protected by the global SPDK vhost mutex, so we're
* safe with not initializing the vdev just yet.
*/
if (spdk_call_unaffinitized(_start_rte_driver, path) == NULL) {
SPDK_ERRLOG("Failed to start vhost driver for controller %s (%d): %s\n",
name, errno, spdk_strerror(errno));
rte_vhost_driver_unregister(path);
rc = -EIO;
goto out;
}
vdev->name = strdup(name);
vdev->path = strdup(path);
vdev->id = ctrlr_num++;
@ -703,13 +728,6 @@ spdk_vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const cha
TAILQ_INSERT_TAIL(&g_spdk_vhost_devices, vdev, tailq);
if (rte_vhost_driver_start(path) != 0) {
SPDK_ERRLOG("Failed to start vhost driver for controller %s (%d): %s\n", name, errno,
spdk_strerror(errno));
rte_vhost_driver_unregister(path);
return -EIO;
}
SPDK_INFOLOG(SPDK_LOG_VHOST, "Controller %s: new controller added\n", vdev->name);
return 0;

View File

@ -106,6 +106,12 @@ DEFINE_STUB(rte_vhost_set_vhost_vring_last_idx, int,
(int vid, uint16_t vring_idx, uint16_t last_avail_idx, uint16_t last_used_idx), 0);
DEFINE_STUB(spdk_env_get_current_core, uint32_t, (void), 0);
void *
spdk_call_unaffinitized(void *cb(void *arg), void *arg)
{
return cb(arg);
}
static struct spdk_vhost_dev_backend g_vdev_backend;
int spdk_vhost_nvme_admin_passthrough(int vid, void *cmd, void *cqe, void *buf)