]> git.proxmox.com Git - pve-qemu-kvm.git/commitdiff
fix vma reader
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 13 Dec 2012 11:03:47 +0000 (12:03 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 13 Dec 2012 11:42:14 +0000 (12:42 +0100)
Avoid integer overflow on restore, add verbose flag for restore.

bump version to 1.3-9

Makefile
debian/changelog
debian/patches/0003-add-backup-related-monitor-commands.patch
debian/patches/0004-introduce-new-vma-archive-format.patch
debian/patches/0005-add-regression-tests-for-backup.patch
debian/patches/0006-add-vm-state-to-backups.patch

index 9d4fb408371eb05f3d2115ab9ff5eb00e9f175ee..13b9122320a78816ed8489256f47681d9f091114 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,8 @@
-RELEASE=2.2
+RELEASE=2.3
 
 # also update debian/changelog
 KVMVER=1.3
-KVMPKGREL=8
+KVMPKGREL=9
 
 KVMPACKAGE=pve-qemu-kvm
 KVMDIR=qemu-kvm
index 8469aa389a7c09e30711624b846d1392b120b72a..8dfdb993f84573a13e0d178af8191c502a73cbc0 100644 (file)
@@ -1,3 +1,9 @@
+pve-qemu-kvm (1.3-9) unstable; urgency=low
+
+  * fixes for vma-reader
+
+ -- Proxmox Support Team <support@proxmox.com>  Thu, 13 Dec 2012 12:08:12 +0100
+
 pve-qemu-kvm (1.3-8) unstable; urgency=low
 
   * re-enable balloon stats
index 9e12a3db8532dc45eb472be71ed349e52ef48430..70efeff06fb79fe0ef4995c1d347325a63264315 100644 (file)
@@ -1,9 +1,9 @@
-From 42ef2313a00a615414c6728a32febe650715769a Mon Sep 17 00:00:00 2001
+From 205f75f449050565262aff7e4fe245e70a659483 Mon Sep 17 00:00:00 2001
 From: Dietmar Maurer <dietmar@proxmox.com>
 Date: Tue, 13 Nov 2012 11:27:56 +0100
 Subject: [PATCH v3 3/6] add backup related monitor commands
 
-We use a generic BackupDriver struct to encaplulated all archive format
+We use a generic BackupDriver struct to encapsulate all archive format
 related function.
 
 Another option would be to simply dump <devid,cluster_num,cluster_data> to
@@ -608,7 +608,7 @@ index c0e32d6..85cf47e 100644
          .args_type  = "",
          .params     = "",
 diff --git a/qapi-schema.json b/qapi-schema.json
-index 5dfa052..71e0ed9 100644
+index 5dfa052..bcc70b1 100644
 --- a/qapi-schema.json
 +++ b/qapi-schema.json
 @@ -358,6 +358,39 @@
@@ -620,7 +620,7 @@ index 5dfa052..71e0ed9 100644
 +# Detailed backup status.
 +#
 +# @status: #optional string describing the current backup status.
-+#          Tthis can be 'active', 'done', 'error'. If this field is not
++#          This can be 'active', 'done', 'error'. If this field is not
 +#          returned, no backup process has been initiated
 +#
 +# @errmsg: #optional error message (only returned if status is 'error')
index ce40f344946ccaf9443fec5dcacb69ff573b9b3c..2d96fe151e20284ee12464bda5c65e64dcc46de9 100644 (file)
@@ -1,4 +1,4 @@
-From e156b88f194c269e708bf604982db3927f0dbc21 Mon Sep 17 00:00:00 2001
+From a259716ad384f2d23992b89f714497e2dc8b7336 Mon Sep 17 00:00:00 2001
 From: Dietmar Maurer <dietmar@proxmox.com>
 Date: Tue, 13 Nov 2012 11:11:38 +0100
 Subject: [PATCH v3 4/6] introduce new vma archive format
@@ -11,11 +11,11 @@ Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
  Makefile.objs           |    2 +-
  blockdev.c              |    6 +-
  docs/specs/vma_spec.txt |   24 ++
- vma-reader.c            |  776 +++++++++++++++++++++++++++++++++++++++
+ vma-reader.c            |  801 +++++++++++++++++++++++++++++++++++++++++
  vma-writer.c            |  920 +++++++++++++++++++++++++++++++++++++++++++++++
- vma.c                   |  556 ++++++++++++++++++++++++++++
- vma.h                   |  145 ++++++++
- 8 files changed, 2428 insertions(+), 4 deletions(-)
+ vma.c                   |  558 ++++++++++++++++++++++++++++
+ vma.h                   |  146 ++++++++
+ 8 files changed, 2456 insertions(+), 4 deletions(-)
  create mode 100644 docs/specs/vma_spec.txt
  create mode 100644 vma-reader.c
  create mode 100644 vma-writer.c
@@ -114,10 +114,10 @@ index 0000000..052c629
 +
 diff --git a/vma-reader.c b/vma-reader.c
 new file mode 100644
-index 0000000..b05d7da
+index 0000000..b6a550b
 --- /dev/null
 +++ b/vma-reader.c
-@@ -0,0 +1,776 @@
+@@ -0,0 +1,801 @@
 +/*
 + * VMA: Virtual Machine Archive
 + *
@@ -171,6 +171,11 @@ index 0000000..b05d7da
 +    GList *cdata_list;
 +    guint8 vmstate_stream;
 +    uint32_t vmstate_clusters;
++    /* to show restore percentage if run with -v */
++    time_t start_time;
++    int64_t cluster_count;
++    int64_t clusters_read;
++    int clusters_read_per;
 +};
 +
 +static guint
