Commit 2a0dfd00 authored by Anthony Liguori's avatar Anthony Liguori
Browse files

Merge remote-tracking branch 'bonzini/migr-coroutine' into staging



Signed-off-by: default avatarAnthony Liguori <aliguori@us.ibm.com>

* bonzini/migr-coroutine:
  migration: move process_incoming_migration to a coroutine
  migration: handle EAGAIN while reading QEMUFile
  migration: move qemu_fclose to process_incoming_migration
  migration: close socket QEMUFile from socket_close
  migration: xxx_close will only be called once
  migration: use closesocket, not close
  migration: use migrate_fd_close in migrate_fd_cleanup
  migration: clean up server sockets and handlers before invoking process_incoming_migration
  migration: replace qemu_stdio_fd with qemu_get_fd
  migration: add qemu_get_fd
  migration: consolidate QEMUFile methods in a single QEMUFileOps struct
  migration: unify stdio-based QEMUFile operations
parents 1ef2a82e 82a4da79
Loading
Loading
Loading
Loading
+17 −4
Original line number Diff line number Diff line
@@ -174,6 +174,13 @@ static int buffered_close(void *opaque)
 *   1: Time to stop
 *   negative: There has been an error
 */
static int buffered_get_fd(void *opaque)
{
    QEMUFileBuffered *s = opaque;

    return qemu_get_fd(s->file);
}

static int buffered_rate_limit(void *opaque)
{
    QEMUFileBuffered *s = opaque;
@@ -234,6 +241,15 @@ static void buffered_rate_tick(void *opaque)
    buffered_put_buffer(s, NULL, 0, 0);
}

static const QEMUFileOps buffered_file_ops = {
    .get_fd =         buffered_get_fd,
    .put_buffer =     buffered_put_buffer,
    .close =          buffered_close,
    .rate_limit =     buffered_rate_limit,
    .get_rate_limit = buffered_get_rate_limit,
    .set_rate_limit = buffered_set_rate_limit,
};

QEMUFile *qemu_fopen_ops_buffered(MigrationState *migration_state)
{
    QEMUFileBuffered *s;
@@ -243,10 +259,7 @@ QEMUFile *qemu_fopen_ops_buffered(MigrationState *migration_state)
    s->migration_state = migration_state;
    s->xfer_limit = migration_state->bandwidth_limit / 10;

    s->file = qemu_fopen_ops(s, buffered_put_buffer, NULL,
                             buffered_close, buffered_rate_limit,
                             buffered_set_rate_limit,
			     buffered_get_rate_limit);
    s->file = qemu_fopen_ops(s, &buffered_file_ops);

    s->timer = qemu_new_timer_ms(rt_clock, buffered_rate_tick, s);

+8 −11
Original line number Diff line number Diff line
@@ -48,7 +48,6 @@ static int exec_close(MigrationState *s)
{
    int ret = 0;
    DPRINTF("exec_close\n");
    if (s->opaque) {
    ret = qemu_fclose(s->opaque);
    s->opaque = NULL;
    s->fd = -1;
@@ -56,7 +55,6 @@ static int exec_close(MigrationState *s)
        /* close succeeded, but non-zero exit code: */
        ret = -EIO; /* fake errno value */
    }
    }
    return ret;
}

@@ -87,9 +85,8 @@ static void exec_accept_incoming_migration(void *opaque)
{
    QEMUFile *f = opaque;

    qemu_set_fd_handler2(qemu_get_fd(f), NULL, NULL, NULL, NULL);
    process_incoming_migration(f);
    qemu_set_fd_handler2(qemu_stdio_fd(f), NULL, NULL, NULL, NULL);
    qemu_fclose(f);
}

void exec_start_incoming_migration(const char *command, Error **errp)
@@ -103,6 +100,6 @@ void exec_start_incoming_migration(const char *command, Error **errp)
        return;
    }

    qemu_set_fd_handler2(qemu_stdio_fd(f), NULL,
    qemu_set_fd_handler2(qemu_get_fd(f), NULL,
			 exec_accept_incoming_migration, NULL, f);
}
+16 −20
Original line number Diff line number Diff line
@@ -48,7 +48,6 @@ static int fd_close(MigrationState *s)
    int ret;

    DPRINTF("fd_close\n");
    if (s->fd != -1) {
    ret = fstat(s->fd, &st);
    if (ret == 0 && S_ISREG(st.st_mode)) {
        /*
@@ -67,10 +66,8 @@ static int fd_close(MigrationState *s)
    if (ret != 0) {
        ret = -errno;
        perror("migration-fd: close");
            return ret;
        }
    }
    return 0;
    return ret;
}

void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp)
@@ -92,9 +89,8 @@ static void fd_accept_incoming_migration(void *opaque)
{
    QEMUFile *f = opaque;

    qemu_set_fd_handler2(qemu_get_fd(f), NULL, NULL, NULL, NULL);
    process_incoming_migration(f);
    qemu_set_fd_handler2(qemu_stdio_fd(f), NULL, NULL, NULL, NULL);
    qemu_fclose(f);
}

void fd_start_incoming_migration(const char *infd, Error **errp)
+8 −11
Original line number Diff line number Diff line
@@ -44,11 +44,8 @@ static int tcp_close(MigrationState *s)
{
    int r = 0;
    DPRINTF("tcp_close\n");
    if (s->fd != -1) {
        if (close(s->fd) < 0) {
            r = -errno;
        }
        s->fd = -1;
    if (closesocket(s->fd) < 0) {
        r = -socket_error();
    }
    return r;
}
@@ -88,12 +85,14 @@ static void tcp_accept_incoming_migration(void *opaque)
    do {
        c = qemu_accept(s, (struct sockaddr *)&addr, &addrlen);
    } while (c == -1 && socket_error() == EINTR);
    qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL);
    closesocket(s);

    DPRINTF("accepted migration\n");

    if (c == -1) {
        fprintf(stderr, "could not accept migration connection\n");
        goto out2;
        goto out;
    }

    f = qemu_fopen_socket(c);
@@ -103,12 +102,10 @@ static void tcp_accept_incoming_migration(void *opaque)
    }

    process_incoming_migration(f);
    qemu_fclose(f);
    return;

out:
    close(c);
out2:
    qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL);
    close(s);
    closesocket(c);
}

void tcp_start_incoming_migration(const char *host_port, Error **errp)
+7 −10
Original line number Diff line number Diff line
@@ -44,12 +44,9 @@ static int unix_close(MigrationState *s)
{
    int r = 0;
    DPRINTF("unix_close\n");
    if (s->fd != -1) {
    if (close(s->fd) < 0) {
        r = -errno;
    }
        s->fd = -1;
    }
    return r;
}

@@ -88,12 +85,14 @@ static void unix_accept_incoming_migration(void *opaque)
    do {
        c = qemu_accept(s, (struct sockaddr *)&addr, &addrlen);
    } while (c == -1 && errno == EINTR);
    qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL);
    close(s);

    DPRINTF("accepted migration\n");

    if (c == -1) {
        fprintf(stderr, "could not accept migration connection\n");
        goto out2;
        goto out;
    }

    f = qemu_fopen_socket(c);
@@ -103,12 +102,10 @@ static void unix_accept_incoming_migration(void *opaque)
    }

    process_incoming_migration(f);
    qemu_fclose(f);
    return;

out:
    close(c);
out2:
    qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL);
    close(s);
}

void unix_start_incoming_migration(const char *path, Error **errp)
Loading