qemu-trivial
[Top][All Lists]
Advanced

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

Re: [PATCHv2 1/2] util/qemu-error: add guest name helper with -msg optio


From: Paolo Bonzini
Subject: Re: [PATCHv2 1/2] util/qemu-error: add guest name helper with -msg options
Date: Thu, 10 Oct 2019 13:25:36 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0

[Sorry Markus, I missed this message before]

On 10/10/19 10:16, Markus Armbruster wrote:
> I don't think merging this via qemu-trivial is a good idea.  First, it's
> not sufficiently trivial, as we shall see below.  Second, the code in
> question has a maintainer willing to review and merge patches: me.  I
> can't always review as quickly as we all would like; sorry about that.

Yes, it's not trivial indeed.

I think I can pick up v2 2/2 separately.  Since I had already started 
working on resolving conflicts before seeing your reply, I will leave
here my resulting patch, for Mario to pick up.

diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h
index 87532d8596..4d3ee6f00c 100644
--- a/include/qemu/error-report.h
+++ b/include/qemu/error-report.h
@@ -75,5 +75,6 @@ void error_init(const char *argv0);
 const char *error_get_progname(void);
 
 extern bool error_with_timestamp;
+extern bool error_with_guest_name;
 
 #endif
diff --git a/qemu-options.hx b/qemu-options.hx
index 158244da0f..70a76069a6 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -4164,17 +4164,20 @@ HXCOMM Deprecated by -accel tcg
 DEF("no-kvm", 0, QEMU_OPTION_no_kvm, "", QEMU_ARCH_I386)
 
 DEF("msg", HAS_ARG, QEMU_OPTION_msg,
-    "-msg timestamp[=on|off]\n"
-    "                control error message format\n"
-    "                timestamp=on enables timestamps (default: off)\n",
+    "-msg [timestamp=on|off][,name=on|off]\n"
+    "                change the format of messages\n"
+    "                timestamp=on|off prepend timestamps (default: off)\n"
+    "                name=on|off prepend guest name (default: off)\n",
     QEMU_ARCH_ALL)
 STEXI
-@item -msg timestamp[=on|off]
+@item -msg
 @findex -msg
 Control error message format.
 @table @option
 @item timestamp=on|off
 Prefix messages with a timestamp.  Default is off.
+@item name=on|off
+Prefix messages with the name of the guest.  Default is off.
 @end table
 ETEXI
 
diff --git a/util/qemu-error.c b/util/qemu-error.c
index dac7c7dc50..497217298f 100644
--- a/util/qemu-error.c
+++ b/util/qemu-error.c
@@ -11,6 +11,8 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/option.h"
+#include "qemu/config-file.h"
 #include "monitor/monitor.h"
 #include "qemu/error-report.h"
 
@@ -27,6 +29,9 @@ typedef enum {
 /* Prepend timestamp to messages */
 bool error_with_timestamp;
 
+/* Prepend guest name to messages */
+bool error_with_guest_name;
+
 int error_printf(const char *fmt, ...)
 {
     va_list ap;
@@ -230,6 +235,27 @@ static void vreport(report_type type, const char *fmt, 
va_list ap)
     error_printf("\n");
 }
 
+static const char *error_get_guest_name(void)
+{
+    QemuOpts *opts = qemu_opts_find(qemu_find_opts("name"), NULL);
+    return qemu_opt_get(opts, "guest");
+}
+
+/*
+ * Also print the guest name, handy if we log to a server.
+ */
+static void error_print_guest_name(void)
+{
+    const char *name;
+
+    if (error_with_guest_name) {
+        name = error_get_guest_name();
+        if (name && !cur_mon) {
+            error_printf("Guest [%s] ", name);
+        }
+    }
+}
+
 /*
  * Print an error message to current monitor if we have one, else to stderr.
  * Format arguments like vsprintf().  The resulting message should be
@@ -239,6 +265,7 @@ static void vreport(report_type type, const char *fmt, 
va_list ap)
  */
 void error_vreport(const char *fmt, va_list ap)
 {
+    error_print_guest_name();
     vreport(REPORT_TYPE_ERROR, fmt, ap);
 }
 
@@ -250,6 +277,7 @@ void error_vreport(const char *fmt, va_list ap)
  */
 void warn_vreport(const char *fmt, va_list ap)
 {
+    error_print_guest_name();
     vreport(REPORT_TYPE_WARNING, fmt, ap);
 }
 
@@ -276,6 +304,7 @@ void error_report(const char *fmt, ...)
 {
     va_list ap;
 
+    error_print_guest_name();
     va_start(ap, fmt);
     vreport(REPORT_TYPE_ERROR, fmt, ap);
     va_end(ap);
@@ -291,6 +320,7 @@ void warn_report(const char *fmt, ...)
 {
     va_list ap;
 
+    error_print_guest_name();
     va_start(ap, fmt);
     vreport(REPORT_TYPE_WARNING, fmt, ap);
     va_end(ap);
@@ -326,6 +356,7 @@ bool error_report_once_cond(bool *printed, const char *fmt, 
...)
         return false;
     }
     *printed = true;
+    error_print_guest_name();
     va_start(ap, fmt);
     vreport(REPORT_TYPE_ERROR, fmt, ap);
     va_end(ap);
@@ -346,6 +377,7 @@ bool warn_report_once_cond(bool *printed, const char *fmt, 
...)
         return false;
     }
     *printed = true;
+    error_print_guest_name();
     va_start(ap, fmt);
     vreport(REPORT_TYPE_WARNING, fmt, ap);
     va_end(ap);
diff --git a/vl.c b/vl.c
index b8e4c11f02..b6f870f079 100644
--- a/vl.c
+++ b/vl.c
@@ -417,6 +417,10 @@ static QemuOptsList qemu_msg_opts = {
             .name = "timestamp",
             .type = QEMU_OPT_BOOL,
         },
+        {
+            .name = "name",
+            .type = QEMU_OPT_BOOL,
+        },
         { /* end of list */ }
     },
 };
@@ -1263,6 +1267,7 @@ static void realtime_init(void)
 static void configure_msg(QemuOpts *opts)
 {
     error_with_timestamp = qemu_opt_get_bool(opts, "timestamp", false);
+    error_with_guest_name = qemu_opt_get_bool(opts, "name", false);
 }
 
 
Paolo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]