diff options
author | Max Reitz <mreitz@redhat.com> | 2014-10-27 11:12:51 +0100 |
---|---|---|
committer | Stefan Hajnoczi <stefanha@redhat.com> | 2014-11-03 11:41:48 +0000 |
commit | 76a3a34dcefbaac3103148e9c3437749b0732cfe (patch) | |
tree | 63381040b369af326b9f44260031463900c43ae0 /qemu-img.c | |
parent | 77485434206bbbfbb7f6a446866f6a327b062d5e (diff) | |
download | qemu-76a3a34dcefbaac3103148e9c3437749b0732cfe.zip qemu-76a3a34dcefbaac3103148e9c3437749b0732cfe.tar.gz qemu-76a3a34dcefbaac3103148e9c3437749b0732cfe.tar.bz2 |
qemu-img: Add progress output for amend
Now that bdrv_amend_options() supports a status callback, use it to
display a progress report.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: BenoƮt Canet <benoit.canet@nodalink.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-id: 1414404776-4919-3-git-send-email-mreitz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'qemu-img.c')
-rw-r--r-- | qemu-img.c | 25 |
1 files changed, 22 insertions, 3 deletions
@@ -2871,6 +2871,12 @@ out: return 0; } +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 = 0; @@ -2879,13 +2885,13 @@ 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; BlockBackend *blk = NULL; 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; } @@ -2915,6 +2921,9 @@ static int img_amend(int argc, char **argv) case 't': cache = optarg; break; + case 'p': + progress = true; + break; case 'q': quiet = true; break; @@ -2925,6 +2934,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 @@ -2968,13 +2982,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(); + blk_unref(blk); qemu_opts_del(opts); qemu_opts_free(create_opts); |