diff mbox

[11/14] block: Add blk_co_readv/writev()

Message ID 1462354765-14037-12-git-send-email-kwolf@redhat.com
State New
Headers show

Commit Message

Kevin Wolf May 4, 2016, 9:39 a.m. UTC
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/block-backend.c          | 26 ++++++++++++++++++++++++++
 include/sysemu/block-backend.h |  4 ++++
 trace-events                   |  2 ++
 3 files changed, 32 insertions(+)

Comments

Max Reitz May 13, 2016, 3:12 p.m. UTC | #1
On 04.05.2016 11:39, Kevin Wolf wrote:
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  block/block-backend.c          | 26 ++++++++++++++++++++++++++
>  include/sysemu/block-backend.h |  4 ++++
>  trace-events                   |  2 ++
>  3 files changed, 32 insertions(+)

Reasonable in principle, but not sure whether we still want to add it now.

Max
diff mbox

Patch

diff --git a/block/block-backend.c b/block/block-backend.c
index 25bb5ca..8dc3aa5 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -794,6 +794,19 @@  static int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset,
     return bdrv_co_pwritev(blk_bs(blk), offset, bytes, qiov, flags);
 }
 
+int coroutine_fn blk_co_readv(BlockBackend *blk, int64_t sector_num,
+                              int nb_sectors, QEMUIOVector *qiov)
+{
+    trace_blk_co_readv(blk, blk_bs(blk), sector_num, nb_sectors);
+
+    if (nb_sectors < 0 || nb_sectors > BDRV_REQUEST_MAX_SECTORS) {
+        return -EINVAL;
+    }
+
+    return blk_co_preadv(blk, sector_num << BDRV_SECTOR_BITS,
+                         nb_sectors << BDRV_SECTOR_BITS, qiov, 0);
+}
+
 int coroutine_fn blk_co_copy_on_readv(BlockBackend *blk,
     int64_t sector_num, int nb_sectors, QEMUIOVector *qiov)
 {
@@ -808,6 +821,19 @@  int coroutine_fn blk_co_copy_on_readv(BlockBackend *blk,
                          BDRV_REQ_COPY_ON_READ);
 }
 
+int coroutine_fn blk_co_writev(BlockBackend *blk, int64_t sector_num,
+                               int nb_sectors, QEMUIOVector *qiov)
+{
+    trace_blk_co_writev(blk, blk_bs(blk), sector_num, nb_sectors);
+
+    if (nb_sectors < 0 || nb_sectors > BDRV_REQUEST_MAX_SECTORS) {
+        return -EINVAL;
+    }
+
+    return blk_co_pwritev(blk, sector_num << BDRV_SECTOR_BITS,
+                          nb_sectors << BDRV_SECTOR_BITS, qiov, 0);
+}
+
 typedef struct BlkRwCo {
     BlockBackend *blk;
     int64_t offset;
diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
index eac4d88..d98552c 100644
--- a/include/sysemu/block-backend.h
+++ b/include/sysemu/block-backend.h
@@ -116,8 +116,12 @@  int blk_read(BlockBackend *blk, int64_t sector_num, uint8_t *buf,
              int nb_sectors);
 int blk_read_unthrottled(BlockBackend *blk, int64_t sector_num, uint8_t *buf,
                          int nb_sectors);
+int coroutine_fn blk_co_readv(BlockBackend *blk, int64_t sector_num,
+                              int nb_sectors, QEMUIOVector *qiov);
 int coroutine_fn blk_co_copy_on_readv(BlockBackend *blk,
     int64_t sector_num, int nb_sectors, QEMUIOVector *qiov);
+int coroutine_fn blk_co_writev(BlockBackend *blk, int64_t sector_num,
+                               int nb_sectors, QEMUIOVector *qiov);
 int blk_write(BlockBackend *blk, int64_t sector_num, const uint8_t *buf,
               int nb_sectors);
 int blk_write_zeroes(BlockBackend *blk, int64_t sector_num,
diff --git a/trace-events b/trace-events
index 9beb588..3b5cce3 100644
--- a/trace-events
+++ b/trace-events
@@ -62,6 +62,8 @@  bdrv_open_common(void *bs, const char *filename, int flags, const char *format_n
 bdrv_lock_medium(void *bs, bool locked) "bs %p locked %d"
 
 # block/block-backend.c
+blk_co_readv(void *blk, void *bs, int64_t sector_num, int nb_sector) "blk %p bs %p sector_num %"PRId64" nb_sectors %d"
+blk_co_writev(void *blk, void *bs, int64_t sector_num, int nb_sector) "blk %p bs %p sector_num %"PRId64" nb_sectors %d"
 blk_co_copy_on_readv(void *blk, void *bs, int64_t sector_num, int nb_sector) "blk %p bs %p sector_num %"PRId64" nb_sectors %d"
 
 # block/io.c