All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Lieven <pl@kamp.de>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, ronniesahlberg@gmail.com,
	Peter Lieven <pl@kamp.de>,
	stefanha@redhat.com, anthony@codemonkey.ws, pbonzini@redhat.com
Subject: [Qemu-devel] [PATCHv3 07/20] block: honour BlockLimits in bdrv_co_do_write_zeroes
Date: Tue, 24 Sep 2013 15:35:01 +0200	[thread overview]
Message-ID: <1380029714-5239-8-git-send-email-pl@kamp.de> (raw)
In-Reply-To: <1380029714-5239-1-git-send-email-pl@kamp.de>

Signed-off-by: Peter Lieven <pl@kamp.de>
---
 block.c |   65 +++++++++++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 49 insertions(+), 16 deletions(-)

diff --git a/block.c b/block.c
index ac35cb5..580570a 100644
--- a/block.c
+++ b/block.c
@@ -2710,32 +2710,65 @@ int coroutine_fn bdrv_co_copy_on_readv(BlockDriverState *bs,
                             BDRV_REQ_COPY_ON_READ);
 }
 
+/* if no limit is specified in the BlockLimits use a default
+ * of 32768 512-byte sectors (16 MiB) per request.
+ */
+#define MAX_WRITE_ZEROES_DEFAULT 32768
+
 static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs,
     int64_t sector_num, int nb_sectors, BdrvRequestFlags flags)
 {
     BlockDriver *drv = bs->drv;
     QEMUIOVector qiov;
-    struct iovec iov;
-    int ret;
+    struct iovec iov = {0};
+    int ret = 0;
 
-    /* TODO Emulate only part of misaligned requests instead of letting block
-     * drivers return -ENOTSUP and emulate everything */
+    int max_write_zeroes = bs->bl.max_write_zeroes ?
+                           bs->bl.max_write_zeroes : MAX_WRITE_ZEROES_DEFAULT;
 
-    /* First try the efficient write zeroes operation */
-    if (drv->bdrv_co_write_zeroes) {
-        ret = drv->bdrv_co_write_zeroes(bs, sector_num, nb_sectors, flags);
-        if (ret != -ENOTSUP) {
-            return ret;
+    while (nb_sectors > 0 && !ret) {
+        int num = nb_sectors;
+
+        /* align request */
+        if (bs->bl.write_zeroes_alignment &&
+            num >= bs->bl.write_zeroes_alignment &&
+            sector_num % bs->bl.write_zeroes_alignment) {
+            if (num > bs->bl.write_zeroes_alignment) {
+                num = bs->bl.write_zeroes_alignment;
+            }
+            num -= sector_num % bs->bl.write_zeroes_alignment;
         }
-    }
 
-    /* Fall back to bounce buffer if write zeroes is unsupported */
-    iov.iov_len  = nb_sectors * BDRV_SECTOR_SIZE;
-    iov.iov_base = qemu_blockalign(bs, iov.iov_len);
-    memset(iov.iov_base, 0, iov.iov_len);
-    qemu_iovec_init_external(&qiov, &iov, 1);
+        /* limit request size */
+        if (num > max_write_zeroes) {
+            num = max_write_zeroes;
+        }
+
+        ret = -ENOTSUP;
+        /* First try the efficient write zeroes operation */
+        if (drv->bdrv_co_write_zeroes) {
+            ret = drv->bdrv_co_write_zeroes(bs, sector_num, num, flags);
+        }
+
+        if (ret == -ENOTSUP) {
+            /* Fall back to bounce buffer if write zeroes is unsupported */
+            iov.iov_len  = num * BDRV_SECTOR_SIZE;
+            if (iov.iov_base == NULL) {
+                /* allocate bounce buffer only once and ensure that it
+                 * is big enough for this and all future requests.
+                 */
+                size_t bufsize = num <= nb_sectors ? num : max_write_zeroes;
+                iov.iov_base = qemu_blockalign(bs, bufsize * BDRV_SECTOR_SIZE);
+                memset(iov.iov_base, 0, bufsize * BDRV_SECTOR_SIZE);
+            }
+            qemu_iovec_init_external(&qiov, &iov, 1);
 
-    ret = drv->bdrv_co_writev(bs, sector_num, nb_sectors, &qiov);
+            ret = drv->bdrv_co_writev(bs, sector_num, num, &qiov);
+        }
+
+        sector_num += num;
+        nb_sectors -= num;
+    }
 
     qemu_vfree(iov.iov_base);
     return ret;
-- 
1.7.9.5

  parent reply	other threads:[~2013-09-24 13:37 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-24 13:34 [Qemu-devel] [PATCHv3 00/20] block: logical block provisioning enhancements Peter Lieven
2013-09-24 13:34 ` [Qemu-devel] [PATCHv3 01/20] block: make BdrvRequestFlags public Peter Lieven
2013-09-24 13:34 ` [Qemu-devel] [PATCHv3 02/20] block: add flags to bdrv_*_write_zeroes Peter Lieven
2013-10-02 15:32   ` Eric Blake
2013-09-24 13:34 ` [Qemu-devel] [PATCHv3 03/20] block: introduce BDRV_REQ_MAY_UNMAP request flag Peter Lieven
2013-09-24 13:34 ` [Qemu-devel] [PATCHv3 04/20] block: introduce bdrv_has_discard_zeroes and bdrv_has_discard_write_zeroes Peter Lieven
2013-10-02 15:41   ` Eric Blake
2013-09-24 13:34 ` [Qemu-devel] [PATCHv3 05/20] block/raw: add " Peter Lieven
2013-10-02 15:43   ` Eric Blake
2013-09-24 13:35 ` [Qemu-devel] [PATCHv3 06/20] block: add BlockLimits structure to BlockDriverState Peter Lieven
2013-10-02 15:53   ` Eric Blake
2013-10-07  8:10     ` Stefan Hajnoczi
2013-09-24 13:35 ` Peter Lieven [this message]
2013-10-02 16:37   ` [Qemu-devel] [PATCHv3 07/20] block: honour BlockLimits in bdrv_co_do_write_zeroes Eric Blake
2013-09-24 13:35 ` [Qemu-devel] [PATCHv3 08/20] block: honour BlockLimits in bdrv_co_discard Peter Lieven
2013-10-02 16:41   ` Eric Blake
2013-10-07  8:29   ` Stefan Hajnoczi
2013-10-07  8:36     ` Peter Lieven
2013-09-24 13:35 ` [Qemu-devel] [PATCHv3 09/20] iscsi: simplify iscsi_co_discard Peter Lieven
2013-09-24 13:35 ` [Qemu-devel] [PATCHv3 10/20] iscsi: set limits in BlockDriverState Peter Lieven
2013-10-02 16:43   ` Eric Blake
2013-09-24 13:35 ` [Qemu-devel] [PATCHv3 11/20] iscsi: add bdrv_has_discard_zeroes and bdrv_has_discard_write_zeroes Peter Lieven
2013-10-02 16:45   ` Eric Blake
2013-09-24 13:35 ` [Qemu-devel] [PATCHv3 12/20] iscsi: add bdrv_co_write_zeroes Peter Lieven
2013-09-24 13:35 ` [Qemu-devel] [PATCHv3 13/20] block: introduce bdrv_zeroize Peter Lieven
2013-10-02 16:51   ` Eric Blake
2013-10-07  8:34   ` Stefan Hajnoczi
2013-10-07  8:39     ` Peter Lieven
2013-09-24 13:35 ` [Qemu-devel] [PATCHv3 14/20] block/get_block_status: set *pnum = 0 on error Peter Lieven
2013-09-24 13:35 ` [Qemu-devel] [PATCHv3 15/20] block/get_block_status: avoid segfault if there is no backing_hd Peter Lieven
2013-09-24 13:35 ` [Qemu-devel] [PATCHv3 16/20] block/get_block_status: avoid redundant callouts on raw devices Peter Lieven
2013-09-24 13:35 ` [Qemu-devel] [PATCHv3 17/20] block/get_block_status: fix BDRV_BLOCK_ZERO for unallocated blocks Peter Lieven
2013-09-24 13:35 ` [Qemu-devel] [PATCHv3 18/20] qemu-img: add support for fully allocated images Peter Lieven
2013-10-02 17:01   ` Eric Blake
2013-09-24 13:35 ` [Qemu-devel] [PATCHv3 19/20] qemu-img: conditionally zero out target on convert Peter Lieven
2013-09-24 13:35 ` [Qemu-devel] [PATCHv3 20/20] block/raw: copy BlockLimits on raw_open Peter Lieven
2013-10-02 17:11   ` Eric Blake
2013-10-07  8:38     ` Stefan Hajnoczi
2013-10-07  8:40       ` Peter Lieven
2013-10-07  8:42 ` [Qemu-devel] [PATCHv3 00/20] block: logical block provisioning enhancements Stefan Hajnoczi
2013-10-07  8:47   ` Peter Lieven
2013-10-07  9:42   ` Paolo Bonzini
2013-10-08  7:02     ` Stefan Hajnoczi
2013-10-08  8:01       ` Peter Lieven
2013-10-08  8:59         ` Stefan Hajnoczi
2013-10-08  9:12           ` Peter Lieven
2013-10-08  9:26             ` Stefan Hajnoczi

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=1380029714-5239-8-git-send-email-pl@kamp.de \
    --to=pl@kamp.de \
    --cc=anthony@codemonkey.ws \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=ronniesahlberg@gmail.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.