2 * QEMU live migration via Unix Domain Sockets
4 * Copyright Red Hat, Inc. 2009-2016
7 * Chris Lalancette <clalance@redhat.com>
8 * Daniel P. Berrange <berrange@redhat.com>
10 * This work is licensed under the terms of the GNU GPL, version 2. See
11 * the COPYING file in the top-level directory.
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.
17 #include "qemu/osdep.h"
19 #include "qemu-common.h"
20 #include "qemu/error-report.h"
21 #include "qapi/error.h"
22 #include "migration/migration.h"
23 #include "migration/qemu-file.h"
24 #include "io/channel-socket.h"
28 static SocketAddress
*unix_build_address(const char *path
)
32 saddr
= g_new0(SocketAddress
, 1);
33 saddr
->type
= SOCKET_ADDRESS_KIND_UNIX
;
34 saddr
->u
.q_unix
.data
= g_new0(UnixSocketAddress
, 1);
35 saddr
->u
.q_unix
.data
->path
= g_strdup(path
);
41 static void unix_outgoing_migration(Object
*src
,
45 MigrationState
*s
= opaque
;
46 QIOChannel
*sioc
= QIO_CHANNEL(src
);
49 trace_migration_unix_outgoing_error(error_get_pretty(err
));
50 s
->to_dst_file
= NULL
;
51 migrate_fd_error(s
, err
);
53 trace_migration_unix_outgoing_connected();
54 migration_set_outgoing_channel(s
, sioc
);
60 void unix_start_outgoing_migration(MigrationState
*s
, const char *path
, Error
**errp
)
62 SocketAddress
*saddr
= unix_build_address(path
);
63 QIOChannelSocket
*sioc
;
64 sioc
= qio_channel_socket_new();
65 qio_channel_socket_connect_async(sioc
,
67 unix_outgoing_migration
,
70 qapi_free_SocketAddress(saddr
);
74 static gboolean
unix_accept_incoming_migration(QIOChannel
*ioc
,
75 GIOCondition condition
,
78 QIOChannelSocket
*sioc
;
81 sioc
= qio_channel_socket_accept(QIO_CHANNEL_SOCKET(ioc
),
84 error_report("could not accept migration connection (%s)",
85 error_get_pretty(err
));
89 trace_migration_unix_incoming_accepted();
91 migration_set_incoming_channel(migrate_get_current(),
93 object_unref(OBJECT(sioc
));
96 /* Close listening socket as its no longer needed */
97 qio_channel_close(ioc
, NULL
);
98 return FALSE
; /* unregister */
102 void unix_start_incoming_migration(const char *path
, Error
**errp
)
104 SocketAddress
*saddr
= unix_build_address(path
);
105 QIOChannelSocket
*listen_ioc
;
107 listen_ioc
= qio_channel_socket_new();
108 if (qio_channel_socket_listen_sync(listen_ioc
, saddr
, errp
) < 0) {
109 object_unref(OBJECT(listen_ioc
));
110 qapi_free_SocketAddress(saddr
);
114 qio_channel_add_watch(QIO_CHANNEL(listen_ioc
),
116 unix_accept_incoming_migration
,
118 (GDestroyNotify
)object_unref
);
120 qapi_free_SocketAddress(saddr
);