Patchwork [02/11] Add migrate_set_parameter command

login
register
mail settings
Submitter Juan Quintela
Date July 24, 2012, 6:19 p.m.
Message ID <1343153964-25254-3-git-send-email-quintela@redhat.com>
Download mbox | patch
Permalink /patch/172999/
State New
Headers show

Comments

Juan Quintela - July 24, 2012, 6:19 p.m.
From: Orit Wasserman <owasserm@redhat.com>

The management can enable/disable a capability for the next migration by using
migrate_set_parameter command.

Signed-off-by: Orit Wasserman <owasserm@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hmp-commands.hx  |   14 ++++++++++++++
 hmp.c            |   45 +++++++++++++++++++++++++++++++++++++++++++++
 hmp.h            |    1 +
 migration.c      |   46 ++++++++++++++++++++++++++++++++++++++++++++--
 migration.h      |    2 ++
 qapi-schema.json |   16 +++++++++++++++-
 qmp-commands.hx  |   47 ++++++++++++++++++++++++++++++++++++++++++++---
 7 files changed, 165 insertions(+), 6 deletions(-)

Patch

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 8786148..4e279a5 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -861,6 +861,20 @@  Set maximum tolerated downtime (in seconds) for migration.
 ETEXI

     {
+        .name       = "migrate_set_parameter",
+        .args_type  = "capability:s,state:b",
+        .params     = "capability state",
+        .help       = "Enable/Disable the usage of a capability for migration",
+        .mhandler.cmd = hmp_migrate_set_parameter,
+    },
+
+STEXI
+@item migrate_set_parameter @var{capability} @var{state}
+@findex migrate_set_parameter
+Enable/Disable the usage of a capability @var{capability} for migration.
+ETEXI
+
+    {
         .name       = "client_migrate_info",
         .args_type  = "protocol:s,hostname:s,port:i?,tls-port:i?,cert-subject:s?",
         .params     = "protocol hostname port tls-port cert-subject",
diff --git a/hmp.c b/hmp.c
index 5c7d0be..3a30660 100644
--- a/hmp.c
+++ b/hmp.c
@@ -131,9 +131,19 @@  void hmp_info_mice(Monitor *mon)
 void hmp_info_migrate(Monitor *mon)
 {
     MigrationInfo *info;
+    MigrationCapabilityStatusList *cap;

     info = qmp_query_migrate(NULL);

+    if (info->has_capabilities && info->capabilities) {
+        monitor_printf(mon, "capabilities: ");
+        for (cap = info->capabilities; cap; cap = cap->next) {
+            monitor_printf(mon, "%s: %s ",
+                           MigrationCapability_lookup[cap->value->capability],
+                           cap->value->state ? "on" : "off");
+        }
+        monitor_printf(mon, "\n");
+    }
     if (info->has_status) {
         monitor_printf(mon, "Migration status: %s\n", info->status);
     }
@@ -754,6 +764,41 @@  void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
     qmp_migrate_set_speed(value, NULL);
 }

+void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
+{
+    const char *cap = qdict_get_str(qdict, "capability");
+    bool state = qdict_get_bool(qdict, "state");
+    Error *err = NULL;
+    MigrationCapabilityStatusList *params = NULL;
+    int i;
+
+    for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+        if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
+            if (!params) {
+                params = g_malloc0(sizeof(*params));
+            }
+            params->value = g_malloc0(sizeof(*params->value));
+            params->value->capability = i;
+            params->value->state = state;
+            params->next = NULL;
+            qmp_migrate_set_parameters(params, &err);
+            break;
+        }
+    }
+
+    if (i == MIGRATION_CAPABILITY_MAX) {
+        error_set(&err, QERR_INVALID_PARAMETER, cap);
+    }
+
+    qapi_free_MigrationCapabilityStatusList(params);
+
+    if (err) {
+        monitor_printf(mon, "migrate_set_parameter: %s\n",
+                       error_get_pretty(err));
+        error_free(err);
+    }
+}
+
 void hmp_set_password(Monitor *mon, const QDict *qdict)
 {
     const char *protocol  = qdict_get_str(qdict, "protocol");
diff --git a/hmp.h b/hmp.h
index 2fb44ca..38f1f25 100644
--- a/hmp.h
+++ b/hmp.h
@@ -52,6 +52,7 @@  void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict);
 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict);
