From patchwork Thu Oct 8 21:35:44 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 35537 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9C511B7B6B for ; Fri, 9 Oct 2009 08:59:18 +1100 (EST) Received: from localhost ([127.0.0.1]:59825 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mw111-0002Vp-SV for incoming@patchwork.ozlabs.org; Thu, 08 Oct 2009 17:59:15 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mw0ev-0001Lp-KJ for qemu-devel@nongnu.org; Thu, 08 Oct 2009 17:36:26 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mw0ep-0001DZ-If for qemu-devel@nongnu.org; Thu, 08 Oct 2009 17:36:23 -0400 Received: from [199.232.76.173] (port=34348 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mw0eo-0001Bp-L6 for qemu-devel@nongnu.org; Thu, 08 Oct 2009 17:36:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55146) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mw0en-00030I-45 for qemu-devel@nongnu.org; Thu, 08 Oct 2009 17:36:17 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n98LaG49025052; Thu, 8 Oct 2009 17:36:16 -0400 Received: from localhost (vpn-13-37.rdu.redhat.com [10.11.13.37]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n98LaEws017176; Thu, 8 Oct 2009 17:36:15 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Thu, 8 Oct 2009 18:35:44 -0300 Message-Id: <1255037747-3340-8-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1255037747-3340-1-git-send-email-lcapitulino@redhat.com> References: <1255037747-3340-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: aliguori@us.ibm.com Subject: [Qemu-devel] [PATCH 07/10] monitor: Convert do_info_migrate() to QObject X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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()); break; case MIG_STATE_COMPLETED: - monitor_printf(mon, "completed\n"); + *ret_data = qobject_from_fmt("{ s: s }", "status", "completed"); break; case MIG_STATE_ERROR: - monitor_printf(mon, "failed\n"); + *ret_data = qobject_from_fmt("{ s: s }", "status", "failed"); break; case MIG_STATE_CANCELLED: - monitor_printf(mon, "cancelled\n"); + *ret_data = qobject_from_fmt("{ s: s }", "status", "cancelled"); break; } + if (*ret_data == NULL) + monitor_printf(mon, "Migration: could not build QObject\n"); } } 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 a095971..7e5c07d 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",