DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 18.05-RC2 0/4] Clean up EAL runtime data paths
@ 2018-04-25 12:24 Anatoly Burakov
  2018-04-25 12:24 ` [dpdk-dev] [PATCH 18.05-RC2 1/4] eal: remove unused define Anatoly Burakov
                   ` (8 more replies)
  0 siblings, 9 replies; 23+ messages in thread
From: Anatoly Burakov @ 2018-04-25 12:24 UTC (permalink / raw)
  To: dev; +Cc: bruce.richardson, thomas

As has been suggested [1], all DPDK runtime paths should be put
into a single place. This patchset accomplishes exactly that.

If running as root, all files will be put under /var/run/dpdk/<prefix>,
otherwise they will be put under $XDG_RUNTIME_PATH/dpdk/<prefix>, or, if
that environment variable is not defined, all files will go under
/tmp/dpdk/<prefix>.

This patchset depends on file locking changes [2], and is targeted for RC2.

[1] http://dpdk.org/dev/patchwork/patch/38688/
[2] http://dpdk.org/dev/patchwork/patch/38888/

Anatoly Burakov (4):
  eal: remove unused define
  eal: rename function returning hugepage data path
  eal: add directory for DPDK runtime data
  eal: move all runtime data into DPDK runtime dir

 lib/librte_eal/bsdapp/eal/eal.c          | 70 +++++++++++++++++++++++++++
 lib/librte_eal/common/eal_filesystem.h   | 81 ++++++++++----------------------
 lib/librte_eal/linuxapp/eal/eal.c        | 69 +++++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_memory.c | 10 ++--
 4 files changed, 171 insertions(+), 59 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [dpdk-dev] [PATCH 18.05-RC2 1/4] eal: remove unused define
  2018-04-25 12:24 [dpdk-dev] [PATCH 18.05-RC2 0/4] Clean up EAL runtime data paths Anatoly Burakov
@ 2018-04-25 12:24 ` Anatoly Burakov
  2018-04-26  7:11   ` David Marchand
  2018-04-25 12:24 ` [dpdk-dev] [PATCH 18.05-RC2 2/4] eal: rename function returning hugepage data path Anatoly Burakov
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 23+ messages in thread
From: Anatoly Burakov @ 2018-04-25 12:24 UTC (permalink / raw)
  To: dev; +Cc: bruce.richardson, thomas, david.marchand, stable

The define was a leftover from IVSHMEM library.

Fixes: c711ccb30987 ("ivshmem: remove library and its EAL integration")
Cc: david.marchand@6wind.com
Cc: stable@dpdk.org

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 lib/librte_eal/common/eal_filesystem.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/lib/librte_eal/common/eal_filesystem.h b/lib/librte_eal/common/eal_filesystem.h
index 0a82f89..37ac672 100644
--- a/lib/librte_eal/common/eal_filesystem.h
+++ b/lib/librte_eal/common/eal_filesystem.h
@@ -104,8 +104,6 @@ eal_hugepage_file_path(void)
 
 /** String format for hugepage map files. */
 #define HUGEFILE_FMT "%s/%smap_%d"
-#define TEMP_HUGEFILE_FMT "%s/%smap_temp_%d"
-
 static inline const char *
 eal_get_hugefile_path(char *buffer, size_t buflen, const char *hugedir, int f_id)
 {
-- 
2.7.4

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [dpdk-dev] [PATCH 18.05-RC2 2/4] eal: rename function returning hugepage data path
  2018-04-25 12:24 [dpdk-dev] [PATCH 18.05-RC2 0/4] Clean up EAL runtime data paths Anatoly Burakov
  2018-04-25 12:24 ` [dpdk-dev] [PATCH 18.05-RC2 1/4] eal: remove unused define Anatoly Burakov
@ 2018-04-25 12:24 ` Anatoly Burakov
  2018-04-25 12:24 ` [dpdk-dev] [PATCH 18.05-RC2 3/4] eal: add directory for DPDK runtime data Anatoly Burakov
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 23+ messages in thread
From: Anatoly Burakov @ 2018-04-25 12:24 UTC (permalink / raw)
  To: dev; +Cc: bruce.richardson, thomas

The original name for this path was not too descriptive and
confusing. Rename it to a more appropriate and descriptive name:
it stores data about hugepages, so name it eal_hugepage_data_path().

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 lib/librte_eal/common/eal_filesystem.h   |  2 +-
 lib/librte_eal/linuxapp/eal/eal_memory.c | 10 ++++++----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/lib/librte_eal/common/eal_filesystem.h b/lib/librte_eal/common/eal_filesystem.h
index 37ac672..2ed857e 100644
--- a/lib/librte_eal/common/eal_filesystem.h
+++ b/lib/librte_eal/common/eal_filesystem.h
@@ -89,7 +89,7 @@ eal_hugepage_info_path(void)
 #define HUGEPAGE_FILE_FMT "%s/.%s_hugepage_file"
 
 static inline const char *
-eal_hugepage_file_path(void)
+eal_hugepage_data_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
 	const char *directory = default_config_dir;
diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
index ad3add8..db401a9 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -1499,7 +1499,7 @@ eal_legacy_hugepage_init(void)
 	}
 
 	/* create shared memory */
-	hugepage = create_shared_memory(eal_hugepage_file_path(),
+	hugepage = create_shared_memory(eal_hugepage_data_path(),
 			nr_hugefiles * sizeof(struct hugepage_file));
 
 	if (hugepage == NULL) {
@@ -1696,16 +1696,18 @@ eal_legacy_hugepage_attach(void)
 
 	test_phys_addrs_available();
 
-	fd_hugepage = open(eal_hugepage_file_path(), O_RDONLY);
+	fd_hugepage = open(eal_hugepage_data_path(), O_RDONLY);
 	if (fd_hugepage < 0) {
-		RTE_LOG(ERR, EAL, "Could not open %s\n", eal_hugepage_file_path());
+		RTE_LOG(ERR, EAL, "Could not open %s\n",
+				eal_hugepage_data_path());
 		goto error;
 	}
 
 	size = getFileSize(fd_hugepage);
 	hp = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd_hugepage, 0);
 	if (hp == MAP_FAILED) {
-		RTE_LOG(ERR, EAL, "Could not mmap %s\n", eal_hugepage_file_path());
+		RTE_LOG(ERR, EAL, "Could not mmap %s\n",
+				eal_hugepage_data_path());
 		goto error;
 	}
 
-- 
2.7.4

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [dpdk-dev] [PATCH 18.05-RC2 3/4] eal: add directory for DPDK runtime data
  2018-04-25 12:24 [dpdk-dev] [PATCH 18.05-RC2 0/4] Clean up EAL runtime data paths Anatoly Burakov
  2018-04-25 12:24 ` [dpdk-dev] [PATCH 18.05-RC2 1/4] eal: remove unused define Anatoly Burakov
  2018-04-25 12:24 ` [dpdk-dev] [PATCH 18.05-RC2 2/4] eal: rename function returning hugepage data path Anatoly Burakov
@ 2018-04-25 12:24 ` Anatoly Burakov
  2018-04-25 12:24 ` [dpdk-dev] [PATCH 18.05-RC2 4/4] eal: move all runtime data into DPDK runtime dir Anatoly Burakov
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 23+ messages in thread
From: Anatoly Burakov @ 2018-04-25 12:24 UTC (permalink / raw)
  To: dev; +Cc: Bruce Richardson, thomas

Currently, during runtime, DPDK will store a bunch of files here
and there (in /var/run, /tmp or in $HOME). Fix it by creating a
DPDK-specific runtime directory, under which all runtime data
will be placed. The template for creating this runtime directory
is the following:

  <base path>/dpdk/<DPDK prefix>/

Where <base path> is set to either "/var/run" if run as root, or
$XDG_RUNTIME_DIR if run as non-root, with a fallback to /tmp if
$XDG_RUNTIME_DIR is not defined. So, for example, if run as root,
by default all runtime data will be stored at /var/run/dpdk/rte/.

There is no equivalent of "mkdir -p", so we will be creating the
path step by step.

Nothing uses this new path yet, changes for that will come in
next commit.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 lib/librte_eal/bsdapp/eal/eal.c        | 68 ++++++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_filesystem.h |  8 ++++
 lib/librte_eal/linuxapp/eal/eal.c      | 67 +++++++++++++++++++++++++++++++++
 3 files changed, 143 insertions(+)

diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index d996190..400c273 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -18,6 +18,7 @@
 #include <limits.h>
 #include <sys/mman.h>
 #include <sys/queue.h>
+#include <sys/stat.h>
 
 #include <rte_compat.h>
 #include <rte_common.h>
@@ -83,6 +84,66 @@ struct internal_config internal_config;
 /* used by rte_rdtsc() */
 int rte_cycles_vmware_tsc_map;
 
+/* platform-specific runtime dir */
+static char runtime_dir[PATH_MAX];
+
+int
+eal_create_runtime_dir(void)
+{
+	const char *directory = default_config_dir;
+	const char *xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
+	const char *fallback = "/tmp";
+	char tmp[PATH_MAX];
+	int ret;
+
+	if (getuid() != 0) {
+		/* try XDG path first, fall back to /tmp */
+		if (xdg_runtime_dir != NULL)
+			directory = xdg_runtime_dir;
+		else
+			directory = fallback;
+	}
+	/* create DPDK subdirectory under runtime dir */
+	ret = snprintf(tmp, sizeof(tmp), "%s/dpdk", directory);
+	if (ret < 0 || ret == sizeof(tmp)) {
+		RTE_LOG(ERR, EAL, "Error creating DPDK runtime path name\n");
+		return -1;
+	}
+
+	/* create prefix-specific subdirectory under DPDK runtime dir */
+	ret = snprintf(runtime_dir, sizeof(runtime_dir), "%s/%s",
+			tmp, internal_config.hugefile_prefix);
+	if (ret < 0 || ret == sizeof(runtime_dir)) {
+		RTE_LOG(ERR, EAL, "Error creating prefix-specific runtime path name\n");
+		return -1;
+	}
+
+	/* create the path if it doesn't exist. no "mkdir -p" here, so do it
+	 * step by step.
+	 */
+	ret = mkdir(tmp, 0600);
+	if (ret < 0 && errno != EEXIST) {
+		RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
+			tmp, strerror(errno));
+		return -1;
+	}
+
+	ret = mkdir(runtime_dir, 0600);
+	if (ret < 0 && errno != EEXIST) {
+		RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
+			runtime_dir, strerror(errno));
+		return -1;
+	}
+
+	return 0;
+}
+
+const char *
+eal_get_runtime_dir(void)
+{
+	return runtime_dir;
+}
+
 /* Return user provided mbuf pool ops name */
 const char * __rte_experimental
 rte_eal_mbuf_user_pool_ops(void)
@@ -522,6 +583,13 @@ rte_eal_init(int argc, char **argv)
 	/* set log level as early as possible */
 	eal_log_level_parse(argc, argv);
 
