[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH 12/17] block: Convert bdrv_write() to BdrvChild
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PATCH 12/17] block: Convert bdrv_write() to BdrvChild |
Date: |
Tue, 21 Jun 2016 11:21:29 +0200 |
Signed-off-by: Kevin Wolf <address@hidden>
---
block/io.c | 5 +++--
block/qcow.c | 10 +++++++++-
block/qcow2-cluster.c | 2 +-
block/qcow2-refcount.c | 2 +-
block/qcow2.c | 10 +++++++++-
block/vdi.c | 4 ++--
block/vvfat.c | 5 ++---
include/block/block.h | 2 +-
8 files changed, 28 insertions(+), 12 deletions(-)
diff --git a/block/io.c b/block/io.c
index d14c982..80ecfdc 100644
--- a/block/io.c
+++ b/block/io.c
@@ -646,10 +646,11 @@ int bdrv_read(BdrvChild *child, int64_t sector_num,
-EINVAL Invalid sector number or nb_sectors
-EACCES Trying to write a read-only device
*/
-int bdrv_write(BlockDriverState *bs, int64_t sector_num,
+int bdrv_write(BdrvChild *child, int64_t sector_num,
const uint8_t *buf, int nb_sectors)
{
- return bdrv_rw_co(bs, sector_num, (uint8_t *)buf, nb_sectors, true, 0);
+ return bdrv_rw_co(child->bs, sector_num, (uint8_t *)buf, nb_sectors,
+ true, 0);
}
int bdrv_pwrite_zeroes(BlockDriverState *bs, int64_t offset,
diff --git a/block/qcow.c b/block/qcow.c
index e09827b..c80df78 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -969,7 +969,15 @@ static int qcow_write_compressed(BlockDriverState *bs,
int64_t sector_num,
if (ret != Z_STREAM_END || out_len >= s->cluster_size) {
/* could not compress: write normal cluster */
- ret = bdrv_write(bs, sector_num, buf, s->cluster_sectors);
+ QEMUIOVector qiov;
+ struct iovec iov = {
+ .iov_base = (uint8_t*) buf,
+ .iov_len = nb_sectors * BDRV_SECTOR_SIZE,
+ };
+ qemu_iovec_init_external(&qiov, &iov, 1);
+
+ ret = bs->drv->bdrv_co_writev(bs, sector_num, s->cluster_sectors,
+ &qiov);
if (ret < 0) {
goto fail;
}
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index ed9832a..c2b78ad 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -1786,7 +1786,7 @@ static int expand_zero_clusters_in_l1(BlockDriverState
*bs, uint64_t *l1_table,
goto fail;
}
- ret = bdrv_write(bs->file->bs, l2_offset / BDRV_SECTOR_SIZE,
+ ret = bdrv_write(bs->file, l2_offset / BDRV_SECTOR_SIZE,
(void *)l2_table, s->cluster_sectors);
if (ret < 0) {
goto fail;
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 66f187a..7d391a5 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -2101,7 +2101,7 @@ write_refblocks:
on_disk_refblock = (void *)((char *) *refcount_table +
refblock_index * s->cluster_size);
- ret = bdrv_write(bs->file->bs, refblock_offset / BDRV_SECTOR_SIZE,
+ ret = bdrv_write(bs->file, refblock_offset / BDRV_SECTOR_SIZE,
on_disk_refblock, s->cluster_sectors);
if (ret < 0) {
fprintf(stderr, "ERROR writing refblock: %s\n", strerror(-ret));
diff --git a/block/qcow2.c b/block/qcow2.c
index 4718f82..bc78af3 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2597,7 +2597,15 @@ static int qcow2_write_compressed(BlockDriverState *bs,
int64_t sector_num,
if (ret != Z_STREAM_END || out_len >= s->cluster_size) {
/* could not compress: write normal cluster */
- ret = bdrv_write(bs, sector_num, buf, s->cluster_sectors);
+ QEMUIOVector qiov;
+ struct iovec iov = {
+ .iov_base = (uint8_t*) buf,
+ .iov_len = nb_sectors * BDRV_SECTOR_SIZE,
+ };
+ qemu_iovec_init_external(&qiov, &iov, 1);
+
+ ret = bs->drv->bdrv_co_writev(bs, sector_num, s->cluster_sectors,
+ &qiov);
if (ret < 0) {
goto fail;
}
diff --git a/block/vdi.c b/block/vdi.c
index 46a3436..b2871ca 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -719,7 +719,7 @@ vdi_co_pwritev(BlockDriverState *bs, uint64_t offset,
uint64_t bytes,
assert(VDI_IS_ALLOCATED(bmap_first));
*header = s->header;
vdi_header_to_le(header);
- ret = bdrv_write(bs->file->bs, 0, block, 1);
+ ret = bdrv_write(bs->file, 0, block, 1);
g_free(block);
block = NULL;
@@ -737,7 +737,7 @@ vdi_co_pwritev(BlockDriverState *bs, uint64_t offset,
uint64_t bytes,
base = ((uint8_t *)&s->bmap[0]) + bmap_first * SECTOR_SIZE;
logout("will write %u block map sectors starting from entry %u\n",
n_sectors, bmap_first);
- ret = bdrv_write(bs->file->bs, offset, base, n_sectors);
+ ret = bdrv_write(bs->file, offset, base, n_sectors);
}
return ret;
diff --git a/block/vvfat.c b/block/vvfat.c
index 1d287a2..a81e040 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -1833,8 +1833,7 @@ static uint32_t
get_cluster_count_for_direntry(BDRVVVFATState* s,
if (res) {
return -1;
}
- res = bdrv_write(s->qcow->bs, offset,
- s->cluster_buffer, 1);
+ res = bdrv_write(s->qcow, offset, s->cluster_buffer,
1);
if (res) {
return -2;
}
@@ -2888,7 +2887,7 @@ DLOG(checkpoint());
* Use qcow backend. Commit later.
*/
DLOG(fprintf(stderr, "Write to qcow backend: %d + %d\n", (int)sector_num,
nb_sectors));
- ret = bdrv_write(s->qcow->bs, sector_num, buf, nb_sectors);
+ ret = bdrv_write(s->qcow, sector_num, buf, nb_sectors);
if (ret < 0) {
fprintf(stderr, "Error writing to qcow backend\n");
return ret;
diff --git a/include/block/block.h b/include/block/block.h
index 47c0177..7eadfaf 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -228,7 +228,7 @@ void bdrv_reopen_commit(BDRVReopenState *reopen_state);
void bdrv_reopen_abort(BDRVReopenState *reopen_state);
int bdrv_read(BdrvChild *child, int64_t sector_num,
uint8_t *buf, int nb_sectors);
-int bdrv_write(BlockDriverState *bs, int64_t sector_num,
+int bdrv_write(BdrvChild *child, int64_t sector_num,
const uint8_t *buf, int nb_sectors);
int bdrv_pwrite_zeroes(BlockDriverState *bs, int64_t offset,
int count, BdrvRequestFlags flags);
--
1.8.3.1
- Re: [Qemu-block] [PATCH 01/17] vvfat: Use BdrvChild for s->qcow, (continued)
- [Qemu-block] [PATCH 04/17] block: Convert bdrv_co_readv() to BdrvChild, Kevin Wolf, 2016/06/21
- [Qemu-block] [PATCH 05/17] block: Convert bdrv_co_writev() to BdrvChild, Kevin Wolf, 2016/06/21
- [Qemu-block] [PATCH 08/17] block: Convert bdrv_co_do_readv/writev to BdrvChild, Kevin Wolf, 2016/06/21
- [Qemu-block] [PATCH 07/17] block: Convert bdrv_aio_writev() to BdrvChild, Kevin Wolf, 2016/06/21
- [Qemu-block] [PATCH 12/17] block: Convert bdrv_write() to BdrvChild,
Kevin Wolf <=
- Re: [Qemu-block] [PATCH 12/17] block: Convert bdrv_write() to BdrvChild, Max Reitz, 2016/06/27
- Re: [Qemu-block] [PATCH 12/17] block: Convert bdrv_write() to BdrvChild, Max Reitz, 2016/06/27
- [Qemu-block] [PATCH v2 12/17] block: Convert bdrv_write() to BdrvChild, Kevin Wolf, 2016/06/29
- Re: [Qemu-block] [PATCH v2 12/17] block: Convert bdrv_write() to BdrvChild, Max Reitz, 2016/06/29
- Re: [Qemu-block] [PATCH v2 12/17] block: Convert bdrv_write() to BdrvChild, Kevin Wolf, 2016/06/29
- Re: [Qemu-block] [PATCH v2 12/17] block: Convert bdrv_write() to BdrvChild, Max Reitz, 2016/06/29
[Qemu-block] [PATCH 10/17] block: Use BlockBackend for I/O in bdrv_commit(), Kevin Wolf, 2016/06/21
[Qemu-block] [PATCH 09/17] block: Move bdrv_commit() to block/commit.c, Kevin Wolf, 2016/06/21