Blame SOURCES/kvm-file-posix-Support-BDRV_REQ_NO_FALLBACK-for-zero-wri.patch

8b1478
From 9a02c0bcafdbf681e76f816ad3f60dfb7dea13fb Mon Sep 17 00:00:00 2001
8b1478
From: Maxim Levitsky <mlevitsk@redhat.com>
8b1478
Date: Wed, 5 Jun 2019 13:57:03 +0200
8b1478
Subject: [PATCH 15/23] file-posix: Support BDRV_REQ_NO_FALLBACK for zero
8b1478
 writes
8b1478
8b1478
RH-Author: Maxim Levitsky <mlevitsk@redhat.com>
8b1478
Message-id: <20190605135705.24526-8-mlevitsk@redhat.com>
8b1478
Patchwork-id: 88560
8b1478
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 7/9] file-posix: Support BDRV_REQ_NO_FALLBACK for zero writes
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
We know that the kernel implements a slow fallback code path for
8b1478
BLKZEROOUT, so if BDRV_REQ_NO_FALLBACK is given, we shouldn't call it.
8b1478
The other operations we call in the context of .bdrv_co_pwrite_zeroes
8b1478
should usually be quick, so no modification should be needed for them.
8b1478
If we ever notice that there are additional problematic cases, we can
8b1478
still make these conditional as well.
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 738301e11758171defaa5a5237d584f8226af89f)
8b1478
8b1478
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
8b1478
---
8b1478
 block/file-posix.c      | 24 ++++++++++++++++--------
8b1478
 include/block/raw-aio.h |  1 +
8b1478
 2 files changed, 17 insertions(+), 8 deletions(-)
8b1478
8b1478
diff --git a/block/file-posix.c b/block/file-posix.c
8b1478
index 90c719f..d1926b3 100644
8b1478
--- a/block/file-posix.c
8b1478
+++ b/block/file-posix.c
8b1478
@@ -632,7 +632,7 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
8b1478
     }
8b1478
 #endif
8b1478
 
8b1478
-    bs->supported_zero_flags = BDRV_REQ_MAY_UNMAP;
8b1478
+    bs->supported_zero_flags = BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK;
8b1478
     ret = 0;
8b1478
 fail:
8b1478
     if (filename && (bdrv_flags & BDRV_O_TEMPORARY)) {
8b1478
@@ -1449,14 +1449,19 @@ static ssize_t handle_aiocb_write_zeroes_block(RawPosixAIOData *aiocb)
8b1478
     }
8b1478
 
8b1478
 #ifdef BLKZEROOUT
8b1478
-    do {
8b1478
-        uint64_t range[2] = { aiocb->aio_offset, aiocb->aio_nbytes };
8b1478
-        if (ioctl(aiocb->aio_fildes, BLKZEROOUT, range) == 0) {
8b1478
-            return 0;
8b1478
-        }
8b1478
-    } while (errno == EINTR);
8b1478
+    /* The BLKZEROOUT implementation in the kernel doesn't set
8b1478
+     * BLKDEV_ZERO_NOFALLBACK, so we can't call this if we have to avoid slow
8b1478
+     * fallbacks. */
8b1478
+    if (!(aiocb->aio_type & QEMU_AIO_NO_FALLBACK)) {
8b1478
+        do {
8b1478
+            uint64_t range[2] = { aiocb->aio_offset, aiocb->aio_nbytes };
8b1478
+            if (ioctl(aiocb->aio_fildes, BLKZEROOUT, range) == 0) {
8b1478
+                return 0;
8b1478
+            }
8b1478
+        } while (errno == EINTR);
8b1478
 
8b1478
-    ret = translate_err(-errno);
8b1478
+        ret = translate_err(-errno);
8b1478
+    }
8b1478
 #endif
8b1478
 
8b1478
     if (ret == -ENOTSUP) {
8b1478
@@ -2535,6 +2540,9 @@ raw_do_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int bytes,
8b1478
     if (blkdev) {
8b1478
         acb.aio_type |= QEMU_AIO_BLKDEV;
8b1478
     }
8b1478
+    if (flags & BDRV_REQ_NO_FALLBACK) {
8b1478
+        acb.aio_type |= QEMU_AIO_NO_FALLBACK;
8b1478
+    }
8b1478
 
8b1478
     if (flags & BDRV_REQ_MAY_UNMAP) {
8b1478
         acb.aio_type |= QEMU_AIO_DISCARD;
8b1478
diff --git a/include/block/raw-aio.h b/include/block/raw-aio.h
8b1478
index 2ffcd9d..5a926a3 100644
8b1478
--- a/include/block/raw-aio.h
8b1478
+++ b/include/block/raw-aio.h
8b1478
@@ -40,6 +40,7 @@
8b1478
 /* AIO flags */
8b1478
 #define QEMU_AIO_MISALIGNED   0x1000
8b1478
 #define QEMU_AIO_BLKDEV       0x2000
8b1478
+#define QEMU_AIO_NO_FALLBACK  0x4000
8b1478
 
8b1478
 
8b1478
 /* linux-aio.c - Linux native implementation */
8b1478
-- 
8b1478
1.8.3.1
8b1478