diskmanage: add has_holder method

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
This commit is contained in:
Fabian Ebner
2021-04-23 12:14:54 +02:00
committed by Thomas Lamprecht
parent 3bf7f8891b
commit cb057e21c5

View File

@ -848,6 +848,30 @@ sub append_partition {
return $partition;
}
# Check if a disk or any of its partitions has a holder.
# Can also be called with a partition.
# Expected to be called with a result of verify_blockdev_path().
sub has_holder {
my ($devpath) = @_;
my $sysdir = "/sys/class/block/";
my $dev = $devpath;
$dev =~ s|^/dev/||;
return $devpath if !dir_is_empty("${sysdir}/${dev}/holders");
my $found;
dir_glob_foreach("/sys/block/${dev}", "${dev}.+", sub {
my ($part) = @_;
$found = "/dev/${part}" if !dir_is_empty("${sysdir}/${part}/holders");
});
return $found;
}
# Basic check if a disk or any of its partitions is mounted.
# Can also be called with a partition.
# Expected to be called with a result of verify_blockdev_path().