~ubuntu-branches/ubuntu/precise/qemu-kvm/precise

« back to all changes in this revision

Viewing changes to savevm.c

  • Committer: Serge Hallyn
  • Date: 2011-10-19 07:37:43 UTC
  • mfrom: (1.2.7)
  • Revision ID: serge.hallyn@ubuntu.com-20111019073743-7i7n9irsxlm38wic
Tags: 0.15.0+noroms-0ubuntu1
* New upstream release
* Remaining changes from upstream:
  - removed all binary roms and tests/pi_10.com
* Removed Detect-and-use-GCC-atomic-builtins-for-locking.patch - non-NPTL
  implementations were removed with commit
  02615337ef295443daa03233e492194e289a807e
* Drop spice-qxl-locking-fix-for-qemu-kvm.patch - should be unnecessary
  as of commit 196a778428989217b82de042725dc8eb29c8f8d8
* drop patches applied upstream:
  - CVE-2011-1751.diff
  - virtio-guard-against-negative-vq-notifies-CVE-2011-2512.diff
  - CVE-2011-2527.patch
  - fix-pa-configure.patch
* Refreshed the remaining patches:
  - larger_default_ram_size.patch
  - CVE-2011-2212-virtqueue-indirect-overflow.patch
  - qemuifup-fix-paths.patch
  - vpc.patch
* e1000-Dont-set-the-Capabilities-List-bit.patch - switched to the
  cherrypicked upstream patch (as the source file changed quite a bit,
  and the hand-ported patch backported to 0.14.1 does not apply).
* Drop qemu-kvm-spice (all changes from 0.14.1+noroms-0ubuntu7), it will
  need its own source package (LP: #878162)

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 */
24
24
#include <unistd.h>
25
25
#include <fcntl.h>
26
 
#include <signal.h>
27
26
#include <time.h>
28
27
#include <errno.h>
29
28
#include <sys/time.h>
82
81
#include "migration.h"
83
82
#include "qemu_socket.h"
84
83
#include "qemu-queue.h"
 
84
#include "cpus.h"
85
85
 
86
86
#define SELF_ANNOUNCE_ROUNDS 5
87
87
 
137
137
 
138
138
    if (--count) {
139
139
        /* delay 50ms, 150ms, 250ms, ... */
140
 
        qemu_mod_timer(timer, qemu_get_clock(rt_clock) +
 
140
        qemu_mod_timer(timer, qemu_get_clock_ms(rt_clock) +
141
141
                       50 + (SELF_ANNOUNCE_ROUNDS - count - 1) * 100);
142
142
    } else {
143
143
            qemu_del_timer(timer);
148
148
void qemu_announce_self(void)
149
149
{
150
150
        static QEMUTimer *timer;
151
 
        timer = qemu_new_timer(rt_clock, qemu_announce_self_once, &timer);
 
151
        timer = qemu_new_timer_ms(rt_clock, qemu_announce_self_once, &timer);
152
152
        qemu_announce_self_once(&timer);
153
153
}
154
154
 
194
194
    ssize_t len;
195
195
 
196
196
    do {
197
 
        len = recv(s->fd, (void *)buf, size, 0);
 
197
        len = qemu_recv(s->fd, buf, size, 0);
198
198
    } while (len == -1 && socket_error() == EINTR);
199
199
 
200
200
    if (len == -1)
882
882
    .put  = put_uint32,
883
883
};
884
884
 
 
885
/* 32 bit uint. See that the received value is the same than the one
 
886
   in the field */
 
887
 
 
888
static int get_uint32_equal(QEMUFile *f, void *pv, size_t size)
 
889
{
 
890
    uint32_t *v = pv;
 
891
    uint32_t v2;
 
892
    qemu_get_be32s(f, &v2);
 
893
 
 
894
    if (*v == v2) {
 
895
        return 0;
 
896
    }
 
897
    return -EINVAL;
 
898
}
 
899
 
 
900
const VMStateInfo vmstate_info_uint32_equal = {
 
901
    .name = "uint32 equal",
 
902
    .get  = get_uint32_equal,
 
903
    .put  = put_uint32,
 
904
};
 
905
 
885
906
/* 64 bit unsigned int */
886
907
 
887
908
static int get_uint64(QEMUFile *f, void *pv, size_t size)
903
924
    .put  = put_uint64,
904
925
};
905
926
 
906
 
/* 64 bit linux kernel unsigned int */
907
 
 
908
 
#ifdef __linux__
909
 
static int get_u64(QEMUFile *f, void *pv, size_t size)
910
 
{
911
 
    uint64_t *v = pv;
912
 
    qemu_get_be64s(f, v);
913
 
    return 0;
914
 
}
915
 
 
916
 
static void put_u64(QEMUFile *f, void *pv, size_t size)
917
 
{
918
 
    uint64_t *v = pv;
919
 
    qemu_put_be64s(f, v);
920
 
}
921
 
 
922
 
const VMStateInfo vmstate_info_u64 = {
923
 
    .name = "__u64",
924
 
    .get  = get_u64,
925
 
    .put  = put_u64,
926
 
};
927
 
#endif /* __linux__ */
928
 
 
929
927
/* 8 bit int. See that the received value is the same than the one
930
928
   in the field */
931
929
 
1009
1007
};
1010
1008
 
