From patchwork Fri Jul 23 19:54:33 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Blue Swirl X-Patchwork-Id: 59831 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 54ABEB6F04 for ; Sat, 24 Jul 2010 05:59:14 +1000 (EST) Received: from localhost ([127.0.0.1]:36156 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OcOLy-0004c6-Sq for incoming@patchwork.ozlabs.org; Fri, 23 Jul 2010 15:56:18 -0400 Received: from [140.186.70.92] (port=45966 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OcOKo-000460-0m for qemu-devel@nongnu.org; Fri, 23 Jul 2010 15:55:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OcOKm-0002jQ-Gw for qemu-devel@nongnu.org; Fri, 23 Jul 2010 15:55:05 -0400 Received: from mail-qw0-f45.google.com ([209.85.216.45]:52051) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OcOKm-0002jJ-EM for qemu-devel@nongnu.org; Fri, 23 Jul 2010 15:55:04 -0400 Received: by qwi4 with SMTP id 4so421093qwi.4 for ; Fri, 23 Jul 2010 12:55:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:from:date :message-id:subject:to:content-type; bh=Q3IQj6nGmbcByVsBqJsnsDoVeNn9WHD/EXmWOmVB1FY=; b=jvNxO1TtMDOtT8PIttkdlGLlOT2NCWPlgpyopL/SlR5DvZ5ncNbPZq24ZC0Zp8Hl/M sgRO1P4nodf07mZtObK2TZxujfZM1aPvj2m7azYpcCYXHQw+Lm91WJz8cSuDx5qWFtWR vVv5iaHCDn5wgF8lsqLg4TLlw067Nf79Nk6Q4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; b=N5uQC6LYk5o7vvcynWWWP7w86CE230lbdRXEThwW+1wpmPcVpmzjas9yTGTdkDo9Ni IADYTK0pyySxZgBW9MVSA+8DTOpAW+ixUC7PD7DNt3JjG+pGsREbKdciBW+oTiDXccyY v9enKMOD3oiEmpS5UCOBwE6+4HZwy1WDpEusU= Received: by 10.224.106.149 with SMTP id x21mr3005351qao.16.1279914893555; Fri, 23 Jul 2010 12:54:53 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.185.146 with HTTP; Fri, 23 Jul 2010 12:54:33 -0700 (PDT) From: Blue Swirl Date: Fri, 23 Jul 2010 19:54:33 +0000 Message-ID: To: qemu-devel X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [Qemu-devel] [PATCH] Fix -snapshot deleting CDROM images 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 Command line flag '-snapshot' was setting the drive flag 'snapshot' for all drives. Therefore also CDROM devices were incorrectly marked with BDRV_O_SNAPSHOT. Thus the backing images were accidentally deleted at bdrv_open time, for example when changing the image with monitor 'change' command. Fix by adding a separate 'global_snapshot' drive flag for use when the command line flag '-snapshot' is used. Also add some extra checks and suppress a kraxelian notation. Signed-off-by: Blue Swirl --- blockdev.c | 12 +++++++++++- qemu-config.c | 3 +++ vl.c | 5 +++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/blockdev.c b/blockdev.c index 0a9dec3..1272a0f 100644 --- a/blockdev.c +++ b/blockdev.c @@ -150,7 +150,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error) int on_read_error, on_write_error; const char *devaddr; DriveInfo *dinfo; - int snapshot = 0; + int snapshot = 0, global_snapshot = 0; int ret; *fatal_error = 1; @@ -178,6 +178,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error) secs = qemu_opt_get_number(opts, "secs", 0); snapshot = qemu_opt_get_bool(opts, "snapshot", 0); + global_snapshot = qemu_opt_get_bool(opts, "global_snapshot", 0); ro = qemu_opt_get_bool(opts, "readonly", 0); file = qemu_opt_get(opts, "file"); @@ -268,6 +269,15 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error) } } + if (media == MEDIA_CDROM && snapshot) { + /* Can't support snapshots */ + fprintf(stderr, "qemu: '%s' invalid media for snapshot\n", devname); + return NULL; + } + if (media != MEDIA_CDROM && global_snapshot) { + /* Can't support snapshots: ignore -snapshot for CDROMs */ + snapshot = global_snapshot; + } if ((buf = qemu_opt_get(opts, "cache")) != NULL) { if (!strcmp(buf, "off") || !strcmp(buf, "none")) { bdrv_flags |= BDRV_O_NOCACHE; diff --git a/qemu-config.c b/qemu-config.c index 95abe61..e8ecec8 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -48,6 +48,9 @@ QemuOptsList qemu_drive_opts = { .name = "snapshot", .type = QEMU_OPT_BOOL, },{ + .name = "global_snapshot", + .type = QEMU_OPT_BOOL, + },{ .name = "file", .type = QEMU_OPT_STRING, .help = "disk image", diff --git a/vl.c b/vl.c index ba6ee11..2804855 100644 --- a/vl.c +++ b/vl.c @@ -646,8 +646,9 @@ static int drive_init_func(QemuOpts *opts, void *opaque) static int drive_enable_snapshot(QemuOpts *opts, void *opaque) { - if (NULL == qemu_opt_get(opts, "snapshot")) { - qemu_opt_set(opts, "snapshot", "on"); + if (qemu_opt_get(opts, "snapshot") == NULL && + qemu_opt_get(opts, "global_snapshot") == NULL) { + qemu_opt_set(opts, "global_snapshot", "on"); } return 0; }