From patchwork Thu Feb 26 07:58:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhanghailiang X-Patchwork-Id: 443829 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 6E0661400DD for ; Thu, 26 Feb 2015 19:01:41 +1100 (AEDT) Received: from localhost ([::1]:57799 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQtO7-00044P-O9 for incoming@patchwork.ozlabs.org; Thu, 26 Feb 2015 03:01:39 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45261) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQtMs-0000pp-IM for qemu-devel@nongnu.org; Thu, 26 Feb 2015 03:00:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YQtMp-0001Qn-0S for qemu-devel@nongnu.org; Thu, 26 Feb 2015 03:00:22 -0500 Received: from szxga02-in.huawei.com ([119.145.14.65]:13516) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQtMn-0001Pu-S5 for qemu-devel@nongnu.org; Thu, 26 Feb 2015 03:00:18 -0500 Received: from 172.24.2.119 (EHLO szxeml430-hub.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CHR82686; Thu, 26 Feb 2015 15:59:52 +0800 (CST) Received: from localhost (10.177.22.69) by szxeml430-hub.china.huawei.com (10.82.67.185) with Microsoft SMTP Server id 14.3.158.1; Thu, 26 Feb 2015 15:58:43 +0800 From: zhanghailiang To: Date: Thu, 26 Feb 2015 15:58:12 +0800 Message-ID: <1424937492-10720-1-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 1.9.2.msysgit.0 MIME-Version: 1.0 X-Originating-IP: [10.177.22.69] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.65 Cc: zhanghailiang , quintela@redhat.com, armbru@redhat.com, lcapitulino@redhat.com, amit.shah@redhat.com, peter.huangpeng@huawei.com, dgilbert@redhat.com Subject: [Qemu-devel] [PATCH RFC] migration: Convert 'status' of MigrationInfo to use an enum type X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The original 'status' is an open-coded 'str' type, convert it to use an enum type. This conversion is backwards compatible, better documented and more convenient for future extensibility. In addition, Fix a typo for qapi-schema.json: comppleted -> completed Signed-off-by: zhanghailiang --- Hi, This conversion from open-coded 'str' type to enum type for 'status' is suggested by Eric, thanks for his comment. Actually, I will add a MIG_STATE_COLO state for COLO, and i also saw David added MIG_STATE_POSTCOPY_ACTIVE for postcopy, after this conversion, it will be more convenient for us to add a new state. One more thing, i have to replace MIG_STATE_ERROR with MIG_STATE_FAILED, and it begin from 0, not its original -1. I think it has no side effect. Please review. Thanks --- hmp.c | 7 ++++--- migration/migration.c | 37 +++++++++++++++---------------------- qapi-schema.json | 34 +++++++++++++++++++++++++++++----- 3 files changed, 48 insertions(+), 30 deletions(-) diff --git a/hmp.c b/hmp.c index 3825b29..8cbd135 100644 --- a/hmp.c +++ b/hmp.c @@ -158,7 +158,8 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict) } if (info->has_status) { - monitor_printf(mon, "Migration status: %s\n", info->status); + monitor_printf(mon, "Migration status: %s\n", + MigState_lookup[info->status]); monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n", info->total_time); if (info->has_expected_downtime) { @@ -1312,8 +1313,8 @@ static void hmp_migrate_status_cb(void *opaque) MigrationInfo *info; info = qmp_query_migrate(NULL); - if (!info->has_status || strcmp(info->status, "active") == 0 || - strcmp(info->status, "setup") == 0) { + if (!info->has_status || info->status == MIG_STATE_ACTIVE || + info->status == MIG_STATE_SETUP) { if (info->has_disk) { int progress; diff --git a/migration/migration.c b/migration/migration.c index b3adbc6..8b8fbbf 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -26,16 +26,6 @@ #include "qmp-commands.h" #include "trace.h" -enum { - MIG_STATE_ERROR = -1, - MIG_STATE_NONE, - MIG_STATE_SETUP, - MIG_STATE_CANCELLING, - MIG_STATE_CANCELLED, - MIG_STATE_ACTIVE, - MIG_STATE_COMPLETED, -}; - #define MAX_THROTTLE (32 << 20) /* Migration speed throttling */ /* Amount of time to allocate to each "chunk" of bandwidth-throttled @@ -189,13 +179,16 @@ MigrationInfo *qmp_query_migrate(Error **errp) break; case MIG_STATE_SETUP: info->has_status = true; - info->status = g_strdup("setup"); + info->status = MIG_STATE_SETUP; info->has_total_time = false; break; case MIG_STATE_ACTIVE: case MIG_STATE_CANCELLING: info->has_status = true; - info->status = g_strdup("active"); + /* Note: when the real state of migration is 'cancelling', + we still return 'active' status to user, it makes no difference + for user. */ + info->status = MIG_STATE_ACTIVE; info->has_total_time = true; info->total_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME) - s->total_time; @@ -231,7 +224,7 @@ MigrationInfo *qmp_query_migrate(Error **errp) get_xbzrle_cache_stats(info); info->has_status = true; - info->status = g_strdup("completed"); + info->status = MIG_STATE_COMPLETED; info->has_total_time = true; info->total_time = s->total_time; info->has_downtime = true; @@ -251,13 +244,13 @@ MigrationInfo *qmp_query_migrate(Error **errp) info->ram->mbps = s->mbps; info->ram->dirty_sync_count = s->dirty_sync_count; break; - case MIG_STATE_ERROR: + case MIG_STATE_FAILED: info->has_status = true; - info->status = g_strdup("failed"); + info->status = MIG_STATE_FAILED; break; case MIG_STATE_CANCELLED: info->has_status = true; - info->status = g_strdup("cancelled"); + info->status = MIG_STATE_CANCELLED; break; } @@ -322,8 +315,8 @@ void migrate_fd_error(MigrationState *s) { trace_migrate_fd_error(); assert(s->file == NULL); - s->state = MIG_STATE_ERROR; - trace_migrate_set_state(MIG_STATE_ERROR); + s->state = MIG_STATE_FAILED; + trace_migrate_set_state(MIG_STATE_FAILED); notifier_list_notify(&migration_state_notifiers, s); } @@ -376,7 +369,7 @@ bool migration_has_finished(MigrationState *s) bool migration_has_failed(MigrationState *s) { return (s->state == MIG_STATE_CANCELLED || - s->state == MIG_STATE_ERROR); + s->state == MIG_STATE_FAILED); } static MigrationState *migrate_init(const MigrationParams *params) @@ -465,7 +458,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, #endif } else { error_set(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol"); - s->state = MIG_STATE_ERROR; + s->state = MIG_STATE_FAILED; return; } @@ -627,7 +620,7 @@ static void *migration_thread(void *opaque) qemu_mutex_unlock_iothread(); if (ret < 0) { - migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_ERROR); + migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_FAILED); break; } @@ -639,7 +632,7 @@ static void *migration_thread(void *opaque) } if (qemu_file_get_error(s->file)) { - migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_ERROR); + migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_FAILED); break; } current_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME); diff --git a/qapi-schema.json b/qapi-schema.json index e16f8eb..89b14a9 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -411,18 +411,42 @@ 'overflow': 'int' } } ## +# @MigState: +# +# An enumeration of migration status. +# +# @failed: some error occurred during migration process. (since 0.14.0) +# +# @none: no migration has happened ever. +# +# @setup: migration process has been initiated. (since 0.14.0) +# +# @cancelling: in the process of cancelling migration. (since 2.0) +# +# @cancelled: cancelling migration is finished. (since 0.14.0) +# +# @active: in the process of doing migration. (since 0.14.0) +# +# @completed: migration is finished. (since 0.14.0) +# +# Since: 2.3 +## +{ 'enum': 'MigState', + 'data': [ 'failed', 'none', 'setup', 'cancelling', 'cancelled', + 'active', 'completed' ] } + +## # @MigrationInfo # # Information about current migration process. # -# @status: #optional string describing the current migration status. -# As of 0.14.0 this can be 'setup', 'active', 'completed', 'failed' or -# 'cancelled'. If this field is not returned, no migration process +# @status: #optional @MigState describing the current migration status. +# If this field is not returned, no migration process # has been initiated # # @ram: #optional @MigrationStats containing detailed migration # status, only returned if status is 'active' or -# 'completed'. 'comppleted' (since 1.2) +# 'completed'. 'completed' (since 1.2) # # @disk: #optional @MigrationStats containing detailed disk migration # status, only returned if status is 'active' and it is a block @@ -453,7 +477,7 @@ # Since: 0.14.0 ## { 'type': 'MigrationInfo', - 'data': {'*status': 'str', '*ram': 'MigrationStats', + 'data': {'*status': 'MigState', '*ram': 'MigrationStats', '*disk': 'MigrationStats', '*xbzrle-cache': 'XBZRLECacheStats', '*total-time': 'int',