[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 11/62] qemu-img: Make img_convert() get image size ju
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 11/62] qemu-img: Make img_convert() get image size just once per image |
Date: |
Fri, 8 Aug 2014 19:39:12 +0200 |
From: Markus Armbruster <address@hidden>
Chiefly so I don't have to do the error checking in quadruplicate in
the next commit. Moreover, replacing the frequently updated
bs_sectors by an array assigned just once makes the code easier to
understand.
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
Reviewed-by: Benoit Canet <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
qemu-img.c | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index 9832a7e..b832997 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1182,7 +1182,7 @@ static int img_convert(int argc, char **argv)
BlockDriver *drv, *proto_drv;
BlockDriverState **bs = NULL, *out_bs = NULL;
int64_t total_sectors, nb_sectors, sector_num, bs_offset;
- uint64_t bs_sectors;
+ uint64_t *bs_sectors = NULL;
uint8_t * buf = NULL;
size_t bufsectors = IO_BUF_SIZE / BDRV_SECTOR_SIZE;
const uint8_t *buf1;
@@ -1323,7 +1323,8 @@ static int img_convert(int argc, char **argv)
qemu_progress_print(0, 100);
- bs = g_malloc0(bs_n * sizeof(BlockDriverState *));
+ bs = g_new0(BlockDriverState *, bs_n);
+ bs_sectors = g_new(uint64_t, bs_n);
total_sectors = 0;
for (bs_i = 0; bs_i < bs_n; bs_i++) {
@@ -1337,8 +1338,8 @@ static int img_convert(int argc, char **argv)
ret = -1;
goto out;
}
- bdrv_get_geometry(bs[bs_i], &bs_sectors);
- total_sectors += bs_sectors;
+ bdrv_get_geometry(bs[bs_i], &bs_sectors[bs_i]);
+ total_sectors += bs_sectors[bs_i];
}
if (sn_opts) {
@@ -1456,7 +1457,6 @@ static int img_convert(int argc, char **argv)
bs_i = 0;
bs_offset = 0;
- bdrv_get_geometry(bs[0], &bs_sectors);
/* increase bufsectors from the default 4096 (2M) if opt_transfer_length
* or discard_alignment of the out_bs is greater. Limit to 32768 (16MB)
@@ -1523,19 +1523,19 @@ static int img_convert(int argc, char **argv)
buf2 = buf;
while (remainder > 0) {
int nlow;
- while (bs_num == bs_sectors) {
+ while (bs_num == bs_sectors[bs_i]) {
+ bs_offset += bs_sectors[bs_i];
bs_i++;
assert (bs_i < bs_n);
- bs_offset += bs_sectors;
- bdrv_get_geometry(bs[bs_i], &bs_sectors);
bs_num = 0;
/* printf("changing part: sector_num=%" PRId64 ", "
"bs_i=%d, bs_offset=%" PRId64 ", bs_sectors=%" PRId64
- "\n", sector_num, bs_i, bs_offset, bs_sectors); */
+ "\n", sector_num, bs_i, bs_offset, bs_sectors[bs_i]); */
}
- assert (bs_num < bs_sectors);
+ assert (bs_num < bs_sectors[bs_i]);
- nlow = (remainder > bs_sectors - bs_num) ? bs_sectors - bs_num
: remainder;
+ nlow = remainder > bs_sectors[bs_i] - bs_num
+ ? bs_sectors[bs_i] - bs_num : remainder;
ret = bdrv_read(bs[bs_i], bs_num, buf2, nlow);
if (ret < 0) {
@@ -1596,14 +1596,13 @@ restart:
break;
}
- while (sector_num - bs_offset >= bs_sectors) {
+ while (sector_num - bs_offset >= bs_sectors[bs_i]) {
+ bs_offset += bs_sectors[bs_i];
bs_i ++;
assert (bs_i < bs_n);
- bs_offset += bs_sectors;
- bdrv_get_geometry(bs[bs_i], &bs_sectors);
/* printf("changing part: sector_num=%" PRId64 ", bs_i=%d, "
"bs_offset=%" PRId64 ", bs_sectors=%" PRId64 "\n",
- sector_num, bs_i, bs_offset, bs_sectors); */
+ sector_num, bs_i, bs_offset, bs_sectors[bs_i]); */
}
if ((out_baseimg || has_zero_init) &&
@@ -1656,7 +1655,7 @@ restart:
}
}
- n = MIN(n, bs_sectors - (sector_num - bs_offset));
+ n = MIN(n, bs_sectors[bs_i] - (sector_num - bs_offset));
sectors_read += n;
if (count_allocated_sectors) {
@@ -1714,6 +1713,7 @@ out:
}
g_free(bs);
}
+ g_free(bs_sectors);
fail_getopt:
g_free(options);
--
1.8.3.1
- [Qemu-devel] [PULL 01/62] nbd: Drop nbd_can_read(), (continued)
- [Qemu-devel] [PULL 01/62] nbd: Drop nbd_can_read(), Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 04/62] block: New bdrv_nb_sectors(), Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 02/62] block: Add AIO context notifiers, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 05/62] block: Use bdrv_nb_sectors() in bdrv_make_zero(), Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 06/62] block: Use bdrv_nb_sectors() in bdrv_aligned_preadv(), Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 03/62] nbd: Follow the BDS' AIO context, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 07/62] block: Use bdrv_nb_sectors() in bdrv_co_get_block_status(), Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 08/62] block: Use bdrv_nb_sectors() in img_convert(), Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 09/62] block: Use bdrv_nb_sectors() where sectors, not bytes are wanted, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 10/62] block: Drop superfluous aligning of bdrv_getlength()'s value, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 11/62] qemu-img: Make img_convert() get image size just once per image,
Kevin Wolf <=
- [Qemu-devel] [PULL 12/62] block: Avoid bdrv_get_geometry() where errors should be detected, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 14/62] configure: explicitly state version requirements to devel packages, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 15/62] xen_disk: fix possible null-ptr dereference, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 13/62] docs: Make the recommendation for the backing file name position a requirement, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 16/62] docs/multiple-iothreads.txt: add documentation on IOThread programming, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 18/62] qdev-monitor: include QOM properties in -device FOO, help output, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 17/62] qmp: hide "hotplugged" device property from device-list-properties, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 19/62] qemu-iotests: Add data pattern in version3 VMDK sample image in 059, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 21/62] qemu-img info: show nocow info, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 20/62] vmdk: Optimize cluster allocation, Kevin Wolf, 2014/08/08