#include "boards.h"
#include "pci.h"
#include "net.h"
-#include "sysemu.h"
#include "pc.h"
#include "monitor.h"
-#include "block_int.h"
#include "scsi.h"
#include "virtio-blk.h"
#include "qemu-config.h"
+#include "blockdev.h"
+#include "error.h"
#if defined(TARGET_I386)
static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon,
const char *devaddr,
const char *opts_str)
{
+ Error *local_err = NULL;
QemuOpts *opts;
PCIBus *bus;
int ret, devfn;
return NULL;
}
- opts = qemu_opts_parse(&qemu_net_opts, opts_str ? opts_str : "", 0);
+ opts = qemu_opts_parse(qemu_find_opts("net"), opts_str ? opts_str : "", 0);
if (!opts) {
return NULL;
}
qemu_opt_set(opts, "type", "nic");
- ret = net_client_init(mon, opts, 0);
- if (ret < 0)
+ ret = net_client_init(opts, 0, &local_err);
+ if (error_is_set(&local_err)) {
+ qerror_report_err(local_err);
+ error_free(local_err);
return NULL;
+ }
if (nd_table[ret].devaddr) {
monitor_printf(mon, "Parameter addr not supported\n");
return NULL;
SCSIBus *scsibus;
SCSIDevice *scsidev;
- scsibus = DO_UPCAST(SCSIBus, qbus, QLIST_FIRST(&adapter->child_bus));
- if (!scsibus || strcmp(scsibus->qbus.info->name, "SCSI") != 0) {
- error_report("Device is not a SCSI adapter");
- return -1;
+ scsibus = (SCSIBus *)
+ object_dynamic_cast(OBJECT(QLIST_FIRST(&adapter->child_bus)),
+ TYPE_SCSI_BUS);
+ if (!scsibus) {
+ error_report("Device is not a SCSI adapter");
+ return -1;
}
/*
* specified).
*/
dinfo->unit = qemu_opt_get_number(dinfo->opts, "unit", -1);
- scsidev = scsi_bus_legacy_add_drive(scsibus, dinfo, dinfo->unit);
+ dinfo->bus = scsibus->busnr;
+ scsidev = scsi_bus_legacy_add_drive(scsibus, dinfo->bdrv, dinfo->unit,
+ false, -1);
+ if (!scsidev) {
+ return -1;
+ }
dinfo->unit = scsidev->id;
if (printinfo)
return 0;
}
-void drive_hot_add(Monitor *mon, const QDict *qdict)
+int pci_drive_hot_add(Monitor *mon, const QDict *qdict, DriveInfo *dinfo)
{
int dom, pci_bus;
unsigned slot;
- int type;
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;
- switch (type) {
+ switch (dinfo->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, slot, 0);
+ 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;
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);
+ monitor_printf(mon, "Can't hot-add drive to type %d\n", dinfo->type);
goto err;
}
- return;
+ return 0;
err:
- if (dinfo)
- drive_uninit(dinfo);
- return;
+ return -1;
}
static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
dev = NULL;
if (dev && dinfo) {
if (scsi_hot_add(mon, &dev->qdev, dinfo, 0) != 0) {
- qdev_unplug(&dev->qdev);
+ qdev_unplug(&dev->qdev, NULL);
dev = NULL;
}
}
return NULL;
}
dev = pci_create(bus, devfn, "virtio-blk-pci");
- qdev_prop_set_drive(&dev->qdev, "drive", dinfo);
+ if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) {
+ qdev_free(&dev->qdev);
+ dev = NULL;
+ break;
+ }
if (qdev_init(&dev->qdev) < 0)
dev = NULL;
break;
}
#endif
-int pci_device_hot_remove(Monitor *mon, const char *pci_addr)
+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, slot, 0);
+ 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;
}
- return qdev_unplug(&d->qdev);
+
+ 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 do_pci_device_hot_remove(Monitor *mon, const QDict *qdict)