qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 14/14] monitor: Convert do_info_balloon() to QObject


From: Luiz Capitulino
Subject: [Qemu-devel] [PATCH 14/14] monitor: Convert do_info_balloon() to QObject
Date: Thu, 1 Oct 2009 12:50:45 -0300

On success return a QInt with the balloon's value, on error
MonitorError is properly filled.

This also introduces monitor_print_balloon() to print the
balloon information in the user protocol format and
monitor_print_error(), which can be used as a standard way
to print error descriptions in the user protocol format.

Signed-off-by: Luiz Capitulino <address@hidden>
---
 monitor.c |   35 +++++++++++++++++++++++++----------
 1 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/monitor.c b/monitor.c
index 1b52355..2cf9f7e 100644
--- a/monitor.c
+++ b/monitor.c
@@ -265,6 +265,11 @@ static void monitor_print_qobject(Monitor *mon, const 
QObject *data)
     monitor_puts(mon, "\n");
 }
 
+static void monitor_print_error(Monitor *mon, const MonitorError *error)
+{
+    monitor_print_qobject(mon, QOBJECT(error->desc));
+}
+
 static int compare_cmd(const char *name, const char *list)
 {
     const char *p, *pstart;
@@ -1669,18 +1674,28 @@ static void do_balloon(Monitor *mon, const QDict 
*qdict, QObject **ret_data,
     qemu_balloon(target << 20);
 }
 
-static void do_info_balloon(Monitor *mon)
+static void monitor_print_balloon(Monitor *mon, const QObject *data)
+{
+    monitor_printf(mon, "balloon: actual=%d\n",
+                                     (int)qint_get_int(qobject_to_qint(data)));
+}
+
+/**
+ * do_info_balloon(): Balloon information
+ */
+static void do_info_balloon(Monitor *mon, QObject **ret_data,
+                            MonitorError *error)
 {
     ram_addr_t actual;
 
     actual = qemu_balloon_status();
-    if (kvm_enabled() && !kvm_has_sync_mmu())
-        monitor_printf(mon, "Using KVM without synchronous MMU, "
-                       "ballooning disabled\n");
-    else if (actual == 0)
-        monitor_printf(mon, "Ballooning not activated in VM\n");
-    else
-        monitor_printf(mon, "balloon: actual=%d\n", (int)(actual >> 20));
+    if (kvm_enabled() && !kvm_has_sync_mmu()) {
+        monitor_error_set_code(error, MON_ERR_BAL_MMU);
+    } else if (actual == 0) {
+        monitor_error_set_code(error, MON_ERR_BAL_DIS);
+    } else {
+        *ret_data = QOBJECT(qint_from_int((int)(actual >> 20)));
+    }
 }
 
 static qemu_acl *find_acl(Monitor *mon, const char *name)
@@ -2203,8 +2218,8 @@ static const mon_cmd_t info_cmds[] = {
         .name       = "balloon",
         .args_type  = "",
         .handler    = do_info_balloon,
-        .user_print = NULL,
-        .user_error = NULL,
+        .user_print = monitor_print_balloon,
+        .user_error = monitor_print_error,
         .params     = "",
         .help       = "show balloon information"
     },
-- 
1.6.5.rc2





reply via email to

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