1011
1009
/* unused buffers: space that was used for some fields that are
1012
 
   not usefull anymore */
 
1010
   not useful anymore */
1013
1011
 
1014
1012
static int get_unused_buffer(QEMUFile *f, void *pv, size_t size)
1015
1013
{
1331
1329
                n_elems = field->num;
1332
1330
            } else if (field->flags & VMS_VARRAY_INT32) {
1333
1331
                n_elems = *(int32_t *)(opaque+field->num_offset);
 
1332
            } else if (field->flags & VMS_VARRAY_UINT32) {
 
1333
                n_elems = *(uint32_t *)(opaque+field->num_offset);
1334
1334
            } else if (field->flags & VMS_VARRAY_UINT16) {
1335
1335
                n_elems = *(uint16_t *)(opaque+field->num_offset);
 
1336
            } else if (field->flags & VMS_VARRAY_UINT8) {
 
1337
                n_elems = *(uint8_t *)(opaque+field->num_offset);
1336
1338
            }
1337
1339
            if (field->flags & VMS_POINTER) {
1338
1340
                base_addr = *(void **)base_addr + field->start;
1393
1395
                n_elems = *(int32_t *)(opaque+field->num_offset);
1394
1396
            } else if (field->flags & VMS_VARRAY_UINT16) {
1395
1397
                n_elems = *(uint16_t *)(opaque+field->num_offset);
 
1398
            } else if (field->flags & VMS_VARRAY_UINT8) {
 
1399
                n_elems = *(uint8_t *)(opaque+field->num_offset);
1396
1400
            }
1397
1401
            if (field->flags & VMS_POINTER) {
1398
1402
                base_addr = *(void **)base_addr + field->start;
1598
1602
    int ret;
1599
1603
 
1600
1604
    saved_vm_running = vm_running;
1601
 
    vm_stop(0);
 
1605
    vm_stop(VMSTOP_SAVEVM);
1602
1606
 
1603
1607
    if (qemu_savevm_state_blocked(mon)) {
1604
1608
        ret = -EINVAL;
1927
1931
    }
1928
1932
 
1929
1933
    saved_vm_running = vm_running;
1930
 
    vm_stop(0);
 
1934
    vm_stop(VMSTOP_SAVEVM);
1931
1935
 
1932
1936
    memset(sn, 0, sizeof(*sn));
1933
1937
 
1941
1945
    sn->date_sec = tv.tv_sec;
1942
1946
    sn->date_nsec = tv.tv_usec * 1000;
1943
1947
#endif
1944
 
    sn->vm_clock_nsec = qemu_get_clock(vm_clock);
 
1948
    sn->vm_clock_nsec = qemu_get_clock_ns(vm_clock);
1945
1949
 
1946
1950
    if (name) {
1947
1951
        ret = bdrv_snapshot_find(bs, old_sn, name);
2019
2023
    if (ret < 0) {
2020
2024
        return ret;
2021
2025
    } else if (sn.vm_state_size == 0) {
 
2026
        error_report("This is a disk-only snapshot. Revert to it offline "
 
2027
            "using qemu-img.");
2022
2028
        return -EINVAL;
2023
2029
    }
2024
2030
 
2067
2073
        return -EINVAL;
2068
2074
    }
2069
2075
 
 
2076
    qemu_system_reset(VMRESET_SILENT);
2070
2077
    ret = qemu_loadvm_state(f);
2071
2078
 
2072
2079
    qemu_fclose(f);