#include "qemu/osdep.h"
#include "hw/sysbus.h"
+#include "monitor/hmp.h"
#include "monitor/monitor.h"
#include "monitor/qdev.h"
#include "sysemu/arch_init.h"
#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"
+#include "qemu/cutils.h"
/*
* Aliases were a bad idea from the start. Let's keep them
{ "virtio-input-host-ccw", "virtio-input-host", QEMU_ARCH_S390X },
{ "virtio-input-host-pci", "virtio-input-host",
QEMU_ARCH_ALL & ~QEMU_ARCH_S390X },
+ { "virtio-iommu-pci", "virtio-iommu", QEMU_ARCH_ALL & ~QEMU_ARCH_S390X },
{ "virtio-keyboard-ccw", "virtio-keyboard", QEMU_ARCH_S390X },
{ "virtio-keyboard-pci", "virtio-keyboard",
QEMU_ARCH_ALL & ~QEMU_ARCH_S390X },
const char *driver;
ObjectPropertyInfoList *prop_list;
ObjectPropertyInfoList *prop;
+ GPtrArray *array;
+ int i;
driver = qemu_opt_get(opts, "driver");
if (driver && is_help_option(driver)) {
} else {
qemu_printf("There are no options for %s.\n", driver);
}
+ array = g_ptr_array_new();
for (prop = prop_list; prop; prop = prop->next) {
- int len;
- qemu_printf(" %s=<%s>%n", prop->value->name, prop->value->type, &len);
- if (prop->value->has_description) {
- if (len < 24) {
- qemu_printf("%*s", 24 - len, "");
- }
- qemu_printf(" - %s\n", prop->value->description);
- } else {
- qemu_printf("\n");
- }
- }
-
+ g_ptr_array_add(array,
+ object_property_help(prop->value->name,
+ prop->value->type,
+ prop->value->default_value,
+ prop->value->description));
+ }
+ g_ptr_array_sort(array, (GCompareFunc)qemu_pstrcmp0);
+ for (i = 0; i < array->len; i++) {
+ printf("%s\n", (char *)array->pdata[i]);
+ }
+ g_ptr_array_set_free_func(array, g_free);
+ g_ptr_array_free(array, true);
qapi_free_ObjectPropertyInfoList(prop_list);
return 1;
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;
/* create device */
dev = DEVICE(object_new(driver));
+ /* Check whether the hotplug is allowed by the machine */
+ if (qdev_hotplug && !qdev_hotplug_allowed(dev, &err)) {
+ /* Error must be set in the machine hook */
+ assert(err);
+ goto err_del_dev;
+ }
+
if (bus) {
qdev_set_parent_bus(dev, bus);
} else if (qdev_hotplug && !qdev_get_machine_hotplug_handler(dev)) {
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;
}
}
class = object_get_class(OBJECT(dev));
do {
- qdev_print_props(mon, dev, DEVICE_CLASS(class)->props, indent);
+ qdev_print_props(mon, dev, DEVICE_CLASS(class)->props_, indent);
class = object_class_get_parent(class);
} while (class != object_class_by_name(TYPE_DEVICE));
bus_print_dev(dev->parent_bus, mon, dev, indent);
return;
}
- if (!migration_is_idle()) {
+ if (!migration_is_idle() && !dev->allow_unplug_during_migration) {
error_setg(errp, "device_del not allowed while migrating");
return;
}
{
DeviceState *dev = find_device_state(id, errp);
if (dev != NULL) {
+ if (dev->pending_deleted_event) {
+ error_setg(errp, "Device %s is already in the "
+ "process of unplug", id);
+ return;
+ }
+
qdev_unplug(dev, errp);
}
}
+void hmp_device_add(Monitor *mon, const QDict *qdict)
+{
+ Error *err = NULL;
+
+ qmp_device_add((QDict *)qdict, NULL, &err);
+ hmp_handle_error(mon, err);
+}
+
+void hmp_device_del(Monitor *mon, const QDict *qdict)
+{
+ const char *id = qdict_get_str(qdict, "id");
+ Error *err = NULL;
+
+ qmp_device_del(id, &err);
+ hmp_handle_error(mon, err);
+}
+
BlockBackend *blk_by_qdev_id(const char *id, Error **errp)
{
DeviceState *dev;