Commit 9f8efd87 authored by Dariusz Stojaczyk's avatar Dariusz Stojaczyk Committed by Jim Harris
Browse files

vhost: moved timed_event functions



In preparation to make them static

Change-Id: I086868aa88fa4f6f9f1c24b15a2e3cd0a04caab1
Signed-off-by: default avatarDariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/377096


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarPawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent d923a9eb
Loading
Loading
Loading
Loading
+41 −41
Original line number Diff line number Diff line
@@ -530,6 +530,47 @@ spdk_vhost_allocate_reactor(uint64_t cpumask)
	return selected_core;
}

static void
vhost_timed_event_fn(void *arg1, void *arg2)
{
	struct spdk_vhost_timed_event *ctx = arg1;

	if (ctx->cb_fn) {
		ctx->cb_fn(arg2);
	}

	sem_post(&ctx->sem);
}

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_ctx = {0};
	struct spdk_event *ev;
	struct timespec timeout;
	int rc;

	if (sem_init(&ev_ctx.sem, 0, 0) < 0)
		SPDK_ERRLOG("Failed to initialize semaphore for vhost timed event\n");

	ev_ctx.cb_fn = cb_fn;
	clock_gettime(CLOCK_REALTIME, &timeout);
	timeout.tv_sec += timeout_sec;

	ev = spdk_event_allocate(lcore, vhost_timed_event_fn, &ev_ctx, arg);
	assert(ev);
	spdk_event_call(ev);

	rc = sem_timedwait(&ev_ctx.sem, &timeout);
	if (rc != 0) {
		SPDK_ERRLOG("Timout waiting for event: %s.\n", errmsg);
		abort();
	}

	sem_destroy(&ev_ctx.sem);
}

static void
destroy_device(int vid)
{
@@ -703,47 +744,6 @@ spdk_vhost_shutdown_cb(void)
	pthread_detach(tid);
}

static void
vhost_timed_event_fn(void *arg1, void *arg2)
{
	struct spdk_vhost_timed_event *ctx = arg1;

	if (ctx->cb_fn) {
		ctx->cb_fn(arg2);
	}

	sem_post(&ctx->sem);
}

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_ctx = {0};
	struct spdk_event *ev;
	struct timespec timeout;
	int rc;

	if (sem_init(&ev_ctx.sem, 0, 0) < 0)
		SPDK_ERRLOG("Failed to initialize semaphore for vhost timed event\n");

	ev_ctx.cb_fn = cb_fn;
	clock_gettime(CLOCK_REALTIME, &timeout);
	timeout.tv_sec += timeout_sec;

	ev = spdk_event_allocate(lcore, vhost_timed_event_fn, &ev_ctx, arg);
	assert(ev);
	spdk_event_call(ev);

	rc = sem_timedwait(&ev_ctx.sem, &timeout);
	if (rc != 0) {
		SPDK_ERRLOG("Timout waiting for event: %s.\n", errmsg);
		abort();
	}

	sem_destroy(&ev_ctx.sem);
}

void
spdk_vhost_dump_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w)
{