Blame SOURCES/kvm-block-Add-BDRV_REQ_NO_FALLBACK.patch

8b1478
From 5ad7c32387034a02c9a932018e60580872431db9 Mon Sep 17 00:00:00 2001
8b1478
From: Maxim Levitsky <mlevitsk@redhat.com>
8b1478
Date: Wed, 5 Jun 2019 13:56:58 +0200
8b1478
Subject: [PATCH 10/23] block: Add BDRV_REQ_NO_FALLBACK
8b1478
8b1478
RH-Author: Maxim Levitsky <mlevitsk@redhat.com>
8b1478
Message-id: <20190605135705.24526-3-mlevitsk@redhat.com>
8b1478
Patchwork-id: 88557
8b1478
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 2/9] block: Add BDRV_REQ_NO_FALLBACK
8b1478
Bugzilla: 1648622
8b1478
RH-Acked-by: Max Reitz <mreitz@redhat.com>
8b1478
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
8b1478
RH-Acked-by: John Snow <jsnow@redhat.com>
8b1478
8b1478
From: Kevin Wolf <kwolf@redhat.com>
8b1478
8b1478
For qemu-img convert, we want an operation that zeroes out the whole
8b1478
image if this can be done efficiently, but that returns an error
8b1478
otherwise so we don't write explicit zeroes and immediately overwrite
8b1478
them with the real data, potentially doubling the amount of data to be
8b1478
written.
8b1478
8b1478
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8b1478
Acked-by: Eric Blake <eblake@redhat.com>
8b1478
8b1478
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1648622
8b1478
8b1478
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
8b1478
(Cherry picked from fe0480d6294270ff0d6fb60e66bb725a6aad2043)
8b1478
8b1478
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
8b1478
---
8b1478
 block/io.c            | 12 +++++++++++-
8b1478
 include/block/block.h |  7 ++++++-
8b1478
 2 files changed, 17 insertions(+), 2 deletions(-)
8b1478
8b1478
diff --git a/block/io.c b/block/io.c
8b1478
index 18bf3c2..26c4075 100644
8b1478
--- a/block/io.c
8b1478
+++ b/block/io.c
8b1478
@@ -1029,6 +1029,7 @@ static int coroutine_fn bdrv_driver_preadv(BlockDriverState *bs,
8b1478
     unsigned int nb_sectors;
8b1478
 
8b1478
     assert(!(flags & ~BDRV_REQ_MASK));
8b1478
+    assert(!(flags & BDRV_REQ_NO_FALLBACK));
8b1478
 
8b1478
     if (!drv) {
8b1478
         return -ENOMEDIUM;
8b1478
@@ -1074,6 +1075,7 @@ static int coroutine_fn bdrv_driver_pwritev(BlockDriverState *bs,
8b1478
     int ret;
8b1478
 
8b1478
     assert(!(flags & ~BDRV_REQ_MASK));
8b1478
+    assert(!(flags & BDRV_REQ_NO_FALLBACK));
8b1478
 
8b1478
     if (!drv) {
8b1478
         return -ENOMEDIUM;
8b1478
@@ -1499,6 +1501,10 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs,
8b1478
         return -ENOMEDIUM;
8b1478
     }
8b1478
 
8b1478
+    if ((flags & ~bs->supported_zero_flags) & BDRV_REQ_NO_FALLBACK) {
8b1478
+        return -ENOTSUP;
8b1478
+    }
8b1478
+
8b1478
     assert(alignment % bs->bl.request_alignment == 0);
8b1478
     head = offset % alignment;
8b1478
     tail = (offset + bytes) % alignment;
8b1478
@@ -1542,7 +1548,7 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs,
8b1478
             assert(!bs->supported_zero_flags);
8b1478
         }
8b1478
 
8b1478
-        if (ret == -ENOTSUP) {
8b1478
+        if (ret == -ENOTSUP && !(flags & BDRV_REQ_NO_FALLBACK)) {
8b1478
             /* Fall back to bounce buffer if write zeroes is unsupported */
8b1478
             BdrvRequestFlags write_flags = flags & ~BDRV_REQ_ZERO_WRITE;
8b1478
 
8b1478
@@ -2973,6 +2979,10 @@ static int coroutine_fn bdrv_co_copy_range_internal(
8b1478
     BdrvTrackedRequest req;
8b1478
     int ret;
8b1478
 
8b1478
+    /* TODO We can support BDRV_REQ_NO_FALLBACK here */
8b1478
+    assert(!(read_flags & BDRV_REQ_NO_FALLBACK));
8b1478
+    assert(!(write_flags & BDRV_REQ_NO_FALLBACK));
8b1478
+
8b1478
     if (!dst || !dst->bs) {
8b1478
         return -ENOMEDIUM;
8b1478
     }
8b1478
diff --git a/include/block/block.h b/include/block/block.h
8b1478
index 5f40140..33fb60c 100644
8b1478
--- a/include/block/block.h
8b1478
+++ b/include/block/block.h
8b1478
@@ -82,8 +82,13 @@ typedef enum {
8b1478
      */
8b1478
     BDRV_REQ_SERIALISING        = 0x80,
8b1478
 
8b1478
+    /* Execute the request only if the operation can be offloaded or otherwise
8b1478
+     * be executed efficiently, but return an error instead of using a slow
8b1478
+     * fallback. */
8b1478
+    BDRV_REQ_NO_FALLBACK        = 0x100,
8b1478
+
8b1478
     /* Mask of valid flags */
8b1478
-    BDRV_REQ_MASK               = 0xff,
8b1478
+    BDRV_REQ_MASK               = 0x1ff,
8b1478
 } BdrvRequestFlags;
8b1478
 
8b1478
 typedef struct BlockSizes {
8b1478
-- 
8b1478
1.8.3.1
8b1478