aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 1 | /* |
| 2 | * QEMU live migration |
| 3 | * |
| 4 | * Copyright IBM, Corp. 2008 |
| 5 | * Copyright Dell MessageOne 2008 |
Daniel P. Berrange | 527792f | 2016-04-27 11:05:06 +0100 | [diff] [blame] | 6 | * Copyright Red Hat, Inc. 2015-2016 |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 7 | * |
| 8 | * Authors: |
| 9 | * Anthony Liguori <aliguori@us.ibm.com> |
| 10 | * Charles Duffy <charles_duffy@messageone.com> |
Daniel P. Berrange | 527792f | 2016-04-27 11:05:06 +0100 | [diff] [blame] | 11 | * Daniel P. Berrange <berrange@redhat.com> |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 12 | * |
| 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 Bonzini | 6b620ca | 2012-01-13 17:44:23 +0100 | [diff] [blame] | 16 | * Contributions after 2012-01-13 are licensed under the terms of the |
| 17 | * GNU GPL, version 2 or (at your option) any later version. |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
Peter Maydell | 1393a48 | 2016-01-26 18:16:54 +0000 | [diff] [blame] | 20 | #include "qemu/osdep.h" |
Juan Quintela | dd4339c | 2017-04-17 17:07:04 +0200 | [diff] [blame] | 21 | #include "channel.h" |
Juan Quintela | f4dbe1b | 2017-04-05 15:54:10 +0200 | [diff] [blame] | 22 | #include "exec.h" |
Juan Quintela | 0efc914 | 2018-05-23 11:14:11 +0200 | [diff] [blame] | 23 | #include "migration.h" |
Daniel P. Berrange | 527792f | 2016-04-27 11:05:06 +0100 | [diff] [blame] | 24 | #include "io/channel-command.h" |
| 25 | #include "trace.h" |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 26 | |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 27 | |
Paolo Bonzini | f37afb5 | 2012-10-02 10:02:46 +0200 | [diff] [blame] | 28 | void exec_start_outgoing_migration(MigrationState *s, const char *command, Error **errp) |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 29 | { |
Daniel P. Berrange | 527792f | 2016-04-27 11:05:06 +0100 | [diff] [blame] | 30 | 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. Berrange | 062d81f | 2017-04-21 12:12:20 +0100 | [diff] [blame] | 35 | O_RDWR, |
Daniel P. Berrange | 527792f | 2016-04-27 11:05:06 +0100 | [diff] [blame] | 36 | errp)); |
| 37 | if (!ioc) { |
Paolo Bonzini | f37afb5 | 2012-10-02 10:02:46 +0200 | [diff] [blame] | 38 | return; |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 39 | } |
| 40 | |
Daniel P. Berrange | 6f01f13 | 2016-09-30 11:57:14 +0100 | [diff] [blame] | 41 | qio_channel_set_name(ioc, "migration-exec-outgoing"); |
Dr. David Alan Gilbert | 688a3dc | 2017-12-15 17:16:55 +0000 | [diff] [blame] | 42 | migration_channel_connect(s, ioc, NULL, NULL); |
Daniel P. Berrange | 527792f | 2016-04-27 11:05:06 +0100 | [diff] [blame] | 43 | object_unref(OBJECT(ioc)); |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Daniel P. Berrange | 527792f | 2016-04-27 11:05:06 +0100 | [diff] [blame] | 46 | static gboolean exec_accept_incoming_migration(QIOChannel *ioc, |
| 47 | GIOCondition condition, |
| 48 | gpointer opaque) |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 49 | { |
Juan Quintela | 5431471 | 2017-04-17 17:15:02 +0200 | [diff] [blame] | 50 | migration_channel_process_incoming(ioc); |
Daniel P. Berrange | 527792f | 2016-04-27 11:05:06 +0100 | [diff] [blame] | 51 | object_unref(OBJECT(ioc)); |
Juan Quintela | 2a543bf | 2017-07-24 12:51:59 +0200 | [diff] [blame] | 52 | return G_SOURCE_REMOVE; |
Chris Lalancette | 8a43b1e | 2009-05-25 16:38:23 +0200 | [diff] [blame] | 53 | } |
| 54 | |
Paolo Bonzini | 43eaae2 | 2012-10-02 18:21:18 +0200 | [diff] [blame] | 55 | void exec_start_incoming_migration(const char *command, Error **errp) |
Chris Lalancette | 8a43b1e | 2009-05-25 16:38:23 +0200 | [diff] [blame] | 56 | { |
Daniel P. Berrange | 527792f | 2016-04-27 11:05:06 +0100 | [diff] [blame] | 57 | QIOChannel *ioc; |
| 58 | const char *argv[] = { "/bin/sh", "-c", command, NULL }; |
Chris Lalancette | 8a43b1e | 2009-05-25 16:38:23 +0200 | [diff] [blame] | 59 | |
Daniel P. Berrange | 527792f | 2016-04-27 11:05:06 +0100 | [diff] [blame] | 60 | trace_migration_exec_incoming(command); |
| 61 | ioc = QIO_CHANNEL(qio_channel_command_new_spawn(argv, |
Daniel P. Berrange | 062d81f | 2017-04-21 12:12:20 +0100 | [diff] [blame] | 62 | O_RDWR, |
Daniel P. Berrange | 527792f | 2016-04-27 11:05:06 +0100 | [diff] [blame] | 63 | errp)); |
| 64 | if (!ioc) { |
Paolo Bonzini | 43eaae2 | 2012-10-02 18:21:18 +0200 | [diff] [blame] | 65 | return; |
Chris Lalancette | 8a43b1e | 2009-05-25 16:38:23 +0200 | [diff] [blame] | 66 | } |
| 67 | |
Daniel P. Berrange | 6f01f13 | 2016-09-30 11:57:14 +0100 | [diff] [blame] | 68 | qio_channel_set_name(ioc, "migration-exec-incoming"); |
Peter Xu | e89f5ff | 2018-05-02 18:47:17 +0800 | [diff] [blame] | 69 | qio_channel_add_watch_full(ioc, G_IO_IN, |
| 70 | exec_accept_incoming_migration, |
| 71 | NULL, NULL, |
| 72 | g_main_context_get_thread_default()); |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 73 | } |