vdi: do not create useless iovecs
Reads and writes to the underlying file can also occur with the simple non-vectored I/O interfaces. Acked-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
a7a43aa199
commit
4eea78e634
79
block/vdi.c
79
block/vdi.c
@ -474,8 +474,6 @@ static int vdi_co_read(BlockDriverState *bs,
|
|||||||
uint32_t block_index;
|
uint32_t block_index;
|
||||||
uint32_t sector_in_block;
|
uint32_t sector_in_block;
|
||||||
uint32_t n_sectors;
|
uint32_t n_sectors;
|
||||||
struct iovec hd_iov;
|
|
||||||
QEMUIOVector hd_qiov;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
logout("\n");
|
logout("\n");
|
||||||
@ -501,10 +499,7 @@ restart:
|
|||||||
uint64_t offset = s->header.offset_data / SECTOR_SIZE +
|
uint64_t offset = s->header.offset_data / SECTOR_SIZE +
|
||||||
(uint64_t)bmap_entry * s->block_sectors +
|
(uint64_t)bmap_entry * s->block_sectors +
|
||||||
sector_in_block;
|
sector_in_block;
|
||||||
hd_iov.iov_base = (void *)buf;
|
ret = bdrv_read(bs->file, offset, buf, n_sectors);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
logout("%u sectors read\n", 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 n_sectors;
|
||||||
uint32_t bmap_first = VDI_UNALLOCATED;
|
uint32_t bmap_first = VDI_UNALLOCATED;
|
||||||
uint32_t bmap_last = VDI_UNALLOCATED;
|
uint32_t bmap_last = VDI_UNALLOCATED;
|
||||||
struct iovec hd_iov;
|
|
||||||
QEMUIOVector hd_qiov;
|
|
||||||
uint8_t *block = NULL;
|
uint8_t *block = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -568,18 +561,12 @@ restart:
|
|||||||
buf, n_sectors * SECTOR_SIZE);
|
buf, n_sectors * SECTOR_SIZE);
|
||||||
memset(block + (sector_in_block + n_sectors) * SECTOR_SIZE, 0,
|
memset(block + (sector_in_block + n_sectors) * SECTOR_SIZE, 0,
|
||||||
(s->block_sectors - n_sectors - sector_in_block) * SECTOR_SIZE);
|
(s->block_sectors - n_sectors - sector_in_block) * SECTOR_SIZE);
|
||||||
hd_iov.iov_base = (void *)block;
|
ret = bdrv_write(bs->file, offset, block, s->block_sectors);
|
||||||
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);
|
|
||||||
} else {
|
} else {
|
||||||
uint64_t offset = s->header.offset_data / SECTOR_SIZE +
|
uint64_t offset = s->header.offset_data / SECTOR_SIZE +
|
||||||
(uint64_t)bmap_entry * s->block_sectors +
|
(uint64_t)bmap_entry * s->block_sectors +
|
||||||
sector_in_block;
|
sector_in_block;
|
||||||
hd_iov.iov_base = (void *)buf;
|
ret = bdrv_write(bs->file, offset, buf, n_sectors);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nb_sectors -= n_sectors;
|
nb_sectors -= n_sectors;
|
||||||
@ -592,39 +579,39 @@ restart:
|
|||||||
}
|
}
|
||||||
|
|
||||||
logout("finished data write\n");
|
logout("finished data write\n");
|
||||||
if (ret >= 0) {
|
if (ret < 0) {
|
||||||
ret = 0;
|
return ret;
|
||||||
if (block) {
|
}
|
||||||
VdiHeader *header = (VdiHeader *) block;
|
|
||||||
logout("now writing modified header\n");
|
if (block) {
|
||||||
assert(VDI_IS_ALLOCATED(bmap_first));
|
/* One or more new blocks were allocated. */
|
||||||
*header = s->header;
|
VdiHeader *header = (VdiHeader *) block;
|
||||||
vdi_header_to_le(header);
|
uint8_t *base;
|
||||||
hd_iov.iov_base = block;
|
uint64_t offset;
|
||||||
hd_iov.iov_len = SECTOR_SIZE;
|
|
||||||
qemu_iovec_init_external(&hd_qiov, &hd_iov, 1);
|
logout("now writing modified header\n");
|
||||||
ret = bdrv_co_writev(bs->file, 0, 1, &hd_qiov);
|
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);
|
g_free(block);
|
||||||
block = NULL;
|
block = NULL;
|
||||||
if (ret >= 0 && VDI_IS_ALLOCATED(bmap_first)) {
|
|
||||||
/* One or more new blocks were allocated. */
|
if (ret < 0) {
|
||||||
uint64_t offset;
|
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;
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user