From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37992) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XlGBd-00061p-ST for qemu-devel@nongnu.org; Mon, 03 Nov 2014 06:52:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XlGBY-0000ln-QC for qemu-devel@nongnu.org; Mon, 03 Nov 2014 06:52:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37069) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XlGBY-0000lf-0x for qemu-devel@nongnu.org; Mon, 03 Nov 2014 06:52:36 -0500 From: Stefan Hajnoczi Date: Mon, 3 Nov 2014 11:50:40 +0000 Message-Id: <1415015456-25086-38-git-send-email-stefanha@redhat.com> In-Reply-To: <1415015456-25086-1-git-send-email-stefanha@redhat.com> References: <1415015456-25086-1-git-send-email-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 37/53] qemu-img: Add progress output for amend List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Stefan Hajnoczi , Max Reitz From: Max Reitz Now that bdrv_amend_options() supports a status callback, use it to display a progress report. Signed-off-by: Max Reitz Reviewed-by: Eric Blake Reviewed-by: Beno=C3=AEt Canet Reviewed-by: Kevin Wolf Message-id: 1414404776-4919-3-git-send-email-mreitz@redhat.com Signed-off-by: Stefan Hajnoczi --- qemu-img-cmds.hx | 4 ++-- qemu-img.c | 25 ++++++++++++++++++++++--- qemu-img.texi | 2 +- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index 04c207d..9567774 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -70,8 +70,8 @@ STEXI ETEXI =20 DEF("amend", img_amend, - "amend [-q] [-f fmt] [-t cache] -o options filename") + "amend [-p] [-q] [-f fmt] [-t cache] -o options filename") STEXI -@item amend [-q] [-f @var{fmt}] [-t @var{cache}] -o @var{options} @var{f= ilename} +@item amend [-p] [-q] [-f @var{fmt}] [-t @var{cache}] -o @var{options} @= var{filename} @end table ETEXI diff --git a/qemu-img.c b/qemu-img.c index a095d42..c7b394a 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2871,6 +2871,12 @@ out: return 0; } =20 +static void amend_status_cb(BlockDriverState *bs, + int64_t offset, int64_t total_work_size) +{ + qemu_progress_print(100.f * offset / total_work_size, 0); +} + static int img_amend(int argc, char **argv) { int c, ret =3D 0; @@ -2879,13 +2885,13 @@ 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; BlockBackend *blk =3D NULL; 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; } @@ -2915,6 +2921,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; @@ -2925,6 +2934,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 filename= is @@ -2968,13 +2982,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(-ret))= ; goto out; } =20 out: + qemu_progress_end(); + blk_unref(blk); qemu_opts_del(opts); qemu_opts_free(create_opts); diff --git a/qemu-img.texi b/qemu-img.texi index 078851a..0a1ab35 100644 --- a/qemu-img.texi +++ b/qemu-img.texi @@ -412,7 +412,7 @@ After using this command to grow a disk image, you mu= st use file system and partitioning tools inside the VM to actually begin using the new space o= n the device. =20 -@item amend [-f @var{fmt}] [-t @var{cache}] -o @var{options} @var{filena= me} +@item amend [-p] [-f @var{fmt}] [-t @var{cache}] -o @var{options} @var{f= ilename} =20 Amends the image format specific @var{options} for the image file @var{filename}. Not all file formats support this operation. --=20 1.9.3