[systemd-devel] [PATCH 08/26] journal: make Server::user_journals a LinkedHashmap
Michal Schmidt
mschmidt at redhat.com
Thu Oct 16 00:50:46 PDT 2014
Order matters here. It replaces oldest entries first when
USER_JOURNALS_MAX is reached.
---
src/journal/journald-server.c | 24 ++++++++++++------------
src/journal/journald-server.h | 2 +-
2 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index 52111f7..275931b 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -266,7 +266,7 @@ static JournalFile* find_journal(Server *s, uid_t uid) {
if (r < 0)
return s->system_journal;
- f = hashmap_get(s->user_journals, UINT32_TO_PTR(uid));
+ f = linked_hashmap_get(s->user_journals, UINT32_TO_PTR(uid));
if (f)
return f;
@@ -274,9 +274,9 @@ static JournalFile* find_journal(Server *s, uid_t uid) {
SD_ID128_FORMAT_VAL(machine), uid) < 0)
return s->system_journal;
- while (hashmap_size(s->user_journals) >= USER_JOURNALS_MAX) {
+ while (linked_hashmap_size(s->user_journals) >= USER_JOURNALS_MAX) {
/* Too many open? Then let's close one */
- f = hashmap_steal_first(s->user_journals);
+ f = linked_hashmap_steal_first(s->user_journals);
assert(f);
journal_file_close(f);
}
@@ -287,7 +287,7 @@ static JournalFile* find_journal(Server *s, uid_t uid) {
server_fix_perms(s, f, uid);
- r = hashmap_put(s->user_journals, UINT32_TO_PTR(uid), f);
+ r = linked_hashmap_put(s->user_journals, UINT32_TO_PTR(uid), f);
if (r < 0) {
journal_file_close(f);
return s->system_journal;
@@ -328,13 +328,13 @@ void server_rotate(Server *s) {
do_rotate(s, &s->runtime_journal, "runtime", false, 0);
do_rotate(s, &s->system_journal, "system", s->seal, 0);
- HASHMAP_FOREACH_KEY(f, k, s->user_journals, i) {
+ LINKED_HASHMAP_FOREACH_KEY(f, k, s->user_journals, i) {
r = do_rotate(s, &f, "user", s->seal, PTR_TO_UINT32(k));
if (r >= 0)
- hashmap_replace(s->user_journals, k, f);
+ linked_hashmap_replace(s->user_journals, k, f);
else if (!f)
/* Old file has been closed and deallocated */
- hashmap_remove(s->user_journals, k);
+ linked_hashmap_remove(s->user_journals, k);
}
}
@@ -350,7 +350,7 @@ void server_sync(Server *s) {
log_error("Failed to sync system journal: %s", strerror(-r));
}
- HASHMAP_FOREACH_KEY(f, k, s->user_journals, i) {
+ LINKED_HASHMAP_FOREACH_KEY(f, k, s->user_journals, i) {
r = journal_file_set_offline(f);
if (r < 0)
log_error("Failed to sync user journal: %s", strerror(-r));
@@ -1482,7 +1482,7 @@ int server_init(Server *s) {
mkdir_p("/run/systemd/journal", 0755);
- s->user_journals = hashmap_new(NULL);
+ s->user_journals = linked_hashmap_new(NULL);
if (!s->user_journals)
return log_oom();
@@ -1602,7 +1602,7 @@ void server_maybe_append_tags(Server *s) {
if (s->system_journal)
journal_file_maybe_append_tag(s->system_journal, n);
- HASHMAP_FOREACH(f, s->user_journals, i)
+ LINKED_HASHMAP_FOREACH(f, s->user_journals, i)
journal_file_maybe_append_tag(f, n);
#endif
}
@@ -1620,10 +1620,10 @@ void server_done(Server *s) {
if (s->runtime_journal)
journal_file_close(s->runtime_journal);
- while ((f = hashmap_steal_first(s->user_journals)))
+ while ((f = linked_hashmap_steal_first(s->user_journals)))
journal_file_close(f);
- hashmap_free(s->user_journals);
+ linked_hashmap_free(s->user_journals);
sd_event_source_unref(s->syslog_event_source);
sd_event_source_unref(s->native_event_source);
diff --git a/src/journal/journald-server.h b/src/journal/journald-server.h
index 42a2235..d3c227d 100644
--- a/src/journal/journald-server.h
+++ b/src/journal/journald-server.h
@@ -76,7 +76,7 @@ typedef struct Server {
JournalFile *runtime_journal;
JournalFile *system_journal;
- Hashmap *user_journals;
+ LinkedHashmap *user_journals;
uint64_t seqnum;
--
2.1.0
More information about the systemd-devel
mailing list