From: "Benoît Canet" <benoit.canet@irqsave.net>
To: Markus Armbruster <armbru@redhat.com>
Cc: kwolf@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com,
mreitz@redhat.com
Subject: Re: [Qemu-devel] [PATCH v3 09/10] qemu-img: Make img_convert() get image size just once per image
Date: Mon, 2 Jun 2014 17:13:36 +0200 [thread overview]
Message-ID: <20140602151336.GI8181@irqsave.net> (raw)
In-Reply-To: <1401473631-10724-10-git-send-email-armbru@redhat.com>
The Friday 30 May 2014 à 20:13:50 (+0200), Markus Armbruster wrote :
> 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 <armbru@redhat.com>
> Reviewed-by: Max Reitz <mreitz@redhat.com>
> ---
> qemu-img.c | 32 ++++++++++++++++----------------
> 1 file changed, 16 insertions(+), 16 deletions(-)
>
> diff --git a/qemu-img.c b/qemu-img.c
> index 8d996ba..2cb56c5 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -1186,7 +1186,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;
> @@ -1326,7 +1326,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++) {
> @@ -1340,8 +1341,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) {
> @@ -1465,7 +1466,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)
> @@ -1532,19 +1532,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) {
> @@ -1605,14 +1605,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) &&
> @@ -1665,7 +1664,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) {
> @@ -1723,6 +1722,7 @@ out:
> }
> g_free(bs);
> }
> + g_free(bs_sectors);
> fail_getopt:
> g_free(options);
>
> --
> 1.9.3
>
>
Reviewed-by: Benoit Canet <benoit@irqsave.net>
next prev parent reply other threads:[~2014-06-02 15:13 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1401473631-10724-1-git-send-email-armbru@redhat.com>
[not found] ` <1401473631-10724-2-git-send-email-armbru@redhat.com>
2014-06-02 14:50 ` [Qemu-devel] [PATCH v3 01/10] raw-posix: Fix raw_getlength() to always return -errno on error Benoît Canet
[not found] ` <1401473631-10724-3-git-send-email-armbru@redhat.com>
2014-06-02 14:54 ` [Qemu-devel] [PATCH v3 02/10] block: New bdrv_nb_sectors() Benoît Canet
[not found] ` <1401473631-10724-4-git-send-email-armbru@redhat.com>
2014-06-02 14:55 ` [Qemu-devel] [PATCH v3 03/10] block: Use bdrv_nb_sectors() in bdrv_make_zero() Benoît Canet
[not found] ` <1401473631-10724-5-git-send-email-armbru@redhat.com>
2014-06-02 14:58 ` [Qemu-devel] [PATCH v3 04/10] block: Use bdrv_nb_sectors() in bdrv_aligned_preadv() Benoît Canet
[not found] ` <1401473631-10724-6-git-send-email-armbru@redhat.com>
2014-06-02 15:00 ` [Qemu-devel] [PATCH v3 05/10] block: Use bdrv_nb_sectors() in bdrv_co_get_block_status() Benoît Canet
[not found] ` <1401473631-10724-7-git-send-email-armbru@redhat.com>
2014-06-02 15:02 ` [Qemu-devel] [PATCH v3 06/10] block: Use bdrv_nb_sectors() in img_convert() Benoît Canet
[not found] ` <1401473631-10724-8-git-send-email-armbru@redhat.com>
2014-06-02 15:06 ` [Qemu-devel] [PATCH v3 07/10] block: Use bdrv_nb_sectors() where sectors, not bytes are wanted Benoît Canet
2014-06-02 16:45 ` Markus Armbruster
[not found] ` <1401473631-10724-9-git-send-email-armbru@redhat.com>
2014-06-02 15:07 ` [Qemu-devel] [PATCH v3 08/10] block: Drop superfluous aligning of bdrv_getlength()'s value Benoît Canet
[not found] ` <1401473631-10724-10-git-send-email-armbru@redhat.com>
2014-06-02 15:13 ` Benoît Canet [this message]
[not found] ` <1401473631-10724-11-git-send-email-armbru@redhat.com>
2014-06-02 15:22 ` [Qemu-devel] [PATCH v3 10/10] block: Avoid bdrv_get_geometry() where errors should be detected Benoît Canet
2014-06-02 16:49 ` Markus Armbruster
2014-06-04 11:51 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140602151336.GI8181@irqsave.net \
--to=benoit.canet@irqsave.net \
--cc=armbru@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).