mirror of https://github.com/xemu-project/xemu.git
refactor drive_hot_add
move pci device lookup into the "case IF_SCSI" section, so we can do something else for other interface types. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
56a1493880
commit
4db49dc087
|
@ -58,48 +58,48 @@ void drive_hot_add(Monitor *mon, const QDict *qdict)
|
||||||
int dom, pci_bus;
|
int dom, pci_bus;
|
||||||
unsigned slot;
|
unsigned slot;
|
||||||
int type, bus;
|
int type, bus;
|
||||||
int success = 0;
|
|
||||||
PCIDevice *dev;
|
PCIDevice *dev;
|
||||||
DriveInfo *dinfo;
|
DriveInfo *dinfo = NULL;
|
||||||
const char *pci_addr = qdict_get_str(qdict, "pci_addr");
|
const char *pci_addr = qdict_get_str(qdict, "pci_addr");
|
||||||
const char *opts = qdict_get_str(qdict, "opts");
|
const char *opts = qdict_get_str(qdict, "opts");
|
||||||
BusState *scsibus;
|
BusState *scsibus;
|
||||||
|
|
||||||
if (pci_read_devaddr(mon, pci_addr, &dom, &pci_bus, &slot)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
dev = pci_find_device(pci_bus, slot, 0);
|
|
||||||
if (!dev) {
|
|
||||||
monitor_printf(mon, "no pci device with address %s\n", pci_addr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
dinfo = add_init_drive(opts);
|
dinfo = add_init_drive(opts);
|
||||||
if (!dinfo)
|
if (!dinfo)
|
||||||
return;
|
goto err;
|
||||||
if (dinfo->devaddr) {
|
if (dinfo->devaddr) {
|
||||||
monitor_printf(mon, "Parameter addr not supported\n");
|
monitor_printf(mon, "Parameter addr not supported\n");
|
||||||
return;
|
goto err;
|
||||||
}
|
}
|
||||||
type = dinfo->type;
|
type = dinfo->type;
|
||||||
bus = drive_get_max_bus (type);
|
bus = drive_get_max_bus (type);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case IF_SCSI:
|
case IF_SCSI:
|
||||||
success = 1;
|
if (pci_read_devaddr(mon, pci_addr, &dom, &pci_bus, &slot)) {
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
dev = pci_find_device(pci_bus, slot, 0);
|
||||||
|
if (!dev) {
|
||||||
|
monitor_printf(mon, "no pci device with address %s\n", pci_addr);
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
scsibus = QLIST_FIRST(&dev->qdev.child_bus);
|
scsibus = QLIST_FIRST(&dev->qdev.child_bus);
|
||||||
scsi_bus_legacy_add_drive(DO_UPCAST(SCSIBus, qbus, scsibus),
|
scsi_bus_legacy_add_drive(DO_UPCAST(SCSIBus, qbus, scsibus),
|
||||||
dinfo, dinfo->unit);
|
dinfo, dinfo->unit);
|
||||||
break;
|
|
||||||
default:
|
|
||||||
monitor_printf(mon, "Can't hot-add drive to type %d\n", type);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (success)
|
|
||||||
monitor_printf(mon, "OK bus %d, unit %d\n",
|
monitor_printf(mon, "OK bus %d, unit %d\n",
|
||||||
dinfo->bus,
|
dinfo->bus,
|
||||||
dinfo->unit);
|
dinfo->unit);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
monitor_printf(mon, "Can't hot-add drive to type %d\n", type);
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
|
||||||
|
err:
|
||||||
|
if (dinfo)
|
||||||
|
drive_uninit(dinfo);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue