Skip to contentSkip to conversation

misc block fixes

PATCH Applied Paolo Bonzini 2 participants 7 messages Nov 18, 2011 – Nov 21, 2011

lore
Share & tools
lore
#0 lore raw

cover misc block fixes

See individual patches, all for 1.0.

Paolo Bonzini (4):
virtio-blk: fix cross-endian config space
usb-msd: do not register twice in the boot order
scsi: fix fw path
scsi-generic: add as boot device

 hw/pci-hotplug.c  |    3 ++-
 hw/scsi-bus.c     |   11 +++++++----
 hw/scsi-disk.c    |    2 +-
 hw/scsi-generic.c |    5 +++++
 hw/scsi.h         |    2 +-
 hw/usb-msd.c      |    4 ++--
 hw/virtio-blk.c   |    7 ++++---
 7 files changed, 22 insertions(+), 12 deletions(-)
Signature · 1 line
1.7.7.1
#1 lore raw

PATCH 1/4 virtio-blk: fix cross-endian config space

---

	v1->v2: do not rely on blkcfg since it is now guest-endian
 hw/virtio-blk.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
hw/virtio-blk.c +4 -3
index 01aeb28..0d6f53b 100644
@@ -474,6 +474,7 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
     struct virtio_blk_config blkcfg;
     uint64_t capacity;
     int cylinders, heads, secs;
+    int blk_size = s->conf->logical_block_size;
 
     bdrv_get_geometry(s->bs, &capacity);
     bdrv_get_geometry_hint(s->bs, &cylinders, &heads, &secs);
@@ -481,14 +482,14 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
     stq_raw(&blkcfg.capacity, capacity);
     stl_raw(&blkcfg.seg_max, 128 - 2);
     stw_raw(&blkcfg.cylinders, cylinders);
+    stl_raw(&blkcfg.blk_size, blk_size);
+    stw_raw(&blkcfg.min_io_size, s->conf->min_io_size / blk_size);
+    stw_raw(&blkcfg.opt_io_size, s->conf->opt_io_size / blk_size);
     blkcfg.heads = heads;
     blkcfg.sectors = secs & ~s->sector_mask;
-    blkcfg.blk_size = s->conf->logical_block_size;
     blkcfg.size_max = 0;
     blkcfg.physical_block_exp = get_physical_block_exp(s->conf);
     blkcfg.alignment_offset = 0;
-    blkcfg.min_io_size = s->conf->min_io_size / blkcfg.blk_size;
-    blkcfg.opt_io_size = s->conf->opt_io_size / blkcfg.blk_size;
     memcpy(config, &blkcfg, sizeof(struct virtio_blk_config));
 }
 
Signature · 1 line
1.7.7.1
#2 lore raw

PATCH 2/4 usb-msd: do not register twice in the boot order

In reply to Paolo Bonzini

USB mass storage devices are registered twice in the boot order. To avoid having to keep the two paths in sync, pass the bootindex property down to the scsi-disk device and let it register itself.

---
 hw/pci-hotplug.c |    3 ++-
 hw/scsi-bus.c    |    7 +++++--
 hw/scsi.h        |    2 +-
 hw/usb-msd.c     |    4 ++--
 4 files changed, 10 insertions(+), 6 deletions(-)
