cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-block-Move-initialisation-of-BlockLimits-to-bdrv_ref.patch

0a122b
From 69a283009c8736d5e063b6721b47f4b453595c15 Mon Sep 17 00:00:00 2001
0a122b
From: Kevin Wolf <kwolf@redhat.com>
0a122b
Date: Wed, 11 Dec 2013 19:26:16 +0100
0a122b
Subject: [PATCH 02/37] block: Move initialisation of BlockLimits to bdrv_refresh_limits()
0a122b
0a122b
Message-id: <1392117622-28812-3-git-send-email-kwolf@redhat.com>
0a122b
Patchwork-id: 57167
0a122b
O-Subject: [RHEL-7.0 qemu-kvm PATCH v2 02/37] block: Move initialisation of BlockLimits to bdrv_refresh_limits()
0a122b
Bugzilla: 748906
0a122b
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
0a122b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
RH-Acked-by: Max Reitz <mreitz@redhat.com>
0a122b
0a122b
This function separates filling the BlockLimits from bdrv_open(), which
0a122b
allows it to call it from other operations which may change the limits
0a122b
(e.g. modifications to the backing file chain or bdrv_reopen)
0a122b
0a122b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
0a122b
Reviewed-by: Max Reitz <mreitz@redhat.com>
0a122b
Reviewed-by: Benoit Canet <benoit@irqsave.net>
0a122b
(cherry picked from commit d34682cd4a06efe9ee3fc8cb7e8a0ea445299989)
0a122b
0a122b
Conflicts:
0a122b
	block/qed.c
0a122b
0a122b
Trivial context-only conflict.
0a122b
0a122b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
0a122b
---
0a122b
 block.c                   | 18 ++++++++++++++++++
0a122b
 block/iscsi.c             | 46 +++++++++++++++++++++++++++++-----------------
0a122b
 block/qcow2.c             | 11 ++++++++++-
0a122b
 block/qed.c               | 11 ++++++++++-
0a122b
 block/vmdk.c              | 22 ++++++++++++++++++----
0a122b
 include/block/block_int.h |  2 ++
0a122b
 6 files changed, 87 insertions(+), 23 deletions(-)
0a122b
---
0a122b
 block.c                   |   18 +++++++++++++++++
0a122b
 block/iscsi.c             |   46 ++++++++++++++++++++++++++++----------------
0a122b
 block/qcow2.c             |   11 +++++++++-
0a122b
 block/qed.c               |   11 +++++++++-
0a122b
 block/vmdk.c              |   22 +++++++++++++++++---
0a122b
 include/block/block_int.h |    2 +
0a122b
 6 files changed, 87 insertions(+), 23 deletions(-)
0a122b
0a122b
diff --git a/block.c b/block.c
0a122b
index df0adf3..26eebcc 100644
0a122b
--- a/block.c
0a122b
+++ b/block.c
0a122b
@@ -446,6 +446,19 @@ int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
0a122b
     return ret;
0a122b
 }
0a122b
 
0a122b
+static int bdrv_refresh_limits(BlockDriverState *bs)
0a122b
+{
0a122b
+    BlockDriver *drv = bs->drv;
0a122b
+
0a122b
+    memset(&bs->bl, 0, sizeof(bs->bl));
0a122b
+
0a122b
+    if (drv && drv->bdrv_refresh_limits) {
0a122b
+        return drv->bdrv_refresh_limits(bs);
0a122b
+    }
0a122b
+
0a122b
+    return 0;
0a122b
+}
0a122b
+
0a122b
 /*
0a122b
  * Create a uniquely-named empty temporary file.
0a122b
  * Return 0 upon success, otherwise a negative errno value.
0a122b
@@ -797,6 +810,8 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
0a122b
         goto free_and_fail;
0a122b
     }
0a122b
 
0a122b
+    bdrv_refresh_limits(bs);
0a122b
+
0a122b
 #ifndef _WIN32
0a122b
     if (bs->is_temporary) {
0a122b
         assert(filename != NULL);
0a122b
@@ -984,6 +999,9 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
0a122b
                 bs->backing_hd->file->filename);
0a122b
     }
0a122b
 
0a122b
+    /* Recalculate the BlockLimits with the backing file */
0a122b
+    bdrv_refresh_limits(bs);
0a122b
+
0a122b
     return 0;
