From patchwork Mon May 9 09:51:33 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 94750 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D5B86B6F7A for ; Mon, 9 May 2011 19:52:07 +1000 (EST) Received: from localhost ([::1]:59883 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QJN8F-0003Ln-Ge for incoming@patchwork.ozlabs.org; Mon, 09 May 2011 05:52:03 -0400 Received: from eggs.gnu.org ([140.186.70.92]:50762) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QJN7t-0003Hc-4T for qemu-devel@nongnu.org; Mon, 09 May 2011 05:51:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QJN7q-0000E4-9m for qemu-devel@nongnu.org; Mon, 09 May 2011 05:51:41 -0400 Received: from oxygen.pond.sub.org ([213.239.205.148]:50346) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QJN7q-0000Da-1J for qemu-devel@nongnu.org; Mon, 09 May 2011 05:51:38 -0400 Received: from blackfin.pond.sub.org (p5B32C6E7.dip.t-dialin.net [91.50.198.231]) by oxygen.pond.sub.org (Postfix) with ESMTPA id EDFAE2DD488; Mon, 9 May 2011 11:51:35 +0200 (CEST) Received: by blackfin.pond.sub.org (Postfix, from userid 500) id 0B8572C8; Mon, 9 May 2011 11:51:35 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 9 May 2011 11:51:33 +0200 Message-Id: <1304934694-13432-5-git-send-email-armbru@redhat.com> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1304934694-13432-1-git-send-email-armbru@redhat.com> References: <1304934694-13432-1-git-send-email-armbru@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 213.239.205.148 Cc: kwolf@redhat.com, kraxel@redhat.com, hch@lst.de Subject: [Qemu-devel] [PATCH v2 4/5] blockdev: Store -drive option media in DriveInfo 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 DriveInfo is closely tied to -drive, and like -drive, it mixes information about host and guest part of the block device. Unlike DriveInfo, BlockDriverState should be about the host part only. One of the remaining guest bits there is the "type hint". -drive option media sets it, and qdevs "ide-drive", "scsi-disk" and non-qdev IF_XEN devices check it to pick HD vs. CD. Communicate -drive option media via new DriveInfo member media_cd instead. Signed-off-by: Markus Armbruster --- blockdev.c | 1 + blockdev.h | 1 + hw/ide/core.c | 3 +-- hw/ide/qdev.c | 10 ++++------ hw/scsi-disk.c | 5 +++-- hw/xen_devconfig.c | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/blockdev.c b/blockdev.c index 5429621..28727df 100644 --- a/blockdev.c +++ b/blockdev.c @@ -488,6 +488,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi) break; case MEDIA_CDROM: bdrv_set_type_hint(dinfo->bdrv, BDRV_TYPE_CDROM); + dinfo->media_cd = 1; break; } break; diff --git a/blockdev.h b/blockdev.h index 2c9e780..3587786 100644 --- a/blockdev.h +++ b/blockdev.h @@ -33,6 +33,7 @@ struct DriveInfo { int bus; int unit; int auto_del; /* see blockdev_mark_auto_del() */ + int media_cd; QemuOpts *opts; char serial[BLOCK_SERIAL_STRLEN + 1]; QTAILQ_ENTRY(DriveInfo) next; diff --git a/hw/ide/core.c b/hw/ide/core.c index 542ed65..45410e8 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -1731,8 +1731,7 @@ void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0, ide_init1(bus, i); if (dinfo) { if (ide_init_drive(&bus->ifs[i], dinfo->bdrv, - bdrv_get_type_hint(dinfo->bdrv) == BDRV_TYPE_CDROM ? IDE_CD : IDE_HD, - NULL, + dinfo->media_cd ? IDE_CD : IDE_HD, NULL, *dinfo->serial ? dinfo->serial : NULL) < 0) { error_report("Can't set up IDE drive %s", dinfo->id); exit(1); diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index 89cf86a..a35eed9 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -98,9 +98,7 @@ IDEDevice *ide_create_drive(IDEBus *bus, int unit, DriveInfo *drive) { DeviceState *dev; - dev = qdev_create(&bus->qbus, - bdrv_get_type_hint(drive->bdrv) == BDRV_TYPE_CDROM - ? "ide-hd" : "ide-cd"); + dev = qdev_create(&bus->qbus, drive->media_cd ? "ide-hd" : "ide-cd"); qdev_prop_set_uint32(dev, "unit", unit); qdev_prop_set_drive_nofail(dev, "drive", drive->bdrv); qdev_init_nofail(dev); @@ -165,9 +163,9 @@ static int ide_cd_initfn(IDEDevice *dev) static int ide_drive_initfn(IDEDevice *dev) { - return ide_dev_initfn(dev, - bdrv_get_type_hint(dev->conf.bs) == BDRV_TYPE_CDROM - ? IDE_CD : IDE_HD); + DriveInfo *dinfo = drive_get_by_blockdev(dev->conf.bs); + + return ide_dev_initfn(dev, dinfo->media_cd ? IDE_CD : IDE_HD); } #define DEFINE_IDE_DEV_PROPERTIES() \ diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 8df8518..397b9d6 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -1295,12 +1295,13 @@ static int scsi_cd_initfn(SCSIDevice *dev) static int scsi_disk_initfn(SCSIDevice *dev) { SCSIDriveKind kind; + DriveInfo *dinfo; if (!dev->conf.bs) { kind = SCSI_HD; /* will die in scsi_initfn() */ } else { - kind = bdrv_get_type_hint(dev->conf.bs) == BDRV_TYPE_CDROM - ? SCSI_CD : SCSI_HD; + dinfo = drive_get_by_blockdev(dev->conf.bs); + kind = dinfo->media_cd ? SCSI_CD : SCSI_HD; } return scsi_initfn(dev, kind); diff --git a/hw/xen_devconfig.c b/hw/xen_devconfig.c index 8d50216..3a92155 100644 --- a/hw/xen_devconfig.c +++ b/hw/xen_devconfig.c @@ -96,7 +96,7 @@ int xen_config_dev_blk(DriveInfo *disk) { char fe[256], be[256]; int vdev = 202 * 256 + 16 * disk->unit; - int cdrom = disk->bdrv->type == BDRV_TYPE_CDROM; + int cdrom = disk->media_cd; const char *devtype = cdrom ? "cdrom" : "disk"; const char *mode = cdrom ? "r" : "w";