chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
dad5031
)
journal: replace linked list by hashmap when merging files
author
Lennart Poettering
<lennart@poettering.net>
Fri, 7 Oct 2011 20:00:05 +0000
(22:00 +0200)
committer
Lennart Poettering
<lennart@poettering.net>
Fri, 7 Oct 2011 20:02:06 +0000
(22:02 +0200)
src/journal/journal-private.h
patch
|
blob
|
history
src/journal/journalctl.c
patch
|
blob
|
history
src/journal/journald.c
patch
|
blob
|
history
src/journal/sd-journal.c
patch
|
blob
|
history
src/journal/test-journal.c
patch
|
blob
|
history
diff --git
a/src/journal/journal-private.h
b/src/journal/journal-private.h
index 863a39893b3f178d0ddfadb372021b988f12374d..914b73a40b801c89cd76578200663cad120041f3 100644
(file)
--- a/
src/journal/journal-private.h
+++ b/
src/journal/journal-private.h
@@
-27,10
+27,20
@@
#include "sd-journal.h"
#include "journal-def.h"
#include "util.h"
#include "sd-journal.h"
#include "journal-def.h"
#include "util.h"
+#include "sd-id128.h"
+
+typedef struct JournalCoursor {
+ sd_id128_t file_id;
+ sd_id128_t boot_id;
+ uint64_t seqnum;
+ uint64_t monotonic;
+ uint64_t realtime;
+ uint64_t xor_hash;
+} JournalCoursor;
typedef struct JournalFile JournalFile;
typedef struct JournalFile JournalFile;
-int journal_file_open(
sd_journal *j,
const char *fname, int flags, mode_t mode, JournalFile **ret);
+int journal_file_open(const char *fname, int flags, mode_t mode, JournalFile **ret);
void journal_file_close(JournalFile *j);
void journal_file_close(JournalFile *j);
diff --git
a/src/journal/journalctl.c
b/src/journal/journalctl.c
index 838e8436e4d3d29353ec3c25f0230489d2fbc571..7bcd842f6db5db8d3a2a1c8c3b19497210a00512 100644
(file)
--- a/
src/journal/journalctl.c
+++ b/
src/journal/journalctl.c
@@
-33,9
+33,9
@@
int main(int argc, char *argv[]) {
log_parse_environment();
log_open();
log_parse_environment();
log_open();
- r = journal_file_open(
NULL,
"/var/log/journal/system.journal", O_RDONLY, 0644, &f);
+ r = journal_file_open("/var/log/journal/system.journal", O_RDONLY, 0644, &f);
if (r == -ENOENT)
if (r == -ENOENT)
- r = journal_file_open(
NULL,
"/run/log/journal/system.journal", O_RDONLY, 0644, &f);
+ r = journal_file_open("/run/log/journal/system.journal", O_RDONLY, 0644, &f);
if (r < 0) {
log_error("Failed to open journal: %s", strerror(-r));
if (r < 0) {
log_error("Failed to open journal: %s", strerror(-r));
diff --git
a/src/journal/journald.c
b/src/journal/journald.c
index 9297ca6fb7da390be8877c4b81d6a55308d79fa0..818e146f94aeb30ce0d9384465f5faef4f9ec734 100644
(file)
--- a/
src/journal/journald.c
+++ b/
src/journal/journald.c
@@
-257,11
+257,11
@@
static int process_event(Server *s, struct epoll_event *ev) {
static int open_system_journal(JournalFile **f) {
int r;
static int open_system_journal(JournalFile **f) {
int r;
- r = journal_file_open(
NULL,
"/var/log/journal/system.journal", O_RDWR|O_CREAT, 0644, f);
+ r = journal_file_open("/var/log/journal/system.journal", O_RDWR|O_CREAT, 0644, f);
if (r == -ENOENT) {
mkdir_p("/run/log/journal", 0755);
if (r == -ENOENT) {
mkdir_p("/run/log/journal", 0755);
- r = journal_file_open(
NULL,
"/run/log/journal/system.journal", O_RDWR|O_CREAT, 0644, f);
+ r = journal_file_open("/run/log/journal/system.journal", O_RDWR|O_CREAT, 0644, f);
}
return r;
}
return r;
diff --git
a/src/journal/sd-journal.c
b/src/journal/sd-journal.c
index d49f7179153ea4318dc5043c37256966255b17ed..8bca300f93f4468531b483788d3ca35f47d54c1a 100644
(file)
--- a/
src/journal/sd-journal.c
+++ b/
src/journal/sd-journal.c
@@
-32,6
+32,7
@@
#include "journal-private.h"
#include "lookup3.h"
#include "list.h"
#include "journal-private.h"
#include "lookup3.h"
#include "list.h"
+#include "hashmap.h"
#define DEFAULT_ARENA_MAX_SIZE (16ULL*1024ULL*1024ULL*1024ULL)
#define DEFAULT_ARENA_MIN_SIZE (256ULL*1024ULL)
#define DEFAULT_ARENA_MAX_SIZE (16ULL*1024ULL*1024ULL*1024ULL)
#define DEFAULT_ARENA_MIN_SIZE (256ULL*1024ULL)
@@
-43,8
+44,6
@@
#define DEFAULT_WINDOW_SIZE (128ULL*1024ULL*1024ULL)
struct JournalFile {
#define DEFAULT_WINDOW_SIZE (128ULL*1024ULL*1024ULL)
struct JournalFile {
- sd_journal *journal;
-
int fd;
char *path;
struct stat last_stat;
int fd;
char *path;
struct stat last_stat;
@@
-72,7
+71,7
@@
struct JournalFile {
};
struct sd_journal {
};
struct sd_journal {
-
LIST_HEAD(JournalFile, files)
;
+
Hashmap *files
;
};
static const char signature[] = { 'L', 'P', 'K', 'S', 'H', 'H', 'R', 'H' };
};
static const char signature[] = { 'L', 'P', 'K', 'S', 'H', 'H', 'R', 'H' };
@@
-82,9
+81,6
@@
static const char signature[] = { 'L', 'P', 'K', 'S', 'H', 'H', 'R', 'H' };
void journal_file_close(JournalFile *f) {
assert(f);
void journal_file_close(JournalFile *f) {
assert(f);
- if (f->journal)
- LIST_REMOVE(JournalFile, files, f->journal->files, f);
-
if (f->fd >= 0)
close_nointr_nofail(f->fd);
if (f->fd >= 0)
close_nointr_nofail(f->fd);
@@
-1146,7
+1142,6
@@
fail:
}
int journal_file_open(
}
int journal_file_open(
- sd_journal *j,
const char *fname,
int flags,
mode_t mode,
const char *fname,
int flags,
mode_t mode,
@@
-1242,11
+1237,6
@@
int journal_file_open(
if (r < 0)
goto fail;
if (r < 0)
goto fail;
- if (j) {
- LIST_PREPEND(JournalFile, files, j->files, f);
- f->journal = j;
- }
-
if (ret)
*ret = f;
if (ret)
*ret = f;
@@
-1273,6
+1263,10
@@
int sd_journal_open(sd_journal **ret) {
if (!j)
return -ENOMEM;
if (!j)
return -ENOMEM;
+ j->files = hashmap_new(string_hash_func, string_compare_func);
+ if (!j->files)
+ goto fail;
+
NULSTR_FOREACH(p, search_paths) {
DIR *d;
NULSTR_FOREACH(p, search_paths) {
DIR *d;
@@
-1287,6
+1281,7
@@
int sd_journal_open(sd_journal **ret) {
for (;;) {
struct dirent buf, *de;
int k;
for (;;) {
struct dirent buf, *de;
int k;
+ JournalFile *f;
k = readdir_r(d, &buf, &de);
if (k != 0) {
k = readdir_r(d, &buf, &de);
if (k != 0) {
@@
-1309,19
+1304,24
@@
int sd_journal_open(sd_journal **ret) {
goto fail;
}
goto fail;
}
- k = journal_file_open(j, fn, O_RDONLY, 0, NULL);
- if (k < 0 && r == 0)
- r = -k;
-
+ k = journal_file_open(fn, O_RDONLY, 0, &f);
free(fn);
free(fn);
- }
- }
- if (!j->files) {
- if (r >= 0)
- r = -ENOENT;
+ if (k < 0) {
- goto fail;
+ if (r == 0)
+ r = -k;
+ } else {
+ k = hashmap_put(j->files, f->path, f);
+ if (k < 0) {
+ journal_file_close(f);
+ closedir(d);
+
+ r = k;
+ goto fail;
+ }
+ }
+ }
}
*ret = j;
}
*ret = j;
@@
-1336,8
+1336,14
@@
fail:
void sd_journal_close(sd_journal *j) {
assert(j);
void sd_journal_close(sd_journal *j) {
assert(j);
- while (j->files)
- journal_file_close(j->files);
+ if (j->files) {
+ JournalFile *f;
+
+ while ((f = hashmap_steal_first(j->files)))
+ journal_file_close(f);
+
+ hashmap_free(j->files);
+ }
free(j);
}
free(j);
}
diff --git
a/src/journal/test-journal.c
b/src/journal/test-journal.c
index 92bef5f3ef9239773a3d2d9c50b6f0d2e884fcaf..e0aedc7b834dcc40b1cfce30631e91587f4ffda9 100644
(file)
--- a/
src/journal/test-journal.c
+++ b/
src/journal/test-journal.c
@@
-33,7
+33,7
@@
int main(int argc, char *argv[]) {
log_set_max_level(LOG_DEBUG);
log_set_max_level(LOG_DEBUG);
- assert_se(journal_file_open(
NULL,
"test", O_RDWR|O_CREAT, 0666, &f) == 0);
+ assert_se(journal_file_open("test", O_RDWR|O_CREAT, 0666, &f) == 0);
dual_timestamp_get(&ts);
dual_timestamp_get(&ts);