Skip to contentSkip to conversation

log: Make glib logging go through QEMU

PATCH In review Christophe Fergeau 2 participants 4 messages Jan 31, 2019 – Apr 25, 2019

lore
Share & tools
lore
#1 lore raw

PATCH v7 1/2 qemu-io: Use error_[gs]et_progname()

In reply to Christophe Fergeau

qemu-io reimplements itself what error_get_progname()/error_set_progname() already does. This commit switches it to use this API from qemu-error.h

---
No changes since v6

 qemu-io.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
qemu-io.c +6 -8
index 6df7731af4..2c52ac0ade 100644
@@ -34,8 +34,6 @@
 
 #define CMD_NOFILE_OK   0x01
 
-static char *progname;
-
 static BlockBackend *qemuio_blk;
 static bool quit_qemu_io;
 
@@ -312,7 +310,7 @@ static char *get_prompt(void)
     static char prompt[FILENAME_MAX + 2 /*"> "*/ + 1 /*"\0"*/ ];
 
     if (!prompt[0]) {
-        snprintf(prompt, sizeof(prompt), "%s> ", progname);
+        snprintf(prompt, sizeof(prompt), "%s> ", error_get_progname());
     }
 
     return prompt;
@@ -525,7 +523,7 @@ int main(int argc, char **argv)
 #endif
 
     module_call_init(MODULE_INIT_TRACE);
-    progname = g_path_get_basename(argv[0]);
+    error_set_progname(argv[0]);
     qemu_init_exec_dir(argv[0]);
 
     qcrypto_init(&error_fatal);
@@ -580,10 +578,10 @@ int main(int argc, char **argv)
             break;
         case 'V':
             printf("%s version " QEMU_FULL_VERSION "\n"
-                   QEMU_COPYRIGHT "\n", progname);
+                   QEMU_COPYRIGHT "\n", error_get_progname());
             exit(0);
         case 'h':
-            usage(progname);
+            usage(error_get_progname());
             exit(0);
         case 'U':
             force_share = true;
@@ -600,13 +598,13 @@ int main(int argc, char **argv)
             imageOpts = true;
             break;
         default:
-            usage(progname);
+            usage(error_get_progname());
             exit(1);
         }
     }
 
     if ((argc - optind) > 1) {
-        usage(progname);
+        usage(error_get_progname());
         exit(1);
     }
 
Signature · 1 line
2.20.1
#0 lore raw

v7 cover log: Make glib logging go through QEMU

The main goal of this patch series is to make logs output by libspice-server.so go through qemu logging infrastructure so that their format is the same as the rest of QEMU messages (in particular, timestamps). This is done in the second patch, the first one is a preparation patch.

Christophe Fergeau (2):
qemu-io: Use error_[gs]et_progname()
log: Make glib logging go through QEMU

 bsd-user/main.c             |  2 ++
 include/qemu/error-report.h |  3 +-
 linux-user/main.c           |  2 ++
 qemu-img.c                  |  2 +-
 qemu-io.c                   | 14 ++++------
 qemu-nbd.c                  |  2 +-
 scsi/qemu-pr-helper.c       |  1 +
 util/qemu-error.c           | 55 ++++++++++++++++++++++++++++++++++++-
 vl.c                        |  2 +-
 9 files changed, 70 insertions(+), 13 deletions(-)
Signature · 1 line
2.20.1
#3 lore raw

PATCH v7 2/2 log: Make glib logging go through QEMU

This commit adds a error_init() helper which calls g_log_set_default_handler() so that glib logs (g_log, g_warning, ...) are handled similarly to other QEMU logs. This means they will get a timestamp if timestamps are enabled, and they will go through the HMP monitor if one is configured.

This commit also adds a call to error_init() to the binaries installed by QEMU. Since error_init() also calls error_set_progname(), this means that *-linux-user, *-bsd-user and qemu-pr-helper messages output with error_report, info_report, ... will slightly change: they will be prefixed by the binary name.

glib debug messages are enabled through G_MESSAGES_DEBUG similarly to the glib default log handler.

At the moment, this change will mostly impact SPICE logging if your spice version is >= 0.14.1. With older spice versions, this is not going to work as expected, but will not have any ill effect, so this call is not conditional on the SPICE version.

---
Changes since v6:
- expanded on the bsd-user/linux-user/qemu-pr-helper changes in the commit log
- fix obsolete mention of qemu_init_logging() in commit log
- improved output when 'log_domain' is NULL
- removed unneeded "fall through" comment in switch/case
- fixed multi-line comments

 bsd-user/main.c             |  2 ++
 include/qemu/error-report.h |  3 +-
 linux-user/main.c           |  2 ++
 qemu-img.c                  |  2 +-
 qemu-io.c                   |  2 +-
 qemu-nbd.c                  |  2 +-
 scsi/qemu-pr-helper.c       |  1 +
 util/qemu-error.c           | 55 ++++++++++++++++++++++++++++++++++++-
 vl.c                        |  2 +-
 9 files changed, 65 insertions(+), 6 deletions(-)
bsd-user/main.c +2 -0
index 0d3156974c..8fd8ae4127 100644
@@ -24,6 +24,7 @@
 #include "qapi/error.h"
 #include "qemu.h"
 #include "qemu/config-file.h"
+#include "qemu/error-report.h"
 #include "qemu/path.h"
 #include "qemu/help_option.h"
 #include "cpu.h"
@@ -743,6 +744,7 @@ int main(int argc, char **argv)
     if (argc <= 1)
         usage();
 
