[pve-devel] [PATCH storage 04/11] diskmanage: add has_holder method
Fabian Ebner
f.ebner at proxmox.com
Fri Apr 23 12:14:54 CEST 2021
Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
PVE/Diskmanage.pm | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/PVE/Diskmanage.pm b/PVE/Diskmanage.pm
index 70677ea..07bcef2 100644
--- a/PVE/Diskmanage.pm
+++ b/PVE/Diskmanage.pm
@@ -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().
--
2.20.1
More information about the pve-devel
mailing list