From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=60480 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PhTfM-0000rm-Mk for qemu-devel@nongnu.org; Mon, 24 Jan 2011 16:09:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PhTfJ-0007LB-Mg for qemu-devel@nongnu.org; Mon, 24 Jan 2011 16:09:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45791) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PhTfJ-0007L5-Fj for qemu-devel@nongnu.org; Mon, 24 Jan 2011 16:09:33 -0500 From: Kevin Wolf Date: Mon, 24 Jan 2011 22:10:34 +0100 Message-Id: <1295903452-18017-6-git-send-email-kwolf@redhat.com> In-Reply-To: <1295903452-18017-1-git-send-email-kwolf@redhat.com> References: <1295903452-18017-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 05/23] Avoid divide by zero when there is no block device to migrate List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Pierre Riteau 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 Signed-off-by: Kevin Wolf --- block-migration.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/block-migration.c b/block-migration.c index 1475325..60b9fc0 100644 --- a/block-migration.c +++ b/block-migration.c @@ -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) -- 1.7.2.3