Skip to contentSkip to conversation

log hmp/qmp command

PATCH In review Denis V. Lunev 3 participants 6 messages Oct 12, 2015 – Oct 13, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 log hmp/qmp command

From: Pavel Butsykin <[email protected]>

This log would be very welcome for long-term diagnostics of the system in the production. This log is at least necessary to understand what has been happened on the system and to identify issues at higher-level subsystems (libvirt, etc).

CC Markus Armbruster <[email protected]>
CC Luiz Capitulino <[email protected]>
CC Eric Blake <[email protected]>
---
 include/qemu/log.h | 1 +
 monitor.c          | 4 ++++
 qemu-log.c         | 1 +
 3 files changed, 6 insertions(+)
include/qemu/log.h +1 -0
index f880e66..dfb587e 100644
@@ -41,6 +41,7 @@ static inline bool qemu_log_enabled(void)
 #define LOG_UNIMP          (1 << 10)
 #define LOG_GUEST_ERROR    (1 << 11)
 #define CPU_LOG_MMU        (1 << 12)
+#define LOG_CMD            (1 << 13)
 
 /* Returns true if a bit is set in the current loglevel mask
  */
monitor.c +4 -0
index 4f1ba2f..a22a798 100644
@@ -2848,6 +2848,8 @@ static void handle_hmp_command(Monitor *mon, const char *cmdline)
     QDict *qdict;
     const mon_cmd_t *cmd;
 
+    qemu_log_mask(LOG_CMD, "hmp \"%s\" requested\n", cmdline);
+
     cmd = monitor_parse_command(mon, &cmdline, mon->cmd_table);
     if (!cmd) {
         return;
@@ -3822,6 +3824,8 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
         error_setg(&local_err, QERR_JSON_PARSING);
         goto err_out;
     }
+    qemu_log_mask(LOG_CMD, "qmp \"%s\" requested\n",
+                  qobject_to_json(obj)->string);
 
     input = qmp_check_input_obj(obj, &local_err);
     if (!input) {
qemu-log.c +1 -0
index 13f3813..66b15ec 100644
@@ -119,6 +119,7 @@ const QEMULogItem qemu_log_items[] = {
     { LOG_GUEST_ERROR, "guest_errors",
       "log when the guest OS does something invalid (eg accessing a\n"
       "non-existent register)" },
+    { LOG_CMD, "cmd", "log the hmp/qmp commands execution" },
     { 0, NULL, NULL },
 };
 
Signature · 1 line
2.1.4
#1 lore raw
Quoted 44 lines · Denis V. Lunev

From: Pavel Butsykin <[email protected]>

This log would be very welcome for long-term diagnostics of the system in the production. This log is at least necessary to understand what has been happened on the system and to identify issues at higher-level subsystems (libvirt, etc).

CC Markus Armbruster <[email protected]>
CC Luiz Capitulino <[email protected]>
CC Eric Blake <[email protected]>
---
  include/qemu/log.h | 1 +
  monitor.c          | 4 ++++
  qemu-log.c         | 1 +
  3 files changed, 6 insertions(+)
include/qemu/log.h +1 -0
index f880e66..dfb587e 100644
@@ -41,6 +41,7 @@ static inline bool qemu_log_enabled(void)
  #define LOG_UNIMP          (1 << 10)
  #define LOG_GUEST_ERROR    (1 << 11)
  #define CPU_LOG_MMU        (1 << 12)
+#define LOG_CMD            (1 << 13)
 
  /* Returns true if a bit is set in the current loglevel mask
   */
monitor.c +2 -0
index 4f1ba2f..a22a798 100644
@@ -2848,6 +2848,8 @@ static void handle_hmp_command(Monitor *mon, const char *cmdline)
      QDict *qdict;
      const mon_cmd_t *cmd;
 
+    qemu_log_mask(LOG_CMD, "hmp \"%s\" requested\n", cmdline);
+
      cmd = monitor_parse_command(mon, &cmdline, mon->cmd_table);
      if (!cmd) {
          return;

monitor.c static void handle_qmp_command(JSONMessageParser *parser, QList *tokens) · line 3828

Quoted 5 lines
monitor.c +2 -0
@@ -3822,6 +3824,8 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
          error_setg(&local_err, QERR_JSON_PARSING);
          goto err_out;
      }
+    qemu_log_mask(LOG_CMD, "qmp \"%s\" requested\n",
+                  qobject_to_json(obj)->string);

it seems that QString here is leaked

Quoted 15 lines
monitor.c +0 -0
      input = qmp_check_input_obj(obj, &local_err);
      if (!input) {
qemu-log.c +1 -0
index 13f3813..66b15ec 100644
@@ -119,6 +119,7 @@ const QEMULogItem qemu_log_items[] = {
      { LOG_GUEST_ERROR, "guest_errors",
        "log when the guest OS does something invalid (eg accessing a\n"
        "non-existent register)" },
+    { LOG_CMD, "cmd", "log the hmp/qmp commands execution" },
      { 0, NULL, NULL },
  };
 
#2 lore raw
In reply to Denis V. Lunev
Quoted 15 lines · Denis V. Lunev

From: Pavel Butsykin <[email protected]>

This log would be very welcome for long-term diagnostics of the system in the production. This log is at least necessary to understand what has been happened on the system and to identify issues at higher-level subsystems (libvirt, etc).

CC Markus Armbruster <[email protected]>
CC Luiz Capitulino <[email protected]>
CC Eric Blake <[email protected]>

---

monitor.c static void handle_qmp_command(JSONMessageParser *parser, QList *tokens) · line 3829

Quoted 6 lines
monitor.c +2 -0
@@ -3822,6 +3824,8 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
         error_setg(&local_err, QERR_JSON_PARSING);
         goto err_out;
     }
+    qemu_log_mask(LOG_CMD, "qmp \"%s\" requested\n",
+                  qobject_to_json(obj)->string);
 

In addition to the leak already pointed out, qobject_to_json() can be expensive, and it looks like we are doing that work unconditionally even if the logging is not turned on. Is there a way to optimize so that the conversion is only done when logging is enabled?

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#3 lore raw
Quoted 17 lines · Eric Blake
Quoted 16 lines · Denis V. Lunev

From: Pavel Butsykin <[email protected]>

This log would be very welcome for long-term diagnostics of the system in the production. This log is at least necessary to understand what has been happened on the system and to identify issues at higher-level subsystems (libvirt, etc).

CC Markus Armbruster <[email protected]>
CC Luiz Capitulino <[email protected]>
CC Eric Blake <[email protected]>

---

monitor.c +0 -0
@@ -3822,6 +3824,8 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
          error_setg(&local_err, QERR_JSON_PARSING);
          goto err_out;
Quoted 9 lines

monitor.c static void handle_qmp_command(JSONMessageParser *parser, QList *tokens) · line 3829

Quoted 4 lines
monitor.c +2 -0
      }
