X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=migration%2Ffd.c;h=0eb677dcae2606eb93e3ae77e249680688fad5d6;hb=abf635ddfe3242df907f58967f3c1e6763bbca2d;hp=3d788bb297139656e5c5eb2dcbeebcca458e8b62;hpb=7cd592bc6504b64f55570325674240a72a1aa037;p=qmiga%2Fqemu.git diff --git a/migration/fd.c b/migration/fd.c index 3d788bb297..0eb677dcae 100644 --- a/migration/fd.c +++ b/migration/fd.c @@ -1,10 +1,11 @@ /* * QEMU live migration via generic fd * - * Copyright Red Hat, Inc. 2009 + * Copyright Red Hat, Inc. 2009-2016 * * Authors: * Chris Lalancette + * Daniel P. Berrange * * This work is licensed under the terms of the GNU GPL, version 2. See * the COPYING file in the top-level directory. @@ -14,77 +15,62 @@ */ #include "qemu/osdep.h" -#include "qapi/error.h" -#include "qemu-common.h" -#include "qemu/main-loop.h" -#include "qemu/sockets.h" -#include "migration/migration.h" +#include "channel.h" +#include "fd.h" +#include "migration.h" #include "monitor/monitor.h" -#include "migration/qemu-file.h" -#include "block/block.h" +#include "io/channel-util.h" +#include "trace.h" -//#define DEBUG_MIGRATION_FD - -#ifdef DEBUG_MIGRATION_FD -#define DPRINTF(fmt, ...) \ - do { printf("migration-fd: " fmt, ## __VA_ARGS__); } while (0) -#else -#define DPRINTF(fmt, ...) \ - do { } while (0) -#endif - -static bool fd_is_socket(int fd) -{ - struct stat stat; - int ret = fstat(fd, &stat); - if (ret == -1) { - /* When in doubt say no */ - return false; - } - return S_ISSOCK(stat.st_mode); -} void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp) { - int fd = monitor_get_fd(cur_mon, fdname, errp); + QIOChannel *ioc; + int fd = monitor_get_fd(monitor_cur(), fdname, errp); if (fd == -1) { return; } - if (fd_is_socket(fd)) { - s->to_dst_file = qemu_fopen_socket(fd, "wb"); - } else { - s->to_dst_file = qemu_fdopen(fd, "wb"); + trace_migration_fd_outgoing(fd); + ioc = qio_channel_new_fd(fd, errp); + if (!ioc) { + close(fd); + return; } - migrate_fd_connect(s); + qio_channel_set_name(ioc, "migration-fd-outgoing"); + migration_channel_connect(s, ioc, NULL, NULL); + object_unref(OBJECT(ioc)); } -static void fd_accept_incoming_migration(void *opaque) +static gboolean fd_accept_incoming_migration(QIOChannel *ioc, + GIOCondition condition, + gpointer opaque) { - QEMUFile *f = opaque; - - qemu_set_fd_handler(qemu_get_fd(f), NULL, NULL, NULL); - process_incoming_migration(f); + migration_channel_process_incoming(ioc); + object_unref(OBJECT(ioc)); + return G_SOURCE_REMOVE; } -void fd_start_incoming_migration(const char *infd, Error **errp) +void fd_start_incoming_migration(const char *fdname, Error **errp) { - int fd; - QEMUFile *f; + QIOChannel *ioc; + int fd = monitor_fd_param(monitor_cur(), fdname, errp); + if (fd == -1) { + return; + } - DPRINTF("Attempting to start an incoming migration via fd\n"); + trace_migration_fd_incoming(fd); - fd = strtol(infd, NULL, 0); - if (fd_is_socket(fd)) { - f = qemu_fopen_socket(fd, "rb"); - } else { - f = qemu_fdopen(fd, "rb"); - } - if(f == NULL) { - error_setg_errno(errp, errno, "failed to open the source descriptor"); + ioc = qio_channel_new_fd(fd, errp); + if (!ioc) { + close(fd); return; } - qemu_set_fd_handler(fd, fd_accept_incoming_migration, NULL, f); + qio_channel_set_name(ioc, "migration-fd-incoming"); + qio_channel_add_watch_full(ioc, G_IO_IN, + fd_accept_incoming_migration, + NULL, NULL, + g_main_context_get_thread_default()); }