]> git.proxmox.com Git - pve-storage.git/commitdiff
diskmanage: add is_mounted method
authorFabian Ebner <f.ebner@proxmox.com>
Fri, 23 Apr 2021 10:14:53 +0000 (12:14 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 2 Jun 2021 09:56:51 +0000 (11:56 +0200)
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
PVE/Diskmanage.pm

index c188d8394bf133696d06dd66c5c5edae24164396..70677ea3b12eafc8cb8802fe65d307dab8c4bcb6 100644 (file)
@@ -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 {