teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/0728-journald-respect-KeepFree-as-well-as-MaxUse-values.patch

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