richardphibel / rpms / systemd

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