vhost: embed destroy ctx into vhost dev struct

So we don't need to do extra memory allocation when stop vhost device.
This makes code more clean.

Change-Id: I27a1b446621ce4f452fee62acd634737b4ffe174
Signed-off-by: wuzhouhui <wuzhouhui@kingsoft.com>
Reviewed-on: https://review.gerrithub.io/427336
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
wuzhouhui 2018-09-30 17:43:41 +08:00 committed by Jim Harris
parent de2cd83828
commit 97c45f5631
4 changed files with 25 additions and 73 deletions

View File

@ -71,6 +71,7 @@ struct spdk_vhost_blk_dev {
struct spdk_bdev_desc *bdev_desc;
struct spdk_io_channel *bdev_io_channel;
struct spdk_poller *requestq_poller;
struct spdk_vhost_dev_destroy_ctx destroy_ctx;
bool readonly;
};
@ -588,17 +589,10 @@ out:
return rc;
}
struct spdk_vhost_dev_destroy_ctx {
struct spdk_vhost_blk_dev *bvdev;
struct spdk_poller *poller;
void *event_ctx;
};
static int
destroy_device_poller_cb(void *arg)
{
struct spdk_vhost_dev_destroy_ctx *ctx = arg;
struct spdk_vhost_blk_dev *bvdev = ctx->bvdev;
struct spdk_vhost_blk_dev *bvdev = arg;
int i;
if (bvdev->vdev.task_cnt > 0) {
@ -618,10 +612,8 @@ destroy_device_poller_cb(void *arg)
}
free_task_pool(bvdev);
spdk_poller_unregister(&ctx->poller);
spdk_vhost_dev_backend_event_done(ctx->event_ctx, 0);
spdk_dma_free(ctx);
spdk_poller_unregister(&bvdev->destroy_ctx.poller);
spdk_vhost_dev_backend_event_done(bvdev->destroy_ctx.event_ctx, 0);
return -1;
}
@ -630,7 +622,6 @@ static int
spdk_vhost_blk_stop(struct spdk_vhost_dev *vdev, void *event_ctx)
{
struct spdk_vhost_blk_dev *bvdev;
struct spdk_vhost_dev_destroy_ctx *destroy_ctx;
bvdev = to_blk_dev(vdev);
if (bvdev == NULL) {
@ -638,18 +629,10 @@ spdk_vhost_blk_stop(struct spdk_vhost_dev *vdev, void *event_ctx)
goto err;
}
destroy_ctx = spdk_dma_zmalloc(sizeof(*destroy_ctx), SPDK_CACHE_LINE_SIZE, NULL);
if (destroy_ctx == NULL) {
SPDK_ERRLOG("Failed to alloc memory for destroying device.\n");
goto err;
}
destroy_ctx->bvdev = bvdev;
destroy_ctx->event_ctx = event_ctx;
bvdev->destroy_ctx.event_ctx = event_ctx;
spdk_poller_unregister(&bvdev->requestq_poller);
destroy_ctx->poller = spdk_poller_register(destroy_device_poller_cb,
destroy_ctx, 1000);
bvdev->destroy_ctx.poller = spdk_poller_register(destroy_device_poller_cb,
bvdev, 1000);
return 0;
err:

View File

@ -176,6 +176,11 @@ struct spdk_vhost_dev {
TAILQ_ENTRY(spdk_vhost_dev) tailq;
};
struct spdk_vhost_dev_destroy_ctx {
struct spdk_poller *poller;
void *event_ctx;
};
struct spdk_vhost_dev *spdk_vhost_dev_find(const char *ctrlr_name);
void *spdk_vhost_gpa_to_vva(struct spdk_vhost_dev *vdev, uint64_t addr, uint64_t len);

View File

@ -139,6 +139,7 @@ struct spdk_vhost_nvme_dev {
TAILQ_ENTRY(spdk_vhost_nvme_dev) tailq;
STAILQ_HEAD(, spdk_vhost_nvme_task) free_tasks;
struct spdk_poller *requestq_poller;
struct spdk_vhost_dev_destroy_ctx destroy_ctx;
};
static const struct spdk_vhost_dev_backend spdk_vhost_nvme_device_backend;
@ -1025,17 +1026,10 @@ bdev_remove_cb(void *remove_ctx)
spdk_vhost_nvme_deactive_ns(ns);
}
struct spdk_vhost_dev_destroy_ctx {
struct spdk_vhost_nvme_dev *bvdev;
struct spdk_poller *poller;
void *event_ctx;
};
static int
destroy_device_poller_cb(void *arg)
{
struct spdk_vhost_dev_destroy_ctx *ctx = arg;
struct spdk_vhost_nvme_dev *nvme = ctx->bvdev;
struct spdk_vhost_nvme_dev *nvme = arg;
struct spdk_vhost_nvme_dev *dev, *tmp;
struct spdk_vhost_nvme_ns *ns_dev;
uint32_t i;
@ -1058,9 +1052,8 @@ destroy_device_poller_cb(void *arg)
}
}
spdk_poller_unregister(&ctx->poller);
spdk_vhost_dev_backend_event_done(ctx->event_ctx, 0);
free(ctx);
spdk_poller_unregister(&nvme->destroy_ctx.poller);
spdk_vhost_dev_backend_event_done(nvme->destroy_ctx.event_ctx, 0);
return -1;
}
@ -1071,7 +1064,6 @@ static int
spdk_vhost_nvme_stop_device(struct spdk_vhost_dev *vdev, void *event_ctx)
{
struct spdk_vhost_nvme_dev *nvme = to_nvme_dev(vdev);
struct spdk_vhost_dev_destroy_ctx *destroy_ctx;
if (nvme == NULL) {
return -1;
@ -1080,23 +1072,11 @@ spdk_vhost_nvme_stop_device(struct spdk_vhost_dev *vdev, void *event_ctx)
free_task_pool(nvme);
SPDK_NOTICELOG("Stopping Device %u, Path %s\n", vdev->vid, vdev->path);
destroy_ctx = malloc(sizeof(*destroy_ctx));
if (destroy_ctx == NULL) {
SPDK_ERRLOG("Failed to alloc memory for destroying device.\n");
goto err;
}
destroy_ctx->bvdev = nvme;
destroy_ctx->event_ctx = event_ctx;
nvme->destroy_ctx.event_ctx = event_ctx;
spdk_poller_unregister(&nvme->requestq_poller);
destroy_ctx->poller = spdk_poller_register(destroy_device_poller_cb, destroy_ctx, 1000);
nvme->destroy_ctx.poller = spdk_poller_register(destroy_device_poller_cb, nvme, 1000);
return 0;
err:
spdk_vhost_dev_backend_event_done(event_ctx, -1);
return -1;
}
static void

View File

@ -80,6 +80,7 @@ struct spdk_vhost_scsi_dev {
struct spdk_poller *requestq_poller;
struct spdk_poller *mgmt_poller;
struct spdk_vhost_dev_destroy_ctx destroy_ctx;
} __rte_cache_aligned;
struct spdk_vhost_scsi_task {
@ -1111,17 +1112,10 @@ out:
return rc;
}
struct spdk_vhost_dev_destroy_ctx {
struct spdk_vhost_scsi_dev *svdev;
struct spdk_poller *poller;
void *event_ctx;
};
static int
destroy_device_poller_cb(void *arg)
{
struct spdk_vhost_dev_destroy_ctx *ctx = arg;
struct spdk_vhost_scsi_dev *svdev = ctx->svdev;
struct spdk_vhost_scsi_dev *svdev = arg;
uint32_t i;
if (svdev->vdev.task_cnt > 0) {
@ -1144,9 +1138,8 @@ destroy_device_poller_cb(void *arg)
free_task_pool(svdev);
spdk_poller_unregister(&ctx->poller);
spdk_vhost_dev_backend_event_done(ctx->event_ctx, 0);
spdk_dma_free(ctx);
spdk_poller_unregister(&svdev->destroy_ctx.poller);
spdk_vhost_dev_backend_event_done(svdev->destroy_ctx.event_ctx, 0);
return -1;
}
@ -1155,7 +1148,6 @@ static int
spdk_vhost_scsi_stop(struct spdk_vhost_dev *vdev, void *event_ctx)
{
struct spdk_vhost_scsi_dev *svdev;
struct spdk_vhost_dev_destroy_ctx *destroy_ctx;
svdev = to_scsi_dev(vdev);
if (svdev == NULL) {
@ -1163,18 +1155,10 @@ spdk_vhost_scsi_stop(struct spdk_vhost_dev *vdev, void *event_ctx)
goto err;
}
destroy_ctx = spdk_dma_zmalloc(sizeof(*destroy_ctx), SPDK_CACHE_LINE_SIZE, NULL);
if (destroy_ctx == NULL) {
SPDK_ERRLOG("Failed to alloc memory for destroying device.\n");
goto err;
}
destroy_ctx->svdev = svdev;
destroy_ctx->event_ctx = event_ctx;
svdev->destroy_ctx.event_ctx = event_ctx;
spdk_poller_unregister(&svdev->requestq_poller);
spdk_poller_unregister(&svdev->mgmt_poller);
destroy_ctx->poller = spdk_poller_register(destroy_device_poller_cb, destroy_ctx,
svdev->destroy_ctx.poller = spdk_poller_register(destroy_device_poller_cb, svdev,
1000);
return 0;