freenode
Databases & Infrastructure

QEMU moves to unique machine types for multi-target builds

Daniel Berrangé's series renames colliding 'virt' machines and adds aliases so one binary can expose every target without hiding types at runtime.

QEMU cannot link several CPU targets into one binary until its object model stops registering the same type name more than once. Daniel Berrangé has posted a large series that treats that uniqueness as a general requirement, not only a packaging problem, so management software can see one unambiguous model no matter which targets are compiled in.

The sharpest collision is historical. Several targets each ship a machine users know as virt, and each registers a distinct QOM type also called virt-machine. Those names cannot coexist in a single process. Berrangé's approach keeps the short name users type, but only as an alias. The primary type becomes target-specific, such as a name derived from the architecture plus virt. A new Aliased interface records those extra names. A TargetSpecific interface records which architectures a type may actually be created on.

That split is what makes a multi-target binary useful to libvirt and similar tools. Introspection of QEMU is expensive because the type graph is huge. Filtering classes out at startup, then repeating the query once per target, would throw that cost away. With every compiled-in type registered, and filtering deferred until a machine is queried or created, one pass with the none machine can list the full set. query-machines is extended to report aliases and the targets each machine supports. Creation is refused when the selected target does not match.

On the QEMU development list, Markus Armbruster and Pierrick Bouvier pressed Berrangé on whether that targets list should be omitted from today's single-target binaries. Berrangé had hidden it when a target is already selected, calling it odd to advertise aarch64 from qemu-system-arm. He later called that a weak reason: reporting the field always is functionally fine. Bouvier argued the opposite of hiding it. QAPI has been moving toward exposing the same details in every binary, and a split between qemu-system and qemu-system-x is not obviously desirable. Bouvier also suggested that once every machine is tagged, an unset target mask should simply be forbidden. Berrangé agreed, correcting his own description: the none machine should be marked valid for every architecture, not left blank.

The series also fixes a related accelerator-CPU hierarchy whose parent type name changed with the selected target, so subclasses from other targets would otherwise lose their parent when linked together. Bouvier has reviewed much of the work, while still questioning whether machine-definition macros are worth the complexity they add.