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" |
Paolo Bonzini | caf71f8 | 2012-12-17 18:19:50 +0100 | [diff] [blame] | 20 | #include "migration/migration.h" |
Juan Quintela | 557ec5a | 2012-10-03 14:07:31 +0200 | [diff] [blame] | 21 | #include "migration/qemu-file.h" |
Paolo Bonzini | 737e150 | 2012-12-17 18:19:44 +0100 | [diff] [blame] | 22 | #include "block/block.h" |
Blue Swirl | 0ffbba3 | 2010-06-04 20:01:07 +0000 | [diff] [blame] | 23 | #include <sys/types.h> |
| 24 | #include <sys/wait.h> |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 25 | |
| 26 | //#define DEBUG_MIGRATION_EXEC |
| 27 | |
| 28 | #ifdef DEBUG_MIGRATION_EXEC |
malc | d0f2c4c | 2010-02-07 02:03:50 +0300 | [diff] [blame] | 29 | #define DPRINTF(fmt, ...) \ |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 30 | do { printf("migration-exec: " fmt, ## __VA_ARGS__); } while (0) |
| 31 | #else |
malc | d0f2c4c | 2010-02-07 02:03:50 +0300 | [diff] [blame] | 32 | #define DPRINTF(fmt, ...) \ |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 33 | do { } while (0) |
| 34 | #endif |
| 35 | |
Paolo Bonzini | f37afb5 | 2012-10-02 10:02:46 +0200 | [diff] [blame] | 36 | void exec_start_outgoing_migration(MigrationState *s, const char *command, Error **errp) |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 37 | { |
Paolo Bonzini | b352365 | 2013-02-22 17:36:47 +0100 | [diff] [blame] | 38 | s->file = qemu_popen_cmd(command, "w"); |
| 39 | if (s->file == NULL) { |
Paolo Bonzini | f37afb5 | 2012-10-02 10:02:46 +0200 | [diff] [blame] | 40 | error_setg_errno(errp, errno, "failed to popen the migration target"); |
| 41 | return; |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 42 | } |
| 43 | |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 44 | migrate_fd_connect(s); |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Chris Lalancette | 8a43b1e | 2009-05-25 16:38:23 +0200 | [diff] [blame] | 47 | static void exec_accept_incoming_migration(void *opaque) |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 48 | { |
Chris Lalancette | 8a43b1e | 2009-05-25 16:38:23 +0200 | [diff] [blame] | 49 | QEMUFile *f = opaque; |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 50 | |
Paolo Bonzini | d263a20 | 2012-08-08 10:21:26 +0200 | [diff] [blame] | 51 | qemu_set_fd_handler2(qemu_get_fd(f), NULL, NULL, NULL, NULL); |
Paolo Bonzini | a6ef290 | 2012-08-07 10:49:13 +0200 | [diff] [blame] | 52 | process_incoming_migration(f); |
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 | { |
| 57 | QEMUFile *f; |
| 58 | |
malc | d0f2c4c | 2010-02-07 02:03:50 +0300 | [diff] [blame] | 59 | DPRINTF("Attempting to start an incoming migration\n"); |
Chris Lalancette | 8a43b1e | 2009-05-25 16:38:23 +0200 | [diff] [blame] | 60 | f = qemu_popen_cmd(command, "r"); |
| 61 | if(f == NULL) { |
Paolo Bonzini | 43eaae2 | 2012-10-02 18:21:18 +0200 | [diff] [blame] | 62 | error_setg_errno(errp, errno, "failed to popen the migration source"); |
| 63 | return; |
Chris Lalancette | 8a43b1e | 2009-05-25 16:38:23 +0200 | [diff] [blame] | 64 | } |
| 65 | |
Paolo Bonzini | d263a20 | 2012-08-08 10:21:26 +0200 | [diff] [blame] | 66 | qemu_set_fd_handler2(qemu_get_fd(f), NULL, |
Juan Quintela | 1c39e2a | 2010-03-11 17:55:38 +0100 | [diff] [blame] | 67 | exec_accept_incoming_migration, NULL, f); |
aliguori | 065e281 | 2008-11-11 16:46:33 +0000 | [diff] [blame] | 68 | } |