From 4a3ef93344e41f267ba25ee96dec674fae2b9dc2 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Mon, 16 Oct 2017 10:22:07 -0700 Subject: [PATCH] env/dpdk: unlink hugepage_info and config files immediately for single process apps There is no need to wait until an atexit() to unlink these - we can do it immediately since the open refs will still be valid. Note: changed the remove() calls to unlink() to be more precise, since these are files and not directories. Signed-off-by: Jim Harris Change-Id: Ib160131bcf3beb9783c6fc4de021f64c43c943a9 Reviewed-on: https://review.gerrithub.io/382697 Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp Reviewed-by: Seth Howell --- lib/env_dpdk/init.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/env_dpdk/init.c b/lib/env_dpdk/init.c index f2e8fee5c..f8b8cf2ee 100644 --- a/lib/env_dpdk/init.c +++ b/lib/env_dpdk/init.c @@ -99,18 +99,18 @@ _sprintf_alloc(const char *format, ...) } static void -spdk_env_delete_shared_files(void) +spdk_env_unlink_shared_files(void) { char buffer[PATH_MAX]; snprintf(buffer, PATH_MAX, "/var/run/.spdk_pid%d_config", getpid()); - if (remove(buffer)) { - fprintf(stderr, "Unable to remove shared memory file: %s. Error code: %d\n", buffer, errno); + if (unlink(buffer)) { + fprintf(stderr, "Unable to unlink shared memory file: %s. Error code: %d\n", buffer, errno); } snprintf(buffer, PATH_MAX, "/var/run/.spdk_pid%d_hugepage_info", getpid()); - if (remove(buffer)) { - fprintf(stderr, "Unable to remove shared memory file: %s. Error code: %d\n", buffer, errno); + if (unlink(buffer)) { + fprintf(stderr, "Unable to unlink shared memory file: %s. Error code: %d\n", buffer, errno); } } @@ -304,16 +304,14 @@ void spdk_env_init(const struct spdk_env_opts *opts) exit(-1); } - /* If the shared memory id is less than 0, that means that we are - * starting a single process application. There will be no other - * processes relying on the shared configuration files created by - * dpdk for this process, and they can be deleted upon exit. - * Specifying a shared memory id >= 0 implies that there will be multiple - * processes relying on those configuration files, and we cannot delete - * them when this process exits. - */ if (opts->shm_id < 0) { - atexit(spdk_env_delete_shared_files); + /* + * Unlink hugepage and config info files after init. This will ensure they get + * deleted on app exit, even if the app crashes and does not exit normally. + * Only do this when not in multi-process mode, since for multi-process other + * apps will need to open these files. + */ + spdk_env_unlink_shared_files(); } spdk_mem_map_init();