scsi: Improve error propagation for scsi_bus_legacy_handle_cmdline()

Let scsi_bus_legacy_add_drive() and scsi_bus_legacy_handle_cmdline()
return an Error**. Prepare qdev initfns for QOM realize error model.

Signed-off-by: Andreas Färber <afaerber@suse.de>
This commit is contained in:
Andreas Färber 2013-07-21 12:16:34 +02:00
parent 22d6aa03fd
commit caad4eb345
10 changed files with 55 additions and 18 deletions

View File

@ -127,7 +127,7 @@ 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, -1, NULL);
false, -1, NULL, NULL);
if (!scsidev) {
return -1;
}

View File

@ -346,6 +346,7 @@ static int esp_pci_scsi_init(PCIDevice *dev)
DeviceState *d = DEVICE(dev);
ESPState *s = &pci->esp;
uint8_t *pci_conf;
Error *err = NULL;
pci_conf = dev->config;
@ -364,7 +365,11 @@ static int esp_pci_scsi_init(PCIDevice *dev)
scsi_bus_new(&s->bus, d, &esp_pci_scsi_info, NULL);
if (!d->hotplugged) {
return scsi_bus_legacy_handle_cmdline(&s->bus);
scsi_bus_legacy_handle_cmdline(&s->bus, &err);
if (err != NULL) {
error_free(err);
return -1;
}
}
return 0;
}

View File

@ -676,6 +676,7 @@ static void sysbus_esp_realize(DeviceState *dev, Error **errp)
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
SysBusESPState *sysbus = ESP(dev);
ESPState *s = &sysbus->esp;
Error *err = NULL;
sysbus_init_irq(sbd, &s->irq);
assert(sysbus->it_shift != -1);
@ -688,8 +689,9 @@ static void sysbus_esp_realize(DeviceState *dev, Error **errp)
qdev_init_gpio_in(dev, sysbus_esp_gpio_demux, 2);
scsi_bus_new(&s->bus, dev, &esp_scsi_info, NULL);
if (scsi_bus_legacy_handle_cmdline(&s->bus) < 0) {
error_setg(errp, "Handling legacy SCSI command line failed");
scsi_bus_legacy_handle_cmdline(&s->bus, &err);
if (err != NULL) {
error_propagate(errp, err);
return;
}
}

View File

@ -2096,6 +2096,7 @@ static int lsi_scsi_init(PCIDevice *dev)
LSIState *s = LSI53C895A(dev);
DeviceState *d = DEVICE(dev);
uint8_t *pci_conf;
Error *err = NULL;
pci_conf = dev->config;
@ -2118,7 +2119,11 @@ static int lsi_scsi_init(PCIDevice *dev)
scsi_bus_new(&s->bus, d, &lsi_scsi_info, NULL);
if (!d->hotplugged) {
return scsi_bus_legacy_handle_cmdline(&s->bus);
scsi_bus_legacy_handle_cmdline(&s->bus, &err);
if (err != NULL) {
error_free(err);
return -1;
}
}
return 0;
}

View File

@ -2102,6 +2102,7 @@ static int megasas_scsi_init(PCIDevice *dev)
MegasasState *s = MEGASAS(dev);
uint8_t *pci_conf;
int i, bar_type;
Error *err = NULL;
pci_conf = dev->config;
@ -2172,7 +2173,11 @@ static int megasas_scsi_init(PCIDevice *dev)
scsi_bus_new(&s->bus, DEVICE(dev), &megasas_scsi_info, NULL);
if (!d->hotplugged) {
return scsi_bus_legacy_handle_cmdline(&s->bus);
scsi_bus_legacy_handle_cmdline(&s->bus, &err);
if (err != NULL) {
error_free(err);
return -1;
}
}
return 0;
}

View File

