Patchwork [7/8] blockdev: Store -drive option media in DriveInfo

login
register
mail settings
Submitter Markus Armbruster
Date July 6, 2010, 12:37 p.m.
Message ID <1278419869-26126-8-git-send-email-armbru@redhat.com>
Download mbox | patch
Permalink /patch/58016/
State New
Headers show

Comments

Markus Armbruster - July 6, 2010, 12:37 p.m.
Use it instead of bdrv_get_type_hint() to pick HD vs. CD for IDE, SCSI
and XEN drives.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 blockdev.c         |    1 +
 blockdev.h         |    1 +
 hw/ide/core.c      |    3 +--
 hw/ide/qdev.c      |   10 ++++------
 hw/scsi-disk.c     |    4 +++-
 hw/xen_devconfig.c |    2 +-
 6 files changed, 11 insertions(+), 10 deletions(-)
Christoph Hellwig - July 7, 2010, 1:38 a.m.
I'd rather have an enum about the drive type instead of the is_cdrom
flag.  In addition I think patch 8 should be folded into this one.

Patch

diff --git a/blockdev.c b/blockdev.c
index cca3eec..02b4c22 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -437,6 +437,7 @@  DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error)
 	    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 37f3a01..2f3684c 100644
--- a/blockdev.h
+++ b/blockdev.h
@@ -32,6 +32,7 @@  typedef 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 1287f11..e3ab22c 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -2694,8 +2694,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 a7f0b22..30a1a8c 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -82,9 +82,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);
@@ -145,9 +143,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_DRIVE_PROPERTIES()                           \
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index ebefcba..06330e5 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1110,11 +1110,13 @@  static int scsi_cd_initfn(SCSIDevice *dev)
 static int scsi_disk_initfn(SCSIDevice *dev)
 {
     int is_cd;
+    DriveInfo *dinfo;
 
     if (!dev->conf.bs) {
         is_cd = 0;              /* will die in scsi_initfn() */
     } else {
-        is_cd = bdrv_get_type_hint(dev->conf.bs) == BDRV_TYPE_CDROM;
+        dinfo = drive_get_by_blockdev(dev->conf.bs);
+        is_cd = dinfo->media_cd;
     }
 
     return scsi_initfn(dev, is_cd);
diff --git a/hw/xen_devconfig.c b/hw/xen_devconfig.c
index ea8f8c4..5d5ce65 100644
--- a/hw/xen_devconfig.c
+++ b/hw/xen_devconfig.c
@@ -94,7 +94,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";