public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
	Markus Frank <m.frank@proxmox.com>
Subject: Re: [pve-devel] [PATCH qemu-server v6 1/4] feature #3784: Parameter for guest vIOMMU & machine as property-string
Date: Thu, 7 Sep 2023 09:57:09 +0200	[thread overview]
Message-ID: <199095f9-902e-0a32-897d-56eadb8a2eb4@proxmox.com> (raw)
In-Reply-To: <20230822124041.119554-2-m.frank@proxmox.com>

Am 22.08.23 um 14:40 schrieb Markus Frank:
> diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
> index bf1de17..013792d 100644
> --- a/PVE/QemuServer.pm
> +++ b/PVE/QemuServer.pm
> @@ -118,12 +118,32 @@ PVE::JSONSchema::register_standard_option('pve-qm-stateuri', {
>      optional => 1,
>  });
>  
> -PVE::JSONSchema::register_standard_option('pve-qemu-machine', {
> +my $machine_fmt = {
> +    type => {
> +	default_key => 1,
>  	description => "Specifies the QEMU machine type.",
>  	type => 'string',
>  	pattern => '(pc|pc(-i440fx)?-\d+(\.\d+)+(\+pve\d+)?(\.pxe)?|q35|pc-q35-\d+(\.\d+)+(\+pve\d+)?(\.pxe)?|virt(?:-\d+(\.\d+)+)?(\+pve\d+)?)',
>  	maxLength => 40,
> +	format_description => 'machine type',
>  	optional => 1,
> +    },
> +    viommu => {
> +	type => 'boolean',
> +	description => "Enable/disable guest vIOMMU"
> +	    ." (needs kvm to be enabled and q35 to be set as machine type).",
> +	default => 0,
> +	optional => 1,
> +    },
> +};
> +
> +PVE::JSONSchema::register_format('pve-qemu-machine-fmt', $machine_fmt);
> +
> +PVE::JSONSchema::register_standard_option('pve-qemu-machine', {
> +    description => "Specify the QEMU machine type & enable/disable vIOMMU.",
> +    type => 'string',
> +    optional => 1,
> +    format => PVE::JSONSchema::get_format('pve-qemu-machine-fmt'),
>  });
>  
>  # FIXME: remove in favor of just using the INotify one, it's cached there exactly the same way
> @@ -2133,6 +2153,31 @@ sub parse_watchdog {
>      return $res;
>  }
>  
> +sub parse_machine {
> +    my ($value) = @_;
> +
> +    return if !$value;
> +
> +    my $res = parse_property_string($machine_fmt, $value);
> +    return $res;
> +}
> +
> +sub check_machine_config {
> +    my ($conf, $machine_conf) = @_;
> +    my $q35 = $machine_conf->{type} && ($machine_conf->{type} =~ m/q35/) ? 1 : 0;
> +    my $kvm = $conf->{kvm};
> +    my $arch = get_vm_arch($conf);
> +    $kvm //= 1 if is_native($arch);
> +    if ($machine_conf->{viommu} && (!$kvm || !$q35)) {
> +	die "to use vIOMMU please enable kvm and set the machine type to q35\n";
> +    }
> +}
> +
> +sub print_machine {
> +    my ($machine_conf) = @_;
> +    return PVE::JSONSchema::print_property_string($machine_conf, $machine_fmt);
> +}
> +

Was there any reason why you didn't put the above, i.e. format
definition/parsing/printing in the QemuServer::Machine module instead
like I suggested in my review of v5?

> diff --git a/PVE/QemuServer/Machine.pm b/PVE/QemuServer/Machine.pm
> index d9429ed..bfbde59 100644
> --- a/PVE/QemuServer/Machine.pm
> +++ b/PVE/QemuServer/Machine.pm
> @@ -15,7 +15,8 @@ our $PVE_MACHINE_VERSION = {
>  sub machine_type_is_q35 {
>      my ($conf) = @_;
>  
> -    return $conf->{machine} && ($conf->{machine} =~ m/q35/) ? 1 : 0;
> +    my $machine_conf = PVE::QemuServer::parse_machine($conf->{machine});
> +    return $machine_conf->{type} && ($machine_conf->{type} =~ m/q35/) ? 1 : 0;
>  }
>  
>  sub current_from_query_machines {
> @@ -120,7 +121,8 @@ sub qemu_machine_pxe {
>  
>      my $machine =  get_current_qemu_machine($vmid);
>  
> -    if ($conf->{machine} && $conf->{machine} =~ m/\.pxe$/) {
> +    my $machine_conf = PVE::QemuServer::parse_machine($conf->{machine});
> +    if ($machine_conf->{type} && $machine_conf->{type} =~ m/\.pxe$/) {
>  	$machine .= '.pxe';
>      }
>  

Because there still are these cyclic calls back into the QemuServer
module (and you would need the cylcic use statement which is what we
want to avoid).




  parent reply	other threads:[~2023-09-07  7:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-22 12:40 [pve-devel] [PATCH qemu-server/docs/manager v6 0/4] vIOMMU-Feature #3784 Markus Frank
2023-08-22 12:40 ` [pve-devel] [PATCH qemu-server v6 1/4] feature #3784: Parameter for guest vIOMMU & machine as property-string Markus Frank
2023-09-07  7:47   ` Thomas Lamprecht
2023-09-07  7:57   ` Fiona Ebner [this message]
2023-08-22 12:40 ` [pve-devel] [PATCH qemu-server v6 2/4] tests: test-cases for new machine-syntax & viommu Markus Frank
2023-08-22 12:40 ` [pve-devel] [PATCH docs v6 3/4] add vIOMMU documentation Markus Frank
2023-08-22 12:40 ` [pve-devel] [PATCH manager v6 4/4] ui: MachineEdit with viommu checkbox Markus Frank

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199095f9-902e-0a32-897d-56eadb8a2eb4@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=m.frank@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal