From 0d28307d2ff4a6385acfeefe2cf9e0619c0fded5 Mon Sep 17 00:00:00 2001 From: Wolfgang Link Date: Mon, 19 Dec 2016 15:15:37 +0100 Subject: [PATCH] Add function get_blockdev. 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 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;