DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] eal/bsdapp: don't clean up files at startup
@ 2019-01-10 11:34 Anatoly Burakov
  2019-01-14 14:22 ` Thomas Monjalon
  0 siblings, 1 reply; 2+ messages in thread
From: Anatoly Burakov @ 2019-01-10 11:34 UTC (permalink / raw)
  To: dev; +Cc: Bruce Richardson, thomas, stable

On FreeBSD, closing the file descriptor drops the lock even if the
file descriptor was mmap'ed. This leads to the cleanup at the end
of EAL init to remove fbarray files that are still in use by the
process itself.

However, instead of working around this issue, we can take advantage
of the fact that FreeBSD doesn't really create any per-process
files in the first place, so no cleanup is actually needed.

Fixes: 0a529578f162 ("eal: clean up unused files on initialization")
Cc: stable@dpdk.org

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 lib/librte_eal/bsdapp/eal/eal.c | 84 ++-------------------------------
 1 file changed, 3 insertions(+), 81 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index c8e0da097..a6e573933 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -3,8 +3,6 @@
  * Copyright(c) 2014 6WIND S.A.
  */
 
-#include <dirent.h>
-#include <fnmatch.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
@@ -146,86 +144,10 @@ eal_create_runtime_dir(void)
 int
 eal_clean_runtime_dir(void)
 {
-	DIR *dir;
-	struct dirent *dirent;
-	int dir_fd, fd, lck_result;
-	static const char * const filters[] = {
-		"fbarray_*",
-		"mp_socket_*"
-	};
-
-	/* open directory */
-	dir = opendir(runtime_dir);
-	if (!dir) {
-		RTE_LOG(ERR, EAL, "Unable to open runtime directory %s\n",
-				runtime_dir);
-		goto error;
-	}
-	dir_fd = dirfd(dir);
-
-	/* lock the directory before doing anything, to avoid races */
-	if (flock(dir_fd, LOCK_EX) < 0) {
-		RTE_LOG(ERR, EAL, "Unable to lock runtime directory %s\n",
-			runtime_dir);
-		goto error;
-	}
-
-	dirent = readdir(dir);
-	if (!dirent) {
-		RTE_LOG(ERR, EAL, "Unable to read runtime directory %s\n",
-				runtime_dir);
-		goto error;
-	}
-
-	while (dirent != NULL) {
-		unsigned int f_idx;
-		bool skip = true;
-
-		/* skip files that don't match the patterns */
-		for (f_idx = 0; f_idx < RTE_DIM(filters); f_idx++) {
-			const char *filter = filters[f_idx];
-
-			if (fnmatch(filter, dirent->d_name, 0) == 0) {
-				skip = false;
-				break;
-			}
-		}
-		if (skip) {
-			dirent = readdir(dir);
-			continue;
-		}
-
-		/* try and lock the file */
-		fd = openat(dir_fd, dirent->d_name, O_RDONLY);
-
-		/* skip to next file */
-		if (fd == -1) {
-			dirent = readdir(dir);
-			continue;
-		}
-
-		/* non-blocking lock */
-		lck_result = flock(fd, LOCK_EX | LOCK_NB);
-
-		/* if lock succeeds, remove the file */
-		if (lck_result != -1)
-			unlinkat(dir_fd, dirent->d_name, 0);
-		close(fd);
-		dirent = readdir(dir);
-	}
-
-	/* closedir closes dir_fd and drops the lock */
-	closedir(dir);
+	/* FreeBSD doesn't need this implemented for now, because, unlike Linux,
+	 * FreeBSD doesn't create per-process files, so no need to clean up.
+	 */
 	return 0;
-
-error:
-	if (dir)
-		closedir(dir);
-
-	RTE_LOG(ERR, EAL, "Error while clearing runtime dir: %s\n",
-		strerror(errno));
-
-	return -1;
 }
 
 
-- 
2.17.1

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

* Re: [dpdk-dev] [PATCH] eal/bsdapp: don't clean up files at startup
  2019-01-10 11:34 [dpdk-dev] [PATCH] eal/bsdapp: don't clean up files at startup Anatoly Burakov
@ 2019-01-14 14:22 ` Thomas Monjalon
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Monjalon @ 2019-01-14 14:22 UTC (permalink / raw)
  To: Anatoly Burakov; +Cc: dev, Bruce Richardson, stable

10/01/2019 12:34, Anatoly Burakov:
> On FreeBSD, closing the file descriptor drops the lock even if the
> file descriptor was mmap'ed. This leads to the cleanup at the end
> of EAL init to remove fbarray files that are still in use by the
> process itself.
> 
> However, instead of working around this issue, we can take advantage
> of the fact that FreeBSD doesn't really create any per-process
> files in the first place, so no cleanup is actually needed.
> 
> Fixes: 0a529578f162 ("eal: clean up unused files on initialization")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>

Applied, thanks

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

end of thread, other threads:[~2019-01-14 14:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-10 11:34 [dpdk-dev] [PATCH] eal/bsdapp: don't clean up files at startup Anatoly Burakov
2019-01-14 14:22 ` Thomas Monjalon

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).