thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-block-honour-BlockLimits-in-bdrv_co_discard.patch.patch.patch

0a122b
From f3ba81ab59dcb21f79cf2f2053206d6b03431658 Mon Sep 17 00:00:00 2001
0a122b
Message-Id: <f3ba81ab59dcb21f79cf2f2053206d6b03431658.1389014116.git.minovotn@redhat.com>
0a122b
In-Reply-To: <c8cc35838d42aa286242772d97e3a9be7bb786ba.1389014116.git.minovotn@redhat.com>
0a122b
References: <c8cc35838d42aa286242772d97e3a9be7bb786ba.1389014116.git.minovotn@redhat.com>
0a122b
From: Paolo Bonzini <pbonzini@redhat.com>
0a122b
Date: Mon, 9 Dec 2013 14:09:03 +0100
0a122b
Subject: [PATCH 15/50] block: honour BlockLimits in bdrv_co_discard
0a122b
0a122b
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
0a122b
Message-id: <1386598178-11845-18-git-send-email-pbonzini@redhat.com>
0a122b
Patchwork-id: 56053
0a122b
O-Subject: [RHEL 7.0 qemu-kvm PATCH 17/52] block: honour BlockLimits in bdrv_co_discard
0a122b
Bugzilla: 1007815
0a122b
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
0a122b
RH-Acked-by: Fam Zheng <famz@redhat.com>
0a122b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
0a122b
From: Peter Lieven <pl@kamp.de>
0a122b
0a122b
Reviewed-by: Eric Blake <eblake@redhat.com>
0a122b
Signed-off-by: Peter Lieven <pl@kamp.de>
0a122b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
(cherry picked from commit 6f14da5247076bde1e00444f6d5b2b7ca8075a09)
0a122b
---
0a122b
 block.c | 37 ++++++++++++++++++++++++++++++++++++-
0a122b
 1 file changed, 36 insertions(+), 1 deletion(-)
0a122b
0a122b
Signed-off-by: Michal Novotny <minovotn@redhat.com>
0a122b
---
0a122b
 block.c | 37 ++++++++++++++++++++++++++++++++++++-
0a122b
 1 file changed, 36 insertions(+), 1 deletion(-)
0a122b
0a122b
diff --git a/block.c b/block.c
0a122b
index 2ed9aa9..23dbafd 100644
0a122b
--- a/block.c
0a122b
+++ b/block.c
0a122b
@@ -4424,6 +4424,11 @@ static void coroutine_fn bdrv_discard_co_entry(void *opaque)
0a122b
     rwco->ret = bdrv_co_discard(rwco->bs, rwco->sector_num, rwco->nb_sectors);
0a122b
 }
0a122b
 
0a122b
+/* if no limit is specified in the BlockLimits use a default
0a122b
+ * of 32768 512-byte sectors (16 MiB) per request.
0a122b
+ */
0a122b
+#define MAX_DISCARD_DEFAULT 32768
0a122b
+
0a122b
 int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num,
0a122b
                                  int nb_sectors)
0a122b
 {
0a122b
@@ -4445,7 +4450,37 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num,
0a122b
     }
0a122b
 
0a122b
     if (bs->drv->bdrv_co_discard) {
0a122b
-        return bs->drv->bdrv_co_discard(bs, sector_num, nb_sectors);
0a122b
+        int max_discard = bs->bl.max_discard ?
0a122b
+                          bs->bl.max_discard : MAX_DISCARD_DEFAULT;
0a122b
+
0a122b
+        while (nb_sectors > 0) {
0a122b
+            int ret;
0a122b
+            int num = nb_sectors;
0a122b
+
0a122b
+            /* align request */
0a122b
+            if (bs->bl.discard_alignment &&
0a122b
+                num >= bs->bl.discard_alignment &&
0a122b
+                sector_num % bs->bl.discard_alignment) {
0a122b
+                if (num > bs->bl.discard_alignment) {
0a122b
+                    num = bs->bl.discard_alignment;
0a122b
+                }
0a122b
+                num -= sector_num % bs->bl.discard_alignment;
0a122b
+            }
0a122b
+
0a122b
+            /* limit request size */
0a122b
+            if (num > max_discard) {
0a122b
+                num = max_discard;
0a122b
+            }
0a122b
+
0a122b
+            ret = bs->drv->bdrv_co_discard(bs, sector_num, num);
0a122b
+            if (ret) {
0a122b
+                return ret;
0a122b
+            }
0a122b
+
0a122b
+            sector_num += num;
0a122b
+            nb_sectors -= num;
0a122b
+        }
0a122b
+        return 0;
0a122b
     } else if (bs->drv->bdrv_aio_discard) {
0a122b
         BlockDriverAIOCB *acb;
0a122b
         CoroutineIOCompletion co = {
0a122b
-- 
0a122b
1.7.11.7
0a122b