qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com,
	mreitz@redhat.com
Subject: [Qemu-devel] [PATCH 6/8] block: Use blk_prw() in blk_pread()/blk_pwrite()
Date: Tue,  8 Mar 2016 13:47:51 +0100	[thread overview]
Message-ID: <1457441273-29821-7-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1457441273-29821-1-git-send-email-kwolf@redhat.com>

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/block-backend.c | 36 +++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/block/block-backend.c b/block/block-backend.c
index 5b9d387..579cc09 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -747,9 +747,9 @@ static void blk_write_entry(void *opaque)
                                rwco->qiov, rwco->flags);
 }
 
-static int blk_rw(BlockBackend *blk, int64_t sector_num, uint8_t *buf,
-                  int nb_sectors, CoroutineEntry co_entry,
-                  BdrvRequestFlags flags)
+static int blk_prw(BlockBackend *blk, int64_t offset, uint8_t *buf,
+                   int64_t bytes, CoroutineEntry co_entry,
+                   BdrvRequestFlags flags)
 {
     AioContext *aio_context;
     QEMUIOVector qiov;
@@ -757,19 +757,15 @@ static int blk_rw(BlockBackend *blk, int64_t sector_num, uint8_t *buf,
     Coroutine *co;
     BlkRwCo rwco;
 
-    if (nb_sectors < 0 || nb_sectors > BDRV_REQUEST_MAX_SECTORS) {
-        return -EINVAL;
-    }
-
     iov = (struct iovec) {
         .iov_base = buf,
-        .iov_len = nb_sectors * BDRV_SECTOR_SIZE,
+        .iov_len = bytes,
     };
     qemu_iovec_init_external(&qiov, &iov, 1);
 
     rwco = (BlkRwCo) {
         .blk    = blk,
-        .offset = sector_num << BDRV_SECTOR_BITS,
+        .offset = offset,
         .qiov   = &qiov,
         .flags  = flags,
         .ret    = NOT_DONE,
@@ -786,6 +782,18 @@ static int blk_rw(BlockBackend *blk, int64_t sector_num, uint8_t *buf,
     return rwco.ret;
 }
 
+static int blk_rw(BlockBackend *blk, int64_t sector_num, uint8_t *buf,
+                  int nb_sectors, CoroutineEntry co_entry,
+                  BdrvRequestFlags flags)
+{
+    if (nb_sectors < 0 || nb_sectors > BDRV_REQUEST_MAX_SECTORS) {
+        return -EINVAL;
+    }
+
+    return blk_prw(blk, sector_num << BDRV_SECTOR_BITS, buf,
+                   nb_sectors << BDRV_SECTOR_BITS, co_entry, flags);
+}
+
 int blk_read(BlockBackend *blk, int64_t sector_num, uint8_t *buf,
              int nb_sectors)
 {
@@ -866,22 +874,20 @@ BlockAIOCB *blk_aio_write_zeroes(BlockBackend *blk, int64_t sector_num,
 
 int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int count)
 {
-    int ret = blk_check_byte_request(blk, offset, count);
+    int ret = blk_prw(blk, offset, buf, count, blk_read_entry, 0);
     if (ret < 0) {
         return ret;
     }
-
-    return bdrv_pread(blk_bs(blk), offset, buf, count);
+    return count;
 }
 
 int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int count)
 {
-    int ret = blk_check_byte_request(blk, offset, count);
+    int ret = blk_prw(blk, offset, (void*) buf, count, blk_write_entry, 0);
     if (ret < 0) {
         return ret;
     }
-
-    return bdrv_pwrite(blk_bs(blk), offset, buf, count);
+    return count;
 }
 
 int64_t blk_getlength(BlockBackend *blk)
-- 
1.8.3.1

  parent reply	other threads:[~2016-03-08 12:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-08 12:47 [Qemu-devel] [PATCH 0/8] block: Introduce common read/write function Kevin Wolf
2016-03-08 12:47 ` [Qemu-devel] [PATCH 1/8] block: Use BdrvChild in BlockBackend Kevin Wolf
2016-03-08 12:47 ` [Qemu-devel] [PATCH 2/8] block: Use blk_co_preadv() for blk_read() Kevin Wolf
2016-03-08 12:47 ` [Qemu-devel] [PATCH 3/8] block: Use blk_co_pwritev() for blk_write() Kevin Wolf
2016-03-08 12:47 ` [Qemu-devel] [PATCH 4/8] block: Pull up blk_read_unthrottled() implementation Kevin Wolf
2016-03-08 12:47 ` [Qemu-devel] [PATCH 5/8] block: Use blk_co_pwritev() in blk_write_zeroes() Kevin Wolf
2016-03-08 12:47 ` Kevin Wolf [this message]
2016-03-08 12:47 ` [Qemu-devel] [PATCH 7/8] block: Use blk_aio_prwv() for aio_read/write/write_zeroes Kevin Wolf
2016-03-08 12:47 ` [Qemu-devel] [PATCH 8/8] block: Use blk_co_pwritev() in blk_co_write_zeroes() Kevin Wolf
2016-03-17 14:08 ` [Qemu-devel] [PATCH 0/8] block: Introduce common read/write function Kevin Wolf
2016-03-17 14:35 ` [Qemu-devel] [Qemu-block] " 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=1457441273-29821-7-git-send-email-kwolf@redhat.com \
    --to=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 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).