-static void fd_wait_for_unfreeze(void *opaque)
-{
- FdMigrationState *s = opaque;
- int ret;
-
- dprintf("wait for unfreeze\n");
- if (s->state != MIG_STATE_ACTIVE)
- return;
-
- do {
- fd_set wfds;
-
- FD_ZERO(&wfds);
- FD_SET(s->fd, &wfds);
-
- ret = select(s->fd + 1, NULL, &wfds, NULL, NULL);
- } while (ret == -1 && socket_error() == EINTR);
-}
-
-static void fd_put_ready(void *opaque)
-{
- FdMigrationState *s = opaque;
-
- if (s->state != MIG_STATE_ACTIVE) {
- dprintf("put_ready returning because of non-active state\n");
- return;
- }
-
- dprintf("iterate\n");
- if (qemu_savevm_state_iterate(s->file) == 1) {
- dprintf("done iterating\n");
- vm_stop(0);
-
- bdrv_flush_all();
- qemu_savevm_state_complete(s->file);
- s->state = MIG_STATE_COMPLETED;
- tcp_cleanup(s);
- }
-}
-
-static void tcp_connect_migrate(FdMigrationState *s)
-{
- int ret;
-
- s->file = qemu_fopen_ops_buffered(s,
- s->bandwidth_limit,
- fd_put_buffer,
- fd_put_ready,
- fd_wait_for_unfreeze,
- fd_close);
-
- dprintf("beginning savevm\n");
- ret = qemu_savevm_state_begin(s->file);
- if (ret < 0) {
- dprintf("failed, %d\n", ret);
- tcp_error(s);
- return;
- }
-
- fd_put_ready(s);
-}