From 3f350e0d3bb3e685de4513de7e03da203bd669fb Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 7 Dec 2012 11:16:05 +0100 Subject: [PATCH] update backup patches --- Makefile | 2 +- debian/changelog | 8 +- ...001-RFC-Efficient-VM-backup-for-qemu.patch | 2 +- ...basic-backup-support-to-block-driver.patch | 2 +- ...-add-backup-related-monitor-commands.patch | 2 +- ...004-introduce-new-vma-archive-format.patch | 62 +++++--- ...0005-add-regression-tests-for-backup.patch | 2 +- .../0006-add-vm-state-to-backups.patch | 2 +- .../patches/implement-qemu-fopen-bdrv.patch | 90 ----------- debian/patches/load-state-from-blockdev.patch | 142 ------------------ debian/rules | 1 + 11 files changed, 56 insertions(+), 259 deletions(-) delete mode 100644 debian/patches/implement-qemu-fopen-bdrv.patch delete mode 100644 debian/patches/load-state-from-blockdev.patch diff --git a/Makefile b/Makefile index 56d9842..e684f62 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ RELEASE=2.2 # also update debian/changelog KVMVER=1.3 -KVMPKGREL=5 +KVMPKGREL=6 KVMPACKAGE=pve-qemu-kvm KVMDIR=qemu-kvm diff --git a/debian/changelog b/debian/changelog index 096c6b0..66b2db2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,8 +1,14 @@ +pve-qemu-kvm (1.3-6) unstable; urgency=low + + * include vma utility + + -- Proxmox Support Team Tue, 04 Dec 2012 10:49:54 +0100 + pve-qemu-kvm (1.3-5) unstable; urgency=low * update to qemu 1.3 final - * include fix-off-by-1-error-in-RAM-migration-code.patch + * include fix-off-by-1-error-in-RAM-migration-code.patch -- Proxmox Support Team Tue, 04 Dec 2012 06:18:16 +0100 diff --git a/debian/patches/0001-RFC-Efficient-VM-backup-for-qemu.patch b/debian/patches/0001-RFC-Efficient-VM-backup-for-qemu.patch index d27efe0..69439e6 100644 --- a/debian/patches/0001-RFC-Efficient-VM-backup-for-qemu.patch +++ b/debian/patches/0001-RFC-Efficient-VM-backup-for-qemu.patch @@ -1,4 +1,4 @@ -From 491d4eb9d078b68616205c0c89de9909df990014 Mon Sep 17 00:00:00 2001 +From 95b9266b030a4962284a0b9eebf9849291809fee Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 13 Nov 2012 09:24:50 +0100 Subject: [PATCH v3 1/6] RFC: Efficient VM backup for qemu diff --git a/debian/patches/0002-add-basic-backup-support-to-block-driver.patch b/debian/patches/0002-add-basic-backup-support-to-block-driver.patch index 152eb0f..a08a834 100644 --- a/debian/patches/0002-add-basic-backup-support-to-block-driver.patch +++ b/debian/patches/0002-add-basic-backup-support-to-block-driver.patch @@ -1,4 +1,4 @@ -From 7ec08213d1b7c9de3b83016db81efd8337838ad2 Mon Sep 17 00:00:00 2001 +From 290368c30f966c3e74d6cd926c0d044f7ba2a3ea Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 13 Nov 2012 10:03:52 +0100 Subject: [PATCH v3 2/6] add basic backup support to block driver diff --git a/debian/patches/0003-add-backup-related-monitor-commands.patch b/debian/patches/0003-add-backup-related-monitor-commands.patch index 83c6921..9e12a3d 100644 --- a/debian/patches/0003-add-backup-related-monitor-commands.patch +++ b/debian/patches/0003-add-backup-related-monitor-commands.patch @@ -1,4 +1,4 @@ -From b58dfd87e2ff6552caab3e8b67966ab6b8c63080 Mon Sep 17 00:00:00 2001 +From 42ef2313a00a615414c6728a32febe650715769a Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 13 Nov 2012 11:27:56 +0100 Subject: [PATCH v3 3/6] add backup related monitor commands diff --git a/debian/patches/0004-introduce-new-vma-archive-format.patch b/debian/patches/0004-introduce-new-vma-archive-format.patch index 6c416c1..e1d6cc1 100644 --- a/debian/patches/0004-introduce-new-vma-archive-format.patch +++ b/debian/patches/0004-introduce-new-vma-archive-format.patch @@ -1,4 +1,4 @@ -From 12a179d66c3ead14c821dbc570f2448c8c8b355f Mon Sep 17 00:00:00 2001 +From ada8961d41298b340dc624da571cba760ab39158 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer 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 Makefile.objs | 2 +- blockdev.c | 6 +- docs/specs/vma_spec.txt | 24 ++ - vma-reader.c | 772 ++++++++++++++++++++++++++++++++++++++++ - vma-writer.c | 907 +++++++++++++++++++++++++++++++++++++++++++++++ - vma.c | 550 ++++++++++++++++++++++++++++ + vma-reader.c | 776 +++++++++++++++++++++++++++++++++++++++ + vma-writer.c | 920 +++++++++++++++++++++++++++++++++++++++++++++++ + vma.c | 555 ++++++++++++++++++++++++++++ vma.h | 145 ++++++++ - 8 files changed, 2405 insertions(+), 4 deletions(-) + 8 files changed, 2427 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..154c96b +index 0000000..b05d7da --- /dev/null +++ b/vma-reader.c -@@ -0,0 +1,772 @@ +@@ -0,0 +1,776 @@ +/* + * VMA: Virtual Machine Archive + * @@ -487,7 +487,11 @@ index 0000000..154c96b + + VmaReader *vmar = g_new0(VmaReader, 1); + -+ vmar->fd = open(filename, O_RDONLY); ++ if (strcmp(filename, "-") == 0) { ++ vmar->fd = dup(0); ++ } else { ++ vmar->fd = open(filename, O_RDONLY); ++ } + + if (vmar->fd < 0) { + error_setg(errp, "can't open file %s - %s\n", filename, @@ -892,10 +896,10 @@ index 0000000..154c96b + diff --git a/vma-writer.c b/vma-writer.c new file mode 100644 -index 0000000..917c77f +index 0000000..c1e1afe --- /dev/null +++ b/vma-writer.c -@@ -0,0 +1,907 @@ +@@ -0,0 +1,920 @@ +/* + * VMA: Virtual Machine Archive + * @@ -927,6 +931,7 @@ index 0000000..917c77f +#include "qemu/ratelimit.h" +#include "vma.h" +#include "block.h" ++#include "monitor.h" + +#define DEBUG_VMA 0 + @@ -1284,12 +1289,24 @@ index 0000000..917c77f + } else { + struct stat st; + int oflags; ++ const char *tmp_id_str; ++ + if ((stat(filename, &st) == 0) && S_ISFIFO(st.st_mode)) { + oflags = O_NONBLOCK|O_WRONLY; -+ } else { ++ vmaw->fd = qemu_open(filename, oflags, 0644); ++ } else if (strstart(filename, "/dev/fdset/", &tmp_id_str)) { ++ oflags = O_NONBLOCK|O_WRONLY; ++ vmaw->fd = qemu_open(filename, oflags, 0644); ++ } else if (strstart(filename, "/dev/fdname/", &tmp_id_str)) { ++ vmaw->fd = monitor_get_fd(cur_mon, tmp_id_str, errp); ++ if (vmaw->fd < 0) { ++ goto err; ++ } ++ } else { + oflags = O_NONBLOCK|O_WRONLY|O_CREAT|O_EXCL; ++ vmaw->fd = qemu_open(filename, oflags, 0644); + } -+ vmaw->fd = open(filename, oflags, 0644); ++ + if (vmaw->fd < 0) { + error_setg(errp, "can't open file %s - %s\n", filename, + strerror(errno)); @@ -1805,10 +1822,10 @@ index 0000000..917c77f + diff --git a/vma.c b/vma.c new file mode 100644 -index 0000000..69af80c +index 0000000..7a88d3f --- /dev/null +++ b/vma.c -@@ -0,0 +1,550 @@ +@@ -0,0 +1,555 @@ +/* + * VMA: Virtual Machine Archive + * @@ -1956,10 +1973,10 @@ index 0000000..69af80c + int c, ret = 0; + const char *filename; + const char *dirname; -+ int readmap = 0; ++ const char *readmap = NULL; + + for (;;) { -+ c = getopt(argc, argv, "hr"); ++ c = getopt(argc, argv, "hr:"); + if (c == -1) { + break; + } @@ -1969,7 +1986,7 @@ index 0000000..69af80c + help(); + break; + case 'r': -+ readmap = 1; ++ readmap = optarg; + break; + default: + help(); @@ -2003,7 +2020,7 @@ index 0000000..69af80c + GError *err = NULL; + if (!g_file_set_contents(cfgfn, (gchar *)cdata->data, cdata->len, + &err)) { -+ g_error("Unable to write file: %s", err->message); ++ g_error("unable to write file: %s", err->message); + } + } + @@ -2012,9 +2029,14 @@ index 0000000..69af80c + if (readmap) { + print_content(vmar); + ++ FILE *map = fopen(readmap, "r"); ++ if (!map) { ++ g_error("unable to open fifo %s - %s", readmap, strerror(errno)); ++ } ++ + while (1) { + char inbuf[8192]; -+ char *line = fgets(inbuf, sizeof(inbuf), stdin); ++ char *line = fgets(inbuf, sizeof(inbuf), map); + if (!line || line[0] == '\0' || !strcmp(line, "done\n")) { + break; + } @@ -2034,7 +2056,7 @@ index 0000000..69af80c + } else if (line[0] == '1' && line[1] == ':') { + path = inbuf + 2; + write_zero = true; -+ } else { ++ } else { + g_error("read map failed - parse error ('%s')", inbuf); + } + diff --git a/debian/patches/0005-add-regression-tests-for-backup.patch b/debian/patches/0005-add-regression-tests-for-backup.patch index d0bcd01..b5670eb 100644 --- a/debian/patches/0005-add-regression-tests-for-backup.patch +++ b/debian/patches/0005-add-regression-tests-for-backup.patch @@ -1,4 +1,4 @@ -From e6cbe1cf67c6fd7b6fdce689c17cb40a4c644e13 Mon Sep 17 00:00:00 2001 +From 017d593f2c83b3e8b415789c10c9d423cf1e811e Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 14 Nov 2012 09:57:04 +0100 Subject: [PATCH v3 5/6] add regression tests for backup diff --git a/debian/patches/0006-add-vm-state-to-backups.patch b/debian/patches/0006-add-vm-state-to-backups.patch index cb5e137..0372218 100644 --- a/debian/patches/0006-add-vm-state-to-backups.patch +++ b/debian/patches/0006-add-vm-state-to-backups.patch @@ -1,4 +1,4 @@ -From 06eb6208bcc65bce57f31bd33ff5256567f49368 Mon Sep 17 00:00:00 2001 +From d4d33a401830ce903c598c04fb9352d91fda5399 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Thu, 29 Nov 2012 10:46:49 +0100 Subject: [PATCH v3 6/6] add vm state to backups diff --git a/debian/patches/implement-qemu-fopen-bdrv.patch b/debian/patches/implement-qemu-fopen-bdrv.patch deleted file mode 100644 index 1e6e5f6..0000000 --- a/debian/patches/implement-qemu-fopen-bdrv.patch +++ /dev/null @@ -1,90 +0,0 @@ -Index: new/savevm.c -=================================================================== ---- new.orig/savevm.c 2012-09-18 07:05:08.000000000 +0200 -+++ new/savevm.c 2012-09-18 07:19:31.000000000 +0200 -@@ -387,29 +387,48 @@ - return NULL; - } - --static int block_put_buffer(void *opaque, const uint8_t *buf, -+static int block_state_put_buffer(void *opaque, const uint8_t *buf, - int64_t pos, int size) - { -- bdrv_save_vmstate(opaque, buf, pos, size); -- return size; -+ return bdrv_save_vmstate(opaque, buf, pos, size); - } - --static int block_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size) -+static int block_state_get_buffer(void *opaque, uint8_t *buf, int64_t pos, -+ int size) - { - return bdrv_load_vmstate(opaque, buf, pos, size); - } - -+static int block_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, -+ int size) -+{ -+ return bdrv_pwrite(opaque, pos, buf, size); -+} -+ -+static int block_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size) -+{ -+ return bdrv_pread(opaque, pos, buf, size); -+} -+ - static int bdrv_fclose(void *opaque) - { - return bdrv_flush(opaque); - } - --static QEMUFile *qemu_fopen_bdrv(BlockDriverState *bs, int is_writable) -+QEMUFile *qemu_fopen_bdrv(BlockDriverState *bs, int is_writable) -+{ -+ return qemu_fopen_ops(bs, is_writable ? block_put_buffer : NULL, -+ block_get_buffer, bdrv_fclose, -+ NULL, NULL, NULL); -+} -+ -+static QEMUFile *qemu_fopen_bdrv_state(BlockDriverState *bs, int is_writable) - { - if (is_writable) -- return qemu_fopen_ops(bs, block_put_buffer, NULL, bdrv_fclose, -+ return qemu_fopen_ops(bs, block_state_put_buffer, NULL, bdrv_fclose, - NULL, NULL, NULL); -- return qemu_fopen_ops(bs, NULL, block_get_buffer, bdrv_fclose, NULL, NULL, NULL); -+ return qemu_fopen_ops(bs, NULL, block_state_get_buffer, bdrv_fclose, -+ NULL, NULL, NULL); - } - - QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer, -@@ -2145,7 +2164,7 @@ - } - - /* save the VM state */ -- f = qemu_fopen_bdrv(bs, 1); -+ f = qemu_fopen_bdrv_state(bs, 1); - if (!f) { - monitor_printf(mon, "Could not open VM state file\n"); - goto the_end; -@@ -2266,7 +2285,7 @@ - } - - /* restore the VM state */ -- f = qemu_fopen_bdrv(bs_vm_state, 0); -+ f = qemu_fopen_bdrv_state(bs_vm_state, 0); - if (!f) { - error_report("Could not open VM state file"); - return -EINVAL; -Index: new/qemu-file.h -=================================================================== ---- new.orig/qemu-file.h 2012-09-18 07:05:08.000000000 +0200 -+++ new/qemu-file.h 2012-09-18 07:07:26.000000000 +0200 -@@ -68,6 +68,7 @@ - QEMUFile *qemu_fopen(const char *filename, const char *mode); - QEMUFile *qemu_fdopen(int fd, const char *mode); - QEMUFile *qemu_fopen_socket(int fd); -+QEMUFile *qemu_fopen_bdrv(BlockDriverState *bs, int is_writable); - QEMUFile *qemu_popen(FILE *popen_file, const char *mode); - QEMUFile *qemu_popen_cmd(const char *command, const char *mode); - int qemu_stdio_fd(QEMUFile *f); diff --git a/debian/patches/load-state-from-blockdev.patch b/debian/patches/load-state-from-blockdev.patch deleted file mode 100644 index c051fd7..0000000 --- a/debian/patches/load-state-from-blockdev.patch +++ /dev/null @@ -1,142 +0,0 @@ -Index: new/savevm.c -=================================================================== ---- new.orig/savevm.c 2012-09-19 07:17:28.000000000 +0200 -+++ new/savevm.c 2012-09-19 14:10:02.000000000 +0200 -@@ -407,6 +407,17 @@ - - static int block_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size) - { -+ int ret; -+ int64_t maxlen = bdrv_getlength(opaque); -+ if (pos > maxlen) { -+ return -EIO; -+ } -+ if ((pos + size) > maxlen) { -+ size = maxlen - pos - 1; -+ } -+ if (size == 0) { -+ return 0; -+ } - return bdrv_pread(opaque, pos, buf, size); - } - -@@ -2223,6 +2234,50 @@ - return; - } - -+int load_state_from_blockdev(const char *filename) -+{ -+ BlockDriverState *bs = NULL; -+ BlockDriver *drv = NULL; -+ QEMUFile *f; -+ int bdrv_oflags = BDRV_O_CACHE_WB | BDRV_O_RDWR; -+ int ret = -1; -+ -+ bs = bdrv_new("vmstate"); -+ ret = bdrv_open(bs, filename, bdrv_oflags, drv); -+ if (ret < 0) { -+ error_report("Could not open VM state file"); -+ goto the_end; -+ } -+ -+ /* Flush all IO requests so they don't interfere with the new state. */ -+ bdrv_drain_all(); -+ -+ /* restore the VM state */ -+ f = qemu_fopen_bdrv(bs, 0); -+ if (!f) { -+ error_report("Could not open VM state file"); -+ ret = -EINVAL; -+ goto the_end; -+ } -+ -+ qemu_system_reset(VMRESET_SILENT); -+ ret = qemu_loadvm_state(f); -+ -+ qemu_fclose(f); -+ if (ret < 0) { -+ error_report("Error %d while loading VM state", ret); -+ goto the_end; -+ } -+ -+ ret = 0; -+ -+ the_end: -+ if (bs) { -+ bdrv_delete(bs); -+ } -+ return ret; -+} -+ - int load_vmstate(const char *name) - { - BlockDriverState *bs, *bs_vm_state; -Index: new/sysemu.h -=================================================================== ---- new.orig/sysemu.h 2012-09-19 07:17:21.000000000 +0200 -+++ new/sysemu.h 2012-09-19 14:09:51.000000000 +0200 -@@ -72,6 +72,7 @@ - - void do_savevm(Monitor *mon, const QDict *qdict); - int load_vmstate(const char *name); -+int load_state_from_blockdev(const char *filename); - void do_delvm(Monitor *mon, const QDict *qdict); - void do_info_snapshots(Monitor *mon); - -Index: new/qemu-options.hx -=================================================================== ---- new.orig/qemu-options.hx 2012-09-19 07:17:28.000000000 +0200 -+++ new/qemu-options.hx 2012-09-19 07:17:28.000000000 +0200 -@@ -2477,6 +2477,19 @@ - Start right away with a saved state (@code{loadvm} in monitor) - ETEXI - -+DEF("loadstate", HAS_ARG, QEMU_OPTION_loadstate, \ -+ "-loadstate file\n" \ -+ " start right away with a saved state\n", -+ QEMU_ARCH_ALL) -+STEXI -+@item -loadstate @var{file} -+@findex -loadstate -+Start right away with a saved state. This option does not rollback -+disk state like @code{loadvm}, so user must make sure that disk -+have correct state. @var{file} can be any valid device URL. See the section -+for "Device URL Syntax" for more information. -+ETEXI -+ - #ifndef _WIN32 - DEF("daemonize", 0, QEMU_OPTION_daemonize, \ - "-daemonize daemonize QEMU after initializing\n", QEMU_ARCH_ALL) -Index: new/vl.c -=================================================================== ---- new.orig/vl.c 2012-09-19 07:17:28.000000000 +0200 -+++ new/vl.c 2012-09-19 07:17:28.000000000 +0200 -@@ -2364,6 +2364,7 @@ - int optind; - const char *optarg; - const char *loadvm = NULL; -+ const char *loadstate = NULL; - QEMUMachine *machine; - const char *cpu_model; - const char *vga_model = "none"; -@@ -2998,6 +2999,9 @@ - case QEMU_OPTION_loadvm: - loadvm = optarg; - break; -+ case QEMU_OPTION_loadstate: -+ loadstate = optarg; -+ break; - case QEMU_OPTION_full_screen: - full_screen = 1; - break; -@@ -3821,6 +3825,10 @@ - if (load_vmstate(loadvm) < 0) { - autostart = 0; - } -+ } else if (loadstate) { -+ if (load_state_from_blockdev(loadstate) < 0) { -+ autostart = 0; -+ } - } - - if (incoming) { diff --git a/debian/rules b/debian/rules index dfcb503..6cfa98e 100755 --- a/debian/rules +++ b/debian/rules @@ -78,6 +78,7 @@ install: build # Install the userspace utilities install -m 0755 scripts/kvm/kvm_stat $(destdir)/usr/bin/ + install -s -m 0755 vma $(destdir)/usr/bin/ install -D -m 0755 $(CURDIR)/debian/kvm-ifup $(destdir)/etc/kvm/kvm-ifup install -D -m 0755 $(CURDIR)/debian/kvm-ifdown $(destdir)/etc/kvm/kvm-ifdown -- 2.39.5