public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH qemu-server v7 4/7] check_local_resources: extend for mapped resources
Date: Fri, 16 Jun 2023 15:05:24 +0200	[thread overview]
Message-ID: <20230616130542.199182-5-d.csapak@proxmox.com> (raw)
In-Reply-To: <20230616130542.199182-1-d.csapak@proxmox.com>

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 <d.csapak@proxmox.com>
---
changes from v6:
* adapted to split into mapping property
 PVE/QemuServer.pm            | 42 ++++++++++++++++++++++++++++++++++--
 test/MigrationTest/Shared.pm | 14 ++++++++++++
 2 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index eebc4b6b..940cdacd 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;
@@ -2650,6 +2652,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 $missing_mappings_by_node = { map { $_ => [] } @$nodelist };
+
+    my $add_missing_mapping = sub {
+	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 @{$missing_mappings_by_node->{$node}}, $key;
+	    }
+	}
+    };
 
     push @loc_res, "hostusb" if $conf->{hostusb}; # old syntax
     push @loc_res, "hostpci" if $conf->{hostpci}; # old syntax
@@ -2657,7 +2681,21 @@ 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('pve-qm-usb', $conf->{$k});
+	    next if $entry->{host} =~ m/^spice$/i;
+	    if ($entry->{mapping}) {
+		$add_missing_mapping->('usb', $k, $entry->{mapping});
+		push @$mapped_res, $k;
+	    }
+	}
+	if ($k =~ m/^hostpci/) {
+	    my $entry = parse_property_string('pve-qm-hostpci', $conf->{$k});
+	    if ($entry->{mapping}) {
+		$add_missing_mapping->('pci', $k, $entry->{mapping});
+		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+$/;
@@ -2665,7 +2703,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, $missing_mappings_by_node) : \@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





  parent reply	other threads:[~2023-06-16 13:05 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-16 13:05 [pve-devel] [PATCH qemu-server/manager/docs v7] cluster mapping Dominik Csapak
2023-06-16 13:05 ` [pve-devel] [PATCH qemu-server v7 1/7] usb: refactor usb code and move some into USB module Dominik Csapak
2023-06-16 13:05 ` [pve-devel] [PATCH qemu-server v7 2/7] enable cluster mapped USB devices for guests Dominik Csapak
2023-06-16 13:05 ` [pve-devel] [PATCH qemu-server v7 3/7] enable cluster mapped PCI " Dominik Csapak
2023-06-16 13:05 ` Dominik Csapak [this message]
2023-06-16 13:05 ` [pve-devel] [PATCH qemu-server v7 5/7] api: migrate preconditions: use new check_local_resources info Dominik Csapak
2023-06-16 13:05 ` [pve-devel] [PATCH qemu-server v7 6/7] migration: check for mapped resources Dominik Csapak
2023-06-16 13:05 ` [pve-devel] [PATCH qemu-server v7 7/7] add test for mapped pci devices Dominik Csapak
2023-06-16 13:05 ` [pve-devel] [PATCH manager v7 01/14] api: add resource map api endpoints for PCI and USB Dominik Csapak
2023-06-16 13:05 ` [pve-devel] [PATCH manager v7 02/14] ui: parser: add helper for lists of property strings Dominik Csapak
2023-06-16 13:05 ` [pve-devel] [PATCH manager v7 03/14] ui: form/USBSelector: make it more flexible with nodename Dominik Csapak
2023-06-16 13:05 ` [pve-devel] [PATCH manager v7 04/14] ui: form: add PCIMapSelector Dominik Csapak
2023-06-16 13:05 ` [pve-devel] [PATCH manager v7 05/14] ui: form: add USBMapSelector Dominik Csapak
2023-06-16 13:05 ` [pve-devel] [PATCH manager v7 06/14] ui: qemu/PCIEdit: rework panel to add a mapped configuration Dominik Csapak
2023-06-16 13:05 ` [pve-devel] [PATCH manager v7 07/14] ui: qemu/USBEdit: add 'mapped' device case Dominik Csapak
2023-06-16 13:05 ` [pve-devel] [PATCH manager v7 08/14] ui: form: add MultiPCISelector Dominik Csapak
2023-06-16 13:05 ` [pve-devel] [PATCH manager v7 09/14] ui: add edit window for pci mappings Dominik Csapak
2023-06-16 13:05 ` [pve-devel] [PATCH manager v7 10/14] ui: add edit window for usb mappings Dominik Csapak
2023-06-16 13:05 ` [pve-devel] [PATCH manager v7 11/14] ui: add ResourceMapTree Dominik Csapak
2023-06-16 13:05 ` [pve-devel] [PATCH manager v7 12/14] ui: allow configuring pci and usb mapping Dominik Csapak
2023-06-16 13:05 ` [pve-devel] [PATCH manager v7 13/14] ui: window/Migrate: allow mapped devices Dominik Csapak
2023-06-16 13:05 ` [pve-devel] [PATCH manager v7 14/14] ui: improve permission handling for hardware Dominik Csapak
2023-06-16 13:05 ` [pve-devel] [PATCH docs v7 1/1] qemu: add documentation about cluster device mapping Dominik Csapak
2023-06-19  7:12   ` [pve-devel] applied: " Thomas Lamprecht
2023-06-16 15:00 ` [pve-devel] [PATCH qemu-server/manager/docs v7] cluster mapping Friedrich Weber
2023-06-19  5:29 ` [pve-devel] partially-applied: " Thomas Lamprecht
2023-06-19  7:28 ` [pve-devel] applied: " Thomas Lamprecht

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=20230616130542.199182-5-d.csapak@proxmox.com \
    --to=d.csapak@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