hw/pci-hotplug.c +2 -1
index b59be2a..12f61fe 100644
@@ -91,7 +91,8 @@ static int scsi_hot_add(Monitor *mon, DeviceState *adapter,
      */
     dinfo->unit = qemu_opt_get_number(dinfo->opts, "unit", -1);
     dinfo->bus = scsibus->busnr;
-    scsidev = scsi_bus_legacy_add_drive(scsibus, dinfo->bdrv, dinfo->unit, false);
+    scsidev = scsi_bus_legacy_add_drive(scsibus, dinfo->bdrv, dinfo->unit,
+                                        false, -1);
     if (!scsidev) {
         return -1;
     }
hw/scsi-bus.c +5 -2
index 372fe7f..61c883f 100644
@@ -166,7 +166,7 @@ void scsi_qdev_register(SCSIDeviceInfo *info)
 
 /* handle legacy '-drive if=scsi,...' cmd line args */
 SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
-                                      int unit, bool removable)
+                                      int unit, bool removable, int bootindex)
 {
     const char *driver;
     DeviceState *dev;
@@ -174,6 +174,9 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
     driver = bdrv_is_sg(bdrv) ? "scsi-generic" : "scsi-disk";
     dev = qdev_create(&bus->qbus, driver);
     qdev_prop_set_uint32(dev, "scsi-id", unit);
+    if (bootindex >= 0) {
+        qdev_prop_set_int32(dev, "bootindex", bootindex);
+    }
     if (qdev_prop_exists(dev, "removable")) {
         qdev_prop_set_bit(dev, "removable", removable);
     }
@@ -199,7 +202,7 @@ int scsi_bus_legacy_handle_cmdline(SCSIBus *bus)
             continue;
         }
         qemu_opts_loc_restore(dinfo->opts);
-        if (!scsi_bus_legacy_add_drive(bus, dinfo->bdrv, unit, false)) {
+        if (!scsi_bus_legacy_add_drive(bus, dinfo->bdrv, unit, false, -1)) {
             res = -1;
             break;
         }
hw/scsi.h +1 -1
index 796ecf1..92e7b43 100644
@@ -131,7 +131,7 @@ static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)
 }
 
 SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
-                                      int unit, bool removable);
+                                      int unit, bool removable, int bootindex);
 int scsi_bus_legacy_handle_cmdline(SCSIBus *bus);
 
 /*
hw/usb-msd.c +2 -2
index 9ba77a3..0e37b9d 100644
@@ -541,7 +541,8 @@ static int usb_msd_initfn(USBDevice *dev)
 
     usb_desc_init(dev);
     scsi_bus_new(&s->bus, &s->dev.qdev, &usb_msd_scsi_info);
-    s->scsi_dev = scsi_bus_legacy_add_drive(&s->bus, bs, 0, !!s->removable);
+    s->scsi_dev = scsi_bus_legacy_add_drive(&s->bus, bs, 0, !!s->removable,
+                                            s->conf.bootindex);
     if (!s->scsi_dev) {
         return -1;
     }
@@ -557,7 +558,6 @@ static int usb_msd_initfn(USBDevice *dev)
         }
     }
 
-    add_boot_device_path(s->conf.bootindex, &dev->qdev, "/disk@0,0");
     return 0;
 }
 
Signature · 1 line
1.7.7.1
#3 lore raw

PATCH 3/4 scsi: fix fw path

In reply to Paolo Bonzini

The pre-1.0 firmware path for SCSI devices already included the LUN using the suffix argument to add_boot_device_path. Avoid that it is included twice, and, for consistency with the OpenFirmware spec:
1) move the "channel" to a separate device path; 2) convert the colons to commas; 3) use hex for the numbers.

This is compatible with SeaBIOS USB boot, which only looks at the prefix for the usb-storage device (e.g. /pci@i0cf8/usb@1,2/storage@1), and never at the SCSI part.

---
 hw/scsi-bus.c  |    4 ++--
 hw/scsi-disk.c |    2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
hw/scsi-bus.c +2 -2
index 61c883f..07d6a7d 100644
@@ -1307,8 +1307,8 @@ static char *scsibus_get_fw_dev_path(DeviceState *dev)
     SCSIDevice *d = DO_UPCAST(SCSIDevice, qdev, dev);
     char path[100];
 
-    snprintf(path, sizeof(path), "%s@%d:%d:%d", qdev_fw_name(dev),
-             d->channel, d->id, d->lun);
+    snprintf(path, sizeof(path), "channel@%x/%s@%x,%x", d->channel,
+             qdev_fw_name(dev), d->id, d->lun);
 
     return strdup(path);
 }
hw/scsi-disk.c +1 -1
index 9da6d36..16a4714 100644
@@ -1581,7 +1581,7 @@ static int scsi_initfn(SCSIDevice *dev)
     bdrv_set_buffer_alignment(s->qdev.conf.bs, s->qdev.blocksize);
 
     bdrv_iostatus_enable(s->qdev.conf.bs);
-    add_boot_device_path(s->qdev.conf.bootindex, &dev->qdev, ",0");
+    add_boot_device_path(s->qdev.conf.bootindex, &dev->qdev, NULL);
     return 0;
 }
 
Signature · 1 line
1.7.7.1
#4 lore raw

PATCH 3/4 scsi: fix fw path

The pre-1.0 firmware path for SCSI devices already included the LUN using the suffix argument to add_boot_device_path. Avoid that it is included twice, and convert the colons to commas for consistency with other kinds of devices

---
 hw/scsi-bus.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
hw/scsi-bus.c +2 -2
index 086bddd..8f19f07 100644
@@ -1395,8 +1395,8 @@ static char *scsibus_get_fw_dev_path(DeviceState *dev)
     SCSIDevice *d = DO_UPCAST(SCSIDevice, qdev, dev);
     char path[100];
 
-    snprintf(path, sizeof(path), "%s@%d,%d,%d", qdev_fw_name(dev),
-             d->channel, d->id, d->lun);
+    snprintf(path, sizeof(path), "channel@%x/%s@%x,%x", d->channel,
+             qdev_fw_name(dev), d->id, d->lun);
 
     return strdup(path);
 }
Signature · 1 line
1.7.7.1
#5 lore raw

PATCH 4/4 scsi-generic: add as boot device

In reply to Paolo Bonzini

There is no reason why a scsi-generic device cannot boot if it has the right type, and indeed it provides already a bootindex property. So register those devices too.

---
 hw/scsi-generic.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
hw/scsi-generic.c +5 -0
index 48e0b50..6f7d3db 100644
@@ -409,6 +409,10 @@ static int scsi_generic_initfn(SCSIDevice *s)
     /* define device state */
     s->type = scsiid.scsi_type;
     DPRINTF("device type %d\n", s->type);
