From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MyQz1-0005mq-Iu for qemu-devel@nongnu.org; Thu, 15 Oct 2009 10:07:11 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MyQyw-0005lO-MB for qemu-devel@nongnu.org; Thu, 15 Oct 2009 10:07:11 -0400 Received: from [199.232.76.173] (port=58294 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MyQyw-0005lL-GM for qemu-devel@nongnu.org; Thu, 15 Oct 2009 10:07:06 -0400 Received: from qw-out-1920.google.com ([74.125.92.150]:32422) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MyQyw-0001Sq-1c for qemu-devel@nongnu.org; Thu, 15 Oct 2009 10:07:06 -0400 Received: by qw-out-1920.google.com with SMTP id 5so242655qwc.4 for ; Thu, 15 Oct 2009 07:07:05 -0700 (PDT) Message-ID: <4AD72C86.3090305@codemonkey.ws> Date: Thu, 15 Oct 2009 09:07:02 -0500 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH 07/10] monitor: Convert do_info_migrate() to QObject References: <1255037747-3340-1-git-send-email-lcapitulino@redhat.com> <1255037747-3340-8-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1255037747-3340-8-git-send-email-lcapitulino@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Luiz Capitulino Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org Luiz Capitulino wrote: > 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 > --- > migration.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++------- > migration.h | 3 +- > monitor.c | 3 +- > 3 files changed, 64 insertions(+), 11 deletions(-) > > diff --git a/migration.c b/migration.c > index 112a5b6..b3bf00f 100644 > --- a/migration.c > +++ b/migration.c > @@ -18,6 +18,7 @@ > #include "sysemu.h" > #include "block.h" > #include "qemu_socket.h" > +#include "qmisc.h" > > //#define DEBUG_MIGRATION > > @@ -158,29 +159,79 @@ 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; > + > + assert(qobject_type(data) == QTYPE_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(): Show 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", "error" or "cancelled": > + * > + * { "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_fmt("{ s: s, s: { s: i, s: i, s: i } }", > + "status", "active", > + "ram", > + "transferred", ram_bytes_transferred(), > + "remaining", ram_bytes_remaining(), > + "total", ram_bytes_total()); > While we're at it, let's add string parsing support. So this becomes *ret_data = qobject_from_fmt("{'status': %s, 'ram': {'transferred': %d, 'remaining': %d, 'total': %d}}", ram_bytes_transferred(), ram_bytes_remaining(), ram_bytes_total()); Regards, Anthony Liguori