[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 05/14] stream: Use BlockBackend for I/O
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 05/14] stream: Use BlockBackend for I/O |
Date: |
Wed, 4 May 2016 11:39:16 +0200 |
This changes the streaming block job to use the job's BlockBackend for
performing the COR reads. job->bs isn't used by the streaming code any
more afterwards.
Signed-off-by: Kevin Wolf <address@hidden>
---
block/block-backend.c | 15 +++++++++++++++
block/io.c | 9 ---------
block/stream.c | 14 ++++++++------
include/block/block.h | 2 --
include/sysemu/block-backend.h | 2 ++
trace-events | 4 +++-
6 files changed, 28 insertions(+), 18 deletions(-)
diff --git a/block/block-backend.c b/block/block-backend.c
index 2932a58..25bb5ca 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -19,6 +19,7 @@
#include "sysemu/sysemu.h"
#include "qapi-event.h"
#include "qemu/id.h"
+#include "trace.h"
/* Number of coroutines to reserve per attached device model */
#define COROUTINE_POOL_RESERVATION 64
@@ -793,6 +794,20 @@ 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_copy_on_readv(BlockBackend *blk,
+ int64_t sector_num, int nb_sectors, QEMUIOVector *qiov)
+{
+ trace_blk_co_copy_on_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,
+ BDRV_REQ_COPY_ON_READ);
+}
+
typedef struct BlkRwCo {
BlockBackend *blk;
int64_t offset;
diff --git a/block/io.c b/block/io.c
index 9aae030..8280e14 100644
--- a/block/io.c
+++ b/block/io.c
@@ -1102,15 +1102,6 @@ int coroutine_fn
bdrv_co_readv_no_serialising(BlockDriverState *bs,
BDRV_REQ_NO_SERIALISING);
}
-int coroutine_fn bdrv_co_copy_on_readv(BlockDriverState *bs,
- int64_t sector_num, int nb_sectors, QEMUIOVector *qiov)
-{
- trace_bdrv_co_copy_on_readv(bs, sector_num, nb_sectors);
-
- return bdrv_co_do_readv(bs, sector_num, nb_sectors, qiov,
- BDRV_REQ_COPY_ON_READ);
-}
-
#define MAX_WRITE_ZEROES_BOUNCE_BUFFER 32768
static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs,
diff --git a/block/stream.c b/block/stream.c
index 40aa322..70ed9be 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -39,7 +39,7 @@ typedef struct StreamBlockJob {
char *backing_file_str;
} StreamBlockJob;
-static int coroutine_fn stream_populate(BlockDriverState *bs,
+static int coroutine_fn stream_populate(BlockBackend *blk,
int64_t sector_num, int nb_sectors,
void *buf)
{
@@ -52,7 +52,7 @@ static int coroutine_fn stream_populate(BlockDriverState *bs,
qemu_iovec_init_external(&qiov, &iov, 1);
/* Copy-on-read the unallocated clusters */
- return bdrv_co_copy_on_readv(bs, sector_num, nb_sectors, &qiov);
+ return blk_co_copy_on_readv(blk, sector_num, nb_sectors, &qiov);
}
typedef struct {
@@ -64,6 +64,7 @@ static void stream_complete(BlockJob *job, void *opaque)
{
StreamBlockJob *s = container_of(job, StreamBlockJob, common);
StreamCompleteData *data = opaque;
+ BlockDriverState *bs = blk_bs(job->blk);
BlockDriverState *base = s->base;
if (!block_job_is_cancelled(&s->common) && data->reached_end &&
@@ -75,8 +76,8 @@ static void stream_complete(BlockJob *job, void *opaque)
base_fmt = base->drv->format_name;
}
}
- data->ret = bdrv_change_backing_file(job->bs, base_id, base_fmt);
- bdrv_set_backing_hd(job->bs, base);
+ data->ret = bdrv_change_backing_file(bs, base_id, base_fmt);
+ bdrv_set_backing_hd(bs, base);
}
g_free(s->backing_file_str);
@@ -88,7 +89,8 @@ static void coroutine_fn stream_run(void *opaque)
{
StreamBlockJob *s = opaque;
StreamCompleteData *data;
- BlockDriverState *bs = s->common.bs;
+ BlockBackend *blk = s->common.blk;
+ BlockDriverState *bs = blk_bs(blk);
BlockDriverState *base = s->base;
int64_t sector_num = 0;
int64_t end = -1;
@@ -159,7 +161,7 @@ wait:
goto wait;
}
}
- ret = stream_populate(bs, sector_num, n, buf);
+ ret = stream_populate(blk, sector_num, n, buf);
}
if (ret < 0) {
BlockErrorAction action =
diff --git a/include/block/block.h b/include/block/block.h
index a4eb5be..39b5812 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -243,8 +243,6 @@ int bdrv_pwrite_sync(BlockDriverState *bs, int64_t offset,
const void *buf, int count);
int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num,
int nb_sectors, QEMUIOVector *qiov);
-int coroutine_fn bdrv_co_copy_on_readv(BlockDriverState *bs,
- int64_t sector_num, int nb_sectors, QEMUIOVector *qiov);
int coroutine_fn bdrv_co_readv_no_serialising(BlockDriverState *bs,
int64_t sector_num, int nb_sectors, QEMUIOVector *qiov);
int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num,
diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
index 12e4585..eac4d88 100644
--- a/include/sysemu/block-backend.h
+++ b/include/sysemu/block-backend.h
@@ -116,6 +116,8 @@ 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_copy_on_readv(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 2f0ec6d..9beb588 100644
--- a/trace-events
+++ b/trace-events
@@ -61,6 +61,9 @@ virtio_console_chr_event(unsigned int port, int event) "port
%u, event %d"
bdrv_open_common(void *bs, const char *filename, int flags, const char
*format_name) "bs %p filename \"%s\" flags %#x format_name \"%s\""
bdrv_lock_medium(void *bs, bool locked) "bs %p locked %d"
+# block/block-backend.c
+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
bdrv_aio_discard(void *bs, int64_t sector_num, int nb_sectors, void *opaque)
"bs %p sector_num %"PRId64" nb_sectors %d opaque %p"
bdrv_aio_flush(void *bs, void *opaque) "bs %p opaque %p"
@@ -68,7 +71,6 @@ bdrv_aio_readv(void *bs, int64_t sector_num, int nb_sectors,
void *opaque) "bs %
bdrv_aio_writev(void *bs, int64_t sector_num, int nb_sectors, void *opaque)
"bs %p sector_num %"PRId64" nb_sectors %d opaque %p"
bdrv_aio_write_zeroes(void *bs, int64_t sector_num, int nb_sectors, int flags,
void *opaque) "bs %p sector_num %"PRId64" nb_sectors %d flags %#x opaque %p"
bdrv_co_readv(void *bs, int64_t sector_num, int nb_sector) "bs %p sector_num
%"PRId64" nb_sectors %d"
-bdrv_co_copy_on_readv(void *bs, int64_t sector_num, int nb_sector) "bs %p
sector_num %"PRId64" nb_sectors %d"
bdrv_co_readv_no_serialising(void *bs, int64_t sector_num, int nb_sector) "bs
%p sector_num %"PRId64" nb_sectors %d"
bdrv_co_writev(void *bs, int64_t sector_num, int nb_sector) "bs %p sector_num
%"PRId64" nb_sectors %d"
bdrv_co_write_zeroes(void *bs, int64_t sector_num, int nb_sector, int flags)
"bs %p sector_num %"PRId64" nb_sectors %d flags %#x"
--
1.8.3.1
- [Qemu-devel] [PATCH 00/14] block jobs: Convert I/O to BlockBackend, Kevin Wolf, 2016/05/04
- [Qemu-devel] [PATCH 03/14] block: Default to enabled write cache in blk_new(), Kevin Wolf, 2016/05/04
- [Qemu-devel] [PATCH 04/14] block: Convert block job core to BlockBackend, Kevin Wolf, 2016/05/04
- [Qemu-devel] [PATCH 05/14] stream: Use BlockBackend for I/O,
Kevin Wolf <=
- [Qemu-devel] [PATCH 06/14] mirror: Allow target that already has a BlockBackend, Kevin Wolf, 2016/05/04
- [Qemu-devel] [PATCH 01/14] block: keep a list of block jobs, Kevin Wolf, 2016/05/04
- [Qemu-devel] [PATCH 08/14] backup: Don't leak BackupBlockJob in error path, Kevin Wolf, 2016/05/04
- [Qemu-devel] [PATCH 02/14] block: Cancel jobs first in bdrv_close_all(), Kevin Wolf, 2016/05/04