~ubuntu-branches/ubuntu/vivid/qemu/vivid

« back to all changes in this revision

Viewing changes to migration.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2014-02-25 22:31:43 UTC
  • mfrom: (1.8.5)
  • Revision ID: package-import@ubuntu.com-20140225223143-odhqxfc60wxrjl15
Tags: 2.0.0~rc1+dfsg-0ubuntu1
* Merge 2.0.0-rc1
* debian/rules: consolidate ppc filter entries.
* Move qemu-system-arch64 into qemu-system-arm
* debian/patches/define-trusty-machine-type.patch: define a trusty machine
  type, currently the same as pc-i440fx-2.0, to put is in a better position
  to enable live migrations from trusty onward.  (LP: #1294823)
* debian/control: build-dep on libfdt >= 1.4.0  (LP: #1295072)
* Merge latest upstream git to commit dc9528f
* Debian/rules:
  - remove -enable-uname-release=2.6.32
  - don't make the aarch64 target Ubuntu-specific.
* Remove patches which are now upstream:
  - fix-smb-security-share.patch
  - slirp-smb-redirect-port-445-too.patch 
  - linux-user-Implement-sendmmsg-syscall.patch (better version is upstream)
  - signal-added-a-wrapper-for-sigprocmask-function.patch
  - ubuntu/signal-sigsegv-protection-on-do_sigprocmask.patch
  - ubuntu/Don-t-block-SIGSEGV-at-more-places.patch
  - ubuntu/ppc-force-cpu-threads-count-to-be-power-of-2.patch
* add link for /usr/share/qemu/bios-256k.bin
* Remove all linaro patches.
* Remove all arm64/ patches.  Many but not all are upstream.
* Remove CVE-2013-4377.patch which is upstream.
* debian/control-in: don't make qemu-system-aarch64 ubuntu-specific

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include "qmp-commands.h"
27
27
#include "trace.h"
28
28
 
29
 
//#define DEBUG_MIGRATION
30
 
 
31
 
#ifdef DEBUG_MIGRATION
32
 
#define DPRINTF(fmt, ...) \
33
 
    do { printf("migration: " fmt, ## __VA_ARGS__); } while (0)
34
 
#else
35
 
#define DPRINTF(fmt, ...) \
36
 
    do { } while (0)
37
 
#endif
38
 
 
39
29
enum {
40
30
    MIG_STATE_ERROR = -1,
41
31
    MIG_STATE_NONE,
42
32
    MIG_STATE_SETUP,
 
33
    MIG_STATE_CANCELLING,
43
34
    MIG_STATE_CANCELLED,
44
35
    MIG_STATE_ACTIVE,
45
36
    MIG_STATE_COMPLETED,
81
72
    if (strstart(uri, "tcp:", &p))
82
73
        tcp_start_incoming_migration(p, errp);
83
74
#ifdef CONFIG_RDMA
84
 
    else if (strstart(uri, "x-rdma:", &p))
 
75
    else if (strstart(uri, "rdma:", &p))
85
76
        rdma_start_incoming_migration(p, errp);
86
77
#endif
87
78
#if !defined(WIN32)
100
91
static void process_incoming_migration_co(void *opaque)
101
92
{
102
93
    QEMUFile *f = opaque;
 
94
    Error *local_err = NULL;
103
95
    int ret;
104
96
 
105
97
    ret = qemu_loadvm_state(f);
106
98
    qemu_fclose(f);
 
99
    free_xbzrle_decoded_buf();
107
100
    if (ret < 0) {
108
101
        fprintf(stderr, "load of migration failed\n");
109
102
        exit(EXIT_FAILURE);
110
103
    }
111
104
    qemu_announce_self();
112
 
    DPRINTF("successfully loaded vm state\n");
113
105
 
114
106
    bdrv_clear_incoming_migration_all();
115
107
    /* Make sure all file formats flush their mutable metadata */
116
 
    bdrv_invalidate_cache_all();
 
108
    bdrv_invalidate_cache_all(&local_err);
 
109
    if (local_err) {
 
110
        qerror_report_err(local_err);
 
111
        error_free(local_err);
 
112
        exit(EXIT_FAILURE);
 
113
    }
117
114
 
118
115
    if (autostart) {
119
116
        vm_start();
196
193
        info->has_total_time = false;
197
194
        break;
198
195
    case MIG_STATE_ACTIVE:
 
196
    case MIG_STATE_CANCELLING:
199
197
        info->has_status = true;
200
198
        info->status = g_strdup("active");
201
199
        info->has_total_time = true;
282
280
 
283
281
/* shared migration helpers */
284
282
 
 
283
static void migrate_set_state(MigrationState *s, int old_state, int new_state)
 
284
{
 
285
    if (atomic_cmpxchg(&s->state, old_state, new_state) == new_state) {
 
286
        trace_migrate_set_state(new_state);
 
287
    }
 
288
}
 
289
 
285
290
static void migrate_fd_cleanup(void *opaque)
286
291
{
287
292
    MigrationState *s = opaque;
290
295
    s->cleanup_bh = NULL;
291
296
 
292
297
    if (s->file) {
293
 
        DPRINTF("closing file\n");
 
298
        trace_migrate_fd_cleanup();
294
299
        qemu_mutex_unlock_iothread();
295
300
        qemu_thread_join(&s->thread);
296
301
        qemu_mutex_lock_iothread();
303
308
 
304
309
    if (s->state != MIG_STATE_COMPLETED) {
305
310
        qemu_savevm_state_cancel();
 
311
        if (s->state == MIG_STATE_CANCELLING) {
 
312
            migrate_set_state(s, MIG_STATE_CANCELLING, MIG_STATE_CANCELLED);
 
313
        }
306
314
    }
307
315
 
308
316
    notifier_list_notify(&migration_state_notifiers, s);
309
317
}
310
318
 
311
 
static void migrate_set_state(MigrationState *s, int old_state, int new_state)
312
 
{
313
 
    if (atomic_cmpxchg(&s->state, old_state, new_state) == new_state) {
314
 
        trace_migrate_set_state(new_state);
315
 
    }
316
 
}
317
 
 
318
319
void migrate_fd_error(MigrationState *s)
319
320
{
320
 
    DPRINTF("setting error state\n");
 
321
    trace_migrate_fd_error();
321
322
    assert(s->file == NULL);
322
323
    s->state = MIG_STATE_ERROR;
323
324
    trace_migrate_set_state(MIG_STATE_ERROR);
326
327
 
327
328
static void migrate_fd_cancel(MigrationState *s)
328
329
{
329
 
    DPRINTF("cancelling migration\n");
 
330
    int old_state ;
 
331
    trace_migrate_fd_cancel();
330
332
 
331
 
    migrate_set_state(s, s->state, MIG_STATE_CANCELLED);
 
333
    do {
 
334
        old_state = s->state;
 
335
        if (old_state != MIG_STATE_SETUP && old_state != MIG_STATE_ACTIVE) {
 
336
            break;
 
337
        }
 
338
        migrate_set_state(s, old_state, MIG_STATE_CANCELLING);
 
339
    } while (s->state != MIG_STATE_CANCELLING);
332
340
}
333
341
 
334
342
void add_migration_state_change_notifier(Notifier *notify)
405
413
    params.blk = has_blk && blk;
406
414
    params.shared = has_inc && inc;
407
415
 
408
 
    if (s->state == MIG_STATE_ACTIVE || s->state == MIG_STATE_SETUP) {
 
416
    if (s->state == MIG_STATE_ACTIVE || s->state == MIG_STATE_SETUP ||
 
417
        s->state == MIG_STATE_CANCELLING) {
409
418
        error_set(errp, QERR_MIGRATION_ACTIVE);
410
419
        return;
411
420
    }
424
433
    if (strstart(uri, "tcp:", &p)) {
425
434
        tcp_start_outgoing_migration(s, p, &local_err);
426
435
#ifdef CONFIG_RDMA
427
 
    } else if (strstart(uri, "x-rdma:", &p)) {
 
436
    } else if (strstart(uri, "rdma:", &p)) {
428
437
        rdma_start_outgoing_migration(s, p, &local_err);
429
438
#endif
430
439
#if !defined(WIN32)
437
446
#endif
438
447
    } else {
439
448
        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol");
 
449
        s->state = MIG_STATE_ERROR;
440
450
        return;
441
451
    }
442
452
 
455
465
void qmp_migrate_set_cache_size(int64_t value, Error **errp)
456
466
{
457
467
    MigrationState *s = migrate_get_current();
 
468
    int64_t new_size;
458
469
 
459
470
    /* Check for truncation */
460
471
    if (value != (size_t)value) {
463
474
        return;
464
475
    }
465
476
 
466
 
    s->xbzrle_cache_size = xbzrle_cache_resize(value);
 
477
    /* Cache should not be larger than guest ram size */
 
478
    if (value > ram_bytes_total()) {
 
479
        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
 
480
                  "exceeds guest ram size ");
 
481
        return;
 
482
    }
 
483
 
 
484
    new_size = xbzrle_cache_resize(value);
 
485
    if (new_size < 0) {
 
486
        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
 
487
                  "is smaller than page size");
 
488
        return;
 
489
    }
 
490
 
 
491
    s->xbzrle_cache_size = new_size;
467
492
}
468
493
 
469
494
int64_t qmp_query_migrate_cache_size(Error **errp)
502
527
 
503
528
    s = migrate_get_current();
504
529
 
505
 
    return s->enabled_capabilities[MIGRATION_CAPABILITY_X_RDMA_PIN_ALL];
 
530
    return s->enabled_capabilities[MIGRATION_CAPABILITY_RDMA_PIN_ALL];
506
531
}
507
532
 
508
533
bool migrate_auto_converge(void)
553
578
    int64_t start_time = initial_time;
554
579
    bool old_vm_running = false;
555
580
 
556
 
    DPRINTF("beginning savevm\n");
557
581
    qemu_savevm_state_begin(s->file, &s->params);
558
582
 
559
583
    s->setup_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) - setup_start;
560
584
    migrate_set_state(s, MIG_STATE_SETUP, MIG_STATE_ACTIVE);
561
585
 
562
 
    DPRINTF("setup complete\n");
563
 
 
564
586
    while (s->state == MIG_STATE_ACTIVE) {
565
587
        int64_t current_time;
566
588
        uint64_t pending_size;
567
589
 
568
590
        if (!qemu_file_rate_limit(s->file)) {
569
 
            DPRINTF("iterate\n");
570
591
            pending_size = qemu_savevm_state_pending(s->file, max_size);
571
 
            DPRINTF("pending size %" PRIu64 " max %" PRIu64 "\n",
572
 
                    pending_size, max_size);
 
592
            trace_migrate_pending(pending_size, max_size);
573
593
            if (pending_size && pending_size >= max_size) {
574
594
                qemu_savevm_state_iterate(s->file);
575
595
            } else {
576
596
                int ret;
577
597
 
578
 
                DPRINTF("done iterating\n");
579
598
                qemu_mutex_lock_iothread();
580
599
                start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
581
600
                qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
583
602
 
584
603
                ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
585
604
                if (ret >= 0) {
586
 
                    qemu_file_set_rate_limit(s->file, INT_MAX);
 
605
                    qemu_file_set_rate_limit(s->file, INT64_MAX);
587
606
                    qemu_savevm_state_complete(s->file);
588
607
                }
589
608
                qemu_mutex_unlock_iothread();
614
633
            s->mbps = time_spent ? (((double) transferred_bytes * 8.0) /
615
634
                    ((double) time_spent / 1000.0)) / 1000.0 / 1000.0 : -1;
616
635
 
617
 
            DPRINTF("transferred %" PRIu64 " time_spent %" PRIu64
618
 
                    " bandwidth %g max_size %" PRId64 "\n",
619
 
                    transferred_bytes, time_spent, bandwidth, max_size);
 
636
            trace_migrate_transferred(transferred_bytes, time_spent,
 
637
                                      bandwidth, max_size);
620
638
            /* if we haven't sent anything, we don't want to recalculate
621
639
               10000 is a small enough number for our purposes */
622
640
            if (s->dirty_bytes_rate && transferred_bytes > 10000) {
665
683
    /* Notify before starting migration thread */
666
684
    notifier_list_notify(&migration_state_notifiers, s);
667
685
 
668
 
    qemu_thread_create(&s->thread, migration_thread, s,
 
686
    qemu_thread_create(&s->thread, "migration", migration_thread, s,
669
687
                       QEMU_THREAD_JOINABLE);
670
688
}