migration: move migrate_new to do_migrate

Once there, remove all parameters that don't need to be passed to
*start_outgoing_migration() functions

Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Juan Quintela 2010-05-11 22:27:45 +02:00
parent 8b6b99b356
commit 07af445291
6 changed files with 46 additions and 100 deletions

View File

@ -61,22 +61,14 @@ static int exec_close(MigrationState *s)
return ret; return ret;
} }
MigrationState *exec_start_outgoing_migration(Monitor *mon, int exec_start_outgoing_migration(MigrationState *s, const char *command)
const char *command,
int64_t bandwidth_limit,
int detach,
int blk,
int inc)
{ {
MigrationState *s;
FILE *f; FILE *f;
s = migrate_new(mon, bandwidth_limit, detach, blk, inc);
f = popen(command, "w"); f = popen(command, "w");
if (f == NULL) { if (f == NULL) {
DPRINTF("Unable to popen exec target\n"); DPRINTF("Unable to popen exec target\n");
goto err_after_alloc; goto err_after_popen;
} }
s->fd = fileno(f); s->fd = fileno(f);
@ -94,13 +86,12 @@ MigrationState *exec_start_outgoing_migration(Monitor *mon,
s->write = file_write; s->write = file_write;
migrate_fd_connect(s); migrate_fd_connect(s);
return s; return 0;
err_after_open: err_after_open:
pclose(f); pclose(f);
err_after_alloc: err_after_popen:
g_free(s); return -1;
return NULL;
} }
static void exec_accept_incoming_migration(void *opaque) static void exec_accept_incoming_migration(void *opaque)

View File

@ -50,21 +50,12 @@ static int fd_close(MigrationState *s)
return 0; return 0;
} }
MigrationState *fd_start_outgoing_migration(Monitor *mon, int fd_start_outgoing_migration(MigrationState *s, const char *fdname)
const char *fdname,
int64_t bandwidth_limit,
int detach,
int blk,
int inc)
{ {
MigrationState *s; s->fd = monitor_get_fd(s->mon, fdname);
s = migrate_new(mon, bandwidth_limit, detach, blk, inc);
s->fd = monitor_get_fd(mon, fdname);
if (s->fd == -1) { if (s->fd == -1) {
DPRINTF("fd_migration: invalid file descriptor identifier\n"); DPRINTF("fd_migration: invalid file descriptor identifier\n");
goto err_after_alloc; goto err_after_get_fd;
} }
if (fcntl(s->fd, F_SETFL, O_NONBLOCK) == -1) { if (fcntl(s->fd, F_SETFL, O_NONBLOCK) == -1) {
@ -77,13 +68,12 @@ MigrationState *fd_start_outgoing_migration(Monitor *mon,
s->close = fd_close; s->close = fd_close;
migrate_fd_connect(s); migrate_fd_connect(s);
return s; return 0;
err_after_open: err_after_open:
close(s->fd); close(s->fd);
err_after_alloc: err_after_get_fd:
g_free(s); return -1;
return NULL;
} }
static void fd_accept_incoming_migration(void *opaque) static void fd_accept_incoming_migration(void *opaque)

View File

@ -75,30 +75,22 @@ static void tcp_wait_for_connect(void *opaque)
} }
} }
MigrationState *tcp_start_outgoing_migration(Monitor *mon, int tcp_start_outgoing_migration(MigrationState *s, const char *host_port)
const char *host_port,
int64_t bandwidth_limit,
int detach,
int blk,
int inc)
{ {
struct sockaddr_in addr; struct sockaddr_in addr;
MigrationState *s;
int ret; int ret;
if (parse_host_port(&addr, host_port) < 0) ret = parse_host_port(&addr, host_port);
return NULL; if (ret < 0) {
return ret;
s = migrate_new(mon, bandwidth_limit, detach, blk, inc); }
s->get_error = socket_errno; s->get_error = socket_errno;
s->write = socket_write; s->write = socket_write;
s->close = tcp_close; s->close = tcp_close;
s->fd = qemu_socket(PF_INET, SOCK_STREAM, 0); s->fd = qemu_socket(PF_INET, SOCK_STREAM, 0);
if (s->fd == -1) { if (s->fd == -1) {
g_free(s); return -1;
return NULL;
} }
socket_set_nonblock(s->fd); socket_set_nonblock(s->fd);
@ -118,7 +110,7 @@ MigrationState *tcp_start_outgoing_migration(Monitor *mon,
} else if (ret >= 0) } else if (ret >= 0)
migrate_fd_connect(s); migrate_fd_connect(s);
return s; return 0;
} }
static void tcp_accept_incoming_migration(void *opaque) static void tcp_accept_incoming_migration(void *opaque)

