Blame SOURCES/kvm-raw-posix-implement-write_zeroes-with-MAY_UNMAP-for-.patch.patch.patch.patch.patch

0a122b
From f1b8961cbef828b62ba1ca7da79cd516f7dfc52b Mon Sep 17 00:00:00 2001
0a122b
Message-Id: <f1b8961cbef828b62ba1ca7da79cd516f7dfc52b.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:28 +0100
0a122b
Subject: [PATCH 40/50] raw-posix: implement write_zeroes with MAY_UNMAP for
0a122b
 block devices
0a122b
0a122b
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
0a122b
Message-id: <1386598178-11845-43-git-send-email-pbonzini@redhat.com>
0a122b
Patchwork-id: 56079
0a122b
O-Subject: [RHEL 7.0 qemu-kvm PATCH 42/52] raw-posix: implement write_zeroes with MAY_UNMAP for block devices
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
See the next commit for the description of the Linux kernel problem
0a122b
that is worked around in raw_open_common.
0a122b
0a122b
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
(cherry picked from commit d0b4503ed2d8713791c38839341b023f78d1a3d9)
0a122b
---
0a122b
 block/raw-posix.c | 37 +++++++++++++++++++++++++++++++++++++
0a122b
 1 file changed, 37 insertions(+)
0a122b
0a122b
Signed-off-by: Michal Novotny <minovotn@redhat.com>
0a122b
---
0a122b
 block/raw-posix.c | 37 +++++++++++++++++++++++++++++++++++++
0a122b
 1 file changed, 37 insertions(+)
0a122b
0a122b
diff --git a/block/raw-posix.c b/block/raw-posix.c
0a122b
index ca5bcb3..815a80b 100644
0a122b
--- a/block/raw-posix.c
0a122b
+++ b/block/raw-posix.c
0a122b
@@ -335,6 +335,22 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
0a122b
     if (S_ISREG(st.st_mode)) {
0a122b
         s->discard_zeroes = true;
0a122b
     }
0a122b
+    if (S_ISBLK(st.st_mode)) {
0a122b
+#ifdef BLKDISCARDZEROES
0a122b
+        unsigned int arg;
0a122b
+        if (ioctl(s->fd, BLKDISCARDZEROES, &arg) == 0 && arg) {
0a122b
+            s->discard_zeroes = true;
0a122b
+        }
0a122b
+#endif
0a122b
+#ifdef __linux__
0a122b
+        /* On Linux 3.10, BLKDISCARD leaves stale data in the page cache.  Do
0a122b
+         * not rely on the contents of discarded blocks unless using O_DIRECT.
0a122b
+         */
0a122b
+        if (!(bs->open_flags & BDRV_O_NOCACHE)) {
0a122b
+            s->discard_zeroes = false;
0a122b
+        }
0a122b
+#endif
0a122b
+    }
0a122b
 
0a122b
 #ifdef CONFIG_XFS
0a122b
     if (platform_test_xfs_fd(s->fd)) {
0a122b
@@ -1586,6 +1602,26 @@ static coroutine_fn BlockDriverAIOCB *hdev_aio_discard(BlockDriverState *bs,
0a122b
                        cb, opaque, QEMU_AIO_DISCARD|QEMU_AIO_BLKDEV);
0a122b
 }
0a122b
 
0a122b
+static coroutine_fn int hdev_co_write_zeroes(BlockDriverState *bs,
0a122b
+    int64_t sector_num, int nb_sectors, BdrvRequestFlags flags)
0a122b
+{
0a122b
+    BDRVRawState *s = bs->opaque;
0a122b
+    int rc;
0a122b
+
0a122b
+    rc = fd_open(bs);
0a122b
+    if (rc < 0) {
0a122b
+        return rc;
0a122b
+    }
0a122b
+    if (!(flags & BDRV_REQ_MAY_UNMAP)) {
0a122b
+        return -ENOTSUP;
0a122b
+    }
0a122b
+    if (!s->discard_zeroes) {
0a122b
+        return -ENOTSUP;
0a122b
+    }
0a122b
+    return paio_submit_co(bs, s->fd, sector_num, NULL, nb_sectors,
0a122b
+                          QEMU_AIO_DISCARD|QEMU_AIO_BLKDEV);
0a122b
+}
0a122b
+
0a122b
 static int hdev_create(const char *filename, QEMUOptionParameter *options,
0a122b
                        Error **errp)
0a122b
 {
0a122b
@@ -1637,6 +1673,7 @@ static BlockDriver bdrv_host_device = {
0a122b
     .bdrv_reopen_abort   = raw_reopen_abort,
0a122b
     .bdrv_create        = hdev_create,
0a122b
     .create_options     = raw_create_options,
0a122b
+    .bdrv_co_write_zeroes = hdev_co_write_zeroes,
0a122b
 
0a122b
     .bdrv_aio_readv	= raw_aio_readv,
0a122b
     .bdrv_aio_writev	= raw_aio_writev,
0a122b
-- 
0a122b
1.7.11.7
0a122b