[PATCH] Add support for timestamping QEMU logs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



QEMU commit 5e2ac51 added a boolean '-msg timestamp=[on|off]'
option, which can enable timestamps on errors:
$ qemu-system-x86_64 -msg timestamp=on zghhdorf
2014-04-09T13:25:46.779484Z qemu-system-x86_64: -msg timestamp=on: could
not open disk image zghhdorf: Could not open 'zghhdorf': No such file or
directory

Enable this timestamp if the QEMU binary supports it.

Add a 'log_timestamp' option to qemu.conf for disabling this behavior.
---
 src/qemu/libvirtd_qemu.aug                    | 3 +++
 src/qemu/qemu.conf                            | 8 ++++++++
 src/qemu/qemu_capabilities.c                  | 5 +++++
 src/qemu/qemu_capabilities.h                  | 1 +
 src/qemu/qemu_command.c                       | 4 ++++
 src/qemu/qemu_conf.c                          | 4 ++++
 src/qemu/qemu_conf.h                          | 2 ++
 src/qemu/test_libvirtd_qemu.aug.in            | 1 +
 tests/qemucapabilitiesdata/caps_1.6.0-1.caps  | 1 +
 tests/qemucapabilitiesdata/caps_1.6.50-1.caps | 1 +
 tests/qemuxml2argvtest.c                      | 1 +
 11 files changed, 31 insertions(+)

diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug
index a9ff421..e985d22 100644
--- a/src/qemu/libvirtd_qemu.aug
+++ b/src/qemu/libvirtd_qemu.aug
@@ -85,6 +85,8 @@ module Libvirtd_qemu =
                  | int_entry "migration_port_min"
                  | int_entry "migration_port_max"
 
+   let log_entry = bool_entry "log_timestamp"
+
    (* Each entry in the config is one of the following ... *)
    let entry = vnc_entry
              | spice_entry
@@ -96,6 +98,7 @@ module Libvirtd_qemu =
              | device_entry
              | rpc_entry
              | network_entry
+             | log_entry
 
    let comment = [ label "#comment" . del /#[ \t]*/ "# " .  store /([^ \t\n][^\n]*)?/ . del /\n/ "\n" ]
    let empty = [ label "#empty" . eol ]
diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf
index f0e802f..42f812d 100644
--- a/src/qemu/qemu.conf
+++ b/src/qemu/qemu.conf
@@ -465,3 +465,11 @@
 #
 #migration_port_min = 49152
 #migration_port_max = 49215
+
+
+
+# Timestamp QEMU's log messages (if QEMU supports it)
+#
+# Defaults to 1.
+#
+#log_timestamp = 0
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 381b3ec..71bf5f2 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -254,6 +254,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
               "spiceport",
 
               "usb-kbd", /* 165 */
+              "msg-timestamp",
     );
 
 
@@ -1143,6 +1144,9 @@ virQEMUCapsComputeCmdFlags(const char *help,
     if (strstr(help, "-machine"))
         virQEMUCapsSet(qemuCaps, QEMU_CAPS_MACHINE_OPT);
 
+    if (strstr(help, "-msg timestamp"))
+        virQEMUCapsSet(qemuCaps, QEMU_CAPS_MSG_TIMESTAMP);
+
      /* USB option is supported v1.3.0 onwards */
     if (qemuCaps->version >= 1003000)
         virQEMUCapsSet(qemuCaps, QEMU_CAPS_MACHINE_USB_OPT);
@@ -2329,6 +2333,7 @@ static struct virQEMUCapsCommandLineProps virQEMUCapsCommandLine[] = {
     { "boot-opts", "strict", QEMU_CAPS_BOOT_STRICT },
     { "boot-opts", "reboot-timeout", QEMU_CAPS_REBOOT_TIMEOUT },
     { "spice", "disable-agent-file-xfer", QEMU_CAPS_SPICE_FILE_XFER_DISABLE },
+    { "msg", "timestamp", QEMU_CAPS_MSG_TIMESTAMP },
 };
 
 static int
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index df8c978..f1ea05b 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -204,6 +204,7 @@ enum virQEMUCapsFlags {
     QEMU_CAPS_SPICE_FILE_XFER_DISABLE = 163, /* -spice disable-agent-file-xfer */
     QEMU_CAPS_CHARDEV_SPICEPORT  = 164, /* -chardev spiceport */
     QEMU_CAPS_DEVICE_USB_KBD     = 165, /* -device usb-kbd */
+    QEMU_CAPS_MSG_TIMESTAMP      = 166, /* -msg timestamp */
 
     QEMU_CAPS_LAST,                   /* this must always be the last item */
 };
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 379c094..286070a 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -9735,6 +9735,10 @@ qemuBuildCommandLine(virConnectPtr conn,
         virCommandSetMaxMemLock(cmd, memKB * 1024);
     }
 
+    if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_MSG_TIMESTAMP) &&
+        cfg->logTimestamp)
+        virCommandAddArgList(cmd, "-msg", "timestamp=on", NULL);
+
     virObjectUnref(cfg);
     return cmd;
 
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 198ee2f..e487f5e 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -255,6 +255,8 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
     cfg->keepAliveCount = 5;
     cfg->seccompSandbox = -1;
 
