]> git.proxmox.com Git - pve-container.git/blobdiff - src/PVE/LXC.pm
run_with_loopdev: reuse existing loopdevs
[pve-container.git] / src / PVE / LXC.pm
index 0f8cff35b5646599c1a7f16333cbbcbecbd9eb53..f5cc1f26b3d626be80fe643a9573ac7f2d13cc92 100644 (file)
@@ -2396,7 +2396,15 @@ sub query_loopdev {
 # Returns the loop device.
 sub run_with_loopdev {
     my ($func, $file) = @_;
-    my $device;
+    my $device = query_loopdev($file);
+    # Try to reuse an existing device
+    if ($device) {
+       # We assume that whoever setup the loop device is responsible for
+       # detaching it.
+       &$func($device);
+       return $device;
+    }
+
     my $parser = sub {
        my $line = shift;
        if ($line =~ m@^(/dev/loop\d+)$@) {