+	/* create runtime data directory */
+	if (eal_create_runtime_dir() < 0) {
+		rte_eal_init_alert("Cannot create runtime directory\n");
+		rte_errno = EACCES;
+		return -1;
+	}
+
 	if (rte_eal_cpu_init() < 0) {
 		rte_eal_init_alert("Cannot detect lcores.");
 		rte_errno = ENOTSUP;
diff --git a/lib/librte_eal/common/eal_filesystem.h b/lib/librte_eal/common/eal_filesystem.h
index 2ed857e..22f9f21 100644
--- a/lib/librte_eal/common/eal_filesystem.h
+++ b/lib/librte_eal/common/eal_filesystem.h
@@ -25,6 +25,14 @@
 
 static const char *default_config_dir = "/var/run";
 
+/* sets up platform-specific runtime data dir */
+int
+eal_create_runtime_dir(void);
+
+/* returns runtime dir */
+const char *
+eal_get_runtime_dir(void);
+
 static inline const char *
 eal_runtime_config_path(void)
 {
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 21afa73..0e2672b 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -92,6 +92,66 @@ struct internal_config internal_config;
 /* used by rte_rdtsc() */
 int rte_cycles_vmware_tsc_map;
 
+/* platform-specific runtime dir */
+static char runtime_dir[PATH_MAX];
+
+int
+eal_create_runtime_dir(void)
+{
+	const char *directory = default_config_dir;
+	const char *xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
+	const char *fallback = "/tmp";
+	char tmp[PATH_MAX];
+	int ret;
+
+	if (getuid() != 0) {
+		/* try XDG path first, fall back to /tmp */
+		if (xdg_runtime_dir != NULL)
+			directory = xdg_runtime_dir;
+		else
+			directory = fallback;
+	}
+	/* create DPDK subdirectory under runtime dir */
+	ret = snprintf(tmp, sizeof(tmp), "%s/dpdk", directory);
+	if (ret < 0 || ret == sizeof(tmp)) {
+		RTE_LOG(ERR, EAL, "Error creating DPDK runtime path name\n");
+		return -1;
+	}
+
+	/* create prefix-specific subdirectory under DPDK runtime dir */
+	ret = snprintf(runtime_dir, sizeof(runtime_dir), "%s/%s",
+			tmp, internal_config.hugefile_prefix);
+	if (ret < 0 || ret == sizeof(runtime_dir)) {
+		RTE_LOG(ERR, EAL, "Error creating prefix-specific runtime path name\n");
+		return -1;
+	}
+
+	/* create the path if it doesn't exist. no "mkdir -p" here, so do it
+	 * step by step.
+	 */
+	ret = mkdir(tmp, 0600);
+	if (ret < 0 && errno != EEXIST) {
+		RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
+			tmp, strerror(errno));
+		return -1;
+	}
+
+	ret = mkdir(runtime_dir, 0600);
+	if (ret < 0 && errno != EEXIST) {
+		RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
+			runtime_dir, strerror(errno));
+		return -1;
+	}
+
+	return 0;
+}
+
+const char *
+eal_get_runtime_dir(void)
+{
+	return runtime_dir;
+}
+
 /* Return user provided mbuf pool ops name */
 const char * __rte_experimental
 rte_eal_mbuf_user_pool_ops(void)
@@ -743,6 +803,13 @@ rte_eal_init(int argc, char **argv)
 	/* set log level as early as possible */
 	eal_log_level_parse(argc, argv);
 
+	/* create runtime data directory */
+	if (eal_create_runtime_dir() < 0) {
+		rte_eal_init_alert("Cannot create runtime directory\n");
+		rte_errno = EACCES;
+		return -1;
+	}
+
 	if (rte_eal_cpu_init() < 0) {
 		rte_eal_init_alert("Cannot detect lcores.");
 		rte_errno = ENOTSUP;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [dpdk-dev] [PATCH 18.05-RC2 4/4] eal: move all runtime data into DPDK runtime dir
  2018-04-25 12:24 [dpdk-dev] [PATCH 18.05-RC2 0/4] Clean up EAL runtime data paths Anatoly Burakov
                   ` (2 preceding siblings ...)
  2018-04-25 12:24 ` [dpdk-dev] [PATCH 18.05-RC2 3/4] eal: add directory for DPDK runtime data Anatoly Burakov
@ 2018-04-25 12:24 ` Anatoly Burakov
  2018-04-30 12:08 ` [dpdk-dev] [PATCH v2 0/4] Clean up EAL runtime data paths Anatoly Burakov
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 23+ messages in thread
From: Anatoly Burakov @ 2018-04-25 12:24 UTC (permalink / raw)
  To: dev; +Cc: Bruce Richardson, thomas

Fix all calls to functions in eal_filesystem to produce paths
residing inside dedicated DPDK runtime directory.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 lib/librte_eal/bsdapp/eal/eal.c        |  2 +
 lib/librte_eal/common/eal_filesystem.h | 71 +++++++++-------------------------
 lib/librte_eal/linuxapp/eal/eal.c      |  2 +
 3 files changed, 22 insertions(+), 53 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index 400c273..e21c1ed 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -87,6 +87,8 @@ int rte_cycles_vmware_tsc_map;
 /* platform-specific runtime dir */
 static char runtime_dir[PATH_MAX];
 
+static const char *default_config_dir = "/var/run";
+
 int
 eal_create_runtime_dir(void)
 {
diff --git a/lib/librte_eal/common/eal_filesystem.h b/lib/librte_eal/common/eal_filesystem.h
index 22f9f21..c98102f 100644
--- a/lib/librte_eal/common/eal_filesystem.h
+++ b/lib/librte_eal/common/eal_filesystem.h
@@ -11,10 +11,6 @@
 #ifndef EAL_FILESYSTEM_H
 #define EAL_FILESYSTEM_H
 
-/** Path of rte config file. */
-#define RUNTIME_CONFIG_FMT "%s/.%s_config"
-#define FBARRAY_FMT "%s/%s_%s"
-
 #include <stdint.h>
 #include <limits.h>
 #include <unistd.h>
@@ -23,8 +19,6 @@
 #include <rte_string_fns.h>
 #include "eal_internal_cfg.h"
 
-static const char *default_config_dir = "/var/run";
-
 /* sets up platform-specific runtime data dir */
 int
 eal_create_runtime_dir(void);
@@ -33,80 +27,57 @@ eal_create_runtime_dir(void);
 const char *
 eal_get_runtime_dir(void);
 
+#define RUNTIME_CONFIG_FNAME "config"
 static inline const char *
 eal_runtime_config_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
-	const char *directory = default_config_dir;
-	const char *home_dir = getenv("HOME");
 
-	if (getuid() != 0 && home_dir != NULL)
-		directory = home_dir;
-	snprintf(buffer, sizeof(buffer) - 1, RUNTIME_CONFIG_FMT, directory,
-			internal_config.hugefile_prefix);
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+			RUNTIME_CONFIG_FNAME);
 	return buffer;
 }
 
 /** Path of primary/secondary communication unix socket file. */
-#define MP_SOCKET_PATH_FMT "%s/.%s_unix"
+#define MP_SOCKET_FNAME "mp_socket"
 static inline const char *
 eal_mp_socket_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
-	const char *directory = default_config_dir;
-	const char *home_dir = getenv("HOME");
-
-	if (getuid() != 0 && home_dir != NULL)
-		directory = home_dir;
-	snprintf(buffer, sizeof(buffer) - 1, MP_SOCKET_PATH_FMT,
-		 directory, internal_config.hugefile_prefix);
 
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+			MP_SOCKET_FNAME);
 	return buffer;
 }
 
+#define FBARRAY_NAME_FMT "%s/fbarray_%s"
 static inline const char *
 eal_get_fbarray_path(char *buffer, size_t buflen, const char *name) {
-	const char *directory = "/tmp";
-	const char *home_dir = getenv("HOME");
-
-	if (getuid() != 0 && home_dir != NULL)
-		directory = home_dir;
-	snprintf(buffer, buflen - 1, FBARRAY_FMT, directory,
-			internal_config.hugefile_prefix, name);
+	snprintf(buffer, buflen, FBARRAY_NAME_FMT, eal_get_runtime_dir(), name);
 	return buffer;
 }
 
 /** Path of hugepage info file. */
-#define HUGEPAGE_INFO_FMT "%s/.%s_hugepage_info"
-
+#define HUGEPAGE_INFO_FNAME "hugepage_info"
 static inline const char *
 eal_hugepage_info_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
-	const char *directory = default_config_dir;
-	const char *home_dir = getenv("HOME");
 
-	if (getuid() != 0 && home_dir != NULL)
-		directory = home_dir;
-	snprintf(buffer, sizeof(buffer) - 1, HUGEPAGE_INFO_FMT, directory,
-			internal_config.hugefile_prefix);
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+			HUGEPAGE_INFO_FNAME);
 	return buffer;
 }
 
-/** Path of hugepage info file. */
-#define HUGEPAGE_FILE_FMT "%s/.%s_hugepage_file"
-
+/** Path of hugepage data file. */
+#define HUGEPAGE_DATA_FNAME "hugepage_data"
 static inline const char *
 eal_hugepage_data_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
-	const char *directory = default_config_dir;
-	const char *home_dir = getenv("HOME");
 
-	if (getuid() != 0 && home_dir != NULL)
-		directory = home_dir;
-	snprintf(buffer, sizeof(buffer) - 1, HUGEPAGE_FILE_FMT, directory,
-			internal_config.hugefile_prefix);
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+			HUGEPAGE_DATA_FNAME);
 	return buffer;
 }
 
@@ -122,18 +93,12 @@ eal_get_hugefile_path(char *buffer, size_t buflen, const char *hugedir, int f_id
 }
 
 /** String format for hugepage map lock files. */
-#define HUGEFILE_LOCK_FMT "%s/.%smap_%d.lock"
-
+#define HUGEFILE_LOCK_FMT "%s/map_%d.lock"
 static inline const char *
 eal_get_hugefile_lock_path(char *buffer, size_t buflen, int f_id)
 {
-	const char *directory = default_config_dir;
-	const char *home_dir = getenv("HOME");
-
-	if (getuid() != 0 && home_dir != NULL)
-		directory = home_dir;
-	snprintf(buffer, buflen - 1, HUGEFILE_LOCK_FMT, directory,
-			internal_config.hugefile_prefix, f_id);
+	snprintf(buffer, buflen, HUGEFILE_LOCK_FMT, eal_get_runtime_dir(),
+			f_id);
 	buffer[buflen - 1] = '\0';
 	return buffer;
 }
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 0e2672b..072d34c 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -95,6 +95,8 @@ int rte_cycles_vmware_tsc_map;
 /* platform-specific runtime dir */
 static char runtime_dir[PATH_MAX];
 
