int pci_drive_hot_add(Monitor *mon, const QDict *qdict, DriveInfo *dinfo, int type) { int dom, pci_bus; unsigned slot; PCIDevice *dev; const char *pci_addr = qdict_get_str(qdict, "pci_addr"); switch (type) { case IF_SCSI: if (pci_read_devaddr(mon, pci_addr, &dom, &pci_bus, &slot)) { goto err; } dev = pci_find_device(pci_find_root_bus(dom), pci_bus, PCI_DEVFN(slot, 0)); if (!dev) { monitor_printf(mon, "no pci device with address %s\n", pci_addr); goto err; } if (scsi_hot_add(mon, &dev->qdev, dinfo, 1) != 0) { goto err; } break; default: monitor_printf(mon, "Can't hot-add drive to type %d\n", type); goto err; } return 0; err: return -1; }
static int pci_device_hot_remove(Monitor *mon, const char *pci_addr) { PCIDevice *d; int dom, bus; unsigned slot; Error *local_err = NULL; if (pci_read_devaddr(mon, pci_addr, &dom, &bus, &slot)) { return -1; } d = pci_find_device(pci_find_root_bus(dom), bus, PCI_DEVFN(slot, 0)); if (!d) { monitor_printf(mon, "slot %d empty\n", slot); return -1; } qdev_unplug(&d->qdev, &local_err); if (error_is_set(&local_err)) { monitor_printf(mon, "%s\n", error_get_pretty(local_err)); error_free(local_err); return -1; } return 0; }
static int pci_device_hot_remove(Monitor *mon, const char *pci_addr) { PCIBus *root = pci_find_primary_bus(); PCIDevice *d; int bus; unsigned slot; Error *local_err = NULL; if (!root) { monitor_printf(mon, "no primary PCI bus (if there are multiple" " PCI roots, you must use device_del instead)"); return -1; } if (pci_read_devaddr(mon, pci_addr, &bus, &slot)) { return -1; } d = pci_find_device(root, bus, PCI_DEVFN(slot, 0)); if (!d) { monitor_printf(mon, "slot %d empty\n", slot); return -1; } qdev_unplug(&d->qdev, &local_err); if (error_is_set(&local_err)) { monitor_printf(mon, "%s\n", error_get_pretty(local_err)); error_free(local_err); return -1; } return 0; }
void drive_hot_add(Monitor *mon, const QDict *qdict) { int dom, pci_bus; unsigned slot; int type, bus; PCIDevice *dev; DriveInfo *dinfo = NULL; const char *pci_addr = qdict_get_str(qdict, "pci_addr"); const char *opts = qdict_get_str(qdict, "opts"); BusState *scsibus; dinfo = add_init_drive(opts); if (!dinfo) goto err; if (dinfo->devaddr) { monitor_printf(mon, "Parameter addr not supported\n"); goto err; } type = dinfo->type; bus = drive_get_max_bus (type); switch (type) { case IF_SCSI: 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); scsi_bus_legacy_add_drive(DO_UPCAST(SCSIBus, qbus, scsibus), dinfo, dinfo->unit); monitor_printf(mon, "OK bus %d, unit %d\n", dinfo->bus, dinfo->unit); break; case IF_NONE: monitor_printf(mon, "OK\n"); 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; }
void drive_hot_add(Monitor *mon, const QDict *qdict) { int dom, pci_bus; unsigned slot; int type, bus; PCIDevice *dev; DriveInfo *dinfo = NULL; const char *pci_addr = qdict_get_str(qdict, "pci_addr"); const char *opts = qdict_get_str(qdict, "opts"); dinfo = add_init_drive(opts); if (!dinfo) goto err; if (dinfo->devaddr) { monitor_printf(mon, "Parameter addr not supported\n"); goto err; } type = dinfo->type; bus = drive_get_max_bus (type); switch (type) { case IF_SCSI: if (pci_read_devaddr(mon, pci_addr, &dom, &pci_bus, &slot)) { goto err; } dev = pci_find_device(pci_find_host_bus(0), pci_bus, slot, 0); if (!dev) { monitor_printf(mon, "no pci device with address %s\n", pci_addr); goto err; } if (scsi_hot_add(&dev->qdev, dinfo, 1) != 0) { goto err; } break; case IF_NONE: monitor_printf(mon, "OK\n"); 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; }
void pci_device_hot_remove(Monitor *mon, const char *pci_addr) { PCIDevice *d; int dom, bus; unsigned slot; if (pci_read_devaddr(mon, pci_addr, &dom, &bus, &slot)) { return; } d = pci_find_device(pci_find_host_bus(0), bus, slot, 0); if (!d) { monitor_printf(mon, "slot %d empty\n", slot); return; } qdev_unplug(&d->qdev); }
int pci_drive_hot_add(Monitor *mon, const QDict *qdict, DriveInfo *dinfo) { int pci_bus; unsigned slot; PCIBus *root = pci_find_primary_bus(); PCIDevice *dev; const char *pci_addr = qdict_get_str(qdict, "pci_addr"); switch (dinfo->type) { case IF_SCSI: if (!root) { monitor_printf(mon, "no primary PCI bus (if there are multiple" " PCI roots, you must use device_add instead)"); goto err; } if (pci_read_devaddr(mon, pci_addr, &pci_bus, &slot)) { goto err; } dev = pci_find_device(root, pci_bus, PCI_DEVFN(slot, 0)); if (!dev) { monitor_printf(mon, "no pci device with address %s\n", pci_addr); goto err; } if (scsi_hot_add(mon, &dev->qdev, dinfo, 1) != 0) { goto err; } break; default: monitor_printf(mon, "Can't hot-add drive to type %d\n", dinfo->type); goto err; } return 0; err: return -1; }