From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 5AF0FA06E6 for ; Tue, 13 Jun 2023 14:43:57 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 33E1C2FD33 for ; Tue, 13 Jun 2023 14:43:27 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Tue, 13 Jun 2023 14:43:26 +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 4AC2844EEE for ; Tue, 13 Jun 2023 14:43:26 +0200 (CEST) Date: Tue, 13 Jun 2023 14:43:25 +0200 From: Wolfgang Bumiller To: Dominik Csapak Cc: pve-devel@lists.proxmox.com Message-ID: <54fazm2zlkmo2d7dxjnwbhgtsxxjnuk6djdxnwj5hltslv3pyd@57vglczjkw6o> References: <20230606135222.984747-1-d.csapak@proxmox.com> <20230606135222.984747-6-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230606135222.984747-6-d.csapak@proxmox.com> X-SPAM-LEVEL: Spam detection results: 0 AWL 0.126 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: Re: [pve-devel] [PATCH qemu-server v5 3/6] check_local_resources: extend for mapped resources X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Jun 2023 12:43:57 -0000 On Tue, Jun 06, 2023 at 03:52:04PM +0200, Dominik Csapak wrote: > by adding them to their own list, saving the nodes where > they are not allowed, and return those on 'wantarray' so we don't break > existing callers that don't expect it. > > Signed-off-by: Dominik Csapak > --- > PVE/QemuServer.pm | 43 ++++++++++++++++++++++++++++++++++-- > test/MigrationTest/Shared.pm | 14 ++++++++++++ > 2 files changed, 55 insertions(+), 2 deletions(-) > > diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm > index 2fd45f61..95bf4338 100644 > --- a/PVE/QemuServer.pm > +++ b/PVE/QemuServer.pm > @@ -34,6 +34,8 @@ use PVE::DataCenterConfig; > use PVE::Exception qw(raise raise_param_exc); > use PVE::Format qw(render_duration render_bytes); > use PVE::GuestHelpers qw(safe_string_ne safe_num_ne safe_boolean_ne); > +use PVE::Mapping::PCI; > +use PVE::Mapping::USB; > use PVE::INotify; > use PVE::JSONSchema qw(get_standard_option parse_property_string); > use PVE::ProcFSTools; > @@ -2704,6 +2706,28 @@ sub check_local_resources { > my ($conf, $noerr) = @_; > > my @loc_res = (); > + my $mapped_res = []; > + > + my $nodelist = PVE::Cluster::get_nodelist(); > + my $pci_map = PVE::Mapping::PCI::config(); > + my $usb_map = PVE::Mapping::USB::config(); > + > + my $not_allowed_nodes = { map { $_ => [] } @$nodelist }; Can we find a better name for this? This maps nodes to lists of conflicting config keys... $node_conflicts or even just $missing_devices?{,_by_node}? > + > + my $add_not_allowed_nodes = sub { $check_mapped_devices_on_nodes? > + my ($type, $key, $id) = @_; > + for my $node (@$nodelist) { > + my $entry; > + if ($type eq 'pci') { > + $entry = PVE::Mapping::PCI::get_node_mapping($pci_map, $id, $node); > + } elsif ($type eq 'usb') { > + $entry = PVE::Mapping::USB::get_node_mapping($usb_map, $id, $node); > + } > + if (!scalar($entry->@*)) { > + push @{$not_allowed_nodes->{$node}}, $key; > + } > + } > + }; > > push @loc_res, "hostusb" if $conf->{hostusb}; # old syntax > push @loc_res, "hostpci" if $conf->{hostpci}; # old syntax > @@ -2711,7 +2735,22 @@ sub check_local_resources { > push @loc_res, "ivshmem" if $conf->{ivshmem}; > > foreach my $k (keys %$conf) { > - next if $k =~ m/^usb/ && ($conf->{$k} =~ m/^spice(?![^,])/); > + if ($k =~ m/^usb/) { > + my $entry = parse_property_string($usb_fmt, $conf->{$k}); > + my $usb = PVE::QemuServer::USB::parse_usb_device($entry->{host}); > + next if $usb->{spice}; > + if ($usb->{mapped}) { > + $add_not_allowed_nodes->('usb', $k, $entry->{host}); > + push @$mapped_res, $k; > + } > + } > + if ($k =~ m/^hostpci/) { > + my $entry = parse_property_string('pve-qm-hostpci', $conf->{$k}); > + if ($entry->{host} !~ m/:/) { > + $add_not_allowed_nodes->('pci', $k, $entry->{host}); > + push @$mapped_res, $k; > + } > + } > # sockets are safe: they will recreated be on the target side post-migrate > next if $k =~ m/^serial/ && ($conf->{$k} eq 'socket'); > push @loc_res, $k if $k =~ m/^(usb|hostpci|serial|parallel)\d+$/; > @@ -2719,7 +2758,7 @@ sub check_local_resources { > > die "VM uses local resources\n" if scalar @loc_res && !$noerr; > > - return \@loc_res; > + return wantarray ? (\@loc_res, $mapped_res, $not_allowed_nodes) : \@loc_res; > } > > # check if used storages are available on all nodes (use by migrate) > diff --git a/test/MigrationTest/Shared.pm b/test/MigrationTest/Shared.pm > index bd4d20c0..aa7203d1 100644 > --- a/test/MigrationTest/Shared.pm > +++ b/test/MigrationTest/Shared.pm > @@ -76,6 +76,20 @@ $cluster_module->mock( > }, > ); > > +our $mapping_usb_module = Test::MockModule->new("PVE::Mapping::USB"); > +$mapping_usb_module->mock( > + config => sub { > + return {}; > + }, > +); > + > +our $mapping_pci_module = Test::MockModule->new("PVE::Mapping::PCI"); > +$mapping_pci_module->mock( > + config => sub { > + return {}; > + }, > +); > + > our $ha_config_module = Test::MockModule->new("PVE::HA::Config"); > $ha_config_module->mock( > vm_is_ha_managed => sub { > -- > 2.30.2