+static const char *default_config_dir = "/var/run";
+
 int
 eal_create_runtime_dir(void)
 {
-- 
2.7.4

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [dpdk-dev] [PATCH 18.05-RC2 1/4] eal: remove unused define
  2018-04-25 12:24 ` [dpdk-dev] [PATCH 18.05-RC2 1/4] eal: remove unused define Anatoly Burakov
@ 2018-04-26  7:11   ` David Marchand
  0 siblings, 0 replies; 23+ messages in thread
From: David Marchand @ 2018-04-26  7:11 UTC (permalink / raw)
  To: Anatoly Burakov; +Cc: dev, Richardson, Bruce, Thomas Monjalon, stable

On Wed, Apr 25, 2018 at 2:24 PM, Anatoly Burakov
<anatoly.burakov@intel.com> wrote:
> The define was a leftover from IVSHMEM library.
>
> Fixes: c711ccb30987 ("ivshmem: remove library and its EAL integration")
> Cc: david.marchand@6wind.com
> Cc: stable@dpdk.org
>
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>

Indeed.
Reviewed-by: David Marchand <david.marchand@6wind.com>

However, not sure this really needs to go to stable.

-- 
David Marchand

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [dpdk-dev] [PATCH v2 0/4] Clean up EAL runtime data paths
  2018-04-25 12:24 [dpdk-dev] [PATCH 18.05-RC2 0/4] Clean up EAL runtime data paths Anatoly Burakov
                   ` (3 preceding siblings ...)
  2018-04-25 12:24 ` [dpdk-dev] [PATCH 18.05-RC2 4/4] eal: move all runtime data into DPDK runtime dir Anatoly Burakov
@ 2018-04-30 12:08 ` Anatoly Burakov
  2018-05-09 15:59   ` Van Haaren, Harry
                     ` (5 more replies)
  2018-04-30 12:08 ` [dpdk-dev] [PATCH v2 1/4] eal: remove unused define Anatoly Burakov
                   ` (3 subsequent siblings)
  8 siblings, 6 replies; 23+ messages in thread
From: Anatoly Burakov @ 2018-04-30 12:08 UTC (permalink / raw)
  To: dev; +Cc: bruce.richardson, thomas

As has been suggested [1], all DPDK runtime paths should be put
into a single place. This patchset accomplishes exactly that.

If running as root, all files will be put under /var/run/dpdk/<prefix>,
otherwise they will be put under $XDG_RUNTIME_PATH/dpdk/<prefix>, or, if
that environment variable is not defined, all files will go under
/tmp/dpdk/<prefix>.

[1] http://dpdk.org/dev/patchwork/patch/38688/

v2:
- Rebase on rc1

Anatoly Burakov (4):
  eal: remove unused define
  eal: rename function returning hugepage data path
  eal: add directory for DPDK runtime data
  eal: move all runtime data into DPDK runtime dir

 lib/librte_eal/bsdapp/eal/eal.c          | 70 +++++++++++++++++++++++++++
 lib/librte_eal/common/eal_filesystem.h   | 81 ++++++++++----------------------
 lib/librte_eal/linuxapp/eal/eal.c        | 69 +++++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_memory.c | 10 ++--
 4 files changed, 171 insertions(+), 59 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [dpdk-dev] [PATCH v2 1/4] eal: remove unused define
  2018-04-25 12:24 [dpdk-dev] [PATCH 18.05-RC2 0/4] Clean up EAL runtime data paths Anatoly Burakov
                   ` (4 preceding siblings ...)
  2018-04-30 12:08 ` [dpdk-dev] [PATCH v2 0/4] Clean up EAL runtime data paths Anatoly Burakov
@ 2018-04-30 12:08 ` Anatoly Burakov
  2018-04-30 12:08 ` [dpdk-dev] [PATCH v2 2/4] eal: rename function returning hugepage data path Anatoly Burakov
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 23+ messages in thread
From: Anatoly Burakov @ 2018-04-30 12:08 UTC (permalink / raw)
  To: dev; +Cc: bruce.richardson, thomas, david.marchand, stable

The define was a leftover from IVSHMEM library.

Fixes: c711ccb30987 ("ivshmem: remove library and its EAL integration")
Cc: david.marchand@6wind.com
Cc: stable@dpdk.org

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
Reviewed-by: David Marchand <david.marchand@6wind.com>
---
 lib/librte_eal/common/eal_filesystem.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/lib/librte_eal/common/eal_filesystem.h b/lib/librte_eal/common/eal_filesystem.h
index 4db5c10..078e2eb 100644
--- a/lib/librte_eal/common/eal_filesystem.h
+++ b/lib/librte_eal/common/eal_filesystem.h
@@ -104,8 +104,6 @@ eal_hugepage_file_path(void)
 
 /** String format for hugepage map files. */
 #define HUGEFILE_FMT "%s/%smap_%d"
-#define TEMP_HUGEFILE_FMT "%s/%smap_temp_%d"
-
 static inline const char *
 eal_get_hugefile_path(char *buffer, size_t buflen, const char *hugedir, int f_id)
 {
-- 
2.7.4

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [dpdk-dev] [PATCH v2 2/4] eal: rename function returning hugepage data path
  2018-04-25 12:24 [dpdk-dev] [PATCH 18.05-RC2 0/4] Clean up EAL runtime data paths Anatoly Burakov
                   ` (5 preceding siblings ...)
  2018-04-30 12:08 ` [dpdk-dev] [PATCH v2 1/4] eal: remove unused define Anatoly Burakov
@ 2018-04-30 12:08 ` Anatoly Burakov
  2018-05-10 13:14   ` Pattan, Reshma
  2018-04-30 12:08 ` [dpdk-dev] [PATCH v2 3/4] eal: add directory for DPDK runtime data Anatoly Burakov
  2018-04-30 12:08 ` [dpdk-dev] [PATCH v2 4/4] eal: move all runtime data into DPDK runtime dir Anatoly Burakov
  8 siblings, 1 reply; 23+ messages in thread
From: Anatoly Burakov @ 2018-04-30 12:08 UTC (permalink / raw)
  To: dev; +Cc: bruce.richardson, thomas

The original name for this path was not too descriptive and
confusing. Rename it to a more appropriate and descriptive name:
it stores data about hugepages, so name it eal_hugepage_data_path().

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 lib/librte_eal/common/eal_filesystem.h   |  2 +-
 lib/librte_eal/linuxapp/eal/eal_memory.c | 10 ++++++----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/lib/librte_eal/common/eal_filesystem.h b/lib/librte_eal/common/eal_filesystem.h
index 078e2eb..060ac2b 100644
--- a/lib/librte_eal/common/eal_filesystem.h
+++ b/lib/librte_eal/common/eal_filesystem.h
@@ -89,7 +89,7 @@ eal_hugepage_info_path(void)
 #define HUGEPAGE_FILE_FMT "%s/.%s_hugepage_file"
 
 static inline const char *
-eal_hugepage_file_path(void)
+eal_hugepage_data_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
 	const char *directory = default_config_dir;
diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
index e0baabb..c917de1 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -1499,7 +1499,7 @@ eal_legacy_hugepage_init(void)
 	}
 
 	/* create shared memory */
-	hugepage = create_shared_memory(eal_hugepage_file_path(),
+	hugepage = create_shared_memory(eal_hugepage_data_path(),
 			nr_hugefiles * sizeof(struct hugepage_file));
 
 	if (hugepage == NULL) {
@@ -1727,16 +1727,18 @@ eal_legacy_hugepage_attach(void)
 
 	test_phys_addrs_available();
 
-	fd_hugepage = open(eal_hugepage_file_path(), O_RDONLY);
+	fd_hugepage = open(eal_hugepage_data_path(), O_RDONLY);
 	if (fd_hugepage < 0) {
-		RTE_LOG(ERR, EAL, "Could not open %s\n", eal_hugepage_file_path());
+		RTE_LOG(ERR, EAL, "Could not open %s\n",
+				eal_hugepage_data_path());
 		goto error;
 	}
 
 	size = getFileSize(fd_hugepage);
 	hp = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd_hugepage, 0);
 	if (hp == MAP_FAILED) {
-		RTE_LOG(ERR, EAL, "Could not mmap %s\n", eal_hugepage_file_path());
+		RTE_LOG(ERR, EAL, "Could not mmap %s\n",
+				eal_hugepage_data_path());
 		goto error;
 	}
 
-- 
2.7.4

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [dpdk-dev] [PATCH v2 3/4] eal: add directory for DPDK runtime data
  2018-04-25 12:24 [dpdk-dev] [PATCH 18.05-RC2 0/4] Clean up EAL runtime data paths Anatoly Burakov
                   ` (6 preceding siblings ...)
  2018-04-30 12:08 ` [dpdk-dev] [PATCH v2 2/4] eal: rename function returning hugepage data path Anatoly Burakov
@ 2018-04-30 12:08 ` Anatoly Burakov
  2018-05-10 14:05   ` Pattan, Reshma
  2018-04-30 12:08 ` [dpdk-dev] [PATCH v2 4/4] eal: move all runtime data into DPDK runtime dir Anatoly Burakov
  8 siblings, 1 reply; 23+ messages in thread
From: Anatoly Burakov @ 2018-04-30 12:08 UTC (permalink / raw)
  To: dev; +Cc: Bruce Richardson, thomas

Currently, during runtime, DPDK will store a bunch of files here
and there (in /var/run, /tmp or in $HOME). Fix it by creating a
DPDK-specific runtime directory, under which all runtime data
will be placed. The template for creating this runtime directory
is the following:

  <base path>/dpdk/<DPDK prefix>/

Where <base path> is set to either "/var/run" if run as root, or
$XDG_RUNTIME_DIR if run as non-root, with a fallback to /tmp if
$XDG_RUNTIME_DIR is not defined. So, for example, if run as root,
by default all runtime data will be stored at /var/run/dpdk/rte/.

There is no equivalent of "mkdir -p", so we will be creating the
path step by step.

Nothing uses this new path yet, changes for that will come in
next commit.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 lib/librte_eal/bsdapp/eal/eal.c        | 68 ++++++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_filesystem.h |  8 ++++
 lib/librte_eal/linuxapp/eal/eal.c      | 67 +++++++++++++++++++++++++++++++++
 3 files changed, 143 insertions(+)

diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index a63f11f..256ab2d 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -18,6 +18,7 @@
 #include <limits.h>
 #include <sys/mman.h>
 #include <sys/queue.h>
+#include <sys/stat.h>
 
 #include <rte_compat.h>
 #include <rte_common.h>
@@ -83,6 +84,66 @@ struct internal_config internal_config;
 /* used by rte_rdtsc() */
 int rte_cycles_vmware_tsc_map;
 
+/* platform-specific runtime dir */
+static char runtime_dir[PATH_MAX];
+
+int
+eal_create_runtime_dir(void)
+{
+	const char *directory = default_config_dir;
+	const char *xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
+	const char *fallback = "/tmp";
+	char tmp[PATH_MAX];
+	int ret;
+
+	if (getuid() != 0) {
+		/* try XDG path first, fall back to /tmp */
+		if (xdg_runtime_dir != NULL)
+			directory = xdg_runtime_dir;
+		else
+			directory = fallback;
+	}
+	/* create DPDK subdirectory under runtime dir */
+	ret = snprintf(tmp, sizeof(tmp), "%s/dpdk", directory);
+	if (ret < 0 || ret == sizeof(tmp)) {
+		RTE_LOG(ERR, EAL, "Error creating DPDK runtime path name\n");
+		return -1;
+	}
+
+	/* create prefix-specific subdirectory under DPDK runtime dir */
+	ret = snprintf(runtime_dir, sizeof(runtime_dir), "%s/%s",
+			tmp, internal_config.hugefile_prefix);
+	if (ret < 0 || ret == sizeof(runtime_dir)) {
+		RTE_LOG(ERR, EAL, "Error creating prefix-specific runtime path name\n");
+		return -1;
+	}
+
+	/* create the path if it doesn't exist. no "mkdir -p" here, so do it
+	 * step by step.
+	 */
+	ret = mkdir(tmp, 0600);
+	if (ret < 0 && errno != EEXIST) {
+		RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
+			tmp, strerror(errno));
+		return -1;
+	}
+
+	ret = mkdir(runtime_dir, 0600);
+	if (ret < 0 && errno != EEXIST) {
+		RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
+			runtime_dir, strerror(errno));
+		return -1;
+	}
+
+	return 0;
+}
+
+const char *
+eal_get_runtime_dir(void)
+{
+	return runtime_dir;
+}
+
 /* Return user provided mbuf pool ops name */
 const char * __rte_experimental
 rte_eal_mbuf_user_pool_ops(void)
