qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, pl@kamp.de, stefanha@redhat.com
Subject: [Qemu-devel] [PATCH 09/11] raw-posix: implement write_zeroes with MAY_UNMAP for block devices
Date: Tue, 12 Nov 2013 16:49:47 +0100	[thread overview]
Message-ID: <1384271389-20716-10-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1384271389-20716-1-git-send-email-pbonzini@redhat.com>

See the next commit for the description of the Linux kernel problem
that is worked around in raw_open_common.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 block/raw-posix.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/block/raw-posix.c b/block/raw-posix.c
index 830e109..5cb46f1 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -335,6 +335,23 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
     if (S_ISREG(st.st_mode)) {
         s->discard_zeroes = true;
     }
+#ifdef BLKDISCARDZEROES
+    if (S_ISBLK(st.st_mode)) {
+        unsigned int arg;
+        if (ioctl(s->fd, BLKDISCARDZEROES, &arg) == 0 && arg) {
+            s->discard_zeroes = true;
+        }
+    }
+#endif
+#ifdef CONFIG_LINUX
+	/* On Linux 3.10, BLKDISCARD leaves stale data in the page cache.  Do
+	 * not rely on the contents of discarded blocks unless using O_DIRECT.
+	 */
+        if (!(bs->open_flags & BDRV_O_NOCACHE)) {
+            s->discard_zeroes = false;
+        }
+#endif
+    }
 
 #ifdef CONFIG_XFS
     if (platform_test_xfs_fd(s->fd)) {
@@ -1587,6 +1604,26 @@ static coroutine_fn BlockDriverAIOCB *hdev_aio_discard(BlockDriverState *bs,
                        cb, opaque, QEMU_AIO_DISCARD|QEMU_AIO_BLKDEV);
 }
 
+static coroutine_fn int hdev_co_write_zeroes(BlockDriverState *bs,
+    int64_t sector_num, int nb_sectors, BdrvRequestFlags flags)
+{
+    BDRVRawState *s = bs->opaque;
+    int rc;
+
+    rc = fd_open(bs);
+    if (rc < 0) {
+        return rc;
+    }
+    if (!(flags & BDRV_REQ_MAY_UNMAP)) {
+        return -ENOTSUP;
+    }
+    if (!s->discard_zeroes) {
+        return -ENOTSUP;
+    }
+    return paio_submit_co(bs, s->fd, sector_num, NULL, nb_sectors,
+                          QEMU_AIO_DISCARD|QEMU_AIO_BLKDEV);
+}
+
 static int hdev_create(const char *filename, QEMUOptionParameter *options,
                        Error **errp)
 {
@@ -1639,6 +1676,7 @@ static BlockDriver bdrv_host_device = {
     .bdrv_reopen_abort   = raw_reopen_abort,
     .bdrv_create        = hdev_create,
     .create_options     = raw_create_options,
+    .bdrv_co_write_zeroes = hdev_co_write_zeroes,
 
     .bdrv_aio_readv	= raw_aio_readv,
     .bdrv_aio_writev	= raw_aio_writev,
-- 
1.8.4.2

  parent reply	other threads:[~2013-11-12 15:50 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-12 15:49 [Qemu-devel] [PATCH 00/11] block & scsi: write_zeroes support through the whole stack Paolo Bonzini
2013-11-12 15:49 ` [Qemu-devel] [PATCH 01/11] block: generalize BlockLimits handling to cover bdrv_aio_discard too Paolo Bonzini
2013-11-13  6:07   ` Peter Lieven
2013-11-12 15:49 ` [Qemu-devel] [PATCH 02/11] block: add flags to BlockRequest Paolo Bonzini
2013-11-12 15:49 ` [Qemu-devel] [PATCH 03/11] block: add bdrv_aio_write_zeroes Paolo Bonzini
2013-11-12 15:49 ` [Qemu-devel] [PATCH 04/11] scsi-disk: catch write protection errors in UNMAP Paolo Bonzini
2013-11-12 15:49 ` [Qemu-devel] [PATCH 05/11] scsi-disk: reject ANCHOR=1 for UNMAP and WRITE SAME commands Paolo Bonzini
2013-11-13 19:03   ` Eric Blake
2013-11-12 15:49 ` [Qemu-devel] [PATCH 06/11] scsi-disk: correctly implement WRITE SAME Paolo Bonzini
2013-11-13  6:18   ` Peter Lieven
2013-11-13  9:38     ` Paolo Bonzini
2013-11-12 15:49 ` [Qemu-devel] [PATCH 07/11] block: handle ENOTSUP from discard in generic code Paolo Bonzini
2013-11-12 15:49 ` [Qemu-devel] [PATCH 08/11] raw-posix: implement write_zeroes with MAY_UNMAP for files Paolo Bonzini
2013-11-13  6:27   ` Peter Lieven
2013-11-13  6:30     ` Peter Lieven
2013-11-12 15:49 ` Paolo Bonzini [this message]
2013-11-13  6:29   ` [Qemu-devel] [PATCH 09/11] raw-posix: implement write_zeroes with MAY_UNMAP for block devices Peter Lieven
2013-11-13  9:44     ` Paolo Bonzini
2013-11-13 14:14       ` Peter Lieven
2013-11-13 14:39         ` Paolo Bonzini
2013-11-13 14:45           ` Peter Lieven
2013-11-12 15:49 ` [Qemu-devel] [PATCH 10/11] raw-posix: add support for write_zeroes on XFS and " Paolo Bonzini
2013-11-12 15:49 ` [Qemu-devel] [PATCH 11/11] qemu-iotests: 033 is fast Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1384271389-20716-10-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pl@kamp.de \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).