yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-block-generalize-BlockLimits-handling-to-cover-bdrv_.patch.patch.patch

0a122b
From 374f2dab9cd7bd26bca73ef93cf75ed919d278f4 Mon Sep 17 00:00:00 2001
0a122b
Message-Id: <374f2dab9cd7bd26bca73ef93cf75ed919d278f4.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:11 +0100
0a122b
Subject: [PATCH 23/50] block: generalize BlockLimits handling to cover
0a122b
 bdrv_aio_discard too
0a122b
0a122b
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
0a122b
Message-id: <1386598178-11845-26-git-send-email-pbonzini@redhat.com>
0a122b
Patchwork-id: 56062
0a122b
O-Subject: [RHEL 7.0 qemu-kvm PATCH 25/52] block: generalize BlockLimits handling to cover bdrv_aio_discard too
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
bdrv_co_discard is only covering drivers which have a .bdrv_co_discard()
0a122b
implementation, but not those with .bdrv_aio_discard(). Not very nice,
0a122b
and easy to avoid.
0a122b
0a122b
Suggested-by: Kevin Wolf <kwolf@redhat.com>
0a122b
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
Reviewed-by: Peter Lieven <pl@kamp.de>
0a122b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
(cherry picked from commit d51e9fe505f7c7b97762100dd0e42cef43c90524)
0a122b
---
0a122b
 block.c | 80 +++++++++++++++++++++++++++++++++--------------------------------
0a122b
 1 file changed, 41 insertions(+), 39 deletions(-)
0a122b
0a122b
Signed-off-by: Michal Novotny <minovotn@redhat.com>
0a122b
---
0a122b
 block.c | 80 +++++++++++++++++++++++++++++++++--------------------------------
0a122b
 1 file changed, 41 insertions(+), 39 deletions(-)
0a122b
0a122b
diff --git a/block.c b/block.c
0a122b
index 60484a6..8dfc207 100644
0a122b
--- a/block.c
0a122b
+++ b/block.c
0a122b
@@ -4469,6 +4469,8 @@ static void coroutine_fn bdrv_discard_co_entry(void *opaque)
0a122b
 int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num,
0a122b
                                  int nb_sectors)
0a122b
 {
0a122b
+    int max_discard;
0a122b
+
0a122b
     if (!bs->drv) {
0a122b
         return -ENOMEDIUM;
0a122b
     } else if (bdrv_check_request(bs, sector_num, nb_sectors)) {
0a122b
@@ -4486,55 +4488,55 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num,
0a122b
         return 0;
0a122b
     }
0a122b
 
0a122b
-    if (bs->drv->bdrv_co_discard) {
0a122b
-        int max_discard = bs->bl.max_discard ?
0a122b
-                          bs->bl.max_discard : MAX_DISCARD_DEFAULT;
0a122b
+    if (!bs->drv->bdrv_co_discard && !bs->drv->bdrv_aio_discard) {
0a122b
+        return 0;
0a122b
+    }
0a122b
 
0a122b
-        while (nb_sectors > 0) {
0a122b
-            int ret;
0a122b
-            int num = nb_sectors;
0a122b
+    max_discard = bs->bl.max_discard ?  bs->bl.max_discard : MAX_DISCARD_DEFAULT;
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
+        /* 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
+        /* limit request size */
0a122b
+        if (num > max_discard) {
0a122b
+            num = max_discard;
0a122b
+        }
0a122b
 
0a122b
+        if (bs->drv->bdrv_co_discard) {
0a122b
             ret = bs->drv->bdrv_co_discard(bs, sector_num, num);
0a122b
-            if (ret) {
0a122b
-                return ret;
0a122b
+        } else {
0a122b
+            BlockDriverAIOCB *acb;
0a122b
+            CoroutineIOCompletion co = {
0a122b
+                .coroutine = qemu_coroutine_self(),
0a122b
+            };
0a122b
+
0a122b
+            acb = bs->drv->bdrv_aio_discard(bs, sector_num, nb_sectors,
0a122b
+                                            bdrv_co_io_em_complete, &co);
0a122b
+            if (acb == NULL) {
0a122b
+                return -EIO;
0a122b
+            } else {
0a122b
+                qemu_coroutine_yield();
0a122b
+                ret = co.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
-            .coroutine = qemu_coroutine_self(),
0a122b
-        };
0a122b
-
0a122b
-        acb = bs->drv->bdrv_aio_discard(bs, sector_num, nb_sectors,
0a122b
-                                        bdrv_co_io_em_complete, &co);
0a122b
-        if (acb == NULL) {
0a122b
-            return -EIO;
0a122b
-        } else {
0a122b
-            qemu_coroutine_yield();
0a122b
-            return co.ret;
0a122b
+        if (ret) {
0a122b
+            return ret;
0a122b
         }
0a122b
-    } else {
0a122b
-        return 0;
0a122b
+
0a122b
+        sector_num += num;
0a122b
+        nb_sectors -= num;
0a122b
     }
0a122b
+    return 0;
0a122b
 }
0a122b
 
0a122b
 int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors)
0a122b
-- 
0a122b
1.7.11.7
0a122b