public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH manager 1/2] pve6to7: content check: fix detecting pass
@ 2021-06-25  8:29 Fabian Ebner
  2021-06-25  8:29 ` [pve-devel] [PATCH manager 2/2] pve6to7: more fine-grained detection of misconfigured guest volumes Fabian Ebner
  0 siblings, 1 reply; 2+ messages in thread
From: Fabian Ebner @ 2021-06-25  8:29 UTC (permalink / raw)
  To: pve-devel

If there is a log_fail, because of misconfigured 'none' content type, the final
log_pass should not be printed.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
 PVE/CLI/pve6to7.pm | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/PVE/CLI/pve6to7.pm b/PVE/CLI/pve6to7.pm
index f56dd42c..3d5b780b 100644
--- a/PVE/CLI/pve6to7.pm
+++ b/PVE/CLI/pve6to7.pm
@@ -707,6 +707,7 @@ sub check_storage_content {
     log_info("Checking storage content type configuration..");
 
     my $found;
+    my $pass = 1;
 
     my $storage_cfg = PVE::Storage::config();
 
@@ -718,6 +719,7 @@ sub check_storage_content {
 	my $valid_content = PVE::Storage::Plugin::valid_content_types($scfg->{type});
 
 	if (scalar(keys $scfg->{content}->%*) == 0 && !$valid_content->{none}) {
+	    $pass = 0;
 	    log_fail("storage '$storeid' does not support configured content type 'none'");
 	    delete $scfg->{content}->{none}; # scan for guest images below
 	}
@@ -738,6 +740,7 @@ sub check_storage_content {
 
 	if (scalar(@volumes) > 0) {
 	    $found = 1;
+	    $pass = 0;
 	    log_warn("storage '$storeid' - neither content type 'images' nor 'rootdir' configured"
 		.", but found guest volume(s):\n    " . join("\n    ", @volumes));
 	}
@@ -746,7 +749,9 @@ sub check_storage_content {
     if ($found) {
 	log_warn("PVE 7.0 enforces stricter content type checks. Guests referencing the above " .
 	    "volumes will not work until the storage configuration is fixed.");
-    } else {
+    }
+
+    if ($pass) {
 	log_pass("no problems found");
     }
 }
-- 
2.20.1





^ permalink raw reply	[flat|nested] 2+ messages in thread

* [pve-devel] [PATCH manager 2/2] pve6to7: more fine-grained detection of misconfigured guest volumes
  2021-06-25  8:29 [pve-devel] [PATCH manager 1/2] pve6to7: content check: fix detecting pass Fabian Ebner
@ 2021-06-25  8:29 ` Fabian Ebner
  0 siblings, 0 replies; 2+ messages in thread
From: Fabian Ebner @ 2021-06-25  8:29 UTC (permalink / raw)
  To: pve-devel

If neither 'rootdir' nor 'images' are configured on a storage, but there are
guest images, just log the number of volumes found, instead of listing all and
warning. They might well be false positive (e.g. same backing storage configured
with different content types).

Also detect content type mismatch for all volumes referenced by guests, which
also covers the case of a VM image on a storage with only 'rootdir' and vice
versa.

Change the message from 'will not work' to 'might not work'. If a volume only
referenced by a snapshot is misconfigured, it doesn't mean that the guest
doesn't work at all. Or it might be an ISO on a misconfigured storage.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
 PVE/CLI/pve6to7.pm | 101 +++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 94 insertions(+), 7 deletions(-)

