mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-05 00:33:55 -06:00
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with the same name already exists. Since our property names are all hardcoded, failure is a programming error, and the appropriate way to handle it is passing &error_abort. Same for its variants, except for object_property_add_child(), which additionally fails when the child already has a parent. Parentage is also under program control, so this is a programming error, too. We have a bit over 500 callers. Almost half of them pass &error_abort, slightly fewer ignore errors, one test case handles errors, and the remaining few callers pass them to their own callers. The previous few commits demonstrated once again that ignoring programming errors is a bad idea. Of the few ones that pass on errors, several violate the Error API. The Error ** argument must be NULL, &error_abort, &error_fatal, or a pointer to a variable containing NULL. Passing an argument of the latter kind twice without clearing it in between is wrong: if the first call sets an error, it no longer points to NULL for the second call. ich9_pm_add_properties(), sparc32_ledma_realize(), sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize() are wrong that way. When the one appropriate choice of argument is &error_abort, letting users pick the argument is a bad idea. Drop parameter @errp and assert the preconditions instead. There's one exception to "duplicate property name is a programming error": the way object_property_add() implements the magic (and undocumented) "automatic arrayification". Don't drop @errp there. Instead, rename object_property_add() to object_property_try_add(), and add the obvious wrapper object_property_add(). Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Message-Id: <20200505152926.18877-15-armbru@redhat.com> [Two semantic rebase conflicts resolved]
This commit is contained in:
parent
9f742c28f5
commit
d2623129a7
192 changed files with 650 additions and 994 deletions
|
@ -340,8 +340,7 @@ static void cryptodev_vhost_user_instance_int(Object *obj)
|
|||
{
|
||||
object_property_add_str(obj, "chardev",
|
||||
cryptodev_vhost_user_get_chardev,
|
||||
cryptodev_vhost_user_set_chardev,
|
||||
NULL);
|
||||
cryptodev_vhost_user_set_chardev);
|
||||
}
|
||||
|
||||
static void cryptodev_vhost_user_finalize(Object *obj)
|
||||
|
|
|
@ -213,7 +213,7 @@ static void cryptodev_backend_instance_init(Object *obj)
|
|||
object_property_add(obj, "queues", "uint32",
|
||||
cryptodev_backend_get_queues,
|
||||
cryptodev_backend_set_queues,
|
||||
NULL, NULL, NULL);
|
||||
NULL, NULL);
|
||||
/* Initialize devices' queues property to 1 */
|
||||
object_property_set_int(obj, 1, "queues", NULL);
|
||||
}
|
||||
|
|
|
@ -481,11 +481,9 @@ dbus_vmstate_class_init(ObjectClass *oc, void *data)
|
|||
vc->get_id = dbus_vmstate_get_id;
|
||||
|
||||
object_class_property_add_str(oc, "addr",
|
||||
get_dbus_addr, set_dbus_addr,
|
||||
&error_abort);
|
||||
get_dbus_addr, set_dbus_addr);
|
||||
object_class_property_add_str(oc, "id-list",
|
||||
get_id_list, set_id_list,
|
||||
&error_abort);
|
||||
get_id_list, set_id_list);
|
||||
}
|
||||
|
||||
static const TypeInfo dbus_vmstate_info = {
|
||||
|
|
|
@ -184,18 +184,15 @@ file_backend_class_init(ObjectClass *oc, void *data)
|
|||
oc->unparent = file_backend_unparent;
|
||||
|
||||
object_class_property_add_bool(oc, "discard-data",
|
||||
file_memory_backend_get_discard_data, file_memory_backend_set_discard_data,
|
||||
&error_abort);
|
||||
file_memory_backend_get_discard_data, file_memory_backend_set_discard_data);
|
||||
object_class_property_add_str(oc, "mem-path",
|
||||
get_mem_path, set_mem_path,
|
||||
&error_abort);
|
||||
get_mem_path, set_mem_path);
|
||||
object_class_property_add(oc, "align", "int",
|
||||
file_memory_backend_get_align,
|
||||
file_memory_backend_set_align,
|
||||
NULL, NULL, &error_abort);
|
||||
NULL, NULL);
|
||||
object_class_property_add_bool(oc, "pmem",
|
||||
file_memory_backend_get_pmem, file_memory_backend_set_pmem,
|
||||
&error_abort);
|
||||
file_memory_backend_get_pmem, file_memory_backend_set_pmem);
|
||||
}
|
||||
|
||||
static void file_backend_instance_finalize(Object *o)
|
||||
|
|
|
@ -141,21 +141,19 @@ memfd_backend_class_init(ObjectClass *oc, void *data)
|
|||
if (qemu_memfd_check(MFD_HUGETLB)) {
|
||||
object_class_property_add_bool(oc, "hugetlb",
|
||||
memfd_backend_get_hugetlb,
|
||||
memfd_backend_set_hugetlb,
|
||||
&error_abort);
|
||||
memfd_backend_set_hugetlb);
|
||||
object_class_property_set_description(oc, "hugetlb",
|
||||
"Use huge pages");
|
||||
object_class_property_add(oc, "hugetlbsize", "int",
|
||||
memfd_backend_get_hugetlbsize,
|
||||
memfd_backend_set_hugetlbsize,
|
||||
NULL, NULL, &error_abort);
|
||||
NULL, NULL);
|
||||
object_class_property_set_description(oc, "hugetlbsize",
|
||||
"Huge pages size (ex: 2M, 1G)");
|
||||
}
|
||||
object_class_property_add_bool(oc, "seal",
|
||||
memfd_backend_get_seal,
|
||||
memfd_backend_set_seal,
|
||||
&error_abort);
|
||||
memfd_backend_set_seal);
|
||||
object_class_property_set_description(oc, "seal",
|
||||
"Seal growing & shrinking");
|
||||
}
|
||||
|
|
|
@ -463,51 +463,50 @@ host_memory_backend_class_init(ObjectClass *oc, void *data)
|
|||
|
||||
object_class_property_add_bool(oc, "merge",
|
||||
host_memory_backend_get_merge,
|
||||
host_memory_backend_set_merge, &error_abort);
|
||||
host_memory_backend_set_merge);
|
||||
object_class_property_set_description(oc, "merge",
|
||||
"Mark memory as mergeable");
|
||||
object_class_property_add_bool(oc, "dump",
|
||||
host_memory_backend_get_dump,
|
||||
host_memory_backend_set_dump, &error_abort);
|
||||
host_memory_backend_set_dump);
|
||||
object_class_property_set_description(oc, "dump",
|
||||
"Set to 'off' to exclude from core dump");
|
||||
object_class_property_add_bool(oc, "prealloc",
|
||||
host_memory_backend_get_prealloc,
|
||||
host_memory_backend_set_prealloc, &error_abort);
|
||||
host_memory_backend_set_prealloc);
|
||||
object_class_property_set_description(oc, "prealloc",
|
||||
"Preallocate memory");
|
||||
object_class_property_add(oc, "prealloc-threads", "int",
|
||||
host_memory_backend_get_prealloc_threads,
|
||||
host_memory_backend_set_prealloc_threads,
|
||||
NULL, NULL, &error_abort);
|
||||
NULL, NULL);
|
||||
object_class_property_set_description(oc, "prealloc-threads",
|
||||
"Number of CPU threads to use for prealloc");
|
||||
object_class_property_add(oc, "size", "int",
|
||||
host_memory_backend_get_size,
|
||||
host_memory_backend_set_size,
|
||||
NULL, NULL, &error_abort);
|
||||
NULL, NULL);
|
||||
object_class_property_set_description(oc, "size",
|
||||
"Size of the memory region (ex: 500M)");
|
||||
object_class_property_add(oc, "host-nodes", "int",
|
||||
host_memory_backend_get_host_nodes,
|
||||
host_memory_backend_set_host_nodes,
|
||||
NULL, NULL, &error_abort);
|
||||
NULL, NULL);
|
||||
object_class_property_set_description(oc, "host-nodes",
|
||||
"Binds memory to the list of NUMA host nodes");
|
||||
object_class_property_add_enum(oc, "policy", "HostMemPolicy",
|
||||
&HostMemPolicy_lookup,
|
||||
host_memory_backend_get_policy,
|
||||
host_memory_backend_set_policy, &error_abort);
|
||||
host_memory_backend_set_policy);
|
||||
object_class_property_set_description(oc, "policy",
|
||||
"Set the NUMA policy");
|
||||
object_class_property_add_bool(oc, "share",
|
||||
host_memory_backend_get_share, host_memory_backend_set_share,
|
||||
&error_abort);
|
||||
host_memory_backend_get_share, host_memory_backend_set_share);
|
||||
object_class_property_set_description(oc, "share",
|
||||
"Mark the memory as private to QEMU or shared");
|
||||
object_class_property_add_bool(oc, "x-use-canonical-path-for-ramblock-id",
|
||||
host_memory_backend_get_use_canonical_path,
|
||||
host_memory_backend_set_use_canonical_path, &error_abort);
|
||||
host_memory_backend_set_use_canonical_path);
|
||||
}
|
||||
|
||||
static const TypeInfo host_memory_backend_info = {
|
||||
|
|
|
@ -138,8 +138,7 @@ static char *rng_egd_get_chardev(Object *obj, Error **errp)
|
|||
static void rng_egd_init(Object *obj)
|
||||
{
|
||||
object_property_add_str(obj, "chardev",
|
||||
rng_egd_get_chardev, rng_egd_set_chardev,
|
||||
NULL);
|
||||
rng_egd_get_chardev, rng_egd_set_chardev);
|
||||
}
|
||||
|
||||
static void rng_egd_finalize(Object *obj)
|
||||
|
|
|
@ -110,8 +110,7 @@ static void rng_random_init(Object *obj)
|
|||
|
||||
object_property_add_str(obj, "filename",
|
||||
rng_random_get_filename,
|
||||
rng_random_set_filename,
|
||||
NULL);
|
||||
rng_random_set_filename);
|
||||
|
||||
s->filename = g_strdup("/dev/urandom");
|
||||
s->fd = -1;
|
||||
|
|
|
@ -108,8 +108,7 @@ static void rng_backend_init(Object *obj)
|
|||
|
||||
object_property_add_bool(obj, "opened",
|
||||
rng_backend_prop_get_opened,
|
||||
rng_backend_prop_set_opened,
|
||||
NULL);
|
||||
rng_backend_prop_set_opened);
|
||||
}
|
||||
|
||||
static void rng_backend_finalize(Object *obj)
|
||||
|
|
|
@ -177,7 +177,7 @@ static char *get_chardev(Object *obj, Error **errp)
|
|||
|
||||
static void vhost_user_backend_init(Object *obj)
|
||||
{
|
||||
object_property_add_str(obj, "chardev", get_chardev, set_chardev, NULL);
|
||||
object_property_add_str(obj, "chardev", get_chardev, set_chardev);
|
||||
}
|
||||
|
||||
static void vhost_user_backend_finalize(Object *obj)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue