From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <f.gruenbichler@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 2AA9C5BC86
 for <pve-devel@pve.proxmox.com>; Wed,  8 Jul 2020 10:36:27 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 1BAE42E426
 for <pve-devel@pve.proxmox.com>; Wed,  8 Jul 2020 10:36:27 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [212.186.127.180])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 23D472E41A
 for <pve-devel@pve.proxmox.com>; Wed,  8 Jul 2020 10:36:25 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 5AA1642109
 for <pve-devel@pve.proxmox.com>; Wed,  8 Jul 2020 10:29:44 +0200 (CEST)
Date: Wed, 08 Jul 2020 10:29:37 +0200
From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= <f.gruenbichler@proxmox.com>
To: PVE development discussion <pve-devel@pve.proxmox.com>
References: <20200625113541.16684-1-s.reiter@proxmox.com>
 <20200625113541.16684-4-s.reiter@proxmox.com>
 <1594028311.osgnixtap1.astroid@nora.none>
In-Reply-To: <1594028311.osgnixtap1.astroid@nora.none>
MIME-Version: 1.0
User-Agent: astroid/0.15.0 (https://github.com/astroidmail/astroid)
Message-Id: <1594196946.lvlrvnum7g.astroid@nora.none>
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.200 Adjusted score from AWL reputation of From: address
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 RCVD_IN_DNSWL_MED        -2.3 Sender listed at https://www.dnswl.org/,
 medium trust
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [proxmox.com, cpuconfig.pm]
Subject: [pve-devel] applied: [PATCH v3 qemu-server 3/3] fix #2671: include
 CPU format in man page again
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Wed, 08 Jul 2020 08:36:27 -0000

On July 6, 2020 11:38 am, Fabian Gr=C3=BCnbichler wrote:
> this looks good, waiting for pve-common bump before applying this with a=20
> versioned dependency.

done now ;)

>=20
> On June 25, 2020 1:35 pm, Stefan Reiter wrote:
>> Use the new register_format(3) call to use a validator (instead of a
>> parser) for 'pve-(vm-)?cpu-conf'. This way the $cpu_fmt hash can be used=
 for
