fd.c 1.9 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"
19
#include "channel.h"
20
#include "fd.h"
21
#include "monitor/monitor.h"
22 23
#include "io/channel-util.h"
#include "trace.h"
P
Paolo Bonzini 已提交
24

25

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

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

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

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

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

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

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

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