@@ -522,6 +583,13 @@ rte_eal_init(int argc, char **argv)
 	/* set log level as early as possible */
 	eal_log_level_parse(argc, argv);
 
+	/* create runtime data directory */
+	if (eal_create_runtime_dir() < 0) {
+		rte_eal_init_alert("Cannot create runtime directory\n");
+		rte_errno = EACCES;
+		return -1;
+	}
+
 	if (rte_eal_cpu_init() < 0) {
 		rte_eal_init_alert("Cannot detect lcores.");
 		rte_errno = ENOTSUP;
diff --git a/lib/librte_eal/common/eal_filesystem.h b/lib/librte_eal/common/eal_filesystem.h
index 060ac2b..67f5ca8 100644
--- a/lib/librte_eal/common/eal_filesystem.h
+++ b/lib/librte_eal/common/eal_filesystem.h
@@ -25,6 +25,14 @@
 
 static const char *default_config_dir = "/var/run";
 
+/* sets up platform-specific runtime data dir */
+int
+eal_create_runtime_dir(void);
+
+/* returns runtime dir */
+const char *
+eal_get_runtime_dir(void);
+
 static inline const char *
 eal_runtime_config_path(void)
 {
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index e2c0bd6..053b7e7 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -92,6 +92,66 @@ struct internal_config internal_config;
 /* used by rte_rdtsc() */
 int rte_cycles_vmware_tsc_map;
 
+/* platform-specific runtime dir */
+static char runtime_dir[PATH_MAX];
+
+int
+eal_create_runtime_dir(void)
+{
+	const char *directory = default_config_dir;
+	const char *xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
+	const char *fallback = "/tmp";
+	char tmp[PATH_MAX];
+	int ret;
+
+	if (getuid() != 0) {
+		/* try XDG path first, fall back to /tmp */
+		if (xdg_runtime_dir != NULL)
+			directory = xdg_runtime_dir;
+		else
+			directory = fallback;
+	}
+	/* create DPDK subdirectory under runtime dir */
+	ret = snprintf(tmp, sizeof(tmp), "%s/dpdk", directory);
+	if (ret < 0 || ret == sizeof(tmp)) {
+		RTE_LOG(ERR, EAL, "Error creating DPDK runtime path name\n");
+		return -1;
+	}
+
+	/* create prefix-specific subdirectory under DPDK runtime dir */
+	ret = snprintf(runtime_dir, sizeof(runtime_dir), "%s/%s",
+			tmp, internal_config.hugefile_prefix);
+	if (ret < 0 || ret == sizeof(runtime_dir)) {
+		RTE_LOG(ERR, EAL, "Error creating prefix-specific runtime path name\n");
+		return -1;
+	}
+
+	/* create the path if it doesn't exist. no "mkdir -p" here, so do it
+	 * step by step.
+	 */
+	ret = mkdir(tmp, 0600);
+	if (ret < 0 && errno != EEXIST) {
+		RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
+			tmp, strerror(errno));
+		return -1;
+	}
+
+	ret = mkdir(runtime_dir, 0600);
+	if (ret < 0 && errno != EEXIST) {
+		RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
+			runtime_dir, strerror(errno));
+		return -1;
+	}
+
+	return 0;
+}
+
+const char *
+eal_get_runtime_dir(void)
+{
+	return runtime_dir;
+}
+
 /* Return user provided mbuf pool ops name */
 const char * __rte_experimental
 rte_eal_mbuf_user_pool_ops(void)
@@ -740,6 +800,13 @@ rte_eal_init(int argc, char **argv)
 	/* set log level as early as possible */
 	eal_log_level_parse(argc, argv);
 
