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:
parent
22d6aa03fd
commit
caad4eb345
@ -127,7 +127,7 @@ static int scsi_hot_add(Monitor *mon, DeviceState *adapter,
|
|||||||
dinfo->unit = qemu_opt_get_number(dinfo->opts, "unit", -1);
|
dinfo->unit = qemu_opt_get_number(dinfo->opts, "unit", -1);
|
||||||
dinfo->bus = scsibus->busnr;
|
dinfo->bus = scsibus->busnr;
|
||||||
scsidev = scsi_bus_legacy_add_drive(scsibus, dinfo->bdrv, dinfo->unit,
|
scsidev = scsi_bus_legacy_add_drive(scsibus, dinfo->bdrv, dinfo->unit,
|
||||||
false, -1, NULL);
|
false, -1, NULL, NULL);
|
||||||
if (!scsidev) {
|
if (!scsidev) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -346,6 +346,7 @@ static int esp_pci_scsi_init(PCIDevice *dev)
|
|||||||
DeviceState *d = DEVICE(dev);
|
DeviceState *d = DEVICE(dev);
|
||||||
ESPState *s = &pci->esp;
|
ESPState *s = &pci->esp;
|
||||||
uint8_t *pci_conf;
|
uint8_t *pci_conf;
|
||||||
|
Error *err = NULL;
|
||||||
|
|
||||||
pci_conf = dev->config;
|
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);
|
scsi_bus_new(&s->bus, d, &esp_pci_scsi_info, NULL);
|
||||||
if (!d->hotplugged) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -676,6 +676,7 @@ static void sysbus_esp_realize(DeviceState *dev, Error **errp)
|
|||||||
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
|
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
|
||||||
SysBusESPState *sysbus = ESP(dev);
|
SysBusESPState *sysbus = ESP(dev);
|
||||||
ESPState *s = &sysbus->esp;
|
ESPState *s = &sysbus->esp;
|
||||||
|
Error *err = NULL;
|
||||||
|
|
||||||
sysbus_init_irq(sbd, &s->irq);
|
sysbus_init_irq(sbd, &s->irq);
|
||||||
assert(sysbus->it_shift != -1);
|
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);
|
qdev_init_gpio_in(dev, sysbus_esp_gpio_demux, 2);
|
||||||
|
|
||||||
scsi_bus_new(&s->bus, dev, &esp_scsi_info, NULL);
|
scsi_bus_new(&s->bus, dev, &esp_scsi_info, NULL);
|
||||||
if (scsi_bus_legacy_handle_cmdline(&s->bus) < 0) {
|
scsi_bus_legacy_handle_cmdline(&s->bus, &err);
|
||||||
error_setg(errp, "Handling legacy SCSI command line failed");
|
if (err != NULL) {
|
||||||
|
error_propagate(errp, err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2096,6 +2096,7 @@ static int lsi_scsi_init(PCIDevice *dev)
|
|||||||
LSIState *s = LSI53C895A(dev);
|
LSIState *s = LSI53C895A(dev);
|
||||||
DeviceState *d = DEVICE(dev);
|
DeviceState *d = DEVICE(dev);
|
||||||
uint8_t *pci_conf;
|
uint8_t *pci_conf;
|
||||||
|
Error *err = NULL;
|
||||||
|
|
||||||
pci_conf = dev->config;
|
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);
|
scsi_bus_new(&s->bus, d, &lsi_scsi_info, NULL);
|
||||||
if (!d->hotplugged) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -2102,6 +2102,7 @@ static int megasas_scsi_init(PCIDevice *dev)
|
|||||||
MegasasState *s = MEGASAS(dev);
|
MegasasState *s = MEGASAS(dev);
|
||||||
uint8_t *pci_conf;
|
uint8_t *pci_conf;
|
||||||
int i, bar_type;
|
int i, bar_type;
|
||||||
|
Error *err = NULL;
|
||||||
|
|
||||||
pci_conf = dev->config;
|
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);
|
scsi_bus_new(&s->bus, DEVICE(dev), &megasas_scsi_info, NULL);
|
||||||
if (!d->hotplugged) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -209,10 +209,11 @@ static int scsi_qdev_exit(DeviceState *qdev)
|
|||||||
/* handle legacy '-drive if=scsi,...' cmd line args */
|
/* handle legacy '-drive if=scsi,...' cmd line args */
|
||||||
SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
|
SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
|
||||||
int unit, bool removable, int bootindex,
|
int unit, bool removable, int bootindex,
|
||||||
const char *serial)
|
const char *serial, Error **errp)
|
||||||
{
|
{
|
||||||
const char *driver;
|
const char *driver;
|
||||||
DeviceState *dev;
|
DeviceState *dev;
|
||||||
|
Error *err = NULL;
|
||||||
|
|
||||||
driver = bdrv_is_sg(bdrv) ? "scsi-generic" : "scsi-disk";
|
driver = bdrv_is_sg(bdrv) ? "scsi-generic" : "scsi-disk";
|
||||||
dev = qdev_create(&bus->qbus, driver);
|
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);
|
qdev_prop_set_string(dev, "serial", serial);
|
||||||
}
|
}
|
||||||
if (qdev_prop_set_drive(dev, "drive", bdrv) < 0) {
|
if (qdev_prop_set_drive(dev, "drive", bdrv) < 0) {
|
||||||
|
error_setg(errp, "Setting drive property failed");
|
||||||
qdev_free(dev);
|
qdev_free(dev);
|
||||||
return NULL;
|
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 NULL;
|
||||||
|
}
|
||||||
return SCSI_DEVICE(dev);
|
return SCSI_DEVICE(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
int scsi_bus_legacy_handle_cmdline(SCSIBus *bus)
|
void scsi_bus_legacy_handle_cmdline(SCSIBus *bus, Error **errp)
|
||||||
{
|
{
|
||||||
Location loc;
|
Location loc;
|
||||||
DriveInfo *dinfo;
|
DriveInfo *dinfo;
|
||||||
int res = 0, unit;
|
int unit;
|
||||||
|
Error *err = NULL;
|
||||||
|
|
||||||
loc_push_none(&loc);
|
loc_push_none(&loc);
|
||||||
for (unit = 0; unit <= bus->info->max_target; unit++) {
|
for (unit = 0; unit <= bus->info->max_target; unit++) {
|
||||||
@ -248,13 +255,14 @@ int scsi_bus_legacy_handle_cmdline(SCSIBus *bus)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
qemu_opts_loc_restore(dinfo->opts);
|
qemu_opts_loc_restore(dinfo->opts);
|
||||||
if (!scsi_bus_legacy_add_drive(bus, dinfo->bdrv, unit, false, -1, NULL)) {
|
scsi_bus_legacy_add_drive(bus, dinfo->bdrv, unit, false, -1, NULL,
|
||||||
res = -1;
|
&err);
|
||||||
|
if (err != NULL) {
|
||||||
|
error_propagate(errp, err);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
loc_pop(&loc);
|
loc_pop(&loc);
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t scsi_invalid_field(SCSIRequest *req, uint8_t *buf)
|
static int32_t scsi_invalid_field(SCSIRequest *req, uint8_t *buf)
|
||||||
|
@ -912,12 +912,17 @@ static void spapr_vscsi_reset(VIOsPAPRDevice *dev)
|
|||||||
static int spapr_vscsi_init(VIOsPAPRDevice *dev)
|
static int spapr_vscsi_init(VIOsPAPRDevice *dev)
|
||||||
{
|
{
|
||||||
VSCSIState *s = VIO_SPAPR_VSCSI_DEVICE(dev);
|
VSCSIState *s = VIO_SPAPR_VSCSI_DEVICE(dev);
|
||||||
|
Error *err = NULL;
|
||||||
|
|
||||||
dev->crq.SendFunc = vscsi_do_crq;
|
dev->crq.SendFunc = vscsi_do_crq;
|
||||||
|
|
||||||
scsi_bus_new(&s->bus, &dev->qdev, &vscsi_scsi_info, NULL);
|
scsi_bus_new(&s->bus, &dev->qdev, &vscsi_scsi_info, NULL);
|
||||||
if (!dev->qdev.hotplugged) {
|
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;
|
return 0;
|
||||||
|
@ -619,6 +619,7 @@ static int virtio_scsi_device_init(VirtIODevice *vdev)
|
|||||||
VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev);
|
VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev);
|
||||||
VirtIOSCSI *s = VIRTIO_SCSI(vdev);
|
VirtIOSCSI *s = VIRTIO_SCSI(vdev);
|
||||||
static int virtio_scsi_id;
|
static int virtio_scsi_id;
|
||||||
|
Error *err = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = virtio_scsi_common_init(vs);
|
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);
|
scsi_bus_new(&s->bus, qdev, &virtio_scsi_scsi_info, vdev->bus_name);
|
||||||
|
|
||||||
if (!qdev->hotplugged) {
|
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,
|
register_savevm(qdev, "virtio-scsi", virtio_scsi_id++, 1,
|
||||||
|
@ -595,6 +595,7 @@ static int usb_msd_initfn_storage(USBDevice *dev)
|
|||||||
MSDState *s = DO_UPCAST(MSDState, dev, dev);
|
MSDState *s = DO_UPCAST(MSDState, dev, dev);
|
||||||
BlockDriverState *bs = s->conf.bs;
|
BlockDriverState *bs = s->conf.bs;
|
||||||
SCSIDevice *scsi_dev;
|
SCSIDevice *scsi_dev;
|
||||||
|
Error *err = NULL;
|
||||||
|
|
||||||
if (!bs) {
|
if (!bs) {
|
||||||
error_report("drive property not set");
|
error_report("drive property not set");
|
||||||
@ -619,7 +620,8 @@ static int usb_msd_initfn_storage(USBDevice *dev)
|
|||||||
usb_desc_init(dev);
|
usb_desc_init(dev);
|
||||||
scsi_bus_new(&s->bus, &s->dev.qdev, &usb_msd_scsi_info_storage, NULL);
|
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,
|
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) {
|
if (!scsi_dev) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -162,8 +162,8 @@ static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)
|
|||||||
|
|
||||||
SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
|
SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
|
||||||
int unit, bool removable, int bootindex,
|
int unit, bool removable, int bootindex,
|
||||||
const char *serial);
|
const char *serial, Error **errp);
|
||||||
int scsi_bus_legacy_handle_cmdline(SCSIBus *bus);
|
void scsi_bus_legacy_handle_cmdline(SCSIBus *bus, Error **errp);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Predefined sense codes
|
* Predefined sense codes
|
||||||
|
Loading…
Reference in New Issue
Block a user