+void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict);
 void hmp_set_password(Monitor *mon, const QDict *qdict);
 void hmp_expire_password(Monitor *mon, const QDict *qdict);
 void hmp_eject(Monitor *mon, const QDict *qdict);
diff --git a/migration.c b/migration.c
index 8c27347..12c16bb 100644
--- a/migration.c
+++ b/migration.c
@@ -113,6 +113,22 @@  uint64_t migrate_max_downtime(void)
     return max_downtime;
 }

+static void get_capabilities(MigrationState *s, MigrationInfo *info)
+{
+    int i;
+
+    for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+        if (!info->has_capabilities) {
+            info->capabilities = g_malloc0(sizeof(*info->capabilities));
+            info->has_capabilities = true;
+        }
+        info->capabilities->value =
+            g_malloc(sizeof(*info->capabilities->value));
+        info->capabilities->value->capability = i;
+        info->capabilities->value->state = s->enabled_capabilities[i];
+        info->capabilities->next = NULL;
+    }
+}
 MigrationInfo *qmp_query_migrate(Error **errp)
 {
     MigrationInfo *info = g_malloc0(sizeof(*info));
@@ -120,9 +136,12 @@  MigrationInfo *qmp_query_migrate(Error **errp)

     switch (s->state) {
     case MIG_STATE_SETUP:
-        /* no migration has happened ever */
+        /* no migration has ever happened; show enabled capabilities */
+        get_capabilities(s, info);
         break;
     case MIG_STATE_ACTIVE:
+        get_capabilities(s, info);
+
         info->has_status = true;
         info->status = g_strdup("active");

@@ -143,6 +162,8 @@  MigrationInfo *qmp_query_migrate(Error **errp)
         }
         break;
     case MIG_STATE_COMPLETED:
+        get_capabilities(s, info);
+
         info->has_status = true;
         info->status = g_strdup("completed");

@@ -177,6 +198,22 @@  MigrationCapabilityStatusList *qmp_query_migration_capabilities(Error **errp)
     return caps_list;
 }

+void qmp_migrate_set_parameters(MigrationCapabilityStatusList *params,
+                                Error **errp)
+{
+    MigrationState *s = migrate_get_current();
+    MigrationCapabilityStatusList *cap;
+
+    if (s->state == MIG_STATE_ACTIVE) {
+        error_set(errp, QERR_MIGRATION_ACTIVE);
+        return;
+    }
+
+    for (cap = params; cap; cap = cap->next) {
+        s->enabled_capabilities[cap->value->capability] = cap->value->state;
+    }
+}
+
 /* shared migration helpers */

 static int migrate_fd_cleanup(MigrationState *s)
