From mboxrd@z Thu Jan 1 00:00:00 1970
Return-Path: <f.ebner@proxmox.com>
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 6FD766B499
for <pve-devel@lists.proxmox.com>; Tue, 26 Jan 2021 12:46:10 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
by firstgate.proxmox.com (Proxmox) with ESMTP id 7064115A56
for <pve-devel@lists.proxmox.com>; Tue, 26 Jan 2021 12:45:39 +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 8FBB615962
for <pve-devel@lists.proxmox.com>; Tue, 26 Jan 2021 12:45:35 +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 592624610E
for <pve-devel@lists.proxmox.com>; Tue, 26 Jan 2021 12:45:35 +0100 (CET)
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Tue, 26 Jan 2021 12:45:19 +0100
Message-Id: <20210126114530.8753-4-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 03/14] Diskmanage: refactor and rename
get_parttype_info
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>,
<mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>,
<mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Tue, 26 Jan 2021 11:46:10 -0000
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