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) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id D81DB71D5B for ; Wed, 30 Jun 2021 14:24:34 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C4AAE19792 for ; Wed, 30 Jun 2021 14:24:04 +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 id 64B2C19785 for ; Wed, 30 Jun 2021 14:24:00 +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 31FE54308E for ; Wed, 30 Jun 2021 14:24:00 +0200 (CEST) Date: Wed, 30 Jun 2021 14:23:52 +0200 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox VE development discussion References: <20210630091618.28792-1-f.ebner@proxmox.com> <20210630091618.28792-2-f.ebner@proxmox.com> In-Reply-To: <20210630091618.28792-2-f.ebner@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.15.0 (https://github.com/astroidmail/astroid) Message-Id: <1625055700.0wfzxppq0f.astroid@nora.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.575 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% 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 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, pve6to7.pm] Subject: [pve-devel] applied: [PATCH v2 manager 2/2] pve6to7: more fine-grained detection of misconfigured guest volumes 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: Wed, 30 Jun 2021 12:24:34 -0000 On June 30, 2021 11:16 am, Fabian Ebner wrote: > If neither 'rootdir' nor 'images' are configured on a storage, but > there are guest images, just log the number of volumes found. If they > are relevant for migration, the check for unreferenced volumes will > catch them later. >=20 > Also detect content type mismatch for all volumes of existing guests, > which also covers the case of a VM image on a storage with only > 'rootdir' and vice versa. To catch all such unreferenced volumes too, > it is necessary to scan all storages that do not have both content > types configured. >=20 > 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. >=20 > Signed-off-by: Fabian Ebner > --- >=20 > Changes from v1 (mostly thanks to Fabian G.'s off-list feedback): > * Add eval around vdisk_list and parse_volname. > * Activate storage first, because vdisk_list does not do that > for storages with neither 'rootdir' nor 'images (although it > still scanned for disks...). > * Also warn about unreferenced volumes on a misconfigured storage > if a guest exists. Put a second final warning explaining that > they are not picked up for migration anymore. > * Don't put single quotes around the number of volumes in ouput > (looked weird). > * Use "Proxmox VE" instead of "PVE" in message. >=20 > PVE/CLI/pve6to7.pm | 154 +++++++++++++++++++++++++++++++++++++++++---- > 1 file changed, 141 insertions(+), 13 deletions(-) >=20 > diff --git a/PVE/CLI/pve6to7.pm b/PVE/CLI/pve6to7.pm > index 3d5b780b..6dd7760c 100644 > --- a/PVE/CLI/pve6to7.pm > +++ b/PVE/CLI/pve6to7.pm > @@ -706,11 +706,15 @@ sub check_description_lengths { > sub check_storage_content { > log_info("Checking storage content type configuration.."); > =20 > - my $found; > + my $found_referenced; > + my $found_unreferenced; > my $pass =3D 1; > =20 > my $storage_cfg =3D PVE::Storage::config(); > =20 > + my $potentially_affected =3D {}; > + my $referenced_volids =3D {}; > + > for my $storeid (keys $storage_cfg->{ids}->%*) { > my $scfg =3D $storage_cfg->{ids}->{$storeid}; > =20 > @@ -724,8 +728,7 @@ sub check_storage_content { > delete $scfg->{content}->{none}; # scan for guest images below > } > =20 > - next if $scfg->{content}->{images}; > - next if $scfg->{content}->{rootdir}; > + next if $scfg->{content}->{images} && $scfg->{content}->{rootdir}; > =20 > # Skip 'iscsi(direct)' (and foreign plugins with potentially similiar b= ehavior) with 'none', > # because that means "use LUNs directly" and vdisk_list() in PVE 6.x st= ill lists those. > @@ -733,22 +736,147 @@ sub check_storage_content { > # and 'images' or 'rootdir', hence being potentially misconfigured. > next if $scfg->{type} ne 'dir' && $scfg->{content}->{none}; > =20 > - my $res =3D PVE::Storage::vdisk_list($storage_cfg, $storeid); > - my $disk_list =3D $res->{$storeid}; > + eval { PVE::Storage::activate_storage($storage_cfg, $storeid) }; > + if (my $err =3D $@) { > + log_warn("activating '$storeid' failed - $err"); > + next; > + } > + > + my $res =3D eval { PVE::Storage::vdisk_list($storage_cfg, $storeid); }; > + if (my $err =3D $@) { > + log_warn("listing images on '$storeid' failed - $err"); > + next; > + } > + my @volids =3D map { $_->{volid} } $res->{$storeid}->@*; > + > + for my $volid (@volids) { > + $potentially_affected->{$volid} =3D 1; > + } > + > + my $number =3D scalar(@volids); > + if ($number > 0 && !$scfg->{content}->{images} && !$scfg->{content}->{r= ootdir}) { > + log_info("storage '$storeid' - neither content type 'images' nor 'r= ootdir' configured" > + .", but found $number guest volume(s)"); > + } > + } > + > + my $check_volid =3D sub { > + my ($volid, $vmid, $vmtype, $reference) =3D @_; > + > + $referenced_volids->{$volid} =3D 1 if $reference ne 'unreferenced'; > + > + my $guesttext =3D $vmtype eq 'qemu' ? 'VM' : 'CT'; > + my $prefix =3D "$guesttext $vmid - volume '$volid' ($reference)"; > =20 > - my @volumes =3D map { $_->{volid} } $disk_list->@*; > + my ($storeid) =3D PVE::Storage::parse_volume_id($volid, 1); > + return if !defined($storeid); > =20 > - if (scalar(@volumes) > 0) { > - $found =3D 1; > + my $scfg =3D $storage_cfg->{ids}->{$storeid}; > + if (!$scfg) { > $pass =3D 0; > - log_warn("storage '$storeid' - neither content type 'images' nor 'r= ootdir' configured" > - .", but found guest volume(s):\n " . join("\n ", @volumes)); > + log_warn("$prefix - storage does not exist!"); > + return; > + } > + > + # cannot use parse_volname for containers, as it can return 'images' > + # but containers cannot have ISO images attached, so assume 'rootdir' > + my $vtype =3D 'rootdir'; > + if ($vmtype eq 'qemu') { > + ($vtype) =3D eval { PVE::Storage::parse_volname($storage_cfg, $voli= d); }; > + return if $@; > } > + > + if (!$scfg->{content}->{$vtype}) { > + $found_referenced =3D 1 if $reference ne 'unreferenced'; > + $found_unreferenced =3D 1 if $reference eq 'unreferenced'; > + $pass =3D 0; > + log_warn("$prefix - storage does not have content type '$vtype' con= figured."); > + } > + }; > + > + my $guests =3D {}; > + > + my $cts =3D PVE::LXC::config_list(); > + for my $vmid (sort { $a <=3D> $b } keys %$cts) { > + $guests->{$vmid} =3D 'lxc'; > + > + my $conf =3D PVE::LXC::Config->load_config($vmid); > + > + my $volhash =3D {}; > + > + my $check =3D sub { > + my ($ms, $mountpoint, $reference) =3D @_; > + > + my $volid =3D $mountpoint->{volume}; > + return if !$volid || $mountpoint->{type} ne 'volume'; > + > + return if $volhash->{$volid}; # volume might be referenced multiple= times > + > + $volhash->{$volid} =3D 1; > + > + $check_volid->($volid, $vmid, 'lxc', $reference); > + }; > + > + my $opts =3D { include_unused =3D> 1 }; > + PVE::LXC::Config->foreach_volume_full($conf, $opts, $check, 'in config'= ); > + for my $snapname (keys $conf->{snapshots}->%*) { > + my $snap =3D $conf->{snapshots}->{$snapname}; > + PVE::LXC::Config->foreach_volume_full($snap, $opts, $check, "in sna= pshot '$snapname'"); > + } > + } > + > + my $vms =3D PVE::QemuServer::config_list(); > + for my $vmid (sort { $a <=3D> $b } keys %$vms) { > + $guests->{$vmid} =3D 'qemu'; > + > + my $conf =3D PVE::QemuConfig->load_config($vmid); > + > + my $volhash =3D {}; > + > + my $check =3D sub { > + my ($key, $drive, $reference) =3D @_; > + > + my $volid =3D $drive->{file}; > + return if $volid =3D~ m|^/|; > + > + return if $volhash->{$volid}; # volume might be referenced multiple= times > + > + $volhash->{$volid} =3D 1; > + > + $check_volid->($volid, $vmid, 'qemu', $reference); > + }; > + > + my $opts =3D { > + extra_keys =3D> ['vmstate'], > + include_unused =3D> 1, > + }; > + # startup from a suspended state works even without 'images' content ty= pe on the > + # state storage, so do not check 'vmstate' for $conf > + PVE::QemuConfig->foreach_volume_full($conf, { include_unused =3D> 1 }, = $check, 'in config'); > + for my $snapname (keys $conf->{snapshots}->%*) { > + my $snap =3D $conf->{snapshots}->{$snapname}; > + PVE::QemuConfig->foreach_volume_full($snap, $opts, $check, "in snap= shot '$snapname'"); > + } > + } > + > + if ($found_referenced) { > + log_warn("Proxmox VE 7.0 enforces stricter content type checks. The gue= sts above " . > + "might not work until the storage configuration is fixed."); > + } > + > + for my $volid (sort keys $potentially_affected->%*) { > + next if $referenced_volids->{$volid}; # already checked > + > + my (undef, undef, $vmid) =3D PVE::Storage::parse_volname($storage_cfg, = $volid); > + my $vmtype =3D $guests->{$vmid}; > + next if !$vmtype; > + > + $check_volid->($volid, $vmid, $vmtype, 'unreferenced'); > } > =20 > - if ($found) { > - log_warn("PVE 7.0 enforces stricter content type checks. Guests referen= cing the above " . > - "volumes will not work until the storage configuration is fixed."); > + if ($found_unreferenced) { > + log_warn("When migrating, Proxmox VE 7.0 only scans storages with the a= ppropriate " . > + "content types for unreferenced guest volumes."); > } > =20 > if ($pass) { > --=20 > 2.20.1 >=20 >=20 >=20 > _______________________________________________ > pve-devel mailing list > pve-devel@lists.proxmox.com > https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel >=20 >=20 >=20