]> git.proxmox.com Git - pve-storage.git/commitdiff
Diskmanage: also include partitions with get_disks if flag is set
authorFabian Ebner <f.ebner@proxmox.com>
Tue, 26 Jan 2021 11:45:27 +0000 (12:45 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Sat, 6 Feb 2021 12:52:20 +0000 (13:52 +0100)
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
PVE/Diskmanage.pm

index c0456be6916e7725beaf53e48ce8dc343f3be3c1..d2ee81dd613fec3c95619504e9becbe082ee4036 100644 (file)
@@ -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 = [];
index 7c07e52c7cc46d9d0d62f5357670fc093bb51822..78f78652d45fd0192298860e042f599130071a54 100644 (file)
@@ -475,7 +475,7 @@ my sub is_ssdlike {
 }
 
 sub get_disks {
-    my ($disks, $nosmart) = @_;
+    my ($disks, $nosmart, $include_partitions) = @_;
     my $disklist = {};
 
     my $mounted = {};
@@ -666,6 +666,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;
@@ -700,9 +701,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.
@@ -720,6 +723,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;