Patchwork [FOR,0.12,11/18] monitor: convert do_change() to QObject, QError

login
register
mail settings
Submitter Markus Armbruster
Date Dec. 7, 2009, 8:37 p.m.
Message ID <1260218236-22143-12-git-send-email-armbru@redhat.com>
Download mbox | patch
Permalink /patch/40540/
State New
Headers show

Comments

Markus Armbruster - Dec. 7, 2009, 8:37 p.m.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 monitor.c       |   19 +++++++++++--------
 qemu-monitor.hx |    3 ++-
 2 files changed, 13 insertions(+), 9 deletions(-)

Patch

diff --git a/monitor.c b/monitor.c
index 62d2ef5..05233cc 100644
--- a/monitor.c
+++ b/monitor.c
@@ -830,13 +830,13 @@  static void do_change_block(Monitor *mon, const char *device,
 
     bs = bdrv_find(device);
     if (!bs) {
-        monitor_printf(mon, "device not found\n");
+        qemu_error_new(QERR_DEVICE_NOT_FOUND, device);
         return;
     }
     if (fmt) {
         drv = bdrv_find_whitelisted_format(fmt);
         if (!drv) {
-            monitor_printf(mon, "invalid format %s\n", fmt);
+            qemu_error_new(QERR_INVALID_BLOCK_FORMAT, fmt);
             return;
         }
     }
@@ -846,17 +846,17 @@  static void do_change_block(Monitor *mon, const char *device,
     monitor_read_bdrv_key_start(mon, bs, NULL, NULL);
 }
 
-static void change_vnc_password(Monitor *mon, const char *password)
+static void change_vnc_password(const char *password)
 {
     if (vnc_display_password(NULL, password) < 0)
-        monitor_printf(mon, "could not set VNC server password\n");
+        qemu_error_new(QERR_SET_PASSWD_FAILED);
 
 }
 
 static void change_vnc_password_cb(Monitor *mon, const char *password,
                                    void *opaque)
 {
-    change_vnc_password(mon, password);
+    change_vnc_password(password);
     monitor_read_command(mon, 1);
 }
 
@@ -868,17 +868,20 @@  static void do_change_vnc(Monitor *mon, const char *target, const char *arg)
             char password[9];
             strncpy(password, arg, sizeof(password));
             password[sizeof(password) - 1] = '\0';
-            change_vnc_password(mon, password);
+            change_vnc_password(password);
         } else {
             monitor_read_password(mon, change_vnc_password_cb, NULL);
         }
     } else {
         if (vnc_display_open(NULL, target) < 0)
-            monitor_printf(mon, "could not start VNC server on %s\n", target);
+            qemu_error_new(QERR_VNC_SERVER_FAILED, target);
     }
 }
 
-static void do_change(Monitor *mon, const QDict *qdict)
+/**
+ * do_change(): Change a removable medium, or VNC configuration
+ */
+static void do_change(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
     const char *device = qdict_get_str(qdict, "device");
     const char *target = qdict_get_str(qdict, "target");
diff --git a/qemu-monitor.hx b/qemu-monitor.hx
index cf2ef9b..c788c73 100644
--- a/qemu-monitor.hx
+++ b/qemu-monitor.hx
@@ -147,7 +147,8 @@  ETEXI
         .args_type  = "device:B,target:F,arg:s?",
         .params     = "device filename [format]",
         .help       = "change a removable medium, optional format",
-        .mhandler.cmd = do_change,
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = do_change,
     },
 
 STEXI