cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
218e99
From eb7381f07b22955557a2b7ea469c5bf5aa39281e Mon Sep 17 00:00:00 2001
218e99
From: Orit Wasserman <owasserm@redhat.com>
218e99
Date: Wed, 9 Oct 2013 10:09:09 +0200
218e99
Subject: [PATCH 14/25] block-migration: efficiently encode zero blocks
218e99
218e99
RH-Author: Orit Wasserman <owasserm@redhat.com>
218e99
Message-id: <1381313355-15641-5-git-send-email-owasserm@redhat.com>
218e99
Patchwork-id: 54800
218e99
O-Subject: [RHEL7.0 qemu-kvm v2 04/10] block-migration: efficiently encode zero blocks
218e99
Bugzilla: 921465
218e99
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
218e99
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
218e99
RH-Acked-by: Juan Quintela <quintela@redhat.com>
218e99
218e99
From: Peter Lieven <pl@kamp.de>
218e99
218e99
this patch adds a efficient encoding for zero blocks by
218e99
adding a new flag indicating a block is completely zero.
218e99
218e99
additionally bdrv_write_zeros() is used at the destination
218e99
to efficiently write these zeroes. depending on the implementation
218e99
this avoids that the destination target gets fully provisioned.
218e99
218e99
Signed-off-by: Peter Lieven <pl@kamp.de>
218e99
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
218e99
(cherry picked from commit 323004a39d4d8d33c744a5b108f80bfe6402fca3)
218e99
Conflicts:
218e99
	include/migration/migration.h
218e99
	qapi-schema.json
218e99
---
218e99
 block-migration.c             | 32 ++++++++++++++++++++++++++------
218e99
 include/migration/migration.h |  2 ++
218e99
 migration.c                   |  9 +++++++++
218e99
 qapi-schema.json              |  8 +++++++-
218e99
 4 files changed, 44 insertions(+), 7 deletions(-)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 block-migration.c             |   32 ++++++++++++++++++++++++++------
218e99
 include/migration/migration.h |    2 ++
218e99
 migration.c                   |    9 +++++++++
218e99
 qapi-schema.json              |    8 +++++++-
218e99
 4 files changed, 44 insertions(+), 7 deletions(-)
218e99
218e99
diff --git a/block-migration.c b/block-migration.c
218e99
index 2fd7699..f803f20 100644
218e99
--- a/block-migration.c
218e99
+++ b/block-migration.c
218e99
@@ -29,6 +29,7 @@
218e99
 #define BLK_MIG_FLAG_DEVICE_BLOCK       0x01
218e99
 #define BLK_MIG_FLAG_EOS                0x02
218e99
 #define BLK_MIG_FLAG_PROGRESS           0x04
218e99
+#define BLK_MIG_FLAG_ZERO_BLOCK         0x08
218e99
 
218e99
 #define MAX_IS_ALLOCATED_SEARCH 65536
218e99
 
218e99
@@ -80,6 +81,7 @@ typedef struct BlkMigState {
218e99
     int shared_base;
218e99
     QSIMPLEQ_HEAD(bmds_list, BlkMigDevState) bmds_list;
218e99
     int64_t total_sector_sum;
218e99
+    bool zero_blocks;
218e99
 
218e99
     /* Protected by lock.  */
218e99
     QSIMPLEQ_HEAD(blk_list, BlkMigBlock) blk_list;
218e99
@@ -114,16 +116,30 @@ static void blk_mig_unlock(void)
218e99
 static void blk_send(QEMUFile *f, BlkMigBlock * blk)
218e99
 {
218e99
     int len;
218e99
+    uint64_t flags = BLK_MIG_FLAG_DEVICE_BLOCK;
218e99
+
218e99
+    if (block_mig_state.zero_blocks &&
218e99
+        buffer_is_zero(blk->buf, BLOCK_SIZE)) {
218e99
+        flags |= BLK_MIG_FLAG_ZERO_BLOCK;
218e99
+    }
218e99
 
218e99
     /* sector number and flags */
218e99
     qemu_put_be64(f, (blk->sector << BDRV_SECTOR_BITS)
218e99
-                     | BLK_MIG_FLAG_DEVICE_BLOCK);
218e99
+                     | flags);
218e99
 
218e99
     /* device name */
218e99
     len = strlen(blk->bmds->bs->device_name);
218e99
     qemu_put_byte(f, len);
218e99
     qemu_put_buffer(f, (uint8_t *)blk->bmds->bs->device_name, len);
218e99
 
218e99
+    /* if a block is zero we need to flush here since the network
218e99
+     * bandwidth is now a lot higher than the storage device bandwidth.
218e99
+     * thus if we queue zero blocks we slow down the migration */
218e99
+    if (flags & BLK_MIG_FLAG_ZERO_BLOCK) {
218e99
+        qemu_fflush(f);
218e99
+        return;
218e99
+    }
218e99
+
218e99
     qemu_put_buffer(f, blk->buf, BLOCK_SIZE);
218e99
 }
