[pve-devel] [PATCH storage 03/11] diskmanage: add is_mounted method

Fabian Ebner f.ebner at proxmox.com
Fri Apr 23 12:14:53 CEST 2021


Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 PVE/Diskmanage.pm | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/PVE/Diskmanage.pm b/PVE/Diskmanage.pm
index c188d83..70677ea 100644
--- a/PVE/Diskmanage.pm
+++ b/PVE/Diskmanage.pm
@@ -848,6 +848,32 @@ sub append_partition {
     return $partition;
 }
 
+# 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().
+sub is_mounted {
+    my ($devpath) = @_;
+
+    my $mounted = mounted_blockdevs();
+
+    return $devpath if $mounted->{$devpath};
+
+    my $dev = $devpath;
+    $dev =~ s|^/dev/||;
+
+    my $found;
+
+    dir_glob_foreach("/sys/block/${dev}", "${dev}.+", sub {
+	my ($part) = @_;
+
+	my $partpath = "/dev/${part}";
+
+	$found = $partpath if $mounted->{$partpath};
+    });
+
+    return $found;
+}
+
 # Wipes all labels and the first 200 MiB of a disk/partition (or the whole if it is smaller).
 # Expected to be called with a result of verify_blockdev_path().
 sub wipe_blockdev {
-- 
2.20.1






More information about the pve-devel mailing list