+	/* create runtime data directory */
+	if (eal_create_runtime_dir() < 0) {
+		rte_eal_init_alert("Cannot create runtime directory\n");
+		rte_errno = EACCES;
+		return -1;
+	}
+
 	if (rte_eal_cpu_init() < 0) {
 		rte_eal_init_alert("Cannot detect lcores.");
 		rte_errno = ENOTSUP;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [dpdk-dev] [PATCH v2 4/4] eal: move all runtime data into DPDK runtime dir
  2018-04-25 12:24 [dpdk-dev] [PATCH 18.05-RC2 0/4] Clean up EAL runtime data paths Anatoly Burakov
                   ` (7 preceding siblings ...)
  2018-04-30 12:08 ` [dpdk-dev] [PATCH v2 3/4] eal: add directory for DPDK runtime data Anatoly Burakov
@ 2018-04-30 12:08 ` Anatoly Burakov
  8 siblings, 0 replies; 23+ messages in thread
From: Anatoly Burakov @ 2018-04-30 12:08 UTC (permalink / raw)
  To: dev; +Cc: Bruce Richardson, thomas

Fix all calls to functions in eal_filesystem to produce paths
residing inside dedicated DPDK runtime directory.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 lib/librte_eal/bsdapp/eal/eal.c        |  2 +
 lib/librte_eal/common/eal_filesystem.h | 71 +++++++++-------------------------
 lib/librte_eal/linuxapp/eal/eal.c      |  2 +
 3 files changed, 22 insertions(+), 53 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index 256ab2d..ebda2ef 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -87,6 +87,8 @@ int rte_cycles_vmware_tsc_map;
 /* platform-specific runtime dir */
 static char runtime_dir[PATH_MAX];
 
+static const char *default_config_dir = "/var/run";
+
 int
 eal_create_runtime_dir(void)
 {
diff --git a/lib/librte_eal/common/eal_filesystem.h b/lib/librte_eal/common/eal_filesystem.h
index 67f5ca8..c98102f 100644
--- a/lib/librte_eal/common/eal_filesystem.h
+++ b/lib/librte_eal/common/eal_filesystem.h
@@ -11,10 +11,6 @@
 #ifndef EAL_FILESYSTEM_H
 #define EAL_FILESYSTEM_H
 
-/** Path of rte config file. */
-#define RUNTIME_CONFIG_FMT "%s/.%s_config"
-#define FBARRAY_FMT "%s/.%s_%s"
-
 #include <stdint.h>
 #include <limits.h>
 #include <unistd.h>
@@ -23,8 +19,6 @@
 #include <rte_string_fns.h>
 #include "eal_internal_cfg.h"
 
-static const char *default_config_dir = "/var/run";
-
 /* sets up platform-specific runtime data dir */
 int
 eal_create_runtime_dir(void);
@@ -33,80 +27,57 @@ eal_create_runtime_dir(void);
 const char *
 eal_get_runtime_dir(void);
 
+#define RUNTIME_CONFIG_FNAME "config"
 static inline const char *
 eal_runtime_config_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
-	const char *directory = default_config_dir;
-	const char *home_dir = getenv("HOME");
 
-	if (getuid() != 0 && home_dir != NULL)
-		directory = home_dir;
-	snprintf(buffer, sizeof(buffer) - 1, RUNTIME_CONFIG_FMT, directory,
-			internal_config.hugefile_prefix);
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+			RUNTIME_CONFIG_FNAME);
 	return buffer;
 }
 
 /** Path of primary/secondary communication unix socket file. */
-#define MP_SOCKET_PATH_FMT "%s/.%s_unix"
+#define MP_SOCKET_FNAME "mp_socket"
 static inline const char *
 eal_mp_socket_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
-	const char *directory = default_config_dir;
-	const char *home_dir = getenv("HOME");
-
-	if (getuid() != 0 && home_dir != NULL)
-		directory = home_dir;
-	snprintf(buffer, sizeof(buffer) - 1, MP_SOCKET_PATH_FMT,
-		 directory, internal_config.hugefile_prefix);
 
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+			MP_SOCKET_FNAME);
 	return buffer;
 }
 
+#define FBARRAY_NAME_FMT "%s/fbarray_%s"
 static inline const char *
 eal_get_fbarray_path(char *buffer, size_t buflen, const char *name) {
-	const char *directory = "/tmp";
-	const char *home_dir = getenv("HOME");
-
-	if (getuid() != 0 && home_dir != NULL)
-		directory = home_dir;
-	snprintf(buffer, buflen - 1, FBARRAY_FMT, directory,
-			internal_config.hugefile_prefix, name);
+	snprintf(buffer, buflen, FBARRAY_NAME_FMT, eal_get_runtime_dir(), name);
 	return buffer;
 }
 
 /** Path of hugepage info file. */
-#define HUGEPAGE_INFO_FMT "%s/.%s_hugepage_info"
-
+#define HUGEPAGE_INFO_FNAME "hugepage_info"
 static inline const char *
 eal_hugepage_info_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
-	const char *directory = default_config_dir;
-	const char *home_dir = getenv("HOME");
 
-	if (getuid() != 0 && home_dir != NULL)
-		directory = home_dir;
-	snprintf(buffer, sizeof(buffer) - 1, HUGEPAGE_INFO_FMT, directory,
-			internal_config.hugefile_prefix);
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+			HUGEPAGE_INFO_FNAME);
 	return buffer;
 }
 
-/** Path of hugepage info file. */
-#define HUGEPAGE_FILE_FMT "%s/.%s_hugepage_file"
-
+/** Path of hugepage data file. */
+#define HUGEPAGE_DATA_FNAME "hugepage_data"
 static inline const char *
 eal_hugepage_data_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
-	const char *directory = default_config_dir;
-	const char *home_dir = getenv("HOME");
 
-	if (getuid() != 0 && home_dir != NULL)
-		directory = home_dir;
-	snprintf(buffer, sizeof(buffer) - 1, HUGEPAGE_FILE_FMT, directory,
-			internal_config.hugefile_prefix);
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+			HUGEPAGE_DATA_FNAME);
 	return buffer;
 }
 
@@ -122,18 +93,12 @@ eal_get_hugefile_path(char *buffer, size_t buflen, const char *hugedir, int f_id
 }
 
 /** String format for hugepage map lock files. */
-#define HUGEFILE_LOCK_FMT "%s/.%smap_%d.lock"
-
+#define HUGEFILE_LOCK_FMT "%s/map_%d.lock"
 static inline const char *
 eal_get_hugefile_lock_path(char *buffer, size_t buflen, int f_id)
 {
-	const char *directory = default_config_dir;
-	const char *home_dir = getenv("HOME");
-
-	if (getuid() != 0 && home_dir != NULL)
-		directory = home_dir;
-	snprintf(buffer, buflen - 1, HUGEFILE_LOCK_FMT, directory,
-			internal_config.hugefile_prefix, f_id);
+	snprintf(buffer, buflen, HUGEFILE_LOCK_FMT, eal_get_runtime_dir(),
+			f_id);
 	buffer[buflen - 1] = '\0';
 	return buffer;
 }
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 053b7e7..4ccb523 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -95,6 +95,8 @@ int rte_cycles_vmware_tsc_map;
 /* platform-specific runtime dir */
 static char runtime_dir[PATH_MAX];
 
+static const char *default_config_dir = "/var/run";
+
 int
 eal_create_runtime_dir(void)
 {
-- 
2.7.4

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [dpdk-dev] [PATCH v2 0/4] Clean up EAL runtime data paths
  2018-04-30 12:08 ` [dpdk-dev] [PATCH v2 0/4] Clean up EAL runtime data paths Anatoly Burakov
@ 2018-05-09 15:59   ` Van Haaren, Harry
  2018-05-09 16:11     ` Bruce Richardson
  2018-05-14 16:27   ` [dpdk-dev] [PATCH v3 " Anatoly Burakov
                     ` (4 subsequent siblings)
  5 siblings, 1 reply; 23+ messages in thread
From: Van Haaren, Harry @ 2018-05-09 15:59 UTC (permalink / raw)
  To: Burakov, Anatoly, dev; +Cc: Richardson, Bruce, thomas

> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Anatoly Burakov
> Sent: Monday, April 30, 2018 1:09 PM
> To: dev@dpdk.org
> Cc: Richardson, Bruce <bruce.richardson@intel.com>; thomas@monjalon.net
> Subject: [dpdk-dev] [PATCH v2 0/4] Clean up EAL runtime data paths
> 
> As has been suggested [1], all DPDK runtime paths should be put
> into a single place. This patchset accomplishes exactly that.
> 
> If running as root, all files will be put under /var/run/dpdk/<prefix>,
> otherwise they will be put under $XDG_RUNTIME_PATH/dpdk/<prefix>, or, if
> that environment variable is not defined, all files will go under
> /tmp/dpdk/<prefix>.
> 
> [1] http://dpdk.org/dev/patchwork/patch/38688/
> 
> v2:
> - Rebase on rc1
> 
> Anatoly Burakov (4):
>   eal: remove unused define
>   eal: rename function returning hugepage data path
>   eal: add directory for DPDK runtime data
>   eal: move all runtime data into DPDK runtime dir

<snip>


No full code review, high level comments:

We have to be careful in changing /var/run/.rte_config, which has always been
the default DPDK primary application lockfile. This has been used to identify
if a primary DPDK application is alive (see rte_eal_primary_proc_alive()) and
possibly the write-lock on this file is checked by other tools/utilities directly
without any DPDK function call.

Changing the filepath just before a release isn't a good idea - we should treat
this as an ABI/API break, as the change will break functionality in other projects
such as CollectD[1], which (by default ;) rely on the defaults. There is a config
file for CollectD to manually override the location, but this will cause headaches
from a usability POV.

I'm not opposed to the change - particularly as I gather the new memory subsystem
causes a number of lockfiles to be created - but we must do our due diligence and
give other projects fair-warning that this change is coming.

As such, I recommend this patchset in its current form (particularly patches 2,3,4)
to be deferred past 18.05.


-Harry


[1] https://github.com/collectd/collectd/blob/master/src/utils_dpdk.c#L46

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [dpdk-dev] [PATCH v2 0/4] Clean up EAL runtime data paths
  2018-05-09 15:59   ` Van Haaren, Harry
@ 2018-05-09 16:11     ` Bruce Richardson
  2018-05-09 19:03       ` Thomas Monjalon
  0 siblings, 1 reply; 23+ messages in thread
From: Bruce Richardson @ 2018-05-09 16:11 UTC (permalink / raw)
  To: Van Haaren, Harry; +Cc: Burakov, Anatoly, dev, thomas

On Wed, May 09, 2018 at 04:59:39PM +0100, Van Haaren, Harry wrote:
> > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Anatoly Burakov
> > Sent: Monday, April 30, 2018 1:09 PM
> > To: dev@dpdk.org
> > Cc: Richardson, Bruce <bruce.richardson@intel.com>; thomas@monjalon.net
> > Subject: [dpdk-dev] [PATCH v2 0/4] Clean up EAL runtime data paths
> > 
> > As has been suggested [1], all DPDK runtime paths should be put
> > into a single place. This patchset accomplishes exactly that.
> > 
> > If running as root, all files will be put under /var/run/dpdk/<prefix>,
> > otherwise they will be put under $XDG_RUNTIME_PATH/dpdk/<prefix>, or, if
> > that environment variable is not defined, all files will go under
> > /tmp/dpdk/<prefix>.
> > 
> > [1] http://dpdk.org/dev/patchwork/patch/38688/
> > 
> > v2:
> > - Rebase on rc1
> > 
> > Anatoly Burakov (4):
> >   eal: remove unused define
> >   eal: rename function returning hugepage data path
> >   eal: add directory for DPDK runtime data
> >   eal: move all runtime data into DPDK runtime dir
> 
> <snip>
> 
> 
> No full code review, high level comments:
> 
> We have to be careful in changing /var/run/.rte_config, which has always been
> the default DPDK primary application lockfile. This has been used to identify
> if a primary DPDK application is alive (see rte_eal_primary_proc_alive()) and
> possibly the write-lock on this file is checked by other tools/utilities directly
> without any DPDK function call.
> 
> Changing the filepath just before a release isn't a good idea - we should treat
> this as an ABI/API break, as the change will break functionality in other projects
> such as CollectD[1], which (by default ;) rely on the defaults. There is a config
> file for CollectD to manually override the location, but this will cause headaches
> from a usability POV.
> 
> I'm not opposed to the change - particularly as I gather the new memory subsystem
> causes a number of lockfiles to be created - but we must do our due diligence and
> give other projects fair-warning that this change is coming.
> 
> As such, I recommend this patchset in its current form (particularly patches 2,3,4)
> to be deferred past 18.05.
> 
> 
What about if we keep the .rte_config file in the same place but move the
rest? The number of new files causes quite a bit of clutter. We can then
have a deprecation notice for the move in 18.05 and finish the cleanup in
18.08.

/Bruce

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [dpdk-dev] [PATCH v2 0/4] Clean up EAL runtime data paths
  2018-05-09 16:11     ` Bruce Richardson
@ 2018-05-09 19:03       ` Thomas Monjalon
  2018-05-14  8:26         ` Burakov, Anatoly
  0 siblings, 1 reply; 23+ messages in thread
From: Thomas Monjalon @ 2018-05-09 19:03 UTC (permalink / raw)
  To: Bruce Richardson, Van Haaren, Harry, Burakov, Anatoly; +Cc: dev

09/05/2018 18:11, Bruce Richardson:
> On Wed, May 09, 2018 at 04:59:39PM +0100, Van Haaren, Harry wrote:
> > > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Anatoly Burakov
> > > Sent: Monday, April 30, 2018 1:09 PM
> > > To: dev@dpdk.org
> > > Cc: Richardson, Bruce <bruce.richardson@intel.com>; thomas@monjalon.net
> > > Subject: [dpdk-dev] [PATCH v2 0/4] Clean up EAL runtime data paths
> > > 
> > > As has been suggested [1], all DPDK runtime paths should be put
> > > into a single place. This patchset accomplishes exactly that.
> > > 
> > > If running as root, all files will be put under /var/run/dpdk/<prefix>,
> > > otherwise they will be put under $XDG_RUNTIME_PATH/dpdk/<prefix>, or, if
> > > that environment variable is not defined, all files will go under
> > > /tmp/dpdk/<prefix>.
> > > 
> > > [1] http://dpdk.org/dev/patchwork/patch/38688/
> > > 
> > > v2:
> > > - Rebase on rc1
> > > 
> > > Anatoly Burakov (4):
> > >   eal: remove unused define
> > >   eal: rename function returning hugepage data path
> > >   eal: add directory for DPDK runtime data
> > >   eal: move all runtime data into DPDK runtime dir
> > 
> > <snip>
> > 
> > 
> > No full code review, high level comments:
> > 
> > We have to be careful in changing /var/run/.rte_config, which has always been
> > the default DPDK primary application lockfile. This has been used to identify
> > if a primary DPDK application is alive (see rte_eal_primary_proc_alive()) and
> > possibly the write-lock on this file is checked by other tools/utilities directly
> > without any DPDK function call.
> > 
> > Changing the filepath just before a release isn't a good idea - we should treat
> > this as an ABI/API break, as the change will break functionality in other projects
> > such as CollectD[1], which (by default ;) rely on the defaults. There is a config
> > file for CollectD to manually override the location, but this will cause headaches
> > from a usability POV.
> > 
> > I'm not opposed to the change - particularly as I gather the new memory subsystem
> > causes a number of lockfiles to be created - but we must do our due diligence and
> > give other projects fair-warning that this change is coming.
> > 
> > As such, I recommend this patchset in its current form (particularly patches 2,3,4)
> > to be deferred past 18.05.
> > 
> > 
> What about if we keep the .rte_config file in the same place but move the
> rest? The number of new files causes quite a bit of clutter. We can then
> have a deprecation notice for the move in 18.05 and finish the cleanup in
> 18.08.

I agree

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [dpdk-dev] [PATCH v2 2/4] eal: rename function returning hugepage data path
  2018-04-30 12:08 ` [dpdk-dev] [PATCH v2 2/4] eal: rename function returning hugepage data path Anatoly Burakov
@ 2018-05-10 13:14   ` Pattan, Reshma
  0 siblings, 0 replies; 23+ messages in thread
From: Pattan, Reshma @ 2018-05-10 13:14 UTC (permalink / raw)
  To: Burakov, Anatoly, dev; +Cc: Richardson, Bruce, thomas



> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Anatoly Burakov
> Sent: Monday, April 30, 2018 1:09 PM
> To: dev@dpdk.org
> Cc: Richardson, Bruce <bruce.richardson@intel.com>; thomas@monjalon.net
> Subject: [dpdk-dev] [PATCH v2 2/4] eal: rename function returning hugepage
> data path
> 
> The original name for this path was not too descriptive and confusing.
> Rename it to a more appropriate and descriptive name:
> it stores data about hugepages, so name it eal_hugepage_data_path().
> 
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>

data_path sounds like packet processing data path.  eal_hugepage_data_file?. 
I am ok anyway :-).
Reviewed-by: Reshma Pattan <reshma.pattan@intel.com>

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [dpdk-dev] [PATCH v2 3/4] eal: add directory for DPDK runtime data
  2018-04-30 12:08 ` [dpdk-dev] [PATCH v2 3/4] eal: add directory for DPDK runtime data Anatoly Burakov
@ 2018-05-10 14:05   ` Pattan, Reshma
  0 siblings, 0 replies; 23+ messages in thread
