[pve-devel] [PATCH container 2/2] Refactor has_feature

Fabian Grünbichler f.gruenbichler at proxmox.com
Thu Feb 25 15:52:56 CET 2016


This allows us to use the same has_feature signature in
both QemuServer.pm and LXC.pm. Also passes the running
status like we do for Qemu.
---
 src/PVE/LXC.pm        | 14 +++++---------
 src/PVE/VZDump/LXC.pm |  2 +-
 2 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 970bd02..a432798 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1824,11 +1824,9 @@ sub snapshot_prepare {
 	    if defined($conf->{snapshots}->{$snapname});
 
 	my $storecfg = PVE::Storage::config();
-
-	# workaround until mp snapshots are implemented
-	my $feature = $snapname eq 'vzdump' ? 'vzdump' : 'snapshot';
-	die "snapshot feature is not available\n" if !has_feature($feature, $conf, $storecfg);
 	my $running = check_running($vmid);
+	die "snapshot feature is not available\n"
+	    if !has_feature('snapshot', $conf, $storecfg, undef, $running, $snapname eq 'vzdump');
 
 	$snap = $conf->{snapshots}->{$snapname} = {};
 
@@ -1880,19 +1878,17 @@ sub snapshot_commit {
 }
 
 sub has_feature {
-    my ($feature, $conf, $storecfg, $snapname) = @_;
+    my ($feature, $conf, $storecfg, $snapname, $running, $backup_only) = @_;
     
     my $err;
-    my $vzdump = $feature eq 'vzdump';
-    $feature = 'snapshot' if $vzdump;
 
     foreach_mountpoint($conf, sub {
 	my ($ms, $mountpoint) = @_;
 
 	return if $err; # skip further test
-	return if $vzdump && $ms ne 'rootfs' && !$mountpoint->{backup};
+	return if $backup_only && $ms ne 'rootfs' && !$mountpoint->{backup};
 	
-	$err = 1 if !PVE::Storage::volume_has_feature($storecfg, $feature, $mountpoint->{volume}, $snapname);
+	$err = 1 if !PVE::Storage::volume_has_feature($storecfg, $feature, $mountpoint->{volume}, $snapname, $running);
     });
 
     return $err ? 0 : 1;
diff --git a/src/PVE/VZDump/LXC.pm b/src/PVE/VZDump/LXC.pm
index 7269ce8..d32c6ff 100644
--- a/src/PVE/VZDump/LXC.pm
+++ b/src/PVE/VZDump/LXC.pm
@@ -131,7 +131,7 @@ sub prepare {
     });
 
     if ($mode eq 'snapshot') {
-	if (!PVE::LXC::has_feature('vzdump', $conf, $storage_cfg)) {
+	if (!PVE::LXC::has_feature('snapshot', $conf, $storage_cfg, undef, $running, 1)) {
 	    die "mode failure - some volumes do not support snapshots\n";
 	}
 
-- 
2.1.4





More information about the pve-devel mailing list