]> git.droids-corp.org - dpdk.git/commitdiff
eal: cache last directory permissions checked
authorBruce Richardson <bruce.richardson@intel.com>
Fri, 3 Jul 2020 10:23:32 +0000 (11:23 +0100)
committerThomas Monjalon <thomas@monjalon.net>
Sun, 5 Jul 2020 19:32:40 +0000 (21:32 +0200)
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>
lib/librte_eal/common/eal_common_options.c

index 6c63b9364de69d6ff196c3b2c8e9a06d1b6afb86..85d5ba723156e5f0c02e55a55e84d33f0832310c 100644 (file)
@@ -414,11 +414,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 */