+    cfg->logTimestamp = true;
+
     return cfg;
 
  error:
@@ -576,6 +578,8 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
 
     GET_VALUE_STR("migration_address", cfg->migrationAddress);
 
+    GET_VALUE_BOOL("log_timestamp", cfg->logTimestamp);
+
     ret = 0;
 
  cleanup:
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index a36ea63..5d2983a 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -167,6 +167,8 @@ struct _virQEMUDriverConfig {
     char *migrationAddress;
     int migrationPortMin;
     int migrationPortMax;
+
+    bool logTimestamp;
 };
 
 /* Main driver state */
diff --git a/src/qemu/test_libvirtd_qemu.aug.in b/src/qemu/test_libvirtd_qemu.aug.in
index b2328d3..30a4257 100644
--- a/src/qemu/test_libvirtd_qemu.aug.in
+++ b/src/qemu/test_libvirtd_qemu.aug.in
@@ -72,3 +72,4 @@ module Test_libvirtd_qemu =
 { "migration_address" = "127.0.0.1" }
 { "migration_port_min" = "49152" }
 { "migration_port_max" = "49215" }
+{ "log_timestamp" = "0" }
diff --git a/tests/qemucapabilitiesdata/caps_1.6.0-1.caps b/tests/qemucapabilitiesdata/caps_1.6.0-1.caps
index 597f873..55ad973 100644
--- a/tests/qemucapabilitiesdata/caps_1.6.0-1.caps
+++ b/tests/qemucapabilitiesdata/caps_1.6.0-1.caps
@@ -142,4 +142,5 @@
     <flag name='spice-file-xfer-disable'/>
     <flag name='spiceport'/>
     <flag name='usb-kbd'/>
+    <flag name='msg-timestamp'/>
   </qemuCaps>
diff --git a/tests/qemucapabilitiesdata/caps_1.6.50-1.caps b/tests/qemucapabilitiesdata/caps_1.6.50-1.caps
index 0c1dd87..37b1a9a 100644
--- a/tests/qemucapabilitiesdata/caps_1.6.50-1.caps
+++ b/tests/qemucapabilitiesdata/caps_1.6.50-1.caps
@@ -140,4 +140,5 @@
     <flag name='spice-file-xfer-disable'/>
     <flag name='spiceport'/>
     <flag name='usb-kbd'/>
+    <flag name='msg-timestamp'/>
   </qemuCaps>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 13ed4f6..3e81998 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -582,6 +582,7 @@ mymain(void)
     unsetenv("SDL_AUDIODRIVER");
 
     DO_TEST("minimal", QEMU_CAPS_NAME);
+    DO_TEST("minimal-msg-timestamp", QEMU_CAPS_NAME, QEMU_CAPS_MSG_TIMESTAMP);
     DO_TEST("minimal-s390", QEMU_CAPS_NAME);
     DO_TEST("machine-aliases1", NONE);
     DO_TEST("machine-aliases2", QEMU_CAPS_KVM);
-- 
1.8.3.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]