From: Pattan, Reshma @ 2018-05-10 14:05 UTC (permalink / raw)
  To: Burakov, Anatoly, dev; +Cc: Richardson, Bruce, thomas

Hi,

> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Anatoly Burakov
> Sent: Monday, April 30, 2018 1:09 PM
> To: dev@dpdk.org
> Cc: Richardson, Bruce <bruce.richardson@intel.com>; thomas@monjalon.net
> Subject: [dpdk-dev] [PATCH v2 3/4] eal: add directory for DPDK runtime data
> 
> Currently, during runtime, DPDK will store a bunch of files here and there (in
> /var/run, /tmp or in $HOME). Fix it by creating a DPDK-specific runtime
> directory, under which all runtime data will be placed. The template for
> creating this runtime directory is the following:
> 
>   <base path>/dpdk/<DPDK prefix>/
> 
> Where <base path> is set to either "/var/run" if run as root, or
> $XDG_RUNTIME_DIR if run as non-root, with a fallback to /tmp if
> $XDG_RUNTIME_DIR is not defined. So, for example, if run as root, by default
> all runtime data will be stored at /var/run/dpdk/rte/.
> 
> There is no equivalent of "mkdir -p", so we will be creating the path step by
> step.
> 
> Nothing uses this new path yet, changes for that will come in next commit.
> 
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
> ---
>  lib/librte_eal/bsdapp/eal/eal.c        | 68
> ++++++++++++++++++++++++++++++++++
>  lib/librte_eal/common/eal_filesystem.h |  8 ++++
>  lib/librte_eal/linuxapp/eal/eal.c      | 67
> +++++++++++++++++++++++++++++++++
>  3 files changed, 143 insertions(+)
> 

Looks good to me.
Reviewed-by: Reshma Pattan <reshma.pattan@intel.cm>

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [dpdk-dev] [PATCH v2 0/4] Clean up EAL runtime data paths
  2018-05-09 19:03       ` Thomas Monjalon
@ 2018-05-14  8:26         ` Burakov, Anatoly
  0 siblings, 0 replies; 23+ messages in thread
From: Burakov, Anatoly @ 2018-05-14  8:26 UTC (permalink / raw)
  To: Thomas Monjalon, Bruce Richardson, Van Haaren, Harry; +Cc: dev

On 09-May-18 8:03 PM, Thomas Monjalon wrote:
> 09/05/2018 18:11, Bruce Richardson:
>> On Wed, May 09, 2018 at 04:59:39PM +0100, Van Haaren, Harry wrote:
>>>> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Anatoly Burakov
>>>> Sent: Monday, April 30, 2018 1:09 PM
>>>> To: dev@dpdk.org
>>>> Cc: Richardson, Bruce <bruce.richardson@intel.com>; thomas@monjalon.net
>>>> Subject: [dpdk-dev] [PATCH v2 0/4] Clean up EAL runtime data paths
>>>>
>>>> As has been suggested [1], all DPDK runtime paths should be put
>>>> into a single place. This patchset accomplishes exactly that.
>>>>
>>>> If running as root, all files will be put under /var/run/dpdk/<prefix>,
>>>> otherwise they will be put under $XDG_RUNTIME_PATH/dpdk/<prefix>, or, if
>>>> that environment variable is not defined, all files will go under
>>>> /tmp/dpdk/<prefix>.
>>>>
>>>> [1] http://dpdk.org/dev/patchwork/patch/38688/
>>>>
>>>> v2:
>>>> - Rebase on rc1
>>>>
>>>> Anatoly Burakov (4):
>>>>    eal: remove unused define
>>>>    eal: rename function returning hugepage data path
>>>>    eal: add directory for DPDK runtime data
>>>>    eal: move all runtime data into DPDK runtime dir
>>>
>>> <snip>
>>>
>>>
>>> No full code review, high level comments:
>>>
>>> We have to be careful in changing /var/run/.rte_config, which has always been
>>> the default DPDK primary application lockfile. This has been used to identify
>>> if a primary DPDK application is alive (see rte_eal_primary_proc_alive()) and
>>> possibly the write-lock on this file is checked by other tools/utilities directly
>>> without any DPDK function call.
>>>
>>> Changing the filepath just before a release isn't a good idea - we should treat
>>> this as an ABI/API break, as the change will break functionality in other projects
>>> such as CollectD[1], which (by default ;) rely on the defaults. There is a config
>>> file for CollectD to manually override the location, but this will cause headaches
>>> from a usability POV.
>>>
>>> I'm not opposed to the change - particularly as I gather the new memory subsystem
>>> causes a number of lockfiles to be created - but we must do our due diligence and
>>> give other projects fair-warning that this change is coming.
>>>
>>> As such, I recommend this patchset in its current form (particularly patches 2,3,4)
>>> to be deferred past 18.05.
>>>
>>>
>> What about if we keep the .rte_config file in the same place but move the
>> rest? The number of new files causes quite a bit of clutter. We can then
>> have a deprecation notice for the move in 18.05 and finish the cleanup in
>> 18.08.
> 
> I agree
> 

Thanks for catching this, Harry. I'll resubmit the patches then, along 
with a deprecation notice about /var/run/.<prefix>_config.

-- 
Thanks,
Anatoly

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [dpdk-dev] [PATCH v3 0/4] Clean up EAL runtime data paths
  2018-04-30 12:08 ` [dpdk-dev] [PATCH v2 0/4] Clean up EAL runtime data paths Anatoly Burakov
  2018-05-09 15:59   ` Van Haaren, Harry
@ 2018-05-14 16:27   ` Anatoly Burakov
  2018-05-14 22:45     ` Thomas Monjalon
  2018-05-14 16:27   ` [dpdk-dev] [PATCH v3 1/4] eal: remove unused define Anatoly Burakov
                     ` (3 subsequent siblings)
  5 siblings, 1 reply; 23+ messages in thread
From: Anatoly Burakov @ 2018-05-14 16:27 UTC (permalink / raw)
  To: dev; +Cc: thomas, bruce.richardson

As has been suggested [1], all DPDK runtime paths should be put
into a single place. This patchset accomplishes exactly that.

If running as root, all files will be put under /var/run/dpdk/<prefix>,
otherwise they will be put under $XDG_RUNTIME_PATH/dpdk/<prefix>, or, if
that environment variable is not defined, all files will go under
/tmp/dpdk/<prefix>.

[1] http://dpdk.org/dev/patchwork/patch/38688/

v3:
- Rebase on rc2
- Leave rte_config path in place, to be fixed for next release

v2:
- Rebase on rc1

Anatoly Burakov (4):
  eal: remove unused define
  eal: rename function returning hugepage data path
  eal: add directory for DPDK runtime data
  eal: move all runtime data into DPDK runtime dir

 lib/librte_eal/bsdapp/eal/eal.c          | 70 +++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_filesystem.h   | 71 +++++++++++---------------------
 lib/librte_eal/linuxapp/eal/eal.c        | 69 +++++++++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_memory.c | 10 +++--
 4 files changed, 169 insertions(+), 51 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [dpdk-dev] [PATCH v3 1/4] eal: remove unused define
  2018-04-30 12:08 ` [dpdk-dev] [PATCH v2 0/4] Clean up EAL runtime data paths Anatoly Burakov
  2018-05-09 15:59   ` Van Haaren, Harry
  2018-05-14 16:27   ` [dpdk-dev] [PATCH v3 " Anatoly Burakov
@ 2018-05-14 16:27   ` Anatoly Burakov
  2018-05-14 16:27   ` [dpdk-dev] [PATCH v3 2/4] eal: rename function returning hugepage data path Anatoly Burakov
                     ` (2 subsequent siblings)
  5 siblings, 0 replies; 23+ messages in thread
From: Anatoly Burakov @ 2018-05-14 16:27 UTC (permalink / raw)
  To: dev; +Cc: thomas, bruce.richardson, david.marchand, stable

The define was a leftover from IVSHMEM library.

Fixes: c711ccb30987 ("ivshmem: remove library and its EAL integration")
Cc: david.marchand@6wind.com
Cc: stable@dpdk.org

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
Reviewed-by: David Marchand <david.marchand@6wind.com>
---
 lib/librte_eal/common/eal_filesystem.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/lib/librte_eal/common/eal_filesystem.h b/lib/librte_eal/common/eal_filesystem.h
index 4db5c10..078e2eb 100644
--- a/lib/librte_eal/common/eal_filesystem.h
+++ b/lib/librte_eal/common/eal_filesystem.h
@@ -104,8 +104,6 @@ eal_hugepage_file_path(void)
 
 /** String format for hugepage map files. */
 #define HUGEFILE_FMT "%s/%smap_%d"
-#define TEMP_HUGEFILE_FMT "%s/%smap_temp_%d"
-
 static inline const char *
 eal_get_hugefile_path(char *buffer, size_t buflen, const char *hugedir, int f_id)
 {
-- 
2.7.4

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [dpdk-dev] [PATCH v3 2/4] eal: rename function returning hugepage data path
  2018-04-30 12:08 ` [dpdk-dev] [PATCH v2 0/4] Clean up EAL runtime data paths Anatoly Burakov
                     ` (2 preceding siblings ...)
  2018-05-14 16:27   ` [dpdk-dev] [PATCH v3 1/4] eal: remove unused define Anatoly Burakov
@ 2018-05-14 16:27   ` Anatoly Burakov
  2018-05-14 16:27   ` [dpdk-dev] [PATCH v3 3/4] eal: add directory for DPDK runtime data Anatoly Burakov
  2018-05-14 16:27   ` [dpdk-dev] [PATCH v3 4/4] eal: move all runtime data into DPDK runtime dir Anatoly Burakov
  5 siblings, 0 replies; 23+ messages in thread
From: Anatoly Burakov @ 2018-05-14 16:27 UTC (permalink / raw)
  To: dev; +Cc: thomas, bruce.richardson

The original name for this path was not too descriptive and
confusing. Rename it to a more appropriate and descriptive name:
it stores data about hugepages, so name it eal_hugepage_data_path().

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
Reviewed-by: Reshma Pattan <reshma.pattan@intel.com>
---
 lib/librte_eal/common/eal_filesystem.h   |  2 +-
 lib/librte_eal/linuxapp/eal/eal_memory.c | 10 ++++++----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/lib/librte_eal/common/eal_filesystem.h b/lib/librte_eal/common/eal_filesystem.h
index 078e2eb..060ac2b 100644
--- a/lib/librte_eal/common/eal_filesystem.h
+++ b/lib/librte_eal/common/eal_filesystem.h
@@ -89,7 +89,7 @@ eal_hugepage_info_path(void)
 #define HUGEPAGE_FILE_FMT "%s/.%s_hugepage_file"
 
 static inline const char *
-eal_hugepage_file_path(void)
+eal_hugepage_data_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
 	const char *directory = default_config_dir;
diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
index e0baabb..c917de1 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -1499,7 +1499,7 @@ eal_legacy_hugepage_init(void)
 	}
 
 	/* create shared memory */
