From: Yonit Halperin <yhalperi@redhat.com>
To: qemu-devel@nongnu.org
Cc: Yonit Halperin <yhalperi@redhat.com>,
aliguori@us.ibm.com, alevy@redhat.com, kraxel@redhat.com
Subject: [Qemu-devel] [RFC PATCH 2/5] migration: moving migration start code to a separated routine
Date: Tue, 5 Jun 2012 08:49:43 +0300 [thread overview]
Message-ID: <1338875386-21051-3-git-send-email-yhalperi@redhat.com> (raw)
In-Reply-To: <1338875386-21051-1-git-send-email-yhalperi@redhat.com>
Preparation for asynchronous migration state change notifiers.
In a following patch the migrate_start routine will be used as
the completion callback of the "migration start" notifiers list.
Signed-off-by: Yonit Halperin <yhalperi@redhat.com>
---
migration.c | 73 +++++++++++++++++++++++++++++++++++++++++++++-------------
migration.h | 2 +
2 files changed, 58 insertions(+), 17 deletions(-)
diff --git a/migration.c b/migration.c
index acaf293..91c807d 100644
--- a/migration.c
+++ b/migration.c
@@ -41,6 +41,14 @@ enum {
MIG_STATE_COMPLETED,
};
+enum {
+ MIGRATION_PROTOCOL_ERROR,
+ MIGRATION_PROTOCOL_TCP,
+ MIGRATION_PROTOCOL_EXEC,
+ MIGRATION_PROTOCOL_UNIX,
+ MIGRATION_PROTOCOL_FD,
+};
+
#define MAX_THROTTLE (32 << 20) /* Migration speed throttling */
static NotifierList migration_state_notifiers =
@@ -361,13 +369,16 @@ void migrate_fd_connect(MigrationState *s)
migrate_fd_put_ready(s);
}
-static MigrationState *migrate_init(int blk, int inc)
+static MigrationState *migrate_init(int protocol, const char *protocol_param,
+ int blk, int inc)
{
MigrationState *s = migrate_get_current();
int64_t bandwidth_limit = s->bandwidth_limit;
memset(s, 0, sizeof(*s));
s->bandwidth_limit = bandwidth_limit;
+ s->protocol = protocol;
+ s->protocol_param = g_strdup(protocol_param);
s->blk = blk;
s->shared = inc;
@@ -389,13 +400,50 @@ void migrate_del_blocker(Error *reason)
migration_blockers = g_slist_remove(migration_blockers, reason);
}
+static void migrate_start(MigrationState *s, Error **errp)
+{
+ int ret;
+
+ switch (s->protocol) {
+ case MIGRATION_PROTOCOL_TCP:
+ ret = tcp_start_outgoing_migration(s, s->protocol_param, errp);
+ break;
+#if !defined(WIN32)
+ case MIGRATION_PROTOCOL_EXEC:
+ ret = exec_start_outgoing_migration(s, s->protocol_param);
+ break;
+ case MIGRATION_PROTOCOL_UNIX:
+ ret = unix_start_outgoing_migration(s, s->protocol_param);
+ break;
+ case MIGRATION_PROTOCOL_FD:
+ ret = fd_start_outgoing_migration(s, s->protocol_param);
+ break;
+#endif
+ default:
+ ret = -EPROTONOSUPPORT;
+ }
+
+ g_free(s->protocol_param);
+ s->protocol_param = NULL;
+
+ if (ret < 0) {
+ if (!error_is_set(errp)) {
+ DPRINTF("migration failed: %s\n", strerror(-ret));
+ /* FIXME: we should return meaningful errors */
+ error_set(errp, QERR_UNDEFINED_ERROR);
+ }
+ return;
+ }
+ notifier_list_notify(&migration_state_notifiers, s);
+}
+
void qmp_migrate(const char *uri, bool has_blk, bool blk,
bool has_inc, bool inc, bool has_detach, bool detach,
Error **errp)
{
MigrationState *s = migrate_get_current();
const char *p;
- int ret;
+ int migrate_protocol;
if (s->state == MIG_STATE_ACTIVE) {
error_set(errp, QERR_MIGRATION_ACTIVE);
@@ -411,33 +459,24 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
return;
}
- s = migrate_init(blk, inc);
-
if (strstart(uri, "tcp:", &p)) {
- ret = tcp_start_outgoing_migration(s, p, errp);
+ migrate_protocol = MIGRATION_PROTOCOL_TCP;
#if !defined(WIN32)
} else if (strstart(uri, "exec:", &p)) {
- ret = exec_start_outgoing_migration(s, p);
+ migrate_protocol = MIGRATION_PROTOCOL_EXEC;
} else if (strstart(uri, "unix:", &p)) {
- ret = unix_start_outgoing_migration(s, p);
+ migrate_protocol = MIGRATION_PROTOCOL_UNIX;
} else if (strstart(uri, "fd:", &p)) {
- ret = fd_start_outgoing_migration(s, p);
+ migrate_protocol = MIGRATION_PROTOCOL_FD;
#endif
} else {
error_set(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol");
return;
}
+ s = migrate_init(migrate_protocol, p, blk, inc);
- if (ret < 0) {
- if (!error_is_set(errp)) {
- DPRINTF("migration failed: %s\n", strerror(-ret));
- /* FIXME: we should return meaningful errors */
- error_set(errp, QERR_UNDEFINED_ERROR);
- }
- return;
- }
+ migrate_start(s, errp);
- notifier_list_notify(&migration_state_notifiers, s);
}
void qmp_migrate_cancel(Error **errp)
diff --git a/migration.h b/migration.h
index 2e9ca2e..5ad67d7 100644
--- a/migration.h
+++ b/migration.h
@@ -33,6 +33,8 @@ struct MigrationState
void *opaque;
int blk;
int shared;
+ int protocol;
+ char *protocol_param;
};
void process_incoming_migration(QEMUFile *f);
--
1.7.7.6
next prev parent reply other threads:[~2012-06-05 5:48 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-05 5:49 [Qemu-devel] [RFC PATCH 0/5] asynchronous migration state change handlers Yonit Halperin
2012-06-05 5:49 ` [Qemu-devel] [RFC PATCH 1/5] notifiers: add support for async notifiers handlers Yonit Halperin
2012-06-05 8:36 ` Gerd Hoffmann
2012-06-05 5:49 ` Yonit Halperin [this message]
2012-06-05 8:44 ` [Qemu-devel] [RFC PATCH 2/5] migration: moving migration start code to a separated routine Gerd Hoffmann
2012-06-05 5:49 ` [Qemu-devel] [RFC PATCH 3/5] migration: moving migration completion " Yonit Halperin
2012-06-05 8:46 ` Gerd Hoffmann
2012-06-05 5:49 ` [Qemu-devel] [RFC PATCH 4/5] migration: replace migration state change notifier with async notifiers Yonit Halperin
2012-06-05 5:49 ` [Qemu-devel] [RFC PATCH 5/5] spice: turn spice "migration end" handler to be async Yonit Halperin
2012-06-05 11:59 ` [Qemu-devel] [RFC PATCH 0/5] asynchronous migration state change handlers Anthony Liguori
2012-06-05 13:15 ` Gerd Hoffmann
2012-06-05 13:38 ` Eric Blake
2012-06-05 21:37 ` Anthony Liguori
2012-06-06 9:10 ` Yonit Halperin
2012-06-06 9:22 ` Anthony Liguori
2012-06-06 10:54 ` Alon Levy
2012-06-06 11:05 ` Anthony Liguori
2012-06-06 11:27 ` Alon Levy
2012-06-06 11:49 ` Anthony Liguori
2012-06-06 12:01 ` Yonit Halperin
2012-06-06 12:08 ` Anthony Liguori
2012-06-06 12:15 ` Alon Levy
2012-06-06 12:17 ` Anthony Liguori
2012-06-06 12:30 ` Alon Levy
2012-06-06 12:34 ` Anthony Liguori
2012-06-06 13:03 ` Gerd Hoffmann
2012-06-06 14:52 ` Alon Levy
2012-06-06 15:00 ` Gerd Hoffmann
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=1338875386-21051-3-git-send-email-yhalperi@redhat.com \
--to=yhalperi@redhat.com \
--cc=alevy@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).