@@ -386,12 +423,17 @@  static MigrationState *migrate_init(const MigrationParams *params)
 {
     MigrationState *s = migrate_get_current();
     int64_t bandwidth_limit = s->bandwidth_limit;
+    bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
+
+    memcpy(enabled_capabilities, s->enabled_capabilities,
+           sizeof(enabled_capabilities));

     memset(s, 0, sizeof(*s));
     s->bandwidth_limit = bandwidth_limit;
     s->params = *params;
+    memcpy(s->enabled_capabilities, enabled_capabilities,
+           sizeof(enabled_capabilities));

-    s->bandwidth_limit = bandwidth_limit;
     s->state = MIG_STATE_SETUP;
     s->total_time = qemu_get_clock_ms(rt_clock);

diff --git a/migration.h b/migration.h
index 57572a6..713aae0 100644
--- a/migration.h
+++ b/migration.h
@@ -19,6 +19,7 @@ 
 #include "notify.h"
 #include "error.h"
 #include "vmstate.h"
+#include "qapi-types.h"

 struct MigrationParams {
     bool blk;
@@ -39,6 +40,7 @@  struct MigrationState
     void *opaque;
     MigrationParams params;
     int64_t total_time;
+    bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
 };

 void process_incoming_migration(QEMUFile *f);
diff --git a/qapi-schema.json b/qapi-schema.json
index eddb32d..778c6bc 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -288,11 +288,15 @@ 
 #        status, only returned if status is 'active' and it is a block
 #        migration
 #
+# @capabilities: #optional a list describing all the migration capabilities
+#                state (since 1.2)
+#
 # Since: 0.14.0
 ##
 { 'type': 'MigrationInfo',
   'data': {'*status': 'str', '*ram': 'MigrationStats',
-           '*disk': 'MigrationStats'} }
+           '*disk': 'MigrationStats',
+           '*capabilities': ['MigrationCapabilityStatus']} }

 ##
 # @query-migrate
@@ -345,6 +349,16 @@ 
 { 'command': 'query-migration-capabilities', 'returns': ['MigrationCapabilityStatus'] }

 ##
+# @migrate_set_parameters
+#
+# Enable/Disable the following migration capabilities (like xbzrle)
+#
+# Since: 1.2
+##
+{ 'command': 'migrate-set-parameters',
+  'data': { 'capabilities': ['MigrationCapabilityStatus'] } }
+
+##
 # @MouseInfo:
 #
 # Information about a mouse device.
diff --git a/qmp-commands.hx b/qmp-commands.hx
index c0ed14c..f3651a8 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -2081,18 +2081,31 @@  The main json-object contains the following:
          - "transferred": amount transferred (json-int)
          - "remaining": amount remaining (json-int)
          - "total": total (json-int)
-
+- "capabilities": migration capabilities state
+         - "xbzrle" : XBZRLE state (json-bool)
 Examples:

 1. Before the first migration

 -> { "execute": "query-migrate" }
-<- { "return": {} }
+<- { "return": {
+        "capabilities" :  [ { "capability" : "xbzrle", "state" : false } ]
+     }
+   }

 2. Migration is done and has succeeded

 -> { "execute": "query-migrate" }
-<- { "return": { "status": "completed" } }
+<- { "return": {
+        "status": "completed",
+        "capabilities":  [ { "capability" : "xbzrle", "state" : false } ],
+        "ram":{
+          "transferred":123,
+          "remaining":123,
+          "total":246
+        }
+     }
+   }

 3. Migration is done and has failed

@@ -2105,6 +2118,7 @@  Examples:
 <- {
       "return":{
          "status":"active",
+         "capabilities":  [ { "capability" : "xbzrle", "state" : false } ],
          "ram":{
             "transferred":123,
             "remaining":123,
@@ -2119,6 +2133,7 @@  Examples:
 <- {
       "return":{
          "status":"active",
+         "capabilities":  [ { "capability" : "xbzrle", "state" : false } ],
          "ram":{
             "total":1057024,
             "remaining":1053304,
@@ -2165,6 +2180,32 @@  EQMP
     },

 SQMP
+migrate_set_parameters
+-------
+
+Enable/Disable migration capabilities
+
+- "xbzrle": xbzrle support
+
+Arguments:
+
+Example:
+
+-> { "execute": "migrate_set_parameters" , "arguments":
+     { "parameters": [ { "capability": "xbzrle", "state": true } ] } }
+
+EQMP
+
+    {
+        .name       = "migrate_set_parameters",
+        .args_type  = "parameters:O",
+        .params     = "capability:s,state:b",
+	.mhandler.cmd_new = qmp_marshal_input_migrate_set_parameters,
+    },
+
+
+
+SQMP
 query-balloon
 -------------