From patchwork Fri Sep 21 22:28:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 10611101 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 19EE5161F for ; Fri, 21 Sep 2018 22:33:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 08D102D796 for ; Fri, 21 Sep 2018 22:33:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EF7E52D79F; Fri, 21 Sep 2018 22:33:21 +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 719062D796 for ; Fri, 21 Sep 2018 22:33:21 +0000 (UTC) Received: from localhost ([::1]:57640 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3TzE-0002uS-M2 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 21 Sep 2018 18:33:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39205) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3TvF-0008Jz-80 for qemu-devel@nongnu.org; Fri, 21 Sep 2018 18:29:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g3TvE-0005OM-79 for qemu-devel@nongnu.org; Fri, 21 Sep 2018 18:29:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51460) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g3TvB-0005HZ-Bv; Fri, 21 Sep 2018 18:29:09 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B487132B660; Fri, 21 Sep 2018 22:29:08 +0000 (UTC) Received: from probe.redhat.com (ovpn-121-77.rdu2.redhat.com [10.10.121.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA40110A3948; Fri, 21 Sep 2018 22:29:05 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Fri, 21 Sep 2018 18:28:45 -0400 Message-Id: <20180921222847.1012-5-jsnow@redhat.com> In-Reply-To: <20180921222847.1012-1-jsnow@redhat.com> References: <20180921222847.1012-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 21 Sep 2018 22:29:08 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC PATCH v2 4/6] bitmaps: add user_modifiable status checker 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: Kevin Wolf , vsementsov@virtuozzo.com, Fam Zheng , Markus Armbruster , Max Reitz , John Snow Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Instead of both frozen and qmp_locked checks, wrap it into one check. frozen implies the bitmap is split in two (for backup), and shouldn't be modified. qmp_locked implies it's being used by another operation, like being exported over NBD. In both cases it means we shouldn't allow the user to modify it in any meaningful way. Replace any usages where we check both frozen and qmp_locked with the new check. Signed-off-by: John Snow --- block/dirty-bitmap.c | 9 +++++++-- blockdev.c | 34 +++++++++------------------------- include/block/dirty-bitmap.h | 1 + 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 216baec388..36c95820af 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -176,6 +176,12 @@ bool bdrv_dirty_bitmap_frozen(BdrvDirtyBitmap *bitmap) return bitmap->successor; } +/* Both conditions disallow user-modification via QMP. */ +bool bdrv_dirty_bitmap_user_modifiable(BdrvDirtyBitmap *bitmap) { + return !(bdrv_dirty_bitmap_frozen(bitmap) || + bdrv_dirty_bitmap_qmp_locked(bitmap)); +} + void bdrv_dirty_bitmap_set_qmp_locked(BdrvDirtyBitmap *bitmap, bool qmp_locked) { qemu_mutex_lock(bitmap->mutex); @@ -797,8 +803,7 @@ void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap *src, qemu_mutex_lock(dest->mutex); - assert(!bdrv_dirty_bitmap_frozen(dest)); - assert(!bdrv_dirty_bitmap_qmp_locked(dest)); + assert(bdrv_dirty_bitmap_user_modifiable(dest)); assert(!bdrv_dirty_bitmap_readonly(dest)); if (!hbitmap_merge(dest->bitmap, src->bitmap)) { diff --git a/blockdev.c b/blockdev.c index b21e635c68..070180898f 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2009,11 +2009,8 @@ static void block_dirty_bitmap_clear_prepare(BlkActionState *common, return; } - if (bdrv_dirty_bitmap_frozen(state->bitmap)) { - error_setg(errp, "Cannot modify a frozen bitmap"); - return; - } else if (bdrv_dirty_bitmap_qmp_locked(state->bitmap)) { - error_setg(errp, "Cannot modify a locked bitmap"); + if (!bdrv_dirty_bitmap_user_modifiable(state->bitmap)) { + error_setg(errp, "Cannot modify a bitmap in-use by another operation"); return; } else if (bdrv_dirty_bitmap_readonly(state->bitmap)) { error_setg(errp, "Cannot clear a readonly bitmap"); @@ -2838,14 +2835,9 @@ void qmp_block_dirty_bitmap_remove(const char *node, const char *name, return; } - if (bdrv_dirty_bitmap_frozen(bitmap)) { + if (!bdrv_dirty_bitmap_user_modifiable(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", + "Bitmap '%s' is currently in-use by another operation and cannot be removed", name); return; } @@ -2876,14 +2868,9 @@ void qmp_block_dirty_bitmap_clear(const char *node, const char *name, return; } - if (bdrv_dirty_bitmap_frozen(bitmap)) { + if (!bdrv_dirty_bitmap_user_modifiable(bitmap)) { error_setg(errp, - "Bitmap '%s' is currently frozen and cannot be modified", - name); - return; - } else if (bdrv_dirty_bitmap_qmp_locked(bitmap)) { - error_setg(errp, - "Bitmap '%s' is currently locked and cannot be modified", + "Bitmap '%s' is currently in-use by another operation and cannot be cleared", name); return; } else if (bdrv_dirty_bitmap_readonly(bitmap)) { @@ -2947,18 +2934,15 @@ void qmp_x_block_dirty_bitmap_merge(const char *node, const char *dst_name, return; } - if (bdrv_dirty_bitmap_frozen(dst)) { - error_setg(errp, "Bitmap '%s' is frozen and cannot be modified", + if (!bdrv_dirty_bitmap_user_modifiable(dst)) { + error_setg(errp, + "Bitmap '%s' is currently in-use by another operation and cannot be modified", dst_name); return; } else if (bdrv_dirty_bitmap_readonly(dst)) { error_setg(errp, "Bitmap '%s' is readonly and cannot be modified", dst_name); return; - } else if (bdrv_dirty_bitmap_qmp_locked(dst)) { - error_setg(errp, "Bitmap '%s' is in-use by an operation " - "and cannot be modified", dst_name); - return; } src = bdrv_find_dirty_bitmap(bs, src_name); diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index 259bd27c40..e3e1c6126f 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -94,6 +94,7 @@ bool bdrv_has_readonly_bitmaps(BlockDriverState *bs); bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap); bool bdrv_dirty_bitmap_get_persistance(BdrvDirtyBitmap *bitmap); bool bdrv_dirty_bitmap_qmp_locked(BdrvDirtyBitmap *bitmap); +bool bdrv_dirty_bitmap_user_modifiable(BdrvDirtyBitmap *bitmap); bool bdrv_has_changed_persistent_bitmaps(BlockDriverState *bs); BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverState *bs, BdrvDirtyBitmap *bitmap);