RFC: Efficient VM backup for qemu (v1)
PATCH 1/5 RFC: Efficient VM backup for qemu (v1)
This series provides a way to efficiently backup VMs.
* Backup to a single archive file
* Backup contain all data to restore VM (full backup)
* Do not depend on storage type or image format
* Avoid use of temporary storage
* store sparse images efficiently
The file docs/backup-rfc.txt contains more details.
--- docs/backup-rfc.txt | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 119 insertions(+), 0 deletions(-) create mode 100644 docs/backup-rfc.txt
docs/backup-rfc.txt new file +119 -0
@@ -0,0 +1,119 @@ +RFC: Efficient VM backup for qemu + +=Requirements= + +* Backup to a single archive file +* Backup needs to contain all data to restore VM (full backup) +* Do not depend on storage type or image format +* Avoid use of temporary storage +* store sparse images efficiently + +=Introduction= + +Most VM backup solutions use some kind of snapshot to get a consistent +VM view at a specific point in time. For example, we previously used +LVM to create a snapshot of all used VM images, which are then copied +into a tar file. + +That basically means that any data written during backup involve +considerable overhead. For LVM we get the following steps: + +1.) read original data (VM write) +2.) write original data into snapshot (VM write) +3.) write new data (VM write) +4.) read data from snapshot (backup) +5.) write data from snapshot into tar file (backup) + +Another approach to backup VM images is to create a new qcow2 image +which use the old image as base. During backup, writes are redirected +to the new image, so the old image represents a 'snapshot'. After +backup, data need to be copied back from new image into the old +one (commit). So a simple write during backup triggers the following +steps: + +1.) write new data to new image (VM write) +2.) read data from old image (backup) +3.) write data from old image into tar file (backup) + +4.) read data from new image (commit) +5.) write data to old image (commit) + +This is in fact the same overhead as before. Other tools like qemu +livebackup produces similar overhead (2 reads, 3 writes). + +Some storage types/formats supports internal snapshots using some kind +of reference counting (rados, sheepdog, dm-thin, qcow2). It would be possible +to use that for backups, but for now we want to be storage-independent. + +Note: It turned out that taking a qcow2 snapshot can take a very long +time on larger files. + +=Make it more efficient= + +The be more efficient, we simply need to avoid unnecessary steps. The +following steps are always required: + +1.) read old data before it gets overwritten +2.) write that data into the backup archive +3.) write new data (VM write) + +As you can see, this involves only one read, an two writes. + +To make that work, our backup archive need to be able to store image +data 'out of order'. It is important to notice that this will not work +with traditional archive formats like tar. + +During backup we simply intercept writes, then read existing data and +store that directly into the archive. After that we can continue the +write. + +==Advantages== + +* very good performance (1 read, 2 writes) +* works on any storage type and image format. +* avoid usage of temporary storage +* we can define a new and simple archive format, which is able to + store sparse files efficiently. + +Note: Storing sparse files is a mess with existing archive +formats. For example, tar requires information about holes at the +beginning of the archive. + +==Disadvantages== + +* we need to define a new archive format + +Note: Most existing archive formats are optimized to store small files +including file attributes. We simply do not need that for VM archives. + +* archive contains data 'out of order' + +If you want to access image data in sequential order, you need to +re-order archive data. It would be possible to to that on the fly, +using temporary files. + +Fortunately, a normal restore/extract works perfectly with 'out of +order' data, because the target files are seekable. + +* slow backup storage can slow down VM during backup + +It is important to note that we only do sequential writes to the +backup storage. Furthermore one can compress the backup stream. IMHO, +it is better to slow down the VM a bit. All other solutions creates +large amounts of temporary data during backup. + +=Archive format requirements= + +The basic requirement for such new format is that we can store image +date 'out of order'. It is also very likely that we have less than 256 +drives/images per VM, and we want to be able to store VM configuration +files. + +We have defined a very simply format with those properties, see: + +docs/specs/vma_spec.txt + +Please let us know if you know an existing format which provides the +same functionality. + +
Signature · 1 line
1.7.2.5
PATCH 2/5 add basic backup support to block driver
Function bdrv_backup_init() creates a block job to backup a block device.
We call brdv_co_backup_cow() for each write during backup. That function reads the original data and pass it to backup_dump_cb().
The tracked_request infrastructure is used to serialize access.
Currently backup cluster size is hardcoded to 65536 bytes.
--- Makefile.objs | 1 + backup.c | 296 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ block.c | 60 +++++++++++- block.h | 6 + block_int.h | 28 ++++++ 5 files changed, 388 insertions(+), 3 deletions(-) create mode 100644 backup.c
Makefile.objs +1 -0
@@ -48,6 +48,7 @@ coroutine-obj-$(CONFIG_WIN32) += coroutine-win32.o block-obj-y = iov.o cache-utils.o qemu-option.o module.o async.o block-obj-y += nbd.o block.o blockjob.o aes.o qemu-config.o block-obj-y += thread-pool.o qemu-progress.o qemu-sockets.o uri.o notify.o +block-obj-y += backup.o block-obj-y += $(coroutine-obj-y) $(qobject-obj-y) $(version-obj-y) block-obj-$(CONFIG_POSIX) += event_notifier-posix.o aio-posix.o block-obj-$(CONFIG_WIN32) += event_notifier-win32.o aio-win32.o
backup.c new file +296 -0
296 lines not on this page · raw message
block.c +57 -3
124 lines not on this page · raw message
block.h +6 -0
@@ -90,6 +90,10 @@ typedef struct BlockDevOps {#define BDRV_SECTOR_SIZE (1ULL << BDRV_SECTOR_BITS)#define BDRV_SECTOR_MASK ~(BDRV_SECTOR_SIZE - 1) +#define BACKUP_CLUSTER_BITS 16 +#define BACKUP_CLUSTER_SIZE (1<<BACKUP_CLUSTER_BITS) +#define BACKUP_BLOCKS_PER_CLUSTER (BACKUP_CLUSTER_SIZE/BDRV_SECTOR_SIZE) +typedef enum {BDRV_ACTION_REPORT ,BDRV_ACTION_IGNORE ,BDRV_ACTION_STOP }BlockErrorAction ;
@@ -172,6 +176,8 @@ int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); int coroutine_fn bdrv_co_copy_on_readv(BlockDriverState *bs,int64_t sector_num,int nb_sectors,QEMUIOVector *qiov); +int coroutine_fn bdrv_co_backup(BlockDriverState *bs, +int64_t sector_num,int nb_sectors); int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num,int nb_sectors,QEMUIOVector *qiov);/*
block_int.h +28 -0
@@ -68,6 +68,32 @@ typedef struct BlockIOBaseValue {uint64_t ios[2 ]; } BlockIOBaseValue; +/** +* Backup related definitions +*/ + +typedef int BackupDumpFunc (void *opaque,BlockDriverState *bs, +int64_t cluster_num,unsigned char *buf); + +typedef struct BackupInfo { +unsigned long *bitmap; +int bitmap_size; +BackupDumpFunc *backup_dump_cb; +BlockDriverCompletionFunc *backup_complete_cb; +void *opaque; +}BackupInfo ; + +BackupInfo *bdrv_backup_init (BlockDriverState *bs, +BackupDumpFunc *backup_dump_cb, +BlockDriverCompletionFunc *backup_complete_cb, +void *opaque); + +void bdrv_backup_deinit (BlockDriverState *bs); + +int coroutine_fn brdv_co_backup_cow(BlockDriverState *bs, +int64_t sector_num,int nb_sectors); + +struct BlockDriver {const char *format_name;int instance_size;
@@ -276,6 +302,8 @@ struct BlockDriverState { QLIST_HEAD(, BdrvTrackedRequest) tracked_requests; +BackupInfo *backup_info; +/* long-running background operation */ BlockJob *job;
Signature · 1 line
1.7.2.5
Re: [Qemu-devel] [PATCH 2/5] add basic backup support to block driver
On Wed, Nov 21, 2012 at 10:01:01AM +0100, Dietmar Maurer wrote:
Two comments from skimming the code, not a full review.
backup.c line 30
Quoted 9 lines
backup.c new file +9
-0+/* #define DEBUG_BACKUP */ + +#ifdef DEBUG_BACKUP +#define DPRINTF (fmt, ...) \ + do { printf("backup: " fmt, ## __VA_ARGS__); } while (0) +#else +#define DPRINTF (fmt, ...) \ + do { } while (0) +#endif
Please don't #define debug macros like this. It hides build breakage because the debug code is #ifdef'd out.
Either use docs/tracing.txt or do the following so the code always gets parsed by the compiler:
#define DEBUG_BACKUP 0
#define DPRINTF(fmt, ...) \
do { \
if (DEBUG_BACKUP) { \
printf("backup: " fmt, ## __VA_ARGS__); \
} \
} while (0)Quoted 28 lines
backup.c new file +28
-0+BackupInfo * +bdrv_backup_init (BlockDriverState *bs,BackupDumpFunc *backup_dump_cb, +BlockDriverCompletionFunc *backup_complete_cb, +void *opaque) +{ +assert (bs); +assert (backup_dump_cb); +assert (backup_complete_cb); + +if (bs->backup_info) { +DPRINTF ("bdrv_backup_init already initialized %s\n" , +bdrv_get_device_name (bs)); +return NULL ; + } + +BackupInfo *info =g_malloc0 (sizeof (BackupInfo)); +int64_t bitmap_size; +const char *devname =bdrv_get_device_name (bs); + +if (!devname || !devname[0 ]) { +return NULL ; + } + +DPRINTF ("bdrv_backup_init %s\n" ,bdrv_get_device_name (bs)); + + bitmap_size = bs->total_sectors + +BACKUP_BLOCKS_PER_CLUSTER *BITS_PER_LONG -1 ; + bitmap_size /=BACKUP_BLOCKS_PER_CLUSTER *BITS_PER_LONG ;
backup.c line 287
Quoted 10 lines
backup.c new file +10
-0+ + info->backup_dump_cb = backup_dump_cb; + info->backup_complete_cb = backup_complete_cb; + info->opaque = opaque; + info->bitmap_size = bitmap_size; + info->bitmap = g_new0(unsigned long, bitmap_size); + +Error *errp; +BackupBlockJob *job =block_job_create (&backup_job_type, bs,0 , + backup_job_cleanup_cb, bs, &errp);
Is there a 1:1 relationship between BackupInfo and BackupBlockJob? Then it would be nicer to move BlockupInfo fields into BackupBlockJob (which is empty right now). Then you also don't need to add fields to BlockDriverState because you know that if your blockjob is running you can access it via bs->job, if necessary. You can then drop BackupInfo and any memory management code for it.
Re: [Qemu-devel] [PATCH 2/5] add basic backup support to block driver
Quoted 3 lines
Is there a 1:1 relationship between BackupInfo and BackupBlockJob? Then it would be nicer to move BlockupInfo fields into BackupBlockJob (which is empty right now
No, a backup create several block jobs - one for each blockdev you want to backup. Those jobs run in parallel.
Re: [Qemu-devel] [PATCH 2/5] add basic backup support to block driver
In reply to Stefan HajnocziQuoted 6 lines
Is there a 1:1 relationship between BackupInfo and BackupBlockJob? Then it would be nicer to move BlockupInfo fields into BackupBlockJob (which is empty right now). Then you also don't need to add fields to BlockDriverState because you know that if your blockjob is running you can access it via bs-
Quoted 1 line
job, if necessary. You can then drop BackupInfo and any memory
management code for it.
Oh, finally got your point.
There is an ongoing discussion about generic block filters, So I guess this totally depends on how we implement them.
- Dietmar
PATCH 3/5 introduce new vma archive format
In reply to Dietmar MaurerThis is a very simple archive format, see docs/specs/vma_spec.txt
--- Makefile | 3 +- docs/specs/vma_spec.txt | 24 ++ vma-reader.c | 720 +++++++++++++++++++++++++++++++++++++++++ vma-writer.c | 824 +++++++++++++++++++++++++++++++++++++++++++++++ vma.c | 526 ++++++++++++++++++++++++++++++ vma.h | 139 ++++++++ 6 files changed, 2235 insertions(+), 1 deletions(-) create mode 100644 docs/specs/vma_spec.txt create mode 100644 vma-reader.c create mode 100644 vma-writer.c create mode 100644 vma.c create mode 100644 vma.h
Makefile +2 -1
@@ -100,7 +100,7 @@ defconfig: -include config-all-devices.mak -all: $(DOCS) $(TOOLS) $(HELPERS-y) recurse-all +all: $(DOCS) $(TOOLS) vma$(EXESUF) $(HELPERS-y) recurse-all config-host.h: config-host.h-timestamp config-host.h-timestamp: config-host.mak
@@ -194,6 +194,7 @@ tools-obj-$(CONFIG_POSIX) += compatfd.o qemu-img$(EXESUF): qemu-img.o $(tools-obj-y) $(block-obj-y) libqemustub.a qemu-nbd$(EXESUF): qemu-nbd.o $(tools-obj-y) $(block-obj-y) libqemustub.a qemu-io$(EXESUF): qemu-io.o cmd.o $(tools-obj-y) $(block-obj-y) libqemustub.a +vma$(EXESUF): vma.o vma-writer.o vma-reader.o $(tools-obj-y) $(block-obj-y) libqemustub.a qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o
docs/specs/vma_spec.txt new file +24 -0
@@ -0,0 +1,24 @@ +=Virtual Machine Archive format (VMA)= + +This format contains a header which includes the VM configuration as +binary blobs, and a list of devices (dev_id, name). + +The actual VM image date is stored inside extends. En extend contains +up to 64 clusters, and start with a 512 byte header containing +additional information for those clusters. + +We use a cluster size of 65536, and use 8 bytes for each +cluster in the header to store the following information: + +* 1 byte dev_id (to identity the drive) +* 2 bytes zero indicator (mark zero regions (16x4069)) +* 4 bytes cluster number +* 1 byte not used (reserved) + +We only store non-zero blocks (such block is 4096 bytes). + +Each archive is marked with an unique uuid. The archive header and all +extend headers includes that uuid and a MD5 checksum (over header +data). + +
vma-reader.c new file +720 -0
720 lines not on this page · raw message
vma-writer.c new file +824 -0
824 lines not on this page · raw message
vma.c new file +526 -0
526 lines not on this page · raw message
vma.h new file +139 -0
139 lines not on this page · raw message
Signature · 1 line
1.7.2.5
Re: [Qemu-devel] [PATCH 3/5] introduce new vma archive format
docs/specs/vma_spec.txt line 6
Quoted 13 lines · Dietmar Maurer
This is a very simple archive format, see
docs/specs/vma_spec.txtSigned-off-by Dietmar Maurer <[email protected]>---
+++
b/docs/specs/vma_spec.txtdocs/specs/vma_spec.txt new file +6
-0@@ -0,0 +1,24 @@ +=Virtual Machine Archive format (VMA)= + +This format contains a header which includes the VM configuration as +binary blobs, and a list of devices (dev_id, name). + +The actual VM image date is stored inside extends. En extend contains
s/date/data/
s/extends. En extend/extents. An extent/
docs/specs/vma_spec.txt line 14
Quoted 8 lines
docs/specs/vma_spec.txt new file +8
-0+up to 64 clusters, and start with a 512 byte header containing +additional information for those clusters. + +We use a cluster size of 65536, and use 8 bytes for each +cluster in the header to store the following information: + +* 1 byte dev_id (to identity the drive) +* 2 bytes zero indicator (mark zero regions (16x4069))
s/4069/4096/
docs/specs/vma_spec.txt line 15
Quoted 1 line
docs/specs/vma_spec.txt new file +1
-0+* 4 bytes cluster number
Is that sufficient, or is it possible to have an image larger than 64k*4G that would overflow?
docs/specs/vma_spec.txt line 20
Quoted 5 lines
docs/specs/vma_spec.txt new file +5
-0+* 1 byte not used (reserved) + +We only store non-zero blocks (such block is 4096 bytes). + +Each archive is marked with an unique uuid. The archive header and all
s/an unique/a/ (by definition, 'uuid' is an acronym that already means unique; also, it is 'a' and not 'an' before any 'u' pronounced as 'y', which is true for both 'unique' and a spelled-out 'uuid')
docs/specs/vma_spec.txt line 21
Quoted 1 line
docs/specs/vma_spec.txt new file +1
-0+extend headers includes that uuid and a MD5 checksum (over header
s/extend/extent/
vma-reader.c line 4
Quoted 13 lines
docs/specs/vma_spec.txt new file +3
-0+data). + +vma-reader.c new file +4
-0@@ -0,0 +1,720 @@ +/* +* VMA: Virtual Machine Archive +* +* Copyright (C) Proxmox Server Solutions
Missing a year.
vma-reader.c line 9
Quoted 5 lines
vma-reader.c new file +5
-0+* +* Authors: +* Dietmar Maurer ([email protected]) +* +* This work is licensed under the terms of the GNU GPL, version 2. See
Can you please use GPLv2+ (the 'or later' clause is essential if you want your work to be reusable in GPLv3[+] projects)?
I didn't review the code, just the specification. I have to wonder how much of your work overlaps with Paolo's 'drive-mirror' and NBD server work; and it seems to me that it is better to use 'drive-mirror' for doing backup work into existing disk formats, rather than inventing yet another archive format.
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 3/5] introduce new vma archive format
Quoted 4 lines
Quoted 1 line
+* 4 bytes cluster number
Is that sufficient, or is it possible to have an image larger than 64k*4G that would overflow?
Well, that is 256TB per image. This is sufficient for us.
Quoted 10 lines
docs/specs/vma_spec.txt
Quoted 6 lines
docs/specs/vma_spec.txt new file +6
-0+* 1 byte not used (reserved) + +We only store non-zero blocks (such block is 4096 bytes). + +Each archive is marked with an unique uuid. The archive header and +alls/an unique/a/ (by definition, 'uuid' is an acronym that already means unique; also, it is 'a' and not 'an' before any 'u' pronounced as 'y', which is true for both 'unique' and a spelled-out 'uuid')
many thanks for your help - will fix those things.
Quoted 5 lines
Quoted 2 lines
+ * This work is licensed under the terms of the GNU GPL, version 2.
+ SeeCan you please use GPLv2+ (the 'or later' clause is essential if you want your work to be reusable in GPLv3[+] projects)?
sure, no problem.
Quoted 4 lines
I didn't review the code, just the specification. I have to wonder how much of your work overlaps with Paolo's 'drive-mirror' and NBD server work; and it seems to me that it is better to use 'drive-mirror' for doing backup work into existing disk formats, rather than inventing yet another archive format.
I already tried to explain why that does not work - see my previous posts.
What image format provides that functionality?
PATCH 4/5 add backup related monitor commands
In reply to Dietmar MaurerWe currently create 'vma' archives without any configuration inside. Future versions may support other formats...
Another option would be to simply dump <devid,cluster_num,cluster_data> to the output fh (pipe), and an external binary saves the data. That way we could move the whole archive format related code out of qemu.
--- Makefile.objs | 2 +- blockdev.c | 263 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ hmp-commands.hx | 31 +++++++ hmp.c | 63 +++++++++++++ hmp.h | 3 + monitor.c | 7 ++ qapi-schema.json | 46 ++++++++++ qmp-commands.hx | 27 ++++++ 8 files changed, 441 insertions(+), 1 deletions(-)
Makefile.objs +1 -1
@@ -48,7 +48,7 @@ coroutine-obj-$(CONFIG_WIN32) += coroutine-win32.o block-obj-y = iov.o cache-utils.o qemu-option.o module.o async.o block-obj-y += nbd.o block.o blockjob.o aes.o qemu-config.o block-obj-y += thread-pool.o qemu-progress.o qemu-sockets.o uri.o notify.o -block-obj-y += backup.o +block-obj-y += vma-writer.o backup.o block-obj-y += $(coroutine-obj-y) $(qobject-obj-y) $(version-obj-y) block-obj-$(CONFIG_POSIX) += event_notifier-posix.o aio-posix.o block-obj-$(CONFIG_WIN32) += event_notifier-win32.o aio-win32.o
blockdev.c +263 -0
275 lines not on this page · raw message
hmp-commands.hx +31 -0
@@ -83,6 +83,35 @@ STEXI Copy data from a backing file into a block device. ETEXI + { + .name = "backup", + .args_type = "backupfile:s,speed:o?,devlist:s?", + .params = "backupfile [speed [devlist]]", + .help = "create a VM Backup.", + .mhandler.cmd = hmp_backup, + }, + +STEXI +@item backup +@findex backup +Create a VM backup. +ETEXI + + { + .name = "backup_cancel", + .args_type = "", + .params = "", + .help = "cancel the current VM backup", + .mhandler.cmd = hmp_backup_cancel, + }, + +STEXI +@item backup_cancel +@findex backup_cancel +Cancel the current VM backup. + +ETEXI + { .name = "block_job_set_speed", .args_type = "device:B,speed:o",
@@ -1558,6 +1587,8 @@ show CPU statistics show user network stack connection states @item info migrate show migration status +@item info backup +show backup status @item info migrate_capabilities show current migration capabilities @item info migrate_cache_size
hmp.c +63 -0
75 lines not on this page · raw message
hmp.h +3 -0
@@ -28,6 +28,7 @@ void hmp_info_mice(Monitor *mon);void hmp_info_migrate (Monitor *mon);void hmp_info_migrate_capabilities (Monitor *mon);void hmp_info_migrate_cache_size (Monitor *mon); +void hmp_info_backup (Monitor *mon);void hmp_info_cpus (Monitor *mon);void hmp_info_block (Monitor *mon);void hmp_info_blockstats (Monitor *mon);
@@ -63,6 +64,8 @@ void hmp_eject(Monitor *mon, const QDict *qdict);void hmp_change (Monitor *mon,const QDict *qdict);void hmp_block_set_io_throttle (Monitor *mon,const QDict *qdict);void hmp_block_stream (Monitor *mon,const QDict *qdict); +void hmp_backup (Monitor *mon,const QDict *qdict); +void hmp_backup_cancel (Monitor *mon,const QDict *qdict);void hmp_block_job_set_speed (Monitor *mon,const QDict *qdict);void hmp_block_job_cancel (Monitor *mon,const QDict *qdict);void hmp_block_job_pause (Monitor *mon,const QDict *qdict);
monitor.c +7 -0
@@ -2680,6 +2680,13 @@ static mon_cmd_t info_cmds[] = { },#endif { + .name = "backup", + .args_type = "", + .params = "", + .help = "show backup status", + .mhandler.info = hmp_info_backup, + }, + { .name = "migrate", .args_type = "", .params = "",
qapi-schema.json +46 -0
58 lines not on this page · raw message
qmp-commands.hx +27 -0
@@ -822,6 +822,18 @@ EQMP }, { + .name = "backup", + .args_type = "backupfile:s,speed:o?,devlist:s?", + .mhandler.cmd_new = qmp_marshal_input_backup, + }, + + { + .name = "backup_cancel", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_backup_cancel, + }, + + { .name = "block-job-set-speed", .args_type = "device:B,speed:o", .mhandler.cmd_new = qmp_marshal_input_block_job_set_speed,
@@ -2491,6 +2503,21 @@ EQMP }, SQMP + +query-backup +------------- + +Backup status. + +EQMP + + { + .name = "query-backup", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_query_backup, + }, + +SQMP migrate-set-capabilities -------
Signature · 1 line
1.7.2.5
Re: [Qemu-devel] [PATCH 4/5] add backup related monitor commands
Quoted 10 lines · Dietmar Maurer
We currently create 'vma' archives without any configuration inside. Future versions may support other formats...
Another option would be to simply dump <devid,cluster_num,cluster_data> to the output fh (pipe), and an external binary saves the data. That way we could move the whole archive format related code out of qemu.
+++
b/qapi-schema.json
qapi-schema.json line 366
Quoted 10 lines
qapi-schema.json +7
-0@@ -357,6 +357,13 @@ ## { 'type': 'EventInfo', 'data': {'name': 'str'} } + +{ 'type': 'BackupStatus', + 'data': {'*status': 'str', '*errmsg': 'str', '*total': 'int', + '*transferred': 'int', '*zero-bytes': 'int', + '*start-time': 'int', '*end-time': 'int', + '*backupfile': 'str', '*uuid': 'str' } } +
Missing documentation for what all these fields mean.
Quoted 9 lines
qapi-schema.json +2
-0## # @query-events: #@@ -1764,6 +1771,45 @@ 'data': { 'path': 'str' }, 'returns': [ 'ObjectPropertyInfo' ] } + +##
qapi-schema.json line 1785
Quoted 10 lines
qapi-schema.json +10
-0+# @backup: +# +# Starts a VM backup. +# +# @backupfile: the backup file name +# +# @speed: #optional the maximum speed, in bytes per second +# +# Returns: the uuid of the backup job +#
Needs to mention when it was introduced (at best, it will be since 1.4).
Quoted 7 lines
qapi-schema.json +7
-0+## +{ 'command': 'backup', 'data': { 'backupfile': 'str', '*devlist': 'str', + '*speed': 'int' }, + 'returns': 'str' } + +## +# @query-backup
qapi-schema.json line 1802
Quoted 10 lines
qapi-schema.json +10
-0+# +# Returns information about current/last backup task. +# +# Returns: @BackupStatus +# +## +{ 'command': 'query-backup', 'returns': 'BackupStatus' } + +## +# @backup_cancel
s/_/-/, you should prefer dashes in QMP
qapi-schema.json line 1812
Quoted 10 lines
qapi-schema.json +10
-0+# +# Cancel the current executing backup process. +# +# Returns: nothing on success +# +# Notes: This command succeeds even if there is no backup process running. +# +## +{ 'command': 'backup_cancel' } +
You are basically adding a new asynchronous job. Do you really need to add a 'backup-cancel' command, or should we be reusing a generic framework for canceling arbitrary jobs?
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 4/5] add backup related monitor commands
Quoted 8 lines
qapi-schema.json line 366
Quoted 6 lines
qapi-schema.json +6
-0+{ 'type': 'BackupStatus', + 'data': {'*status': 'str', '*errmsg': 'str', '*total': 'int', + '*transferred': 'int', '*zero-bytes': 'int', + '*start-time': 'int', '*end-time': 'int', + '*backupfile': 'str', '*uuid': 'str' } } +Missing documentation for what all these fields mean.
Yes, sorry for that. I just wanted to get an early feedback from the community before I work out the details.
Re: [Qemu-devel] [PATCH 4/5] add backup related monitor commands
In reply to Eric BlakeQuoted 6 lines
qapi-schema.json line 1812
Quoted 2 lines
qapi-schema.json +2
-0+{ 'command': 'backup_cancel' } +You are basically adding a new asynchronous job. Do you really need to add a 'backup-cancel' command, or should we be reusing a generic framework for canceling arbitrary jobs?
No, we basically add several asynchronous job - one for each blockdev. And we want to cancel them all together.
PATCH 5/5 add regression tests for backup
In reply to Dietmar MaurerAlso added the ratelimit.h fix here, because it is still not upstream.
--- include/qemu/ratelimit.h | 2 +- tests/Makefile | 11 +- tests/backup-test.c | 505 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 515 insertions(+), 3 deletions(-) create mode 100644 tests/backup-test.c
include/qemu/ratelimit.h +1 -1
@@ -42,7 +42,7 @@ static inline void ratelimit_set_speed(RateLimit *limit, uint64_t speed, uint64_t slice_ns) { limit->slice_ns = slice_ns; - limit->slice_quota = ((double )speed *1000000000ULL ) / slice_ns; + limit->slice_quota = ((double )speed * slice_ns)/1000000000ULL ; }#endif
tests/Makefile +9 -2
@@ -18,6 +18,8 @@ check-unit-y += tests/test-iov$(EXESUF) check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh +check-backup-y = tests/backup-test$(EXESUF) + # All QTests for now are POSIX-only, but the dependencies are # really in libqtest, not in the testcases themselves. check-qtest-i386-y = tests/fdc-test$(EXESUF)
@@ -50,6 +52,7 @@ tests/check-qfloat$(EXESUF): tests/check-qfloat.o qfloat.o tests/check-qjson$(EXESUF): tests/check-qjson.o $(qobject-obj-y) qemu-tool.o tests/test-coroutine$(EXESUF): tests/test-coroutine.o $(coroutine-obj-y) $(tools-obj-y) $(block-obj-y) iov.o libqemustub.a tests/test-iov$(EXESUF): tests/test-iov.o iov.o +tests/backup-test$(EXESUF): tests/backup-test.o vma-reader.o $(tools-obj-y) $(block-obj-y) libqemustub.a tests/test-qapi-types.c tests/test-qapi-types.h :\ $(SRC_PATH)/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-types.py
@@ -142,10 +145,14 @@ check-tests/qemu-iotests-quick.sh: tests/qemu-iotests-quick.sh qemu-img$(EXESUF) # Consolidated targets -.PHONY: check-qtest check-unit check +.PHONY: check-backup check-qtest check-unit check check-qtest: $(patsubst %,check-qtest-%, $(QTEST_TARGETS)) check-unit: $(patsubst %,check-%, $(check-unit-y)) check-block: $(patsubst %,check-%, $(check-block-y)) -check: check-unit check-qtest + +check-backup: tests/backup-test$(EXESUF) + $< + +check: check-unit check-qtest check-backup -include $(wildcard tests/*.d)
tests/backup-test.c new file +505 -0
505 lines not on this page · raw message
Signature · 1 line
1.7.2.5
Am 21.11.2012 10:01, schrieb Dietmar Maurer:
docs/backup-rfc.txt line 49
Quoted 6 lines
docs/backup-rfc.txt new file +6
-0+Some storage types/formats supports internal snapshots using some kind +of reference counting (rados, sheepdog, dm-thin, qcow2). It would be possible +to use that for backups, but for now we want to be storage-independent. + +Note: It turned out that taking a qcow2 snapshot can take a very long +time on larger files.
Hm, really? What are "larger files"? It has always been relatively quick when I tested it, though internal snapshots are not my focus, so that need not mean much.
If this is really an important use case for someone, I think qcow2 internal snapshots still have some potential for relatively easy performance optimisations.
But that just as an aside...
docs/backup-rfc.txt line 60
Quoted 11 lines
docs/backup-rfc.txt new file +11
-0+ +=Make it more efficient= + +The be more efficient, we simply need to avoid unnecessary steps. The +following steps are always required: + +1.) read old data before it gets overwritten +2.) write that data into the backup archive +3.) write new data (VM write) + +As you can see, this involves only one read, an two writes.
Looks like a nice approach to backup indeed.
The question is how to fit this into the big picture of qemu's live block operations. Much of it looks like an active mirror (which is still to be implemented), with the difference that it doesn't write the new, but the old data, and that it keeps a bitmap of clusters that should not be mirrored.
I'm not sure if this means that code should be shared between these two or if the differences are too big. However, both of them have things in common regarding the design. For example, both have a background part (copying the existing data) and an active part (mirroring/backing up data on writes). Block jobs are the right tool for the background part.
The active part is a bit more tricky. You're putting some code into block.c to achieve it, which is kind of ugly. We have been talking about "block filters" previously that would provide a generic infrastructure, and at least in the mid term the additions to block.c must disappear. (Same for block.h and block_int.h - keep things as separated from the core as possible) Maybe we should introduce this infrastructure now.
Another interesting point is how (or whether) to link block jobs with block filters. I think when the job is started, the filter should be inserted automatically, and when you cancel it, it should be stopped. When you pause the job... no idea. :-)
Quoted 31 lines
docs/backup-rfc.txt new file +27
-0+ +To make that work, our backup archive need to be able to store image +data 'out of order'. It is important to notice that this will not work +with traditional archive formats like tar. +* works on any storage type and image format. +* we can define a new and simple archive format, which is able to + store sparse files efficiently. + +Note: Storing sparse files is a mess with existing archive +formats. For example, tar requires information about holes at the +beginning of the archive. +* we need to define a new archive format + +Note: Most existing archive formats are optimized to store small files +including file attributes. We simply do not need that for VM archives. + +* archive contains data 'out of order' + +If you want to access image data in sequential order, you need to +re-order archive data. It would be possible to to that on the fly, +using temporary files. + +Fortunately, a normal restore/extract works perfectly with 'out of +order' data, because the target files are seekable. +=Archive format requirements= + +The basic requirement for such new format is that we can store image
docs/backup-rfc.txt line 117
Quoted 10 lines
docs/backup-rfc.txt new file +10
-0+date 'out of order'. It is also very likely that we have less than 256 +drives/images per VM, and we want to be able to store VM configuration +files. + +We have defined a very simply format with those properties, see: + +docs/specs/vma_spec.txt + +Please let us know if you know an existing format which provides the +same functionality.
Essentially, what you need is an image format. You want to be independent from the source image formats, but you're okay with using a specific format for the backup (or you wouldn't have defined a new format for it).
The one special thing that you need is storing multiple images in one file. There's something like this already in qemu: qcow2 with its internal snapshots is basically a flat file system.
Not saying that this is necessarily the best option, but I think reusing existing formats and implementation is always a good thing, so it's an idea to consider.
Kevin
Quoted 6 lines
docs/backup-rfc.txt line 49
Quoted 2 lines
docs/backup-rfc.txt new file +2
-0+Note: It turned out that taking a qcow2 snapshot can take a very long +time on larger files.Hm, really? What are "larger files"? It has always been relatively quick when I tested it, though internal snapshots are not my focus, so that need not mean much.
300GB or larger
Quoted 3 lines
If this is really an important use case for someone, I think qcow2 internal snapshots still have some potential for relatively easy performance optimisations.
I guess the problem is the small cluster size, so the reference table gets quite large (for example fvd uses 2GB to minimize table size).
Quoted 21 lines
But that just as an aside...
docs/backup-rfc.txt line 60
Quoted 11 lines
docs/backup-rfc.txt new file +11
-0+ +=Make it more efficient= + +The be more efficient, we simply need to avoid unnecessary steps. The +following steps are always required: + +1.) read old data before it gets overwritten +2.) write that data into the backup archive +3.) write new data (VM write) + +As you can see, this involves only one read, an two writes.Looks like a nice approach to backup indeed.
The question is how to fit this into the big picture of qemu's live block operations. Much of it looks like an active mirror (which is still to be implemented), with the difference that it doesn't write the new, but the old data, and that it keeps a bitmap of clusters that should not be mirrored.
Quoted 5 lines
I'm not sure if this means that code should be shared between these two or if the differences are too big. However, both of them have things in common regarding the design. For example, both have a background part (copying the existing data) and an active part (mirroring/backing up data on writes). Block jobs are the right tool for the background part.
I already use block jobs. Or do you want to share more?
Quoted 2 lines
The active part is a bit more tricky. You're putting some code into
block.cto achieve it, which is kind of ugly.
yes. but I tried to keep that small ;-)
Quoted 5 lines
We have been talking about "block filters"
previously that would provide a generic infrastructure, and at least in the mid term the additions toblock.cmust disappear.
(Same forblock.handblock_int.h- keep things as separated from the core as possible) Maybe we should introduce this infrastructure now.
I have no idea what you talk about? Can you point me to the relevant discussion?
Quoted 51 lines
Another interesting point is how (or whether) to link block jobs with block filters. I think when the job is started, the filter should be inserted automatically, and when you cancel it, it should be stopped. When you pause the job... no idea. :-)
Quoted 31 lines
docs/backup-rfc.txt new file +27
-0+ +To make that work, our backup archive need to be able to store image +data 'out of order'. It is important to notice that this will not +work with traditional archive formats like tar. +* works on any storage type and image format. +* we can define a new and simple archive format, which is able to + store sparse files efficiently. + +Note: Storing sparse files is a mess with existing archive formats. +For example, tar requires information about holes at the beginning of +the archive. +* we need to define a new archive format + +Note: Most existing archive formats are optimized to store small +files including file attributes. We simply do not need that for VM archives. + +* archive contains data 'out of order' + +If you want to access image data in sequential order, you need to +re-order archive data. It would be possible to to that on the fly, +using temporary files. + +Fortunately, a normal restore/extract works perfectly with 'out of +order' data, because the target files are seekable. +=Archive format requirements= + +The basic requirement for such new format is that we can store imagedocs/backup-rfc.txt line 117
Quoted 10 lines
docs/backup-rfc.txt new file +10
-0+date 'out of order'. It is also very likely that we have less than +256 drives/images per VM, and we want to be able to store VM +configuration files. + +We have defined a very simply format with those properties, see: + +docs/specs/vma_spec.txt + +Please let us know if you know an existing format which provides the +same functionality.Essentially, what you need is an image format. You want to be independent from the source image formats, but you're okay with using a specific format for the backup (or you wouldn't have defined a new format for it).
Quoted 7 lines
The one special thing that you need is storing multiple images in one file. There's something like this already in qemu: qcow2 with its internal snapshots is basically a flat file system.
Not saying that this is necessarily the best option, but I think reusing existing formats and implementation is always a good thing, so it's an idea to consider.
AFAIK qcow2 file cannot store data out of order. In general, an backup fd is not seekable, and we only want to do sequential writes. Image format always requires seekable fds?
Anyways, a qcow2 file is really complex beast - I am quite unsure if I would use that for backup if it is possible.
That would require any external tool to include >=50000 LOC
The vma reader code is about 700 LOC (quite easy).
Am 21.11.2012 12:10, schrieb Dietmar Maurer:
Quoted 7 lines
Quoted 6 lines
docs/backup-rfc.txt line 49
Quoted 2 lines
docs/backup-rfc.txt new file +2
-0+Note: It turned out that taking a qcow2 snapshot can take a very long +time on larger files.Hm, really? What are "larger files"? It has always been relatively quick when I tested it, though internal snapshots are not my focus, so that need not mean much.
Quoted 8 lines
300GB or larger
Quoted 3 lines
If this is really an important use case for someone, I think qcow2 internal snapshots still have some potential for relatively easy performance optimisations.
I guess the problem is the small cluster size, so the reference table gets quite large (for example fvd uses 2GB to minimize table size).
qemu-img check gives an idea of what it costs to read in the whole metadata of an image. Updating some of it should mean not more than a factor of two. I'm seeing much bigger differences, so I suspect there's something wrong.
Somebody should probably try tracing where the performance is lost.
Quoted 21 lines
Quoted 21 lines
But that just as an aside...
docs/backup-rfc.txt line 60
Quoted 11 lines
docs/backup-rfc.txt new file +11
-0+ +=Make it more efficient= + +The be more efficient, we simply need to avoid unnecessary steps. The +following steps are always required: + +1.) read old data before it gets overwritten +2.) write that data into the backup archive +3.) write new data (VM write) + +As you can see, this involves only one read, an two writes.Looks like a nice approach to backup indeed.
The question is how to fit this into the big picture of qemu's live block operations. Much of it looks like an active mirror (which is still to be implemented), with the difference that it doesn't write the new, but the old data, and that it keeps a bitmap of clusters that should not be mirrored.
Quoted 7 lines
Quoted 5 lines
I'm not sure if this means that code should be shared between these two or if the differences are too big. However, both of them have things in common regarding the design. For example, both have a background part (copying the existing data) and an active part (mirroring/backing up data on writes). Block jobs are the right tool for the background part.
I already use block jobs. Or do you want to share more?
I was thinking about sharing code between a future active mirror and the backup job. Which may or may not make sense. I'm mostly hoping for input from Paolo here.
Quoted 4 lines
Quoted 2 lines
The active part is a bit more tricky. You're putting some code into
block.cto achieve it, which is kind of ugly.yes. but I tried to keep that small ;-)
Yup, it's already not too bad. I haven't looked into it in much detail, but I'd like to reduce it even a bit more. In particular, the backup_info field in the BlockDriverState feels wrong to me. In the long term the generic block layer shouldn't know at all what a backup is, and baking it into BDS couples it very tightly.
Quoted 7 lines
Quoted 5 lines
We have been talking about "block filters"
previously that would provide a generic infrastructure, and at least in the mid term the additions toblock.cmust disappear.
(Same forblock.handblock_int.h- keep things as separated from the core as possible) Maybe we should introduce this infrastructure now.I have no idea what you talk about? Can you point me to the relevant discussion?
Not sure if a single discussion explains it, and I can't even find one at the moment.
In short, the idea is that you can stick filters on top of a BlockDriverState, so that any read/writes (and possibly more requests, if necessary) are routed through the filter before they are passed to the block driver of this BDS. Filters would be implemented as BlockDrivers, i.e. you could implement .bdrv_co_write() in a filter to intercept all writes to an image.
Quoted 13 lines
Quoted 13 lines
Another interesting point is how (or whether) to link block jobs with block filters. I think when the job is started, the filter should be inserted automatically, and when you cancel it, it should be stopped. When you pause the job... no idea. :-)
Essentially, what you need is an image format. You want to be independent from the source image formats, but you're okay with using a specific format for the backup (or you wouldn't have defined a new format for it).
The one special thing that you need is storing multiple images in one file. There's something like this already in qemu: qcow2 with its internal snapshots is basically a flat file system.
Quoted 6 lines
Quoted 3 lines
Not saying that this is necessarily the best option, but I think reusing existing formats and implementation is always a good thing, so it's an idea to consider.
AFAIK qcow2 file cannot store data out of order. In general, an backup fd is not seekable, and we only want to do sequential writes. Image format always requires seekable fds?
Ah, this is what you mean by "out of order". Just out of curiosity, what are these non-seekable backup fds usually?
In principle even for this qcow2 could be used as an image format, however the existing implementation wouldn't be of much use for you, so it loses quite a bit of its attractiveness.
Quoted 6 lines
Anyways, a qcow2 file is really complex beast - I am quite unsure if I would use that for backup if it is possible.
That would require any external tool to include >=50000 LOC
The vma reader code is about 700 LOC (quite easy).
So what? qemu-img is already there.
Kevin
Il 21/11/2012 13:37, Kevin Wolf ha scritto:
Quoted 9 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
The active part is a bit more tricky. You're putting some code into
block.cto achieve it, which is kind of ugly.yes. but I tried to keep that small ;-)
Yup, it's already not too bad. I haven't looked into it in much detail, but I'd like to reduce it even a bit more. In particular, the
backup_infofield in the BlockDriverState feels wrong to me. In the long term the generic block layer shouldn't know at all what a backup is, and baking it into BDS couples it very tightly.
My plan was to have something like bs->job->job_type->{before,after}_write.
int coroutine_fn (*before_write)(BlockDriverState *bs,
int64_t sector_num, int nb_sectors, QEMUIOVector *qiov, void **cookie);
int coroutine_fn (*after_write)(BlockDriverState *bs,
int64_t sector_num, int nb_sectors, QEMUIOVector *qiov, void *cookie);
The before_write could optionally return a "cookie" that is passed back to the after_write callback.
Actually this was plan B, as a poor-man implementation of the filter infrastructure. Plan A was that the block filters would materialize suddenly in someone's git tree.
Anyway, it should be very easy to convert Dietmar's code to something like that, and the active mirror could use it as well.
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
AFAIK qcow2 file cannot store data out of order. In general, an backup fd is not seekable, and we only want to do sequential writes. Image format always requires seekable fds?
Ah, this is what you mean by "out of order". Just out of curiosity, what are these non-seekable backup fds usually?
Perhaps I've been reading the SCSI standards too much lately, but tapes come to mind. :)
Paolo
Quoted 16 lines
Quoted 5 lines
Yup, it's already not too bad. I haven't looked into it in much detail, but I'd like to reduce it even a bit more. In particular, the
backup_infofield in the BlockDriverState feels wrong to me. In the long term the generic block layer shouldn't know at all what a backup is, and baking it into BDS couples it very tightly.My plan was to have something like bs->job->job_type->{before,after}_write.
int
coroutine_fn(*before_write)(BlockDriverState *bs,
int64_tsector_num, intnb_sectors, QEMUIOVector *qiov, void **cookie);
intcoroutine_fn(*after_write)(BlockDriverState *bs,
int64_tsector_num, intnb_sectors, QEMUIOVector *qiov, void *cookie);
Quoted 2 lines
The
before_writecould optionally return a "cookie" that is passed back to theafter_writecallback.
I don't really understand why a filter is related to the job? This is sometimes useful, but not a generic filter infrastructure (maybe someone want to use filters without a job).
Il 23/11/2012 08:42, Dietmar Maurer ha scritto:
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
My plan was to have something like bs->job->job_type->{before,after}_write.
int
coroutine_fn(*before_write)(BlockDriverState *bs,
int64_tsector_num, intnb_sectors, QEMUIOVector *qiov, void **cookie);
intcoroutine_fn(*after_write)(BlockDriverState *bs,
int64_tsector_num, intnb_sectors, QEMUIOVector *qiov, void *cookie);
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
The
before_writecould optionally return a "cookie" that is passed back to theafter_writecallback.I don't really understand why a filter is related to the job? This is sometimes useful, but not a generic filter infrastructure (maybe someone want to use filters without a job).
See the part you snipped:
Actually this was plan B, as a poor-man implementation of the filter infrastructure. Plan A was that the block filters would materialize suddenly in someone's git tree.
Paolo
Quoted 3 lines
Actually this was plan B, as a poor-man implementation of the filter infrastructure. Plan A was that the block filters would materialize suddenly in someone's git tree.
OK, so let us summarize the options:
a.) wait untit it materialize suddenly in someone's git tree.
b.) add BlockFilter inside BDS
c.) add filter callbacks to block bojs (job_type)
d.) use BlockDriver as filter
e.) use the current BackupInfo unless filters materialize suddenly in someone's git tree.
more ideas?
Quoted 6 lines
Quoted 5 lines
Yup, it's already not too bad. I haven't looked into it in much detail, but I'd like to reduce it even a bit more. In particular, the
backup_infofield in the BlockDriverState feels wrong to me. In the long term the generic block layer shouldn't know at all what a backup is, and baking it into BDS couples it very tightly.
Quoted 8 lines
My plan was to have something like bs->job->job_type->{before,after}_write.
int
coroutine_fn(*before_write)(BlockDriverState *bs,
int64_tsector_num, intnb_sectors, QEMUIOVector *qiov, void **cookie);
intcoroutine_fn(*after_write)(BlockDriverState *bs,
int64_tsector_num, intnb_sectors, QEMUIOVector *qiov, void *cookie);
I don't think that job is the right place. Instead I would put a list of filters into BDS:
typedef struct BlockFilter {
void *opaque;
int cluster_size;
int coroutine_fn (before_read)(BlockDriverState *bs,
int64_t sector_num, int nb_sectors, QEMUIOVector *qiov, BdrvRequestFlags flags, void **cookie);
int coroutine_fn (after_read)(BlockDriverState *bs,
int64_t sector_num, int nb_sectors, QEMUIOVector *qiov, BdrvRequestFlags flags, void *cookie);
int coroutine_fn (*before_write)(BlockDriverState *bs,
int64_t sector_num, int nb_sectors, QEMUIOVector *qiov, void **cookie);
int coroutine_fn (*after_write)(BlockDriverState *bs,
int64_t sector_num, int nb_sectors, QEMUIOVector *qiov, void *cookie);
} BlockFilter;
struct BlockDriverState {
...
QLIST_HEAD(, BlockFilters) filters; };
Would that work for you?
Quoted 10 lines
Quoted 9 lines
My plan was to have something like bs->job->job_type- {before,after}_write.
int
coroutine_fn(*before_write)(BlockDriverState *bs,
int64_tsector_num, intnb_sectors, QEMUIOVector *qiov, void **cookie);
intcoroutine_fn(*after_write)(BlockDriverState *bs,
int64_tsector_num, intnb_sectors, QEMUIOVector *qiov, void *cookie);
Quoted 2 lines
I don't think that job is the right place. Instead I would put a list of filters into BDS:
Well, I can also add it to job_type. Just tell me what you prefer, and I will write the patch.
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
My plan was to have something like bs->job->job_type- {before,after}_write.
int
coroutine_fn(*before_write)(BlockDriverState *bs,
int64_tsector_num, intnb_sectors, QEMUIOVector *qiov, void **cookie);
intcoroutine_fn(*after_write)(BlockDriverState *bs,
int64_tsector_num, intnb_sectors, QEMUIOVector *qiov, void *cookie);
Quoted 6 lines
Quoted 3 lines
I don't think that job is the right place. Instead I would put a list of filters into
BDS:Well, I can also add it to
job_type. Just tell me what you prefer, and I will write the patch.
BTW, will such filters work with the new virtio-blk-data-plane?
Il 23/11/2012 10:05, Dietmar Maurer ha scritto:
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
My plan was to have something like bs->job->job_type- {before,after}_write.
int
coroutine_fn(*before_write)(BlockDriverState *bs,
int64_tsector_num, intnb_sectors, QEMUIOVector *qiov, void **cookie);
intcoroutine_fn(*after_write)(BlockDriverState *bs,
int64_tsector_num, intnb_sectors, QEMUIOVector *qiov, void *cookie);
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
I don't think that job is the right place. Instead I would put a list of filters into
BDS:Well, I can also add it to
job_type. Just tell me what you prefer, and I will write the patch.BTW, will such filters work with the new virtio-blk-data-plane?
No, virtio-blk-data-plane is a hack and will be slowly rewritten to support all fancy features.
Paolo
Quoted 4 lines
Quoted 1 line
BTW, will such filters work with the new virtio-blk-data-plane?
No, virtio-blk-data-plane is a hack and will be slowly rewritten to support all fancy features.
Ah, good to know ;-) thanks.
Am 23.11.2012 10:05, schrieb Dietmar Maurer:
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
My plan was to have something like bs->job->job_type- {before,after}_write.
int
coroutine_fn(*before_write)(BlockDriverState *bs,
int64_tsector_num, intnb_sectors, QEMUIOVector *qiov, void **cookie);
intcoroutine_fn(*after_write)(BlockDriverState *bs,
int64_tsector_num, intnb_sectors, QEMUIOVector *qiov, void *cookie);
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
I don't think that job is the right place. Instead I would put a list of filters into
BDS:Well, I can also add it to
job_type. Just tell me what you prefer, and I will write the patch.
A block filter shouldn't be tied to a job, I think. We have things like blkdebug that are really filters and aren't coupled with a job, and on the other hand we want to generalise "block jobs" into just "jobs", so adding block specific things to job_type would be a step in the wrong direction.
I also think that before_write/after_write isn't a convenient interface, it brings back much of the callback-based AIO cruft and passing void* isn't nice anyway. It's much nice to have a single .bdrv_co_write callback that somewhere in the middle calls the layer below with a simple function call.
Also read/write aren't enough, for a full filter interface you potentially also need flush, discard and probably most other operations.
This is why I suggested using a regular BlockDriver struct for filters, it already has all functions that are needed.
Quoted 1 line
BTW, will such filters work with the new virtio-blk-data-plane?
Not initially, but I think as soon as data plane gets support for image formats, filters would work as well.
Kevin
Quoted 30 lines · Kevin Wolf
Am 23.11.2012 10:05, schrieb Dietmar Maurer:
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
My plan was to have something like bs->job->job_type- {before,after}_write.
int
coroutine_fn(*before_write)(BlockDriverState *bs,
int64_tsector_num, intnb_sectors, QEMUIOVector *qiov, void **cookie);
intcoroutine_fn(*after_write)(BlockDriverState *bs,
int64_tsector_num, intnb_sectors, QEMUIOVector *qiov, void *cookie);Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
I don't think that job is the right place. Instead I would put a list of filters into
BDS:Well, I can also add it to
job_type. Just tell me what you prefer, and I will write the patch.A block filter shouldn't be tied to a job, I think. We have things like blkdebug that are really filters and aren't coupled with a job, and on the other hand we want to generalise "block jobs" into just "jobs", so adding block specific things to
job_typewould be a step in the wrong direction.I also think that before_write/after_write isn't a convenient interface, it brings back much of the callback-based AIO cruft and passing void* isn't nice anyway. It's much nice to have a single .bdrv_co_write callback that somewhere in the middle calls the layer below with a simple function call.
Quoted 5 lines
Also read/write aren't enough, for a full filter interface you potentially also need flush, discard and probably most other operations.
This is why I suggested using a regular BlockDriver struct for filters, it already has all functions that are needed.
Let me elaborate a bit.
A block backend is a tree of block driver instances (BlockDriverState). Common examples:
raw qcow2 qcow2
| / \ / \ file file raw file qcow2
| / \
file file raw
|
file
A less common example:
raw
|
blkdebug
|
fileHere, "blkdebug" acts as a filter, i.e. a block driver that can be put between two adjacent tree nodes. It injects errors by selectively failing some bdrv_aio_readv() and bdrv_aio_writev() operations.
Actually, "raw" could also be viewed as a degenerate filter that does nothing[*], but such a filter isn't particularly useful.
Except perhaps to serve as base for real filters, that do stuff. To do stuff in your filter, you'd replace raw's operations with your own.
Hmm, blkdebug implements much fewer operations than raw. Makes me wonder whether it works only in special places in the tree now.
[...]
[*] Except occasionally inject bugs when somebody adds new BlockDriver operations without updating "raw" to forward them.
Quoted 6 lines
Quoted 2 lines
AFAIK qcow2 file cannot store data out of order. In general, an backup fd is not seekable, and we only want to do sequential writes. Image format
always requires seekable fds?
Ah, this is what you mean by "out of order". Just out of curiosity, what are these non-seekable backup fds usually?
/dev/nst0 ;-)
But there are better examples. Usually you want to use some kind of compression, and you do that with existing tools:
# backup to stdout|gzip|...
A common usage scenario is to pipe a backup into a restore (copy)
# backup to stdout|ssh to remote host -c 'restore from stdin'
It is also a performance question. Seeks are terrible slow.
Quoted 4 lines
In principle even for this qcow2 could be used as an image format, however the existing implementation wouldn't be of much use for you, so it loses quite a bit of its attractiveness.
Quoted 8 lines
Quoted 6 lines
Anyways, a qcow2 file is really complex beast - I am quite unsure if I would use that for backup if it is possible.
That would require any external tool to include >=50000 LOC
The vma reader code is about 700 LOC (quite easy).
So what? qemu-img is already there.
Anyways, you already pointed out that the existing implementation does not work.
But I already expected such discussion. So maybe it is better we simply pipe all data to an external binary? We just need to define a minimal protocol.
In future we can produce different archivers as independent/external binaries?
Am 21.11.2012 14:25, schrieb Dietmar Maurer:
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
AFAIK qcow2 file cannot store data out of order. In general, an backup fd is not seekable, and we only want to do sequential writes. Image format
always requires seekable fds?
Ah, this is what you mean by "out of order". Just out of curiosity, what are these non-seekable backup fds usually?
/dev/nst0;-)
Sure. :-)
Quoted 4 lines
But there are better examples. Usually you want to use some kind of compression, and you do that with existing tools:
# backup to stdout|gzip|...
When you use an image/archive format anyway, you could use a compression mechanism that it already supports.
Quoted 3 lines
A common usage scenario is to pipe a backup into a restore (copy)
# backup to stdout|ssh to remote host -c 'restore from stdin'
This is a good one. I believe our usual solution would have been to backup to a NBD server on the remote host instead.
In general I can see that being able to pipe it to other programs could be nice. I'm not sure if it's an absolute requirement. Would your tools for taking the backup employ any specific use of pipes?
Quoted 1 line
It is also a performance question. Seeks are terrible slow.
You wouldn't do it a lot. Only for metadata, and you would only write out the metadata once the in-memory cache is full.
Quoted 7 lines
Quoted 7 lines
In principle even for this qcow2 could be used as an image format, however the existing implementation wouldn't be of much use for you, so it loses quite a bit of its attractiveness.
Quoted 3 lines
Anyways, a qcow2 file is really complex beast - I am quite unsure if I would use that for backup if it is possible.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
That would require any external tool to include >=50000 LOC
The vma reader code is about 700 LOC (quite easy).
So what? qemu-img is already there.
Anyways, you already pointed out that the existing implementation does not work.
I'm still trying to figure out the real requirements to think some more about it. :-)
Quoted 4 lines
But I already expected such discussion. So maybe it is better we simply pipe all data to an external binary? We just need to define a minimal protocol.
In future we can produce different archivers as independent/external binaries?
You shouldn't look at discussions as a bad thing. We're not trying to block your changes, but to understand and possibly improve them.
Yes, discussions mean that it takes a bit longer to get things merged, but they also mean that usually something better is merged in the end that actually fits well in qemu's design, is maintainable, generic and so on. Evading the discussions by keeping code externally wouldn't improve things.
Which doesn't mean that external archivers are completely out of the question, but I would only consider them if there's a good technical reason to do so.
So if eventually we come to the conclusion that vma (or for that matter, anything else in your patches) is the right solution, let's take it. But first please give us the chance to understand the reasons of why you did things the way you did them, and to discuss the pros and cons of alternative solutions.
Kevin
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Ah, this is what you mean by "out of order". Just out of curiosity, what are these non-seekable backup fds usually?
/dev/nst0;-)Sure. :-)
Quoted 7 lines
Quoted 4 lines
But there are better examples. Usually you want to use some kind of compression, and you do that with existing tools:
# backup to stdout|gzip|...When you use an image/archive format anyway, you could use a compression mechanism that it already supports.
Many archive formats does not support compressions internally (tar, cpio, ..). I also avoided to include that in the 'vma' format. So you can use any external tool.
Some user wants to compress, other wants bzip2, or gzip -1, xz, pgzip, ... Or maybe pipe into some kind of encryption tool ...
Quoted 10 lines
Quoted 3 lines
A common usage scenario is to pipe a backup into a restore (copy)
# backup to stdout|ssh to remote host -c 'restore from stdin'This is a good one. I believe our usual solution would have been to backup to a NBD server on the remote host instead.
In general I can see that being able to pipe it to other programs could be nice. I'm not sure if it's an absolute requirement. Would your tools for taking the backup employ any specific use of pipes?
Yes, we currently have that functionality, and I do not want to remove features.
Quoted 4 lines
Quoted 1 line
It is also a performance question. Seeks are terrible slow.
You wouldn't do it a lot. Only for metadata, and you would only write out the metadata once the in-memory cache is full.
IMHO it is still much better to write sequentially, because that has 'zero' overhead.
Besides, writing data sequentially is so much easier (on the implementation side)
The current VMA code also use checksums and special 'uuid' markers, which makes it possible to find and recover damaged archives. I guess such things are quite impossible with qcow2, or very hard to do?
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
In principle even for this qcow2 could be used as an image format, however the existing implementation wouldn't be of much use for you, so it loses quite a bit of its attractiveness.
Quoted 6 lines
Anyways, a qcow2 file is really complex beast - I am quite unsure if I would use that for backup if it is possible.
That would require any external tool to include >=50000 LOC
The vma reader code is about 700 LOC (quite easy).
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
So what? qemu-img is already there.
Anyways, you already pointed out that the existing implementation does
not work.
I'm still trying to figure out the real requirements to think some more about it. :-)
Any existing archive format I know works on pipes (without seeks). Well, that does not really mean anything.
Quoted 9 lines
Quoted 1 line
But I already expected such discussion. So maybe it is better we simply pipe
all data to an external binary?
Quoted 3 lines
We just need to define a minimal protocol.
In future we can produce different archivers as independent/external
binaries?
You shouldn't look at discussions as a bad thing. We're not trying to block your changes, but to understand and possibly improve them.
I do not consider your comments as 'bad thing' - above idea was a real suggestion ;-)
I already have plans to use a Content Addressable Storage (instead of 'vma'), so such plugin architecture makes it easier to play around with different formats.
Quoted 4 lines
Yes, discussions mean that it takes a bit longer to get things merged, but they also mean that usually something better is merged in the end that actually fits well in qemu's design, is maintainable, generic and so on. Evading the discussions by keeping code externally wouldn't improve things.
sure.
Quoted 3 lines
Which doesn't mean that external archivers are completely out of the question, but I would only consider them if there's a good technical reason to do so.
As noted above, I can see rooms for different format.
1.) 'vma' is my proof of concept, easy to implement and use. 2.) CAS - very useful to sync backup data across datacenters (this gives us deduplication and kind of 'incremental backups') 3.) support existing archive format like 'tar' (this is possible if we use temporary files to store out-of-order data)
4.) backup to some kind of external server
5.) plugins for existing backup tools (bacula, ...)?
Quoted 5 lines
So if eventually we come to the conclusion that vma (or for that matter, anything else in your patches) is the right solution, let's take it. But first please give us the chance to understand the reasons of why you did things the way you did them, and to discuss the pros and cons of alternative solutions.
Sure. I was not aware that I wrote something negative in the previous reply - sorry for that.
Quoted 5 lines
In short, the idea is that you can stick filters on top of a BlockDriverState, so that any read/writes (and possibly more requests, if necessary) are routed through the filter before they are passed to the block driver of this BDS. Filters would be implemented as BlockDrivers, i.e. you could implement .bdrv_co_write() in a filter to intercept all writes to an image.
I am quite unsure if that make things easier.
Am 23.11.2012 08:38, schrieb Dietmar Maurer:
Quoted 7 lines
Quoted 5 lines
In short, the idea is that you can stick filters on top of a BlockDriverState, so that any read/writes (and possibly more requests, if necessary) are routed through the filter before they are passed to the block driver of this BDS. Filters would be implemented as BlockDrivers, i.e. you could implement .bdrv_co_write() in a filter to intercept all writes to an image.
I am quite unsure if that make things easier.
At least it would make for a much cleaner design compared to putting code for every feature you can think of into bdrv_co_do_readv/writev().
Kevin
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Filters would be implemented as BlockDrivers, i.e. you could implement
.bdrv_co_write() in a filter to intercept all writes to an image.I am quite unsure if that make things easier.
At least it would make for a much cleaner design compared to putting code for every feature you can think of into bdrv_co_do_readv/writev().
So if you want to add a filter, you simply modify bs->drv to point to the filter?
Quoted 10 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Filters would be implemented as BlockDrivers, i.e. you could implement
.bdrv_co_write() in a filter to intercept all writes to an image.I am quite unsure if that make things easier.
At least it would make for a much cleaner design compared to putting code for every feature you can think of into bdrv_co_do_readv/writev().
So if you want to add a filter, you simply modify
bs->drvto point to the filter?
Seems the BlockDriver struct does not contain any 'state' (I guess that is by design), so where do you store filter related dynamic data?
Am 23.11.2012 10:31, schrieb Dietmar Maurer:
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
Filters would be implemented as BlockDrivers, i.e. you could implement
.bdrv_co_write() in a filter to intercept all writes to an image.I am quite unsure if that make things easier.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
At least it would make for a much cleaner design compared to putting code for every feature you can think of into bdrv_co_do_readv/writev().
So if you want to add a filter, you simply modify
bs->drvto point to the filter?Seems the BlockDriver struct does not contain any 'state' (I guess that is by design), so where do you store filter related dynamic data?
You wouldn't change bs->drv of the block device, you still need that one after having processed the data in the filter.
Instead, you'd have some BlockDriverState *first_filter in bs to which requests are forwarded. first_filter->file would point to either the next filter or if there are no more filters to the real BlockDriverState.
Which raises the question of how to distinguish whether it's a new request to bs that must go through the filters or whether it actually comes from the last filter in the chain. As you can see, we don't have a well thought out plan yet, just rough ideas (otherwise it would probably be implemented already).
Kevin
Quoted 4 lines
Which raises the question of how to distinguish whether it's a new request to bs that must go through the filters or whether it actually comes from the last filter in the chain. As you can see, we don't have a well thought out plan yet, just rough ideas (otherwise it would probably be implemented already).
The question is if I should modify my backup patch (regarding block filters)?
IMHO, the current implementation is quite simple and easy to maintain. We can easily convert it if someone comes up with a full featured 'block filter' solution.
Il 26/11/2012 06:51, Dietmar Maurer ha scritto:
Quoted 6 lines
Quoted 4 lines
Which raises the question of how to distinguish whether it's a new request to bs that must go through the filters or whether it actually comes from the last filter in the chain. As you can see, we don't have a well thought out plan yet, just rough ideas (otherwise it would probably be implemented already).
The question is if I should modify my backup patch (regarding block filters)?
The only solution I came up with is to add before/after hooks in the block job. I agree with the criticism, but I think it's general enough and at the same time easy enough to implement.
Quoted 1 line
IMHO, the current implementation is quite simple and easy to maintain.
No, "if (bs->backup_info)" simply doesn't belong in bdrv_co_writev.
Paolo
Quoted 7 lines
The only solution I came up with is to add before/after hooks in the block job. I agree with the criticism, but I think it's general enough and at the same time easy enough to implement.
Quoted 1 line
IMHO, the current implementation is quite simple and easy to maintain.
No, "if (
bs->backup_info)" simply doesn't belong inbdrv_co_writev.
I do not really understand that argument, because the current COPY_ON_READ implementation also works that way:
if (bs->copy_on_read) {
flags |= BDRV_REQ_COPY_ON_READ;
}
if (flags & BDRV_REQ_COPY_ON_READ) {
bs->copy_on_read_in_flight++;
}
if (bs->copy_on_read_in_flight) {
wait_for_overlapping_requests(bs, sector_num, nb_sectors);
}
tracked_request_begin(&req, bs, sector_num, nb_sectors, false);
if (flags & BDRV_REQ_COPY_ON_READ) {...
Or do you also want to move that to block job hooks?
Quoted 26 lines
Quoted 7 lines
The only solution I came up with is to add before/after hooks in the block job. I agree with the criticism, but I think it's general enough and at the same time easy enough to implement.
Quoted 1 line
IMHO, the current implementation is quite simple and easy to maintain.
No, "if (
bs->backup_info)" simply doesn't belong inbdrv_co_writev.I do not really understand that argument, because the current
COPY_ON_READimplementation also works that way:if (bs->copy_on_read) { flags |= BDRV_REQ_COPY_ON_READ; } if (flags & BDRV_REQ_COPY_ON_READ) { bs->copy_on_read_in_flight++; } if (bs->copy_on_read_in_flight) { wait_for_overlapping_requests(bs, sector_num, nb_sectors); } tracked_request_begin(&req, bs, sector_num, nb_sectors, false); if (flags & BDRV_REQ_COPY_ON_READ) { ...
Quoted 1 line
Or do you also want to move that to block job hooks?
Just tried to move that code, but copy on read feature is unrelated to block jobs, i.e. one can open a bdrv with BDRV_O_COPY_ON_READ, and that does not create a job.
I already suggested to add those hooks to BDS instead - don't you think that would work?
Am 27.11.2012 08:15, schrieb Dietmar Maurer:
Quoted 26 lines
Quoted 26 lines
Quoted 7 lines
The only solution I came up with is to add before/after hooks in the block job. I agree with the criticism, but I think it's general enough and at the same time easy enough to implement.
Quoted 1 line
IMHO, the current implementation is quite simple and easy to maintain.
No, "if (
bs->backup_info)" simply doesn't belong inbdrv_co_writev.I do not really understand that argument, because the current
COPY_ON_READimplementation also works that way:if (bs->copy_on_read) { flags |= BDRV_REQ_COPY_ON_READ; } if (flags & BDRV_REQ_COPY_ON_READ) { bs->copy_on_read_in_flight++; } if (bs->copy_on_read_in_flight) { wait_for_overlapping_requests(bs, sector_num, nb_sectors); } tracked_request_begin(&req, bs, sector_num, nb_sectors, false); if (flags & BDRV_REQ_COPY_ON_READ) { ...
Quoted 7 lines
Quoted 1 line
Or do you also want to move that to block job hooks?
Just tried to move that code, but copy on read feature is unrelated to block jobs, i.e. one can open a bdrv with
BDRV_O_COPY_ON_READ, and that does not create a job.I already suggested to add those hooks to BDS instead - don't you think that would work?
To which BDS? If it is the BDS that is being backed up, the problem is that you could only have one implementation per BDS, i.e. you couldn't use backup and copy on read or I/O throttling or whatever at the same time.
Kevin
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
The only solution I came up with is to add before/after hooks in the block job. I agree with the criticism, but I think it's general enough and at the same time easy enough to implement.
Ok, here is another try - do you think that is better?
Note: This code is not tested - I just want to ask if I am moving into the right direction.
I tried to move BackupInfo into the block job.
Quoted 1 line
From
86c3ca6467e8d220369f5e7b235cdc0e88a79ff9Mon Sep 17 00:00:00 2001
From: Dietmar Maurer <[email protected]>
Date: Tue, 27 Nov 2012 11:05:23 +0100
Subject: [PATCH] add basic backup support to block driver
Function bdrv_backup_init() creates a block job to backup a block device.
We call brdv_co_backup_cow() for each write during backup. That function reads the original data and pass it to backup_dump_cb().
The tracked_request infrastructure is used to serialize access.
Currently backup cluster size is hardcoded to 65536 bytes.
--- Makefile.objs | 1 + backup.c | 302 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ backup.h | 30 ++++++ block.c | 71 ++++++++++++- block.h | 2 + blockjob.h | 10 ++ 6 files changed, 410 insertions(+), 6 deletions(-) create mode 100644 backup.c create mode 100644 backup.h
Makefile.objs +1 -0
@@ -48,6 +48,7 @@ coroutine-obj-$(CONFIG_WIN32) += coroutine-win32.o block-obj-y = iov.o cache-utils.o qemu-option.o module.o async.o block-obj-y += nbd.o block.o blockjob.o aes.o qemu-config.o block-obj-y += thread-pool.o qemu-progress.o qemu-sockets.o uri.o notify.o +block-obj-y += backup.o block-obj-y += $(coroutine-obj-y) $(qobject-obj-y) $(version-obj-y) block-obj-$(CONFIG_POSIX) += event_notifier-posix.o aio-posix.o block-obj-$(CONFIG_WIN32) += event_notifier-win32.o aio-win32.o
backup.c new file +302 -0
302 lines not on this page · raw message
backup.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* QEMU backup related definitions +* +* Copyright (C) Proxmox Server Solutions +* +* Authors: +* Dietmar Maurer ([email protected]) +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +* +*/ + +#ifndef QEMU_BACKUP_H +#define QEMU_BACKUP_H + +#include "block.h" + +#define BACKUP_CLUSTER_BITS 16 +#define BACKUP_CLUSTER_SIZE (1<<BACKUP_CLUSTER_BITS) +#define BACKUP_BLOCKS_PER_CLUSTER (BACKUP_CLUSTER_SIZE/BDRV_SECTOR_SIZE) + +typedef int BackupDumpFunc (void *opaque,BlockDriverState *bs, +int64_t cluster_num,unsigned char *buf); + +int bdrv_backup_init (BlockDriverState *bs,BackupDumpFunc *backup_dump_cb, +BlockDriverCompletionFunc *backup_complete_cb, +void *opaque); + +#endif /* QEMU_BACKUP_H */
block.c +65 -6
133 lines not on this page · raw message
block.h +2 -0
@@ -172,6 +172,8 @@ int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); int coroutine_fn bdrv_co_copy_on_readv(BlockDriverState *bs,int64_t sector_num,int nb_sectors,QEMUIOVector *qiov); +int coroutine_fn bdrv_co_backup(BlockDriverState *bs, +int64_t sector_num,int nb_sectors); int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num,int nb_sectors,QEMUIOVector *qiov);/*
blockjob.h +10 -0
@@ -50,6 +50,13 @@ typedef struct BlockJobType {* manually. */ void (*complete)(BlockJob *job,Error **errp); + +/** tracked requests */ + int coroutine_fn (*before_read)(BlockDriverState *bs, int64_t sector_num, +int nb_sectors,QEMUIOVector *qiov); + int coroutine_fn (*before_write)(BlockDriverState *bs, int64_t sector_num, +int nb_sectors,QEMUIOVector *qiov); + } BlockJobType;/**
@@ -103,6 +110,9 @@ struct BlockJob {/** Speed that was set with @block_job_set_speed. */ int64_t speed; +/** tracked requests */ +int cluster_size; +/** The completion function that will be called when the job completes. */ BlockDriverCompletionFunc *cb;
Signature · 1 line
1.7.2.5
Quoted 3 lines
Not saying that this is necessarily the best option, but I think reusing existing formats and implementation is always a good thing, so it's an idea to consider.
Yes, I would really like to reuse something. Our current backup software uses 'tar' files, but that is really inefficient. We also analyzed all other available archive formats, but none of them is capable to store sparse files efficiently.
And storing data out of order is beyond the scope of existing format.
docs/backup-rfc.txt line 87
Quoted 6 lines · Dietmar Maurer
+==Disadvantages==
docs/backup-rfc.txt new file +5
-0+ +* we need to define a new archive format + +Note: Most existing archive formats are optimized to store small files +including file attributes. We simply do not need that for VM archives.
Did you look at the VMDK "Stream-Optimized Compressed" subformat?
http://www.vmware.com/support/developer/vddk/vmdk_50_technote.pdf?src=vmdk
It is a stream of compressed "grains" (data). They are out-of-order and each grain comes with the virtual disk lba where the data should be visible to the guest.
The stream also contains "grain tables" and "grain directories". This metadata makes random read access to the file possible once you have downloaded the entire file (i.e. it is seekable). Although tools can choose to consume the stream in sequential order too and ignore the metadata.
In other words, the format is an out-of-order stream of data chunks plus random access lookup tables at the end.
QEMU's block/vmdk.c already has some support for this format although I don't think we generate out-of-order yet.
The benefit of reusing this code is that existing tools can consume these files.
Stefan
Quoted 9 lines
Did you look at the VMDK "Stream-Optimized Compressed" subformat?
http://www.vmware.com/support/developer/vddk/vmdk_50_technote.pdf?
src=vmdkIt is a stream of compressed "grains" (data). They are out-of-order and each grain comes with the virtual disk lba where the data should be visible to the guest.
What kind of license is applied to that specification?
Quoted 11 lines · Dietmar Maurer
Quoted 9 lines
Did you look at the VMDK "Stream-Optimized Compressed" subformat?
http://www.vmware.com/support/developer/vddk/vmdk_50_technote.pdf?
src=vmdkIt is a stream of compressed "grains" (data). They are out-of-order and each grain comes with the virtual disk lba where the data should be visible to the guest.
What kind of license is applied to that specification?
The document I linked came straight from Google Search and you don't need to agree to anything to view it. The document doesn't seem to impose restrictions. QEMU has supported the VMDK format and so have other open source tools for a number of years.
For anything more specific you could search VMware's website and/or check with a lawyer.
Stefan
Quoted 22 lines
-----Original Message-----
From: Stefan Hajnoczi [mailto:[email protected]]
Sent: Donnerstag, 22. November 2012 13:45
To: Dietmar Maurer
Cc: [email protected]; [email protected]
Subject: Re: [Qemu-devel] [PATCH 1/5] RFC: Efficient VM backup for qemu (v1)Quoted 3 lines · Dietmar Maurer
Quoted 3 lines
Did you look at the VMDK "Stream-Optimized Compressed" subformat?
http://www.vmware.com/support/developer/vddk/vmdk_50_technote.pdf?
Quoted 8 lines
Quoted 6 lines
src=vmdk
It is a stream of compressed "grains" (data). They are out-of-order and each grain comes with the virtual disk lba where the data should be visible to the guest.
What kind of license is applied to that specification?
Quoted 7 lines
The document I linked came straight from Google Search and you don't need to agree to anything to view it. The document doesn't seem to impose restrictions. QEMU has supported the VMDK format and so have other open source tools for a number of years.
For anything more specific you could search VMware's website and/or check with a lawyer.
The documents says: VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents
I simply do not have the time to check all those things, which make that format unusable for me.
Anyways, thanks for the link.
Quoted 27 lines · Dietmar Maurer
Quoted 27 lines
-----Original Message-----
From: Stefan Hajnoczi [mailto:[email protected]]
Sent: Donnerstag, 22. November 2012 13:45
To: Dietmar Maurer
Cc: [email protected]; [email protected]
Subject: Re: [Qemu-devel] [PATCH 1/5] RFC: Efficient VM backup for qemu (v1)Quoted 3 lines · Dietmar Maurer
Quoted 3 lines
Did you look at the VMDK "Stream-Optimized Compressed" subformat?
http://www.vmware.com/support/developer/vddk/vmdk_50_technote.pdf?
Quoted 8 lines
Quoted 6 lines
src=vmdk
It is a stream of compressed "grains" (data). They are out-of-order and each grain comes with the virtual disk lba where the data should be visible to the guest.
What kind of license is applied to that specification?
The document I linked came straight from Google Search and you don't need to agree to anything to view it. The document doesn't seem to impose restrictions. QEMU has supported the VMDK format and so have other open source tools for a number of years.
Quoted 6 lines
Quoted 2 lines
For anything more specific you could search VMware's website and/or check with a lawyer.
The documents says: VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents
I simply do not have the time to check all those things, which make that format unusable for me.
In think proxmox ships the QEMU vmdk functionality today? In that case you should check this :).
Stefan
Quoted 9 lines
Quoted 1 line
The documents says: VMware products are covered by one or more
patents
Quoted 3 lines
listed at http://www.vmware.com/go/patents
I simply do not have the time to check all those things, which make that
format unusable for me.
In think proxmox ships the QEMU vmdk functionality today? In that case you should check this :).
Well, and also remove it from the qemu repository? Such things are not compatible with GPL?
Quoted 11 lines · Dietmar Maurer
Quoted 9 lines
Quoted 1 line
The documents says: VMware products are covered by one or more
patents
Quoted 3 lines
listed at http://www.vmware.com/go/patents
I simply do not have the time to check all those things, which make that
format unusable for me.
In think proxmox ships the QEMU vmdk functionality today? In that case you should check this :).
Well, and also remove it from the qemu repository? Such things are not compatible with GPL?
If you are really concerned about this then submit a patch to add ./configure --disable-vmdk, ship QEMU without VMDK, and drop it from your documentation/wiki.
If you're not really concerned, then let's accept that VMDK support is okay.
Stefan
Quoted 23 lines
-----Original Message-----
From: Stefan Hajnoczi [mailto:[email protected]]
Sent: Donnerstag, 22. November 2012 18:02
To: Dietmar Maurer
Cc: [email protected]; [email protected]
Subject: Re: [Qemu-devel] [PATCH 1/5] RFC: Efficient VM backup for qemu (v1)Quoted 11 lines · Dietmar Maurer
Quoted 10 lines
Quoted 1 line
The documents says: VMware products are covered by one or more
patents
Quoted 4 lines
listed at http://www.vmware.com/go/patents
I simply do not have the time to check all those things, which make that
format unusable for me.
In think proxmox ships the QEMU vmdk functionality today? In that case you should check this :).
Quoted 8 lines
Quoted 1 line
Well, and also remove it from the qemu repository? Such things are not
compatible with GPL?
If you are really concerned about this then submit a patch to add ./configure --disable-vmdk, ship QEMU without VMDK, and drop it from your documentation/wiki.
If you're not really concerned, then let's accept that VMDK support is okay.
I simply don't want to waste time one something with unclear License issues. So I will not work on such format.
Don't get me wrong - that is just my personal opinion.
Quoted 4 lines
Did you look at the VMDK "Stream-Optimized Compressed" subformat?
http://www.vmware.com/support/developer/vddk/vmdk_50_technote.pdf?
src=vmdk
Max file size 2TB?
Quoted 6 lines · Dietmar Maurer
Quoted 4 lines
Did you look at the VMDK "Stream-Optimized Compressed" subformat?
http://www.vmware.com/support/developer/vddk/vmdk_50_technote.pdf?
src=vmdkMax file size 2TB?
That is for a single .vmdk file. But vmdks can also be split across multiple files ("extents") so you can get more than 2TB.
QEMU has some support for reading vmdks with extents, but I think we never create files like this today.
Stefan
Quoted 9 lines
It is a stream of compressed "grains" (data). They are out-of-order and each grain comes with the virtual disk lba where the data should be visible to the guest.
The stream also contains "grain tables" and "grain directories". This metadata makes random read access to the file possible once you have downloaded the entire file (i.e. it is seekable). Although tools can choose to consume the stream in sequential order too and ignore the metadata.
Quoted 7 lines
In other words, the format is an out-of-order stream of data chunks plus random access lookup tables at the end.
QEMU's
block/vmdk.calready has some support for this format although I don't think we generate out-of-order yet.The benefit of reusing this code is that existing tools can consume these files.
Compression format is hardcoded to RFC 1951 (defalte). I think this is a major disadvantage, because it is really slow (compared to lzop).
Quoted 12 lines · Dietmar Maurer
Quoted 12 lines
It is a stream of compressed "grains" (data). They are out-of-order and each grain comes with the virtual disk lba where the data should be visible to the guest.
The stream also contains "grain tables" and "grain directories". This metadata makes random read access to the file possible once you have downloaded the entire file (i.e. it is seekable). Although tools can choose to consume the stream in sequential order too and ignore the metadata.
In other words, the format is an out-of-order stream of data chunks plus random access lookup tables at the end.
Quoted 7 lines
Quoted 4 lines
QEMU's
block/vmdk.calready has some support for this format although I don't think we generate out-of-order yet.The benefit of reusing this code is that existing tools can consume these files.
Compression format is hardcoded to RFC 1951 (defalte). I think this is a major disadvantage, because it is really slow (compared to lzop).
It's a naughty thing to do but we could simply pick a new constant and support LZO as an incompatible option. The file is then no longer compatible with existing vmdk tools but at least we then have a choice of using compatible deflate or the LZO extension.
VMDK already has 99% of what you need and we already have a bunch of code to handle this format. This seems like a good opportunity to flesh out VMDK support and avoid reinventing the wheel.
Stefan
Quoted 4 lines
It's a naughty thing to do but we could simply pick a new constant and support LZO as an incompatible option. The file is then no longer compatible with existing vmdk tools but at least we then have a choice of using compatible deflate or the LZO extension.
To be 100% incompatible to existing tools? That would remove any advantage.
Quoted 3 lines
VMDK already has 99% of what you need and we already have a bunch of code to handle this format. This seems like a good opportunity to flesh out VMDK support and avoid reinventing the wheel.
Using 'probably' patented software is a bad idea - I will not go that way.
Quoted 6 lines · Dietmar Maurer
Quoted 4 lines
It's a naughty thing to do but we could simply pick a new constant and support LZO as an incompatible option. The file is then no longer compatible with existing vmdk tools but at least we then have a choice of using compatible deflate or the LZO extension.
To be 100% incompatible to existing tools? That would remove any advantage.
No, it should be an option. Users who care about compatibility can use deflate.
Stefan
Quoted 4 lines
Did you look at the VMDK "Stream-Optimized Compressed" subformat?
http://www.vmware.com/support/developer/vddk/vmdk_50_technote.pdf?
src=vmdk
And is that covered by any patents?
Quoted 9 lines · Stefan Hajnoczi
docs/backup-rfc.txt line 87
Quoted 6 lines · Dietmar Maurer
+==Disadvantages==
docs/backup-rfc.txt new file +5
-0+ +* we need to define a new archive format + +Note: Most existing archive formats are optimized to store small files +including file attributes. We simply do not need that for VM archives.Did you look at the VMDK "Stream-Optimized Compressed" subformat?
We've gone down several sub-threads discussing whether VMDK is suitable. I want to summarize why this is a good approach:
The VMDK format already allows for out-of-order data and is supported by existing tools - this is very important for backups where people are (rightfully) paranoid about putting their backups in an obscure format. They want to be able to access their data years later, whether your tool is still around or not.
QEMU's implementation has partial support for Stream-Optimized Compressed images. If you complete the code for this subformat, not only does this benefit the VM Backup feature, but it also makes qemu-img convert more powerful for everyone. I hope we can kill two birds with one stone here.
Stefan
Quoted 10 lines
Quoted 1 line
Did you look at the VMDK "Stream-Optimized Compressed" subformat?
We've gone down several sub-threads discussing whether VMDK is suitable. I want to summarize why this is a good approach:
The VMDK format already allows for out-of-order data and is supported by existing tools - this is very important for backups where people are (rightfully) paranoid about putting their backups in an obscure format. They want to be able to access their data years later, whether your tool is still around or not.
The VMDK format has strong disadvantages:
- unclear License (the spec links to patents)
- they use a very slow compression algorithm (deflate), which makes it unusable for backup
Quoted 11 lines · Dietmar Maurer
Quoted 10 lines
Quoted 1 line
Did you look at the VMDK "Stream-Optimized Compressed" subformat?
We've gone down several sub-threads discussing whether VMDK is suitable. I want to summarize why this is a good approach:
The VMDK format already allows for out-of-order data and is supported by existing tools - this is very important for backups where people are (rightfully) paranoid about putting their backups in an obscure format. They want to be able to access their data years later, whether your tool is still around or not.
Quoted 3 lines
The VMDK format has strong disadvantages:
- unclear License (the spec links to patents)
I've already pointed out that you're taking an inconsistent position on this point. It's FUD.
Quoted 1 line
- they use a very slow compression algorithm (deflate), which makes it unusable for backup
I've already pointed out that we can optionally support other algorithms.
Stefan
Quoted 14 lines · Stefan Hajnoczi
Quoted 13 lines · Dietmar Maurer
Quoted 10 lines
Quoted 1 line
Did you look at the VMDK "Stream-Optimized Compressed" subformat?
We've gone down several sub-threads discussing whether VMDK is suitable. I want to summarize why this is a good approach:
The VMDK format already allows for out-of-order data and is supported by existing tools - this is very important for backups where people are (rightfully) paranoid about putting their backups in an obscure format. They want to be able to access their data years later, whether your tool is still around or not.
The VMDK format has strong disadvantages:
Quoted 8 lines
Quoted 1 line
- unclear License (the spec links to patents)
I've already pointed out that you're taking an inconsistent position on this point. It's FUD.
Quoted 1 line
- they use a very slow compression algorithm (deflate), which makes it unusable for backup
I've already pointed out that we can optionally support other algorithms.
To make progress here I'll review the RFC patches. VMDK or not isn't the main thing, a backup feature like this looks interesting.
Stefan
Quoted 2 lines
To make progress here I'll review the RFC patches. VMDK or not isn't the main thing, a backup feature like this looks interesting.
Yes, a 'review' would be great - thanks.
- Dietmar
Quoted 11 lines
Quoted 3 lines
The VMDK format has strong disadvantages:
- unclear License (the spec links to patents)
I've already pointed out that you're taking an inconsistent position on this point. It's FUD.
Quoted 2 lines
- they use a very slow compression algorithm (deflate), which makes it unusable for backup
I've already pointed out that we can optionally support other algorithms.
Well, I guess we both pointed out our opinions.
I will try to implement some kind of plugging architecture for backup formats. That way we can implement/support more than one format.
Quoted 5 lines
The VMDK format has strong disadvantages:
- unclear License (the spec links to patents)
- they use a very slow compression algorithm (deflate), which makes it unusable for backup
Seems they do not support multiple configuration files. You can only a single text block, and that needs to contain vmware specific info. So where do I add my qemu related config?
Quoted 9 lines · Dietmar Maurer
Quoted 5 lines
The VMDK format has strong disadvantages:
- unclear License (the spec links to patents)
- they use a very slow compression algorithm (deflate), which makes it unusable for backupSeems they do not support multiple configuration files. You can only a single text block, and that needs to contain vmware specific info. So where do I add my qemu related config?
This is true. QEMU uses a VMDK as a single disk image. To handle multiple disks there would need to be multiple images plus a vmstate or config file.
Stefan
Quoted 4 lines
QEMU's implementation has partial support for Stream-Optimized Compressed images. If you complete the code for this subformat, not only does this benefit the VM Backup feature, but it also makes qemu-img convert more powerful for everyone. I hope we can kill two birds with one stone
The doc contain the following link:
http://www.vmware.com/download/patents.html
I simply have no idea how to check all those patents. How can someone tell that they do not cover things in the specs? I am really curios?
Quoted 11 lines · Dietmar Maurer
Quoted 4 lines
QEMU's implementation has partial support for Stream-Optimized Compressed images. If you complete the code for this subformat, not only does this benefit the VM Backup feature, but it also makes qemu-img convert more powerful for everyone. I hope we can kill two birds with one stone
The doc contain the following link:
http://www.vmware.com/download/patents.html
I simply have no idea how to check all those patents. How can someone tell that they do not cover things in the specs? I am really curios?
If you want to investigate it then you would look at each one or use search engines to make it easier (skip all the non-disk image related patents).
But keep in mind that any other company out there could have a patent on out-of-order data in an image file or other aspects of what you're proposing. Reinventing the wheel may not stop you from infringing on their patents so the fact that VMware may or may not have patents doesn't change things if you're really trying to find possible issues.
This is why SQLite has a policy of only using algorithms that are older than 17 years, see comment by drh:
http://www.sqlite.org/cvstrac/wiki?p=BlueSky
Stefan
Quoted 2 lines
But keep in mind that any other company out there could have a patent on out-of-order data in an image file or other aspects of what you're proposing.
Sorry, but the vmware docs explicitly include a pointer to those patents. So this is something completely different to me.
Quoted 5 lines
The VMDK format already allows for out-of-order data and is supported by existing tools - this is very important for backups where people are (rightfully) paranoid about putting their backups in an obscure format. They want to be able to access their data years later, whether your tool is still around or not.
Anything we will add to the qemu source fulfills those properties. Or do you really think qemu will disappear soon?
Besides, the VMA format is much simpler than the vmdk format. Thus I consider it safer (and not 'obscure').
Quoted 132 lines · Dietmar Maurer
This series provides a way to efficiently backup VMs.
* Backup to a single archive file
* Backup contain all data to restore VM (full backup)
* Do not depend on storage type or image format
* Avoid use of temporary storage
* store sparse images efficientlyThe file
docs/backup-rfc.txtcontains more details.Signed-off-by Dietmar Maurer <[email protected]>--- docs/backup-rfc.txt | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 119 insertions(+), 0 deletions(-)create mode 100644
docs/backup-rfc.txtdocs/backup-rfc.txt new file +109
-0@@ -0,0 +1,119 @@ +RFC: Efficient VM backup for qemu + +=Requirements= + +* Backup to a single archive file +* Backup needs to contain all data to restore VM (full backup) +* Do not depend on storage type or image format +* Avoid use of temporary storage +* store sparse images efficiently + +=Introduction= + +Most VM backup solutions use some kind of snapshot to get a consistent +VM view at a specific point in time. For example, we previously used +LVM to create a snapshot of all used VM images, which are then copied +into a tar file. + +That basically means that any data written during backup involve +considerable overhead. For LVM we get the following steps: + +1.) read original data (VM write) +2.) write original data into snapshot (VM write) +3.) write new data (VM write) +4.) read data from snapshot (backup) +5.) write data from snapshot into tar file (backup) + +Another approach to backup VM images is to create a new qcow2 image +which use the old image as base. During backup, writes are redirected +to the new image, so the old image represents a 'snapshot'. After +backup, data need to be copied back from new image into the old +one (commit). So a simple write during backup triggers the following +steps: + +1.) write new data to new image (VM write) +2.) read data from old image (backup) +3.) write data from old image into tar file (backup) + +4.) read data from new image (commit) +5.) write data to old image (commit) + +This is in fact the same overhead as before. Other tools like qemu +livebackup produces similar overhead (2 reads, 3 writes). + +Some storage types/formats supports internal snapshots using some kind +of reference counting (rados, sheepdog, dm-thin, qcow2). It would be possible +to use that for backups, but for now we want to be storage-independent. + +Note: It turned out that taking a qcow2 snapshot can take a very long +time on larger files. + +=Make it more efficient= + +The be more efficient, we simply need to avoid unnecessary steps. The +following steps are always required: + +1.) read old data before it gets overwritten +2.) write that data into the backup archive +3.) write new data (VM write) + +As you can see, this involves only one read, an two writes. + +To make that work, our backup archive need to be able to store image +data 'out of order'. It is important to notice that this will not work +with traditional archive formats like tar. + +During backup we simply intercept writes, then read existing data and +store that directly into the archive. After that we can continue the +write. + +==Advantages== + +* very good performance (1 read, 2 writes) +* works on any storage type and image format. +* avoid usage of temporary storage +* we can define a new and simple archive format, which is able to + store sparse files efficiently. + +Note: Storing sparse files is a mess with existing archive +formats. For example, tar requires information about holes at the +beginning of the archive. + +==Disadvantages== + +* we need to define a new archive format + +Note: Most existing archive formats are optimized to store small files +including file attributes. We simply do not need that for VM archives. + +* archive contains data 'out of order' + +If you want to access image data in sequential order, you need to +re-order archive data. It would be possible to to that on the fly, +using temporary files. + +Fortunately, a normal restore/extract works perfectly with 'out of +order' data, because the target files are seekable. + +* slow backup storage can slow down VM during backup + +It is important to note that we only do sequential writes to the +backup storage. Furthermore one can compress the backup stream. IMHO, +it is better to slow down the VM a bit. All other solutions creates +large amounts of temporary data during backup. + +=Archive format requirements= + +The basic requirement for such new format is that we can store image +date 'out of order'. It is also very likely that we have less than 256 +drives/images per VM, and we want to be able to store VM configuration
docs/backup-rfc.txt line 119
Quoted 10 lines
docs/backup-rfc.txt new file +10
-0+files. + +We have defined a very simply format with those properties, see: + +docs/specs/vma_spec.txt + +Please let us know if you know an existing format which provides the +same functionality. + +
Just want to confirm something to understand it better:
you are backing up the block image not including VM memory state right? I am considering a way to do live Savevm including memory and device state, so wonder if you already had a solution for it.
Signature · 3 lines
Best Regards Wenchao Xia
Quoted 4 lines
Just want to confirm something to understand it better:
you are backing up the block image not including VM memory state right? I am considering a way to do live Savevm including memory and device state, so wonder if you already had a solution for it.
Yes, I have already code for that.
Quoted 8 lines · Dietmar Maurer
Quoted 4 lines
Just want to confirm something to understand it better:
you are backing up the block image not including VM memory state right? I am considering a way to do live Savevm including memory and device state, so wonder if you already had a solution for it.Yes, I have already code for that.
Does those code for VM memory and device state lively save/restore
included in this patch serials? I quickly reviewed the patches but did not found a hook to save VM memory state? Hope you can enlight me your way, my thoughts is do live migration into qcow2 file, but your code seems not touched qcow2 images.
Signature · 3 lines
Best Regards Wenchao Xia
Quoted 5 lines
Does those code for VM memory and device state lively save/restore
included in this patch serials? I quickly reviewed the patches but did not found a hook to save VM memory state? Hope you can enlight me your way, my thoughts is do live migration into qcow2 file, but your code seems not touched qcow2 images.
I will post that code in a few days.