4 * Copyright IBM, Corp. 2008
5 * Copyright Dell MessageOne 2008
8 * Anthony Liguori <aliguori@us.ibm.com>
9 * Charles Duffy <charles_duffy@messageone.com>
11 * This work is licensed under the terms of the GNU GPL, version 2. See
12 * the COPYING file in the top-level directory.
16 #include "qemu-common.h"
17 #include "qemu_socket.h"
18 #include "migration.h"
19 #include "qemu-char.h"
21 #include "buffered_file.h"
24 //#define DEBUG_MIGRATION_EXEC
26 #ifdef DEBUG_MIGRATION_EXEC
27 #define DPRINTF(fmt, ...) \
28 do { printf("migration-exec: " fmt, ## __VA_ARGS__); } while (0)
30 #define DPRINTF(fmt, ...) \
34 static int file_errno(FdMigrationState
*s
)
39 static int file_write(FdMigrationState
*s
, const void * buf
, size_t size
)
41 return write(s
->fd
, buf
, size
);
44 static int exec_close(FdMigrationState
*s
)
47 DPRINTF("exec_close\n");
49 ret
= qemu_fclose(s
->opaque
);
54 && WEXITSTATUS(ret
) == 0) {
63 MigrationState
*exec_start_outgoing_migration(Monitor
*mon
,
65 int64_t bandwidth_limit
,
73 s
= qemu_mallocz(sizeof(*s
));
75 f
= popen(command
, "w");
77 DPRINTF("Unable to popen exec target\n");
83 DPRINTF("Unable to retrieve file descriptor for popen'd handle\n");
87 socket_set_nonblock(s
->fd
);
89 s
->opaque
= qemu_popen(f
, "w");
91 s
->close
= exec_close
;
92 s
->get_error
= file_errno
;
93 s
->write
= file_write
;
94 s
->mig_state
.cancel
= migrate_fd_cancel
;
95 s
->mig_state
.get_status
= migrate_fd_get_status
;
96 s
->mig_state
.release
= migrate_fd_release
;
98 s
->mig_state
.blk
= blk
;
99 s
->mig_state
.shared
= inc
;
101 s
->state
= MIG_STATE_ACTIVE
;
103 s
->bandwidth_limit
= bandwidth_limit
;
106 migrate_fd_monitor_suspend(s
, mon
);
109 migrate_fd_connect(s
);
110 return &s
->mig_state
;
119 static void exec_accept_incoming_migration(void *opaque
)
121 QEMUFile
*f
= opaque
;
124 ret
= qemu_loadvm_state(f
);
126 fprintf(stderr
, "load of migration failed\n");
129 qemu_announce_self();
130 DPRINTF("successfully loaded vm state\n");
136 qemu_set_fd_handler2(qemu_stdio_fd(f
), NULL
, NULL
, NULL
, NULL
);
140 int exec_start_incoming_migration(const char *command
)
144 DPRINTF("Attempting to start an incoming migration\n");
145 f
= qemu_popen_cmd(command
, "r");
147 DPRINTF("Unable to apply qemu wrapper to popen file\n");
151 qemu_set_fd_handler2(qemu_stdio_fd(f
), NULL
,
152 exec_accept_incoming_migration
, NULL
, f
);