~jderose/ubuntu/raring/qemu/vde-again

« back to all changes in this revision

Viewing changes to migration.c

  • Committer: Bazaar Package Importer
  • Author(s): Riku Voipio, Josh Triplett, Riku Voipio
  • Date: 2009-07-29 13:28:05 UTC
  • mfrom: (1.4.1 upstream)
  • mto: (12.1.1 sid) (10.1.13 sid)
  • mto: This revision was merged to the branch mainline in revision 13.
  • Revision ID: james.westby@ubuntu.com-20090729132805-cau7rfexh7dawyb8
Tags: 0.10.50+git20090729-1
[ Josh Triplett ]
* Remove myself from Uploaders.

[ Riku Voipio ]
* new upstream RC version
* nuke all linux-user patches (applied upstream)
  06_exit_segfault
  12_signal_powerpc_support
  21_net_soopts
  30_syscall_ipc
  32_syscall_sysctl
  35_syscall_sockaddr
  48_signal_terminate
  55_unmux_socketcall
* nuke all other applied-upstream patches
  01_nostrip (better version upstream)
  07_i386_exec_name (can be reintroduced in debian/rules)
  50_linuxbios_isa_bios_ram (shouldn't be needed anymore)
  51_linuxbios_piix_ram_size (applied)
  56_dhcp (crap)
  60_ppc_ld (reintroduce if needed)
  64_ppc_asm_constraints (ditto)
  66_tls_ld.patch (ditto)
  81_compile_dtb.patch (applied upstream)
  82_qemu-img_decimal (ditto)
* move to git
* simplify build rules
* Correct my email address

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 
14
14
#include "qemu-common.h"
15
15
#include "migration.h"
16
 
#include "console.h"
 
16
#include "monitor.h"
17
17
#include "buffered_file.h"
18
18
#include "sysemu.h"
19
19
#include "block.h"
48
48
        fprintf(stderr, "unknown migration protocol: %s\n", uri);
49
49
}
50
50
 
51
 
void do_migrate(int detach, const char *uri)
 
51
void do_migrate(Monitor *mon, int detach, const char *uri)
52
52
{
53
53
    MigrationState *s = NULL;
54
54
    const char *p;
60
60
        s = exec_start_outgoing_migration(p, max_throttle, detach);
61
61
#endif
62
62
    else
63
 
        term_printf("unknown migration protocol: %s\n", uri);
 
63
        monitor_printf(mon, "unknown migration protocol: %s\n", uri);
64
64
 
65
65
    if (s == NULL)
66
 
        term_printf("migration failed\n");
 
66
        monitor_printf(mon, "migration failed\n");
67
67
    else {
68
68
        if (current_migration)
69
69
            current_migration->release(current_migration);
72
72
    }
73
73
}
74
74
 
75
 
void do_migrate_cancel(void)
 
75
void do_migrate_cancel(Monitor *mon)
76
76
{
77
77
    MigrationState *s = current_migration;
78
78
 
80
80
        s->cancel(s);
81
81
}
82
82
 
83
 
void do_migrate_set_speed(const char *value)
 
83
void do_migrate_set_speed(Monitor *mon, const char *value)
84
84
{
85
85
    double d;
86
86
    char *ptr;
 
87
    FdMigrationState *s;
87
88
 
88
89
    d = strtod(value, &ptr);
89
90
    switch (*ptr) {
98
99
    }
99
100
 
100
101
    max_throttle = (uint32_t)d;
101
 
}
 
102
    s = migrate_to_fms(current_migration);
102
103
 
103
 
void do_info_migrate(void)
104
 
{
105
 
    MigrationState *s = current_migration;
 
104
    if (s) {
 
105
        qemu_file_set_rate_limit(s->file, max_throttle);
 
106
    }
106
107
    
 
108
}
 
109
 
 
110
/* amount of nanoseconds we are willing to wait for migration to be down.
 
111
 * the choice of nanoseconds is because it is the maximum resolution that
 
112
 * get_clock() can achieve. It is an internal measure. All user-visible
 
113
 * units must be in seconds */
 
