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 3E0366B415 for ; Tue, 26 Jan 2021 12:46:14 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 24BFB15AF9 for ; Tue, 26 Jan 2021 12:45:43 +0100 (CET) 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 5D45E1598A for ; Tue, 26 Jan 2021 12:45:36 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 1E29C46118 for ; Tue, 26 Jan 2021 12:45:36 +0100 (CET) From: Fabian Ebner To: pve-devel@lists.proxmox.com Date: Tue, 26 Jan 2021 12:45:23 +0100 Message-Id: <20210126114530.8753-8-f.ebner@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210126114530.8753-1-f.ebner@proxmox.com> References: <20210126114530.8753-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.006 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. [diskmanage.pm] Subject: [pve-devel] [PATCH storage 07/14] Diskmanage: introduce usage helper 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, 26 Jan 2021 11:46:14 -0000 Note that this is a slight behavior change, because now the first partition's usage which is not simply 'partition' will become the disk's usage. Previously, if any partition was 'mounted', it would become the disk's usage, then 'LVM', 'ZFS', etc. A partitions usage defaults to 'partition' if nothing more specific can be found, and is never treated as unused for now. Signed-off-by: Fabian Ebner --- PVE/Diskmanage.pm | 71 +++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 40 deletions(-) diff --git a/PVE/Diskmanage.pm b/PVE/Diskmanage.pm index a06f8ae..32789f2 100644 --- a/PVE/Diskmanage.pm +++ b/PVE/Diskmanage.pm @@ -566,22 +566,6 @@ sub get_disks { }; } - my $used; - - $used = 'LVM' if $lvmhash->{$devpath}; - - $used = 'mounted' if $mounted->{$devpath}; - - $used = 'ZFS' if $zfshash->{$devpath}; - - if (defined($lsblk_info->{$devpath})) { - my $fstype = $lsblk_info->{$devpath}->{fstype}; - if (defined($fstype)) { - $used = $fstype; - $used .= ' (mounted)' if $mounted->{$devpath}; - } - } - # we replaced cciss/ with cciss! above # but in the result we need cciss/ again # because the caller might want to check the @@ -615,10 +599,6 @@ sub get_disks { my $db_count = 0; my $wal_count = 0; - my $found_lvm; - my $found_mountpoints; - my $found_zfs; - my $found_dm; my $partpath = $devpath; # remove part after last / to @@ -626,6 +606,28 @@ sub get_disks { # e.g. from /dev/cciss/c0d0 get /dev/cciss $partpath =~ s/\/[^\/]+$//; + my $determine_usage = sub { + my ($devpath, $sysdir, $is_partition) = @_; + + return 'LVM' if $lvmhash->{$devpath}; + return 'ZFS' if $zfshash->{$devpath}; + + my $info = $lsblk_info->{$devpath} // {}; + my $fstype = $info->{fstype}; + if (defined($fstype)) { + return "${fstype} (mounted)" if $mounted->{$devpath}; + return "${fstype}"; + } + return 'mounted' if $mounted->{$devpath}; + + return if !$is_partition; + + # for devices, this check is done explicitly later + return 'Device Mapper' if !dir_is_empty("$sysdir/holders"); + + return 'partition'; + }; + my $partitions = {}; dir_glob_foreach("$sysdir", "$dev.+", sub { @@ -635,32 +637,21 @@ sub get_disks { $partitions->{$part}->{gpt} = $data->{gpt}; $partitions->{$part}->{size} = get_sysdir_size("$sysdir/$part") // 0; + $partitions->{$part}->{used} = + $determine_usage->("$partpath/$part", "$sysdir/$part", 1); if (my $mp = $mounted->{"$partpath/$part"}) { - $found_mountpoints = 1; if ($mp =~ m|^/var/lib/ceph/osd/ceph-(\d+)$|) { $osdid = $1; } } - if ($lvmhash->{"$partpath/$part"}) { - $found_lvm = 1; - } - - if ($zfshash->{"$partpath/$part"}) { - $found_zfs = 1; - } - if (my $journal_part = $journalhash->{"$partpath/$part"}) { $journal_count++ if $journal_part == 1; $db_count++ if $journal_part == 2; $wal_count++ if $journal_part == 3; $bluestore = 1 if $journal_part == 4; } - - if (!dir_is_empty("$sysdir/$part/holders") && !$found_lvm) { - $found_dm = 1; - } }); if (my $ceph_volume = $ceph_volume_infos->{$devpath}) { @@ -674,16 +665,16 @@ sub get_disks { } } - $used = 'mounted' if $found_mountpoints && !$used; - $used = 'LVM' if $found_lvm && !$used; - $used = 'ZFS' if $found_zfs && !$used; - $used = 'Device Mapper' if $found_dm && !$used; - $used = 'partitions' if scalar(keys %{$partitions}) && !$used; - + my $used = $determine_usage->($devpath, $sysdir, 0); + foreach my $part (sort keys %{$partitions}) { + next if $partitions->{$part}->{used} eq 'partition'; + $used //= $partitions->{$part}->{used}; + } + $used //= 'partitions' if scalar(keys %{$partitions}); # multipath, software raid, etc. # this check comes in last, to show more specific info # if we have it - $used = 'Device Mapper' if !$used && !dir_is_empty("$sysdir/holders"); + $used //= 'Device Mapper' if !dir_is_empty("$sysdir/holders"); $disklist->{$dev}->{used} = $used if $used; $disklist->{$dev}->{osdid} = $osdid; -- 2.20.1