vhost: readded return codes for dpdk callbacks

Added spdk_vhost_dev_backend_event_done function
that sets the return code for the callback and
transparently calls sem_post.

Change-Id: Iba27af780cd1753056c1607177c945e13c95c712
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/377585
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
Dariusz Stojaczyk 2017-09-07 20:34:15 +02:00 committed by Jim Harris
parent 5226e9082d
commit 2670503d46
6 changed files with 37 additions and 25 deletions

View File

@ -61,6 +61,9 @@ struct spdk_vhost_dev_event_ctx {
/** Semaphore used to signal that event is done. */
sem_t sem;
/** Response to be written by enqueued event. */
int response;
};
static int new_connection(int vid);
@ -536,12 +539,21 @@ spdk_vhost_allocate_reactor(uint64_t cpumask)
return selected_core;
}
void
spdk_vhost_dev_backend_event_done(void *event_ctx, int response)
{
struct spdk_vhost_dev_event_ctx *ctx = event_ctx;
ctx->response = response;
sem_post(&ctx->sem);
}
static void
spdk_vhost_event_cb(void *arg1, void *arg2)
{
struct spdk_vhost_dev_event_ctx *ctx = arg1;
ctx->cb_fn(ctx->vdev, &ctx->sem);
ctx->cb_fn(ctx->vdev, ctx);
}
static void
@ -599,7 +611,7 @@ spdk_vhost_event_send(struct spdk_vhost_dev *vdev, spdk_vhost_event_fn cb_fn,
sem_destroy(&ev_ctx.sem);
free(ev_ctx.ctrlr_name);
return rc;
return ev_ctx.response;
}
static int

View File

