blob: 9157721dfe596e3a4a83a92a80b9ca8fb2b92c7a [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"
Markus Armbrusterda34e652016-03-14 09:01:28 +010021#include "qapi/error.h"
aliguori065e2812008-11-11 16:46:33 +000022#include "qemu-common.h"
Paolo Bonzinicaf71f82012-12-17 18:19:50 +010023#include "migration/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,
35 O_WRONLY,
36 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");
Daniel P. Berrange22724f42016-06-01 11:17:14 +010042 migration_channel_connect(s, ioc, 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{
Daniel P. Berrange22724f42016-06-01 11:17:14 +010050 migration_channel_process_incoming(migrate_get_current(), ioc);
Daniel P. Berrange527792f2016-04-27 11:05:06 +010051 object_unref(OBJECT(ioc));
52 return FALSE; /* unregister */
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,
62 O_RDONLY,
63 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");
Daniel P. Berrange527792f2016-04-27 11:05:06 +010069 qio_channel_add_watch(ioc,
70 G_IO_IN,
71 exec_accept_incoming_migration,
72 NULL,
73 NULL);
aliguori065e2812008-11-11 16:46:33 +000074}