[systemd-commits] Branch 'journal' - 6 commits - src/journal

Lennart Poettering lennart at kemper.freedesktop.org
Thu Dec 29 06:38:56 PST 2011


 src/journal/journal-file.c |  109 ++++++++++++++++-
 src/journal/journal-file.h |    4 
 src/journal/journalctl.c   |    2 
 src/journal/journald.c     |  281 ++++++++++++++++++++++++++++++++++-----------
 src/journal/sd-journal.c   |   69 +++--------
 src/journal/sd-journal.h   |   25 +++-
 6 files changed, 360 insertions(+), 130 deletions(-)

New commits:
commit 54a7b863dd3937893abae47b20b6f655b8e9252a
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Dec 29 15:25:42 2011 +0100

    journald: don't recheck /var availability more often than 30s

diff --git a/src/journal/journald.c b/src/journal/journald.c
index 1efe042..52cdc70 100644
--- a/src/journal/journald.c
+++ b/src/journal/journald.c
@@ -51,6 +51,8 @@
 
 #define RECHECK_AVAILABLE_SPACE_USEC (30*USEC_PER_SEC)
 
+#define RECHECK_VAR_AVAILABLE_USEC (30*USEC_PER_SEC)
+
 typedef struct StdoutStream StdoutStream;
 
 typedef struct Server {
@@ -78,6 +80,8 @@ typedef struct Server {
         uint64_t cached_available_space;
         usec_t cached_available_space_timestamp;
 
+        uint64_t var_available_timestamp;
+
         LIST_HEAD(StdoutStream, stdout_streams);
         unsigned n_stdout_streams;
 } Server;
@@ -1200,12 +1204,22 @@ static int server_flush_to_var(Server *s) {
         int r;
         sd_id128_t machine;
         sd_journal *j;
+        usec_t ts;
 
         assert(s);
 
+        if (!s->runtime_journal)
+                return 0;
+
+        ts = now(CLOCK_MONOTONIC);
+        if (s->var_available_timestamp + RECHECK_VAR_AVAILABLE_USEC > ts)
+                return 0;
+
+        s->var_available_timestamp = ts;
+
         system_journal_open(s);
 
-        if (!s->system_journal || !s->runtime_journal)
+        if (!s->system_journal)
                 return 0;
 
         r = sd_id128_get_machine(&machine);
diff --git a/src/journal/sd-journal.h b/src/journal/sd-journal.h
index f6b1c95..97f9f0f 100644
--- a/src/journal/sd-journal.h
+++ b/src/journal/sd-journal.h
@@ -36,6 +36,7 @@
  *   - accelerate looking for "all hostnames" and suchlike.
  *   - hookup with systemctl
  *   - handle incomplete header
+ *   - write unit files
  *
  *   - local deserializer
  *   - http server

commit cf244689e9d1ab50082c9ddd0f3c4d1eb982badc
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Dec 29 15:00:57 2011 +0100

    journald: flush /run to /var as soon as it becomes available

diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 6c7718d..190bfb9 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -950,7 +950,7 @@ static int journal_file_append_entry_internal(
         return 0;
 }
 
-static void journal_file_post_change(JournalFile *f) {
+void journal_file_post_change(JournalFile *f) {
         assert(f);
 
         /* inotify() does not receive IN_MODIFY events from file
@@ -989,9 +989,7 @@ int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const st
         if (ts->realtime < le64toh(f->header->tail_entry_realtime))
                 return -EINVAL;
 
-        items = new(EntryItem, n_iovec);
-        if (!items)
-                return -ENOMEM;
+        items = alloca(sizeof(EntryItem) * n_iovec);
 
         for (i = 0; i < n_iovec; i++) {
                 uint64_t p;
@@ -999,7 +997,7 @@ int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const st
 
                 r = journal_file_append_data(f, iovec[i].iov_base, iovec[i].iov_len, &o, &p);
                 if (r < 0)
-                        goto finish;
+                        return r;
 
                 xor_hash ^= le64toh(o->data.hash);
                 items[i].object_offset = htole64(p);
@@ -1010,9 +1008,6 @@ int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const st
 
         journal_file_post_change(f);
 
-finish:
-        free(items);
-
         return r;
 }
 
@@ -1999,3 +1994,85 @@ finish:
 
         return r;
 }
+
+int journal_file_copy_entry(JournalFile *from, JournalFile *to, Object *o, uint64_t p, uint64_t *seqnum, Object **ret, uint64_t *offset) {
+        uint64_t i, n;
+        uint64_t q, xor_hash = 0;
+        int r;
+        EntryItem *items;
+        dual_timestamp ts;
+
+        assert(from);
+        assert(to);
+        assert(o);
+        assert(p);
+
+        if (!to->writable)
+                return -EPERM;
+
+        ts.monotonic = le64toh(o->entry.monotonic);
+        ts.realtime = le64toh(o->entry.realtime);
+
+        if (to->tail_entry_monotonic_valid &&
+            ts.monotonic < le64toh(to->header->tail_entry_monotonic))
+                return -EINVAL;
+
+        if (ts.realtime < le64toh(to->header->tail_entry_realtime))
+                return -EINVAL;
+
+        n = journal_file_entry_n_items(o);
+        items = alloca(sizeof(EntryItem) * n);
+
+        for (i = 0; i < n; i++) {
+                uint64_t le_hash, l, h;
+                size_t t;
+                void *data;
+                Object *u;
+
+                q = le64toh(o->entry.items[i].object_offset);
+                le_hash = o->entry.items[i].hash;
+
+                r = journal_file_move_to_object(from, OBJECT_DATA, q, &o);
+                if (r < 0)
+                        return r;
+
+                if (le_hash != o->data.hash)
+                        return -EBADMSG;
+
+                l = le64toh(o->object.size) - offsetof(Object, data.payload);
+                t = (size_t) l;
+
+                /* We hit the limit on 32bit machines */
+                if ((uint64_t) t != l)
+                        return -E2BIG;
+
+                if (o->object.flags & OBJECT_COMPRESSED) {
+#ifdef HAVE_XZ
+                        uint64_t rsize;
+
+                        if (!uncompress_blob(o->data.payload, l, &from->compress_buffer, &from->compress_buffer_size, &rsize))
+                                return -EBADMSG;
+
+                        data = from->compress_buffer;
+                        l = rsize;
+#else
+                        return -EPROTONOSUPPORT;
+#endif
+                } else
+                        data = o->data.payload;
+
+                r = journal_file_append_data(to, data, l, &u, &h);
+                if (r < 0)
+                        return r;
+
+                xor_hash ^= le64toh(u->data.hash);
+                items[i].object_offset = htole64(h);
+                items[i].hash = u->data.hash;
+
+                r = journal_file_move_to_object(from, OBJECT_ENTRY, p, &o);
+                if (r < 0)
+                        return r;
+        }
+
+        return journal_file_append_entry_internal(to, &ts, xor_hash, items, n, seqnum, ret, offset);
+}
diff --git a/src/journal/journal-file.h b/src/journal/journal-file.h
index 421dfa6..ab2970c 100644
--- a/src/journal/journal-file.h
+++ b/src/journal/journal-file.h
@@ -113,10 +113,14 @@ int journal_file_move_to_entry_by_monotonic(JournalFile *f, sd_id128_t boot_id,
 int journal_file_move_to_entry_by_seqnum_for_data(JournalFile *f, uint64_t data_offset, uint64_t seqnum, direction_t direction, Object **ret, uint64_t *offset);
 int journal_file_move_to_entry_by_realtime_for_data(JournalFile *f, uint64_t data_offset, uint64_t realtime, direction_t direction, Object **ret, uint64_t *offset);
 
+int journal_file_copy_entry(JournalFile *from, JournalFile *to, Object *o, uint64_t p, uint64_t *seqnum, Object **ret, uint64_t *offset);
+
 void journal_file_dump(JournalFile *f);
 
 int journal_file_rotate(JournalFile **f);
 
 int journal_directory_vacuum(const char *directory, uint64_t max_use, uint64_t min_free);
 
+void journal_file_post_change(JournalFile *f);
+
 #endif
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 5a1cb6e..da4f510 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -454,7 +454,7 @@ int main(int argc, char *argv[]) {
         if (r <= 0)
                 goto finish;
 
-        r = sd_journal_open(&j);
+        r = sd_journal_open(&j, 0);
         if (r < 0) {
                 log_error("Failed to open journal: %s", strerror(-r));
                 goto finish;
diff --git a/src/journal/journald.c b/src/journal/journald.c
index e7231d9..1efe042 100644
--- a/src/journal/journald.c
+++ b/src/journal/journald.c
@@ -40,6 +40,8 @@
 #include "cgroup-util.h"
 #include "list.h"
 #include "journal-rate-limit.h"
+#include "sd-journal.h"
+#include "journal-internal.h"
 
 #define USER_JOURNALS_MAX 1024
 #define STDOUT_STREAMS_MAX 4096
@@ -107,6 +109,8 @@ struct StdoutStream {
         LIST_FIELDS(StdoutStream, stdout_stream);
 };
 
+static int server_flush_to_var(Server *s);
+
 static uint64_t available_space(Server *s) {
         char ids[33];
         sd_id128_t machine;
@@ -239,8 +243,12 @@ static JournalFile* find_journal(Server *s, uid_t uid) {
 
         assert(s);
 
-        /* We split up user logs only on /var, not on /run */
-        if (!s->system_journal)
+        /* We split up user logs only on /var, not on /run. If the
+         * runtime file is open, we write to it exclusively, in order
+         * to guarantee proper order as soon as we flush /run to
+         * /var and close the runtime file. */
+
+        if (s->runtime_journal)
                 return s->runtime_journal;
 
         if (uid <= 0)
@@ -486,6 +494,8 @@ static void dispatch_message_real(Server *s,
 
         assert(n <= m);
 
+        server_flush_to_var(s);
+
 retry:
         f = find_journal(s, realuid == 0 ? 0 : loginuid);
         if (!f)
@@ -1088,6 +1098,170 @@ fail:
         return r;
 }
 
+static int system_journal_open(Server *s) {
+        int r;
+        char *fn;
+        sd_id128_t machine;
+        char ids[33];
+
+        r = sd_id128_get_machine(&machine);
+        if (r < 0)
+                return r;
+
+        sd_id128_to_string(machine, ids);
+
+        if (!s->system_journal) {
+
+                /* First try to create the machine path, but not the prefix */
+                fn = strappend("/var/log/journal/", ids);
+                if (!fn)
+                        return -ENOMEM;
+                (void) mkdir(fn, 0755);
+                free(fn);
+
+                /* The create the system journal file */
+                fn = join("/var/log/journal/", ids, "/system.journal", NULL);
+                if (!fn)
+                        return -ENOMEM;
+
+                r = journal_file_open(fn, O_RDWR|O_CREAT, 0640, NULL, &s->system_journal);
+                free(fn);
+
+                if (r >= 0) {
+                        s->system_journal->metrics = s->metrics;
+                        s->system_journal->compress = s->compress;
+
+                        fix_perms(s->system_journal, 0);
+                } else if (r < 0) {
+
+                        if (r == -ENOENT)
+                                r = 0;
+                        else {
+                                log_error("Failed to open system journal: %s", strerror(-r));
+                                return r;
+                        }
+                }
+        }
+
+        if (!s->runtime_journal) {
+
+                fn = join("/run/log/journal/", ids, "/system.journal", NULL);
+                if (!fn)
+                        return -ENOMEM;
+
+                if (s->system_journal) {
+
+                        /* Try to open the runtime journal, but only
+                         * if it already exists, so that we can flush
+                         * it into the system journal */
+
+                        r = journal_file_open(fn, O_RDWR, 0640, NULL, &s->runtime_journal);
+                        free(fn);
+
+                        if (r < 0) {
+
+                                if (r == -ENOENT)
+                                        r = 0;
+                                else {
+                                        log_error("Failed to open runtime journal: %s", strerror(-r));
+                                        return r;
+                                }
+                        }
+
+                } else {
+
+                        /* OK, we really need the runtime journal, so create
+                         * it if necessary. */
+
+                        (void) mkdir_parents(fn, 0755);
+                        r = journal_file_open(fn, O_RDWR|O_CREAT, 0640, NULL, &s->runtime_journal);
+                        free(fn);
+
+                        if (r < 0) {
+                                log_error("Failed to open runtime journal: %s", strerror(-r));
+                                return r;
+                        }
+                }
+
+                if (s->runtime_journal) {
+                        s->runtime_journal->metrics = s->metrics;
+                        s->runtime_journal->compress = s->compress;
+
+                        fix_perms(s->runtime_journal, 0);
+                }
+        }
+
+        return r;
+}
+
+static int server_flush_to_var(Server *s) {
+        char path[] = "/run/log/journal/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
+        Object *o = NULL;
+        int r;
+        sd_id128_t machine;
+        sd_journal *j;
+
+        assert(s);
+
+        system_journal_open(s);
+
+        if (!s->system_journal || !s->runtime_journal)
+                return 0;
+
+        r = sd_id128_get_machine(&machine);
+        if (r < 0) {
+                log_error("Failed to get machine id: %s", strerror(-r));
+                return r;
+        }
+
+        r = sd_journal_open(&j, SD_JOURNAL_RUNTIME_ONLY);
+        if (r < 0) {
+                log_error("Failed to read runtime journal: %s", strerror(-r));
+                return r;
+        }
+
+        SD_JOURNAL_FOREACH(j) {
+                JournalFile *f;
+
+                f = j->current_file;
+                assert(f && f->current_offset > 0);
+
+                r = journal_file_move_to_object(f, OBJECT_ENTRY, f->current_offset, &o);
+                if (r < 0) {
+                        log_error("Can't read entry: %s", strerror(-r));
+                        goto finish;
+                }
+
+                r = journal_file_copy_entry(f, s->system_journal, o, f->current_offset, NULL, NULL, NULL);
+                if (r == -E2BIG) {
+                        log_info("Allocation limit reached.");
+
+                        journal_file_post_change(s->system_journal);
+                        server_vacuum(s);
+
+                        r = journal_file_copy_entry(f, s->system_journal, o, f->current_offset, NULL, NULL, NULL);
+                }
+
+                if (r < 0) {
+                        log_error("Can't write entry: %s", strerror(-r));
+                        goto finish;
+                }
+        }
+
+finish:
+        journal_file_post_change(s->system_journal);
+
+        journal_file_close(s->runtime_journal);
+        s->runtime_journal = NULL;
+
+        if (r >= 0) {
+                sd_id128_to_string(machine, path + 17);
+                rm_rf(path, false, true, false);
+        }
+
+        return r;
+}
+
 static int process_event(Server *s, struct epoll_event *ev) {
         assert(s);
 
@@ -1112,6 +1286,11 @@ static int process_event(Server *s, struct epoll_event *ev) {
                         return -errno;
                 }
 
+                if (sfsi.ssi_signo == SIGUSR1) {
+                        server_flush_to_var(s);
+                        return 0;
+                }
+
                 log_debug("Received SIG%s", signal_to_string(sfsi.ssi_signo));
                 return 0;
 
@@ -1247,66 +1426,6 @@ static int process_event(Server *s, struct epoll_event *ev) {
         return 0;
 }
 
-static int system_journal_open(Server *s) {
-        int r;
-        char *fn;
-        sd_id128_t machine;
-        char ids[33];
-
-        r = sd_id128_get_machine(&machine);
-        if (r < 0)
-                return r;
-
-        /* First try to create the machine path, but not the prefix */
-        fn = strappend("/var/log/journal/", sd_id128_to_string(machine, ids));
-        if (!fn)
-                return -ENOMEM;
-        (void) mkdir(fn, 0755);
-        free(fn);
-
-        /* The create the system journal file */
-        fn = join("/var/log/journal/", ids, "/system.journal", NULL);
-        if (!fn)
-                return -ENOMEM;
-
-        r = journal_file_open(fn, O_RDWR|O_CREAT, 0640, NULL, &s->system_journal);
-        free(fn);
-
-        if (r >= 0) {
-                s->system_journal->metrics = s->metrics;
-                s->system_journal->compress = s->compress;
-
-                fix_perms(s->system_journal, 0);
-                return r;
-        }
-
-        if (r < 0 && r != -ENOENT) {
-                log_error("Failed to open system journal: %s", strerror(-r));
-                return r;
-        }
-
-        /* /var didn't work, so try /run, but this time we
-         * create the prefix too */
-        fn = join("/run/log/journal/", ids, "/system.journal", NULL);
-        if (!fn)
-                return -ENOMEM;
-
-        (void) mkdir_parents(fn, 0755);
-        r = journal_file_open(fn, O_RDWR|O_CREAT, 0640, NULL, &s->runtime_journal);
-        free(fn);
-
-        if (r < 0) {
-                log_error("Failed to open runtime journal: %s", strerror(-r));
-                return r;
-        }
-
-        s->runtime_journal->metrics = s->metrics;
-        s->runtime_journal->compress = s->compress;
-
-        fix_perms(s->runtime_journal, 0);
-        return r;
-}
-
 static int open_syslog_socket(Server *s) {
         union sockaddr_union sa;
         int one, r;
@@ -1470,7 +1589,7 @@ static int open_signalfd(Server *s) {
         assert(s);
 
         assert_se(sigemptyset(&mask) == 0);
-        sigset_add_many(&mask, SIGINT, SIGTERM, -1);
+        sigset_add_many(&mask, SIGINT, SIGTERM, SIGUSR1, -1);
         assert_se(sigprocmask(SIG_SETMASK, &mask, NULL) == 0);
 
         s->signal_fd = signalfd(-1, &mask, SFD_NONBLOCK|SFD_CLOEXEC);
@@ -1652,6 +1771,9 @@ int main(int argc, char *argv[]) {
                   "READY=1\n"
                   "STATUS=Processing requests...");
 
+        server_vacuum(&server);
+        server_flush_to_var(&server);
+
         for (;;) {
                 struct epoll_event event;
 
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index 8fc8ec5..38e58f5 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -32,58 +32,10 @@
 #include "list.h"
 #include "lookup3.h"
 #include "compress.h"
+#include "journal-internal.h"
 
 #define JOURNAL_FILES_MAX 1024
 
-typedef struct Match Match;
-
-struct Match {
-        char *data;
-        size_t size;
-        uint64_t le_hash;
-
-        LIST_FIELDS(Match, matches);
-};
-
-typedef enum location_type {
-        LOCATION_HEAD,
-        LOCATION_TAIL,
-        LOCATION_DISCRETE
-} location_type_t;
-
-typedef struct Location {
-        location_type_t type;
-
-        uint64_t seqnum;
-        sd_id128_t seqnum_id;
-        bool seqnum_set;
-
-        uint64_t realtime;
-        bool realtime_set;
-
-        uint64_t monotonic;
-        sd_id128_t boot_id;
-        bool monotonic_set;
-
-        uint64_t xor_hash;
-        bool xor_hash_set;
-} Location;
-
-struct sd_journal {
-        Hashmap *files;
-
-        Location current_location;
-        JournalFile *current_file;
-        uint64_t current_field;
-
-        int inotify_fd;
-        Hashmap *inotify_wd_dirs;
-        Hashmap *inotify_wd_roots;
-
-        LIST_HEAD(Match, matches);
-        unsigned n_matches;
-};
-
 static void detach_location(sd_journal *j) {
         Iterator i;
         JournalFile *f;
@@ -948,6 +900,10 @@ static int add_file(sd_journal *j, const char *prefix, const char *dir, const ch
         assert(prefix);
         assert(filename);
 
+        if ((j->flags & SD_JOURNAL_SYSTEM_ONLY) &&
+            !startswith(filename, "system.journal"))
+                return 0;
+
         if (dir)
                 fn = join(prefix, "/", dir, "/", filename, NULL);
         else
@@ -1024,11 +980,18 @@ static int add_directory(sd_journal *j, const char *prefix, const char *dir) {
         int r;
         DIR *d;
         int wd;
+        sd_id128_t id, mid;
 
         assert(j);
         assert(prefix);
         assert(dir);
 
+        if ((j->flags & SD_JOURNAL_LOCAL_ONLY) &&
+            (sd_id128_from_string(dir, &id) < 0 ||
+             sd_id128_get_machine(&mid) < 0 ||
+             !sd_id128_equal(id, mid)))
+            return 0;
+
         fn = join(prefix, "/", dir, NULL);
         if (!fn)
                 return -ENOMEM;
@@ -1132,7 +1095,7 @@ static void remove_root_wd(sd_journal *j, int wd) {
         }
 }
 
-int sd_journal_open(sd_journal **ret) {
+int sd_journal_open(sd_journal **ret, int flags) {
         sd_journal *j;
         const char *p;
         const char search_paths[] =
@@ -1146,6 +1109,8 @@ int sd_journal_open(sd_journal **ret) {
         if (!j)
                 return -ENOMEM;
 
+        j->flags = flags;
+
         j->inotify_fd = inotify_init1(IN_NONBLOCK|IN_CLOEXEC);
         if (j->inotify_fd < 0) {
                 r = -errno;
@@ -1172,6 +1137,10 @@ int sd_journal_open(sd_journal **ret) {
         NULSTR_FOREACH(p, search_paths) {
                 DIR *d;
 
+                if ((flags & SD_JOURNAL_RUNTIME_ONLY) &&
+                    !path_startswith(p, "/run"))
+                        continue;
+
                 d = opendir(p);
                 if (!d) {
                         if (errno != ENOENT)
diff --git a/src/journal/sd-journal.h b/src/journal/sd-journal.h
index 7f9f785..f6b1c95 100644
--- a/src/journal/sd-journal.h
+++ b/src/journal/sd-journal.h
@@ -31,19 +31,20 @@
 
 /* TODO:
  *
- *   - check LE/BE conversion for 8bit, 16bit, 32bit values
- *   - implement audit gateway
+ *   - OR of matches is borked...
  *   - extend hash tables table as we go
  *   - accelerate looking for "all hostnames" and suchlike.
- *   - cryptographic hash
- *   - OR of matches is borked...
- *   - flush /run to /var
  *   - hookup with systemctl
+ *   - handle incomplete header
+ *
  *   - local deserializer
- *   - think about manipulations of header
  *   - http server
- *   - handle incomplete header
  *   - message catalog
+ *
+ *   - check LE/BE conversion for 8bit, 16bit, 32bit values
+ *   - cryptographic hash
+ *   - think about manipulations of header
+ *   - implement audit gateway
  */
 
 /* Write to daemon */
@@ -60,7 +61,13 @@ int sd_journal_stream_fd(const char *tag, int priority, int priority_prefix);
 
 typedef struct sd_journal sd_journal;
 
-int sd_journal_open(sd_journal **ret);
+enum {
+        SD_JOURNAL_LOCAL_ONLY = 1,
+        SD_JOURNAL_RUNTIME_ONLY = 2,
+        SD_JOURNAL_SYSTEM_ONLY = 4
+};
+
+int sd_journal_open(sd_journal **ret, int flags);
 void sd_journal_close(sd_journal *j);
 
 int sd_journal_previous(sd_journal *j);

commit de97b26ac5e29063632312ec1a20eb6318ca924c
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Dec 29 15:00:05 2011 +0100

    journald: increase rate limit burst rate

diff --git a/src/journal/journald.c b/src/journal/journald.c
index c216b78..e7231d9 100644
--- a/src/journal/journald.c
+++ b/src/journal/journald.c
@@ -44,6 +44,9 @@
 #define USER_JOURNALS_MAX 1024
 #define STDOUT_STREAMS_MAX 4096
 
+#define DEFAULT_RATE_LIMIT_INTERVAL (10*USEC_PER_SEC)
+#define DEFAULT_RATE_LIMIT_BURST 200
+
 #define RECHECK_AVAILABLE_SPACE_USEC (30*USEC_PER_SEC)
 
 typedef struct StdoutStream StdoutStream;
@@ -1574,7 +1577,7 @@ static int server_init(Server *s) {
         if (r < 0)
                 return r;
 
-        s->rate_limit = journal_rate_limit_new(10*USEC_PER_SEC, 2);
+        s->rate_limit = journal_rate_limit_new(DEFAULT_RATE_LIMIT_INTERVAL, DEFAULT_RATE_LIMIT_BURST);
         if (!s->rate_limit)
                 return -ENOMEM;
 

commit 2a59ea54f136f8fcf6a4e1bdfc51448c81281a3e
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Dec 28 01:53:06 2011 +0100

    journal: never mmap beyond file size

diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 80775e1..6c7718d 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -241,6 +241,10 @@ static int journal_file_map(
         wsize = size + (offset - woffset);
         wsize = PAGE_ALIGN(wsize);
 
+        /* Avoid SIGBUS on invalid accesses */
+        if (woffset + wsize > (uint64_t) PAGE_ALIGN(f->last_stat.st_size))
+                return -EADDRNOTAVAIL;
+
         window = mmap(NULL, wsize, f->prot, MAP_SHARED, f->fd, woffset);
         if (window == MAP_FAILED)
                 return -errno;
@@ -305,6 +309,15 @@ static int journal_file_move_to(JournalFile *f, int wt, uint64_t offset, uint64_
         } else
                 delta = 0;
 
+        if (offset > (uint64_t) f->last_stat.st_size)
+                return -EADDRNOTAVAIL;
+
+        if (offset + size > (uint64_t) f->last_stat.st_size)
+                size = PAGE_ALIGN((uint64_t) f->last_stat.st_size - offset);
+
+        if (size <= 0)
+                return -EADDRNOTAVAIL;
+
         r = journal_file_map(f,
                              offset, size,
                              &w->ptr, &w->offset, &w->size,
diff --git a/src/journal/sd-journal.h b/src/journal/sd-journal.h
index 9872e9c..7f9f785 100644
--- a/src/journal/sd-journal.h
+++ b/src/journal/sd-journal.h
@@ -36,8 +36,14 @@
  *   - extend hash tables table as we go
  *   - accelerate looking for "all hostnames" and suchlike.
  *   - cryptographic hash
- *   - never access beyond fle size check
  *   - OR of matches is borked...
+ *   - flush /run to /var
+ *   - hookup with systemctl
+ *   - local deserializer
+ *   - think about manipulations of header
+ *   - http server
+ *   - handle incomplete header
+ *   - message catalog
  */
 
 /* Write to daemon */

commit 9cfb57c989b62d11c073c77179df4bb7fa19f35d
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Dec 27 23:18:09 2011 +0100

    journald: when checking available disk space for rate limiting, cache the results temporarily

diff --git a/src/journal/journald.c b/src/journal/journald.c
index 9f75301..c216b78 100644
--- a/src/journal/journald.c
+++ b/src/journal/journald.c
@@ -44,6 +44,8 @@
 #define USER_JOURNALS_MAX 1024
 #define STDOUT_STREAMS_MAX 4096
 
+#define RECHECK_AVAILABLE_SPACE_USEC (30*USEC_PER_SEC)
+
 typedef struct StdoutStream StdoutStream;
 
 typedef struct Server {
@@ -68,6 +70,9 @@ typedef struct Server {
         uint64_t max_use;
         bool compress;
 
+        uint64_t cached_available_space;
+        usec_t cached_available_space_timestamp;
+
         LIST_HEAD(StdoutStream, stdout_streams);
         unsigned n_stdout_streams;
 } Server;
@@ -108,6 +113,10 @@ static uint64_t available_space(Server *s) {
         uint64_t sum = 0, avail = 0, ss_avail = 0;
         int r;
         DIR *d;
+        usec_t ts = now(CLOCK_MONOTONIC);
+
+        if (s->cached_available_space_timestamp + RECHECK_AVAILABLE_SPACE_USEC > ts)
+                return s->cached_available_space;
 
         r = sd_id128_get_machine(&machine);
         if (r < 0)
@@ -163,6 +172,9 @@ static uint64_t available_space(Server *s) {
         if (ss_avail < avail)
                 avail = ss_avail;
 
+        s->cached_available_space = avail;
+        s->cached_available_space_timestamp = ts;
+
 finish:
         closedir(d);
 
@@ -326,6 +338,8 @@ static void server_vacuum(Server *s) {
         if (r < 0 && r != -ENOENT)
                 log_error("Failed to vacuum %s: %s", p, strerror(-r));
         free(p);
+
+        s->cached_available_space_timestamp = 0;
 }
 
 static char *shortened_cgroup_path(pid_t pid) {

commit 85a131e8d8aa9fe3c2115e281569bed64a4200f1
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Dec 27 22:58:20 2011 +0100

    journal: fix hash table lookup logic

diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 4a006d3..80775e1 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -595,7 +595,7 @@ int journal_file_find_data_object_with_hash(
                         return r;
 
                 if (le64toh(o->data.hash) != hash)
-                        return -EBADMSG;
+                        goto next;
 
                 if (o->object.flags & OBJECT_COMPRESSED) {
 #ifdef HAVE_XZ
@@ -637,6 +637,7 @@ int journal_file_find_data_object_with_hash(
                         return 1;
                 }
 
+        next:
                 p = le64toh(o->data.next_hash_offset);
         }
 
diff --git a/src/journal/sd-journal.h b/src/journal/sd-journal.h
index 7e2ef15..9872e9c 100644
--- a/src/journal/sd-journal.h
+++ b/src/journal/sd-journal.h
@@ -35,7 +35,6 @@
  *   - implement audit gateway
  *   - extend hash tables table as we go
  *   - accelerate looking for "all hostnames" and suchlike.
- *   - throttling
  *   - cryptographic hash
  *   - never access beyond fle size check
  *   - OR of matches is borked...



More information about the systemd-commits mailing list