[pve-devel] [PATCH pve-container 1/4] factor query_loopdev into PVE::LXC

Wolfgang Bumiller w.bumiller at proxmox.com
Fri Nov 20 14:04:26 CET 2015


---
 src/PVE/API2/LXC.pm | 16 +---------------
 src/PVE/LXC.pm      | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 0a80dfc..e362379 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -1007,20 +1007,6 @@ __PACKAGE__->register_method({
 
 	my $storage_cfg = cfs_read_file("storage.cfg");
 
-	my $query_loopdev = sub {
-	    my ($path) = @_;
-	    my $found;
-	    my $parser = sub {
-		my $line = shift;
-		if ($line =~ m@^(/dev/loop\d+):@) {
-		    $found = $1;
-		}
-	    };
-	    my $cmd = ['losetup', '--associated', $path];
-	    PVE::Tools::run_command($cmd, outfunc => $parser);
-	    return $found;
-	};
-
 	my $code = sub {
 
 	    my $conf = PVE::LXC::load_config($vmid);
@@ -1072,7 +1058,7 @@ __PACKAGE__->register_method({
 
 			$mp->{mp} = '/';
 			my $use_loopdev = (PVE::LXC::mountpoint_mount_path($mp, $storage_cfg))[1];
-			$path = &$query_loopdev($path) if $use_loopdev;
+			$path = PVE::LXC::query_loopdev($path) if $use_loopdev;
 			die "internal error: CT running but mountpoint not attached to a loop device"
 			    if !$path;
 			PVE::Tools::run_command(['losetup', '--set-capacity', $path]) if $use_loopdev;
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 6775fe3..52f1077 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -2109,6 +2109,20 @@ my $check_mount_path = sub {
     }
 };
 
+sub query_loopdev {
+    my ($path) = @_;
+    my $found;
+    my $parser = sub {
+	my $line = shift;
+	if ($line =~ m@^(/dev/loop\d+):@) {
+	    $found = $1;
+	}
+    };
+    my $cmd = ['losetup', '--associated', $path];
+    PVE::Tools::run_command($cmd, outfunc => $parser);
+    return $found;
+}
+
 # use $rootdir = undef to just return the corresponding mount path
 sub mountpoint_mount {
     my ($mountpoint, $rootdir, $storage_cfg, $snapname) = @_;
-- 
2.1.4





More information about the pve-devel mailing list