[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 20/46] vdi: do not create useless iovecs
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 20/46] vdi: do not create useless iovecs |
Date: |
Thu, 5 Apr 2012 17:51:58 +0200 |
From: Paolo Bonzini <address@hidden>
Reads and writes to the underlying file can also occur with the simple
non-vectored I/O interfaces.
Acked-by: Stefan Weil <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/vdi.c | 79 ++++++++++++++++++++++++----------------------------------
1 files changed, 33 insertions(+), 46 deletions(-)
diff --git a/block/vdi.c b/block/vdi.c
index 790b61e..bfeafea 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -474,8 +474,6 @@ static int vdi_co_read(BlockDriverState *bs,
uint32_t block_index;
uint32_t sector_in_block;
uint32_t n_sectors;
- struct iovec hd_iov;
- QEMUIOVector hd_qiov;
int ret;
logout("\n");
@@ -501,10 +499,7 @@ restart:
uint64_t offset = s->header.offset_data / SECTOR_SIZE +
(uint64_t)bmap_entry * s->block_sectors +
sector_in_block;
- hd_iov.iov_base = (void *)buf;
- hd_iov.iov_len = n_sectors * SECTOR_SIZE;
- qemu_iovec_init_external(&hd_qiov, &hd_iov, 1);
- ret = bdrv_co_readv(bs->file, offset, n_sectors, &hd_qiov);
+ ret = bdrv_read(bs->file, offset, buf, n_sectors);
}
logout("%u sectors read\n", n_sectors);
@@ -529,8 +524,6 @@ static int vdi_co_write(BlockDriverState *bs,
uint32_t n_sectors;
uint32_t bmap_first = VDI_UNALLOCATED;
uint32_t bmap_last = VDI_UNALLOCATED;
- struct iovec hd_iov;
- QEMUIOVector hd_qiov;
uint8_t *block = NULL;
int ret;
@@ -568,18 +561,12 @@ restart:
buf, n_sectors * SECTOR_SIZE);
memset(block + (sector_in_block + n_sectors) * SECTOR_SIZE, 0,
(s->block_sectors - n_sectors - sector_in_block) * SECTOR_SIZE);
- hd_iov.iov_base = (void *)block;
- hd_iov.iov_len = s->block_size;
- qemu_iovec_init_external(&hd_qiov, &hd_iov, 1);
- ret = bdrv_co_writev(bs->file, offset, s->block_sectors, &hd_qiov);
+ ret = bdrv_write(bs->file, offset, block, s->block_sectors);
} else {
uint64_t offset = s->header.offset_data / SECTOR_SIZE +
(uint64_t)bmap_entry * s->block_sectors +
sector_in_block;
- hd_iov.iov_base = (void *)buf;
- hd_iov.iov_len = n_sectors * SECTOR_SIZE;
- qemu_iovec_init_external(&hd_qiov, &hd_iov, 1);
- ret = bdrv_co_writev(bs->file, offset, n_sectors, &hd_qiov);
+ ret = bdrv_write(bs->file, offset, buf, n_sectors);
}
nb_sectors -= n_sectors;
@@ -592,39 +579,39 @@ restart:
}
logout("finished data write\n");
- if (ret >= 0) {
- ret = 0;
- if (block) {
- VdiHeader *header = (VdiHeader *) block;
- logout("now writing modified header\n");
- assert(VDI_IS_ALLOCATED(bmap_first));
- *header = s->header;
- vdi_header_to_le(header);
- hd_iov.iov_base = block;
- hd_iov.iov_len = SECTOR_SIZE;
- qemu_iovec_init_external(&hd_qiov, &hd_iov, 1);
- ret = bdrv_co_writev(bs->file, 0, 1, &hd_qiov);
- }
+ if (ret < 0) {
+ return ret;
+ }
+
+ if (block) {
+ /* One or more new blocks were allocated. */
+ VdiHeader *header = (VdiHeader *) block;
+ uint8_t *base;
+ uint64_t offset;
+
+ logout("now writing modified header\n");
+ assert(VDI_IS_ALLOCATED(bmap_first));
+ *header = s->header;
+ vdi_header_to_le(header);
+ ret = bdrv_write(bs->file, 0, block, 1);
g_free(block);
block = NULL;
- if (ret >= 0 && VDI_IS_ALLOCATED(bmap_first)) {
- /* One or more new blocks were allocated. */
- uint64_t offset;
- logout("now writing modified block map entry %u...%u\n",
- bmap_first, bmap_last);
- /* Write modified sectors from block map. */
- bmap_first /= (SECTOR_SIZE / sizeof(uint32_t));
- bmap_last /= (SECTOR_SIZE / sizeof(uint32_t));
- n_sectors = bmap_last - bmap_first + 1;
- offset = s->bmap_sector + bmap_first;
- hd_iov.iov_base = (void *)((uint8_t *)&s->bmap[0] +
- bmap_first * SECTOR_SIZE);
- hd_iov.iov_len = n_sectors * SECTOR_SIZE;
- qemu_iovec_init_external(&hd_qiov, &hd_iov, 1);
- logout("will write %u block map sectors starting from entry %u\n",
- n_sectors, bmap_first);
- ret = bdrv_co_writev(bs->file, offset, n_sectors, &hd_qiov);
+
+ if (ret < 0) {
+ return ret;
}
+
+ logout("now writing modified block map entry %u...%u\n",
+ bmap_first, bmap_last);
+ /* Write modified sectors from block map. */
+ bmap_first /= (SECTOR_SIZE / sizeof(uint32_t));
+ bmap_last /= (SECTOR_SIZE / sizeof(uint32_t));
+ n_sectors = bmap_last - bmap_first + 1;
+ offset = s->bmap_sector + bmap_first;
+ 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, offset, base, n_sectors);
}
return ret;
--
1.7.6.5
- [Qemu-devel] [PATCH 23/46] block: disable I/O throttling on sync api, (continued)
- [Qemu-devel] [PATCH 23/46] block: disable I/O throttling on sync api, Kevin Wolf, 2012/04/05
- [Qemu-devel] [PATCH 24/46] block: cancel jobs when a device is ready to go away, Kevin Wolf, 2012/04/05
- [Qemu-devel] [PATCH 22/46] Use DMADirection type for dma_bdrv_io, Kevin Wolf, 2012/04/05
- [Qemu-devel] [PATCH 43/46] qed: add bdrv_invalidate_cache to be called after incoming live migration, Kevin Wolf, 2012/04/05
- [Qemu-devel] [PATCH 37/46] qemu-iotests: Fix call syntax for qemu-img, Kevin Wolf, 2012/04/05
- [Qemu-devel] [PATCH 38/46] qemu-iotests: Fix call syntax for qemu-io, Kevin Wolf, 2012/04/05
- [Qemu-devel] [PATCH 28/46] qemu-img: add image fragmentation statistics, Kevin Wolf, 2012/04/05
- [Qemu-devel] [PATCH 21/46] vdi: change goto to loop, Kevin Wolf, 2012/04/05
- [Qemu-devel] [PATCH 32/46] block: bdrv_append() fixes, Kevin Wolf, 2012/04/05
- [Qemu-devel] [PATCH 13/46] qdev: add blocksize property type, Kevin Wolf, 2012/04/05
- [Qemu-devel] [PATCH 20/46] vdi: do not create useless iovecs,
Kevin Wolf <=
- [Qemu-devel] [PATCH 42/46] blockdev: open images with BDRV_O_INCOMING on incoming live migration, Kevin Wolf, 2012/04/05
- [Qemu-devel] [PATCH 25/46] block: fix streaming/closing race, Kevin Wolf, 2012/04/05
- [Qemu-devel] [PATCH 36/46] qemu-iotests: Test unknown qcow2 header extensions, Kevin Wolf, 2012/04/05
- [Qemu-devel] [PATCH 33/46] sheepdog: implement SD_OP_FLUSH_VDI operation, Kevin Wolf, 2012/04/05
- [Qemu-devel] [PATCH 11/46] block/vpc: write checksum back to footer after check, Kevin Wolf, 2012/04/05
- [Qemu-devel] [PATCH 15/46] vdi: basic conversion to coroutines, Kevin Wolf, 2012/04/05
- [Qemu-devel] [PATCH 09/46] ide: Change serial number strncpy() to pstrcpy(), Kevin Wolf, 2012/04/05
- [Qemu-devel] [PATCH 27/46] block: document job API, Kevin Wolf, 2012/04/05
- [Qemu-devel] [PATCH 19/46] vdi: leave bounce buffering to block layer, Kevin Wolf, 2012/04/05
- [Qemu-devel] [PATCH 29/46] qed: image fragmentation statistics, Kevin Wolf, 2012/04/05