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 03/14] Diskmanage: refactor and rename get_parttype_info
Date: Tue, 26 Jan 2021 12:45:19 +0100	[thread overview]
Message-ID: <20210126114530.8753-4-f.ebner@proxmox.com> (raw)
In-Reply-To: <20210126114530.8753-1-f.ebner@proxmox.com>

in preparation to also query the file system type from lsblk. Note that the
result now also includes devices without a parttype, so a definedness check in
get_devices_by_partuuid is needed. This will be useful when the whole device
contains a filesystem.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
 PVE/Diskmanage.pm | 39 +++++++++++++++++++--------------------
 1 file changed, 19 insertions(+), 20 deletions(-)

diff --git a/PVE/Diskmanage.pm b/PVE/Diskmanage.pm
index f28e007..e20484b 100644
--- a/PVE/Diskmanage.pm
+++ b/PVE/Diskmanage.pm
@@ -157,7 +157,7 @@ sub get_smart_data {
     return $smartdata;
 }
 
-sub get_parttype_info() {
+sub get_lsblk_info() {
     my $cmd = [$LSBLK, '--json', '-o', 'path,parttype'];
     my $output = "";
     my $res = {};
@@ -174,30 +174,29 @@ sub get_parttype_info() {
     warn "$@\n" if $@;
     my $list = $parsed->{blockdevices} // [];
 
-    foreach my $dev (@$list) {
-	next if !($dev->{parttype});
-	my $type = $dev->{parttype};
-	$res->{$type} = [] if !defined($res->{$type});
-	push @{$res->{$type}}, $dev->{path};
-    }
+    $res = { map {
+	$_->{path} => { parttype => $_->{parttype} }
+    } @{$list} };
 
     return $res;
 }
 
 my $get_devices_by_partuuid = sub {
-    my ($parttype_map, $uuids, $res) = @_;
+    my ($lsblk_info, $uuids, $res) = @_;
 
     $res = {} if !defined($res);
 
-    foreach my $uuid (sort keys %$uuids) {
-       map { $res->{$_} = $uuids->{$uuid} } @{$parttype_map->{$uuid}};
+    foreach my $dev (sort keys %{$lsblk_info}) {
+	my $uuid = $lsblk_info->{$dev}->{parttype};
+	next if !defined($uuid) || !defined($uuids->{$uuid});
+	$res->{$dev} = $uuids->{$uuid};
     }
 
     return $res;
 };
 
 sub get_zfs_devices {
-    my ($parttype_map) = @_;
+    my ($lsblk_info) = @_;
     my $res = {};
 
     return {} if ! -x $ZPOOL;
@@ -225,13 +224,13 @@ sub get_zfs_devices {
     };
 
 
-    $res = $get_devices_by_partuuid->($parttype_map, $uuids, $res);
+    $res = $get_devices_by_partuuid->($lsblk_info, $uuids, $res);
 
     return $res;
 }
 
 sub get_lvm_devices {
-    my ($parttype_map) = @_;
+    my ($lsblk_info) = @_;
     my $res = {};
     eval {
 	run_command([$PVS, '--noheadings', '--readonly', '-o', 'pv_name'], outfunc => sub{
@@ -251,13 +250,13 @@ sub get_lvm_devices {
 	"e6d6d379-f507-44c2-a23c-238f2a3df928" => 1,
     };
 
-    $res = $get_devices_by_partuuid->($parttype_map, $uuids, $res);
+    $res = $get_devices_by_partuuid->($lsblk_info, $uuids, $res);
 
     return $res;
 }
 
 sub get_ceph_journals {
-    my ($parttype_map) = @_;
+    my ($lsblk_info) = @_;
     my $res = {};
 
     my $uuids = {
@@ -267,7 +266,7 @@ sub get_ceph_journals {
 	'cafecafe-9b03-4f30-b4c6-b4b80ceff106' => 4, # block
     };
 
-    $res = $get_devices_by_partuuid->($parttype_map, $uuids, $res);
+    $res = $get_devices_by_partuuid->($lsblk_info, $uuids, $res);
 
     return $res;
 }
@@ -480,14 +479,14 @@ sub get_disks {
 	$mounted->{abs_path($mount->[0])} = $mount->[1];
     };
 
-    my $parttype_map = get_parttype_info();
+    my $lsblk_info = get_lsblk_info();
 
-    my $journalhash = get_ceph_journals($parttype_map);
+    my $journalhash = get_ceph_journals($lsblk_info);
     my $ceph_volume_infos = get_ceph_volume_infos();
 
-    my $zfshash = get_zfs_devices($parttype_map);
+    my $zfshash = get_zfs_devices($lsblk_info);
 
-    my $lvmhash = get_lvm_devices($parttype_map);
+    my $lvmhash = get_lvm_devices($lsblk_info);
 
     my $disk_regex = ".*";
     if (defined($disks)) {
-- 
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 ` Fabian Ebner [this message]
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 ` [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-4-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