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 <james.r.harris@intel.com> Change-Id: Id9cb189b6b4afa3c724181ff190b640654d0804e Reviewed-on: https://review.gerrithub.io/366545 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
c09bfe8965
commit
fa3dd136d0
@ -251,7 +251,7 @@ function start_stub() {
|
|||||||
|
|
||||||
function kill_stub() {
|
function kill_stub() {
|
||||||
kill $stubpid
|
kill $stubpid
|
||||||
rm -rf /var/run/spdk_stub0
|
rm -f /var/run/spdk_stub0
|
||||||
}
|
}
|
||||||
|
|
||||||
function run_test() {
|
function run_test() {
|
||||||
|
@ -41,7 +41,7 @@ CFLAGS += $(ENV_CFLAGS)
|
|||||||
|
|
||||||
C_SRCS := stub.c
|
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 += $(SPDK_LIB_LINKER_ARGS)
|
||||||
LIBS += $(ENV_LINKER_ARGS)
|
LIBS += $(ENV_LINKER_ARGS)
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
#include "spdk/stdinc.h"
|
#include "spdk/stdinc.h"
|
||||||
|
|
||||||
#include "spdk/env.h"
|
#include "spdk/event.h"
|
||||||
#include "spdk/nvme.h"
|
#include "spdk/nvme.h"
|
||||||
|
|
||||||
static char g_path[256];
|
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
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int ch;
|
int ch;
|
||||||
struct spdk_env_opts opts = {};
|
struct spdk_app_opts opts = {};
|
||||||
|
|
||||||
/* default value in opts structure */
|
/* default value in opts structure */
|
||||||
spdk_env_opts_init(&opts);
|
spdk_app_opts_init(&opts);
|
||||||
|
|
||||||
opts.name = "stub";
|
opts.name = "stub";
|
||||||
|
|
||||||
@ -81,7 +107,7 @@ main(int argc, char **argv)
|
|||||||
opts.shm_id = atoi(optarg);
|
opts.shm_id = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
opts.core_mask = optarg;
|
opts.reactor_mask = optarg;
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
opts.mem_channel = atoi(optarg);
|
opts.mem_channel = atoi(optarg);
|
||||||
@ -105,21 +131,10 @@ main(int argc, char **argv)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
spdk_env_init(&opts);
|
opts.shutdown_cb = stub_shutdown;
|
||||||
if (spdk_nvme_probe(NULL, NULL, probe_cb, attach_cb, NULL) != 0) {
|
opts.max_delay_us = 1000 * 1000;
|
||||||
fprintf(stderr, "spdk_nvme_probe() failed\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(g_path, sizeof(g_path), "/var/run/spdk_stub%d", opts.shm_id);
|
spdk_app_start(&opts, stub_start, (void *)(intptr_t)opts.shm_id, NULL);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user