The Saturday 26 Jul 2014 à 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 <mre...@redhat.com> > --- > 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; > } > > +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 ?
> + qemu_progress_print(100.f * offset / total_work_size, 0); > +} > + > static int img_amend(int argc, char **argv) > { > int c, ret = 0; > @@ -2740,12 +2747,12 @@ static int img_amend(int argc, char **argv) > QemuOpts *opts = NULL; > const char *fmt = NULL, *filename, *cache; > int flags; > - bool quiet = false; > + bool quiet = false, progress = false; > BlockDriverState *bs = NULL; > > cache = BDRV_DEFAULT_CACHE; > for (;;) { > - c = getopt(argc, argv, "ho:f:t:q"); > + c = getopt(argc, argv, "ho:f:t:pq"); > if (c == -1) { > break; > } > @@ -2775,6 +2782,9 @@ static int img_amend(int argc, char **argv) > case 't': > cache = optarg; > break; > + case 'p': > + progress = true; > + break; > case 'q': > quiet = true; > break; > @@ -2785,6 +2795,11 @@ static int img_amend(int argc, char **argv) > error_exit("Must specify options (-o)"); > } > > + if (quiet) { > + progress = false; > + } > + qemu_progress_init(progress, 1.0); > + > filename = (optind == argc - 1) ? argv[argc - 1] : NULL; > if (fmt && has_help_option(options)) { > /* If a format is explicitly specified (and possibly no filename is > @@ -2827,13 +2842,18 @@ static int img_amend(int argc, char **argv) > goto out; > } > > - ret = bdrv_amend_options(bs, opts, NULL); > + /* In case the driver does not call amend_status_cb() */ > + qemu_progress_print(0.f, 0); > + ret = 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; > } > > out: > + qemu_progress_end(); > + > if (bs) { > bdrv_unref(bs); > } > -- > 2.0.3 > >