diff --git a/PVE/CLI/pve6to7.pm b/PVE/CLI/pve6to7.pm
index 3d5b780b..70600c89 100644
--- a/PVE/CLI/pve6to7.pm
+++ b/PVE/CLI/pve6to7.pm
@@ -734,21 +734,108 @@ sub check_storage_content {
 	next if $scfg->{type} ne 'dir' && $scfg->{content}->{none};
 
 	my $res = PVE::Storage::vdisk_list($storage_cfg, $storeid);
-	my $disk_list = $res->{$storeid};
+	my @volids = map { $_->{volid} } $res->{$storeid}->@*;
 
-	my @volumes = map { $_->{volid} } $disk_list->@*;
+	if ((my $number = scalar(@volids)) > 0) {
+	    log_info("storage '$storeid' - neither content type 'images' nor 'rootdir' configured"
+		.", but found '$number' guest volume(s)");
+	}
+    }
+
+    # now check referenced volids
+
+    my $check_volid = sub {
+	my ($volid, $vmid, $vmtype, $reference) = @_;
+
+	my $guesttext = $vmtype eq 'qemu' ? 'VM' : 'CT';
+	my $prefix = "$guesttext $vmid - volume '$volid' (in $reference)";
+
+	my ($storeid) = PVE::Storage::parse_volume_id($volid, 1);
+	return if !defined($storeid);
+
+	my $scfg = $storage_cfg->{ids}->{$storeid};
+	if (!$scfg) {
+	    $pass = 0;
+	    log_warn("$prefix - storage does not exist!");
+	    return;
+	}
 
-	if (scalar(@volumes) > 0) {
+	# cannot use parse_volname for containers, as it can return 'images'
+	# but containers cannot have ISO images attached, so assume 'rootdir'
+	my $vtype = 'rootdir';
+	if ($vmtype eq 'qemu') {
+	    ($vtype) = PVE::Storage::parse_volname($storage_cfg, $volid);
+	}
+
+	if (!$scfg->{content}->{$vtype}) {
 	    $found = 1;
 	    $pass = 0;
-	    log_warn("storage '$storeid' - neither content type 'images' nor 'rootdir' configured"
-		.", but found guest volume(s):\n    " . join("\n    ", @volumes));
+	    log_warn("$prefix - storage does not have content type '$vtype' configured.");
+	}
+    };
+
+    my $cts = PVE::LXC::config_list();
+    for my $vmid (sort { $a <=> $b } keys %$cts) {
+	my $conf = PVE::LXC::Config->load_config($vmid);
+
+	my $volhash = {};
+
+	my $check = sub {
+	    my ($ms, $mountpoint, $reference) = @_;
+
+	    my $volid = $mountpoint->{volume};
+	    return if !$volid || $mountpoint->{type} ne 'volume';
+
+	    return if $volhash->{$volid}; # volume might be referenced multiple times
+
+	    $volhash->{$volid} = 1;
+
+	    $check_volid->($volid, $vmid, 'lxc', $reference);
+	};
+
+	my $opts = { include_unused => 1 };
+	PVE::LXC::Config->foreach_volume_full($conf, $opts, $check, 'config');
+	for my $snapname (keys $conf->{snapshots}->%*) {
+	    my $snap = $conf->{snapshots}->{$snapname};
+	    PVE::LXC::Config->foreach_volume_full($snap, $opts, $check, "snapshot '$snapname'");
+	}
+    }
+
+    my $vms = PVE::QemuServer::config_list();
+    for my $vmid (sort { $a <=> $b } keys %$vms) {
+	my $conf = PVE::QemuConfig->load_config($vmid);
+
+	my $volhash = {};
+
+	my $check = sub {
+	    my ($key, $drive, $reference) = @_;
+
+	    my $volid = $drive->{file};
+	    return if $volid =~ m|^/|;
+
+	    return if $volhash->{$volid}; # volume might be referenced multiple times
+
+	    $volhash->{$volid} = 1;
+
+	    $check_volid->($volid, $vmid, 'qemu', $reference);
+	};
+
+	my $opts = {
+	    extra_keys => ['vmstate'],
+	    include_unused => 1,
+	};
+	# startup from a suspended state works even without 'images' content type on the
+	# state storage, so do not check 'vmstate' for $conf
+	PVE::QemuConfig->foreach_volume_full($conf, { include_unused => 1 }, $check, 'config');
+	for my $snapname (keys $conf->{snapshots}->%*) {
+	    my $snap = $conf->{snapshots}->{$snapname};
+	    PVE::QemuConfig->foreach_volume_full($snap, $opts, $check, "snapshot '$snapname'");
 	}
     }
 
     if ($found) {
-	log_warn("PVE 7.0 enforces stricter content type checks. Guests referencing the above " .
-	    "volumes will not work until the storage configuration is fixed.");
+	log_warn("PVE 7.0 enforces stricter content type checks. The guests above " .
+	    "might not work until the storage configuration is fixed.");
     }
 
     if ($pass) {
-- 
2.20.1





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-06-25  8:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-25  8:29 [pve-devel] [PATCH manager 1/2] pve6to7: content check: fix detecting pass Fabian Ebner
2021-06-25  8:29 ` [pve-devel] [PATCH manager 2/2] pve6to7: more fine-grained detection of misconfigured guest volumes Fabian Ebner

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