From patchwork Tue Sep 20 14:19:35 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 115558 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 530D3B6F86 for ; Wed, 21 Sep 2011 00:37:42 +1000 (EST) Received: from localhost ([::1]:59235 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R61Bq-0005pH-BI for incoming@patchwork.ozlabs.org; Tue, 20 Sep 2011 10:20:50 -0400 Received: from eggs.gnu.org ([140.186.70.92]:39215) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R61BJ-0004fE-BI for qemu-devel@nongnu.org; Tue, 20 Sep 2011 10:20:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R61BB-0008A0-8l for qemu-devel@nongnu.org; Tue, 20 Sep 2011 10:20:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34429) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R61BA-00089V-R4 for qemu-devel@nongnu.org; Tue, 20 Sep 2011 10:20:09 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p8KEK8cM031333 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 20 Sep 2011 10:20:08 -0400 Received: from trasno.mitica (ovpn-113-56.phx2.redhat.com [10.3.113.56]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p8KEJv9a015328; Tue, 20 Sep 2011 10:20:07 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Tue, 20 Sep 2011 16:19:35 +0200 Message-Id: <95517f0324d87441ecbd67cc07fe37e7d717c97d.1316526970.git.quintela@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 07/23] migration: move migrate_create_state to do_migrate X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Once there, remove all parameters that don't need to be passed to *start_outgoing_migration() functions Signed-off-by: Juan Quintela --- migration-exec.c | 19 +++++-------------- migration-fd.c | 22 ++++++---------------- migration-tcp.c | 22 +++++++--------------- migration-unix.c | 19 +++++-------------- migration.c | 34 +++++++++++++++++++++------------- migration.h | 31 ++++--------------------------- 6 files changed, 48 insertions(+), 99 deletions(-) diff --git a/migration-exec.c b/migration-exec.c index 6bddb7b..41d90a4 100644 --- a/migration-exec.c +++ b/migration-exec.c @@ -61,22 +61,14 @@ static int exec_close(MigrationState *s, bool flush) return ret; } -MigrationState *exec_start_outgoing_migration(Monitor *mon, - const char *command, - int64_t bandwidth_limit, - int detach, - int blk, - int inc) +int exec_start_outgoing_migration(MigrationState *s, const char *command) { - MigrationState *s; FILE *f; - s = migrate_create_state(mon, bandwidth_limit, detach, blk, inc); - f = popen(command, "w"); if (f == NULL) { DPRINTF("Unable to popen exec target\n"); - goto err_after_alloc; + goto err_after_popen; } s->fd = fileno(f); @@ -94,13 +86,12 @@ MigrationState *exec_start_outgoing_migration(Monitor *mon, s->write = file_write; migrate_fd_connect(s); - return s; + return 0; err_after_open: pclose(f); -err_after_alloc: - g_free(s); - return NULL; +err_after_popen: + return -1; } static void exec_accept_incoming_migration(void *opaque) diff --git a/migration-fd.c b/migration-fd.c index 040a372..4f9e785 100644 --- a/migration-fd.c +++ b/migration-fd.c @@ -50,21 +50,12 @@ static int fd_close(MigrationState *s, bool flush) return 0; } -MigrationState *fd_start_outgoing_migration(Monitor *mon, - const char *fdname, - int64_t bandwidth_limit, - int detach, - int blk, - int inc) +int fd_start_outgoing_migration(MigrationState *s, const char *fdname) { - MigrationState *s; - - s = migrate_create_state(mon, bandwidth_limit, detach, blk, inc); - - s->fd = monitor_get_fd(mon, fdname); + s->fd = monitor_get_fd(s->mon, fdname); if (s->fd == -1) { 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) { @@ -77,13 +68,12 @@ MigrationState *fd_start_outgoing_migration(Monitor *mon, s->close = fd_close; migrate_fd_connect(s); - return s; + return 0; err_after_open: close(s->fd); -err_after_alloc: - g_free(s); - return NULL; +err_after_get_fd: + return -1; } static void fd_accept_incoming_migration(void *opaque) diff --git a/migration-tcp.c b/migration-tcp.c index f93b037..1ca48fa 100644 --- a/migration-tcp.c +++ b/migration-tcp.c @@ -75,30 +75,22 @@ static void tcp_wait_for_connect(void *opaque) } } -MigrationState *tcp_start_outgoing_migration(Monitor *mon, - const char *host_port, - int64_t bandwidth_limit, - int detach, - int blk, - int inc) +int tcp_start_outgoing_migration(MigrationState *s, const char *host_port) { struct sockaddr_in addr; - MigrationState *s; int ret; - if (parse_host_port(&addr, host_port) < 0) - return NULL; - - s = migrate_create_state(mon, bandwidth_limit, detach, blk, inc); - + ret = parse_host_port(&addr, host_port); + if (ret < 0) { + return ret; + } s->get_error = socket_errno; s->write = socket_write; s->close = tcp_close; s->fd = qemu_socket(PF_INET, SOCK_STREAM, 0); if (s->fd == -1) { - g_free(s); - return NULL; + return -1; } socket_set_nonblock(s->fd); @@ -118,7 +110,7 @@ MigrationState *tcp_start_outgoing_migration(Monitor *mon, } else if (ret >= 0) migrate_fd_connect(s); - return s; + return 0; } static void tcp_accept_incoming_migration(void *opaque) diff --git a/migration-unix.c b/migration-unix.c index 63be155..0b82c91 100644 --- a/migration-unix.c +++ b/migration-unix.c @@ -74,22 +74,14 @@ static void unix_wait_for_connect(void *opaque) } } -MigrationState *unix_start_outgoing_migration(Monitor *mon, - const char *path, - int64_t bandwidth_limit, - int detach, - int blk, - int inc) +int unix_start_outgoing_migration(MigrationState *s, const char *path) { - MigrationState *s; struct sockaddr_un addr; int ret; addr.sun_family = AF_UNIX; snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", path); - s = migrate_create_state(mon, bandwidth_limit, detach, blk, inc); - s->get_error = unix_errno; s->write = unix_write; s->close = unix_close; @@ -97,7 +89,7 @@ MigrationState *unix_start_outgoing_migration(Monitor *mon, s->fd = qemu_socket(PF_UNIX, SOCK_STREAM, 0); if (s->fd < 0) { DPRINTF("Unable to open socket"); - goto err_after_alloc; + goto err_after_socket; } socket_set_nonblock(s->fd); @@ -119,14 +111,13 @@ MigrationState *unix_start_outgoing_migration(Monitor *mon, if (ret >= 0) migrate_fd_connect(s); - return s; + return 0; err_after_open: close(s->fd); -err_after_alloc: - g_free(s); - return NULL; +err_after_socket: + return -1; } static void unix_accept_incoming_migration(void *opaque) diff --git a/migration.c b/migration.c index 96f00b7..1d7a488 100644 --- a/migration.c +++ b/migration.c @@ -76,6 +76,10 @@ void process_incoming_migration(QEMUFile *f) vm_start(); } +static MigrationState *migrate_create_state(Monitor *mon, + int64_t bandwidth_limit, + int detach, int blk, int inc); + int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data) { MigrationState *s = NULL; @@ -84,6 +88,7 @@ int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data) int blk = qdict_get_try_bool(qdict, "blk", 0); int inc = qdict_get_try_bool(qdict, "inc", 0); const char *uri = qdict_get_str(qdict, "uri"); + int ret; if (current_migration && current_migration->get_status(current_migration) == MIG_STATE_ACTIVE) { @@ -95,28 +100,27 @@ int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data) return -1; } + s = migrate_create_state(mon, max_throttle, detach, blk, inc); + if (strstart(uri, "tcp:", &p)) { - s = tcp_start_outgoing_migration(mon, p, max_throttle, detach, - blk, inc); + ret = tcp_start_outgoing_migration(s, p); #if !defined(WIN32) } else if (strstart(uri, "exec:", &p)) { - s = exec_start_outgoing_migration(mon, p, max_throttle, detach, - blk, inc); + ret = exec_start_outgoing_migration(s, p); } else if (strstart(uri, "unix:", &p)) { - s = unix_start_outgoing_migration(mon, p, max_throttle, detach, - blk, inc); + ret = unix_start_outgoing_migration(s, p); } else if (strstart(uri, "fd:", &p)) { - s = fd_start_outgoing_migration(mon, p, max_throttle, detach, - blk, inc); + ret = fd_start_outgoing_migration(s, p); #endif } else { 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"); - return -1; + goto free_migrate_state; } if (current_migration) { @@ -126,6 +130,9 @@ int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data) current_migration = s; notifier_list_notify(&migration_state_notifiers, NULL); return 0; +free_migrate_state: + g_free(s); + return -1; } int do_migrate_cancel(Monitor *mon, const QDict *qdict, QObject **ret_data) @@ -479,8 +486,9 @@ void migrate_fd_connect(MigrationState *s) migrate_fd_put_ready(s); } -MigrationState *migrate_create_state(Monitor *mon, int64_t bandwidth_limit, - int detach, int blk, int inc) +static MigrationState *migrate_create_state(Monitor *mon, + int64_t bandwidth_limit, + int detach, int blk, int inc) { MigrationState *s = g_malloc0(sizeof(*s)); diff --git a/migration.h b/migration.h index f5de3da..a08b5fa 100644 --- a/migration.h +++ b/migration.h @@ -64,47 +64,24 @@ void do_info_migrate(Monitor *mon, QObject **ret_data); int exec_start_incoming_migration(const char *host_port); -MigrationState *exec_start_outgoing_migration(Monitor *mon, - const char *host_port, - int64_t bandwidth_limit, - int detach, - int blk, - int inc); +int exec_start_outgoing_migration(MigrationState *s, const char *host_port); int tcp_start_incoming_migration(const char *host_port); -MigrationState *tcp_start_outgoing_migration(Monitor *mon, - const char *host_port, - int64_t bandwidth_limit, - int detach, - int blk, - int inc); +int tcp_start_outgoing_migration(MigrationState *s, const char *host_port); int unix_start_incoming_migration(const char *path); -MigrationState *unix_start_outgoing_migration(Monitor *mon, - const char *path, - int64_t bandwidth_limit, - int detach, - int blk, - int inc); +int unix_start_outgoing_migration(MigrationState *s, const char *path); int fd_start_incoming_migration(const char *path); -MigrationState *fd_start_outgoing_migration(Monitor *mon, - const char *fdname, - int64_t bandwidth_limit, - int detach, - int blk, - int inc); +int fd_start_outgoing_migration(MigrationState *s, const char *fdname); void migrate_fd_error(MigrationState *s); void migrate_fd_connect(MigrationState *s); -MigrationState *migrate_create_state(Monitor *mon, int64_t bandwidth_limit, - int detach, int blk, int inc); - void add_migration_state_change_notifier(Notifier *notify); void remove_migration_state_change_notifier(Notifier *notify); int get_migration_state(void);