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