public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH storage 07/14] Diskmanage: introduce usage helper
Date: Tue, 26 Jan 2021 12:45:23 +0100	[thread overview]
Message-ID: <20210126114530.8753-8-f.ebner@proxmox.com> (raw)
In-Reply-To: <20210126114530.8753-1-f.ebner@proxmox.com>

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 <f.ebner@proxmox.com>
---
 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





  parent reply	other threads:[~2021-01-26 11:46 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-26 11:45 [pve-devel] [PATCH-SERIES] partially fix #2285: extend Diskmanage to also list partitions Fabian Ebner
2021-01-26 11:45 ` [pve-devel] [PATCH storage 01/14] Disks: return correct journal disk candidates Fabian Ebner
2021-01-26 11:45 ` [pve-devel] [PATCH storage 02/14] Diskmanage: replace closure with direct hash access Fabian Ebner
2021-01-26 11:45 ` [pve-devel] [PATCH storage 03/14] Diskmanage: refactor and rename get_parttype_info Fabian Ebner
2021-01-26 11:45 ` [pve-devel] [PATCH storage 04/14] Diskmanage: also check for filesystem type when determining usage Fabian Ebner
2021-01-26 11:45 ` [pve-devel] [PATCH storage 05/14] Diskmanage: introduce get_sysdir_size helper Fabian Ebner
2021-01-26 11:45 ` [pve-devel] [PATCH storage 06/14] Diskmanage: collect partitions in hash Fabian Ebner
2021-01-26 11:45 ` Fabian Ebner [this message]
2021-01-26 11:45 ` [pve-devel] [PATCH storage 08/14] Diskmanage: also detect BIOS boot, EFI and ZFS reserved type partitions Fabian Ebner
2021-01-26 11:45 ` [pve-devel] [PATCH storage 09/14] Diskmanage: introduce ceph info helper Fabian Ebner
2021-01-26 11:45 ` [pve-devel] [PATCH storage 10/14] Diskmanage: save OSD information for individual partitions Fabian Ebner
2021-01-26 11:45 ` [pve-devel] [PATCH storage 11/14] Diskmanage: also include partitions with get_disks if flag is set Fabian Ebner
2021-01-26 11:45 ` [pve-devel] [PATCH manager 12/14] api: Ceph: add reminder to remove 'disks' call Fabian Ebner
2021-01-26 11:45 ` [pve-devel] [PATCH widget-toolkit 13/14] convert disk list to disk tree including the partitions Fabian Ebner
2021-01-26 11:45 ` [pve-devel] [PATCH widget-toolkit 14/14] move DiskList.js from grid/ to panel/ Fabian Ebner
2021-02-06 13:13 ` [pve-devel] partially-applied: [PATCH-SERIES] partially fix #2285: extend Diskmanage to also list partitions Thomas Lamprecht
2021-02-08  7:58   ` Fabian Ebner

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=20210126114530.8753-8-f.ebner@proxmox.com \
    --to=f.ebner@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