static void colo_process_checkpoint(MigrationState *s)

{

    QIOChannelBuffer *bioc;

    QEMUFile *fb = NULL;

    int64_t current_time, checkpoint_time = qemu_clock_get_ms(QEMU_CLOCK_HOST);

    Error *local_err = NULL;

    int ret;



    failover_init_state();



    s->rp_state.from_dst_file = qemu_file_get_return_path(s->to_dst_file);

    if (!s->rp_state.from_dst_file) {

        error_report("Open QEMUFile from_dst_file failed");

        goto out;

    }



    /*

     * Wait for Secondary finish loading VM states and enter COLO

     * restore.

     */

    colo_receive_check_message(s->rp_state.from_dst_file,

                       COLO_MESSAGE_CHECKPOINT_READY, &local_err);

    if (local_err) {

        goto out;

    }

    bioc = qio_channel_buffer_new(COLO_BUFFER_BASE_SIZE);

    fb = qemu_fopen_channel_output(QIO_CHANNEL(bioc));

    object_unref(OBJECT(bioc));



    qemu_mutex_lock_iothread();

    vm_start();

    qemu_mutex_unlock_iothread();

    trace_colo_vm_state_change("stop", "run");



    while (s->state == MIGRATION_STATUS_COLO) {

        if (failover_get_state() != FAILOVER_STATUS_NONE) {

            error_report("failover request");

            goto out;

        }



        current_time = qemu_clock_get_ms(QEMU_CLOCK_HOST);

        if (current_time - checkpoint_time <

            s->parameters.x_checkpoint_delay) {

            int64_t delay_ms;



            delay_ms = s->parameters.x_checkpoint_delay -

                       (current_time - checkpoint_time);

            g_usleep(delay_ms * 1000);

        }

        ret = colo_do_checkpoint_transaction(s, bioc, fb);

        if (ret < 0) {

            goto out;

        }

        checkpoint_time = qemu_clock_get_ms(QEMU_CLOCK_HOST);

    }



out:

    /* Throw the unreported error message after exited from loop */

    if (local_err) {

        error_report_err(local_err);

    }



    if (fb) {

        qemu_fclose(fb);

    }



    if (s->rp_state.from_dst_file) {

        qemu_fclose(s->rp_state.from_dst_file);

    }

}

static void colo_process_checkpoint(MigrationState *s)

{

    QIOChannelBuffer *bioc;

    QEMUFile *fb = NULL;

    int64_t current_time, checkpoint_time = qemu_clock_get_ms(QEMU_CLOCK_HOST);

    Error *local_err = NULL;

    int ret;



    failover_init_state();



    s->rp_state.from_dst_file = qemu_file_get_return_path(s->to_dst_file);

    if (!s->rp_state.from_dst_file) {

        error_report("Open QEMUFile from_dst_file failed");

        goto out;

    }



    







    colo_receive_check_message(s->rp_state.from_dst_file,

                       COLO_MESSAGE_CHECKPOINT_READY, &local_err);

    if (local_err) {

        goto out;

    }

    bioc = qio_channel_buffer_new(COLO_BUFFER_BASE_SIZE);

    fb = qemu_fopen_channel_output(QIO_CHANNEL(bioc));

    object_unref(OBJECT(bioc));



    qemu_mutex_lock_iothread();

    vm_start();

    qemu_mutex_unlock_iothread();

    trace_colo_vm_state_change("stop", "run");



    while (s->state == MIGRATION_STATUS_COLO) {

        if (failover_get_state() != FAILOVER_STATUS_NONE) {

            error_report("failover request");

            goto out;

        }



        current_time = qemu_clock_get_ms(QEMU_CLOCK_HOST);

        if (current_time - checkpoint_time <

            s->parameters.x_checkpoint_delay) {

            int64_t delay_ms;



            delay_ms = s->parameters.x_checkpoint_delay -

                       (current_time - checkpoint_time);

            g_usleep(delay_ms * 1000);

        }

        ret = colo_do_checkpoint_transaction(s, bioc, fb);

        if (ret < 0) {

            goto out;

        }

        checkpoint_time = qemu_clock_get_ms(QEMU_CLOCK_HOST);

    }



out:

    

    if (local_err) {

        error_report_err(local_err);

    }



    if (fb) {

        qemu_fclose(fb);

    }



    if (s->rp_state.from_dst_file) {

        qemu_fclose(s->rp_state.from_dst_file);

    }

}

