Switch max_size from virConfGetValueSizeT() to virConfGetValueBytes(),
so it accepts "2MiB" the same way domain XML memory sizes do, instead
of only a raw byte count.

virtlogd.aug accepts the quoted form too; its quoted branch requires a
unit suffix, as one matching a bare number would overlap the integer
branch.

Signed-off-by: Denis V. Lunev <[email protected]>
Reviewed-by: Daniel P. BerrangĂ© <[email protected]>
---
 NEWS.rst                         | 5 +++++
 src/logging/log_daemon_config.c  | 2 +-
 src/logging/log_daemon_config.h  | 2 +-
 src/logging/test_virtlogd.aug.in | 2 +-
 src/logging/virtlogd.aug         | 5 ++++-
 src/logging/virtlogd.conf        | 7 ++++++-
 6 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/NEWS.rst b/NEWS.rst
index 529546f02e..357f9cda10 100644
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -26,6 +26,11 @@ v12.8.0 (unreleased)
     available only to a guest that can use it, such dumps are now written in
     win-dmp format instead.
 
+  * logging: ``max_size`` in virtlogd.conf accepts a unit suffix
+
+    The setting now takes a size such as ``"2MiB"`` as well as a plain byte
+    count.
+
 * **Bug fixes**
 
 
diff --git a/src/logging/log_daemon_config.c b/src/logging/log_daemon_config.c
index 60c424ad84..e0d6384818 100644
--- a/src/logging/log_daemon_config.c
+++ b/src/logging/log_daemon_config.c
@@ -91,7 +91,7 @@ virLogDaemonConfigLoadOptions(virLogDaemonConfig *data,
         return -1;
     if (virConfGetValueUInt(conf, "admin_max_clients", 
&data->admin_max_clients) < 0)
         return -1;
-    if (virConfGetValueSizeT(conf, "max_size", &data->max_size) < 0)
+    if (virConfGetValueBytes(conf, "max_size", &data->max_size) < 0)
         return -1;
     if (virConfGetValueSizeT(conf, "max_backups", &data->max_backups) < 0)
         return -1;
diff --git a/src/logging/log_daemon_config.h b/src/logging/log_daemon_config.h
index 5c10cc50d7..617b62258b 100644
--- a/src/logging/log_daemon_config.h
+++ b/src/logging/log_daemon_config.h
@@ -32,7 +32,7 @@ struct _virLogDaemonConfig {
     unsigned int admin_max_clients;
 
     size_t max_backups;
-    size_t max_size;
+    unsigned long long max_size;
 
     char *log_root;
     size_t max_age_days;
diff --git a/src/logging/test_virtlogd.aug.in b/src/logging/test_virtlogd.aug.in
index 8dfad39506..da1c8530d1 100644
--- a/src/logging/test_virtlogd.aug.in
+++ b/src/logging/test_virtlogd.aug.in
@@ -7,7 +7,7 @@ module Test_virtlogd =
         { "log_outputs" = "3:syslog:virtlogd" }
         { "max_clients" = "1024" }
         { "admin_max_clients" = "5" }
-        { "max_size" = "2097152" }
+        { "max_size" = "2MiB" }
         { "max_backups" = "3" }
         { "max_age_days" = "0" }
         { "log_root" = "/var/log/libvirt" }
diff --git a/src/logging/virtlogd.aug b/src/logging/virtlogd.aug
index bdf61dea6e..17b2aea452 100644
--- a/src/logging/virtlogd.aug
+++ b/src/logging/virtlogd.aug
@@ -22,6 +22,9 @@ module Virtlogd =
    let int_entry      (kw:string) = [ key kw . value_sep . int_val ]
    let str_array_entry (kw:string) = [ key kw . value_sep . str_array_val ]
 
+   let bytes_val = del /\"/ "\"" . store /[0-9]+[a-zA-Z]+/ . del /\"/ "\""
+   let bytes_entry    (kw:string) = [ key kw . value_sep . bytes_val ] | [ key 
kw . value_sep . int_val ]
+
 
    (* Config entry grouped by function - same order as example config *)
    let logging_entry = int_entry "log_level"
@@ -29,7 +32,7 @@ module Virtlogd =
                      | str_entry "log_outputs"
                      | int_entry "max_clients"
                      | int_entry "admin_max_clients"
-                     | int_entry "max_size"
+                     | bytes_entry "max_size"
                      | int_entry "max_backups"
                      | int_entry "max_age_days"
                      | str_entry "log_root"
diff --git a/src/logging/virtlogd.conf b/src/logging/virtlogd.conf
index 5214e96121..51bc0590ed 100644
--- a/src/logging/virtlogd.conf
+++ b/src/logging/virtlogd.conf
@@ -87,6 +87,11 @@
 
 # Maximum file size before rolling over. Defaults to 2 MB
 #
+# The value is a plain byte count, or a byte count followed by a unit
+# suffix: bytes/b, KB/k/KiB, MB/M/MiB, GB/G/GiB, TB/T/TiB, PB/P/PiB, or
+# EB/E/EiB (decimal 'B' suffixes scale by 1000, binary 'iB' suffixes,
+# and their bare single-letter equivalents, scale by 1024).
+#
 # Setting max_size to zero will disable rollover entirely.
 # NOTE: disabling rollover exposes the host filesystem to
 # denial of service from a malicious guest.
@@ -96,7 +101,7 @@
 # the logrotate config is a no-op when virtlogd is running,
 # make sure that max_size here is smaller than size listed
 # in the logrotate config.
-#max_size = 2097152
+#max_size = "2MiB"
 
 # Maximum number of backup files to keep. Defaults to 3,
 # not including the primary active file
-- 
2.53.0

Reply via email to