From patchwork Mon Nov 25 13:57:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 293991 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 78C0D2C00C1 for ; Tue, 26 Nov 2013 00:59:59 +1100 (EST) Received: from localhost ([::1]:52905 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vkwhg-00077U-VV for incoming@patchwork.ozlabs.org; Mon, 25 Nov 2013 08:59:56 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57102) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vkwfz-0004lm-4u for qemu-devel@nongnu.org; Mon, 25 Nov 2013 08:58:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vkwfs-0006kZ-9a for qemu-devel@nongnu.org; Mon, 25 Nov 2013 08:58:11 -0500 Received: from mx.ipv6.kamp.de ([2a02:248:0:51::16]:48497 helo=mx01.kamp.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vkwfr-0006kM-VP for qemu-devel@nongnu.org; Mon, 25 Nov 2013 08:58:04 -0500 Received: (qmail 4671 invoked by uid 89); 25 Nov 2013 13:58:03 -0000 Received: from [82.141.1.145] by client-16-kamp (envelope-from , uid 89) with qmail-scanner-2010/03/19-MF (clamdscan: 0.98/18158. hbedv: 8.2.12.150/7.11.115.110. spamassassin: 3.3.1. Clear:RC:1(82.141.1.145):SA:0(-1.2/4.0):. Processed in 1.293507 secs); 25 Nov 2013 13:58:03 -0000 Received: from ns.kamp-intra.net (HELO dns.kamp-intra.net) ([82.141.1.145]) by mx01.kamp.de with SMTP; 25 Nov 2013 13:58:01 -0000 X-GL_Whitelist: yes Received: from lieven-pc.kamp-intra.net (lieven-pc.kamp-intra.net [172.21.12.60]) by dns.kamp-intra.net (Postfix) with ESMTP id 25939206AD; Mon, 25 Nov 2013 14:57:00 +0100 (CET) Received: by lieven-pc.kamp-intra.net (Postfix, from userid 1000) id 95C085FA86; Mon, 25 Nov 2013 14:57:23 +0100 (CET) From: Peter Lieven To: qemu-devel@nongnu.org Date: Mon, 25 Nov 2013 14:57:20 +0100 Message-Id: <1385387840-17307-7-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1385387840-17307-1-git-send-email-pl@kamp.de> References: <1385387840-17307-1-git-send-email-pl@kamp.de> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a02:248:0:51::16 Cc: kwolf@redhat.com, pbonzini@redhat.com, Peter Lieven , stefanha@redhat.com Subject: [Qemu-devel] [PATCH 1.8 6/6] qemu-img: add option to show progress in sectors X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Peter Lieven --- qemu-img-cmds.hx | 4 ++-- qemu-img.c | 23 ++++++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index 266cdf3..4190ec1 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -34,9 +34,9 @@ STEXI ETEXI DEF("convert", img_convert, - "convert [-c] [-p] [-q] [-n] [-a] [-f fmt] [-t cache] [-O output_fmt] [-o options] [-s snapshot_name] [-S sparse_size] [-m iobuf_size] filename [filename2 [...]] output_filename") + "convert [-c] [-p|pp] [-q] [-n] [-a] [-f fmt] [-t cache] [-O output_fmt] [-o options] [-s snapshot_name] [-S sparse_size] [-m iobuf_size] filename [filename2 [...]] output_filename") STEXI -@item convert [-c] [-p] [-q] [-n] [-a] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] [-m @var{iobuf_size}] @var{filename} [@var{filename2} [...]] @var{output_filename} +@item convert [-c] [-p|pp] [-q] [-n] [-a] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] [-m @var{iobuf_size}] @var{filename} [@var{filename2} [...]] @var{output_filename} ETEXI DEF("info", img_info, diff --git a/qemu-img.c b/qemu-img.c index 9fa8fd4..f58247f 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -99,6 +99,7 @@ static void help(void) " rebasing in this case (useful for renaming the backing file)\n" " '-h' with or without a command shows this help and lists the supported formats\n" " '-p' show progress of command (only certain commands)\n" + " '-pp' show progress of command in sectors (only convert command)\n" " '-q' use Quiet mode - do not print any output (except errors)\n" " '-S' indicates the consecutive number of bytes (defaults to 4k) that must\n" " contain only zeros for qemu-img to create a sparse image during\n" @@ -1124,6 +1125,14 @@ out3: return ret; } +static void print_sector_progress(int progress, int64_t sector_num, + int64_t total_sectors) +{ + if (progress == 2) { + printf("%ld of %ld sectors converted.\r", sector_num, total_sectors); + } +} + static int img_convert(int argc, char **argv) { int c, n, n1, bs_n, bs_i, compress, cluster_sectors, skip_create; @@ -1132,7 +1141,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, + int64_t total_sectors = 0, nb_sectors, sector_num, bs_offset, sector_num_next_status = 0; uint64_t bs_sectors; uint8_t * buf = NULL; @@ -1219,7 +1228,7 @@ static int img_convert(int argc, char **argv) break; } case 'p': - progress = 1; + progress++; break; case 't': cache = optarg; @@ -1245,7 +1254,7 @@ static int img_convert(int argc, char **argv) out_filename = argv[argc - 1]; /* Initialize before goto out */ - qemu_progress_init(progress, 2.0); + qemu_progress_init(progress == 1, 2.0); if (options && is_help_option(options)) { ret = print_block_option_help(out_filename, out_fmt); @@ -1276,6 +1285,8 @@ static int img_convert(int argc, char **argv) total_sectors += bs_sectors; } + print_sector_progress(progress, 0, total_sectors); + if (snapshot_name != NULL) { if (bs_n > 1) { error_report("No support for concatenating multiple snapshot"); @@ -1481,6 +1492,7 @@ static int img_convert(int argc, char **argv) } sector_num += n; qemu_progress_print(100.0 * sector_num / total_sectors, 0); + print_sector_progress(progress, sector_num, total_sectors); } /* signal EOF to align */ bdrv_write_compressed(out_bs, 0, NULL, 0); @@ -1595,11 +1607,16 @@ static int img_convert(int argc, char **argv) buf1 += n1 * 512; } qemu_progress_print(100.0 * sector_num / total_sectors, 0); + print_sector_progress(progress, sector_num, total_sectors); } } out: if (!ret) { qemu_progress_print(100, 0); + print_sector_progress(progress, total_sectors, total_sectors); + } + if (progress == 2) { + printf("\n"); } qemu_progress_end(); free_option_parameters(create_options);