[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 21/46] vdi: change goto to loop
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 21/46] vdi: change goto to loop |
Date: |
Thu, 5 Apr 2012 17:51:59 +0200 |
From: Paolo Bonzini <address@hidden>
Finally reindent all code and change goto statements to a loop.
Acked-by: Stefan Weil <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/vdi.c | 143 ++++++++++++++++++++++++++++------------------------------
1 files changed, 69 insertions(+), 74 deletions(-)
diff --git a/block/vdi.c b/block/vdi.c
index bfeafea..119d3c7 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -474,41 +474,38 @@ static int vdi_co_read(BlockDriverState *bs,
uint32_t block_index;
uint32_t sector_in_block;
uint32_t n_sectors;
- int ret;
+ int ret = 0;
logout("\n");
-restart:
- block_index = sector_num / s->block_sectors;
- sector_in_block = sector_num % s->block_sectors;
- n_sectors = s->block_sectors - sector_in_block;
- if (n_sectors > nb_sectors) {
- n_sectors = nb_sectors;
- }
-
- logout("will read %u sectors starting at sector %" PRIu64 "\n",
- n_sectors, sector_num);
+ while (ret >= 0 && nb_sectors > 0) {
+ block_index = sector_num / s->block_sectors;
+ sector_in_block = sector_num % s->block_sectors;
+ n_sectors = s->block_sectors - sector_in_block;
+ if (n_sectors > nb_sectors) {
+ n_sectors = nb_sectors;
+ }
- /* prepare next AIO request */
- bmap_entry = le32_to_cpu(s->bmap[block_index]);
- if (!VDI_IS_ALLOCATED(bmap_entry)) {
- /* Block not allocated, return zeros, no need to wait. */
- memset(buf, 0, n_sectors * SECTOR_SIZE);
- ret = 0;
- } else {
- uint64_t offset = s->header.offset_data / SECTOR_SIZE +
- (uint64_t)bmap_entry * s->block_sectors +
- sector_in_block;
- ret = bdrv_read(bs->file, offset, buf, n_sectors);
- }
- logout("%u sectors read\n", n_sectors);
+ logout("will read %u sectors starting at sector %" PRIu64 "\n",
+ n_sectors, sector_num);
- nb_sectors -= n_sectors;
- sector_num += n_sectors;
- buf += n_sectors * SECTOR_SIZE;
+ /* prepare next AIO request */
+ bmap_entry = le32_to_cpu(s->bmap[block_index]);
+ if (!VDI_IS_ALLOCATED(bmap_entry)) {
+ /* Block not allocated, return zeros, no need to wait. */
+ memset(buf, 0, n_sectors * SECTOR_SIZE);
+ ret = 0;
+ } else {
+ uint64_t offset = s->header.offset_data / SECTOR_SIZE +
+ (uint64_t)bmap_entry * s->block_sectors +
+ sector_in_block;
+ ret = bdrv_read(bs->file, offset, buf, n_sectors);
+ }
+ logout("%u sectors read\n", n_sectors);
- if (ret >= 0 && nb_sectors > 0) {
- goto restart;
+ nb_sectors -= n_sectors;
+ sector_num += n_sectors;
+ buf += n_sectors * SECTOR_SIZE;
}
return ret;
@@ -525,57 +522,55 @@ static int vdi_co_write(BlockDriverState *bs,
uint32_t bmap_first = VDI_UNALLOCATED;
uint32_t bmap_last = VDI_UNALLOCATED;
uint8_t *block = NULL;
- int ret;
+ int ret = 0;
logout("\n");
-restart:
- block_index = sector_num / s->block_sectors;
- sector_in_block = sector_num % s->block_sectors;
- n_sectors = s->block_sectors - sector_in_block;
- if (n_sectors > nb_sectors) {
- n_sectors = nb_sectors;
- }
-
- logout("will write %u sectors starting at sector %" PRIu64 "\n",
- n_sectors, sector_num);
+ while (ret >= 0 && nb_sectors > 0) {
+ block_index = sector_num / s->block_sectors;
+ sector_in_block = sector_num % s->block_sectors;
+ n_sectors = s->block_sectors - sector_in_block;
+ if (n_sectors > nb_sectors) {
+ n_sectors = nb_sectors;
+ }
- /* prepare next AIO request */
- bmap_entry = le32_to_cpu(s->bmap[block_index]);
- if (!VDI_IS_ALLOCATED(bmap_entry)) {
- /* Allocate new block and write to it. */
- uint64_t offset;
- bmap_entry = s->header.blocks_allocated;
- s->bmap[block_index] = cpu_to_le32(bmap_entry);
- s->header.blocks_allocated++;
- offset = s->header.offset_data / SECTOR_SIZE +
- (uint64_t)bmap_entry * s->block_sectors;
- if (block == NULL) {
- block = g_malloc(s->block_size);
- bmap_first = block_index;
+ logout("will write %u sectors starting at sector %" PRIu64 "\n",
+ n_sectors, sector_num);
+
+ /* prepare next AIO request */
+ bmap_entry = le32_to_cpu(s->bmap[block_index]);
+ if (!VDI_IS_ALLOCATED(bmap_entry)) {
+ /* Allocate new block and write to it. */
+ uint64_t offset;
+ bmap_entry = s->header.blocks_allocated;
+ s->bmap[block_index] = cpu_to_le32(bmap_entry);
+ s->header.blocks_allocated++;
+ offset = s->header.offset_data / SECTOR_SIZE +
+ (uint64_t)bmap_entry * s->block_sectors;
+ if (block == NULL) {
+ block = g_malloc(s->block_size);
+ bmap_first = block_index;
+ }
+ bmap_last = block_index;
+ /* Copy data to be written to new block and zero unused parts. */
+ memset(block, 0, sector_in_block * SECTOR_SIZE);
+ memcpy(block + sector_in_block * SECTOR_SIZE,
+ 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);
+ 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;
+ ret = bdrv_write(bs->file, offset, buf, n_sectors);
}
- bmap_last = block_index;
- /* Copy data to be written to new block and zero unused parts. */
- memset(block, 0, sector_in_block * SECTOR_SIZE);
- memcpy(block + sector_in_block * SECTOR_SIZE,
- 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);
- 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;
- ret = bdrv_write(bs->file, offset, buf, n_sectors);
- }
- nb_sectors -= n_sectors;
- sector_num += n_sectors;
- buf += n_sectors * SECTOR_SIZE;
+ nb_sectors -= n_sectors;
+ sector_num += n_sectors;
+ buf += n_sectors * SECTOR_SIZE;
- logout("%u sectors written\n", n_sectors);
- if (ret >= 0 && nb_sectors > 0) {
- goto restart;
+ logout("%u sectors written\n", n_sectors);
}
logout("finished data write\n");
--
1.7.6.5
- [Qemu-devel] [PATCH 08/46] ide: Add "model=s" qdev option, (continued)
- [Qemu-devel] [PATCH 08/46] ide: Add "model=s" qdev option, Kevin Wolf, 2012/04/05
- [Qemu-devel] [PATCH 17/46] vdi: merge aio_read_cb and aio_write_cb into callers, Kevin Wolf, 2012/04/05
- [Qemu-devel] [PATCH 18/46] vdi: move aiocb fields to locals, Kevin Wolf, 2012/04/05
- [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 <=
- [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, 2012/04/05
- [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