[v2,4/4] eal: cache last directory permissions checked

Message ID 20200622143337.562637-5-bruce.richardson@intel.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series improve runtime loading of shared drivers |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/travis-robot warning Travis build: failed

Commit Message

Bruce Richardson June 22, 2020, 2:33 p.m. UTC
  When loading a directory of drivers, we check the same hierarchy multiple
times. If we just cache the last directory checked, this avoids repeated
checks of the same path, since all drivers in that path have been added to
the list consecutively.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
V2: Fix checkpatch issue for unnecessary else.
---
 lib/librte_eal/common/eal_common_options.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
  

Patch

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 6978e6744..e6b2a195f 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -388,11 +388,17 @@  verify_perms(const char *dirpath)
 
 	/* if not root, check down one level first */
 	if (strcmp(dirpath, "/") != 0) {
+		static __thread char last_dir_checked[PATH_MAX];
 		char copy[PATH_MAX];
+		const char *dir;
 
 		strlcpy(copy, dirpath, PATH_MAX);
-		if (verify_perms(dirname(copy)) != 0)
-			return -1;
+		dir = dirname(copy);
+		if (strncmp(dir, last_dir_checked, PATH_MAX) != 0) {
+			if (verify_perms(dir) != 0)
+				return -1;
+			strlcpy(last_dir_checked, dir, PATH_MAX);
+		}
 	}
 
 	/* call stat to check for permissions and ensure not world writable */