From patchwork Mon Jun 25 02:47:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yaoxu@didichuxing.com X-Patchwork-Id: 10484985 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 C1A10601D5 for ; Mon, 25 Jun 2018 03:00:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BFC37286EC for ; Mon, 25 Jun 2018 03:00:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B46F22870C; Mon, 25 Jun 2018 03:00:51 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, 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 6A38A286EC for ; Mon, 25 Jun 2018 03:00:51 +0000 (UTC) Received: from localhost ([::1]:43947 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXHkI-00027J-Kg for patchwork-qemu-devel@patchwork.kernel.org; Sun, 24 Jun 2018 23:00:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59369) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXHhS-0008WS-M2 for qemu-devel@nongnu.org; Sun, 24 Jun 2018 22:57:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fXHhR-0007FM-V1 for qemu-devel@nongnu.org; Sun, 24 Jun 2018 22:57:54 -0400 Received: from [210.13.242.136] (port=3943 helo=localhost.localdomain) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXHhM-0007C3-Ip; Sun, 24 Jun 2018 22:57:48 -0400 Received: by localhost.localdomain (Postfix, from userid 0) id 9069810461C0; Mon, 25 Jun 2018 10:47:22 +0800 (CST) From: yaoxu@didichuxing.com To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Mon, 25 Jun 2018 10:47:21 +0800 Message-Id: <20180625024721.5082-1-yaoxu@didichuxing.com> X-Mailer: git-send-email 2.11.0 (Apple Git-81) X-detected-operating-system: by eggs.gnu.org: Mac OS X [generic] [fuzzy] X-Received-From: 210.13.242.136 Subject: [Qemu-devel] block/dirty-bitmap: Useless bitmaps in image can be removed 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, Yaoxu19870920 <13466399134@163.com>, armbru@redhat.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 If qemu-kvm quit without saving bitmaps to image(coredump, host kernel panic, or host pooweroff), bitmaps in image can not be safely used anymore, and also can not be removed. Useless bitmaps should be removed. Signed-off-by: Yaoxu19870920 <13466399134@163.com> diff --git a/blockdev.c b/blockdev.c index 58d7570932..c85056a74b 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2837,31 +2837,35 @@ void qmp_block_dirty_bitmap_remove(const char *node, const char *name, Error *local_err = NULL; bitmap = block_dirty_bitmap_lookup(node, name, &bs, errp); - if (!bitmap || !bs) { + if (!bs) { return; } - if (bdrv_dirty_bitmap_frozen(bitmap)) { - error_setg(errp, - "Bitmap '%s' is currently frozen and cannot be removed", - name); - return; - } else if (bdrv_dirty_bitmap_qmp_locked(bitmap)) { - error_setg(errp, - "Bitmap '%s' is currently locked and cannot be removed", - name); + if (bitmap) { + if (bdrv_dirty_bitmap_frozen(bitmap)) { + error_setg(errp, + "Bitmap '%s' is currently frozen and cannot be removed", + name); + return; + } else if (bdrv_dirty_bitmap_qmp_locked(bitmap)) { + error_setg(errp, + "Bitmap '%s' is currently locked and cannot be removed", + name); + return; + } + } + + bdrv_remove_persistent_dirty_bitmap(bs, name, &local_err); + if (local_err != NULL) { + error_propagate(errp, local_err); return; } - if (bdrv_dirty_bitmap_get_persistance(bitmap)) { - bdrv_remove_persistent_dirty_bitmap(bs, name, &local_err); - if (local_err != NULL) { - error_propagate(errp, local_err); - return; - } + if (bitmap) { + bdrv_release_dirty_bitmap(bs, bitmap); } - bdrv_release_dirty_bitmap(bs, bitmap); + if (*errp) { + error_free(*errp); + *errp = NULL; + } } /**