On Mon, 16 Nov 2026, Pierrick Bouvier wrote:
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 think it does not but GObject was fairly new at the time and maybe QEMU
wanted to stay independent and not affected by changes in other project.
But this was before I started following QEMU so I'm not sure about 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.
We may need it later in devices if we resurrect the linked idea (which I'd
like to try eventually) so it should either be in QOM Object or an
interface that Device or its sub classes can implement and not only
machines. I only thought that it may be less boiler plate and maybe
simpler implementation if it's not an interface but just adding another
hash table similar to the one storing type names or even allowing multiple
names for same objects within QOM and then it would be easier to search
for objects by alias that way, but if it works with an interface I don't
mind much.
Regards,
BALATON Zoltan