qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: Anthony Liguori <aliguori@us.ibm.com>
Cc: qemu-devel@nongnu.org, Liran Schour <lirans@il.ibm.com>,
	Pierre Riteau <pierre.riteau@irisa.fr>
Subject: [Qemu-devel] [PATCH v2 22/23] block migration: Add support for restore progress reporting
Date: Tue, 01 Dec 2009 15:20:17 +0100	[thread overview]
Message-ID: <4B152621.9020108@siemens.com> (raw)
In-Reply-To: <20091130172121.22889.68041.stgit@mchn012c.ww002.siemens.net>

Inject progress report in percentage into the block live stream. This
can be read out and displayed easily on restore.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---

Changes in v2:
 - Print banner only if there is really some block device to restore

 block-migration.c |   30 ++++++++++++++++++++++--------
 1 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/block-migration.c b/block-migration.c
index 7510923..a066f19 100644
--- a/block-migration.c
+++ b/block-migration.c
@@ -23,6 +23,7 @@
 
 #define BLK_MIG_FLAG_DEVICE_BLOCK       0x01
 #define BLK_MIG_FLAG_EOS                0x02
+#define BLK_MIG_FLAG_PROGRESS           0x04
 
 #define MAX_IS_ALLOCATED_SEARCH 65536
 #define MAX_BLOCKS_READ 10000
@@ -70,7 +71,7 @@ typedef struct BlkMigState {
     int read_done;
     int transferred;
     int64_t total_sector_sum;
-    int64_t print_completion;
+    int prev_progress;
 } BlkMigState;
 
 static BlkMigState block_mig_state;
@@ -226,7 +227,7 @@ static void init_blk_migration(Monitor *mon, QEMUFile *f)
     block_mig_state.read_done = 0;
     block_mig_state.transferred = 0;
     block_mig_state.total_sector_sum = 0;