>> generating the documentation, while still applying the same verification
>> rules as before.
>>=20
>> Since the function no longer parses but only verifies, the parsing in
>> print_cpu_device/get_cpu_options has to go via JSONSchema directly.
>>=20
>> Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
>> ---
>>  PVE/QemuServer/CPUConfig.pm | 56 ++++++++++++-------------------------
>>  1 file changed, 18 insertions(+), 38 deletions(-)
>>=20
>> diff --git a/PVE/QemuServer/CPUConfig.pm b/PVE/QemuServer/CPUConfig.pm
>> index 6250591..8ed898c 100644
>> --- a/PVE/QemuServer/CPUConfig.pm
>> +++ b/PVE/QemuServer/CPUConfig.pm
>> @@ -153,6 +153,7 @@ my $cpu_fmt =3D {
>>      'phys-bits' =3D> {
>>  	type =3D> 'string',
>>  	format =3D> 'pve-phys-bits',
>> +	format_description =3D> '8-64|host',
>>  	description =3D> "The physical memory address bits that are reported t=
o"
>>  		     . " the guest OS. Should be smaller or equal to the host's."
>>  		     . " Set to 'host' to use value from host CPU, but note that"
>> @@ -182,57 +183,36 @@ sub parse_phys_bits {
>> =20
>>  # $cpu_fmt describes both the CPU config passed as part of a VM config,=
 as well
>>  # as the definition of a custom CPU model. There are some slight differ=
ences
>> -# though, which we catch in the custom verification function below.
>> -PVE::JSONSchema::register_format('pve-cpu-conf', \&parse_cpu_conf_basic=
);
>> -sub parse_cpu_conf_basic {
>> -    my ($cpu_str, $noerr) =3D @_;
>> -
>> -    my $cpu =3D eval { PVE::JSONSchema::parse_property_string($cpu_fmt,=
 $cpu_str) };
>> -    if ($@) {
>> -        die $@ if !$noerr;
>> -        return undef;
>> -    }
>> +# though, which we catch in the custom validation functions below.
>> +PVE::JSONSchema::register_format('pve-cpu-conf', $cpu_fmt, \&validate_c=
pu_conf);
>> +sub validate_cpu_conf {
>> +    my ($cpu) =3D @_;
>> =20
>>      # required, but can't be forced in schema since it's encoded in sec=
tion
>>      # header for custom models
>> -    if (!$cpu->{cputype}) {
>> -	die "CPU is missing cputype\n" if !$noerr;
>> -	return undef;
>> -    }
>> -
>> -    return $cpu;
>> +    die "CPU is missing cputype\n" if !$cpu->{cputype};
>>  }
>> +PVE::JSONSchema::register_format('pve-vm-cpu-conf', $cpu_fmt, \&validat=
e_vm_cpu_conf);
>> +sub validate_vm_cpu_conf {
>> +    my ($cpu) =3D @_;
>> =20
>> -PVE::JSONSchema::register_format('pve-vm-cpu-conf', \&parse_vm_cpu_conf=
);
>> -sub parse_vm_cpu_conf {
>> -    my ($cpu_str, $noerr) =3D @_;
>> -
>> -    my $cpu =3D parse_cpu_conf_basic($cpu_str, $noerr);
>> -    return undef if !$cpu;
>> +    validate_cpu_conf($cpu);
>> =20
>>      my $cputype =3D $cpu->{cputype};
>> =20
>>      # a VM-specific config is only valid if the cputype exists
>>      if (is_custom_model($cputype)) {
>> -	eval { get_custom_model($cputype); };
>> -	if ($@) {
>> -	    die $@ if !$noerr;
>> -	    return undef;
>> -	}
>> +	# dies on unknown model
>> +	get_custom_model($cputype);
>>      } else {
>> -	if (!defined($cpu_vendor_list->{$cputype})) {
>> -	    die "Built-in cputype '$cputype' is not defined (missing 'custom-'=
 prefix?)\n" if !$noerr;
>> -	    return undef;
>> -	}
>> +	die "Built-in cputype '$cputype' is not defined (missing 'custom-' pre=
fix?)\n"
>> +	    if !defined($cpu_vendor_list->{$cputype});
>>      }
>> =20
>>      # in a VM-specific config, certain properties are limited/forbidden
>> =20
>> -    if ($cpu->{flags} && $cpu->{flags} !~ m/$cpu_flag_supported_re(;$cp=
u_flag_supported_re)*/) {
>> -	die "VM-specific CPU flags must be a subset of: @{[join(', ', @support=
ed_cpu_flags)]}\n"
>> -	    if !$noerr;
>> -	return undef;
>> -    }
>> +    die "VM-specific CPU flags must be a subset of: @{[join(', ', @supp=
orted_cpu_flags)]}\n"
>> +	if ($cpu->{flags} && $cpu->{flags} !~ m/$cpu_flag_supported_re(;$cpu_f=
lag_supported_re)*/);
>> =20
>>      die "Property 'reported-model' not allowed in VM-specific CPU confi=
g.\n"
>>  	if defined($cpu->{'reported-model'});
>> @@ -369,7 +349,7 @@ sub print_cpu_device {
>>      my $kvm =3D $conf->{kvm} // 1;
>>      my $cpu =3D $kvm ? "kvm64" : "qemu64";
>>      if (my $cputype =3D $conf->{cpu}) {
>> -	my $cpuconf =3D parse_cpu_conf_basic($cputype)
>> +	my $cpuconf =3D PVE::JSONSchema::parse_property_string('pve-vm-cpu-con=
f', $cputype)
>>  	    or die "Cannot parse cpu description: $cputype\n";
>>  	$cpu =3D $cpuconf->{cputype};
>> =20
>> @@ -481,7 +461,7 @@ sub get_cpu_options {
>>      my $custom_cpu;
>>      my $hv_vendor_id;
>>      if (my $cpu_prop_str =3D $conf->{cpu}) {
>> -	$cpu =3D parse_vm_cpu_conf($cpu_prop_str)
>> +	$cpu =3D PVE::JSONSchema::parse_property_string('pve-vm-cpu-conf', $cp=
u_prop_str)
>>  	    or die "Cannot parse cpu description: $cpu_prop_str\n";
>> =20
>>  	$cputype =3D $cpu->{cputype};
>> --=20
>> 2.20.1
>>=20
>>=20
>> _______________________________________________
>> pve-devel mailing list
>> pve-devel@pve.proxmox.com
>> https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
>>=20
>>=20
>=20
=