+    qemu_log_mask(LOG_CMD, "qmp \"%s\" requested\n",
+                  qobject_to_json(obj)->string);
 

In addition to the leak already pointed out, qobject_to_json() can be expensive, and it looks like we are doing that work unconditionally even if the logging is not turned on. Is there a way to optimize so that the conversion is only done when logging is enabled?

this seems quite reasonable.

Will it be good if we'll change logging implementation to use macros, something like

#define qemu_log_mask(int mask, const char *ftp, ...) \
do { \
va_list ap; \
\

if (!(qemu_loglevel & mask) || !qemu_logfile) {\
      break;\

}\
qemu_log(ftp, __VA_ARGS__); \
} while (0)

This IMHO makes sense even out of the scope of this patch.

Den

#4 lore raw
In reply to Denis V. Lunev
Quoted 6 lines · On Mon, 12 Oct 2015 11:41:35 +0300 "Denis V. Lunev" <[email protected]> wrote:

From: Pavel Butsykin <[email protected]>

This log would be very welcome for long-term diagnostics of the system in the production. This log is at least necessary to understand what has been happened on the system and to identify issues at higher-level subsystems (libvirt, etc).

This is good to have, and probably we should have had it since day one. But I have the following considerations:

- libvirt would need support for this to use it the way you describe, although libvirt already has its logging facility (well, one could wrap qemu in bash and pass this by default but this is not ideal)

- A true logging facility would also log responses and events

- I don't think it's important to log HMP

Quoted 58 lines
CC Markus Armbruster <[email protected]>
CC Luiz Capitulino <[email protected]>
CC Eric Blake <[email protected]>
---
 include/qemu/log.h | 1 +
 monitor.c          | 4 ++++
 qemu-log.c         | 1 +
 3 files changed, 6 insertions(+)
include/qemu/log.h +1 -0
index f880e66..dfb587e 100644
@@ -41,6 +41,7 @@ static inline bool qemu_log_enabled(void)
 #define LOG_UNIMP          (1 << 10)
 #define LOG_GUEST_ERROR    (1 << 11)
 #define CPU_LOG_MMU        (1 << 12)
