From fa3dd136d0cb79f97b412d14468995970d756418 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Wed, 21 Jun 2017 23:30:02 -0700 Subject: [PATCH] test/app/stub: remove sentinel file on shutdown Rather than manually adding signal handlers, just convert the stub app to use the event framework and use its shutdown handler. Still rm -f the sentinel file in the autotest_common.sh kill_stub function, although it really isn't needed anymore. Signed-off-by: Jim Harris Change-Id: Id9cb189b6b4afa3c724181ff190b640654d0804e Reviewed-on: https://review.gerrithub.io/366545 Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp Reviewed-by: Ben Walker --- scripts/autotest_common.sh | 2 +- test/app/stub/Makefile | 2 +- test/app/stub/stub.c | 51 ++++++++++++++++++++++++-------------- 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/scripts/autotest_common.sh b/scripts/autotest_common.sh index 8b698ee371..a90cbb7e4b 100755 --- a/scripts/autotest_common.sh +++ b/scripts/autotest_common.sh @@ -251,7 +251,7 @@ function start_stub() { function kill_stub() { kill $stubpid - rm -rf /var/run/spdk_stub0 + rm -f /var/run/spdk_stub0 } function run_test() { diff --git a/test/app/stub/Makefile b/test/app/stub/Makefile index 6cab555d57..2703c1e887 100644 --- a/test/app/stub/Makefile +++ b/test/app/stub/Makefile @@ -41,7 +41,7 @@ CFLAGS += $(ENV_CFLAGS) C_SRCS := stub.c -SPDK_LIB_LIST = nvme util log trace +SPDK_LIB_LIST = event conf nvme util log trace LIBS += $(SPDK_LIB_LINKER_ARGS) LIBS += $(ENV_LINKER_ARGS) diff --git a/test/app/stub/stub.c b/test/app/stub/stub.c index 7ffb8940df..8b176ffed8 100644 --- a/test/app/stub/stub.c +++ b/test/app/stub/stub.c @@ -33,7 +33,7 @@ #include "spdk/stdinc.h" -#include "spdk/env.h" +#include "spdk/event.h" #include "spdk/nvme.h" static char g_path[256]; @@ -64,14 +64,40 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid, { } +static void +stub_start(void *arg1, void *arg2) +{ + int shm_id = (intptr_t)arg1; + + spdk_unaffinitize_thread(); + + if (spdk_nvme_probe(NULL, NULL, probe_cb, attach_cb, NULL) != 0) { + fprintf(stderr, "spdk_nvme_probe() failed\n"); + exit(1); + } + + snprintf(g_path, sizeof(g_path), "/var/run/spdk_stub%d", shm_id); + if (mknod(g_path, S_IFREG, 0) != 0) { + fprintf(stderr, "could not create sentinel file %s\n", g_path); + exit(1); + } +} + +static void +stub_shutdown(void) +{ + unlink(g_path); + spdk_app_stop(0); +} + int main(int argc, char **argv) { int ch; - struct spdk_env_opts opts = {}; + struct spdk_app_opts opts = {}; /* default value in opts structure */ - spdk_env_opts_init(&opts); + spdk_app_opts_init(&opts); opts.name = "stub"; @@ -81,7 +107,7 @@ main(int argc, char **argv) opts.shm_id = atoi(optarg); break; case 'm': - opts.core_mask = optarg; + opts.reactor_mask = optarg; break; case 'n': opts.mem_channel = atoi(optarg); @@ -105,21 +131,10 @@ main(int argc, char **argv) exit(1); } - spdk_env_init(&opts); - if (spdk_nvme_probe(NULL, NULL, probe_cb, attach_cb, NULL) != 0) { - fprintf(stderr, "spdk_nvme_probe() failed\n"); - exit(1); - } + opts.shutdown_cb = stub_shutdown; + opts.max_delay_us = 1000 * 1000; - snprintf(g_path, sizeof(g_path), "/var/run/spdk_stub%d", opts.shm_id); - if (mknod(g_path, S_IFREG, 0) != 0) { - fprintf(stderr, "could not create sentinel file %s\n", g_path); - exit(1); - } - - while (1) { - sleep(1); - } + spdk_app_start(&opts, stub_start, (void *)(intptr_t)opts.shm_id, NULL); return 0; }