|
|
9ae3a8 |
From 69e802baf506bd21a2f444cfebe4ac7f5b5d07a8 Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
Message-Id: <69e802baf506bd21a2f444cfebe4ac7f5b5d07a8.1389014116.git.minovotn@redhat.com>
|
|
|
9ae3a8 |
In-Reply-To: <c8cc35838d42aa286242772d97e3a9be7bb786ba.1389014116.git.minovotn@redhat.com>
|
|
|
9ae3a8 |
References: <c8cc35838d42aa286242772d97e3a9be7bb786ba.1389014116.git.minovotn@redhat.com>
|
|
|
9ae3a8 |
From: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9ae3a8 |
Date: Mon, 9 Dec 2013 14:09:02 +0100
|
|
|
9ae3a8 |
Subject: [PATCH 14/50] block: honour BlockLimits in bdrv_co_do_write_zeroes
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1386598178-11845-17-git-send-email-pbonzini@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 56052
|
|
|
9ae3a8 |
O-Subject: [RHEL 7.0 qemu-kvm PATCH 16/52] block: honour BlockLimits in bdrv_co_do_write_zeroes
|
|
|
9ae3a8 |
Bugzilla: 1007815
|
|
|
9ae3a8 |
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
From: Peter Lieven <pl@kamp.de>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Peter Lieven <pl@kamp.de>
|
|
|
9ae3a8 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit c31cb70728d2c0c8900b35a66784baa446fd5147)
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++----------------
|
|
|
9ae3a8 |
1 file changed, 49 insertions(+), 16 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Michal Novotny <minovotn@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++----------------
|
|
|
9ae3a8 |
1 file changed, 49 insertions(+), 16 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block.c b/block.c
|
|
|
9ae3a8 |
index 2fae459..2ed9aa9 100644
|
|
|
9ae3a8 |
--- a/block.c
|
|
|
9ae3a8 |
+++ b/block.c
|
|
|
9ae3a8 |
@@ -2724,32 +2724,65 @@ int coroutine_fn bdrv_co_copy_on_readv(BlockDriverState *bs,
|
|
|
9ae3a8 |
BDRV_REQ_COPY_ON_READ);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+/* if no limit is specified in the BlockLimits use a default
|
|
|
9ae3a8 |
+ * of 32768 512-byte sectors (16 MiB) per request.
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+#define MAX_WRITE_ZEROES_DEFAULT 32768
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs,
|
|
|
9ae3a8 |
int64_t sector_num, int nb_sectors, BdrvRequestFlags flags)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
BlockDriver *drv = bs->drv;
|
|
|
9ae3a8 |
QEMUIOVector qiov;
|
|
|
9ae3a8 |
- struct iovec iov;
|
|
|
9ae3a8 |
- int ret;
|
|
|
9ae3a8 |
+ struct iovec iov = {0};
|
|
|
9ae3a8 |
+ int ret = 0;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- /* TODO Emulate only part of misaligned requests instead of letting block
|
|
|
9ae3a8 |
- * drivers return -ENOTSUP and emulate everything */
|
|
|
9ae3a8 |
+ int max_write_zeroes = bs->bl.max_write_zeroes ?
|
|
|
9ae3a8 |
+ bs->bl.max_write_zeroes : MAX_WRITE_ZEROES_DEFAULT;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- /* First try the efficient write zeroes operation */
|
|
|
9ae3a8 |
- if (drv->bdrv_co_write_zeroes) {
|
|
|
9ae3a8 |
- ret = drv->bdrv_co_write_zeroes(bs, sector_num, nb_sectors, flags);
|
|
|
9ae3a8 |
- if (ret != -ENOTSUP) {
|
|
|
9ae3a8 |
- return ret;
|
|
|
9ae3a8 |
+ while (nb_sectors > 0 && !ret) {
|
|
|
9ae3a8 |
+ int num = nb_sectors;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* align request */
|
|
|
9ae3a8 |
+ if (bs->bl.write_zeroes_alignment &&
|
|
|
9ae3a8 |
+ num >= bs->bl.write_zeroes_alignment &&
|
|
|
9ae3a8 |
+ sector_num % bs->bl.write_zeroes_alignment) {
|
|
|
9ae3a8 |
+ if (num > bs->bl.write_zeroes_alignment) {
|
|
|
9ae3a8 |
+ num = bs->bl.write_zeroes_alignment;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ num -= sector_num % bs->bl.write_zeroes_alignment;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- /* Fall back to bounce buffer if write zeroes is unsupported */
|
|
|
9ae3a8 |
- iov.iov_len = nb_sectors * BDRV_SECTOR_SIZE;
|
|
|
9ae3a8 |
- iov.iov_base = qemu_blockalign(bs, iov.iov_len);
|
|
|
9ae3a8 |
- memset(iov.iov_base, 0, iov.iov_len);
|
|
|
9ae3a8 |
- qemu_iovec_init_external(&qiov, &iov, 1);
|
|
|
9ae3a8 |
+ /* limit request size */
|
|
|
9ae3a8 |
+ if (num > max_write_zeroes) {
|
|
|
9ae3a8 |
+ num = max_write_zeroes;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ ret = -ENOTSUP;
|
|
|
9ae3a8 |
+ /* First try the efficient write zeroes operation */
|
|
|
9ae3a8 |
+ if (drv->bdrv_co_write_zeroes) {
|
|
|
9ae3a8 |
+ ret = drv->bdrv_co_write_zeroes(bs, sector_num, num, flags);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (ret == -ENOTSUP) {
|
|
|
9ae3a8 |
+ /* Fall back to bounce buffer if write zeroes is unsupported */
|
|
|
9ae3a8 |
+ iov.iov_len = num * BDRV_SECTOR_SIZE;
|
|
|
9ae3a8 |
+ if (iov.iov_base == NULL) {
|
|
|
9ae3a8 |
+ /* allocate bounce buffer only once and ensure that it
|
|
|
9ae3a8 |
+ * is big enough for this and all future requests.
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+ size_t bufsize = num <= nb_sectors ? num : max_write_zeroes;
|
|
|
9ae3a8 |
+ iov.iov_base = qemu_blockalign(bs, bufsize * BDRV_SECTOR_SIZE);
|
|
|
9ae3a8 |
+ memset(iov.iov_base, 0, bufsize * BDRV_SECTOR_SIZE);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ qemu_iovec_init_external(&qiov, &iov, 1);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- ret = drv->bdrv_co_writev(bs, sector_num, nb_sectors, &qiov);
|
|
|
9ae3a8 |
+ ret = drv->bdrv_co_writev(bs, sector_num, num, &qiov);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ sector_num += num;
|
|
|
9ae3a8 |
+ nb_sectors -= num;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
qemu_vfree(iov.iov_base);
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.7.11.7
|
|
|
9ae3a8 |
|