Avoid divide by zero when there is no block device to migrate
authorPierre Riteau <Pierre.Riteau@irisa.fr>
Wed, 12 Jan 2011 13:41:00 +0000 (14:41 +0100)
committerKevin Wolf <kwolf@redhat.com>
Mon, 24 Jan 2011 10:08:50 +0000 (11:08 +0100)
When block migration is requested and no read-write block device is
present, a divide by zero exception is triggered because
total_sector_sum equals zero.

Signed-off-by: Pierre Riteau <Pierre.Riteau@irisa.fr>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block-migration.c

index 14753254d6bcdd9e57c10d65d739ab944a9ff94b..60b9fc0ef0cc9471ae6b882838cefcc112b3f6b0 100644 (file)
@@ -350,7 +350,12 @@ static int blk_mig_save_bulked_block(Monitor *mon, QEMUFile *f)
         }
     }
 
-    progress = completed_sector_sum * 100 / block_mig_state.total_sector_sum;
+    if (block_mig_state.total_sector_sum != 0) {
+        progress = completed_sector_sum * 100 /
+                   block_mig_state.total_sector_sum;
+    } else {
+        progress = 100;
+    }
     if (progress != block_mig_state.prev_progress) {
         block_mig_state.prev_progress = progress;
         qemu_put_be64(f, (progress << BDRV_SECTOR_BITS)