From: Kevin Wolf <kwolf@redhat.com>
To: anthony@codemonkey.ws
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 5/6] qemu-img: make progress output more accurate during convert
Date: Fri, 13 Dec 2013 18:49:02 +0100 [thread overview]
Message-ID: <1386956943-19474-6-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1386956943-19474-1-git-send-email-kwolf@redhat.com>
From: Peter Lieven <pl@kamp.de>
the progress output is very bumpy if the input images contains
a significant portion of unallocated sectors. This patch
checks how much sectors are allocated a priori if progress
output is selected.
Signed-off-by: Peter Lieven <pl@kamp.de>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
qemu-img.c | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index 7dfe982..a4b3931 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1135,8 +1135,7 @@ static int img_convert(int argc, char **argv)
const char *fmt, *out_fmt, *cache, *out_baseimg, *out_filename;
BlockDriver *drv, *proto_drv;
BlockDriverState **bs = NULL, *out_bs = NULL;
- int64_t total_sectors, nb_sectors, sector_num, bs_offset,
- sector_num_next_status = 0;
+ int64_t total_sectors, nb_sectors, sector_num, bs_offset;
uint64_t bs_sectors;
uint8_t * buf = NULL;
size_t bufsectors = IO_BUF_SIZE / BDRV_SECTOR_SIZE;
@@ -1505,6 +1504,8 @@ static int img_convert(int argc, char **argv)
/* signal EOF to align */
bdrv_write_compressed(out_bs, 0, NULL, 0);
} else {
+ int64_t sectors_to_read, sectors_read, sector_num_next_status;
+ bool count_allocated_sectors;
int has_zero_init = min_sparse ? bdrv_has_zero_init(out_bs) : 0;
if (!has_zero_init && bdrv_can_write_zeroes_with_unmap(out_bs)) {
@@ -1515,12 +1516,21 @@ static int img_convert(int argc, char **argv)
has_zero_init = 1;
}
+ sectors_to_read = total_sectors;
+ count_allocated_sectors = progress && (out_baseimg || has_zero_init);
+restart:
sector_num = 0; // total number of sectors converted so far
- nb_sectors = total_sectors - sector_num;
+ sectors_read = 0;
+ sector_num_next_status = 0;
for(;;) {
nb_sectors = total_sectors - sector_num;
if (nb_sectors <= 0) {
+ if (count_allocated_sectors) {
+ sectors_to_read = sectors_read;
+ count_allocated_sectors = false;
+ goto restart;
+ }
ret = 0;
break;
}
@@ -1586,8 +1596,14 @@ static int img_convert(int argc, char **argv)
}
n = MIN(n, bs_sectors - (sector_num - bs_offset));
- n1 = n;
+ sectors_read += n;
+ if (count_allocated_sectors) {
+ sector_num += n;
+ continue;
+ }
+
+ n1 = n;
ret = bdrv_read(bs[bs_i], sector_num - bs_offset, buf, n);
if (ret < 0) {
error_report("error while reading sector %" PRId64 ": %s",
@@ -1612,7 +1628,7 @@ static int img_convert(int argc, char **argv)
n -= n1;
buf1 += n1 * 512;
}
- qemu_progress_print(100.0 * sector_num / total_sectors, 0);
+ qemu_progress_print(100.0 * sectors_read / sectors_to_read, 0);
}
}
out:
--
1.8.1.4
next prev parent reply other threads:[~2013-12-13 17:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-13 17:48 [Qemu-devel] [PULL 0/6] Block patches Kevin Wolf
2013-12-13 17:48 ` [Qemu-devel] [PULL 1/6] sheepdog: check if '-o redundancy' is passed from user Kevin Wolf
2013-12-13 17:48 ` [Qemu-devel] [PULL 2/6] qapi-schema.json: Change 1.8 reference to 2.0 Kevin Wolf
2013-12-13 17:49 ` [Qemu-devel] [PULL 3/6] block/vvfat: Fix compiler warnings for OpenBSD Kevin Wolf
2013-12-13 17:49 ` [Qemu-devel] [PULL 4/6] block: expect get_block_status errors in bdrv_make_zero Kevin Wolf
2013-12-13 17:49 ` Kevin Wolf [this message]
2013-12-13 17:49 ` [Qemu-devel] [PULL 6/6] blkdebug: Use QLIST_FOREACH_SAFE to resume IO Kevin Wolf
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=1386956943-19474-6-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=anthony@codemonkey.ws \
--cc=qemu-devel@nongnu.org \
/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).