From patchwork Sat May 25 03:09:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 246307 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B9A172C0087 for ; Sat, 25 May 2013 13:12:47 +1000 (EST) Received: from localhost ([::1]:40214 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ug4uT-0000Dd-SI for incoming@patchwork.ozlabs.org; Fri, 24 May 2013 23:12:45 -0400 Received: from eggs.gnu.org ([208.118.235.92]:57625) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ug4u0-0008Uy-L6 for qemu-devel@nongnu.org; Fri, 24 May 2013 23:12:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ug4tv-0004h5-PO for qemu-devel@nongnu.org; Fri, 24 May 2013 23:12:16 -0400 Received: from e23smtp03.au.ibm.com ([202.81.31.145]:50874) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ug4tv-0004gx-7x for qemu-devel@nongnu.org; Fri, 24 May 2013 23:12:11 -0400 Received: from /spool/local by e23smtp03.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sat, 25 May 2013 13:03:35 +1000 Received: from d23dlp03.au.ibm.com (202.81.31.214) by e23smtp03.au.ibm.com (202.81.31.209) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sat, 25 May 2013 13:03:33 +1000 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [9.190.235.152]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id DD773357804E for ; Sat, 25 May 2013 13:12:06 +1000 (EST) Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r4P2vkE319071100 for ; Sat, 25 May 2013 12:57:46 +1000 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r4P3C6M3010251 for ; Sat, 25 May 2013 13:12:06 +1000 Received: from RH63Wenchao.localdomain ([9.77.178.167]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r4P39SQQ008212; Sat, 25 May 2013 13:12:02 +1000 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Sat, 25 May 2013 11:09:42 +0800 Message-Id: <1369451385-23452-2-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1369451385-23452-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1369451385-23452-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13052503-6102-0000-0000-00000394F92A X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.145 Cc: kwolf@redhat.com, phrdina@redhat.com, stefanha@gmail.com, armbru@redhat.com, lcapitulino@redhat.com, Stefan Hajnoczi , pbonzini@redhat.com, Wenchao Xia Subject: [Qemu-devel] [PATCH V3 1/4] block: drop bs_snapshots global variable X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stefan Hajnoczi The bs_snapshots global variable points to the BlockDriverState which will be used to save vmstate. This is really a savevm.c concept but was moved into block.c:bdrv_snapshots() when it became clear that hotplug could result in a dangling pointer. While auditing the block layer's global state I came upon bs_snapshots and realized that a variable is not necessary here. Simply find the first BlockDriverState capable of internal snapshots each time this is needed. The behavior of bdrv_snapshots() is preserved across hotplug because new drives are always appended to the bdrv_states list. This means that calling the new find_vmstate_bs() function is idempotent - it returns the same BlockDriverState unless it was hot-unplugged. Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake Reviewed-by: Wenchao Xia Signed-off-by: Wenchao Xia --- block.c | 28 ---------------------------- include/block/block.h | 1 - savevm.c | 19 +++++++++++++++---- 3 files changed, 15 insertions(+), 33 deletions(-) diff --git a/block.c b/block.c index 3f87489..478a3b2 100644 --- a/block.c +++ b/block.c @@ -99,9 +99,6 @@ static QTAILQ_HEAD(, BlockDriverState) bdrv_states = static QLIST_HEAD(, BlockDriver) bdrv_drivers = QLIST_HEAD_INITIALIZER(bdrv_drivers); -/* The device to use for VM snapshots */ -static BlockDriverState *bs_snapshots; - /* If non-zero, use only whitelisted block drivers */ static int use_bdrv_whitelist; @@ -1357,9 +1354,6 @@ void bdrv_close(BlockDriverState *bs) notifier_list_notify(&bs->close_notifiers, bs); if (bs->drv) { - if (bs == bs_snapshots) { - bs_snapshots = NULL; - } if (bs->backing_hd) { bdrv_delete(bs->backing_hd); bs->backing_hd = NULL; @@ -1591,7 +1585,6 @@ void bdrv_delete(BlockDriverState *bs) bdrv_close(bs); - assert(bs != bs_snapshots); g_free(bs); } @@ -1635,9 +1628,6 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops, { bs->dev_ops = ops; bs->dev_opaque = opaque; - if (bdrv_dev_has_removable_media(bs) && bs == bs_snapshots) { - bs_snapshots = NULL; - } } void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv, @@ -3381,24 +3371,6 @@ int bdrv_is_snapshot(BlockDriverState *bs) return !!(bs->open_flags & BDRV_O_SNAPSHOT); } -BlockDriverState *bdrv_snapshots(void) -{ - BlockDriverState *bs; - - if (bs_snapshots) { - return bs_snapshots; - } - - bs = NULL; - while ((bs = bdrv_next(bs))) { - if (bdrv_can_snapshot(bs)) { - bs_snapshots = bs; - return bs; - } - } - return NULL; -} - int bdrv_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) { diff --git a/include/block/block.h b/include/block/block.h index 1251c5c..38263b9 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -332,7 +332,6 @@ BlockInfo *bdrv_query_info(BlockDriverState *s); BlockStats *bdrv_query_stats(const BlockDriverState *bs); int bdrv_can_snapshot(BlockDriverState *bs); int bdrv_is_snapshot(BlockDriverState *bs); -BlockDriverState *bdrv_snapshots(void); int bdrv_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info); int bdrv_snapshot_goto(BlockDriverState *bs, diff --git a/savevm.c b/savevm.c index 31dcce9..baa1a09 100644 --- a/savevm.c +++ b/savevm.c @@ -2262,6 +2262,17 @@ out: return ret; } +static BlockDriverState *find_vmstate_bs(void) +{ + BlockDriverState *bs = NULL; + while ((bs = bdrv_next(bs))) { + if (bdrv_can_snapshot(bs)) { + return bs; + } + } + return NULL; +} + static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info, const char *name) { @@ -2338,7 +2349,7 @@ void do_savevm(Monitor *mon, const QDict *qdict) } } - bs = bdrv_snapshots(); + bs = find_vmstate_bs(); if (!bs) { monitor_printf(mon, "No block device can accept snapshots\n"); return; @@ -2440,7 +2451,7 @@ int load_vmstate(const char *name) QEMUFile *f; int ret; - bs_vm_state = bdrv_snapshots(); + bs_vm_state = find_vmstate_bs(); if (!bs_vm_state) { error_report("No block device supports snapshots"); return -ENOTSUP; @@ -2519,7 +2530,7 @@ void do_delvm(Monitor *mon, const QDict *qdict) int ret; const char *name = qdict_get_str(qdict, "name"); - bs = bdrv_snapshots(); + bs = find_vmstate_bs(); if (!bs) { monitor_printf(mon, "No block device supports snapshots\n"); return; @@ -2551,7 +2562,7 @@ void do_info_snapshots(Monitor *mon, const QDict *qdict) int *available_snapshots; char buf[256]; - bs = bdrv_snapshots(); + bs = find_vmstate_bs(); if (!bs) { monitor_printf(mon, "No available block device supports snapshots\n"); return;