1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#include "qemu/osdep.h"
18#include "channel.h"
19#include "fd.h"
20#include "monitor/monitor.h"
21#include "io/channel-util.h"
22#include "trace.h"
23
24
25void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp)
26{
27 QIOChannel *ioc;
28 int fd = monitor_get_fd(cur_mon, fdname, errp);
29 if (fd == -1) {
30 return;
31 }
32
33 trace_migration_fd_outgoing(fd);
34 ioc = qio_channel_new_fd(fd, errp);
35 if (!ioc) {
36 close(fd);
37 return;
38 }
39
40 qio_channel_set_name(QIO_CHANNEL(ioc), "migration-fd-outgoing");
41 migration_channel_connect(s, ioc, NULL, NULL);
42 object_unref(OBJECT(ioc));
43}
44
45static gboolean fd_accept_incoming_migration(QIOChannel *ioc,
46 GIOCondition condition,
47 gpointer opaque)
48{
49 migration_channel_process_incoming(ioc);
50 object_unref(OBJECT(ioc));
51 return G_SOURCE_REMOVE;
52}
53
54void 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_set_name(QIO_CHANNEL(ioc), "migration-fd-incoming");
69 qio_channel_add_watch(ioc,
70 G_IO_IN,
71 fd_accept_incoming_migration,
72 NULL,
73 NULL);
74}
75