On Sun, Nov 15, 2026 at 08:36:41PM +0800, 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; > > + > > /** > > * UserCreatableClass: > > * @parent_class: the base class > > @@ -242,4 +253,70 @@ bool target_specific_class_creatable(ObjectClass *oc); > > ObjectClass *target_specific_class_check(ObjectClass *oc, > > Error **errp); > > > > +/** > > + * AliasedClass > > + * @parent_class: the base class > > + * > > + * Interface for classes that want to declare they have aliases > > + * for their primary type name. > > + * > > + * While QOM type names are required to be unique, aliases allow > > + * for ambiguity across classes. The ambiguity is resolved at > > + * runtime based on system state, typically by the selection of > > + * a specific target. If ambiguity cannot be resolved, the user > > + * will need to use the unique QOM type name instead. > > + */ > > +struct AliasedClass { > > + InterfaceClass parent_class; > > + > > + const char *const *aliases; /* NULL terminated list of typenames */ > > > Hi Daniel, > I have a though that can we specify the target for each alias, so for example > "aarch64-virt" will pair with QEMU_ARCH_BIT(SYS_EMU_TARGET_AARCH64) > and > "arm-virt" will pair with QEMU_ARCH_BIT(SYS_EMU_TARGET_ARM), > so that when select name aarch64-virt, we will automatically infer the > QEMU_ARCH_BIT(SYS_EMU_TARGET_AARCH64) out.
I don't believe we need to distinguish aliases "arm-virt" and "aarch64-virt" - this series proposes just using "arm-virt" unconditionally. Likewise for the other targets where there is a 32/64 variant - eg this series adds 'riscv-virt' as the alias, not "riscv64-virt" or "riscv32-virt". With that, the list of aliases we need is fixed per machine class, and doesn't need to be associated directly with a subset of targets the machine is compatible with. > Also > "virt" will pair with QEMU_ARCH_ALL, this is for single-target binary. > So that the paired target can be either QEMU_ARCH_ALL or single > QEMU_ARCH_BIT(target_arch). > After this design, the TYPE_TARGET_SPECIFIC won't be needed anymore and > we can use machine names to select "target_arch" in an explicit way(As > each alias name is > mapped to explicit QEMU_ARCH_BIT(target_arch)). for QEMU_ARCH_ALL is > only work for single-target binary. > > And we can add some helper macro to generate the pair easily. 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 :|
