All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-devel@nongnu.org, qemu-block@nongnu.org
Cc: kwolf@redhat.com, fam@euphon.net, vsementsov@virtuozzo.com,
	mreitz@redhat.com, stefanha@redhat.com, den@openvz.org,
	jsnow@redhat.com
Subject: [Qemu-devel] [PATCH 1/3] block: implement blk_co_pcache
Date: Thu,  6 Jun 2019 16:48:12 +0300	[thread overview]
Message-ID: <20190606134814.123689-2-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <20190606134814.123689-1-vsementsov@virtuozzo.com>

Do effective copy-on-read request when we don't need data actually. It
will be used for block-stream and NBD_CMD_CACHE.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 include/block/block.h          |  8 +++++++-
 include/sysemu/block-backend.h |  7 +++++++
 block/io.c                     | 18 ++++++++++++------
 3 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/include/block/block.h b/include/block/block.h
index f9415ed740..4662f25513 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -88,8 +88,14 @@ typedef enum {
      * fallback. */
     BDRV_REQ_NO_FALLBACK        = 0x100,
 
+    /*
+     * BDRV_REQ_CACHE may be used only together with BDRV_REQ_COPY_ON_READ
+     * on read request and means that caller don't really need data to be
+     * written to qiov parameter which may be NULL.
+     */
+    BDRV_REQ_CACHE  = 0x200,
     /* Mask of valid flags */
-    BDRV_REQ_MASK               = 0x1ff,
+    BDRV_REQ_MASK               = 0x3ff,
 } BdrvRequestFlags;
 
 typedef struct BlockSizes {
diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
index 733c4957eb..2bcecd1190 100644
--- a/include/sysemu/block-backend.h
+++ b/include/sysemu/block-backend.h
@@ -135,6 +135,13 @@ static inline int coroutine_fn blk_co_pread(BlockBackend *blk, int64_t offset,
     return blk_co_preadv(blk, offset, bytes, &qiov, flags);
 }
 
+static inline int coroutine_fn blk_co_pcache(BlockBackend *blk, int64_t offset,
+                                             unsigned int bytes)
+{
+    return blk_co_preadv(blk, offset, bytes, NULL,
+                         BDRV_REQ_COPY_ON_READ | BDRV_REQ_CACHE);
+}
+
 static inline int coroutine_fn blk_co_pwrite(BlockBackend *blk, int64_t offset,
                                              unsigned int bytes, void *buf,
                                              BdrvRequestFlags flags)
diff --git a/block/io.c b/block/io.c
index 9ba1bada36..9daf7332bd 100644
--- a/block/io.c
+++ b/block/io.c
@@ -1104,7 +1104,8 @@ bdrv_driver_pwritev_compressed(BlockDriverState *bs, uint64_t offset,
 }
 
 static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child,
-        int64_t offset, unsigned int bytes, QEMUIOVector *qiov)
+        int64_t offset, unsigned int bytes, QEMUIOVector *qiov,
+        int flags)
 {
     BlockDriverState *bs = child->bs;
 
@@ -1215,9 +1216,11 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child,
                 goto err;
             }
 
-            qemu_iovec_from_buf(qiov, progress, bounce_buffer + skip_bytes,
-                                pnum - skip_bytes);
-        } else {
+            if (!(flags & BDRV_REQ_CACHE)) {
+                qemu_iovec_from_buf(qiov, progress, bounce_buffer + skip_bytes,
+                                    pnum - skip_bytes);
+            }
+        } else if (!(flags & BDRV_REQ_CACHE)) {
             /* Read directly into the destination */
             qemu_iovec_init(&local_qiov, qiov->niov);
             qemu_iovec_concat(&local_qiov, qiov, progress, pnum - skip_bytes);
@@ -1268,7 +1271,8 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild *child,
      * potential fallback support, if we ever implement any read flags
      * to pass through to drivers.  For now, there aren't any
      * passthrough flags.  */
-    assert(!(flags & ~(BDRV_REQ_NO_SERIALISING | BDRV_REQ_COPY_ON_READ)));
+    assert(!(flags & ~(BDRV_REQ_NO_SERIALISING | BDRV_REQ_COPY_ON_READ |
+                       BDRV_REQ_CACHE)));
 
     /* Handle Copy on Read and associated serialisation */
     if (flags & BDRV_REQ_COPY_ON_READ) {
@@ -1296,7 +1300,9 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild *child,
         }
 
         if (!ret || pnum != bytes) {
-            ret = bdrv_co_do_copy_on_readv(child, offset, bytes, qiov);
+            ret = bdrv_co_do_copy_on_readv(child, offset, bytes, qiov, flags);
+            goto out;
+        } else if (flags & BDRV_REQ_CACHE) {
             goto out;
         }
     }
-- 
2.18.0



  reply	other threads:[~2019-06-06 13:51 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-06 13:48 [Qemu-devel] [PATCH 0/3] block: blk_co_pcache Vladimir Sementsov-Ogievskiy
2019-06-06 13:48 ` Vladimir Sementsov-Ogievskiy [this message]
2019-06-06 13:48 ` [Qemu-devel] [PATCH 2/3] block/stream: use blk_co_pcache Vladimir Sementsov-Ogievskiy
2019-06-06 13:48 ` [Qemu-devel] [PATCH 3/3] nbd: improve CMD_CACHE: " Vladimir Sementsov-Ogievskiy
2019-06-06 13:55 ` [Qemu-devel] [PATCH 0/3] block: blk_co_pcache Eric Blake
2019-06-06 14:07   ` Vladimir Sementsov-Ogievskiy
2019-06-17 11:20     ` Vladimir Sementsov-Ogievskiy
2019-06-17 12:09       ` Kevin Wolf
2019-06-17 12:32         ` Vladimir Sementsov-Ogievskiy
2019-06-17 13:09         ` Eric Blake
2019-06-17 13:20           ` Kevin Wolf
2019-06-18  7:38             ` Vladimir Sementsov-Ogievskiy
2019-06-18  8:23               ` Kevin Wolf

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=20190606134814.123689-2-vsementsov@virtuozzo.com \
    --to=vsementsov@virtuozzo.com \
    --cc=den@openvz.org \
    --cc=fam@euphon.net \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --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 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.