From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: "Mark Cave-Ayland" <mark.caveayland@nutanix.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
pbonzini@redhat.com, richard.henderson@linaro.org,
mst@redhat.com, mtosatti@redhat.com, qemu-devel@nongnu.org
Subject: Re: [PATCH v3 2/8] qom/object.c: introduce object_class_property_add_alias()
Date: Mon, 21 Sep 2026 10:06:49 +0100 [thread overview]
Message-ID: <arDzqatu3M17Nth8@redhat.com> (raw)
In-Reply-To: <875x03nd5s.fsf@pond.sub.org>
On Fri, Sep 18, 2026 at 11:04:31AM +0200, Markus Armbruster wrote:
> Mark Cave-Ayland <mark.caveayland@nutanix.com> writes:
>
> > On 17/09/2026 09:52, Marc-André Lureau wrote:
> >
> >> Hi
> >> On Wed, Sep 2, 2026 at 6:42 PM Mark Cave-Ayland
> >> <mark.caveayland@nutanix.com> wrote:
> >>>
> >>> This is eventually intended to be a replacement for object_property_add_alias()
> >>> which uses an object property instead of a class property.
> >>>
> >>> With the advent of class properties, it is possible that QOM may attempt to
> >>> set or retrieve the value of an unset alias property. Update the existing
> >>> property_get_alias() and property_set_alias() functions to use the null visitor
> >>> if the alias target has not been set, and property_resolve_alias() to return
> >>> NULL for the same case.
> >>>
> >>> This ensures that unset class alias properties accessed e.g. via the monitor do
> >>> not cause QEMU to crash.
> >>>
> >>> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
> >>> ---
> >>> include/qom/object.h | 25 +++++++++++
> >>> qom/object.c | 100 +++++++++++++++++++++++++++++++++++++------
> >>> 2 files changed, 113 insertions(+), 12 deletions(-)
> >>>
> >>> diff --git a/include/qom/object.h b/include/qom/object.h
> >>> index e24f0a2b2d..96c76975ef 100644
> >>> --- a/include/qom/object.h
> >>> +++ b/include/qom/object.h
> >>> @@ -2263,6 +2263,11 @@ ObjectProperty *object_class_static_property_add_uint64_ptr(ObjectClass *klass,
> >>> const uint64_t *v,
> >>> ObjectPropertyFlags flags);
> >>>
> >>> +typedef enum {
> >>> + /* private */
> >>> + OBJ_PROP_ALIAS_CLASS = 0x1,
> >>> +} ObjectPropertyAliasFlags;
> >>> +
> >>> /**
> >>> * object_property_add_alias:
> >>> * @obj: the object to add a property to
> >>> @@ -2283,6 +2288,26 @@ ObjectProperty *object_class_static_property_add_uint64_ptr(ObjectClass *klass,
> >>> ObjectProperty *object_property_add_alias(Object *obj, const char *name,
> >>> Object *target_obj, const char *target_name);
> >>>
> >>> +/**
> >>> + * object_class_property_add_alias:
> >>> + * @klass: the object class to add a property to
> >>> + * @name: the name of the property
> >>> + * @offset: the offset from the object instance where the object alias is
> >>> + * stored
> >>> + * @target_type: QOM type we expect the alias to resolve to
> >>> + * @target_name: the name of the property on the forwarded object
> >>> + *
> >>> + * Add an alias for a property on an object. This function will add a property
> >>> + * of the same type as the forwarded property.
> >>> + *
> >>> + * Returns: The newly added property on success, or %NULL on failure.
> >> actually, it assert() on error and never returns NULL.
> >
> > I was able to reproduce this by attempting to add a class alias property with the same name again, and then started to look at other related functions do to understand what the behaviour should be. There seems to be a number of existing issues here:
> >
> > - object_property_try_add() returns NULL in the case a property cannot
> > be created (which seems to be only when an attempt to make add a
> > property that already exists). However since object_property_add()
> > always passes &error_abort, then QEMU terminates immediately without
> > returning the NULL.
>
> Convention: when we have a pair of functions FOO_try_BAR() and
> FOO_BAR(), the former can fail and the latter cannot. The latter is
> useful when failure would be a programming error.
>
> When FOO_try_BAR() sets an Error on failure, FOO_BAR() is a thin wrapper
> that passes &error_abort.
>
> We pass &error_abort when failure would be a programming error. It's
> more concise than "call then assert it didn't fail". Concise is good.
>
> The wrapper makes calls that cannot fail even more concise. Worth
> having only when there are plenty of callers that profit from that.
> Someone decided this is the case for object_property_try_add() /
> object_property_add().
>
> > - object_class_property_add() will currently assert() if an attempt is
> > made to add a duplicate property: it is fairly trivial to update it to
> > return the same error that object_property_add() does, however it is
> > interesting to note that the kernel-doc states that
> > error_setg(&error_abort, ...) should NOT be used. However in this case
> > it appears to return a genuinely helpful message which I think is
> > worth keeping.
>
> The only difference between object_class_property_add() and
> object_property_add() should be where the property is recorded (class
> vs. object). In particular, they should treat failure the same way.
>
> This may make object_class_property_try_add() necessary.
IMHO such a method should not exist. A class must have a well-defined
set of properties that is invariant. Any scenario where a
object_class_property_try_add() method could fail would be 100%
repeatable and at the same time a significant programmer error.
When we had properties against objects 'try_add' was passable, as
we're dynamically adding props and different instances can have
different props, even when the same time. This is all a terrible
idea, and ideally object_property_try_add would not exist either
but it is probably more trouble than its worth right now to attempt
removing object_property_try_add. Just don't mirror it into class
properties.
With regards,
Daniel
--
|: https://berrange.com ~~ https://hachyderm.io/@berrange :|
|: https://libvirt.org ~~ https://entangle-photo.org :|
|: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
next prev parent reply other threads:[~2026-09-21 9:08 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 14:40 [PATCH v3 0/8] hw/i386: convert object props to class props Mark Cave-Ayland
2026-09-02 14:40 ` [PATCH v3 1/8] qom/object.c: introduce object_alias_get_targetp() lookup function Mark Cave-Ayland
2026-09-02 14:40 ` [PATCH v3 2/8] qom/object.c: introduce object_class_property_add_alias() Mark Cave-Ayland
2026-09-17 8:52 ` Marc-André Lureau
2026-09-18 8:38 ` Mark Cave-Ayland
2026-09-18 9:04 ` Markus Armbruster
2026-09-21 9:06 ` Daniel P. Berrangé [this message]
2026-09-21 13:28 ` Markus Armbruster
2026-09-02 14:40 ` [PATCH v3 3/8] qom/object.c: introduce object_property_set_alias() function Mark Cave-Ayland
2026-09-02 14:40 ` [PATCH v3 4/8] hw/i386/pc.c: convert pcspk-audiodev object prop to a class prop Mark Cave-Ayland
2026-09-02 21:08 ` Philippe Mathieu-Daudé
2026-09-02 14:40 ` [PATCH v3 5/8] hw/i386/pc.c: convert rtc-time " Mark Cave-Ayland
2026-09-02 14:40 ` [PATCH v3 6/8] hw/i386/pc.c: convert PC_MACHINE_ACPI_DEVICE_PROP from object prop to " Mark Cave-Ayland
2026-09-02 14:40 ` [PATCH v3 7/8] hw/i386/pc_sysfw.c: convert pflash0 and pflash1 object props to class props Mark Cave-Ayland
2026-09-02 14:40 ` [PATCH v3 8/8] hw/i386/sgx-epc.c: convert SGX_EPC_SIZE_PROP object prop to class prop Mark Cave-Ayland
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=arDzqatu3M17Nth8@redhat.com \
--to=berrange@redhat.com \
--cc=armbru@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mark.caveayland@nutanix.com \
--cc=mst@redhat.com \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.