From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6459BA0519; Mon, 22 Jun 2020 16:34:23 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8C1FA1D731; Mon, 22 Jun 2020 16:33:58 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id E49851D71F for ; Mon, 22 Jun 2020 16:33:52 +0200 (CEST) IronPort-SDR: yVAmIWReg+ntW6S8nT934SDVFwHxaMa10ZdvR4a8gKCmNi7Es/1NOwLwL/16ViihXLIhYl0ty/ iOqGTuLvP9pQ== X-IronPort-AV: E=McAfee;i="6000,8403,9659"; a="228428032" X-IronPort-AV: E=Sophos;i="5.75,267,1589266800"; d="scan'208";a="228428032" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2020 07:33:52 -0700 IronPort-SDR: cFeRAkjbIt6vVK0duax740bz8ulc7ifsnY7fAoZ3kndp6J9W6ecGeyz+ra6I/w4xpa9ncEpItR le2zBnjgxCJw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,267,1589266800"; d="scan'208";a="300860168" Received: from silpixa00399126.ir.intel.com ([10.237.222.84]) by fmsmga004.fm.intel.com with ESMTP; 22 Jun 2020 07:33:51 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: thomas@monjalon.net, david.marchand@redhat.com, Bruce Richardson Date: Mon, 22 Jun 2020 15:33:37 +0100 Message-Id: <20200622143337.562637-5-bruce.richardson@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200622143337.562637-1-bruce.richardson@intel.com> References: <20200618135049.489773-1-bruce.richardson@intel.com> <20200622143337.562637-1-bruce.richardson@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 4/4] eal: cache last directory permissions checked X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- V2: Fix checkpatch issue for unnecessary else. --- lib/librte_eal/common/eal_common_options.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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 */ -- 2.25.1