Fix whitespace in migration code.
[qemu] / migration.c
1 /*
2  * QEMU live migration
3  *
4  * Copyright IBM, Corp. 2008
5  *
6  * Authors:
7  *  Anthony Liguori   <aliguori@us.ibm.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2.  See
10  * the COPYING file in the top-level directory.
11  *
12  */
13
14 #include "qemu-common.h"
15 #include "migration.h"
16 #include "console.h"
17
18 /* Migration speed throttling */
19 static uint32_t max_throttle = (32 << 20);
20
21 static MigrationState *current_migration;
22
23 void qemu_start_incoming_migration(const char *uri)
24 {
25     const char *p;
26
27     if (strstart(uri, "tcp:", &p))
28         tcp_start_incoming_migration(p);
29     else
30         fprintf(stderr, "unknown migration protocol: %s\n", uri);
31 }
32
33 void do_migrate(int detach, const char *uri)
34 {
35     MigrationState *s = NULL;
36     const char *p;
37
38     if (strstart(uri, "tcp:", &p))
39         s = tcp_start_outgoing_migration(p, max_throttle, detach);
40     else
41         term_printf("unknown migration protocol: %s\n", uri);
42
43     if (s == NULL)
44         term_printf("migration failed\n");
45     else {
46         if (current_migration)
47             current_migration->release(current_migration);
48
49         current_migration = s;
50     }
51 }
52
53 void do_migrate_cancel(void)
54 {
55     MigrationState *s = current_migration;
56
57     if (s)
58         s->cancel(s);
59 }
60
61 void do_migrate_set_speed(const char *value)
62 {
63     double d;
64     char *ptr;
65
66     d = strtod(value, &ptr);
67     switch (*ptr) {
68     case 'G': case 'g':
69         d *= 1024;
70     case 'M': case 'm':
71         d *= 1024;
72     case 'K': case 'k':
73         d *= 1024;
74     default:
75         break;
76     }
77
78     max_throttle = (uint32_t)d;
79 }
80
81 void do_info_migrate(void)
82 {
83     MigrationState *s = current_migration;
84     
85     if (s) {
86         term_printf("Migration status: ");
87         switch (s->get_status(s)) {
88         case MIG_STATE_ACTIVE:
89             term_printf("active\n");
90             break;
91         case MIG_STATE_COMPLETED:
92             term_printf("completed\n");
93             break;
94         case MIG_STATE_ERROR:
95             term_printf("failed\n");
96             break;
97         case MIG_STATE_CANCELLED:
98             term_printf("cancelled\n");
99             break;
100         }
101     }
102 }
103