Pablo Greco 48fc63
From 467f1b0cec3d48ddbf61aaa000757af82394609e Mon Sep 17 00:00:00 2001
Pablo Greco 48fc63
From: Jan Synacek <jsynacek@redhat.com>
Pablo Greco 48fc63
Date: Mon, 22 Oct 2018 12:15:07 +0200
Pablo Greco 48fc63
Subject: [PATCH] journald: respect KeepFree= as well as MaxUse= values
Pablo Greco 48fc63
Pablo Greco 48fc63
Resolves: #1361893
Pablo Greco 48fc63
---
Pablo Greco 48fc63
 src/journal/journald-server.c | 15 ++++++++++++++-
Pablo Greco 48fc63
 1 file changed, 14 insertions(+), 1 deletion(-)
Pablo Greco 48fc63
Pablo Greco 48fc63
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
Pablo Greco 48fc63
index 88cf0b2d53..2e1e07eb0e 100644
Pablo Greco 48fc63
--- a/src/journal/journald-server.c
Pablo Greco 48fc63
+++ b/src/journal/journald-server.c
Pablo Greco 48fc63
@@ -557,6 +557,8 @@ static void do_vacuum(
Pablo Greco 48fc63
                 const char* path,
Pablo Greco 48fc63
                 JournalMetrics *metrics) {
Pablo Greco 48fc63
 
Pablo Greco 48fc63
+        uint64_t total, limit = metrics->max_use;
Pablo Greco 48fc63
+        struct statvfs st;
Pablo Greco 48fc63
         const char *p;
Pablo Greco 48fc63
         int r;
Pablo Greco 48fc63
 
Pablo Greco 48fc63
@@ -564,7 +566,18 @@ static void do_vacuum(
Pablo Greco 48fc63
                 return;
Pablo Greco 48fc63
 
Pablo Greco 48fc63
         p = strjoina(path, id);
Pablo Greco 48fc63
-        r = journal_directory_vacuum(p, metrics->max_use, s->max_retention_usec, &s->oldest_file_usec, false);
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+        r = statvfs(p, &st);
Pablo Greco 48fc63
+        if (r < 0) {
Pablo Greco 48fc63
+                log_error_errno(r, "Failed to statvfs: %s", p);
Pablo Greco 48fc63
+                return;
Pablo Greco 48fc63
+        }
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+        total = st.f_bsize * st.f_blocks;
Pablo Greco 48fc63
+        if (total - metrics->keep_free < limit)
Pablo Greco 48fc63
+                limit = total - metrics->keep_free;
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+        r = journal_directory_vacuum(p, limit, s->max_retention_usec, &s->oldest_file_usec, false);
Pablo Greco 48fc63
         if (r < 0 && r != -ENOENT)
Pablo Greco 48fc63
                 log_error_errno(r, "Failed to vacuum %s: %m", p);
Pablo Greco 48fc63
 }