View File

@ -74,22 +74,13 @@ static void unix_wait_for_connect(void *opaque)
} }
} }
MigrationState *unix_start_outgoing_migration(Monitor *mon, int unix_start_outgoing_migration(MigrationState *s, const char *path)
const char *path,
int64_t bandwidth_limit,
int detach,
int blk,
int inc)
{ {
MigrationState *s;
struct sockaddr_un addr; struct sockaddr_un addr;
int ret; int ret;
addr.sun_family = AF_UNIX; addr.sun_family = AF_UNIX;
snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", path); snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", path);
s = migrate_new(mon, bandwidth_limit, detach, blk, inc);
s->get_error = unix_errno; s->get_error = unix_errno;
s->write = unix_write; s->write = unix_write;
s->close = unix_close; s->close = unix_close;
@ -97,7 +88,7 @@ MigrationState *unix_start_outgoing_migration(Monitor *mon,
s->fd = qemu_socket(PF_UNIX, SOCK_STREAM, 0); s->fd = qemu_socket(PF_UNIX, SOCK_STREAM, 0);
if (s->fd < 0) { if (s->fd < 0) {
DPRINTF("Unable to open socket"); DPRINTF("Unable to open socket");
goto err_after_alloc; goto err_after_socket;
} }
socket_set_nonblock(s->fd); socket_set_nonblock(s->fd);
@ -119,14 +110,13 @@ MigrationState *unix_start_outgoing_migration(Monitor *mon,
if (ret >= 0) if (ret >= 0)
migrate_fd_connect(s); migrate_fd_connect(s);
return s; return 0;
err_after_open: err_after_open:
close(s->fd); close(s->fd);
err_after_alloc: err_after_socket:
g_free(s); return -1;
return NULL;
} }
static void unix_accept_incoming_migration(void *opaque) static void unix_accept_incoming_migration(void *opaque)

View File

@ -77,6 +77,9 @@ void process_incoming_migration(QEMUFile *f)
} }
} }
static MigrationState *migrate_new(Monitor *mon, int64_t bandwidth_limit,
int detach, int blk, int inc);
int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data) int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data)
{ {
MigrationState *s = NULL; MigrationState *s = NULL;
@ -85,6 +88,7 @@ int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data)
int blk = qdict_get_try_bool(qdict, "blk", 0); int blk = qdict_get_try_bool(qdict, "blk", 0);
int inc = qdict_get_try_bool(qdict, "inc", 0); int inc = qdict_get_try_bool(qdict, "inc", 0);
const char *uri = qdict_get_str(qdict, "uri"); const char *uri = qdict_get_str(qdict, "uri");
int ret;
if (current_migration && if (current_migration &&
current_migration->get_status(current_migration) == MIG_STATE_ACTIVE) { current_migration->get_status(current_migration) == MIG_STATE_ACTIVE) {
@ -96,28 +100,27 @@ int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data)
return -1; return -1;
} }
s = migrate_new(mon, max_throttle, detach, blk, inc);
if (strstart(uri, "tcp:", &p)) { if (strstart(uri, "tcp:", &p)) {
s = tcp_start_outgoing_migration(mon, p, max_throttle, detach, ret = tcp_start_outgoing_migration(s, p);
blk, inc);
#if !defined(WIN32) #if !defined(WIN32)
} else if (strstart(uri, "exec:", &p)) { } else if (strstart(uri, "exec:", &p)) {
s = exec_start_outgoing_migration(mon, p, max_throttle, detach, ret = exec_start_outgoing_migration(s, p);
blk, inc);
} else if (strstart(uri, "unix:", &p)) { } else if (strstart(uri, "unix:", &p)) {
s = unix_start_outgoing_migration(mon, p, max_throttle, detach, ret = unix_start_outgoing_migration(s, p);
blk, inc);
} else if (strstart(uri, "fd:", &p)) { } else if (strstart(uri, "fd:", &p)) {
s = fd_start_outgoing_migration(mon, p, max_throttle, detach, ret = fd_start_outgoing_migration(s, p);
blk, inc);
#endif #endif
} else { } else {
monitor_printf(mon, "unknown migration protocol: %s\n", uri); monitor_printf(mon, "unknown migration protocol: %s\n", uri);
return -1; ret = -EINVAL;
goto free_migrate_state;
} }
if (s == NULL) { if (ret < 0) {
monitor_printf(mon, "migration failed\n"); monitor_printf(mon, "migration failed\n");
return -1; goto free_migrate_state;
} }
if (current_migration) { if (current_migration) {
@ -127,6 +130,9 @@ int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data)
current_migration = s; current_migration = s;
notifier_list_notify(&migration_state_notifiers, NULL); notifier_list_notify(&migration_state_notifiers, NULL);
return 0; return 0;
free_migrate_state:
g_free(s);
return -1;
} }
int do_migrate_cancel(Monitor *mon, const QDict *qdict, QObject **ret_data) int do_migrate_cancel(Monitor *mon, const QDict *qdict, QObject **ret_data)
@ -489,8 +495,8 @@ void migrate_fd_connect(MigrationState *s)
migrate_fd_put_ready(s); migrate_fd_put_ready(s);
} }
MigrationState *migrate_new(Monitor *mon, int64_t bandwidth_limit, static MigrationState *migrate_new(Monitor *mon, int64_t bandwidth_limit,
int detach, int blk, int inc) int detach, int blk, int inc)
{ {
MigrationState *s = g_malloc0(sizeof(*s)); MigrationState *s = g_malloc0(sizeof(*s));

View File

@ -64,47 +64,24 @@ void do_info_migrate(Monitor *mon, QObject **ret_data);
int exec_start_incoming_migration(const char *host_port); int exec_start_incoming_migration(const char *host_port);
MigrationState *exec_start_outgoing_migration(Monitor *mon, int exec_start_outgoing_migration(MigrationState *s, const char *host_port);
const char *host_port,
int64_t bandwidth_limit,
int detach,
int blk,
int inc);
int tcp_start_incoming_migration(const char *host_port); int tcp_start_incoming_migration(const char *host_port);
MigrationState *tcp_start_outgoing_migration(Monitor *mon, int tcp_start_outgoing_migration(MigrationState *s, const char *host_port);
const char *host_port,
int64_t bandwidth_limit,
int detach,
int blk,
int inc);
int unix_start_incoming_migration(const char *path); int unix_start_incoming_migration(const char *path);
MigrationState *unix_start_outgoing_migration(Monitor *mon, int unix_start_outgoing_migration(MigrationState *s, const char *path);
const char *path,
int64_t bandwidth_limit,
int detach,
int blk,
int inc);
int fd_start_incoming_migration(const char *path); int fd_start_incoming_migration(const char *path);
MigrationState *fd_start_outgoing_migration(Monitor *mon, int fd_start_outgoing_migration(MigrationState *s, const char *fdname);
const char *fdname,
int64_t bandwidth_limit,
int detach,
int blk,
int inc);
void migrate_fd_error(MigrationState *s); void migrate_fd_error(MigrationState *s);
void migrate_fd_connect(MigrationState *s); void migrate_fd_connect(MigrationState *s);
MigrationState *migrate_new(Monitor *mon, int64_t bandwidth_limit,
int detach, int blk, int inc);
void add_migration_state_change_notifier(Notifier *notify); void add_migration_state_change_notifier(Notifier *notify);
void remove_migration_state_change_notifier(Notifier *notify); void remove_migration_state_change_notifier(Notifier *notify);
int get_migration_state(void); int get_migration_state(void);