4 * Copyright IBM, Corp. 2008
5 * Copyright Dell MessageOne 2008
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"
22 #include "buffered_file.h"
25 //#define DEBUG_MIGRATION_EXEC
27 #ifdef DEBUG_MIGRATION_EXEC
28 #define dprintf(fmt, ...) \
29 do { printf("migration-exec: " fmt, ## __VA_ARGS__); } while (0)
31 #define dprintf(fmt, ...) \
35 static int file_errno(FdMigrationState *s)
40 static int file_write(FdMigrationState *s, const void * buf, size_t size)
42 return write(s->fd, buf, size);
45 static int exec_close(FdMigrationState *s)
47 dprintf("exec_close\n");
49 qemu_fclose(s->opaque);
56 MigrationState *exec_start_outgoing_migration(const char *command,
57 int64_t bandwidth_limit,
63 s = qemu_mallocz(sizeof(*s));
65 dprintf("Unable to allocate FdMigrationState\n");
69 f = popen(command, "w");
71 dprintf("Unable to popen exec target\n");
77 dprintf("Unable to retrieve file descriptor for popen'd handle\n");
81 if (fcntl(s->fd, F_SETFD, O_NONBLOCK) == -1) {
82 dprintf("Unable to set nonblocking mode on file descriptor\n");
86 s->opaque = qemu_popen(f, "w");
88 s->close = exec_close;
89 s->get_error = file_errno;
90 s->write = file_write;
91 s->mig_state.cancel = migrate_fd_cancel;
92 s->mig_state.get_status = migrate_fd_get_status;
93 s->mig_state.release = migrate_fd_release;
95 s->state = MIG_STATE_ACTIVE;
97 s->bandwidth_limit = bandwidth_limit;
100 dprintf("detaching from monitor\n");
105 migrate_fd_connect(s);
106 return &s->mig_state;
116 int exec_start_incoming_migration(const char *command)
121 dprintf("Attempting to start an incoming migration\n");
122 f = qemu_popen_cmd(command, "r");
124 dprintf("Unable to apply qemu wrapper to popen file\n");
127 vm_stop(0); /* just in case */
128 ret = qemu_loadvm_state(f);
130 fprintf(stderr, "load of migration failed\n");
133 qemu_announce_self();
134 dprintf("successfully loaded vm state\n");