]> git.proxmox.com Git - mirror_qemu.git/blob - migration/fd.c
Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging
[mirror_qemu.git] / migration / fd.c
1 /*
2 * QEMU live migration via generic fd
3 *
4 * Copyright Red Hat, Inc. 2009-2016
5 *
6 * Authors:
7 * Chris Lalancette <clalance@redhat.com>
8 * Daniel P. Berrange <berrange@redhat.com>
9 *
10 * This work is licensed under the terms of the GNU GPL, version 2. See
11 * the COPYING file in the top-level directory.
12 *
13 * Contributions after 2012-01-13 are licensed under the terms of the
14 * GNU GPL, version 2 or (at your option) any later version.
15 */
16
17 #include "qemu/osdep.h"
18 #include "qapi/error.h"
19 #include "qemu-common.h"
20 #include "migration/migration.h"
21 #include "monitor/monitor.h"
22 #include "io/channel-util.h"
23 #include "trace.h"
24
25
26 void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp)
27 {
28 QIOChannel *ioc;
29 int fd = monitor_get_fd(cur_mon, fdname, errp);
30 if (fd == -1) {
31 return;
32 }
33
34 trace_migration_fd_outgoing(fd);
35 ioc = qio_channel_new_fd(fd, errp);
36 if (!ioc) {
37 close(fd);
38 return;
39 }
40
41 migration_channel_connect(s, ioc, NULL);
42 object_unref(OBJECT(ioc));
43 }
44
45 static gboolean fd_accept_incoming_migration(QIOChannel *ioc,
46 GIOCondition condition,
47 gpointer opaque)
48 {
49 migration_channel_process_incoming(migrate_get_current(), ioc);
50 object_unref(OBJECT(ioc));
51 return FALSE; /* unregister */
52 }
53
54 void fd_start_incoming_migration(const char *infd, Error **errp)
55 {
56 QIOChannel *ioc;
57 int fd;
58
59 fd = strtol(infd, NULL, 0);
60 trace_migration_fd_incoming(fd);
61
62 ioc = qio_channel_new_fd(fd, errp);
63 if (!ioc) {
64 close(fd);
65 return;
66 }
67
68 qio_channel_add_watch(ioc,
69 G_IO_IN,
70 fd_accept_incoming_migration,
71 NULL,
72 NULL);
73 }