From patchwork Mon Jan 31 15:29:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 81174 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 9AE1BB70E9 for ; Tue, 1 Feb 2011 03:16:48 +1100 (EST) Received: from localhost ([127.0.0.1]:55784 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PjwQn-0002S3-Jx for incoming@patchwork.ozlabs.org; Mon, 31 Jan 2011 11:16:45 -0500 Received: from [140.186.70.92] (port=43199 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pjvfy-0002nC-IT for qemu-devel@nongnu.org; Mon, 31 Jan 2011 10:28:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pjvfj-0003WU-HI for qemu-devel@nongnu.org; Mon, 31 Jan 2011 10:28:10 -0500 Received: from mx1.redhat.com ([209.132.183.28]:1031) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pjvfj-0003W8-A7 for qemu-devel@nongnu.org; Mon, 31 Jan 2011 10:28:07 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p0VFS5jT010629 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 31 Jan 2011 10:28:06 -0500 Received: from dhcp-5-188.str.redhat.com (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p0VFRZ2O012144; Mon, 31 Jan 2011 10:28:04 -0500 From: Kevin Wolf To: anthony@codemonkey.ws Date: Mon, 31 Jan 2011 16:29:14 +0100 Message-Id: <1296487756-12553-27-git-send-email-kwolf@redhat.com> In-Reply-To: <1296487756-12553-1-git-send-email-kwolf@redhat.com> References: <1296487756-12553-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 26/28] blockdev: Reject multiple definitions for the same drive 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 silently ignore multiple definitions for the same drive: $ qemu-system-x86_64 -nodefaults -vnc :1 -S -monitor stdio -drive if=ide,index=1,file=tmp.qcow2 -drive if=ide,index=1,file=nonexistant QEMU 0.13.50 monitor - type 'help' for more information (qemu) info block ide0-hd1: type=hd removable=0 file=tmp.qcow2 backing_file=tmp.img ro=0 drv=qcow2 encrypted=0 With if=none, this can become quite confusing: $ qemu-system-x86_64 -nodefaults -vnc :1 -S -monitor stdio -drive if=none,index=1,file=tmp.qcow2,id=eins -drive if=none,index=1,file=nonexistant,id=zwei -device ide-drive,drive=eins -device ide-drive,drive=zwei qemu-system-x86_64: -device ide-drive,drive=zwei: Property 'ide-drive.drive' can't find value 'zwei' The second -device fails, because it refers to drive zwei, which got silently ignored. Make multiple drive definitions fail cleanly. Unfortunately, there's code that relies on multiple drive definitions being silently ignored: main() merrily adds default drives even when the user already defined these drives. Fix that up. Signed-off-by: Markus Armbruster Signed-off-by: Kevin Wolf --- blockdev.c | 5 +++-- vl.c | 45 ++++++++++++++++++++++++++++++--------------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/blockdev.c b/blockdev.c index 01228f6..3f7b560 100644 --- a/blockdev.c +++ b/blockdev.c @@ -429,11 +429,12 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error) } /* - * ignore multiple definitions + * catch multiple definitions */ if (drive_get(type, bus_id, unit_id) != NULL) { - *fatal_error = 0; + error_report("drive with bus=%d, unit=%d (index=%d) exists", + bus_id, unit_id, index); return NULL; } diff --git a/vl.c b/vl.c index 5399e33..99f5bfe 100644 --- a/vl.c +++ b/vl.c @@ -649,6 +649,29 @@ static int drive_enable_snapshot(QemuOpts *opts, void *opaque) return 0; } +static void default_drive(int enable, int snapshot, int use_scsi, + BlockInterfaceType type, int index, + const char *optstr) +{ + QemuOpts *opts; + + if (type == IF_DEFAULT) { + type = use_scsi ? IF_SCSI : IF_IDE; + } + + if (!enable || drive_get_by_index(type, index)) { + return; + } + + opts = drive_add(type, index, NULL, optstr); + if (snapshot) { + drive_enable_snapshot(opts, NULL); + } + if (drive_init_func(opts, &use_scsi)) { + exit(1); + } +} + void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque) { boot_set_handler = func; @@ -2893,27 +2916,19 @@ int main(int argc, char **argv, char **envp) blk_mig_init(); - if (default_cdrom) { - /* we always create the cdrom drive, even if no disk is there */ - drive_add(IF_DEFAULT, 2, NULL, CDROM_OPTS); - } - - if (default_floppy) { - /* we always create at least one floppy */ - drive_add(IF_FLOPPY, 0, NULL, FD_OPTS); - } - - if (default_sdcard) { - /* we always create one sd slot, even if no card is in it */ - drive_add(IF_SD, 0, NULL, SD_OPTS); - } - /* open the virtual block devices */ if (snapshot) qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0); if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, &machine->use_scsi, 1) != 0) exit(1); + default_drive(default_cdrom, snapshot, machine->use_scsi, + IF_DEFAULT, 2, CDROM_OPTS); + default_drive(default_floppy, snapshot, machine->use_scsi, + IF_FLOPPY, 0, FD_OPTS); + default_drive(default_sdcard, snapshot, machine->use_scsi, + IF_SD, 0, SD_OPTS); + register_savevm_live(NULL, "ram", 0, 4, NULL, ram_save_live, NULL, ram_load, NULL);