Avoid integer overflow on restore, add verbose flag for restore.
bump version to 1.3-9
# also update debian/changelog
KVMVER=1.3
# also update debian/changelog
KVMVER=1.3
KVMPACKAGE=pve-qemu-kvm
KVMDIR=qemu-kvm
KVMPACKAGE=pve-qemu-kvm
KVMDIR=qemu-kvm
+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
pve-qemu-kvm (1.3-8) unstable; urgency=low
* re-enable balloon stats
-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
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
related function.
Another option would be to simply dump <devid,cluster_num,cluster_data> to
.args_type = "",
.params = "",
diff --git a/qapi-schema.json b/qapi-schema.json
.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 @@
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -358,6 +358,39 @@
+# Detailed backup status.
+#
+# @status: #optional string describing the current backup status.
+# 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')
+# returned, no backup process has been initiated
+#
+# @errmsg: #optional error message (only returned if status is 'error')
-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
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
Makefile.objs | 2 +-
blockdev.c | 6 +-
docs/specs/vma_spec.txt | 24 ++
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-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
create mode 100644 docs/specs/vma_spec.txt
create mode 100644 vma-reader.c
create mode 100644 vma-writer.c
+
diff --git a/vma-reader.c b/vma-reader.c
new file mode 100644
+
diff --git a/vma-reader.c b/vma-reader.c
new file mode 100644
--- /dev/null
+++ b/vma-reader.c
--- /dev/null
+++ b/vma-reader.c
+/*
+ * VMA: Virtual Machine Archive
+ *
+/*
+ * VMA: Virtual Machine Archive
+ *
+ GList *cdata_list;
+ guint8 vmstate_stream;
+ uint32_t vmstate_clusters;
+ 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;
+ vmar->rstate[dev_id].bitmap_size = bitmap_size;
+ vmar->rstate[dev_id].bitmap = g_new0(unsigned long, bitmap_size);
+
+ 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;
+}
+static int restore_extent(VmaReader *vmar, unsigned char *buf,
+ 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);
+{
+ assert(vmar);
+ assert(buf);
+
+ for (i = 0; i < VMA_BLOCKS_PER_EXTENT; i++) {
+ uint64_t block_info = GUINT64_FROM_BE(ehead->blockinfo[i]);
+
+ 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;
+
+ uint16_t mask = block_info >> (32+16);
+ int64_t max_sector;
+
+ }
+
+ if (vma_reader_get_bitmap(rstate, cluster_num)) {
+ }
+
+ 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;
+ }
+ cluster_num, vmar->devinfo[dev_id].devname);
+ return -1;
+ }
+ vmar->vmstate_clusters++;
+ }
+
+ 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) {
+ /* try to write whole clusters to speedup restore */
+ if (mask == 0xffff) {
+ if ((start + VMA_CLUSTER_SIZE) > extent_size) {
-+ 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?)
+ */
+ /* Todo: use bdrv_co_write_zeroes (but that need to
+ * be run inside coroutine?)
+ */
-+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);
+{
+ assert(vmar);
+ assert(vmar->head_data);
+ unsigned char md5sum[16];
+ VmaHeader *h = (VmaHeader *)vmar->head_data;
+
+ 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);
+
+ while (1) {
+ int bytes = full_read(vmar->fd, buf + buf_pos, sizeof(buf) - buf_pos);
-+ if (restore_extent(vmar, buf, extent_size, vmstate_fd, errp) < 0) {
++ if (restore_extent(vmar, buf, extent_size, vmstate_fd, verbose,
++ errp) < 0) {
+
diff --git a/vma.c b/vma.c
new file mode 100644
+
diff --git a/vma.c b/vma.c
new file mode 100644
--- /dev/null
+++ b/vma.c
--- /dev/null
+++ b/vma.c
+/*
+ * VMA: Virtual Machine Archive
+ *
+/*
+ * VMA: Virtual Machine Archive
+ *
+static int extract_content(int argc, char **argv)
+{
+ int c, ret = 0;
+static int extract_content(int argc, char **argv)
+{
+ int c, ret = 0;
+ const char *filename;
+ const char *dirname;
+ const char *readmap = NULL;
+
+ for (;;) {
+ 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;
+ }
+ if (c == -1) {
+ break;
+ }
+ case 'r':
+ readmap = optarg;
+ break;
+ case 'r':
+ readmap = optarg;
+ break;
++ case 'v':
++ verbose = 1;
++ break;
-+ printf("TEST %s %s\n", path, devname);
-+
+ RestoreMap *map = g_new0(RestoreMap, 1);
+ map->devname = g_strdup(devname);
+ map->path = g_strdup(path);
+ RestoreMap *map = g_new0(RestoreMap, 1);
+ map->devname = g_strdup(devname);
+ map->path = g_strdup(path);
-+ 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));
+ }
+
+ g_error("restore failed - %s", error_get_pretty(errp));
+ }
+
+}
diff --git a/vma.h b/vma.h
new file mode 100644
+}
diff --git a/vma.h b/vma.h
new file mode 100644
--- /dev/null
+++ b/vma.h
--- /dev/null
+++ b/vma.h
+/*
+ * VMA: Virtual Machine Archive
+ *
+/*
+ * VMA: Virtual Machine Archive
+ *
+int vma_reader_register_bs(VmaReader *vmar, guint8 dev_id,
+ BlockDriverState *bs, bool write_zeroes,
+ Error **errp);
+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 */
--
+
+#endif /* BACKUP_VMA_H */
--
-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
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
-include $(wildcard tests/*.d)
diff --git a/tests/backup-test.c b/tests/backup-test.c
new file mode 100644
-include $(wildcard tests/*.d)
diff --git a/tests/backup-test.c b/tests/backup-test.c
new file mode 100644
--- /dev/null
+++ b/tests/backup-test.c
@@ -0,0 +1,511 @@
--- /dev/null
+++ b/tests/backup-test.c
@@ -0,0 +1,511 @@
+ g_error("%s", error_get_pretty(errp));
+ }
+
+ 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));
+ }
+
+ g_error("restore failed - %s", error_get_pretty(errp));
+ }
+
-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
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
if (error_is_set(&errp)) {
monitor_printf(mon, "%s\n", error_get_pretty(errp));
diff --git a/qapi-schema.json b/qapi-schema.json
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 @@
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1812,13 +1812,15 @@