blob: 375d2e1b54c421646e613b56efe6511c5c789e7f [file] [log] [blame]
aliguori065e2812008-11-11 16:46:33 +00001/*
2 * QEMU live migration
3 *
4 * Copyright IBM, Corp. 2008
5 * Copyright Dell MessageOne 2008
Daniel P. Berrange527792f2016-04-27 11:05:06 +01006 * Copyright Red Hat, Inc. 2015-2016
aliguori065e2812008-11-11 16:46:33 +00007 *
8 * Authors:
9 * Anthony Liguori <aliguori@us.ibm.com>
10 * Charles Duffy <charles_duffy@messageone.com>
Daniel P. Berrange527792f2016-04-27 11:05:06 +010011 * Daniel P. Berrange <berrange@redhat.com>
aliguori065e2812008-11-11 16:46:33 +000012 *
13 * This work is licensed under the terms of the GNU GPL, version 2. See
14 * the COPYING file in the top-level directory.
15 *
Paolo Bonzini6b620ca2012-01-13 17:44:23 +010016 * Contributions after 2012-01-13 are licensed under the terms of the
17 * GNU GPL, version 2 or (at your option) any later version.
aliguori065e2812008-11-11 16:46:33 +000018 */
19
Peter Maydell1393a482016-01-26 18:16:54 +000020#include "qemu/osdep.h"
Juan Quinteladd4339c2017-04-17 17:07:04 +020021#include "channel.h"
Juan Quintelaf4dbe1b2017-04-05 15:54:10 +020022#include "exec.h"
Juan Quintela0efc9142018-05-23 11:14:11 +020023#include "migration.h"
Daniel P. Berrange527792f2016-04-27 11:05:06 +010024#include "io/channel-command.h"
25#include "trace.h"
aliguori065e2812008-11-11 16:46:33 +000026
aliguori065e2812008-11-11 16:46:33 +000027
Paolo Bonzinif37afb52012-10-02 10:02:46 +020028void exec_start_outgoing_migration(MigrationState *s, const char *command, Error **errp)
aliguori065e2812008-11-11 16:46:33 +000029{
Daniel P. Berrange527792f2016-04-27 11:05:06 +010030 QIOChannel *ioc;
31 const char *argv[] = { "/bin/sh", "-c", command, NULL };
32
33 trace_migration_exec_outgoing(command);
34 ioc = QIO_CHANNEL(qio_channel_command_new_spawn(argv,
Daniel P. Berrange062d81f2017-04-21 12:12:20 +010035 O_RDWR,
Daniel P. Berrange527792f2016-04-27 11:05:06 +010036 errp));
37 if (!ioc) {
Paolo Bonzinif37afb52012-10-02 10:02:46 +020038 return;
aliguori065e2812008-11-11 16:46:33 +000039 }
40
Daniel P. Berrange6f01f132016-09-30 11:57:14 +010041 qio_channel_set_name(ioc, "migration-exec-outgoing");
Dr. David Alan Gilbert688a3dc2017-12-15 17:16:55 +000042 migration_channel_connect(s, ioc, NULL, NULL);
Daniel P. Berrange527792f2016-04-27 11:05:06 +010043 object_unref(OBJECT(ioc));
aliguori065e2812008-11-11 16:46:33 +000044}
45
Daniel P. Berrange527792f2016-04-27 11:05:06 +010046static gboolean exec_accept_incoming_migration(QIOChannel *ioc,
47 GIOCondition condition,
48 gpointer opaque)
aliguori065e2812008-11-11 16:46:33 +000049{
Juan Quintela54314712017-04-17 17:15:02 +020050 migration_channel_process_incoming(ioc);
Daniel P. Berrange527792f2016-04-27 11:05:06 +010051 object_unref(OBJECT(ioc));
Juan Quintela2a543bf2017-07-24 12:51:59 +020052 return G_SOURCE_REMOVE;
Chris Lalancette8a43b1e2009-05-25 16:38:23 +020053}
54
Paolo Bonzini43eaae22012-10-02 18:21:18 +020055void exec_start_incoming_migration(const char *command, Error **errp)
Chris Lalancette8a43b1e2009-05-25 16:38:23 +020056{
Daniel P. Berrange527792f2016-04-27 11:05:06 +010057 QIOChannel *ioc;
58 const char *argv[] = { "/bin/sh", "-c", command, NULL };
Chris Lalancette8a43b1e2009-05-25 16:38:23 +020059
Daniel P. Berrange527792f2016-04-27 11:05:06 +010060 trace_migration_exec_incoming(command);
61 ioc = QIO_CHANNEL(qio_channel_command_new_spawn(argv,
Daniel P. Berrange062d81f2017-04-21 12:12:20 +010062 O_RDWR,
Daniel P. Berrange527792f2016-04-27 11:05:06 +010063 errp));
64 if (!ioc) {
Paolo Bonzini43eaae22012-10-02 18:21:18 +020065 return;
Chris Lalancette8a43b1e2009-05-25 16:38:23 +020066 }
67
Daniel P. Berrange6f01f132016-09-30 11:57:14 +010068 qio_channel_set_name(ioc, "migration-exec-incoming");
Peter Xue89f5ff2018-05-02 18:47:17 +080069 qio_channel_add_watch_full(ioc, G_IO_IN,
70 exec_accept_incoming_migration,
71 NULL, NULL,
72 g_main_context_get_thread_default());
aliguori065e2812008-11-11 16:46:33 +000073}