#include "qemu/help_option.h"
#include "qemu/option.h"
#include "qemu/qemu-print.h"
+#include "qemu/option_int.h"
#include "sysemu/block-backend.h"
#include "sysemu/sysemu.h"
#include "migration/misc.h"
+#include "migration/migration.h"
/*
* Aliases were a bad idea from the start. Let's keep them
return dev;
}
-static void qbus_list_bus(DeviceState *dev, Error **errp)
+static void qbus_error_append_bus_list_hint(DeviceState *dev,
+ Error *const *errp)
{
BusState *child;
const char *sep = " ";
error_append_hint(errp, "\n");
}
-static void qbus_list_dev(BusState *bus, Error **errp)
+static void qbus_error_append_dev_list_hint(BusState *bus,
+ Error *const *errp)
{
BusChild *kid;
const char *sep = " ";
if (!dev) {
error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", elem);
- qbus_list_dev(bus, errp);
+ qbus_error_append_dev_list_hint(bus, errp);
return NULL;
}
if (dev->num_child_bus) {
error_setg(errp, "Device '%s' has multiple child buses",
elem);
- qbus_list_bus(dev, errp);
+ qbus_error_append_bus_list_hint(dev, errp);
} else {
error_setg(errp, "Device '%s' has no child bus", elem);
}
bus = qbus_find_bus(dev, elem);
if (!bus) {
error_setg(errp, "Bus '%s' not found", elem);
- qbus_list_bus(dev, errp);
+ qbus_error_append_bus_list_hint(dev, errp);
return NULL;
}
}
}
}
+static int is_failover_device(void *opaque, const char *name, const char *value,
+ Error **errp)
+{
+ if (strcmp(name, "failover_pair_id") == 0) {
+ QemuOpts *opts = (QemuOpts *)opaque;
+
+ if (qdev_should_hide_device(opts)) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+static bool should_hide_device(QemuOpts *opts)
+{
+ if (qemu_opt_foreach(opts, is_failover_device, opts, NULL) == 0) {
+ return false;
+ }
+ return true;
+}
+
DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
{
DeviceClass *dc;
const char *driver, *path;
- DeviceState *dev;
+ DeviceState *dev = NULL;
BusState *bus = NULL;
Error *err = NULL;
+ bool hide;
driver = qemu_opt_get(opts, "driver");
if (!driver) {
return NULL;
}
}
- if (qdev_hotplug && bus && !qbus_is_hotpluggable(bus)) {
+ hide = should_hide_device(opts);
+
+ if ((hide || qdev_hotplug) && bus && !qbus_is_hotpluggable(bus)) {
error_setg(errp, QERR_BUS_NO_HOTPLUG, bus->name);
return NULL;
}
+ if (hide) {
+ return NULL;
+ }
+
if (!migration_is_idle()) {
error_setg(errp, "device_add not allowed while migrating");
return NULL;
err_del_dev:
error_propagate(errp, err);
- object_unparent(OBJECT(dev));
- object_unref(OBJECT(dev));
+ if (dev) {
+ object_unparent(OBJECT(dev));
+ object_unref(OBJECT(dev));
+ }
return NULL;
}
return;
}
- if (!migration_is_idle()) {
+ if (!migration_is_idle() && !dev->allow_unplug_during_migration) {
error_setg(errp, "device_del not allowed while migrating");
return;
}
Error *err = NULL;
qmp_device_add((QDict *)qdict, NULL, &err);
- hmp_handle_error(mon, &err);
+ hmp_handle_error(mon, err);
}
void hmp_device_del(Monitor *mon, const QDict *qdict)
Error *err = NULL;
qmp_device_del(id, &err);
- hmp_handle_error(mon, &err);
+ hmp_handle_error(mon, err);
}
BlockBackend *blk_by_qdev_id(const char *id, Error **errp)