+    error_init(argv[0]);
     module_call_init(MODULE_INIT_TRACE);
     qemu_init_cpu_list();
     module_call_init(MODULE_INIT_QOM);
include/qemu/error-report.h +2 -1
index 0a8d9cc9ea..ce43c02314 100644
@@ -34,7 +34,6 @@ void error_vprintf(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
 void error_printf(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
 void error_vprintf_unless_qmp(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
 void error_printf_unless_qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
-void error_set_progname(const char *argv0);
 
 void error_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
 void warn_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
@@ -49,6 +48,8 @@ bool error_report_once_cond(bool *printed, const char *fmt, ...)
 bool warn_report_once_cond(bool *printed, const char *fmt, ...)
     GCC_FMT_ATTR(2, 3);
 
+void error_init(const char *argv0);
+
 /*
  * Similar to error_report(), except it prints the message just once.
  * Return true when it prints, false otherwise.
linux-user/main.c +2 -0
index a0aba9cb1e..f9efe9ff6e 100644
@@ -27,6 +27,7 @@
 #include "qemu/path.h"
 #include "qemu/config-file.h"
 #include "qemu/cutils.h"
+#include "qemu/error-report.h"
 #include "qemu/help_option.h"
 #include "cpu.h"
 #include "exec/exec-all.h"
@@ -600,6 +601,7 @@ int main(int argc, char **argv, char **envp)
     int ret;
     int execfd;
 
+    error_init(argv[0]);
     module_call_init(MODULE_INIT_TRACE);
     qemu_init_cpu_list();
     module_call_init(MODULE_INIT_QOM);
qemu-img.c +1 -1
index ad04f59565..0af9cac244 100644
@@ -4912,8 +4912,8 @@ int main(int argc, char **argv)
     signal(SIGPIPE, SIG_IGN);
 #endif
 
+    error_init(argv[0]);
     module_call_init(MODULE_INIT_TRACE);
-    error_set_progname(argv[0]);
     qemu_init_exec_dir(argv[0]);
 
     if (qemu_init_main_loop(&local_error)) {
qemu-io.c +1 -1
index 2c52ac0ade..8d5d5911cb 100644
@@ -522,8 +522,8 @@ int main(int argc, char **argv)
     signal(SIGPIPE, SIG_IGN);
 #endif
 
+    error_init(argv[0]);
     module_call_init(MODULE_INIT_TRACE);
-    error_set_progname(argv[0]);
     qemu_init_exec_dir(argv[0]);
 
     qcrypto_init(&error_fatal);
qemu-nbd.c +1 -1
index 1f7b2a03f5..39849f1692 100644
@@ -685,8 +685,8 @@ int main(int argc, char **argv)
     signal(SIGPIPE, SIG_IGN);
 #endif
 
+    error_init(argv[0]);
     module_call_init(MODULE_INIT_TRACE);
-    error_set_progname(argv[0]);
     qcrypto_init(&error_fatal);
 
     module_call_init(MODULE_INIT_QOM);
scsi/qemu-pr-helper.c +1 -0
index e7af637232..2541fbbd1b 100644
@@ -895,6 +895,7 @@ int main(int argc, char **argv)
 
     signal(SIGPIPE, SIG_IGN);
 
+    error_init(argv[0]);
     module_call_init(MODULE_INIT_TRACE);
     module_call_init(MODULE_INIT_QOM);
     qemu_add_opts(&qemu_trace_opts);
util/qemu-error.c +54 -1

64 lines not on this page · raw message

vl.c +1 -1
index 9cf0fbe0b8..3d447b84d1 100644
@@ -3042,6 +3042,7 @@ int main(int argc, char **argv, char **envp)
     QSIMPLEQ_HEAD(, BlockdevOptions_queue) bdo_queue
         = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue);
 
+    error_init(argv[0]);
     module_call_init(MODULE_INIT_TRACE);
 
     qemu_init_cpu_list();
@@ -3050,7 +3051,6 @@ int main(int argc, char **argv, char **envp)
     qemu_mutex_lock_iothread();
 
     atexit(qemu_run_exit_notifiers);
-    error_set_progname(argv[0]);
     qemu_init_exec_dir(argv[0]);
 
     module_call_init(MODULE_INIT_QOM);
Signature · 1 line
2.20.1
#2 lore raw

Re: [Qemu-devel] [PATCH v7 1/2] qemu-io: Use error_[gs]et_progname()

In reply to Christophe Fergeau
Quoted 7 lines · Christophe Fergeau

qemu-io reimplements itself what error_get_progname()/error_set_progname() already does. This commit switches it to use this API from qemu-error.h

This patch causes some qemu-iotests to fail now, e.g.:

cd tests/qemu-iotests
./check -qcow2 114
[...]
114 0s ... - output mismatch (see 114.out.bad)
--- /home/thuth/devel/qemu/tests/qemu-iotests/114.out 2019-04-23
16:43:12.000000000 +0200
+++ /home/thuth/tmp/qemu-build/tests/qemu-iotests/114.out.bad 2019-04-25
12:27:47.000000000 +0200
@@ -7,7 +7,7 @@
cluster_size: 65536
backing file: TEST_DIR/t.IMGFMT.base
backing file format: foo
-can't open device TEST_DIR/t.qcow2: Could not open backing file:
Unknown driver 'foo'
+qemu-io: can't open device TEST_DIR/t.qcow2: Could not open backing
file: Unknown driver 'foo'
no file open, try 'help open'
read 4096/4096 bytes at offset 0
4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)

Could you please have a look?

Thomas