aboutsummaryrefslogtreecommitdiff
path: root/migration.c
blob: 9e6c43731ee6f6f2524c67eff2af6b7d7ea0e82c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 * QEMU live migration
 *
 * Copyright IBM, Corp. 2008
 *
 * Authors:
 *  Anthony Liguori   <aliguori@us.ibm.com>
 *
 * This work is licensed under the terms of the GNU GPL, version 2.  See
 * the COPYING file in the top-level directory.
 *
 */

#include "qemu-common.h"
#include "migration.h"
#include "console.h"

/* Migration speed throttling */
static uint32_t max_throttle = (32 << 20);

static MigrationState *current_migration;

void qemu_start_incoming_migration(const char *uri)
{
    const char *p;

    if (strstart(uri, "tcp:", &p))
        tcp_start_incoming_migration(p);
    else
        fprintf(stderr, "unknown migration protocol: %s\n", uri);
}

void do_migrate(int detach, const char *uri)
{
    MigrationState *s = NULL;
    const char *p;

    if (strstart(uri, "tcp:", &p))
        s = tcp_start_outgoing_migration(p, max_throttle, detach);
    else
        term_printf("unknown migration protocol: %s\n", uri);

    if (s == NULL)
        term_printf("migration failed\n");
    else {
        if (current_migration)
            current_migration->release(current_migration);

        current_migration = s;
    }
}

void do_migrate_cancel(void)
{
    MigrationState *s = current_migration;

    if (s)
        s->cancel(s);
}

void do_migrate_set_speed(const char *value)
{
    double d;
    char *ptr;

    d = strtod(value, &ptr);
    switch (*ptr) {
    case 'G': case 'g':
        d *= 1024;
    case 'M': case 'm':
        d *= 1024;
    case 'K': case 'k':
        d *= 1024;
    default:
        break;
    }

    max_throttle = (uint32_t)d;
}

void do_info_migrate(void)
{
    MigrationState *s = current_migration;
    
    if (s) {
        term_printf("Migration status: ");
        switch (s->get_status(s)) {
        case MIG_STATE_ACTIVE:
            term_printf("active\n");
            break;
        case MIG_STATE_COMPLETED:
            term_printf("completed\n");
            break;
        case MIG_STATE_ERROR:
            term_printf("failed\n");
            break;
        case MIG_STATE_CANCELLED:
            term_printf("cancelled\n");
            break;
        }
    }
}