diff mbox series

[6/6] migration: make migrate uri parameter optional

Message ID 20171030112112.6952-7-quintela@redhat.com
State New
Headers show
Series Improve info migrate output on destination | expand

Commit Message

Juan Quintela Oct. 30, 2017, 11:21 a.m. UTC
Now that we have set an uri migration parameter, we can make it
optional in the command line.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hmp-commands.hx       |  4 ++--
 hmp.c                 |  5 +++--
 migration/migration.c | 12 +++++++++---
 qapi/migration.json   |  2 +-
 4 files changed, 15 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 4afd57cf5f..5be4e3934d 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -928,8 +928,8 @@  ETEXI
 
     {
         .name       = "migrate",
-        .args_type  = "detach:-d,blk:-b,inc:-i,uri:s",
-        .params     = "[-d] [-b] [-i] uri",
+        .args_type  = "detach:-d,blk:-b,inc:-i,uri:-s",
+        .params     = "[-d] [-b] [-i] [uri]",
         .help       = "migrate to URI (using -d to not wait for completion)"
 		      "\n\t\t\t -b for migration without shared storage with"
 		      " full copy of disk\n\t\t\t -i for migration without "
diff --git a/hmp.c b/hmp.c
index 9c544560bb..f8fae740e8 100644
--- a/hmp.c
+++ b/hmp.c
@@ -1938,10 +1938,11 @@  void hmp_migrate(Monitor *mon, const QDict *qdict)
     bool detach = qdict_get_try_bool(qdict, "detach", false);
     bool blk = qdict_get_try_bool(qdict, "blk", false);
     bool inc = qdict_get_try_bool(qdict, "inc", false);
-    const char *uri = qdict_get_str(qdict, "uri");
+    bool has_uri = qdict_get_try_bool(qdict, "uri", false);
+    const char *uri = qdict_get_try_str(qdict, "uri");
     Error *err = NULL;
 
-    qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
+    qmp_migrate(!!has_uri, uri, !!blk, blk, !!inc, inc, false, false, &err);
     if (err) {
         error_report_err(err);
         return;
diff --git a/migration/migration.c b/migration/migration.c
index 507226907b..3818a83489 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -1356,7 +1356,7 @@  bool migration_is_blocked(Error **errp)
     return false;
 }
 
-void qmp_migrate(const char *uri, bool has_blk, bool blk,
+void qmp_migrate(bool has_uri, const char *uri, bool has_blk, bool blk,
                  bool has_inc, bool inc, bool has_detach, bool detach,
                  Error **errp)
 {
@@ -1374,7 +1374,13 @@  void qmp_migrate(const char *uri, bool has_blk, bool blk,
         error_setg(errp, "Guest is waiting for an incoming migration");
         return;
     }
-    migrate_set_uri(uri, errp);
+    if (has_uri && uri) {
+        migrate_set_uri(uri, errp);
+    }
+    if (!s->parameters.uri) {
+        error_setg(errp, "Migration uri needs to be set");
+        return;
+    }
     if (migration_is_blocked(errp)) {
         return;
     }
@@ -1412,7 +1418,7 @@  void qmp_migrate(const char *uri, bool has_blk, bool blk,
     } else if (strstart(s->parameters.uri, "fd:", &p)) {
         fd_start_outgoing_migration(s, p, &local_err);
     } else {
-        error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "s->parameters.uri",
+        error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "migration uri",
                    "a valid migration protocol");
         migrate_set_state(&s->state, MIGRATION_STATUS_SETUP,
                           MIGRATION_STATUS_FAILED);
diff --git a/qapi/migration.json b/qapi/migration.json
index ebde890604..6b9758ab99 100644
--- a/qapi/migration.json
+++ b/qapi/migration.json
@@ -1042,7 +1042,7 @@ 
 #
 ##
 { 'command': 'migrate',
-  'data': {'uri': 'str', '*blk': 'bool', '*inc': 'bool', '*detach': 'bool' } }
+  'data': {'*uri': 'str', '*blk': 'bool', '*inc': 'bool', '*detach': 'bool' } }
 
 ##
 # @migrate-incoming: