all lists on 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 11/14] Diskmanage: also include partitions with get_disks if flag is set
Date: Tue, 26 Jan 2021 12:45:27 +0100	[thread overview]
Message-ID: <20210126114530.8753-12-f.ebner@proxmox.com> (raw)
In-Reply-To: <20210126114530.8753-1-f.ebner@proxmox.com>

and have a parent key for partitions, to be able to see the associated disk in
the result without having to rely on naming heuristics (just adding a number at
the end doesn't work for NVMes).

The disk's usage will not be based on the partitions usage if the flag is set,
but will simply be 'partitions'.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
 PVE/API2/Disks.pm | 19 ++++++++++++++++++-
 PVE/Diskmanage.pm | 17 +++++++++++++----
 2 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/PVE/API2/Disks.pm b/PVE/API2/Disks.pm
index c0456be..d2ee81d 100644
--- a/PVE/API2/Disks.pm
+++ b/PVE/API2/Disks.pm
@@ -88,6 +88,12 @@ __PACKAGE__->register_method ({
 	additionalProperties => 0,
 	properties => {
 	    node => get_standard_option('pve-node'),
+	    'include-partitions' => {
+		description => "Also include partitions.",
+		type => 'boolean',
+		optional => 1,
+		default => 0,
+	    },
 	    skipsmart => {
 		description => "Skip smart checks.",
 		type => 'boolean',
@@ -120,6 +126,12 @@ __PACKAGE__->register_method ({
 		serial =>  { type => 'string', optional => 1 },
 		wwn => { type => 'string', optional => 1},
 		health => { type => 'string', optional => 1},
+		parent => {
+		    type => 'string',
+		    description => 'For partitions only. The device path of ' .
+			'the disk the partition resides on.',
+		    optional => 1
+		},
 	    },
 	},
     },
@@ -127,8 +139,13 @@ __PACKAGE__->register_method ({
 	my ($param) = @_;
 
 	my $skipsmart = $param->{skipsmart} // 0;
+	my $include_partitions = $param->{'include-partitions'} // 0;
 
-	my $disks = PVE::Diskmanage::get_disks(undef, $skipsmart);
+	my $disks = PVE::Diskmanage::get_disks(
+	    undef,
+	    $skipsmart,
+	    $include_partitions
+	);
 
 	my $type = $param->{type} // '';
 	my $result = [];
diff --git a/PVE/Diskmanage.pm b/PVE/Diskmanage.pm
index 195b706..8967ca7 100644
--- a/PVE/Diskmanage.pm
+++ b/PVE/Diskmanage.pm
@@ -476,7 +476,7 @@ my sub is_ssdlike {
 }
 
 sub get_disks {
-    my ($disks, $nosmart) = @_;
+    my ($disks, $nosmart, $include_partitions) = @_;
     my $disklist = {};
 
     my $mounted = {};
@@ -667,6 +667,7 @@ sub get_disks {
 	    my $lvm_based_osd = defined($partitions->{$part});
 
 	    $partitions->{$part}->{devpath} = "$partpath/$part";
+	    $partitions->{$part}->{parent} = "$devpath";
 	    $partitions->{$part}->{gpt} = $data->{gpt};
 	    $partitions->{$part}->{size} =
 		get_sysdir_size("$sysdir/$part") // 0;
@@ -701,9 +702,11 @@ sub get_disks {
 	});
 
 	my $used = $determine_usage->($devpath, $sysdir, 0);
-	foreach my $part (sort keys %{$partitions}) {
-	    next if $partitions->{$part}->{used} eq 'partition';
-	    $used //= $partitions->{$part}->{used};
+	if (!$include_partitions) {
+	    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.
@@ -721,6 +724,12 @@ sub get_disks {
 	$disklist->{$dev}->{osdencrypted} = $osdencrypted if $osdid != -1;
 	$disklist->{$dev}->{db} = $db_count if $db_count;
 	$disklist->{$dev}->{wal} = $wal_count if $wal_count;
+
+	if ($include_partitions) {
+	    foreach my $part (keys %{$partitions}) {
+		$disklist->{$part} = $partitions->{$part};
+	    }
+	}
     });
 
     return $disklist;
-- 
2.20.1





  parent reply	other threads:[~2021-01-26 11:45 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 ` [pve-devel] [PATCH storage 07/14] Diskmanage: introduce usage helper Fabian Ebner
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 ` Fabian Ebner [this message]
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-12-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal