From patchwork Mon Nov 23 20:06:18 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 39091 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 3DA69B6EEF for ; Tue, 24 Nov 2009 07:27:52 +1100 (EST) Received: from localhost ([127.0.0.1]:56893 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NCfVl-0000bg-9T for incoming@patchwork.ozlabs.org; Mon, 23 Nov 2009 15:27:49 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NCfBb-0008VM-Qb for qemu-devel@nongnu.org; Mon, 23 Nov 2009 15:06:59 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NCfBW-0008Sd-2S for qemu-devel@nongnu.org; Mon, 23 Nov 2009 15:06:58 -0500 Received: from [199.232.76.173] (port=42686 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NCfBV-0008SY-QL for qemu-devel@nongnu.org; Mon, 23 Nov 2009 15:06:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:64223) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NCfBV-0001c4-8h for qemu-devel@nongnu.org; Mon, 23 Nov 2009 15:06:53 -0500 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nANK6qxD002925 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 23 Nov 2009 15:06:52 -0500 Received: from localhost (vpn-9-248.rdu.redhat.com [10.11.9.248]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nANK6pRL027986 for ; Mon, 23 Nov 2009 15:06:51 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Mon, 23 Nov 2009 18:06:18 -0200 Message-Id: <1259006783-945-13-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1259006783-945-1-git-send-email-lcapitulino@redhat.com> References: <1259006783-945-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH 12/17] migration: 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. IMPORTANT: as a QInt stores a int64_t integer, RAM values are going to be 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. Signed-off-by: Luiz Capitulino --- migration.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++------- migration.h | 4 ++- monitor.c | 3 +- 3 files changed, 64 insertions(+), 11 deletions(-) diff --git a/migration.c b/migration.c index 3ae0be8..96f4f02 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 @@ -157,29 +158,78 @@ void do_migrate_set_downtime(Monitor *mon, const QDict *qdict) max_downtime = (uint64_t)d; } -void do_info_migrate(Monitor *mon) +void do_info_migrate_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 "} }", + 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' }"); break; case MIG_STATE_ERROR: - monitor_printf(mon, "failed\n"); + *ret_data = qobject_from_jsonf("{ 'status': 'failed' }"); break; case MIG_STATE_CANCELLED: - monitor_printf(mon, "cancelled\n"); + *ret_data = qobject_from_jsonf("{ 'status': 'cancelled' }"); break; } + assert(*ret_data != NULL); } } diff --git a/migration.h b/migration.h index 56adf05..08c3dcc 100644 --- a/migration.h +++ b/migration.h @@ -62,7 +62,9 @@ uint64_t migrate_max_downtime(void); void do_migrate_set_downtime(Monitor *mon, const QDict *qdict); -void do_info_migrate(Monitor *mon); +void do_info_migrate_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 ac0c02c..3485f4b 100644 --- a/monitor.c +++ b/monitor.c @@ -2257,7 +2257,8 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show migration status", - .mhandler.info = do_info_migrate, + .user_print = do_info_migrate_print, + .mhandler.info_new = do_info_migrate, }, { .name = "balloon",