static void FUNC_0(MigrationState *VAR_0)

{

    QIOChannelBuffer *bioc;

    QEMUFile *fb = NULL;

    int64_t current_time, checkpoint_time = qemu_clock_get_ms(QEMU_CLOCK_HOST);

    Error *local_err = NULL;

    int VAR_1;



    failover_init_state();



    VAR_0->rp_state.from_dst_file = qemu_file_get_return_path(VAR_0->to_dst_file);

    if (!VAR_0->rp_state.from_dst_file) {

        error_report("Open QEMUFile from_dst_file failed");

        goto out;

    }



    







    colo_receive_check_message(VAR_0->rp_state.from_dst_file,

                       COLO_MESSAGE_CHECKPOINT_READY, &local_err);

    if (local_err) {

        goto out;

    }

    bioc = qio_channel_buffer_new(COLO_BUFFER_BASE_SIZE);

    fb = qemu_fopen_channel_output(QIO_CHANNEL(bioc));

    object_unref(OBJECT(bioc));



    qemu_mutex_lock_iothread();

    vm_start();

    qemu_mutex_unlock_iothread();

    trace_colo_vm_state_change("stop", "run");



    while (VAR_0->state == MIGRATION_STATUS_COLO) {

        if (failover_get_state() != FAILOVER_STATUS_NONE) {

            error_report("failover request");

            goto out;

        }



        current_time = qemu_clock_get_ms(QEMU_CLOCK_HOST);

        if (current_time - checkpoint_time <

            VAR_0->parameters.x_checkpoint_delay) {

            int64_t delay_ms;



            delay_ms = VAR_0->parameters.x_checkpoint_delay -

                       (current_time - checkpoint_time);

            g_usleep(delay_ms * 1000);

        }

        VAR_1 = colo_do_checkpoint_transaction(VAR_0, bioc, fb);

        if (VAR_1 < 0) {

            goto out;

        }

        checkpoint_time = qemu_clock_get_ms(QEMU_CLOCK_HOST);

    }



out:

    

    if (local_err) {

        error_report_err(local_err);

    }



    if (fb) {

        qemu_fclose(fb);

    }



    if (VAR_0->rp_state.from_dst_file) {

        qemu_fclose(VAR_0->rp_state.from_dst_file);

    }

}

static void FUNC_0(MigrationState *VAR_0)
{ QIOChannelBuffer *bioc; QEMUFile *fb = NULL; int64_t current_time, checkpoint_time = qemu_clock_get_ms(QEMU_CLOCK_HOST); Error *local_err = NULL; int VAR_1; failover_init_state(); VAR_0->rp_state.from_dst_file = qemu_file_get_return_path(VAR_0->to_dst_file); if (!VAR_0->rp_state.from_dst_file) { error_report("Open QEMUFile from_dst_file failed"); goto out; } colo_receive_check_message(VAR_0->rp_state.from_dst_file,
COLO_MESSAGE_CHECKPOINT_READY, &local_err); if (local_err) { goto out; } bioc = qio_channel_buffer_new(COLO_BUFFER_BASE_SIZE); fb = qemu_fopen_channel_output(QIO_CHANNEL(bioc)); object_unref(OBJECT(bioc)); qemu_mutex_lock_iothread(); vm_start(); qemu_mutex_unlock_iothread(); trace_colo_vm_state_change("stop", "run"); while (VAR_0->state == MIGRATION_STATUS_COLO) { if (failover_get_state() != FAILOVER_STATUS_NONE) { error_report("failover request"); goto out; } current_time = qemu_clock_get_ms(QEMU_CLOCK_HOST); if (current_time - checkpoint_time <
VAR_0->parameters.x_checkpoint_delay) { int64_t delay_ms; delay_ms = VAR_0->parameters.x_checkpoint_delay -
(current_time - checkpoint_time); g_usleep(delay_ms * 1000); } VAR_1 = colo_do_checkpoint_transaction(VAR_0, bioc, fb); if (VAR_1 < 0) { goto out; } checkpoint_time = qemu_clock_get_ms(QEMU_CLOCK_HOST); } out:
if (local_err) { error_report_err(local_err); } if (fb) { qemu_fclose(fb); } if (VAR_0->rp_state.from_dst_file) { qemu_fclose(VAR_0->rp_state.from_dst_file); } }