vhost: remove all devices on shutdown
Fixes a memory leak on shutdown. Change-Id: I1fb922374b98771858757c536ab45202283150f4 Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com> Reviewed-on: https://review.gerrithub.io/396576 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
483567b1ae
commit
2307738334
@ -707,6 +707,7 @@ spdk_vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const cha
|
||||
vdev->vid = -1;
|
||||
vdev->lcore = -1;
|
||||
vdev->cpumask = cpumask;
|
||||
vdev->registered = true;
|
||||
vdev->type = type;
|
||||
vdev->backend = backend;
|
||||
|
||||
@ -754,7 +755,7 @@ spdk_vhost_dev_unregister(struct spdk_vhost_dev *vdev)
|
||||
return -ENOSPC;
|
||||
}
|
||||
|
||||
if (rte_vhost_driver_unregister(vdev->path) != 0) {
|
||||
if (vdev->registered && rte_vhost_driver_unregister(vdev->path) != 0) {
|
||||
SPDK_ERRLOG("Could not unregister controller %s with vhost library\n"
|
||||
"Check if domain socket %s still exists\n",
|
||||
vdev->name, vdev->path);
|
||||
@ -1181,6 +1182,7 @@ session_shutdown(void *arg)
|
||||
}
|
||||
|
||||
rte_vhost_driver_unregister(vdev->path);
|
||||
vdev->registered = false;
|
||||
}
|
||||
|
||||
SPDK_NOTICELOG("Exiting\n");
|
||||
@ -1337,13 +1339,28 @@ spdk_vhost_init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
_spdk_vhost_fini_remove_vdev_cb(struct spdk_vhost_dev *vdev, void *arg)
|
||||
{
|
||||
spdk_vhost_fini_cb fini_cb = arg;
|
||||
|
||||
if (vdev != NULL) {
|
||||
spdk_vhost_dev_remove(vdev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* All devices are removed now. */
|
||||
free(g_num_ctrlrs);
|
||||
fini_cb();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
_spdk_vhost_fini(void *arg1, void *arg2)
|
||||
{
|
||||
spdk_vhost_fini_cb fini_cb = arg1;
|
||||
|
||||
free(g_num_ctrlrs);
|
||||
fini_cb();
|
||||
spdk_vhost_call_external_event_foreach(_spdk_vhost_fini_remove_vdev_cb, fini_cb);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -146,6 +146,7 @@ struct spdk_vhost_dev {
|
||||
int task_cnt;
|
||||
int32_t lcore;
|
||||
struct spdk_cpuset *cpumask;
|
||||
bool registered;
|
||||
|
||||
enum spdk_vhost_dev_type type;
|
||||
const struct spdk_vhost_dev_backend *backend;
|
||||
|
@ -721,8 +721,16 @@ spdk_vhost_scsi_dev_remove(struct spdk_vhost_dev *vdev)
|
||||
|
||||
for (i = 0; i < SPDK_VHOST_SCSI_CTRLR_MAX_DEVS; ++i) {
|
||||
if (svdev->scsi_dev[i]) {
|
||||
SPDK_ERRLOG("Trying to remove non-empty controller: %s.\n", vdev->name);
|
||||
return -EBUSY;
|
||||
if (vdev->registered) {
|
||||
SPDK_ERRLOG("Trying to remove non-empty controller: %s.\n", vdev->name);
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
rc = spdk_vhost_scsi_dev_remove_tgt(vdev, i, NULL, NULL);
|
||||
if (rc != 0) {
|
||||
SPDK_ERRLOG("%s: failed to force-remove target %d\n", vdev->name, i);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,6 +115,7 @@ spdk_vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const cha
|
||||
}
|
||||
|
||||
g_spdk_vhost_device = vdev;
|
||||
vdev->registered = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -104,6 +104,7 @@ alloc_svdev(void)
|
||||
SPDK_CACHE_LINE_SIZE, NULL);
|
||||
|
||||
SPDK_CU_ASSERT_FATAL(svdev != NULL);
|
||||
svdev->vdev.registered = true;
|
||||
return svdev;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user