[systemd-commits] 2 commits - src/journal
Lennart Poettering
lennart at kemper.freedesktop.org
Fri Sep 28 06:42:42 PDT 2012
src/journal/journald.c | 106 ++++++++++++++++++++++++++++---------------------
1 file changed, 61 insertions(+), 45 deletions(-)
New commits:
commit 760c85c0bdf02d68589971b869f61038e7893d75
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Sep 28 15:42:34 2012 +0200
journald: rework auto-rotation logic
diff --git a/src/journal/journald.c b/src/journal/journald.c
index a1506b2..0910d7d 100644
--- a/src/journal/journald.c
+++ b/src/journal/journald.c
@@ -440,6 +440,35 @@ static char *shortened_cgroup_path(pid_t pid) {
return path;
}
+static bool shall_try_append_again(JournalFile *f, int r) {
+
+ /* -E2BIG Hit configured limit
+ -EFBIG Hit fs limit
+ -EDQUOT Quota limit hit
+ -ENOSPC Disk full
+ -EHOSTDOWN Other machine
+ -EBUSY Unclean shutdown
+ -EPROTONOSUPPORT Unsupported feature
+ -EBADMSG Corrupted
+ -ENODATA Truncated
+ -ESHUTDOWN Already archived */
+
+ if (r == -E2BIG || r == -EFBIG || r == -EDQUOT || r == -ENOSPC)
+ log_debug("%s: Allocation limit reached, rotating.", f->path);
+ else if (r == -EHOSTDOWN)
+ log_info("%s: Journal file from other machine, rotating.", f->path);
+ else if (r == -EBUSY)
+ log_info("%s: Unclean shutdown, rotating.", f->path);
+ else if (r == -EPROTONOSUPPORT)
+ log_info("%s: Unsupported feature, rotating.", f->path);
+ else if (r == -EBADMSG || r == -ENODATA || r == ESHUTDOWN)
+ log_warning("%s: Journal file corrupted, rotating.", f->path);
+ else
+ return false;
+
+ return true;
+}
+
static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned n) {
JournalFile *f;
bool vacuumed = false;
@@ -454,7 +483,7 @@ static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned
return;
if (journal_file_rotate_suggested(f)) {
- log_debug("Journal header limits reached or header out-of-date, rotating.");
+ log_debug("%s: Journal header limits reached or header out-of-date, rotating.", f->path);
server_rotate(s);
server_vacuum(s);
vacuumed = true;
@@ -464,45 +493,26 @@ static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned
return;
}
- for (;;) {
- r = journal_file_append_entry(f, NULL, iovec, n, &s->seqnum, NULL, NULL);
- if (r >= 0)
- return;
-
- if (vacuumed ||
- (r != -E2BIG && /* hit limit */
- r != -EFBIG && /* hit fs limit */
- r != -EDQUOT && /* quota hit */
- r != -ENOSPC && /* disk full */
- r != -EBADMSG && /* corrupted */
- r != -ENODATA && /* truncated */
- r != -EHOSTDOWN && /* other machine */
- r != -EPROTONOSUPPORT && /* unsupported feature */
- r != -EBUSY && /* unclean shutdown */
- r != -ESHUTDOWN /* already archived */)) {
- log_error("Failed to write entry, ignoring: %s", strerror(-r));
- return;
- }
+ r = journal_file_append_entry(f, NULL, iovec, n, &s->seqnum, NULL, NULL);
+ if (r >= 0)
+ return;
- if (r == -E2BIG || r == -EFBIG || r == EDQUOT || r == ENOSPC)
- log_debug("Allocation limit reached, rotating.");
- else if (r == -EHOSTDOWN)
- log_info("Journal file from other machine, rotating.");
- else if (r == -EBUSY)
- log_info("Unclean shutdown, rotating.");
- else
- log_warning("Journal file corrupted, rotating.");
+ if (vacuumed || !shall_try_append_again(f, r)) {
+ log_error("Failed to write entry, ignoring: %s", strerror(-r));
+ return;
+ }
- server_rotate(s);
- server_vacuum(s);
- vacuumed = true;
+ server_rotate(s);
+ server_vacuum(s);
- f = find_journal(s, uid);
- if (!f)
- return;
+ f = find_journal(s, uid);
+ if (!f)
+ return;
- log_debug("Retrying write.");
- }
+ log_debug("Retrying write.");
+ r = journal_file_append_entry(f, NULL, iovec, n, &s->seqnum, NULL, NULL);
+ if (r < 0)
+ log_error("Failed to write entry, ignoring: %s", strerror(-r));
}
static void dispatch_message_real(
@@ -942,16 +952,19 @@ static int server_flush_to_var(Server *s) {
}
r = journal_file_copy_entry(f, s->system_journal, o, f->current_offset, NULL, NULL, NULL);
- if (r == -E2BIG) {
- log_debug("Allocation limit reached.");
-
- journal_file_post_change(s->system_journal);
- server_rotate(s);
- server_vacuum(s);
+ if (r >= 0)
+ continue;
- r = journal_file_copy_entry(f, s->system_journal, o, f->current_offset, NULL, NULL, NULL);
+ if (!shall_try_append_again(s->system_journal, r)) {
+ log_error("Can't write entry: %s", strerror(-r));
+ goto finish;
}
+ server_rotate(s);
+ server_vacuum(s);
+
+ log_debug("Retrying write.");
+ 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;
commit 80d1c5988bfd804bc9494a33a5db5a16609cdb48
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Sep 28 15:41:20 2012 +0200
journald: close sd_journal context after flushing to /var
diff --git a/src/journal/journald.c b/src/journal/journald.c
index 3267fff..a1506b2 100644
--- a/src/journal/journald.c
+++ b/src/journal/journald.c
@@ -896,10 +896,9 @@ static int system_journal_open(Server *s) {
}
static int server_flush_to_var(Server *s) {
- Object *o = NULL;
int r;
sd_id128_t machine;
- sd_journal *j;
+ sd_journal *j = NULL;
assert(s);
@@ -930,6 +929,7 @@ static int server_flush_to_var(Server *s) {
}
SD_JOURNAL_FOREACH(j) {
+ Object *o = NULL;
JournalFile *f;
f = j->current_file;
@@ -967,6 +967,9 @@ finish:
if (r >= 0)
rm_rf("/run/log/journal", false, true, false);
+ if (j)
+ sd_journal_close(j);
+
return r;
}
More information about the systemd-commits
mailing list