+#define LOG_CMD            (1 << 13)
 
 /* Returns true if a bit is set in the current loglevel mask
  */
monitor.c +4 -0
index 4f1ba2f..a22a798 100644
@@ -2848,6 +2848,8 @@ static void handle_hmp_command(Monitor *mon, const char *cmdline)
     QDict *qdict;
     const mon_cmd_t *cmd;
 
+    qemu_log_mask(LOG_CMD, "hmp \"%s\" requested\n", cmdline);
+
     cmd = monitor_parse_command(mon, &cmdline, mon->cmd_table);
     if (!cmd) {
         return;
@@ -3822,6 +3824,8 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
         error_setg(&local_err, QERR_JSON_PARSING);
         goto err_out;
     }
+    qemu_log_mask(LOG_CMD, "qmp \"%s\" requested\n",
+                  qobject_to_json(obj)->string);
 
     input = qmp_check_input_obj(obj, &local_err);
     if (!input) {
qemu-log.c +1 -0
index 13f3813..66b15ec 100644
@@ -119,6 +119,7 @@ const QEMULogItem qemu_log_items[] = {
     { LOG_GUEST_ERROR, "guest_errors",
       "log when the guest OS does something invalid (eg accessing a\n"
       "non-existent register)" },
+    { LOG_CMD, "cmd", "log the hmp/qmp commands execution" },
     { 0, NULL, NULL },
 };
 
#5 lore raw
Quoted 9 lines · Luiz Capitulino
Quoted 6 lines · On Mon, 12 Oct 2015 11:41:35 +0300 "Denis V. Lunev" <[email protected]> wrote:

From: Pavel Butsykin <[email protected]>

This log would be very welcome for long-term diagnostics of the system in the production. This log is at least necessary to understand what has been happened on the system and to identify issues at higher-level subsystems (libvirt, etc).

Quoted 6 lines

This is good to have, and probably we should have had it since day one. But I have the following considerations:

- libvirt would need support for this to use it the way you describe, although libvirt already has its logging facility (well, one could wrap qemu in bash and pass this by default but this is not ideal)

OK, I'll add task to the queue for our libvirt guys

Quoted 1 line

- A true logging facility would also log responses and events

responses are done alreade internally in the scope of preparations to the next submission, events are missed. Thank you for pointing this out

Quoted 1 line

- I don't think it's important to log HMP

OK, but I do not that that this will hurt us :)

Den

Quoted 57 lines
Quoted 57 lines
CC Markus Armbruster <[email protected]>
CC Luiz Capitulino <[email protected]>
CC Eric Blake <[email protected]>
---
  include/qemu/log.h | 1 +
  monitor.c          | 4 ++++
  qemu-log.c         | 1 +
  3 files changed, 6 insertions(+)
include/qemu/log.h +1 -0
index f880e66..dfb587e 100644
@@ -41,6 +41,7 @@ static inline bool qemu_log_enabled(void)
  #define LOG_UNIMP          (1 << 10)
  #define LOG_GUEST_ERROR    (1 << 11)
  #define CPU_LOG_MMU        (1 << 12)
+#define LOG_CMD            (1 << 13)
 
  /* Returns true if a bit is set in the current loglevel mask
   */
monitor.c +4 -0
index 4f1ba2f..a22a798 100644
@@ -2848,6 +2848,8 @@ static void handle_hmp_command(Monitor *mon, const char *cmdline)
      QDict *qdict;
      const mon_cmd_t *cmd;
 
+    qemu_log_mask(LOG_CMD, "hmp \"%s\" requested\n", cmdline);
+
      cmd = monitor_parse_command(mon, &cmdline, mon->cmd_table);
      if (!cmd) {
          return;
@@ -3822,6 +3824,8 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
          error_setg(&local_err, QERR_JSON_PARSING);
          goto err_out;
      }
+    qemu_log_mask(LOG_CMD, "qmp \"%s\" requested\n",
+                  qobject_to_json(obj)->string);
 
      input = qmp_check_input_obj(obj, &local_err);
      if (!input) {
qemu-log.c +1 -0
index 13f3813..66b15ec 100644
@@ -119,6 +119,7 @@ const QEMULogItem qemu_log_items[] = {
      { LOG_GUEST_ERROR, "guest_errors",
        "log when the guest OS does something invalid (eg accessing a\n"
        "non-existent register)" },
+    { LOG_CMD, "cmd", "log the hmp/qmp commands execution" },
      { 0, NULL, NULL },
  };