114
static uint64_t max_downtime = 30000000;
 
115
 
 
116
uint64_t migrate_max_downtime(void)
 
117
{
 
118
    return max_downtime;
 
119
}
 
120
 
 
121
void do_migrate_set_downtime(Monitor *mon, const char *value)
 
122
{
 
123
    char *ptr;
 
124
    double d;
 
125
 
 
126
    d = strtod(value, &ptr);
 
127
    if (!strcmp(ptr,"ms")) {
 
128
        d *= 1000000;
 
129
    } else if (!strcmp(ptr,"us")) {
 
130
        d *= 1000;
 
131
    } else if (!strcmp(ptr,"ns")) {
 
132
    } else {
 
133
        /* all else considered to be seconds */
 
134
        d *= 1000000000;
 
135
    }
 
136
 
 
137
    max_downtime = (uint64_t)d;
 
138
}
 
139
 
 
140
void do_info_migrate(Monitor *mon)
 
141
{
 
142
    MigrationState *s = current_migration;
 
143
 
107
144
    if (s) {
108
 
        term_printf("Migration status: ");
 
145
        monitor_printf(mon, "Migration status: ");
109
146
        switch (s->get_status(s)) {
110
147
        case MIG_STATE_ACTIVE:
111
 
            term_printf("active\n");
 
148
            monitor_printf(mon, "active\n");
 
149
            monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n", ram_bytes_transferred() >> 10);
 
150
            monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n", ram_bytes_remaining() >> 10);
 
151
            monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n", ram_bytes_total() >> 10);
112
152
            break;
113
153
        case MIG_STATE_COMPLETED:
114
 
            term_printf("completed\n");
 
154
            monitor_printf(mon, "completed\n");
115
155
            break;
116
156
        case MIG_STATE_ERROR:
117
 
            term_printf("failed\n");
 
157
            monitor_printf(mon, "failed\n");
118
158
            break;
119
159
        case MIG_STATE_CANCELLED:
120
 
            term_printf("cancelled\n");
 
160
            monitor_printf(mon, "cancelled\n");
121
161
            break;
122
162
        }
123
163
    }
125
165
 
126
166
/* shared migration helpers */
127
167
 
 
168
void migrate_fd_monitor_suspend(FdMigrationState *s)
 
169
{
 
170
    s->mon_resume = cur_mon;
 
171
    if (monitor_suspend(cur_mon) == 0)
 
172
        dprintf("suspending monitor\n");
 
173
    else
 
174
        monitor_printf(cur_mon, "terminal does not allow synchronous "
 
175
                       "migration, continuing detached\n");
 
176
}
 
177
 
128
178
void migrate_fd_error(FdMigrationState *s)
129
179
{
130
180
    dprintf("setting error state\n");
145
195
        close(s->fd);
146
196
 
147
197
    /* Don't resume monitor until we've flushed all of the buffers */
148
 
    if (s->detach == 2) {
149
 
        monitor_resume();
150
 
        s->detach = 0;
151
 
    }
 
198
    if (s->mon_resume)
 
199
        monitor_resume(s->mon_resume);
152
200
 
153
201
    s->fd = -1;
154
202
}
213
261
    dprintf("iterate\n");
214
262
    if (qemu_savevm_state_iterate(s->file) == 1) {
215
263
        int state;
 
264
        int old_vm_running = vm_running;
 
265
 
216
266
        dprintf("done iterating\n");
217
267
        vm_stop(0);
218
268
 
 
269
        qemu_aio_flush();
219
270
        bdrv_flush_all();
220
271
        if ((qemu_savevm_state_complete(s->file)) < 0) {
221
 
            vm_start();
 
272
            if (old_vm_running) {
 
273
                vm_start();
 
274
            }
222
275
            state = MIG_STATE_ERROR;
223
276
        } else {
224
277
            state = MIG_STATE_COMPLETED;
283
336
int migrate_fd_close(void *opaque)
284
337
{
285
338
    FdMigrationState *s = opaque;
 
339
 
 
340
    qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
286
341
    return s->close(s);
287
342
}