|
|
9ae3a8 |
From f3ba81ab59dcb21f79cf2f2053206d6b03431658 Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
Message-Id: <f3ba81ab59dcb21f79cf2f2053206d6b03431658.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:03 +0100
|
|
|
9ae3a8 |
Subject: [PATCH 15/50] block: honour BlockLimits in bdrv_co_discard
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1386598178-11845-18-git-send-email-pbonzini@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 56053
|
|
|
9ae3a8 |
O-Subject: [RHEL 7.0 qemu-kvm PATCH 17/52] block: honour BlockLimits in bdrv_co_discard
|
|
|
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 6f14da5247076bde1e00444f6d5b2b7ca8075a09)
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block.c | 37 ++++++++++++++++++++++++++++++++++++-
|
|
|
9ae3a8 |
1 file changed, 36 insertions(+), 1 deletion(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Michal Novotny <minovotn@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block.c | 37 ++++++++++++++++++++++++++++++++++++-
|
|
|
9ae3a8 |
1 file changed, 36 insertions(+), 1 deletion(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block.c b/block.c
|
|
|
9ae3a8 |
index 2ed9aa9..23dbafd 100644
|
|
|
9ae3a8 |
--- a/block.c
|
|
|
9ae3a8 |
+++ b/block.c
|
|
|
9ae3a8 |
@@ -4424,6 +4424,11 @@ static void coroutine_fn bdrv_discard_co_entry(void *opaque)
|
|
|
9ae3a8 |
rwco->ret = bdrv_co_discard(rwco->bs, rwco->sector_num, rwco->nb_sectors);
|
|
|
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_DISCARD_DEFAULT 32768
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num,
|
|
|
9ae3a8 |
int nb_sectors)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
@@ -4445,7 +4450,37 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num,
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (bs->drv->bdrv_co_discard) {
|
|
|
9ae3a8 |
- return bs->drv->bdrv_co_discard(bs, sector_num, nb_sectors);
|
|
|
9ae3a8 |
+ int max_discard = bs->bl.max_discard ?
|
|
|
9ae3a8 |
+ bs->bl.max_discard : MAX_DISCARD_DEFAULT;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ while (nb_sectors > 0) {
|
|
|
9ae3a8 |
+ int ret;
|
|
|
9ae3a8 |
+ int num = nb_sectors;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* align request */
|
|
|
9ae3a8 |
+ if (bs->bl.discard_alignment &&
|
|
|
9ae3a8 |
+ num >= bs->bl.discard_alignment &&
|
|
|
9ae3a8 |
+ sector_num % bs->bl.discard_alignment) {
|
|
|
9ae3a8 |
+ if (num > bs->bl.discard_alignment) {
|
|
|
9ae3a8 |
+ num = bs->bl.discard_alignment;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ num -= sector_num % bs->bl.discard_alignment;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* limit request size */
|
|
|
9ae3a8 |
+ if (num > max_discard) {
|
|
|
9ae3a8 |
+ num = max_discard;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ ret = bs->drv->bdrv_co_discard(bs, sector_num, num);
|
|
|
9ae3a8 |
+ if (ret) {
|
|
|
9ae3a8 |
+ return ret;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ sector_num += num;
|
|
|
9ae3a8 |
+ nb_sectors -= num;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ return 0;
|
|
|
9ae3a8 |
} else if (bs->drv->bdrv_aio_discard) {
|
|
|
9ae3a8 |
BlockDriverAIOCB *acb;
|
|
|
9ae3a8 |
CoroutineIOCompletion co = {
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.7.11.7
|
|
|
9ae3a8 |
|