On 11/16/2026 1:53 PM, Daniel P. Berrangé wrote:
> On Sun, Nov 15, 2026 at 04:31:01PM +0100, BALATON Zoltan wrote:
>> On Sun, 15 Nov 2026, Yonggang Luo wrote:
>>> On Thu, Nov 12, 2026 at 9:31 PM Daniel P. Berrangé <[email protected]> 
>>> wrote:
>>>>
>>>> All QOM types must have a globally unique typename, however, for
>>>> user convenience, some might also want to have aliases which are
>>>> permitted to be ambiguous. Define an "Aliased" interface which
>>>> can be implemented by types which want to support aliases.
>>>>
>>>> When resolving an alias, if there are multiple QOM types with a
>>>> matching alias this is considered an error. Ambiguity can be
>>>> resolved by matching system state, with the selected target
>>>> being the currently implemented filter.
>>>>
>>>> Signed-off-by: Daniel P. Berrangé <[email protected]>
>>>> ---
>>>>  include/qom/object_interfaces.h | 77 +++++++++++++++++++++++++++++++++
>>>>  qom/object_interfaces.c         | 57 ++++++++++++++++++++++++
>>>>  2 files changed, 134 insertions(+)
>>>>
>>>> diff --git a/include/qom/object_interfaces.h 
>>>> b/include/qom/object_interfaces.h
>>>> index d222a3d7481..010e37d63f7 100644
>>>> --- a/include/qom/object_interfaces.h
>>>> +++ b/include/qom/object_interfaces.h
>>>> @@ -27,6 +27,17 @@ DECLARE_CLASS_CHECKERS(TargetSpecificClass, 
>>>> TARGET_SPECIFIC,
>>>>
>>>>  typedef struct TargetSpecific TargetSpecific;
>>>>
>>>> +#define TYPE_ALIASED "aliased"
>>>> +
>>>> +typedef struct AliasedClass AliasedClass;
>>>> +DECLARE_CLASS_CHECKERS(AliasedClass, ALIASED,
>>>> +                       TYPE_ALIASED)
>>>> +#define ALIASED(obj) \
>>>> +     INTERFACE_CHECK(Aliased, (obj), \
>>>> +                     TYPE_ALIASED)
>>>> +
>>>> +typedef struct Aliased Aliased;
>>
>> I wonder if it would be simpler to add the possibility to define aliases to
>> all QOM objects as standard instead of by an interface? This is useful for
>> other cases, it came up here too for example:
>> https://lists.nongnu.org/archive/html/qemu-ppc/2025-02/msg00113.html
>> Or maybe this could be done with this interface by common super classes
>> implementing it such as device and machine allowing aliases that commonly
>> need it to use it but then it would be quite widespread use to consider just
>> adding it to object right away which may also help interaction with arch.
>> Why separating it into an interface is better when we need it for most
>> objects?
> 
> We really don't need it for most objects. It is somewhat common for
> machine classes, just because we have many called 'virt', but even
> they are a minority of all machines. The number of places we might
> need it outside of machines will likely not exceed single digits.
> 
> The core QOM framework tries to be a fairly "pure" object model
> without QEMU specific aspects to its design. It is somewhat
> inspired by GObject, and I still rather regret that QEMU is not
> using GObject as it would have done everything we need and made
> life easier.
>

I guess QOM predated it?
I always thought QOM was made by secret C++ lovers who couldn't use the
language in QEMU.

> Stuff that starts to get QEMU specific is pushed into interfaces
> like UserCreatable, or abstract base classes like "Device". IMHO
> it is beneficial to retain this conceptual division, as it lets
> us understand the behaviour of QOM as a framework in isolation
> from the bulk of QEMU.
>

That seems like a good rationale about what to implement where. It's
more debatable about having an interface or a machine field though.
I personally like the interface concept for this, even though it comes
with extra verbosity.

> With regards,
> Daniel


Reply via email to