From: Luiz Capitulino <lcapitulino@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 4/8] monitor: Convert do_info_migrate() to QObject
Date: Sun, 1 Nov 2009 12:51:14 -0200 [thread overview]
Message-ID: <1257087078-5757-5-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1257087078-5757-1-git-send-email-lcapitulino@redhat.com>
Return a QDict, which may contain another QDict if the migration
process is active.
The main QDict contains the following:
- "status": migration status
- "ram": only present if "status" is "active", it is a QDict with the
following information (in bytes):
- "transferred": amount of RAM transferred
- "remaining": amount of RAM remaining
- "total": total RAM
IMPORTANT: as a QInt stores a int64_t integer, those RAM values
are going to stored as int64_t and not as uint64_t as they are
today. If this is a problem QInt will have to be changed.
This commit should not change user output, the following is an
example of the returned QDict:
{ "status": "active", "ram":
{ "transferred": 885030912, "remaining": 198529024, "total": 1082392576 } }
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
migration.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
migration.h | 3 +-
monitor.c | 3 +-
3 files changed, 56 insertions(+), 11 deletions(-)
diff --git a/migration.c b/migration.c
index b20beb7..da33506 100644
--- a/migration.c
+++ b/migration.c
@@ -18,6 +18,7 @@
#include "sysemu.h"
#include "block.h"
#include "qemu_socket.h"
+#include "qemu-objects.h"
//#define DEBUG_MIGRATION
@@ -149,29 +150,71 @@ void do_migrate_set_downtime(Monitor *mon, const QDict *qdict)
max_downtime = (uint64_t)d;
}
-void do_info_migrate(Monitor *mon)
+void migration_user_print(Monitor *mon, const QObject *data)
+{
+ QDict *qdict;
+
+ qdict = qobject_to_qdict(data);
+
+ monitor_printf(mon, "Migration status: %s\n", qdict_get_str(qdict, "status"));
+
+ if (qdict_haskey(qdict, "ram")) {
+ QDict *qdict_ram = qobject_to_qdict(qdict_get(qdict, "ram"));
+ monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
+ qdict_get_int(qdict_ram, "transferred") >> 10);
+ monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
+ qdict_get_int(qdict_ram, "remaining") >> 10);
+ monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
+ qdict_get_int(qdict_ram, "total") >> 10);
+ }
+}
+
+/**
+ * do_info_migrate(): Migration status
+ *
+ * Return a QDict. If migration is active there will be another
+ * QDict with RAM information.
+ *
+ * The main QDict contains the following:
+ *
+ * - "status": migration status
+ * - "ram": only present if "status" is "active", it is a QDict with the
+ * following information (in bytes):
+ * - "transferred": amount of RAM transferred
+ * - "remaining": amount of RAM remaining
+ * - "total": total RAM
+ *
+ * Examples:
+ *
+ * 1. If migration is "completed":
+ *
+ * { "status": "completed" }
+ *
+ * 2. If migration is "active":
+ *
+ * { "status": "active", "ram":
+ * { "transferred": 123, "remaining": 123, "total": 246 } }
+ */
+void do_info_migrate(Monitor *mon, QObject **ret_data)
{
MigrationState *s = current_migration;
if (s) {
- monitor_printf(mon, "Migration status: ");
switch (s->get_status(s)) {
case MIG_STATE_ACTIVE:
- monitor_printf(mon, "active\n");
- monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n", ram_bytes_transferred() >> 10);
- monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n", ram_bytes_remaining() >> 10);
- monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n", ram_bytes_total() >> 10);
+ *ret_data = qobject_from_jsonf("{ 'status': 'active', 'ram': { 'transferred': %" PRId64 ", 'remaining': %" PRId64 ", 'total': %" PRId64 "} }", NULL, ram_bytes_transferred(), ram_bytes_remaining(), ram_bytes_total());
break;
case MIG_STATE_COMPLETED:
- monitor_printf(mon, "completed\n");
+ *ret_data = qobject_from_jsonf("{ 'status': 'completed' }", NULL);
break;
case MIG_STATE_ERROR:
- monitor_printf(mon, "failed\n");
+ *ret_data = qobject_from_jsonf("{ 'status': 'failed' }", NULL);
break;
case MIG_STATE_CANCELLED:
- monitor_printf(mon, "cancelled\n");
+ *ret_data = qobject_from_jsonf("{ 'status': 'cancelled' }", NULL);
break;
}
+ assert(*ret_data != NULL);
}
}
diff --git a/migration.h b/migration.h
index 2d28b8f..7666c4b 100644
--- a/migration.h
+++ b/migration.h
@@ -60,7 +60,8 @@ uint64_t migrate_max_downtime(void);
void do_migrate_set_downtime(Monitor *mon, const QDict *qdict);
-void do_info_migrate(Monitor *mon);
+void migration_user_print(Monitor *mon, const QObject *data);
+void do_info_migrate(Monitor *mon, QObject **ret_data);
int exec_start_incoming_migration(const char *host_port);
diff --git a/monitor.c b/monitor.c
index 109ff5c..667dd7c 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2177,7 +2177,8 @@ static const mon_cmd_t info_cmds[] = {
.args_type = "",
.params = "",
.help = "show migration status",
- .mhandler.info = do_info_migrate,
+ .user_print = migration_user_print,
+ .mhandler.info_new = do_info_migrate,
},
{
.name = "balloon",
--
1.6.5.2.101.gcd0f8
next prev parent reply other threads:[~2009-11-01 14:51 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-01 14:51 [Qemu-devel] [RFC 0/8]: Some 'info' handlers conversions Luiz Capitulino
2009-11-01 14:51 ` [Qemu-devel] [PATCH 1/8] Introduce qemu-objects.h header file Luiz Capitulino
2009-11-01 14:51 ` [Qemu-devel] [PATCH 2/8] Makefile: move QObject objs to their own entry Luiz Capitulino
2009-11-01 14:51 ` [Qemu-devel] [PATCH 3/8] QDict: Introduce qdict_get_qbool() Luiz Capitulino
2009-11-01 14:51 ` Luiz Capitulino [this message]
2009-11-01 14:51 ` [Qemu-devel] [PATCH 5/8] monitor: Convert bdrv_info() to QObject Luiz Capitulino
2009-11-01 14:51 ` [Qemu-devel] [PATCH 6/8] monitor: Convert qemu_chr_info() " Luiz Capitulino
2009-11-01 14:51 ` [Qemu-devel] [PATCH 7/8] monitor: Convert pci_device_hot_add() " Luiz Capitulino
2009-11-01 14:51 ` [Qemu-devel] [PATCH 8/8] monitor: Convert do_info_status() " Luiz Capitulino
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1257087078-5757-5-git-send-email-lcapitulino@redhat.com \
--to=lcapitulino@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).