@ -484,10 +484,9 @@ alloc_task_pool(struct spdk_vhost_blk_dev *bvdev)
*
*/
static int
new_device(struct spdk_vhost_dev *vdev, void *arg)
new_device(struct spdk_vhost_dev *vdev, void *event_ctx)
{
struct spdk_vhost_blk_dev *bvdev;
sem_t *sem = arg;
int rc = 0;
bvdev = to_blk_dev(vdev);
@ -522,14 +521,14 @@ new_device(struct spdk_vhost_dev *vdev, void *arg)
bvdev, vdev->lcore, 0);
SPDK_NOTICELOG("Started poller for vhost controller %s on lcore %d\n", vdev->name, vdev->lcore);
out:
sem_post(sem);
spdk_vhost_dev_backend_event_done(event_ctx, rc);
return rc;
}
struct spdk_vhost_dev_destroy_ctx {
struct spdk_vhost_blk_dev *bvdev;
struct spdk_poller *poller;
sem_t *sem;
void *event_ctx;
};
static void
@ -553,15 +552,14 @@ destroy_device_poller_cb(void *arg)
spdk_vhost_dev_mem_unregister(&bvdev->vdev);
spdk_poller_unregister(&ctx->poller, NULL);
sem_post(ctx->sem);
spdk_vhost_dev_backend_event_done(ctx->event_ctx, 0);
}
static int
destroy_device(struct spdk_vhost_dev *vdev, void *arg)
destroy_device(struct spdk_vhost_dev *vdev, void *event_ctx)
{
struct spdk_vhost_blk_dev *bvdev;
struct spdk_vhost_dev_destroy_ctx *destroy_ctx;
sem_t *sem = arg;
bvdev = to_blk_dev(vdev);
if (bvdev == NULL) {
@ -576,7 +574,7 @@ destroy_device(struct spdk_vhost_dev *vdev, void *arg)
}
destroy_ctx->bvdev = bvdev;
destroy_ctx->sem = arg;
destroy_ctx->event_ctx = event_ctx;
spdk_poller_unregister(&bvdev->requestq_poller, NULL);
spdk_poller_register(&destroy_ctx->poller, destroy_device_poller_cb, destroy_ctx, vdev->lcore,
@ -584,7 +582,7 @@ destroy_device(struct spdk_vhost_dev *vdev, void *arg)
return 0;
err:
sem_post(sem);
spdk_vhost_dev_backend_event_done(event_ctx, -1);
return -1;
}

View File

@ -88,11 +88,12 @@ struct spdk_vhost_dev_backend {
/**
* Callbacks for starting and pausing the device.
* The first param is struct spdk_vhost_dev *,
* The second one is sem_t* passed as a void*.
* The callback must call sem_post with given sem.
* If sem_post won't be called within an arbitrary
* limit of 3 seconds, this will time out.
* The first param is struct spdk_vhost_dev *.
* The second one is event context that has to be
* passed to spdk_vhost_dev_backend_event_done().
* If spdk_vhost_dev_backend_event_done isn't called
* within an arbitrary limit of 3 seconds, these
* callbacks will time out.
*/
spdk_vhost_event_fn new_device;
spdk_vhost_event_fn destroy_device;
@ -147,5 +148,6 @@ int spdk_vhost_dev_remove(struct spdk_vhost_dev *vdev);
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_dev_backend_event_done(void *event_ctx, int response);
#endif /* SPDK_VHOST_INTERNAL_H */

View File

@ -1052,10 +1052,9 @@ alloc_task_pool(struct spdk_vhost_scsi_dev *svdev)
* and then allocated to a specific data core.
*/
static int
new_device(struct spdk_vhost_dev *vdev, void *arg)
new_device(struct spdk_vhost_dev *vdev, void *event_ctx)
{
struct spdk_vhost_scsi_dev *svdev;
sem_t *sem = arg;
uint32_t i;
int rc = 0;
@ -1094,14 +1093,14 @@ new_device(struct spdk_vhost_dev *vdev, void *arg)
spdk_poller_register(&svdev->mgmt_poller, vdev_mgmt_worker, svdev, vdev->lcore,
MGMT_POLL_PERIOD_US);
out:
sem_post(sem);
spdk_vhost_dev_backend_event_done(event_ctx, rc);
return rc;
}
struct spdk_vhost_dev_destroy_ctx {
struct spdk_vhost_scsi_dev *svdev;
struct spdk_poller *poller;
sem_t *sem;
void *event_ctx;
};
static void
@ -1138,15 +1137,14 @@ destroy_device_poller_cb(void *arg)
free_task_pool(svdev);
spdk_poller_unregister(&ctx->poller, NULL);
sem_post(ctx->sem);
spdk_vhost_dev_backend_event_done(ctx->event_ctx, 0);
}
static int
destroy_device(struct spdk_vhost_dev *vdev, void *arg)
destroy_device(struct spdk_vhost_dev *vdev, void *event_ctx)
{
struct spdk_vhost_scsi_dev *svdev;
struct spdk_vhost_dev_destroy_ctx *destroy_ctx;
sem_t *sem = arg;
svdev = to_scsi_dev(vdev);
if (svdev == NULL) {
@ -1161,7 +1159,7 @@ destroy_device(struct spdk_vhost_dev *vdev, void *arg)
}
destroy_ctx->svdev = svdev;
destroy_ctx->sem = arg;
destroy_ctx->event_ctx = event_ctx;
spdk_poller_unregister(&svdev->requestq_poller, NULL);
spdk_poller_unregister(&svdev->mgmt_poller, NULL);
@ -1171,7 +1169,7 @@ destroy_device(struct spdk_vhost_dev *vdev, void *arg)
return 0;
err:
sem_post(sem);
spdk_vhost_dev_backend_event_done(event_ctx, -1);
return -1;
}

View File

@ -121,6 +121,7 @@ DEFINE_STUB(spdk_json_write_array_end, int, (struct spdk_json_write_ctx *w), 0);
DEFINE_STUB_P(spdk_bdev_get_io_channel, struct spdk_io_channel, (struct spdk_bdev_desc *desc), {0});
DEFINE_STUB_V(spdk_vhost_call_external_event, (const char *ctrlr_name, spdk_vhost_event_fn fn,
void *arg));
DEFINE_STUB_V(spdk_vhost_dev_backend_event_done, (void *event_ctx, int response));
/* This sets spdk_vhost_dev_remove to either to fail or success */
DEFINE_STUB(spdk_vhost_dev_remove_fail, bool, (void), false);

View File

@ -117,6 +117,7 @@ DEFINE_STUB(spdk_json_write_string, int, (struct spdk_json_write_ctx *w, const c
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_array_end, int, (struct spdk_json_write_ctx *w), 0);
DEFINE_STUB_V(spdk_vhost_dev_backend_event_done, (void *event_ctx, int response));
/* This sets spdk_vhost_dev_remove to either to fail or success */
DEFINE_STUB(spdk_vhost_dev_remove_fail, bool, (void), false);