blob: 6f2f50475f445407e6e1f6d55a00131a97f3066c [file] [log] [blame]
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +02001/*
2 * QEMU live migration via generic fd
3 *
Daniel P. Berrange64802ee2016-04-27 11:05:05 +01004 * Copyright Red Hat, Inc. 2009-2016
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +02005 *
6 * Authors:
7 * Chris Lalancette <clalance@redhat.com>
Daniel P. Berrange64802ee2016-04-27 11:05:05 +01008 * Daniel P. Berrange <berrange@redhat.com>
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +02009 *
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 *
Paolo Bonzini6b620ca2012-01-13 17:44:23 +010013 * Contributions after 2012-01-13 are licensed under the terms of the
14 * GNU GPL, version 2 or (at your option) any later version.
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +020015 */
16
Peter Maydell1393a482016-01-26 18:16:54 +000017#include "qemu/osdep.h"
Juan Quinteladd4339c2017-04-17 17:07:04 +020018#include "channel.h"
Juan Quintela7fcac4a2017-04-05 15:58:29 +020019#include "fd.h"
Juan Quintela0efc9142018-05-23 11:14:11 +020020#include "migration.h"
Paolo Bonzini83c90892012-12-17 18:19:49 +010021#include "monitor/monitor.h"
Daniel P. Berrange64802ee2016-04-27 11:05:05 +010022#include "io/channel-util.h"
23#include "trace.h"
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +020024
Cristian Klein131fe9b2015-01-08 11:11:31 +000025
Paolo Bonzinif37afb52012-10-02 10:02:46 +020026void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp)
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +020027{
Daniel P. Berrange64802ee2016-04-27 11:05:05 +010028 QIOChannel *ioc;
Kevin Wolf947e4742020-10-05 17:58:44 +020029 int fd = monitor_get_fd(monitor_cur(), fdname, errp);
Paolo Bonzinif8bbc122013-02-22 17:36:41 +010030 if (fd == -1) {
Paolo Bonzinif37afb52012-10-02 10:02:46 +020031 return;
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +020032 }
Cristian Klein131fe9b2015-01-08 11:11:31 +000033
Daniel P. Berrange64802ee2016-04-27 11:05:05 +010034 trace_migration_fd_outgoing(fd);
35 ioc = qio_channel_new_fd(fd, errp);
36 if (!ioc) {
37 close(fd);
38 return;
Cristian Klein131fe9b2015-01-08 11:11:31 +000039 }
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +020040
Daniel P. Berrange6f01f132016-09-30 11:57:14 +010041 qio_channel_set_name(QIO_CHANNEL(ioc), "migration-fd-outgoing");
Dr. David Alan Gilbert688a3dc2017-12-15 17:16:55 +000042 migration_channel_connect(s, ioc, NULL, NULL);
Daniel P. Berrange64802ee2016-04-27 11:05:05 +010043 object_unref(OBJECT(ioc));
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +020044}
45
Daniel P. Berrange64802ee2016-04-27 11:05:05 +010046static gboolean fd_accept_incoming_migration(QIOChannel *ioc,
47 GIOCondition condition,
48 gpointer opaque)
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +020049{
Juan Quintela54314712017-04-17 17:15:02 +020050 migration_channel_process_incoming(ioc);
Daniel P. Berrange64802ee2016-04-27 11:05:05 +010051 object_unref(OBJECT(ioc));
Juan Quintela2a543bf2017-07-24 12:51:59 +020052 return G_SOURCE_REMOVE;
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +020053}
54
Yury Kotov61053d42019-05-28 12:16:32 +030055void fd_start_incoming_migration(const char *fdname, Error **errp)
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +020056{
Daniel P. Berrange64802ee2016-04-27 11:05:05 +010057 QIOChannel *ioc;
Kevin Wolf947e4742020-10-05 17:58:44 +020058 int fd = monitor_fd_param(monitor_cur(), fdname, errp);
Yury Kotov61053d42019-05-28 12:16:32 +030059 if (fd == -1) {
60 return;
61 }
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +020062
Daniel P. Berrange64802ee2016-04-27 11:05:05 +010063 trace_migration_fd_incoming(fd);
64
65 ioc = qio_channel_new_fd(fd, errp);
66 if (!ioc) {
67 close(fd);
Paolo Bonzini43eaae22012-10-02 18:21:18 +020068 return;
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +020069 }
70
Daniel P. Berrange6f01f132016-09-30 11:57:14 +010071 qio_channel_set_name(QIO_CHANNEL(ioc), "migration-fd-incoming");
Peter Xue89f5ff2018-05-02 18:47:17 +080072 qio_channel_add_watch_full(ioc, G_IO_IN,
73 fd_accept_incoming_migration,
74 NULL, NULL,
75 g_main_context_get_thread_default());
Paolo Bonzini5ac1fad2009-08-18 15:56:25 +020076}