218e99
 
218e99
@@ -344,6 +360,7 @@ static void init_blk_migration(QEMUFile *f)
218e99
     block_mig_state.total_sector_sum = 0;
218e99
     block_mig_state.prev_progress = -1;
218e99
     block_mig_state.bulk_completed = 0;
218e99
+    block_mig_state.zero_blocks = migrate_zero_blocks();
218e99
 
218e99
     bdrv_iterate(init_blk_migration_it, NULL);
218e99
 }
218e99
@@ -762,12 +779,15 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
218e99
                 nr_sectors = BDRV_SECTORS_PER_DIRTY_CHUNK;
218e99
             }
218e99
 
218e99
-            buf = g_malloc(BLOCK_SIZE);
218e99
-
218e99
-            qemu_get_buffer(f, buf, BLOCK_SIZE);
218e99
-            ret = bdrv_write(bs, addr, buf, nr_sectors);
218e99
+            if (flags & BLK_MIG_FLAG_ZERO_BLOCK) {
218e99
+                ret = bdrv_write_zeroes(bs, addr, nr_sectors);
218e99
+            } else {
218e99
+                buf = g_malloc(BLOCK_SIZE);
218e99
+                qemu_get_buffer(f, buf, BLOCK_SIZE);
218e99
+                ret = bdrv_write(bs, addr, buf, nr_sectors);
218e99
+                g_free(buf);
218e99
+            }
218e99
 
218e99
-            g_free(buf);
218e99
             if (ret < 0) {
218e99
                 return ret;
218e99
             }
218e99
diff --git a/include/migration/migration.h b/include/migration/migration.h
218e99
index 1fc2666..f1519dd 100644
218e99
--- a/include/migration/migration.h
218e99
+++ b/include/migration/migration.h
218e99
@@ -119,6 +119,8 @@ void migrate_add_blocker(Error *reason);
218e99
  */
218e99
 void migrate_del_blocker(Error *reason);
218e99
 
218e99
+bool migrate_zero_blocks(void);
218e99
+
218e99
 bool migrate_auto_converge(void);
218e99
 
218e99
 int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen,
218e99
diff --git a/migration.c b/migration.c
218e99
index 177fc22..cc0e649 100644
218e99
--- a/migration.c
218e99
+++ b/migration.c
218e99
@@ -483,6 +483,15 @@ bool migrate_auto_converge(void)
218e99
     return s->enabled_capabilities[MIGRATION_CAPABILITY_AUTO_CONVERGE];
218e99
 }
218e99
 
218e99
+bool migrate_zero_blocks(void)
218e99
+{
218e99
+    MigrationState *s;
218e99
+
218e99
+    s = migrate_get_current();
218e99
+
218e99
+    return s->enabled_capabilities[MIGRATION_CAPABILITY_ZERO_BLOCKS];
218e99
+}
218e99
+
218e99
 int migrate_use_xbzrle(void)
218e99
 {
218e99
     MigrationState *s;
218e99
diff --git a/qapi-schema.json b/qapi-schema.json
218e99
index 3936337..a717fbf 100644
218e99
--- a/qapi-schema.json
218e99
+++ b/qapi-schema.json
218e99
@@ -605,10 +605,16 @@
218e99
 # @auto-converge: If enabled, QEMU will automatically throttle down the guest
218e99
 #          to speed up convergence of RAM migration. (since 1.6)
218e99
 #
218e99
+# @zero-blocks: During storage migration encode blocks of zeroes efficiently. This
218e99
+#          essentially saves 1MB of zeroes per block on the wire. Enabling requires
218e99
+#          source and target VM to support this feature. To enable it is sufficient
218e99
+#          to enable the capability on the source VM. The feature is disabled by
218e99
+#          default. (since 1.6)
218e99
+#
218e99
 # Since: 1.2
218e99
 ##
218e99
 { 'enum': 'MigrationCapability',
218e99
-  'data': ['xbzrle', 'auto-converge'] }
218e99
+  'data': ['xbzrle', 'auto-converge', 'zero-blocks'] }
218e99
 
218e99
 ##
218e99
 # @MigrationCapabilityStatus
218e99
-- 
218e99
1.7.1
218e99