From patchwork Tue Jun 15 14:19:37 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 55695 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D2B3A1007D5 for ; Wed, 16 Jun 2010 01:05:58 +1000 (EST) Received: from localhost ([127.0.0.1]:47508 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OOXi5-0006V1-OY for incoming@patchwork.ozlabs.org; Tue, 15 Jun 2010 11:05:53 -0400 Received: from [140.186.70.92] (port=37896 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OOX02-0008Cx-B1 for qemu-devel@nongnu.org; Tue, 15 Jun 2010 10:20:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OOX00-0000CK-RA for qemu-devel@nongnu.org; Tue, 15 Jun 2010 10:20:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20619) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OOX00-0000C8-De for qemu-devel@nongnu.org; Tue, 15 Jun 2010 10:20:20 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5FEKIL4011673 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 15 Jun 2010 10:20:18 -0400 Received: from localhost.localdomain (dhcp-5-217.str.redhat.com [10.32.5.217]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5FEJq74025060; Tue, 15 Jun 2010 10:20:15 -0400 From: Kevin Wolf To: anthony@codemonkey.ws Date: Tue, 15 Jun 2010 16:19:37 +0200 Message-Id: <1276611581-3757-16-git-send-email-kwolf@redhat.com> In-Reply-To: <1276611581-3757-1-git-send-email-kwolf@redhat.com> References: <1276611581-3757-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 15/19] block: Decouple savevm from DriveInfo X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Markus Armbruster We find snapshots by iterating over the list of drives defined with drive_init(). This misses host block devices defined by other means. Such means don't exist now, but will be introduced later in this series. Iterate over all host block devices instead, with bdrv_next(). Signed-off-by: Markus Armbruster Signed-off-by: Kevin Wolf --- savevm.c | 40 ++++++++++++++++++---------------------- 1 files changed, 18 insertions(+), 22 deletions(-) diff --git a/savevm.c b/savevm.c index ab58d63..20354a8 100644 --- a/savevm.c +++ b/savevm.c @@ -1578,12 +1578,13 @@ out: static BlockDriverState *get_bs_snapshots(void) { BlockDriverState *bs; - DriveInfo *dinfo; if (bs_snapshots) return bs_snapshots; - QTAILQ_FOREACH(dinfo, &drives, next) { - bs = dinfo->bdrv; + /* FIXME what if bs_snapshots gets hot-unplugged? */ + + bs = NULL; + while ((bs = bdrv_next(bs))) { if (bdrv_can_snapshot(bs)) { goto ok; } @@ -1622,12 +1623,11 @@ static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info, static int del_existing_snapshots(Monitor *mon, const char *name) { BlockDriverState *bs; - DriveInfo *dinfo; QEMUSnapshotInfo sn1, *snapshot = &sn1; int ret; - QTAILQ_FOREACH(dinfo, &drives, next) { - bs = dinfo->bdrv; + bs = NULL; + while ((bs = bdrv_next(bs))) { if (bdrv_can_snapshot(bs) && bdrv_snapshot_find(bs, snapshot, name) >= 0) { @@ -1646,7 +1646,6 @@ static int del_existing_snapshots(Monitor *mon, const char *name) void do_savevm(Monitor *mon, const QDict *qdict) { - DriveInfo *dinfo; BlockDriverState *bs, *bs1; QEMUSnapshotInfo sn1, *sn = &sn1, old_sn1, *old_sn = &old_sn1; int ret; @@ -1661,8 +1660,8 @@ void do_savevm(Monitor *mon, const QDict *qdict) const char *name = qdict_get_try_str(qdict, "name"); /* Verify if there is a device that doesn't support snapshots and is writable */ - QTAILQ_FOREACH(dinfo, &drives, next) { - bs = dinfo->bdrv; + bs = NULL; + while ((bs = bdrv_next(bs))) { if (bdrv_is_removable(bs) || bdrv_is_read_only(bs)) { continue; @@ -1730,8 +1729,8 @@ void do_savevm(Monitor *mon, const QDict *qdict) /* create the snapshots */ - QTAILQ_FOREACH(dinfo, &drives, next) { - bs1 = dinfo->bdrv; + bs1 = NULL; + while ((bs1 = bdrv_next(bs1))) { if (bdrv_can_snapshot(bs1)) { /* Write VM state size only to the image that contains the state */ sn->vm_state_size = (bs == bs1 ? vm_state_size : 0); @@ -1750,15 +1749,14 @@ void do_savevm(Monitor *mon, const QDict *qdict) int load_vmstate(const char *name) { - DriveInfo *dinfo; BlockDriverState *bs, *bs1; QEMUSnapshotInfo sn; QEMUFile *f; int ret; /* Verify if there is a device that doesn't support snapshots and is writable */ - QTAILQ_FOREACH(dinfo, &drives, next) { - bs = dinfo->bdrv; + bs = NULL; + while ((bs = bdrv_next(bs))) { if (bdrv_is_removable(bs) || bdrv_is_read_only(bs)) { continue; @@ -1780,8 +1778,8 @@ int load_vmstate(const char *name) /* Flush all IO requests so they don't interfere with the new state. */ qemu_aio_flush(); - QTAILQ_FOREACH(dinfo, &drives, next) { - bs1 = dinfo->bdrv; + bs1 = NULL; + while ((bs1 = bdrv_next(bs1))) { if (bdrv_can_snapshot(bs1)) { ret = bdrv_snapshot_goto(bs1, name); if (ret < 0) { @@ -1831,7 +1829,6 @@ int load_vmstate(const char *name) void do_delvm(Monitor *mon, const QDict *qdict) { - DriveInfo *dinfo; BlockDriverState *bs, *bs1; int ret; const char *name = qdict_get_str(qdict, "name"); @@ -1842,8 +1839,8 @@ void do_delvm(Monitor *mon, const QDict *qdict) return; } - QTAILQ_FOREACH(dinfo, &drives, next) { - bs1 = dinfo->bdrv; + bs1 = NULL; + while ((bs1 = bdrv_next(bs1))) { if (bdrv_can_snapshot(bs1)) { ret = bdrv_snapshot_delete(bs1, name); if (ret < 0) { @@ -1861,7 +1858,6 @@ void do_delvm(Monitor *mon, const QDict *qdict) void do_info_snapshots(Monitor *mon) { - DriveInfo *dinfo; BlockDriverState *bs, *bs1; QEMUSnapshotInfo *sn_tab, *sn; int nb_sns, i; @@ -1873,8 +1869,8 @@ void do_info_snapshots(Monitor *mon) return; } monitor_printf(mon, "Snapshot devices:"); - QTAILQ_FOREACH(dinfo, &drives, next) { - bs1 = dinfo->bdrv; + bs1 = NULL; + while ((bs1 = bdrv_next(bs1))) { if (bdrv_can_snapshot(bs1)) { if (bs == bs1) monitor_printf(mon, " %s", bdrv_get_device_name(bs1));