@ -209,10 +209,11 @@ static int scsi_qdev_exit(DeviceState *qdev)
/* handle legacy '-drive if=scsi,...' cmd line args */
SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
int unit, bool removable, int bootindex,
const char *serial)
const char *serial, Error **errp)
{
const char *driver;
DeviceState *dev;
Error *err = NULL;
driver = bdrv_is_sg(bdrv) ? "scsi-generic" : "scsi-disk";
dev = qdev_create(&bus->qbus, driver);
@ -227,19 +228,25 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
qdev_prop_set_string(dev, "serial", serial);
}
if (qdev_prop_set_drive(dev, "drive", bdrv) < 0) {
error_setg(errp, "Setting drive property failed");
qdev_free(dev);
return NULL;
}
if (qdev_init(dev) < 0)
object_property_set_bool(OBJECT(dev), true, "realized", &err);
if (err != NULL) {
error_propagate(errp, err);
qdev_free(dev);
return NULL;
}
return SCSI_DEVICE(dev);
}
int scsi_bus_legacy_handle_cmdline(SCSIBus *bus)
void scsi_bus_legacy_handle_cmdline(SCSIBus *bus, Error **errp)
{
Location loc;
DriveInfo *dinfo;
int res = 0, unit;
int unit;
Error *err = NULL;
loc_push_none(&loc);
for (unit = 0; unit <= bus->info->max_target; unit++) {
@ -248,13 +255,14 @@ 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, -1, NULL)) {
res = -1;
scsi_bus_legacy_add_drive(bus, dinfo->bdrv, unit, false, -1, NULL,
&err);
if (err != NULL) {
error_propagate(errp, err);
break;
}
}
loc_pop(&loc);
return res;
}
static int32_t scsi_invalid_field(SCSIRequest *req, uint8_t *buf)

View File

@ -912,12 +912,17 @@ static void spapr_vscsi_reset(VIOsPAPRDevice *dev)
static int spapr_vscsi_init(VIOsPAPRDevice *dev)
{
VSCSIState *s = VIO_SPAPR_VSCSI_DEVICE(dev);
Error *err = NULL;
dev->crq.SendFunc = vscsi_do_crq;
scsi_bus_new(&s->bus, &dev->qdev, &vscsi_scsi_info, NULL);
if (!dev->qdev.hotplugged) {
scsi_bus_legacy_handle_cmdline(&s->bus);
scsi_bus_legacy_handle_cmdline(&s->bus, &err);
if (err != NULL) {
error_free(err);
return -1;
}
}
return 0;

View File

@ -619,6 +619,7 @@ static int virtio_scsi_device_init(VirtIODevice *vdev)
VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev);
VirtIOSCSI *s = VIRTIO_SCSI(vdev);
static int virtio_scsi_id;
Error *err = NULL;
int ret;
ret = virtio_scsi_common_init(vs);
@ -629,7 +630,11 @@ static int virtio_scsi_device_init(VirtIODevice *vdev)
scsi_bus_new(&s->bus, qdev, &virtio_scsi_scsi_info, vdev->bus_name);
if (!qdev->hotplugged) {
scsi_bus_legacy_handle_cmdline(&s->bus);
scsi_bus_legacy_handle_cmdline(&s->bus, &err);
if (err != NULL) {
error_free(err);
return -1;
}
}
register_savevm(qdev, "virtio-scsi", virtio_scsi_id++, 1,

View File

@ -595,6 +595,7 @@ static int usb_msd_initfn_storage(USBDevice *dev)
MSDState *s = DO_UPCAST(MSDState, dev, dev);
BlockDriverState *bs = s->conf.bs;
SCSIDevice *scsi_dev;
Error *err = NULL;
if (!bs) {
error_report("drive property not set");
@ -619,7 +620,8 @@ static int usb_msd_initfn_storage(USBDevice *dev)
usb_desc_init(dev);
scsi_bus_new(&s->bus, &s->dev.qdev, &usb_msd_scsi_info_storage, NULL);
scsi_dev = scsi_bus_legacy_add_drive(&s->bus, bs, 0, !!s->removable,
s->conf.bootindex, dev->serial);
s->conf.bootindex, dev->serial,
&err);
if (!scsi_dev) {
return -1;
}

View File

@ -162,8 +162,8 @@ static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)
SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
int unit, bool removable, int bootindex,
const char *serial);
int scsi_bus_legacy_handle_cmdline(SCSIBus *bus);
const char *serial, Error **errp);
void scsi_bus_legacy_handle_cmdline(SCSIBus *bus, Error **errp);
/*
* Predefined sense codes