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 |
| 6 | * |
| 7 | * Authors: |
| 8 | * Anthony Liguori <aliguori@us.ibm.com> |
| 9 | * Charles Duffy <charles_duffy@messageone.com> |
| 10 | * |
| 11 | * This work is licensed under the terms of the GNU GPL, version 2. See |
| 12 | * the COPYING file in the top-level directory. |
| 13 | * |
Paolo Bonzini | 6b620ca | 2012-01-13 17:44:23 +0100 | [diff] [blame] | 14 | * Contributions after 2012-01-13 are licensed under the terms of the |
| 15 | * GNU GPL, version 2 or (at your option) any later version. |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include "qemu-common.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 19 | #include "qemu/sockets.h" |
Alex Bligh | 6a1751b | 2013-08-21 16:02:47 +0100 | [diff] [blame] | 20 | #include "qemu/main-loop.h" |
Paolo Bonzini | caf71f8 | 2012-12-17 18:19:50 +0100 | [diff] [blame] | 21 | #include "migration/migration.h" |
Juan Quintela | 557ec5a | 2012-10-03 14:07:31 +0200 | [diff] [blame] | 22 | #include "migration/qemu-file.h" |
Paolo Bonzini | 737e150 | 2012-12-17 18:19:44 +0100 | [diff] [blame] | 23 | #include "block/block.h" |
Blue Swirl | 0ffbba3 | 2010-06-04 20:01:07 +0000 | [diff] [blame] | 24 | #include <sys/types.h> |
| 25 | #include <sys/wait.h> |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 26 | |
| 27 | //#define DEBUG_MIGRATION_EXEC |
| 28 | |
| 29 | #ifdef DEBUG_MIGRATION_EXEC |
malc | d0f2c4c | 2010-02-07 02:03:50 +0300 | [diff] [blame] | 30 | #define DPRINTF(fmt, ...) \ |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 31 | do { printf("migration-exec: " fmt, ## __VA_ARGS__); } while (0) |
| 32 | #else |
malc | d0f2c4c | 2010-02-07 02:03:50 +0300 | [diff] [blame] | 33 | #define DPRINTF(fmt, ...) \ |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 34 | do { } while (0) |
| 35 | #endif |
| 36 | |
Paolo Bonzini | f37afb5 | 2012-10-02 10:02:46 +0200 | [diff] [blame] | 37 | void exec_start_outgoing_migration(MigrationState *s, const char *command, Error **errp) |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 38 | { |
Paolo Bonzini | b352365 | 2013-02-22 17:36:47 +0100 | [diff] [blame] | 39 | s->file = qemu_popen_cmd(command, "w"); |
| 40 | if (s->file == NULL) { |
Paolo Bonzini | f37afb5 | 2012-10-02 10:02:46 +0200 | [diff] [blame] | 41 | error_setg_errno(errp, errno, "failed to popen the migration target"); |
| 42 | return; |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 43 | } |
| 44 | |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 45 | migrate_fd_connect(s); |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Chris Lalancette | 8a43b1e | 2009-05-25 16:38:23 +0200 | [diff] [blame] | 48 | static void exec_accept_incoming_migration(void *opaque) |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 49 | { |
Chris Lalancette | 8a43b1e | 2009-05-25 16:38:23 +0200 | [diff] [blame] | 50 | QEMUFile *f = opaque; |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 51 | |
Paolo Bonzini | d263a20 | 2012-08-08 10:21:26 +0200 | [diff] [blame] | 52 | qemu_set_fd_handler2(qemu_get_fd(f), NULL, NULL, NULL, NULL); |
Paolo Bonzini | a6ef290 | 2012-08-07 10:49:13 +0200 | [diff] [blame] | 53 | process_incoming_migration(f); |
Chris Lalancette | 8a43b1e | 2009-05-25 16:38:23 +0200 | [diff] [blame] | 54 | } |
| 55 | |
Paolo Bonzini | 43eaae2 | 2012-10-02 18:21:18 +0200 | [diff] [blame] | 56 | void exec_start_incoming_migration(const char *command, Error **errp) |
Chris Lalancette | 8a43b1e | 2009-05-25 16:38:23 +0200 | [diff] [blame] | 57 | { |
| 58 | QEMUFile *f; |
| 59 | |
malc | d0f2c4c | 2010-02-07 02:03:50 +0300 | [diff] [blame] | 60 | DPRINTF("Attempting to start an incoming migration\n"); |
Chris Lalancette | 8a43b1e | 2009-05-25 16:38:23 +0200 | [diff] [blame] | 61 | f = qemu_popen_cmd(command, "r"); |
| 62 | if(f == NULL) { |
Paolo Bonzini | 43eaae2 | 2012-10-02 18:21:18 +0200 | [diff] [blame] | 63 | error_setg_errno(errp, errno, "failed to popen the migration source"); |
| 64 | return; |
Chris Lalancette | 8a43b1e | 2009-05-25 16:38:23 +0200 | [diff] [blame] | 65 | } |
| 66 | |
Paolo Bonzini | d263a20 | 2012-08-08 10:21:26 +0200 | [diff] [blame] | 67 | qemu_set_fd_handler2(qemu_get_fd(f), NULL, |
Juan Quintela | 1c39e2a | 2010-03-11 17:55:38 +0100 | [diff] [blame] | 68 | exec_accept_incoming_migration, NULL, f); |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 69 | } |