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

Wolfgang Link w.link at proxmox.com
Mon Dec 19 15:15:37 CET 2016


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

V2 Fix typo and space.


diff --git a/PVE/Diskmanage.pm b/PVE/Diskmanage.pm
index e4821d4..5fd7c6a 100644
--- a/PVE/Diskmanage.pm
+++ b/PVE/Diskmanage.pm
@@ -544,4 +544,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