Use the helper for machine_type_is_q35() to start out. The plan is to re-use the helper for a function checking which machine flags are supported for a given machine type.
Signed-off-by: Fiona Ebner <[email protected]> --- src/PVE/QemuServer/Machine.pm | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/PVE/QemuServer/Machine.pm b/src/PVE/QemuServer/Machine.pm index b2ff7e24..7a401087 100644 --- a/src/PVE/QemuServer/Machine.pm +++ b/src/PVE/QemuServer/Machine.pm @@ -142,11 +142,34 @@ sub assert_valid_machine_property { if $machine_conf->{'aw-bits'} && !$machine_conf->{viommu}; } +=head3 machine_base_type + + my $base_type = machine_base_type($machine_type); + +Returns the base type of the machine, currently either C<i440fx>, C<q35> or C<virt>. A value must be +passed in. Dies if the machine type cannot be determined, but should not happen if it is valid for +the C<$machine_fmt> schema. + +=cut + +my sub machine_base_type { + my ($machine_type) = @_; + + die "unable to determine machine base type - no value\n" if !$machine_type; + + return 'q35' if $machine_type =~ m/q35/; + return 'i440fx' if $machine_type =~ m/^pc/; + return 'virt' if $machine_type =~ m/^virt/; + + die "unable to determine machine base type '$machine_type'\n"; +} + sub machine_type_is_q35 { my ($conf) = @_; my $machine_conf = parse_machine($conf->{machine}); - return $machine_conf->{type} && ($machine_conf->{type} =~ m/q35/) ? 1 : 0; + return 0 if !$machine_conf || !$machine_conf->{type}; + return machine_base_type($machine_conf->{type}) eq 'q35' ? 1 : 0; } # In list context, also returns whether the current machine is deprecated or not. -- 2.47.3 _______________________________________________ pve-devel mailing list [email protected] https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