0a122b
 }
0a122b
 
0a122b
diff --git a/block/iscsi.c b/block/iscsi.c
0a122b
index 1c5b0a2..83e4f15 100644
0a122b
--- a/block/iscsi.c
0a122b
+++ b/block/iscsi.c
0a122b
@@ -1445,23 +1445,6 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
0a122b
                sizeof(struct scsi_inquiry_block_limits));
0a122b
         scsi_free_scsi_task(task);
0a122b
         task = NULL;
0a122b
-
0a122b
-        if (iscsilun->bl.max_unmap < 0xffffffff) {
0a122b
-            bs->bl.max_discard = sector_lun2qemu(iscsilun->bl.max_unmap,
0a122b
-                                                 iscsilun);
0a122b
-        }
0a122b
-        bs->bl.discard_alignment = sector_lun2qemu(iscsilun->bl.opt_unmap_gran,
0a122b
-                                                   iscsilun);
0a122b
-
0a122b
-        if (iscsilun->bl.max_ws_len < 0xffffffff) {
0a122b
-            bs->bl.max_write_zeroes = sector_lun2qemu(iscsilun->bl.max_ws_len,
0a122b
-                                                      iscsilun);
0a122b
-        }
0a122b
-        bs->bl.write_zeroes_alignment = sector_lun2qemu(iscsilun->bl.opt_unmap_gran,
0a122b
-                                                        iscsilun);
0a122b
-
0a122b
-        bs->bl.opt_transfer_length = sector_lun2qemu(iscsilun->bl.opt_xfer_len,
0a122b
-                                                     iscsilun);
0a122b
     }
0a122b
 
0a122b
 #if defined(LIBISCSI_FEATURE_NOP_COUNTER)
0a122b
@@ -1506,6 +1489,34 @@ static void iscsi_close(BlockDriverState *bs)
0a122b
     memset(iscsilun, 0, sizeof(IscsiLun));
0a122b
 }
0a122b
 
0a122b
+static int iscsi_refresh_limits(BlockDriverState *bs)
0a122b
+{
0a122b
+    IscsiLun *iscsilun = bs->opaque;
0a122b
+
0a122b
+    /* We don't actually refresh here, but just return data queried in
0a122b
+     * iscsi_open(): iscsi targets don't change their limits. */
0a122b
+    if (iscsilun->lbp.lbpu || iscsilun->lbp.lbpws) {
0a122b
+        if (iscsilun->bl.max_unmap < 0xffffffff) {
0a122b
+            bs->bl.max_discard = sector_lun2qemu(iscsilun->bl.max_unmap,
0a122b
+                                                 iscsilun);
0a122b
+        }
0a122b
+        bs->bl.discard_alignment = sector_lun2qemu(iscsilun->bl.opt_unmap_gran,
0a122b
+                                                   iscsilun);
0a122b
+
0a122b
+        if (iscsilun->bl.max_ws_len < 0xffffffff) {
0a122b
+            bs->bl.max_write_zeroes = sector_lun2qemu(iscsilun->bl.max_ws_len,
0a122b
+                                                      iscsilun);
0a122b
+        }
0a122b
+        bs->bl.write_zeroes_alignment = sector_lun2qemu(iscsilun->bl.opt_unmap_gran,
0a122b
+                                                        iscsilun);
0a122b
+
0a122b
+        bs->bl.opt_transfer_length = sector_lun2qemu(iscsilun->bl.opt_xfer_len,
0a122b
+                                                     iscsilun);
0a122b
+    }
0a122b
+
0a122b
+    return 0;
0a122b
+}
0a122b
+
0a122b
 /* We have nothing to do for iSCSI reopen, stub just returns
0a122b
  * success */