-    block_mig_state.print_completion = 0;
+    block_mig_state.prev_progress = -1;
 
     for (bs = bdrv_first; bs != NULL; bs = bs->next) {
         if (bs->type == BDRV_TYPE_HD) {
@@ -257,6 +258,7 @@ static int blk_mig_save_bulked_block(Monitor *mon, QEMUFile *f, int is_async)
 {
     int64_t completed_sector_sum = 0;
     BlkMigDevState *bmds;
+    int progress;
     int ret = 0;
 
     QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) {
@@ -273,13 +275,13 @@ static int blk_mig_save_bulked_block(Monitor *mon, QEMUFile *f, int is_async)
         }
     }
 
-    if (completed_sector_sum >= block_mig_state.print_completion) {
-        monitor_printf(mon, "Completed %" PRId64 " %%\r",
-                       completed_sector_sum * 100 /
-                       block_mig_state.total_sector_sum);
+    progress = completed_sector_sum * 100 / block_mig_state.total_sector_sum;
+    if (progress != block_mig_state.prev_progress) {
+        block_mig_state.prev_progress = progress;
+        qemu_put_be64(f, (progress << BDRV_SECTOR_BITS)
+                         | BLK_MIG_FLAG_PROGRESS);
+        monitor_printf(mon, "Completed %d %%\r", progress);
         monitor_flush(mon);
-        block_mig_state.print_completion +=
-            (BDRV_SECTORS_PER_DIRTY_CHUNK * 10000);
     }
 
     return ret;
@@ -445,6 +447,9 @@ static int block_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)
         blk_mig_save_dirty_blocks(mon, f);
         blk_mig_cleanup(mon);
 
+        /* report completion */
+        qemu_put_be64(f, (100 << BDRV_SECTOR_BITS) | BLK_MIG_FLAG_PROGRESS);
+
         if (qemu_file_has_error(f)) {
             return 0;
         }
@@ -459,6 +464,7 @@ static int block_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)
 
 static int block_load(QEMUFile *f, void *opaque, int version_id)
 {
+    static int banner_printed;
     int len, flags;
     char device_name[256];
     int64_t addr;
@@ -490,6 +496,14 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
             bdrv_write(bs, addr, buf, BDRV_SECTORS_PER_DIRTY_CHUNK);
 
             qemu_free(buf);
+        } else if (flags & BLK_MIG_FLAG_PROGRESS) {
+            if (!banner_printed) {
+                printf("Receiving block device images\n");
+                banner_printed = 1;
+            }
+            printf("Completed %d %%%c", (int)addr,
+                   (addr == 100) ? '\n' : '\r');
+            fflush(stdout);
         } else if (!(flags & BLK_MIG_FLAG_EOS)) {
             fprintf(stderr, "Unknown flags\n");
             return -EINVAL;

  reply	other threads:[~2009-12-01 14:20 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-30 17:21 [Qemu-devel] [PATCH 00/23] block migration: Fixes, cleanups and speedups Jan Kiszka
2009-11-30 17:21 ` [Qemu-devel] [PATCH 01/23] migration: Fix use of file after release Jan Kiszka
2009-11-30 17:21 ` [Qemu-devel] [PATCH 04/23] block migration: Rework constants API Jan Kiszka
2009-11-30 17:21 ` [Qemu-devel] [PATCH 03/23] block migration: Fix coding style and whitespaces Jan Kiszka
2009-11-30 17:21 ` [Qemu-devel] [PATCH 02/23] migration: Catch multiple start commands Jan Kiszka
2009-11-30 17:21 ` [Qemu-devel] [PATCH 13/23] block migration: Consolidate mig_read_device_bulk into mig_save_device_bulk Jan Kiszka
2009-11-30 17:21 ` [Qemu-devel] [PATCH 06/23] block migration: Avoid large stack buffer Jan Kiszka
2009-11-30 17:21 ` [Qemu-devel] [PATCH 10/23] block migration: Switch device and block lists to QSIMPLEQ Jan Kiszka
2009-11-30 17:21 ` [Qemu-devel] [PATCH 07/23] block migration: Avoid indirection of block_mig_state Jan Kiszka
2009-11-30 17:21 ` [Qemu-devel] [PATCH 12/23] block migration: Clean up use of total_sectors Jan Kiszka
2009-11-30 17:21 ` [Qemu-devel] [PATCH 05/23] block migration: Cleanup dirty tracking code Jan Kiszka
2009-11-30 17:21 ` [Qemu-devel] [PATCH 11/23] block migration: Initialize remaining BlkMigState fields Jan Kiszka
2009-11-30 17:21 ` [Qemu-devel] [PATCH 09/23] Import a simple queue implementation from NetBSD Jan Kiszka
2009-11-30 17:21 ` [Qemu-devel] [PATCH 08/23] block migration: Drop dead code Jan Kiszka
2009-11-30 17:21 ` [Qemu-devel] [PATCH 20/23] block migration: Fix outgoing progress output Jan Kiszka
2009-11-30 17:21 ` [Qemu-devel] [PATCH 18/23] block migration: Report overall migration progress Jan Kiszka
2009-11-30 17:21 ` [Qemu-devel] [PATCH 21/23] block migration: Report progress also via info migration Jan Kiszka
2009-11-30 17:21 ` [Qemu-devel] [PATCH 14/23] block migration: Consolidate block transmission Jan Kiszka
2009-11-30 17:21 ` [Qemu-devel] [PATCH 16/23] ram migration: Stop loading on error Jan Kiszka
2009-11-30 17:21 ` [Qemu-devel] [PATCH 15/23] block migration: Add error handling/propagation Jan Kiszka
2009-11-30 17:21 ` [Qemu-devel] [PATCH 19/23] live migration: Propagate output monitor to callback handler Jan Kiszka
2009-11-30 17:21 ` [Qemu-devel] [PATCH 17/23] live migration: Allow cleanup after cancellation or error Jan Kiszka
2009-11-30 17:21 ` [Qemu-devel] [PATCH 22/23] block migration: Add support for restore progress reporting Jan Kiszka
2009-12-01 14:20   ` Jan Kiszka [this message]
2009-12-01 17:01     ` [Qemu-devel] Re: [PATCH v2 " Pierre Riteau
2009-12-01 17:17       ` Jan Kiszka
2009-11-30 17:21 ` [Qemu-devel] [PATCH 23/23] block migration: Increase dirty chunk size to 1M Jan Kiszka
2009-11-30 18:34 ` [Qemu-devel] [PATCH 00/23] block migration: Fixes, cleanups and speedups Anthony Liguori
2009-11-30 18:50   ` Pierre Riteau
2009-11-30 19:23     ` Pierre Riteau
2009-11-30 19:34       ` [Qemu-devel] [PATCH 24/23] block migration: Skip zero-sized disks Jan Kiszka
2009-11-30 19:25     ` [Qemu-devel] [PATCH 00/23] block migration: Fixes, cleanups and speedups Jan Kiszka
2009-11-30 19:34       ` Pierre Riteau
2009-11-30 19:44         ` Jan Kiszka
2009-11-30 18:50   ` Jan Kiszka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B152621.9020108@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=aliguori@us.ibm.com \
    --cc=lirans@il.ibm.com \
    --cc=pierre.riteau@irisa.fr \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).