//#define DEBUG_MIGRATION_UNIX
#ifdef DEBUG_MIGRATION_UNIX
-#define dprintf(fmt, ...) \
+#define DPRINTF(fmt, ...) \
do { printf("migration-unix: " fmt, ## __VA_ARGS__); } while (0)
#else
-#define dprintf(fmt, ...) \
+#define DPRINTF(fmt, ...) \
do { } while (0)
#endif
static int unix_close(FdMigrationState *s)
{
- dprintf("unix_close\n");
+ DPRINTF("unix_close\n");
if (s->fd != -1) {
close(s->fd);
s->fd = -1;
int val, ret;
socklen_t valsize = sizeof(val);
- dprintf("connect completed\n");
+ DPRINTF("connect completed\n");
do {
ret = getsockopt(s->fd, SOL_SOCKET, SO_ERROR, (void *) &val, &valsize);
} while (ret == -1 && (s->get_error(s)) == EINTR);
if (val == 0)
migrate_fd_connect(s);
else {
- dprintf("error connecting %d\n", val);
+ DPRINTF("error connecting %d\n", val);
migrate_fd_error(s);
}
}
s->state = MIG_STATE_ACTIVE;
s->mon = NULL;
s->bandwidth_limit = bandwidth_limit;
- s->fd = socket(PF_UNIX, SOCK_STREAM, 0);
+ s->fd = qemu_socket(PF_UNIX, SOCK_STREAM, 0);
if (s->fd < 0) {
- dprintf("Unable to open socket");
+ DPRINTF("Unable to open socket");
goto err_after_alloc;
}
socket_set_nonblock(s->fd);
- if (!detach) {
- migrate_fd_monitor_suspend(s, mon);
- }
-
do {
ret = connect(s->fd, (struct sockaddr *)&addr, sizeof(addr));
if (ret == -1)
} while (ret == -EINTR);
if (ret < 0 && ret != -EINPROGRESS && ret != -EWOULDBLOCK) {
- dprintf("connect failed\n");
+ DPRINTF("connect failed\n");
goto err_after_open;
- } else if (ret >= 0)
+ }
+
+ if (!detach) {
+ migrate_fd_monitor_suspend(s, mon);
+ }
+
+ if (ret >= 0)
migrate_fd_connect(s);
return &s->mig_state;
socklen_t addrlen = sizeof(addr);
int s = (unsigned long)opaque;
QEMUFile *f;
- int c, ret;
+ int c;
do {
- c = accept(s, (struct sockaddr *)&addr, &addrlen);
+ c = qemu_accept(s, (struct sockaddr *)&addr, &addrlen);
} while (c == -1 && socket_error() == EINTR);
- dprintf("accepted migration\n");
+ DPRINTF("accepted migration\n");
if (c == -1) {
fprintf(stderr, "could not accept migration connection\n");
goto out;
}
- ret = qemu_loadvm_state(f);
- if (ret < 0) {
- fprintf(stderr, "load of migration failed\n");
- goto out_fopen;
- }
- qemu_announce_self();
- dprintf("successfully loaded vm state\n");
-
- /* we've successfully migrated, close the server socket */
- qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL);
- close(s);
-
-out_fopen:
+ process_incoming_migration(f);
qemu_fclose(f);
out:
+ qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL);
+ close(s);
close(c);
}
struct sockaddr_un un;
int sock;
- dprintf("Attempting to start an incoming migration\n");
+ DPRINTF("Attempting to start an incoming migration\n");
- sock = socket(PF_UNIX, SOCK_STREAM, 0);
+ sock = qemu_socket(PF_UNIX, SOCK_STREAM, 0);
if (sock < 0) {
fprintf(stderr, "Could not open unix socket: %s\n", strerror(errno));
return -EINVAL;