-	hugepage = create_shared_memory(eal_hugepage_file_path(),
+	hugepage = create_shared_memory(eal_hugepage_data_path(),
 			nr_hugefiles * sizeof(struct hugepage_file));
 
 	if (hugepage == NULL) {
@@ -1727,16 +1727,18 @@ eal_legacy_hugepage_attach(void)
 
 	test_phys_addrs_available();
 
-	fd_hugepage = open(eal_hugepage_file_path(), O_RDONLY);
+	fd_hugepage = open(eal_hugepage_data_path(), O_RDONLY);
 	if (fd_hugepage < 0) {
-		RTE_LOG(ERR, EAL, "Could not open %s\n", eal_hugepage_file_path());
+		RTE_LOG(ERR, EAL, "Could not open %s\n",
+				eal_hugepage_data_path());
 		goto error;
 	}
 
 	size = getFileSize(fd_hugepage);
 	hp = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd_hugepage, 0);
 	if (hp == MAP_FAILED) {
-		RTE_LOG(ERR, EAL, "Could not mmap %s\n", eal_hugepage_file_path());
+		RTE_LOG(ERR, EAL, "Could not mmap %s\n",
+				eal_hugepage_data_path());
 		goto error;
 	}
 
-- 
2.7.4

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [dpdk-dev] [PATCH v3 3/4] eal: add directory for DPDK runtime data
  2018-04-30 12:08 ` [dpdk-dev] [PATCH v2 0/4] Clean up EAL runtime data paths Anatoly Burakov
                     ` (3 preceding siblings ...)
  2018-05-14 16:27   ` [dpdk-dev] [PATCH v3 2/4] eal: rename function returning hugepage data path Anatoly Burakov
@ 2018-05-14 16:27   ` Anatoly Burakov
  2018-05-14 16:27   ` [dpdk-dev] [PATCH v3 4/4] eal: move all runtime data into DPDK runtime dir Anatoly Burakov
  5 siblings, 0 replies; 23+ messages in thread
From: Anatoly Burakov @ 2018-05-14 16:27 UTC (permalink / raw)
  To: dev; +Cc: Bruce Richardson, thomas

Currently, during runtime, DPDK will store a bunch of files here
and there (in /var/run, /tmp or in $HOME). Fix it by creating a
DPDK-specific runtime directory, under which all runtime data
will be placed. The template for creating this runtime directory
is the following:

  <base path>/dpdk/<DPDK prefix>/

Where <base path> is set to either "/var/run" if run as root, or
$XDG_RUNTIME_DIR if run as non-root, with a fallback to /tmp if
$XDG_RUNTIME_DIR is not defined. So, for example, if run as root,
by default all runtime data will be stored at /var/run/dpdk/rte/.

There is no equivalent of "mkdir -p", so we will be creating the
path step by step.

Nothing uses this new path yet, changes for that will come in
next commit.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
Reviewed-by: Reshma Pattan <reshma.pattan@intel.com>
---
 lib/librte_eal/bsdapp/eal/eal.c        | 68 ++++++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_filesystem.h |  8 ++++
 lib/librte_eal/linuxapp/eal/eal.c      | 67 +++++++++++++++++++++++++++++++++
 3 files changed, 143 insertions(+)

diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index 3ba328a..de88b6a 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -18,6 +18,7 @@
 #include <limits.h>
 #include <sys/mman.h>
 #include <sys/queue.h>
+#include <sys/stat.h>
 
 #include <rte_compat.h>
 #include <rte_common.h>
@@ -83,6 +84,66 @@ struct internal_config internal_config;
 /* used by rte_rdtsc() */
 int rte_cycles_vmware_tsc_map;
 
+/* platform-specific runtime dir */
+static char runtime_dir[PATH_MAX];
+
+int
+eal_create_runtime_dir(void)
+{
+	const char *directory = default_config_dir;
+	const char *xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
+	const char *fallback = "/tmp";
+	char tmp[PATH_MAX];
+	int ret;
+
+	if (getuid() != 0) {
+		/* try XDG path first, fall back to /tmp */
+		if (xdg_runtime_dir != NULL)
+			directory = xdg_runtime_dir;
+		else
+			directory = fallback;
+	}
+	/* create DPDK subdirectory under runtime dir */
+	ret = snprintf(tmp, sizeof(tmp), "%s/dpdk", directory);
+	if (ret < 0 || ret == sizeof(tmp)) {
+		RTE_LOG(ERR, EAL, "Error creating DPDK runtime path name\n");
+		return -1;
+	}
+
+	/* create prefix-specific subdirectory under DPDK runtime dir */
+	ret = snprintf(runtime_dir, sizeof(runtime_dir), "%s/%s",
+			tmp, internal_config.hugefile_prefix);
+	if (ret < 0 || ret == sizeof(runtime_dir)) {
+		RTE_LOG(ERR, EAL, "Error creating prefix-specific runtime path name\n");
+		return -1;
+	}
+
+	/* create the path if it doesn't exist. no "mkdir -p" here, so do it
+	 * step by step.
+	 */
+	ret = mkdir(tmp, 0600);
+	if (ret < 0 && errno != EEXIST) {
+		RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
+			tmp, strerror(errno));
+		return -1;
+	}
+
+	ret = mkdir(runtime_dir, 0600);
+	if (ret < 0 && errno != EEXIST) {
+		RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
+			runtime_dir, strerror(errno));
+		return -1;
+	}
+
+	return 0;
+}
+
+const char *
+eal_get_runtime_dir(void)
+{
+	return runtime_dir;
+}
+
 /* Return user provided mbuf pool ops name */
 const char * __rte_experimental
 rte_eal_mbuf_user_pool_ops(void)
@@ -523,6 +584,13 @@ rte_eal_init(int argc, char **argv)
 	/* set log level as early as possible */
 	eal_log_level_parse(argc, argv);
 
+	/* create runtime data directory */
+	if (eal_create_runtime_dir() < 0) {
+		rte_eal_init_alert("Cannot create runtime directory\n");
+		rte_errno = EACCES;
+		return -1;
+	}
+
 	if (rte_eal_cpu_init() < 0) {
 		rte_eal_init_alert("Cannot detect lcores.");
 		rte_errno = ENOTSUP;
diff --git a/lib/librte_eal/common/eal_filesystem.h b/lib/librte_eal/common/eal_filesystem.h
index 060ac2b..67f5ca8 100644
--- a/lib/librte_eal/common/eal_filesystem.h
+++ b/lib/librte_eal/common/eal_filesystem.h
@@ -25,6 +25,14 @@
 
 static const char *default_config_dir = "/var/run";
 
+/* sets up platform-specific runtime data dir */
+int
+eal_create_runtime_dir(void);
+
+/* returns runtime dir */
+const char *
+eal_get_runtime_dir(void);
+
 static inline const char *
 eal_runtime_config_path(void)
 {
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 34d9412..6048063 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -92,6 +92,66 @@ struct internal_config internal_config;
 /* used by rte_rdtsc() */
 int rte_cycles_vmware_tsc_map;
 
+/* platform-specific runtime dir */
+static char runtime_dir[PATH_MAX];
+
+int
+eal_create_runtime_dir(void)
+{
+	const char *directory = default_config_dir;
+	const char *xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
+	const char *fallback = "/tmp";
+	char tmp[PATH_MAX];
+	int ret;
+
+	if (getuid() != 0) {
+		/* try XDG path first, fall back to /tmp */
+		if (xdg_runtime_dir != NULL)
+			directory = xdg_runtime_dir;
+		else
+			directory = fallback;
+	}
+	/* create DPDK subdirectory under runtime dir */
+	ret = snprintf(tmp, sizeof(tmp), "%s/dpdk", directory);
+	if (ret < 0 || ret == sizeof(tmp)) {
+		RTE_LOG(ERR, EAL, "Error creating DPDK runtime path name\n");
+		return -1;
+	}
+
+	/* create prefix-specific subdirectory under DPDK runtime dir */
+	ret = snprintf(runtime_dir, sizeof(runtime_dir), "%s/%s",
+			tmp, internal_config.hugefile_prefix);
+	if (ret < 0 || ret == sizeof(runtime_dir)) {
+		RTE_LOG(ERR, EAL, "Error creating prefix-specific runtime path name\n");
+		return -1;
+	}
+
+	/* create the path if it doesn't exist. no "mkdir -p" here, so do it
+	 * step by step.
+	 */
+	ret = mkdir(tmp, 0600);
+	if (ret < 0 && errno != EEXIST) {
+		RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
+			tmp, strerror(errno));
+		return -1;
+	}
+
+	ret = mkdir(runtime_dir, 0600);
+	if (ret < 0 && errno != EEXIST) {
+		RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
+			runtime_dir, strerror(errno));
+		return -1;
+	}
+
+	return 0;
+}
+
+const char *
+eal_get_runtime_dir(void)
+{
+	return runtime_dir;
+}
+
 /* Return user provided mbuf pool ops name */
 const char * __rte_experimental
 rte_eal_mbuf_user_pool_ops(void)
@@ -741,6 +801,13 @@ rte_eal_init(int argc, char **argv)
 	/* set log level as early as possible */
 	eal_log_level_parse(argc, argv);
 
+	/* create runtime data directory */
+	if (eal_create_runtime_dir() < 0) {
+		rte_eal_init_alert("Cannot create runtime directory\n");
+		rte_errno = EACCES;
+		return -1;
+	}
+
 	if (rte_eal_cpu_init() < 0) {
 		rte_eal_init_alert("Cannot detect lcores.");
 		rte_errno = ENOTSUP;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [dpdk-dev] [PATCH v3 4/4] eal: move all runtime data into DPDK runtime dir
  2018-04-30 12:08 ` [dpdk-dev] [PATCH v2 0/4] Clean up EAL runtime data paths Anatoly Burakov
                     ` (4 preceding siblings ...)
  2018-05-14 16:27   ` [dpdk-dev] [PATCH v3 3/4] eal: add directory for DPDK runtime data Anatoly Burakov
@ 2018-05-14 16:27   ` Anatoly Burakov
  5 siblings, 0 replies; 23+ messages in thread
From: Anatoly Burakov @ 2018-05-14 16:27 UTC (permalink / raw)
  To: dev; +Cc: Bruce Richardson, thomas

Fix all calls to functions in eal_filesystem to produce paths
residing inside dedicated DPDK runtime directory. Leaving DPDK
runtime config in place as 3rd-party applications within the
DPDK ecosystem might rely on this path to determine whether
DPDK is running, so moving that will be postponed to the next
release cycle.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---

Notes:
    v3:
    - Leave rte_config path as is

 lib/librte_eal/bsdapp/eal/eal.c        |  4 ++-
 lib/librte_eal/common/eal_filesystem.h | 61 +++++++++-------------------------
 lib/librte_eal/linuxapp/eal/eal.c      |  4 ++-
 3 files changed, 22 insertions(+), 47 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index de88b6a..c890bfe 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -87,10 +87,12 @@ int rte_cycles_vmware_tsc_map;
 /* platform-specific runtime dir */
 static char runtime_dir[PATH_MAX];
 
+static const char *default_runtime_dir = "/var/run";
+
 int
 eal_create_runtime_dir(void)
 {
-	const char *directory = default_config_dir;
+	const char *directory = default_runtime_dir;
 	const char *xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
 	const char *fallback = "/tmp";
 	char tmp[PATH_MAX];
diff --git a/lib/librte_eal/common/eal_filesystem.h b/lib/librte_eal/common/eal_filesystem.h
index 67f5ca8..364f38d 100644
--- a/lib/librte_eal/common/eal_filesystem.h
+++ b/lib/librte_eal/common/eal_filesystem.h
@@ -13,7 +13,6 @@
 
 /** Path of rte config file. */
 #define RUNTIME_CONFIG_FMT "%s/.%s_config"
-#define FBARRAY_FMT "%s/.%s_%s"
 
 #include <stdint.h>
 #include <limits.h>
@@ -23,8 +22,6 @@
 #include <rte_string_fns.h>
 #include "eal_internal_cfg.h"
 
-static const char *default_config_dir = "/var/run";
-
 /* sets up platform-specific runtime data dir */
 int
 eal_create_runtime_dir(void);
@@ -37,7 +34,7 @@ static inline const char *
 eal_runtime_config_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
-	const char *directory = default_config_dir;
+	const char *directory = "/var/run";
 	const char *home_dir = getenv("HOME");
 
 	if (getuid() != 0 && home_dir != NULL)
@@ -48,65 +45,45 @@ eal_runtime_config_path(void)
 }
 
 /** Path of primary/secondary communication unix socket file. */
-#define MP_SOCKET_PATH_FMT "%s/.%s_unix"
+#define MP_SOCKET_FNAME "mp_socket"
 static inline const char *
 eal_mp_socket_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
-	const char *directory = default_config_dir;
-	const char *home_dir = getenv("HOME");
-
-	if (getuid() != 0 && home_dir != NULL)
-		directory = home_dir;
-	snprintf(buffer, sizeof(buffer) - 1, MP_SOCKET_PATH_FMT,
-		 directory, internal_config.hugefile_prefix);
 
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+			MP_SOCKET_FNAME);
 	return buffer;
 }
 
+#define FBARRAY_NAME_FMT "%s/fbarray_%s"
 static inline const char *
 eal_get_fbarray_path(char *buffer, size_t buflen, const char *name) {
-	const char *directory = "/tmp";
-	const char *home_dir = getenv("HOME");
-
-	if (getuid() != 0 && home_dir != NULL)
-		directory = home_dir;
-	snprintf(buffer, buflen - 1, FBARRAY_FMT, directory,
-			internal_config.hugefile_prefix, name);
+	snprintf(buffer, buflen, FBARRAY_NAME_FMT, eal_get_runtime_dir(), name);
 	return buffer;
 }
 
 /** Path of hugepage info file. */
-#define HUGEPAGE_INFO_FMT "%s/.%s_hugepage_info"
-
+#define HUGEPAGE_INFO_FNAME "hugepage_info"
 static inline const char *
 eal_hugepage_info_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
-	const char *directory = default_config_dir;
-	const char *home_dir = getenv("HOME");
 
-	if (getuid() != 0 && home_dir != NULL)
-		directory = home_dir;
-	snprintf(buffer, sizeof(buffer) - 1, HUGEPAGE_INFO_FMT, directory,
-			internal_config.hugefile_prefix);
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+			HUGEPAGE_INFO_FNAME);
 	return buffer;
 }
 
-/** Path of hugepage info file. */
-#define HUGEPAGE_FILE_FMT "%s/.%s_hugepage_file"
-
+/** Path of hugepage data file. */
+#define HUGEPAGE_DATA_FNAME "hugepage_data"
 static inline const char *
 eal_hugepage_data_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
-	const char *directory = default_config_dir;
-	const char *home_dir = getenv("HOME");
 
-	if (getuid() != 0 && home_dir != NULL)
-		directory = home_dir;
-	snprintf(buffer, sizeof(buffer) - 1, HUGEPAGE_FILE_FMT, directory,
-			internal_config.hugefile_prefix);
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+			HUGEPAGE_DATA_FNAME);
 	return buffer;
 }
 
@@ -122,18 +99,12 @@ eal_get_hugefile_path(char *buffer, size_t buflen, const char *hugedir, int f_id
 }
 
 /** String format for hugepage map lock files. */
-#define HUGEFILE_LOCK_FMT "%s/.%smap_%d.lock"
-
+#define HUGEFILE_LOCK_FMT "%s/map_%d.lock"
 static inline const char *
 eal_get_hugefile_lock_path(char *buffer, size_t buflen, int f_id)
 {
-	const char *directory = default_config_dir;
-	const char *home_dir = getenv("HOME");
-
-	if (getuid() != 0 && home_dir != NULL)
-		directory = home_dir;
-	snprintf(buffer, buflen - 1, HUGEFILE_LOCK_FMT, directory,
-			internal_config.hugefile_prefix, f_id);
+	snprintf(buffer, buflen, HUGEFILE_LOCK_FMT, eal_get_runtime_dir(),
+			f_id);
 	buffer[buflen - 1] = '\0';
 	return buffer;
 }
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 6048063..bed5823 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -95,10 +95,12 @@ int rte_cycles_vmware_tsc_map;
 /* platform-specific runtime dir */
 static char runtime_dir[PATH_MAX];
 
+static const char *default_runtime_dir = "/var/run";
+
 int
 eal_create_runtime_dir(void)
 {
-	const char *directory = default_config_dir;
+	const char *directory = default_runtime_dir;
 	const char *xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
 	const char *fallback = "/tmp";
 	char tmp[PATH_MAX];
-- 
2.7.4

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [dpdk-dev] [PATCH v3 0/4] Clean up EAL runtime data paths
  2018-05-14 16:27   ` [dpdk-dev] [PATCH v3 " Anatoly Burakov
@ 2018-05-14 22:45     ` Thomas Monjalon
  0 siblings, 0 replies; 23+ messages in thread
From: Thomas Monjalon @ 2018-05-14 22:45 UTC (permalink / raw)
  To: Anatoly Burakov; +Cc: dev, bruce.richardson

14/05/2018 18:27, Anatoly Burakov:
> As has been suggested [1], all DPDK runtime paths should be put
> into a single place. This patchset accomplishes exactly that.
> 
> If running as root, all files will be put under /var/run/dpdk/<prefix>,
> otherwise they will be put under $XDG_RUNTIME_PATH/dpdk/<prefix>, or, if
> that environment variable is not defined, all files will go under
> /tmp/dpdk/<prefix>.
> 
> [1] http://dpdk.org/dev/patchwork/patch/38688/
> 
> v3:
> - Rebase on rc2
> - Leave rte_config path in place, to be fixed for next release
> 
> v2:
> - Rebase on rc1
> 
> Anatoly Burakov (4):
>   eal: remove unused define
>   eal: rename function returning hugepage data path
>   eal: add directory for DPDK runtime data
>   eal: move all runtime data into DPDK runtime dir

Applied, thanks

You will need to send a deprecation notice to move rte_config path
in 18.08.

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2018-05-14 22:45 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-25 12:24 [dpdk-dev] [PATCH 18.05-RC2 0/4] Clean up EAL runtime data paths Anatoly Burakov
2018-04-25 12:24 ` [dpdk-dev] [PATCH 18.05-RC2 1/4] eal: remove unused define Anatoly Burakov
2018-04-26  7:11   ` David Marchand
2018-04-25 12:24 ` [dpdk-dev] [PATCH 18.05-RC2 2/4] eal: rename function returning hugepage data path Anatoly Burakov
2018-04-25 12:24 ` [dpdk-dev] [PATCH 18.05-RC2 3/4] eal: add directory for DPDK runtime data Anatoly Burakov
2018-04-25 12:24 ` [dpdk-dev] [PATCH 18.05-RC2 4/4] eal: move all runtime data into DPDK runtime dir Anatoly Burakov
2018-04-30 12:08 ` [dpdk-dev] [PATCH v2 0/4] Clean up EAL runtime data paths Anatoly Burakov
2018-05-09 15:59   ` Van Haaren, Harry
2018-05-09 16:11     ` Bruce Richardson
2018-05-09 19:03       ` Thomas Monjalon
2018-05-14  8:26         ` Burakov, Anatoly
2018-05-14 16:27   ` [dpdk-dev] [PATCH v3 " Anatoly Burakov
2018-05-14 22:45     ` Thomas Monjalon
2018-05-14 16:27   ` [dpdk-dev] [PATCH v3 1/4] eal: remove unused define Anatoly Burakov
2018-05-14 16:27   ` [dpdk-dev] [PATCH v3 2/4] eal: rename function returning hugepage data path Anatoly Burakov
2018-05-14 16:27   ` [dpdk-dev] [PATCH v3 3/4] eal: add directory for DPDK runtime data Anatoly Burakov
2018-05-14 16:27   ` [dpdk-dev] [PATCH v3 4/4] eal: move all runtime data into DPDK runtime dir Anatoly Burakov
2018-04-30 12:08 ` [dpdk-dev] [PATCH v2 1/4] eal: remove unused define Anatoly Burakov
2018-04-30 12:08 ` [dpdk-dev] [PATCH v2 2/4] eal: rename function returning hugepage data path Anatoly Burakov
2018-05-10 13:14   ` Pattan, Reshma
2018-04-30 12:08 ` [dpdk-dev] [PATCH v2 3/4] eal: add directory for DPDK runtime data Anatoly Burakov
2018-05-10 14:05   ` Pattan, Reshma
2018-04-30 12:08 ` [dpdk-dev] [PATCH v2 4/4] eal: move all runtime data into DPDK runtime dir Anatoly Burakov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).