xref: /qemu/migration/fd.c (revision bd4480b0)
1329c9b10SDr. David Alan Gilbert /*
2329c9b10SDr. David Alan Gilbert  * QEMU live migration via generic fd
3329c9b10SDr. David Alan Gilbert  *
464802ee5SDaniel P. Berrange  * Copyright Red Hat, Inc. 2009-2016
5329c9b10SDr. David Alan Gilbert  *
6329c9b10SDr. David Alan Gilbert  * Authors:
7329c9b10SDr. David Alan Gilbert  *  Chris Lalancette <clalance@redhat.com>
864802ee5SDaniel P. Berrange  *  Daniel P. Berrange <berrange@redhat.com>
9329c9b10SDr. David Alan Gilbert  *
10329c9b10SDr. David Alan Gilbert  * This work is licensed under the terms of the GNU GPL, version 2.  See
11329c9b10SDr. David Alan Gilbert  * the COPYING file in the top-level directory.
12329c9b10SDr. David Alan Gilbert  *
13329c9b10SDr. David Alan Gilbert  * Contributions after 2012-01-13 are licensed under the terms of the
14329c9b10SDr. David Alan Gilbert  * GNU GPL, version 2 or (at your option) any later version.
15329c9b10SDr. David Alan Gilbert  */
16329c9b10SDr. David Alan Gilbert 
171393a485SPeter Maydell #include "qemu/osdep.h"
18dd4339c5SJuan Quintela #include "channel.h"
197fcac4a2SJuan Quintela #include "fd.h"
20*74228c59SFabiano Rosas #include "file.h"
210efc9142SJuan Quintela #include "migration.h"
22329c9b10SDr. David Alan Gilbert #include "monitor/monitor.h"
2364802ee5SDaniel P. Berrange #include "io/channel-util.h"
2464802ee5SDaniel P. Berrange #include "trace.h"
25329c9b10SDr. David Alan Gilbert 
26131fe9b8SCristian Klein 
fd_start_outgoing_migration(MigrationState * s,const char * fdname,Error ** errp)27329c9b10SDr. David Alan Gilbert void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp)
28329c9b10SDr. David Alan Gilbert {
2964802ee5SDaniel P. Berrange     QIOChannel *ioc;
30947e4744SKevin Wolf     int fd = monitor_get_fd(monitor_cur(), fdname, errp);
31329c9b10SDr. David Alan Gilbert     if (fd == -1) {
32329c9b10SDr. David Alan Gilbert         return;
33329c9b10SDr. David Alan Gilbert     }
34131fe9b8SCristian Klein 
3564802ee5SDaniel P. Berrange     trace_migration_fd_outgoing(fd);
3664802ee5SDaniel P. Berrange     ioc = qio_channel_new_fd(fd, errp);
3764802ee5SDaniel P. Berrange     if (!ioc) {
3864802ee5SDaniel P. Berrange         close(fd);
3964802ee5SDaniel P. Berrange         return;
40131fe9b8SCristian Klein     }
41329c9b10SDr. David Alan Gilbert 
427d5b0d68SPhilippe Mathieu-Daudé     qio_channel_set_name(ioc, "migration-fd-outgoing");
43688a3dcbSDr. David Alan Gilbert     migration_channel_connect(s, ioc, NULL, NULL);
4464802ee5SDaniel P. Berrange     object_unref(OBJECT(ioc));
45329c9b10SDr. David Alan Gilbert }
46329c9b10SDr. David Alan Gilbert 
fd_accept_incoming_migration(QIOChannel * ioc,GIOCondition condition,gpointer opaque)4764802ee5SDaniel P. Berrange static gboolean fd_accept_incoming_migration(QIOChannel *ioc,
4864802ee5SDaniel P. Berrange                                              GIOCondition condition,
4964802ee5SDaniel P. Berrange                                              gpointer opaque)
50329c9b10SDr. David Alan Gilbert {
5154314711SJuan Quintela     migration_channel_process_incoming(ioc);
5264802ee5SDaniel P. Berrange     object_unref(OBJECT(ioc));
532a543bfdSJuan Quintela     return G_SOURCE_REMOVE;
54329c9b10SDr. David Alan Gilbert }
55329c9b10SDr. David Alan Gilbert 
fd_start_incoming_migration(const char * fdname,Error ** errp)5661053d48SYury Kotov void fd_start_incoming_migration(const char *fdname, Error **errp)
57329c9b10SDr. David Alan Gilbert {
5864802ee5SDaniel P. Berrange     QIOChannel *ioc;
59947e4744SKevin Wolf     int fd = monitor_fd_param(monitor_cur(), fdname, errp);
6061053d48SYury Kotov     if (fd == -1) {
6161053d48SYury Kotov         return;
6261053d48SYury Kotov     }
63329c9b10SDr. David Alan Gilbert 
6464802ee5SDaniel P. Berrange     trace_migration_fd_incoming(fd);
6564802ee5SDaniel P. Berrange 
6664802ee5SDaniel P. Berrange     ioc = qio_channel_new_fd(fd, errp);
6764802ee5SDaniel P. Berrange     if (!ioc) {
6864802ee5SDaniel P. Berrange         close(fd);
69329c9b10SDr. David Alan Gilbert         return;
70329c9b10SDr. David Alan Gilbert     }
71329c9b10SDr. David Alan Gilbert 
727d5b0d68SPhilippe Mathieu-Daudé     qio_channel_set_name(ioc, "migration-fd-incoming");
73e89f5ff2SPeter Xu     qio_channel_add_watch_full(ioc, G_IO_IN,
7464802ee5SDaniel P. Berrange                                fd_accept_incoming_migration,
75e89f5ff2SPeter Xu                                NULL, NULL,
76e89f5ff2SPeter Xu                                g_main_context_get_thread_default());
77decdc767SFabiano Rosas }
78