@@ -576,6 +581,8 @@ index 0000000..b05d7da
 +    vmar->rstate[dev_id].bitmap_size = bitmap_size;
 +    vmar->rstate[dev_id].bitmap = g_new0(unsigned long, bitmap_size);
 +
++    vmar->cluster_count += size/VMA_CLUSTER_SIZE;
++
 +    return 0;
 +}
 +
@@ -642,7 +649,8 @@ index 0000000..b05d7da
 +    return 0;
 +}
 +static int restore_extent(VmaReader *vmar, unsigned char *buf,
-+                          int extent_size, int vmstate_fd, Error **errp)
++                          int extent_size, int vmstate_fd, 
++                          bool verbose, Error **errp)
 +{
 +    assert(vmar);
 +    assert(buf);
@@ -653,8 +661,8 @@ index 0000000..b05d7da
 +
 +    for (i = 0; i < VMA_BLOCKS_PER_EXTENT; i++) {
 +        uint64_t block_info = GUINT64_FROM_BE(ehead->blockinfo[i]);
-+        uint32_t cluster_num = block_info &  0xffffffff;
-+        uint8_t dev_id = (block_info >> 32) &  0xff;
++        uint64_t cluster_num = block_info & 0xffffffff;
++        uint8_t dev_id = (block_info >> 32) & 0xff;
 +        uint16_t mask = block_info >> (32+16);
 +        int64_t max_sector;
 +
@@ -673,7 +681,7 @@ index 0000000..b05d7da
 +            }
 +
 +            if (vma_reader_get_bitmap(rstate, cluster_num)) {
-+                error_setg(errp, "found duplicated cluster %d for stream %s",
++                error_setg(errp, "found duplicated cluster %zd for stream %s",
 +                          cluster_num, vmar->devinfo[dev_id].devname);
 +                return -1;
 +            }
@@ -689,6 +697,20 @@ index 0000000..b05d7da
 +            vmar->vmstate_clusters++;
 +        }
 +
++        vmar->clusters_read++;
++
++        if (verbose) {
++            time_t duration = time(NULL) - vmar->start_time;
++            int percent = (vmar->clusters_read*100)/vmar->cluster_count;
++            if (percent != vmar->clusters_read_per) {
++                printf("progress %d%% (read %zd bytes, duration %zd sec)\n", 
++                       percent, vmar->clusters_read*VMA_CLUSTER_SIZE,
++                       duration);
++                fflush(stdout);
++                vmar->clusters_read_per = percent;
++            }
++        }
++
 +        /* try to write whole clusters to speedup restore */
 +        if (mask == 0xffff) {
 +            if ((start + VMA_CLUSTER_SIZE) > extent_size) {
@@ -753,7 +775,7 @@ index 0000000..b05d7da
 +
 +                } else {
 +
-+                    if (rstate->write_zeroes & (end_sector > sector_num)) {
++                    if (rstate->write_zeroes && (end_sector > sector_num)) {
 +                        /* Todo: use bdrv_co_write_zeroes (but that need to
 +                         * be run inside coroutine?)
 +                         */
@@ -779,7 +801,8 @@ index 0000000..b05d7da
 +    return 0;
 +}
 +
-+int vma_reader_restore(VmaReader *vmar, int vmstate_fd, Error **errp)
++int vma_reader_restore(VmaReader *vmar, int vmstate_fd, bool verbose,
++                     Error **errp)
 +{
 +    assert(vmar);
 +    assert(vmar->head_data);
@@ -790,6 +813,7 @@ index 0000000..b05d7da
 +    unsigned char md5sum[16];
 +    VmaHeader *h = (VmaHeader *)vmar->head_data;
 +
++    vmar->start_time = time(NULL);
 +
 +    while (1) {
 +        int bytes = full_read(vmar->fd, buf + buf_pos, sizeof(buf) - buf_pos);
@@ -844,7 +868,8 @@ index 0000000..b05d7da
 +            return -1;
 +        }
 +
-+        if (restore_extent(vmar, buf, extent_size, vmstate_fd, errp) < 0) {
++        if (restore_extent(vmar, buf, extent_size, vmstate_fd, verbose, 
++                           errp) < 0) {
 +            return -1;
 +        }
 +
@@ -1822,10 +1847,10 @@ index 0000000..c1e1afe
 +
 diff --git a/vma.c b/vma.c
 new file mode 100644
-index 0000000..64dde97
+index 0000000..8d6f32d
 --- /dev/null
 +++ b/vma.c
-@@ -0,0 +1,556 @@
+@@ -0,0 +1,558 @@
 +/*
 + * VMA: Virtual Machine Archive
 + *
@@ -1972,12 +1997,13 @@ index 0000000..64dde97
 +static int extract_content(int argc, char **argv)
 +{
 +    int c, ret = 0;
++    int verbose = 0;
 +    const char *filename;
 +    const char *dirname;
 +    const char *readmap = NULL;
 +
 +    for (;;) {
-+        c = getopt(argc, argv, "hr:");
++        c = getopt(argc, argv, "hvr:");
 +        if (c == -1) {
 +            break;
 +        }
@@ -1989,6 +2015,9 @@ index 0000000..64dde97
 +        case 'r':
 +            readmap = optarg;
 +            break;
++       case 'v':
++            verbose = 1;
++            break;
 +        default:
 +            help();
 +        }
@@ -2068,8 +2097,6 @@ index 0000000..64dde97
 +                        inbuf);
 +            }
 +
-+            printf("TEST %s %s\n", path, devname);
-+
 +            RestoreMap *map = g_new0(RestoreMap, 1);
 +            map->devname = g_strdup(devname);
 +            map->path = g_strdup(path);
@@ -2138,7 +2165,7 @@ index 0000000..64dde97
 +        }
 +    }
 +
-+    if (vma_reader_restore(vmar, vmstate_fd, &errp) < 0) {
++    if (vma_reader_restore(vmar, vmstate_fd, verbose, &errp) < 0) {
 +        g_error("restore failed - %s", error_get_pretty(errp));
 +    }
 +
@@ -2384,10 +2411,10 @@ index 0000000..64dde97
 +}
 diff --git a/vma.h b/vma.h
 new file mode 100644
-index 0000000..10800a1
+index 0000000..f30a2bc
 --- /dev/null
 +++ b/vma.h
-@@ -0,0 +1,145 @@
+@@ -0,0 +1,146 @@
 +/*
 + * VMA: Virtual Machine Archive
 + *
@@ -2530,7 +2557,8 @@ index 0000000..10800a1
 +int vma_reader_register_bs(VmaReader *vmar, guint8 dev_id,
 +                           BlockDriverState *bs, bool write_zeroes,
 +                           Error **errp);
-+int vma_reader_restore(VmaReader *vmar, int vmstate_fd, Error **errp);
++int vma_reader_restore(VmaReader *vmar, int vmstate_fd, bool verbose, 
++                     Error **errp);
 +
 +#endif /* BACKUP_VMA_H */
 -- 
index 5e7d758e62e7deb942ebdd416df15d583f7df694..785c7b29935d6826a580f31402892aa8850efe81 100644 (file)
@@ -1,4 +1,4 @@
-From 8b0a6a7bedcbfc846138c57c090ea3ada1e32505 Mon Sep 17 00:00:00 2001
+From bc2cfdba56c1a5071a1436384280d9b7f7501f12 Mon Sep 17 00:00:00 2001
 From: Dietmar Maurer <dietmar@proxmox.com>
 Date: Wed, 14 Nov 2012 09:57:04 +0100
 Subject: [PATCH v3 5/6] add regression tests for backup
@@ -52,7 +52,7 @@ index b60f0fb..cffbd22 100644
  -include $(wildcard tests/*.d)
 diff --git a/tests/backup-test.c b/tests/backup-test.c
 new file mode 100644
-index 0000000..c434c5f
+index 0000000..b14e9a0
 --- /dev/null
 +++ b/tests/backup-test.c
 @@ -0,0 +1,511 @@
@@ -317,7 +317,7 @@ index 0000000..c434c5f
 +        g_error("%s", error_get_pretty(errp));
 +    }
 +
-+    if (vma_reader_restore(vmar, -1, &errp) < 0) {
++    if (vma_reader_restore(vmar, -1, false, &errp) < 0) {
 +        g_error("restore failed - %s", error_get_pretty(errp));
 +    }
 +
index 752ef5adfe7c3ff0176b57289b3db83c1a9558ac..39cfe13bf0775630dd6129791075e001b347ccc3 100644 (file)
@@ -1,4 +1,4 @@
-From c07e6b278f0cdc3d386fb7878d5048195f565806 Mon Sep 17 00:00:00 2001
+From 936c3272e09bc60de51ef985f7ec651051f924a8 Mon Sep 17 00:00:00 2001
 From: Dietmar Maurer <dietmar@proxmox.com>
 Date: Thu, 29 Nov 2012 10:46:49 +0100
 Subject: [PATCH v3 6/6] add vm state to backups
@@ -271,7 +271,7 @@ index 600792f..e92bba9 100644
      if (error_is_set(&errp)) {
          monitor_printf(mon, "%s\n", error_get_pretty(errp));
 diff --git a/qapi-schema.json b/qapi-schema.json
-index 71e0ed9..2d7ecaa 100644
+index bcc70b1..2af4359 100644
 --- a/qapi-schema.json
 +++ b/qapi-schema.json
 @@ -1812,13 +1812,15 @@