From: Mark Wielaard <mark@klomp.org>
To: elfutils-devel@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH 2/3] debuginfod: Remove debuginfod_init_cache
Date: Tue, 10 May 2022 00:57:22 +0200 [thread overview]
Message-ID: <20220509225723.96902-3-mark@klomp.org> (raw)
In-Reply-To: <20220509225723.96902-1-mark@klomp.org>
debuginfod_init_cache would create all config files if they didn't
exist yet. It always made two stat calls. Then debuginfod_clean_cache
would call debuginfod_config_cache which did the same checks and
created any missing config files. Just make sure the cache_path
directory exists and remove debuginfod_init_cache before calling
debuginfod_clean_cache.
Signed-off-by: Mark Wielaard <mark@klomp.org>
---
debuginfod/ChangeLog | 6 ++++
debuginfod/debuginfod-client.c | 61 +++++-----------------------------
2 files changed, 15 insertions(+), 52 deletions(-)
diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog
index 46a6e22b..c9aa4fcf 100644
--- a/debuginfod/ChangeLog
+++ b/debuginfod/ChangeLog
@@ -1,3 +1,9 @@
+2022-05-09 Mark Wielaard <mark@klomp.org>
+
+ * debuginfod-client.c (debuginfod_init_cache): Remove.
+ (debuginfod_query_server): Don't call debuginfod_init_cache, call
+ mkdir then debuginfod_clean_cache.
+
2022-05-09 Mark Wielaard <mark@klomp.org>
* debuginfod-client.c (debuginfod_config_cache): Always open with
diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index 3b2728f1..6bdf1908 100644
--- a/debuginfod/debuginfod-client.c
+++ b/debuginfod/debuginfod-client.c
@@ -274,55 +274,6 @@ debuginfod_config_cache(char *config_path,
return cache_config;
}
-/* Create the cache and interval file if they do not already exist.
- Return 0 if cache and config file are initialized, otherwise return
- the appropriate error code. */
-static int
-debuginfod_init_cache (char *cache_path, char *interval_path, char *maxage_path)
-{
- struct stat st;
-
- /* If the cache and config file already exist then we are done. */
- if (stat(cache_path, &st) == 0 && stat(interval_path, &st) == 0)
- return 0;
-
- /* Create the cache and config files as necessary. */
- if (stat(cache_path, &st) != 0 && mkdir(cache_path, ACCESSPERMS) < 0)
- return -errno;
-
- int fd = -1;
-
- /* init cleaning interval config file. */
- fd = open(interval_path, O_CREAT | O_RDWR, DEFFILEMODE);
- if (fd < 0)
- return -errno;
-
- if (dprintf(fd, "%ld", cache_clean_default_interval_s) < 0)
- {
- int ret = -errno;
- close (fd);
- return ret;
- }
-
- close (fd);
-
- /* init max age config file. */
- if (stat(maxage_path, &st) != 0
- && (fd = open(maxage_path, O_CREAT | O_RDWR, DEFFILEMODE)) < 0)
- return -errno;
-
- if (dprintf(fd, "%ld", cache_default_max_unused_age_s) < 0)
- {
- int ret = -errno;
- close (fd);
- return ret;
- }
-
- close (fd);
- return 0;
-}
-
-
/* Delete any files that have been unmodied for a period
longer than $DEBUGINFOD_CACHE_CLEAN_INTERVAL_S. */
static int
@@ -795,9 +746,15 @@ debuginfod_query_server (debuginfod_client *c,
if (vfd >= 0)
dprintf (vfd, "checking cache dir %s\n", cache_path);
- rc = debuginfod_init_cache(cache_path, interval_path, maxage_path);
- if (rc != 0)
- goto out;
+ /* Make sure cache dir exists. debuginfo_clean_cache will then make
+ sure the interval, cache_miss and maxage files exist. */
+ if (mkdir (cache_path, ACCESSPERMS) != 0
+ && errno != EEXIST)
+ {
+ rc = -errno;
+ goto out;
+ }
+
rc = debuginfod_clean_cache(c, cache_path, interval_path, maxage_path);
if (rc != 0)
goto out;
--
2.30.2
next prev parent reply other threads:[~2022-05-09 22:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-09 22:57 Optimize debuginfod-client cache lookup/cleanup a little Mark Wielaard
2022-05-09 22:57 ` [PATCH 1/3] debuginfod: Make sure debuginfod_config_cache always returns valid stat Mark Wielaard
2022-05-09 22:57 ` Mark Wielaard [this message]
2022-05-09 22:57 ` [PATCH 3/3] debuginfod: update mtime of interval_path as early as possible Mark Wielaard
2022-05-14 22:36 ` Optimize debuginfod-client cache lookup/cleanup a little Mark Wielaard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220509225723.96902-3-mark@klomp.org \
--to=mark@klomp.org \
--cc=elfutils-devel@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).