From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53722) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XDJ9G-00027L-UX for qemu-devel@nongnu.org; Fri, 01 Aug 2014 16:10:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XDJ9A-0006oK-P8 for qemu-devel@nongnu.org; Fri, 01 Aug 2014 16:09:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:22694) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XDJ9A-0006o6-Hy for qemu-devel@nongnu.org; Fri, 01 Aug 2014 16:09:48 -0400 Message-ID: <53DBF406.1070900@redhat.com> Date: Fri, 01 Aug 2014 22:09:42 +0200 From: Max Reitz MIME-Version: 1.0 References: <1406402531-9278-1-git-send-email-mreitz@redhat.com> <1406402531-9278-3-git-send-email-mreitz@redhat.com> <20140731075634.GF707@irqsave.net> In-Reply-To: <20140731075634.GF707@irqsave.net> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH alt 2/7] qemu-img: Add progress output for amend List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?windows-1252?Q?Beno=EEt_Canet?= Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi On 31.07.2014 09:56, Beno=EEt Canet wrote: > The Saturday 26 Jul 2014 =E0 21:22:06 (+0200), Max Reitz wrote : >> Now that bdrv_amend_options() supports a status callback, use it to >> display a progress report. >> >> Signed-off-by: Max Reitz >> --- >> qemu-img.c | 26 +++++++++++++++++++++++--- >> 1 file changed, 23 insertions(+), 3 deletions(-) >> >> diff --git a/qemu-img.c b/qemu-img.c >> index 90d6b79..a06f425 100644 >> --- a/qemu-img.c >> +++ b/qemu-img.c >> @@ -2732,6 +2732,13 @@ out: >> return 0; >> } >> =20 >> +static void amend_status_cb(BlockDriverState *bs, >> + int64_t offset, int64_t total_work_size) >> +{ >> + (void)bs; > This cast also look like a compiler pleasing thing. > Is it really required ? You're right, I thought -Wunused-parameter was enabled. Actually, this=20 cast is unneeded; I'll drop it in v2. Max >> + qemu_progress_print(100.f * offset / total_work_size, 0); >> +} >> + >> static int img_amend(int argc, char **argv) >> { >> int c, ret =3D 0; >> @@ -2740,12 +2747,12 @@ static int img_amend(int argc, char **argv) >> QemuOpts *opts =3D NULL; >> const char *fmt =3D NULL, *filename, *cache; >> int flags; >> - bool quiet =3D false; >> + bool quiet =3D false, progress =3D false; >> BlockDriverState *bs =3D NULL; >> =20 >> cache =3D BDRV_DEFAULT_CACHE; >> for (;;) { >> - c =3D getopt(argc, argv, "ho:f:t:q"); >> + c =3D getopt(argc, argv, "ho:f:t:pq"); >> if (c =3D=3D -1) { >> break; >> } >> @@ -2775,6 +2782,9 @@ static int img_amend(int argc, char **argv) >> case 't': >> cache =3D optarg; >> break; >> + case 'p': >> + progress =3D true; >> + break; >> case 'q': >> quiet =3D true; >> break; >> @@ -2785,6 +2795,11 @@ static int img_amend(int argc, char **argv) >> error_exit("Must specify options (-o)"); >> } >> =20 >> + if (quiet) { >> + progress =3D false; >> + } >> + qemu_progress_init(progress, 1.0); >> + >> filename =3D (optind =3D=3D argc - 1) ? argv[argc - 1] : NULL; >> if (fmt && has_help_option(options)) { >> /* If a format is explicitly specified (and possibly no file= name is >> @@ -2827,13 +2842,18 @@ static int img_amend(int argc, char **argv) >> goto out; >> } >> =20 >> - ret =3D bdrv_amend_options(bs, opts, NULL); >> + /* In case the driver does not call amend_status_cb() */ >> + qemu_progress_print(0.f, 0); >> + ret =3D bdrv_amend_options(bs, opts, &amend_status_cb); >> + qemu_progress_print(100.f, 0); >> if (ret < 0) { >> error_report("Error while amending options: %s", strerror(-r= et)); >> goto out; >> } >> =20 >> out: >> + qemu_progress_end(); >> + >> if (bs) { >> bdrv_unref(bs); >> } >> --=20 >> 2.0.3 >> >>