Browse Source

error: Use error_report_err() instead of monitor_printf()

Both error_report_err() and monitor_printf() print to the same
destination when monitor_printf() is used correctly, i.e. within an
HMP monitor.  Elsewhere, monitor_printf() does nothing, while
error_report_err() reports to stderr.

Most changed functions are HMP command handlers.  These should only
run within an HMP monitor.  The one exception is bdrv_password_cb(),
which should also only run within an HMP monitor.

Four command handlers prefix the error message with the command name:
balloon, migrate_set_capability, migrate_set_parameter, migrate.
Pointless, drop.

Unlike monitor_printf(), error_report_err() uses the error whole
instead of just its message obtained with error_get_pretty().  This
avoids suppressing its hint (see commit 50b7b00).  Example:

    (qemu) device_add ivshmem,id=666
    Parameter 'id' expects an identifier
    Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.
    Try "help device_add" for more information

The "Identifiers consist of..." line is new with this patch.

Coccinelle semantic patch:

    @@
    expression M, E;
    @@
    -    monitor_printf(M, "%s\n", error_get_pretty(E));
    -    error_free(E);
    +    error_report_err(E);
    @r1@
    expression M, E;
    format F;
    position p;
    @@
    -    monitor_printf(M, "...%@F@\n", error_get_pretty(E));@p
    -    error_free(E);
    +    error_report_err(E);
    @script:python@
	p << r1.p;
    @@
    print "%s:%s:%s: prefix dropped" % (p[0].file, p[0].line, p[0].column)

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <1450452927-8346-4-git-send-email-armbru@redhat.com>
Markus Armbruster 9 years ago
parent
commit
193227f9e5
4 changed files with 13 additions and 28 deletions
  1. 9 20
      hmp.c
  2. 1 2
      hw/s390x/s390-skeys.c
  3. 1 2
      migration/savevm.c
  4. 2 4
      monitor.c

+ 9 - 20
hmp.c

@@ -41,8 +41,7 @@ static void hmp_handle_error(Monitor *mon, Error **errp)
 {
 {
     assert(errp);
     assert(errp);
     if (*errp) {
     if (*errp) {
-        monitor_printf(mon, "%s\n", error_get_pretty(*errp));
-        error_free(*errp);
+        error_report_err(*errp);
     }
     }
 }
 }
 
 
@@ -556,8 +555,7 @@ void hmp_info_vnc(Monitor *mon, const QDict *qdict)
 
 
     info = qmp_query_vnc(&err);
     info = qmp_query_vnc(&err);
     if (err) {
     if (err) {
-        monitor_printf(mon, "%s\n", error_get_pretty(err));
-        error_free(err);
+        error_report_err(err);
         return;
         return;
     }
     }
 
 
@@ -679,8 +677,7 @@ void hmp_info_balloon(Monitor *mon, const QDict *qdict)
 
 
     info = qmp_query_balloon(&err);
     info = qmp_query_balloon(&err);
     if (err) {
     if (err) {
-        monitor_printf(mon, "%s\n", error_get_pretty(err));
-        error_free(err);
+        error_report_err(err);
         return;
         return;
     }
     }
 
 
@@ -948,8 +945,7 @@ void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
 
 
     data = qmp_ringbuf_read(chardev, size, false, 0, &err);
     data = qmp_ringbuf_read(chardev, size, false, 0, &err);
     if (err) {
     if (err) {
-        monitor_printf(mon, "%s\n", error_get_pretty(err));
-        error_free(err);
+        error_report_err(err);
         return;
         return;
     }
     }
 
 
@@ -1042,8 +1038,7 @@ void hmp_balloon(Monitor *mon, const QDict *qdict)
 
 
     qmp_balloon(value, &err);
     qmp_balloon(value, &err);
     if (err) {
     if (err) {
-        monitor_printf(mon, "balloon: %s\n", error_get_pretty(err));
-        error_free(err);
+        error_report_err(err);
     }
     }
 }
 }
 
 
@@ -1191,8 +1186,7 @@ void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
 
 
     qmp_migrate_set_cache_size(value, &err);
     qmp_migrate_set_cache_size(value, &err);
     if (err) {
     if (err) {
-        monitor_printf(mon, "%s\n", error_get_pretty(err));
-        error_free(err);
+        error_report_err(err);
         return;
         return;
     }
     }
 }
 }
@@ -1229,9 +1223,7 @@ void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
     qapi_free_MigrationCapabilityStatusList(caps);
     qapi_free_MigrationCapabilityStatusList(caps);
 
 
     if (err) {
     if (err) {
-        monitor_printf(mon, "migrate_set_capability: %s\n",
-                       error_get_pretty(err));
-        error_free(err);
+        error_report_err(err);
     }
     }
 }
 }
 
 
@@ -1281,9 +1273,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
     }
     }
 
 
     if (err) {
     if (err) {
-        monitor_printf(mon, "migrate_set_parameter: %s\n",
-                       error_get_pretty(err));
-        error_free(err);
+        error_report_err(err);
     }
     }
 }
 }
 
 
@@ -1544,8 +1534,7 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)
 
 
     qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
     qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
     if (err) {
     if (err) {
-        monitor_printf(mon, "migrate: %s\n", error_get_pretty(err));
-        error_free(err);
+        error_report_err(err);
         return;
         return;
     }
     }
 
 

+ 1 - 2
hw/s390x/s390-skeys.c

@@ -100,8 +100,7 @@ void hmp_dump_skeys(Monitor *mon, const QDict *qdict)
 
 
     qmp_dump_skeys(filename, &err);
     qmp_dump_skeys(filename, &err);
     if (err) {
     if (err) {
-        monitor_printf(mon, "%s\n", error_get_pretty(err));
-        error_free(err);
+        error_report_err(err);
     }
     }
 }
 }
 
 

+ 1 - 2
migration/savevm.c

@@ -1984,8 +1984,7 @@ void hmp_savevm(Monitor *mon, const QDict *qdict)
     vm_state_size = qemu_ftell(f);
     vm_state_size = qemu_ftell(f);
     qemu_fclose(f);
     qemu_fclose(f);
     if (ret < 0) {
     if (ret < 0) {
-        monitor_printf(mon, "%s\n", error_get_pretty(local_err));
-        error_free(local_err);
+        error_report_err(local_err);
         goto the_end;
         goto the_end;
     }
     }
 
 

+ 2 - 4
monitor.c

@@ -1464,8 +1464,7 @@ static void hmp_boot_set(Monitor *mon, const QDict *qdict)
 
 
     qemu_boot_set(bootdevice, &local_err);
     qemu_boot_set(bootdevice, &local_err);
     if (local_err) {
     if (local_err) {
-        monitor_printf(mon, "%s\n", error_get_pretty(local_err));
-        error_free(local_err);
+        error_report_err(local_err);
     } else {
     } else {
         monitor_printf(mon, "boot device list now set to %s\n", bootdevice);
         monitor_printf(mon, "boot device list now set to %s\n", bootdevice);
     }
     }
@@ -4149,8 +4148,7 @@ static void bdrv_password_cb(void *opaque, const char *password,
 
 
     bdrv_add_key(bs, password, &local_err);
     bdrv_add_key(bs, password, &local_err);
     if (local_err) {
     if (local_err) {
-        monitor_printf(mon, "%s\n", error_get_pretty(local_err));
-        error_free(local_err);
+        error_report_err(local_err);
         ret = -EPERM;
         ret = -EPERM;
     }
     }
     if (mon->password_completion_cb)
     if (mon->password_completion_cb)