0a122b
 static int iscsi_reopen_prepare(BDRVReopenState *state,
0a122b
@@ -1626,6 +1637,7 @@ static BlockDriver bdrv_iscsi = {
0a122b
     .bdrv_getlength  = iscsi_getlength,
0a122b
     .bdrv_get_info   = iscsi_get_info,
0a122b
     .bdrv_truncate   = iscsi_truncate,
0a122b
+    .bdrv_refresh_limits = iscsi_refresh_limits,
0a122b
 
0a122b
     .bdrv_co_get_block_status = iscsi_co_get_block_status,
0a122b
     .bdrv_co_discard      = iscsi_co_discard,
0a122b
diff --git a/block/qcow2.c b/block/qcow2.c
0a122b
index f6307af..05ea0cd 100644
0a122b
--- a/block/qcow2.c
0a122b
+++ b/block/qcow2.c
0a122b
@@ -718,7 +718,6 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
0a122b
     }
0a122b
 
0a122b
     qemu_opts_del(opts);
0a122b
-    bs->bl.write_zeroes_alignment = s->cluster_sectors;
0a122b
 
0a122b
     if (s->use_lazy_refcounts && s->qcow_version < 3) {
0a122b
         error_setg(errp, "Lazy refcounts require a qcow2 image with at least "
0a122b
@@ -751,6 +750,15 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
0a122b
     return ret;
0a122b
 }
0a122b
 
0a122b
+static int qcow2_refresh_limits(BlockDriverState *bs)
0a122b
+{
0a122b
+    BDRVQcowState *s = bs->opaque;
0a122b
+
0a122b
+    bs->bl.write_zeroes_alignment = s->cluster_sectors;
0a122b
+
0a122b
+    return 0;
0a122b
+}
0a122b
+
0a122b
 static int qcow2_set_key(BlockDriverState *bs, const char *key)
0a122b
 {
0a122b
     BDRVQcowState *s = bs->opaque;
0a122b
@@ -2262,6 +2270,7 @@ static BlockDriver bdrv_qcow2 = {
0a122b
 
0a122b
     .bdrv_change_backing_file   = qcow2_change_backing_file,
0a122b
 
0a122b
+    .bdrv_refresh_limits        = qcow2_refresh_limits,
0a122b
     .bdrv_invalidate_cache      = qcow2_invalidate_cache,
0a122b
 
0a122b
     .create_options = qcow2_create_options,
0a122b
diff --git a/block/qed.c b/block/qed.c
0a122b
index fb8ccd5..da68152 100644
0a122b
--- a/block/qed.c
0a122b
+++ b/block/qed.c
0a122b
@@ -495,7 +495,6 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags,
0a122b
         }
0a122b
     }
0a122b
 
0a122b
-    bs->bl.write_zeroes_alignment = s->header.cluster_size >> BDRV_SECTOR_BITS;
0a122b
     s->need_check_timer = qemu_new_timer_ns(vm_clock,
0a122b
                                             qed_need_check_timer_cb, s);
0a122b
 
0a122b
@@ -507,6 +506,15 @@ out:
0a122b
     return ret;
0a122b
 }
0a122b
 
0a122b
+static int bdrv_qed_refresh_limits(BlockDriverState *bs)
0a122b
+{
0a122b
+    BDRVQEDState *s = bs->opaque;
0a122b
+
0a122b
+    bs->bl.write_zeroes_alignment = s->header.cluster_size >> BDRV_SECTOR_BITS;
0a122b
+
0a122b
+    return 0;
0a122b
+}
0a122b
+
0a122b
 /* We have nothing to do for QED reopen, stubs just return
0a122b
  * success */
0a122b
 static int bdrv_qed_reopen_prepare(BDRVReopenState *state,
0a122b
@@ -1616,6 +1624,7 @@ static BlockDriver bdrv_qed = {
0a122b
     .bdrv_truncate            = bdrv_qed_truncate,
0a122b
     .bdrv_getlength           = bdrv_qed_getlength,
0a122b
     .bdrv_get_info            = bdrv_qed_get_info,
0a122b
+    .bdrv_refresh_limits      = bdrv_qed_refresh_limits,
0a122b
     .bdrv_change_backing_file = bdrv_qed_change_backing_file,
0a122b
     .bdrv_invalidate_cache    = bdrv_qed_invalidate_cache,
0a122b
     .bdrv_check               = bdrv_qed_check,
0a122b
diff --git a/block/vmdk.c b/block/vmdk.c
0a122b
index a1994a4..a966715 100644
0a122b
--- a/block/vmdk.c
0a122b
+++ b/block/vmdk.c
0a122b
@@ -428,10 +428,6 @@ static int vmdk_add_extent(BlockDriverState *bs,
0a122b
     extent->l2_size = l2_size;
0a122b
     extent->cluster_sectors = flat ? sectors : cluster_sectors;
0a122b
 
0a122b
-    if (!flat) {
0a122b
-        bs->bl.write_zeroes_alignment =
0a122b
-            MAX(bs->bl.write_zeroes_alignment, cluster_sectors);
0a122b
-    }
0a122b
     if (s->num_extents > 1) {
0a122b
         extent->end_sector = (*(extent - 1)).end_sector + extent->sectors;
0a122b
     } else {
0a122b
@@ -886,6 +882,23 @@ fail:
0a122b
     return ret;
0a122b
 }
0a122b
 
0a122b
+
0a122b
+static int vmdk_refresh_limits(BlockDriverState *bs)
0a122b
+{
0a122b
+    BDRVVmdkState *s = bs->opaque;
0a122b
+    int i;
0a122b
+
0a122b
+    for (i = 0; i < s->num_extents; i++) {
0a122b
+        if (!s->extents[i].flat) {
0a122b
+            bs->bl.write_zeroes_alignment =
0a122b
+                MAX(bs->bl.write_zeroes_alignment,
0a122b
+                    s->extents[i].cluster_sectors);
0a122b
+        }
0a122b
+    }
0a122b
+
0a122b
+    return 0;
0a122b
+}
0a122b
+
0a122b
 static int get_whole_cluster(BlockDriverState *bs,
0a122b
                 VmdkExtent *extent,
0a122b
                 uint64_t cluster_offset,
0a122b
@@ -1957,6 +1970,7 @@ static BlockDriver bdrv_vmdk = {
0a122b
     .bdrv_get_allocated_file_size = vmdk_get_allocated_file_size,
0a122b
     .bdrv_has_zero_init           = vmdk_has_zero_init,
0a122b
     .bdrv_get_specific_info       = vmdk_get_specific_info,
0a122b
+    .bdrv_refresh_limits          = vmdk_refresh_limits,
0a122b
 
0a122b
     .create_options               = vmdk_create_options,
0a122b
 };
0a122b
diff --git a/include/block/block_int.h b/include/block/block_int.h
0a122b
index c8f30fd..13a52e8 100644
0a122b
--- a/include/block/block_int.h
0a122b
+++ b/include/block/block_int.h
0a122b
@@ -213,6 +213,8 @@ struct BlockDriver {
0a122b
     int (*bdrv_debug_resume)(BlockDriverState *bs, const char *tag);
0a122b
     bool (*bdrv_debug_is_suspended)(BlockDriverState *bs, const char *tag);
0a122b
 
0a122b
+    int (*bdrv_refresh_limits)(BlockDriverState *bs);
0a122b
+
0a122b
     /*
0a122b
      * Returns 1 if newly created images are guaranteed to contain only
0a122b
      * zeros, 0 otherwise.
0a122b
-- 
0a122b
1.7.1
0a122b