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:
Markus Armbruster
2020-05-15 07:07:58 +02:00
parent 9f742c28f5
commit d2623129a7
192 changed files with 650 additions and 994 deletions
+2 -2
View File
@@ -3111,13 +3111,13 @@ static void kvm_accel_class_init(ObjectClass *oc, void *data)
object_class_property_add(oc, "kernel-irqchip", "on|off|split",
NULL, kvm_set_kernel_irqchip,
NULL, NULL, &error_abort);
NULL, NULL);
object_class_property_set_description(oc, "kernel-irqchip",
"Configure KVM in-kernel irqchip");
object_class_property_add(oc, "kvm-shadow-mem", "int",
kvm_get_kvm_shadow_mem, kvm_set_kvm_shadow_mem,
NULL, NULL, &error_abort);
NULL, NULL);
object_class_property_set_description(oc, "kvm-shadow-mem",
"KVM shadow MMU size");
}
+2 -3
View File
@@ -203,12 +203,11 @@ static void tcg_accel_class_init(ObjectClass *oc, void *data)
object_class_property_add_str(oc, "thread",
tcg_get_thread,
tcg_set_thread,
NULL);
tcg_set_thread);
object_class_property_add(oc, "tb-size", "int",
tcg_get_tb_size, tcg_set_tb_size,
NULL, NULL, &error_abort);
NULL, NULL);
object_class_property_set_description(oc, "tb-size",
"TCG translation block cache size");
+2 -3
View File
@@ -124,13 +124,12 @@ qauthz_list_class_init(ObjectClass *oc, void *data)
"QAuthZListPolicy",
&QAuthZListPolicy_lookup,
qauthz_list_prop_get_policy,
qauthz_list_prop_set_policy,
NULL);
qauthz_list_prop_set_policy);
object_class_property_add(oc, "rules", "QAuthZListRule",
qauthz_list_prop_get_rules,
qauthz_list_prop_set_rules,
NULL, NULL, NULL);
NULL, NULL);
authz->is_allowed = qauthz_list_is_allowed;
}
+2 -4
View File
@@ -221,12 +221,10 @@ qauthz_list_file_class_init(ObjectClass *oc, void *data)
object_class_property_add_str(oc, "filename",
qauthz_list_file_prop_get_filename,
qauthz_list_file_prop_set_filename,
NULL);
qauthz_list_file_prop_set_filename);
object_class_property_add_bool(oc, "refresh",
qauthz_list_file_prop_get_refresh,
qauthz_list_file_prop_set_refresh,
NULL);
qauthz_list_file_prop_set_refresh);
authz->is_allowed = qauthz_list_file_is_allowed;
}
+1 -2
View File
@@ -107,8 +107,7 @@ qauthz_pam_class_init(ObjectClass *oc, void *data)
object_class_property_add_str(oc, "service",
qauthz_pam_prop_get_service,
qauthz_pam_prop_set_service,
NULL);
qauthz_pam_prop_set_service);
}
+1 -2
View File
@@ -74,8 +74,7 @@ qauthz_simple_class_init(ObjectClass *oc, void *data)
object_class_property_add_str(oc, "identity",
qauthz_simple_prop_get_identity,
qauthz_simple_prop_set_identity,
NULL);
qauthz_simple_prop_set_identity);
}
+1 -2
View File
@@ -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)
+1 -1
View File
@@ -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);
}
+2 -4
View File
@@ -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 = {
+4 -7
View File
@@ -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)
+3 -5
View File
@@ -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");
}
+9 -10
View File
@@ -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 = {
+1 -2
View File
@@ -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)
+1 -2
View File
@@ -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;
+1 -2
View File
@@ -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)
+1 -1
View File
@@ -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)
+2 -4
View File
@@ -954,8 +954,7 @@ static void throttle_group_obj_class_init(ObjectClass *klass, void *class_data)
"int",
throttle_group_get,
throttle_group_set,
NULL, &properties[i],
&error_abort);
NULL, &properties[i]);
}
/* ThrottleLimits */
@@ -963,8 +962,7 @@ static void throttle_group_obj_class_init(ObjectClass *klass, void *class_data)
"limits", "ThrottleLimits",
throttle_group_get_limits,
throttle_group_set_limits,
NULL, NULL,
&error_abort);
NULL, NULL);
}
static const TypeInfo throttle_group_info = {
+1 -7
View File
@@ -329,7 +329,6 @@ void device_add_bootindex_property(Object *obj, int32_t *bootindex,
const char *name, const char *suffix,
DeviceState *dev, Error **errp)
{
Error *local_err = NULL;
BootIndexProperty *prop = g_malloc0(sizeof(*prop));
prop->bootindex = bootindex;
@@ -340,13 +339,8 @@ void device_add_bootindex_property(Object *obj, int32_t *bootindex,
device_get_bootindex,
device_set_bootindex,
property_release_bootindex,
prop, &local_err);
prop);
if (local_err) {
error_propagate(errp, local_err);
g_free(prop);
return;
}
/* initialize devices' bootindex property to -1 */
object_property_set_int(obj, -1, name, NULL);
}
+2 -2
View File
@@ -1489,10 +1489,10 @@ static void char_socket_class_init(ObjectClass *oc, void *data)
object_class_property_add(oc, "addr", "SocketAddress",
char_socket_get_addr, NULL,
NULL, NULL, &error_abort);
NULL, NULL);
object_class_property_add_bool(oc, "connected", char_socket_get_connected,
NULL, &error_abort);
NULL);
}
static const TypeInfo char_socket_type_info = {
+2 -5
View File
@@ -986,10 +986,7 @@ static Chardev *chardev_new(const char *id, const char *typename,
}
if (id) {
object_property_add_child(get_chardevs_root(), id, obj, &local_err);
if (local_err) {
goto end;
}
object_property_add_child(get_chardevs_root(), id, obj);
object_unref(obj);
}
@@ -1116,7 +1113,7 @@ ChardevReturn *qmp_chardev_change(const char *id, ChardevBackend *backend,
object_unparent(OBJECT(chr));
object_property_add_child(get_chardevs_root(), chr_new->label,
OBJECT(chr_new), &error_abort);
OBJECT(chr_new));
object_unref(OBJECT(chr_new));
ret = g_new0(ChardevReturn, 1);

Some files were not shown because too many files have changed in this diff Show More