All of lore.kernel.org
 help / color / mirror / Atom feed
From: Juan Quintela <quintela@redhat.com>
To: qemu-devel@nongnu.org
Cc: zhanghailiang <zhang.zhanghailiang@huawei.com>
Subject: [Qemu-devel] [PULL 12/13] migration: Convert 'status' of MigrationInfo to use an enum type
Date: Tue, 17 Mar 2015 16:30:34 +0100	[thread overview]
Message-ID: <1426606235-7238-13-git-send-email-quintela@redhat.com> (raw)
In-Reply-To: <1426606235-7238-1-git-send-email-quintela@redhat.com>

From: zhanghailiang <zhang.zhanghailiang@huawei.com>

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 (just remove the typo) :
s/'completed'. 'comppleted' (since 1.2)/'completed' (since 1.2)

Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hmp.c                 |  7 ++++---
 migration/migration.c | 20 +++++---------------
 qapi-schema.json      | 34 +++++++++++++++++++++++++++++-----
 3 files changed, 38 insertions(+), 23 deletions(-)

diff --git a/hmp.c b/hmp.c
index 8afce2d..7d5c81e 100644
--- a/hmp.c
+++ b/hmp.c
@@ -162,7 +162,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",
+                       MigrationStatus_lookup[info->status]);
         monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
                        info->total_time);
         if (info->has_expected_downtime) {
@@ -1354,8 +1355,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 == MIGRATION_STATUS_ACTIVE ||
+        info->status == MIGRATION_STATUS_SETUP) {
         if (info->has_disk) {
             int progress;

diff --git a/migration/migration.c b/migration/migration.c
index b0860fa..d7a1e7d 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -26,16 +26,6 @@
 #include "qmp-commands.h"
 #include "trace.h"

-enum {
-    MIGRATION_STATUS_FAILED = -1,
-    MIGRATION_STATUS_NONE,
-    MIGRATION_STATUS_SETUP,
-    MIGRATION_STATUS_CANCELLING,
-    MIGRATION_STATUS_CANCELLED,
-    MIGRATION_STATUS_ACTIVE,
-    MIGRATION_STATUS_COMPLETED,
-};
-
 #define MAX_THROTTLE  (32 << 20)      /* Migration speed throttling */

 /* Amount of time to allocate to each "chunk" of bandwidth-throttled
@@ -205,13 +195,13 @@ MigrationInfo *qmp_query_migrate(Error **errp)
         break;
     case MIGRATION_STATUS_SETUP:
         info->has_status = true;
-        info->status = g_strdup("setup");
+        info->status = MIGRATION_STATUS_SETUP;
         info->has_total_time = false;
         break;
     case MIGRATION_STATUS_ACTIVE:
     case MIGRATION_STATUS_CANCELLING:
         info->has_status = true;
-        info->status = g_strdup("active");
+        info->status = MIGRATION_STATUS_ACTIVE;
         info->has_total_time = true;
         info->total_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME)
             - s->total_time;
@@ -247,7 +237,7 @@ MigrationInfo *qmp_query_migrate(Error **errp)
         get_xbzrle_cache_stats(info);

         info->has_status = true;
-        info->status = g_strdup("completed");
+        info->status = MIGRATION_STATUS_COMPLETED;
         info->has_total_time = true;
         info->total_time = s->total_time;
         info->has_downtime = true;
@@ -269,11 +259,11 @@ MigrationInfo *qmp_query_migrate(Error **errp)
         break;
     case MIGRATION_STATUS_FAILED:
         info->has_status = true;
-        info->status = g_strdup("failed");
+        info->status = MIGRATION_STATUS_FAILED;
         break;
     case MIGRATION_STATUS_CANCELLED:
         info->has_status = true;
-        info->status = g_strdup("cancelled");
+        info->status = MIGRATION_STATUS_CANCELLED;
         break;
     }

diff --git a/qapi-schema.json b/qapi-schema.json
index d1f65a1..ac9594d 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -410,19 +410,43 @@
            'cache-miss': 'int', 'cache-miss-rate': 'number',
            'overflow': 'int' } }

+# @MigrationStatus:
+#
+# An enumeration of migration status.
+#
+# @none: no migration has ever happened.
+#
+# @setup: migration process has been initiated.
+#
+# @cancelling: in the process of cancelling migration.
+#
+# @cancelled: cancelling migration is finished.
+#
+# @active: in the process of doing migration.
+#
+# @completed: migration is finished.
+#
+# @failed: some error occurred during migration process.
+#
+# Since: 2.3
+#
+##
+{ 'enum': 'MigrationStatus',
+  'data': [ 'none', 'setup', 'cancelling', 'cancelled',
+            'active', 'completed', 'failed' ] }
+
 ##
 # @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 @MigrationStatus 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'(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': 'MigrationStatus', '*ram': 'MigrationStats',
            '*disk': 'MigrationStats',
            '*xbzrle-cache': 'XBZRLECacheStats',
            '*total-time': 'int',
-- 
2.1.0

  parent reply	other threads:[~2015-03-17 15:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-17 15:30 [Qemu-devel] [PULL 00/13] migration pull queue Juan Quintela
2015-03-17 15:30 ` [Qemu-devel] [PULL 01/13] migration: Avoid qerror_report_err() outside QMP command handlers Juan Quintela
2015-03-17 15:30 ` [Qemu-devel] [PULL 02/13] migration/rdma: clean up qemu_rdma_dest_init a bit Juan Quintela
2015-03-17 15:30 ` [Qemu-devel] [PULL 03/13] migration: Fix some 32 bit compiler errors Juan Quintela
2015-03-17 15:30 ` [Qemu-devel] [PULL 04/13] migration: Fix remaining " Juan Quintela
2015-03-17 15:30 ` [Qemu-devel] [PULL 05/13] migrate_incoming: use hmp_handle_error Juan Quintela
2015-03-17 15:30 ` [Qemu-devel] [PULL 06/13] Warn against the use of the string as uri parameter to migrate-incoming Juan Quintela
2015-03-17 15:30 ` [Qemu-devel] [PULL 07/13] migrate_incoming: Cleanup/clarify error messages Juan Quintela
2015-03-17 15:30 ` [Qemu-devel] [PULL 08/13] arch_init: Count the total number of pages by using helper function Juan Quintela
2015-03-17 15:30 ` [Qemu-devel] [PULL 09/13] migration: Remove unused functions Juan Quintela
2015-03-17 15:30 ` [Qemu-devel] [PULL 10/13] migration: Rename abbreviated macro MIG_STATE_* to MIGRATION_STATUS_* Juan Quintela
2015-03-17 15:30 ` [Qemu-devel] [PULL 11/13] hmp: Rename 'MigrationStatus' to 'HMPMigrationStatus' Juan Quintela
2015-03-17 15:30 ` Juan Quintela [this message]
2015-03-17 15:30 ` [Qemu-devel] [PULL 13/13] migration: Expose 'cancelling' status to user Juan Quintela
2015-03-17 18:53 ` [Qemu-devel] [PULL 00/13] migration pull queue Peter Maydell

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=1426606235-7238-13-git-send-email-quintela@redhat.com \
    --to=quintela@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=zhang.zhanghailiang@huawei.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.