+    if (s->type == TYPE_DISK || s->type == TYPE_ROM) {
+        add_boot_device_path(s->conf.bootindex, &s->qdev, NULL);
+    }
+
     switch (s->type) {
     case TYPE_TAPE:
         s->blocksize = get_stream_blocksize(s->conf.bs);
@@ -455,6 +459,7 @@ static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag, uint32_t lun,
 
 static SCSIDeviceInfo scsi_generic_info = {
     .qdev.name    = "scsi-generic",
+    .qdev.fw_name = "disk",
     .qdev.desc    = "pass through generic scsi device (/dev/sg*)",
     .qdev.size    = sizeof(SCSIDevice),
     .qdev.reset   = scsi_generic_reset,
Signature · 1 line
1.7.7.1
Applied
#6 lore raw
In reply to Paolo Bonzini

Am 18.11.2011 16:31, schrieb Paolo Bonzini:

Quoted 8 lines

See individual patches, all for 1.0.

Paolo Bonzini (4):
virtio-blk: fix cross-endian config space
usb-msd: do not register twice in the boot order
scsi: fix fw path
scsi-generic: add as boot device

Quoted 8 lines
 hw/pci-hotplug.c  |    3 ++-
 hw/scsi-bus.c     |   11 +++++++----
 hw/scsi-disk.c    |    2 +-
 hw/scsi-generic.c |    5 +++++
 hw/scsi.h         |    2 +-
 hw/usb-msd.c      |    4 ++--
 hw/virtio-blk.c   |    7 ++++---
 7 files changed, 22 insertions(+), 12 deletions(-)

Thanks, applied all to the block-stable branch (for 1.0)

Kevin