vhost: simplified timed_event API

Public API has been made smaller before refactoring timed_events
entirely.

Change-Id: Ie03bf5066582b6fd243229a9c8b1ceb77658dc2f
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/372686
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: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Dariusz Stojaczyk 2017-08-03 11:24:00 +02:00 committed by Jim Harris
parent 211604b76c
commit 5ccd7974cc
4 changed files with 41 additions and 61 deletions

View File

@ -49,6 +49,20 @@ static char dev_dirname[PATH_MAX] = "";
#define MAX_VHOST_DEVICES 64
struct spdk_vhost_timed_event {
/** User callback function to be executed on given lcore. */
spdk_vhost_timed_event_fn cb_fn;
/** Semaphore used to signal that event is done. */
sem_t sem;
/** Timout specified during initialization. */
struct timespec timeout;
/** Event object that can be passed to *spdk_event_call()*. */
struct spdk_event *spdk_event;
};
static int new_connection(int vid);
static int new_device(int vid);
static void destroy_device(int vid);
@ -707,12 +721,13 @@ vhost_timed_event_fn(void *arg1, void *arg2)
sem_post(&ev->sem);
}
static void
vhost_timed_event_init(struct spdk_vhost_timed_event *ev, int32_t lcore,
spdk_vhost_timed_event_fn cb_fn, void *arg, unsigned timeout_sec)
void
spdk_vhost_timed_event_send(int32_t lcore, spdk_vhost_timed_event_fn cb_fn, void *arg,
unsigned timeout_sec, const char *errmsg)
{
/* No way to free spdk event so don't allow to use it again without calling, waiting. */
assert(ev->spdk_event == NULL);
struct spdk_vhost_timed_event _ev = {0};
struct spdk_vhost_timed_event *ev = &_ev;
int rc;
if (sem_init(&ev->sem, 0, 0) < 0)
SPDK_ERRLOG("Failed to initialize semaphore for vhost timed event\n");
@ -721,32 +736,8 @@ vhost_timed_event_init(struct spdk_vhost_timed_event *ev, int32_t lcore,
clock_gettime(CLOCK_REALTIME, &ev->timeout);
ev->timeout.tv_sec += timeout_sec;
ev->spdk_event = spdk_event_allocate(lcore, vhost_timed_event_fn, ev, arg);
}
void
spdk_vhost_timed_event_init(struct spdk_vhost_timed_event *ev, int32_t lcore,
spdk_vhost_timed_event_fn cb_fn, void *arg, unsigned timeout_sec)
{
vhost_timed_event_init(ev, lcore, cb_fn, arg, timeout_sec);
}
void
spdk_vhost_timed_event_send(int32_t lcore, spdk_vhost_timed_event_fn cb_fn, void *arg,
unsigned timeout_sec, const char *errmsg)
{
struct spdk_vhost_timed_event ev = {0};
vhost_timed_event_init(&ev, lcore, cb_fn, arg, timeout_sec);
spdk_event_call(ev.spdk_event);
spdk_vhost_timed_event_wait(&ev, errmsg);
}
void
spdk_vhost_timed_event_wait(struct spdk_vhost_timed_event *ev, const char *errmsg)
{
int rc;
assert(ev->spdk_event != NULL);
assert(ev->spdk_event);
spdk_event_call(ev->spdk_event);
rc = sem_timedwait(&ev->sem, &ev->timeout);
if (rc != 0) {

View File

@ -395,6 +395,14 @@ remove_vdev_cb(void *arg)
spdk_vhost_dev_mem_unregister(&bvdev->vdev);
}
static void
unregister_vdev_cb(void *arg)
{
struct spdk_vhost_blk_dev *bvdev = arg;
spdk_poller_unregister(&bvdev->requestq_poller, NULL);
}
static struct spdk_vhost_blk_dev *
to_blk_dev(struct spdk_vhost_dev *vdev)
{
@ -546,7 +554,6 @@ static int
destroy_device(struct spdk_vhost_dev *vdev)
{
struct spdk_vhost_blk_dev *bvdev;
struct spdk_vhost_timed_event event = {0};
uint32_t i;
bvdev = to_blk_dev(vdev);
@ -555,9 +562,7 @@ destroy_device(struct spdk_vhost_dev *vdev)
return -1;
}
spdk_vhost_timed_event_init(&event, vdev->lcore, NULL, NULL, 1);
spdk_poller_unregister(&bvdev->requestq_poller, event.spdk_event);
spdk_vhost_timed_event_wait(&event, "unregister poller");
spdk_vhost_timed_event_send(vdev->lcore, unregister_vdev_cb, bvdev, 1, "unregister vdev");
/* Wait for all tasks to finish */
for (i = 1000; i && vdev->task_cnt > 0; i--) {

View File

@ -137,26 +137,8 @@ int spdk_vhost_dev_remove(struct spdk_vhost_dev *vdev);
typedef void (*spdk_vhost_timed_event_fn)(void *);
struct spdk_vhost_timed_event {
/** User callback function to be executed on given lcore. */
spdk_vhost_timed_event_fn cb_fn;
/** Semaphore used to signal that event is done. */
sem_t sem;
/** Timout specified during initialization. */
struct timespec timeout;
/** Event object that can be passed to *spdk_event_call()*. */
struct spdk_event *spdk_event;
};
void spdk_vhost_timed_event_init(struct spdk_vhost_timed_event *ev, int32_t lcore,
spdk_vhost_timed_event_fn cb_fn, void *arg, unsigned timeout_sec);
void spdk_vhost_timed_event_send(int32_t lcore, spdk_vhost_timed_event_fn cn_fn, void *arg,
unsigned timeout_sec, const char *errmsg);
void spdk_vhost_timed_event_wait(struct spdk_vhost_timed_event *event, const char *errmsg);
int spdk_vhost_blk_controller_construct(void);
void spdk_vhost_dump_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w);

View File

@ -727,6 +727,15 @@ remove_vdev_cb(void *arg)
spdk_vhost_dev_mem_unregister(&svdev->vdev);
}
static void
unregister_vdev_cb(void *arg)
{
struct spdk_vhost_scsi_dev *svdev = arg;
spdk_poller_unregister(&svdev->requestq_poller, NULL);
spdk_poller_unregister(&svdev->mgmt_poller, NULL);
}
static struct spdk_vhost_scsi_dev *
to_scsi_dev(struct spdk_vhost_dev *ctrlr)
{
@ -1125,7 +1134,6 @@ destroy_device(struct spdk_vhost_dev *vdev)
{
struct spdk_vhost_scsi_dev *svdev;
void *ev;
struct spdk_vhost_timed_event event = {0};
uint32_t i;
svdev = to_scsi_dev(vdev);
@ -1134,13 +1142,7 @@ destroy_device(struct spdk_vhost_dev *vdev)
return -1;
}
spdk_vhost_timed_event_init(&event, vdev->lcore, NULL, NULL, 1);
spdk_poller_unregister(&svdev->requestq_poller, event.spdk_event);
spdk_vhost_timed_event_wait(&event, "unregister request queue poller");
spdk_vhost_timed_event_init(&event, vdev->lcore, NULL, NULL, 1);
spdk_poller_unregister(&svdev->mgmt_poller, event.spdk_event);
spdk_vhost_timed_event_wait(&event, "unregister management poller");
spdk_vhost_timed_event_send(vdev->lcore, unregister_vdev_cb, svdev, 1, "unregister scsi vdev");
/* Wait for all tasks to finish */
for (i = 1000; i && vdev->task_cnt > 0; i--) {