[pve-devel] [PATCH pve-storage 2/2] Add function get_blockdev.

Wolfgang Link w.link at proxmox.com
Mon Dec 19 12:41:29 CET 2016


This function will return you the block device of a given partition path.
---
 PVE/Diskmanage.pm | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/PVE/Diskmanage.pm b/PVE/Diskmanage.pm
index 1171031..3c3518b 100644
--- a/PVE/Diskmanage.pm
+++ b/PVE/Diskmanage.pm
@@ -548,4 +548,20 @@ sub get_partnum {
     return $partnum;
 }
 
+sub get_blockdev {
+    my ($part_path) = @_;
+
+    my $dev = $1 if  $part_path =~ m|^/dev/(.*)$|;
+    my $link = readlink "/sys/class/block/$dev";
+    my $block_dev = $1 if $link =~ m|([^/]*)/$dev$|;
+
+    die "Can't parse parent Device\n" if !defined($block_dev);
+    die "No valid block device\n" if index($dev, $block_dev) == -1;
+
+    $block_dev = "/dev/$block_dev";
+    die "Block device does not exsists\n" if !(-b $block_dev);
+
+    return  $block_dev;
+}
+
 1;
-- 
2.1.4





More information about the pve-devel mailing list