colo.c 2.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
 * COarse-grain LOck-stepping Virtual Machines for Non-stop Service (COLO)
 * (a.k.a. Fault Tolerance or Continuous Replication)
 *
 * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
 * Copyright (c) 2016 FUJITSU LIMITED
 * Copyright (c) 2016 Intel Corporation
 *
 * This work is licensed under the terms of the GNU GPL, version 2 or
 * later.  See the COPYING file in the top-level directory.
 */

#include "qemu/osdep.h"
14
#include "sysemu/sysemu.h"
15
#include "migration/colo.h"
16
#include "trace.h"
17
#include "qemu/error-report.h"
18 19 20 21 22

bool colo_supported(void)
{
    return false;
}
23 24 25 26 27 28 29 30

bool migration_in_colo_state(void)
{
    MigrationState *s = migrate_get_current();

    return (s->state == MIGRATION_STATUS_COLO);
}

31 32 33 34 35 36 37
bool migration_incoming_in_colo_state(void)
{
    MigrationIncomingState *mis = migration_incoming_get_current();

    return mis && (mis->state == MIGRATION_STATUS_COLO);
}

38 39
static void colo_process_checkpoint(MigrationState *s)
{
40 41 42 43 44 45
    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;
    }

46 47 48 49 50 51 52
    qemu_mutex_lock_iothread();
    vm_start();
    qemu_mutex_unlock_iothread();
    trace_colo_vm_state_change("stop", "run");

    /* TODO: COLO checkpoint savevm loop */

53 54 55 56
out:
    if (s->rp_state.from_dst_file) {
        qemu_fclose(s->rp_state.from_dst_file);
    }
57 58 59 60 61 62 63 64 65 66
}

void migrate_start_colo_process(MigrationState *s)
{
    qemu_mutex_unlock_iothread();
    migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE,
                      MIGRATION_STATUS_COLO);
    colo_process_checkpoint(s);
    qemu_mutex_lock_iothread();
}
67 68 69 70 71 72 73 74

void *colo_process_incoming_thread(void *opaque)
{
    MigrationIncomingState *mis = opaque;

    migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE,
                      MIGRATION_STATUS_COLO);

75 76 77 78 79 80 81 82 83 84 85 86 87
    mis->to_src_file = qemu_file_get_return_path(mis->from_src_file);
    if (!mis->to_src_file) {
        error_report("COLO incoming thread: Open QEMUFile to_src_file failed");
        goto out;
    }
    /*
     * Note: the communication between Primary side and Secondary side
     * should be sequential, we set the fd to unblocked in migration incoming
     * coroutine, and here we are in the COLO incoming thread, so it is ok to
     * set the fd back to blocked.
     */
    qemu_file_set_blocking(mis->from_src_file, true);

88 89
    /* TODO: COLO checkpoint restore loop */

90 91 92 93
out:
    if (mis->to_src_file) {
        qemu_fclose(mis->to_src_file);
    }
94 95 96 97
    migration_incoming_exit_colo();

    return NULL;
}