fd.c 2.0 KB
Newer Older
P
Paolo Bonzini 已提交
1 2 3
/*
 * QEMU live migration via generic fd
 *
4
 * Copyright Red Hat, Inc. 2009-2016
P
Paolo Bonzini 已提交
5 6 7
 *
 * Authors:
 *  Chris Lalancette <clalance@redhat.com>
8
 *  Daniel P. Berrange <berrange@redhat.com>
P
Paolo Bonzini 已提交
9 10 11 12
 *
 * This work is licensed under the terms of the GNU GPL, version 2.  See
 * the COPYING file in the top-level directory.
 *
13 14
 * Contributions after 2012-01-13 are licensed under the terms of the
 * GNU GPL, version 2 or (at your option) any later version.
P
Paolo Bonzini 已提交
15 16
 */

P
Peter Maydell 已提交
17
#include "qemu/osdep.h"
18
#include "qapi/error.h"
P
Paolo Bonzini 已提交
19
#include "qemu-common.h"
20
#include "channel.h"
21
#include "migration/migration.h"
22
#include "monitor/monitor.h"
23 24
#include "io/channel-util.h"
#include "trace.h"
P
Paolo Bonzini 已提交
25

26

27
void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp)
P
Paolo Bonzini 已提交
28
{
29
    QIOChannel *ioc;
30 31
    int fd = monitor_get_fd(cur_mon, fdname, errp);
    if (fd == -1) {
32
        return;
P
Paolo Bonzini 已提交
33
    }
34

35 36 37 38 39
    trace_migration_fd_outgoing(fd);
    ioc = qio_channel_new_fd(fd, errp);
    if (!ioc) {
        close(fd);
        return;
40
    }
P
Paolo Bonzini 已提交
41

42
    qio_channel_set_name(QIO_CHANNEL(ioc), "migration-fd-outgoing");
43
    migration_channel_connect(s, ioc, NULL);
44
    object_unref(OBJECT(ioc));
P
Paolo Bonzini 已提交
45 46
}

47 48 49
static gboolean fd_accept_incoming_migration(QIOChannel *ioc,
                                             GIOCondition condition,
                                             gpointer opaque)
P
Paolo Bonzini 已提交
50
{
51
    migration_channel_process_incoming(migrate_get_current(), ioc);
52 53
    object_unref(OBJECT(ioc));
    return FALSE; /* unregister */
P
Paolo Bonzini 已提交
54 55
}

56
void fd_start_incoming_migration(const char *infd, Error **errp)
P
Paolo Bonzini 已提交
57
{
58
    QIOChannel *ioc;
P
Paolo Bonzini 已提交
59 60 61
    int fd;

    fd = strtol(infd, NULL, 0);
62 63 64 65 66
    trace_migration_fd_incoming(fd);

    ioc = qio_channel_new_fd(fd, errp);
    if (!ioc) {
        close(fd);
67
        return;
P
Paolo Bonzini 已提交
68 69
    }

70
    qio_channel_set_name(QIO_CHANNEL(ioc), "migration-fd-incoming");
71 72 73 74 75
    qio_channel_add_watch(ioc,
                          G_IO_IN,
                          fd_accept_incoming_migration,
                          NULL,
                          NULL);
P
Paolo Bonzini 已提交
76
}