From patchwork Tue Jun 14 17:08:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 9176343 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D792260772 for ; Tue, 14 Jun 2016 17:20:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA0CF28047 for ; Tue, 14 Jun 2016 17:20:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BE8012823D; Tue, 14 Jun 2016 17:20:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4E05028047 for ; Tue, 14 Jun 2016 17:20:31 +0000 (UTC) Received: from localhost ([::1]:37110 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCs0s-0000cJ-DA for patchwork-qemu-devel@patchwork.kernel.org; Tue, 14 Jun 2016 13:20:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43762) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCrpC-0006I7-BH for qemu-devel@nongnu.org; Tue, 14 Jun 2016 13:08:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bCrp6-0003V9-BI for qemu-devel@nongnu.org; Tue, 14 Jun 2016 13:08:25 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:40697 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCrp5-0003UZ-Ts for qemu-devel@nongnu.org; Tue, 14 Jun 2016 13:08:20 -0400 Received: from kvm.sw.ru. ([10.28.8.145]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id u5EH8Dt5026445; Tue, 14 Jun 2016 20:08:18 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Tue, 14 Jun 2016 20:08:13 +0300 Message-Id: <1465924093-76875-3-git-send-email-vsementsov@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1465924093-76875-1-git-send-email-vsementsov@virtuozzo.com> References: <1465924093-76875-1-git-send-email-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 2/2] block: fix libvirt snapshot with existing bitmaps X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, den@openvz.org, vsementsov@virtuozzo.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Fix the following bug: # virsh start test Domain test started # virsh qemu-monitor-command test \ '{"execute":"block-dirty-bitmap-add",\ "arguments":{"node":"drive0","name":"ab"}}' {"return":{},"id":"libvirt-36"}'}' # virsh snapshot-create test error: Unable to read from monitor: Connection reset by peer Actually, assert "assert(pos < hb->size)" in hbitmap_iter_init fires, because qcow2_save_vmstate just writes to bs (not to bs->file->bs) after the end of the drive. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/dirty-bitmap.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 4902ca5..d28b49c 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -364,6 +364,20 @@ void bdrv_set_dirty(BlockDriverState *bs, int64_t cur_sector, int nr_sectors) { BdrvDirtyBitmap *bitmap; + int64_t bitmap_size; + + if (QLIST_EMPTY(&bs->dirty_bitmaps)) { + return; + } + + bitmap_size = QLIST_FIRST(&bs->dirty_bitmaps)->size; + + if (cur_sector >= bitmap_size) { + /* this may come from qcow2_save_vmstate */ + return; + } + assert(cur_sector + nr_sectors <= bitmap_size); + QLIST_FOREACH(bitmap, &bs->dirty_bitmaps, list) { if (!bdrv_dirty_bitmap_enabled(bitmap)) { continue;