[pve-devel] [PATCH] extend functionality to (de)activate_volumes with snapshots

Wolfgang Link w.link at proxmox.com
Fri Sep 18 11:57:07 CEST 2015


this extension provide the capability to activate or deactivate snapshot,
so we can use this e.g. for LXC backup in snapshot mode.
---
 PVE/Storage.pm                   | 8 ++++----
 PVE/Storage/DRBDPlugin.pm        | 8 ++++++--
 PVE/Storage/GlusterfsPlugin.pm   | 4 ++--
 PVE/Storage/ISCSIDirectPlugin.pm | 4 ++--
 PVE/Storage/LVMPlugin.pm         | 8 ++++----
 PVE/Storage/Plugin.pm            | 6 +++---
 PVE/Storage/RBDPlugin.pm         | 9 ++++++---
 PVE/Storage/SheepdogPlugin.pm    | 4 ++--
 PVE/Storage/ZFSPoolPlugin.pm     | 4 ++--
 9 files changed, 31 insertions(+), 24 deletions(-)

diff --git a/PVE/Storage.pm b/PVE/Storage.pm
index 7622b1a..dc4c330 100755
--- a/PVE/Storage.pm
+++ b/PVE/Storage.pm
@@ -831,7 +831,7 @@ sub deactivate_storage {
 }
 
 sub activate_volumes {
-    my ($cfg, $vollist) = @_;
+    my ($cfg, $vollist, $snapname) = @_;
 
     return if !($vollist && scalar(@$vollist));
 
@@ -849,12 +849,12 @@ sub activate_volumes {
 	my ($storeid, $volname) = parse_volume_id($volid);
 	my $scfg = storage_config($cfg, $storeid);
 	my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
-	$plugin->activate_volume($storeid, $scfg, $volname, $cache);
+	$plugin->activate_volume($storeid, $scfg, $volname, $cache, $snapname);
     }
 }
 
 sub deactivate_volumes {
-    my ($cfg, $vollist) = @_;
+    my ($cfg, $vollist, $snapname) = @_;
 
     return if !($vollist && scalar(@$vollist));
 
@@ -868,7 +868,7 @@ sub deactivate_volumes {
 	my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
 
 	eval {
-	    $plugin->deactivate_volume($storeid, $scfg, $volname, $cache);
+	    $plugin->deactivate_volume($storeid, $scfg, $volname, $cache, $snapname);
 	};
 	if (my $err = $@) {
 	    warn $err;
diff --git a/PVE/Storage/DRBDPlugin.pm b/PVE/Storage/DRBDPlugin.pm
index c4a5ee1..29f088e 100644
--- a/PVE/Storage/DRBDPlugin.pm
+++ b/PVE/Storage/DRBDPlugin.pm
@@ -296,7 +296,9 @@ sub deactivate_storage {
 }
 
 sub activate_volume {
-    my ($class, $storeid, $scfg, $volname, $cache) = @_;
+    my ($class, $storeid, $scfg, $volname, $cache, $snapname) = @_;
+
+    die "Snapshot not implemented on DRBD\n" if $snapname;
 
     my $path = $class->path($scfg, $volname);
     
@@ -340,7 +342,9 @@ sub activate_volume {
 }
 
 sub deactivate_volume {
-    my ($class, $storeid, $scfg, $volname, $cache) = @_;
+    my ($class, $storeid, $scfg, $volname, $cache, $snapname) = @_;
+
+    die "Snapshot not implemented on DRBD\n" if $snapname;
 
     return undef; # fixme: should we unassign ?
 
diff --git a/PVE/Storage/GlusterfsPlugin.pm b/PVE/Storage/GlusterfsPlugin.pm
index dee34c3..80e5152 100644
--- a/PVE/Storage/GlusterfsPlugin.pm
+++ b/PVE/Storage/GlusterfsPlugin.pm
@@ -300,13 +300,13 @@ sub deactivate_storage {
 }
 
 sub activate_volume {
-    my ($class, $storeid, $scfg, $volname, $cache) = @_;
+    my ($class, $storeid, $scfg, $volname, $cache, $snapname) = @_;
 
     # do nothing by default
 }
 
 sub deactivate_volume {
-    my ($class, $storeid, $scfg, $volname, $cache) = @_;
+    my ($class, $storeid, $scfg, $volname, $cache, $snapname) = @_;
 
     # do nothing by default
 }
diff --git a/PVE/Storage/ISCSIDirectPlugin.pm b/PVE/Storage/ISCSIDirectPlugin.pm
index cece023..2d3b8e5 100644
--- a/PVE/Storage/ISCSIDirectPlugin.pm
+++ b/PVE/Storage/ISCSIDirectPlugin.pm
@@ -184,12 +184,12 @@ sub deactivate_storage {
 }
 
 sub activate_volume {
-    my ($class, $storeid, $scfg, $volname, $cache) = @_;
+    my ($class, $storeid, $scfg, $volname, $cache, $snapname) = @_;
     return 1;
 }
 
 sub deactivate_volume {
-    my ($class, $storeid, $scfg, $volname, $cache) = @_;
+    my ($class, $storeid, $scfg, $volname, $cache, $snapname) = @_;
     return 1;
 }
 
diff --git a/PVE/Storage/LVMPlugin.pm b/PVE/Storage/LVMPlugin.pm
index e59c4a9..8df74f6 100644
--- a/PVE/Storage/LVMPlugin.pm
+++ b/PVE/Storage/LVMPlugin.pm
@@ -421,9 +421,9 @@ sub deactivate_storage {
 }
 
 sub activate_volume {
-    my ($class, $storeid, $scfg, $volname, $cache) = @_;
+    my ($class, $storeid, $scfg, $volname, $cache, $snapname) = @_;
     #fix me lvmchange is not provided on
-    my $path = $class->path($scfg, $volname);
+    my $path = $class->path($scfg, $volname, $snapname);
 
     my $lvm_activate_mode = 'ey';
 
@@ -432,9 +432,9 @@ sub activate_volume {
 }
 
 sub deactivate_volume {
-    my ($class, $storeid, $scfg, $volname, $cache) = @_;
+    my ($class, $storeid, $scfg, $volname, $cache, $snapname) = @_;
 
-    my $path = $class->path($scfg, $volname);
+    my $path = $class->path($scfg, $volname, $snapname);
     return if ! -b $path;
 
     my $cmd = ['/sbin/lvchange', '-aln', $path];
diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
index a245192..087c469 100644
--- a/PVE/Storage/Plugin.pm
+++ b/PVE/Storage/Plugin.pm
@@ -831,9 +831,9 @@ sub deactivate_storage {
 }
 
 sub activate_volume {
-    my ($class, $storeid, $scfg, $volname, $cache) = @_;
+    my ($class, $storeid, $scfg, $volname, $cache, $snapname) = @_;
 
-    my $path = $class->filesystem_path($scfg, $volname);
+    my $path = $class->filesystem_path($scfg, $volname, $snapname);
 
     # check is volume exists
     if ($scfg->{path}) {
@@ -844,7 +844,7 @@ sub activate_volume {
 }
 
 sub deactivate_volume {
-    my ($class, $storeid, $scfg, $volname, $cache) = @_;
+    my ($class, $storeid, $scfg, $volname, $cache, $snapname) = @_;
 
     # do nothing by default
 }
diff --git a/PVE/Storage/RBDPlugin.pm b/PVE/Storage/RBDPlugin.pm
index 4fe6345..7793772 100644
--- a/PVE/Storage/RBDPlugin.pm
+++ b/PVE/Storage/RBDPlugin.pm
@@ -489,16 +489,18 @@ sub deactivate_storage {
 }
 
 sub activate_volume {
-    my ($class, $storeid, $scfg, $volname, $cache) = @_;
+    my ($class, $storeid, $scfg, $volname, $cache, $snapname) = @_;
 
     return 1 if !$scfg->{krbd};
 
     my ($vtype, $name, $vmid) = $class->parse_volname($volname);
     my $pool =  $scfg->{pool} ? $scfg->{pool} : 'rbd';
 
-    my $path = "/dev/rbd/$pool/$name";
+    my $path = "/dev/rbd/$pool/$name"; 
+    $path .= '@'.$snapname if $snapname;
     return if -b $path;
 
+    $name .= '@'.$snapname if $snapname;
     my $cmd = &$rbd_cmd($scfg, $storeid, 'map', $name);
     run_rbd_command($cmd, errmsg => "can't mount rbd volume $name");
 
@@ -506,7 +508,7 @@ sub activate_volume {
 }
 
 sub deactivate_volume {
-    my ($class, $storeid, $scfg, $volname, $cache) = @_;
+    my ($class, $storeid, $scfg, $volname, $cache, $snapname) = @_;
 
     return 1 if !$scfg->{krbd};
 
@@ -514,6 +516,7 @@ sub deactivate_volume {
     my $pool =  $scfg->{pool} ? $scfg->{pool} : 'rbd';
 
     my $path = "/dev/rbd/$pool/$name";
+    $path .= '@'.$snapname if $snapname;
     return if ! -b $path;
 
     my $cmd = &$rbd_cmd($scfg, $storeid, 'unmap', $path);
diff --git a/PVE/Storage/SheepdogPlugin.pm b/PVE/Storage/SheepdogPlugin.pm
index 4241742..6981df8 100644
--- a/PVE/Storage/SheepdogPlugin.pm
+++ b/PVE/Storage/SheepdogPlugin.pm
@@ -345,12 +345,12 @@ sub deactivate_storage {
 }
 
 sub activate_volume {
-    my ($class, $storeid, $scfg, $volname, $cache) = @_;
+    my ($class, $storeid, $scfg, $volname, $cache, $snapname) = @_;
     return 1;
 }
 
 sub deactivate_volume {
-    my ($class, $storeid, $scfg, $volname, $cache) = @_;
+    my ($class, $storeid, $scfg, $volname, $cache, $snapname) = @_;
     return 1;
 }
 
diff --git a/PVE/Storage/ZFSPoolPlugin.pm b/PVE/Storage/ZFSPoolPlugin.pm
index 880d504..c1d3758 100644
--- a/PVE/Storage/ZFSPoolPlugin.pm
+++ b/PVE/Storage/ZFSPoolPlugin.pm
@@ -505,12 +505,12 @@ sub deactivate_storage {
 }
 
 sub activate_volume {
-    my ($class, $storeid, $scfg, $volname, $cache) = @_;
+    my ($class, $storeid, $scfg, $volname, $cache, $snapname) = @_;
     return 1;
 }
 
 sub deactivate_volume {
-    my ($class, $storeid, $scfg, $volname, $cache) = @_;
+    my ($class, $storeid, $scfg, $volname, $cache, $snapname) = @_;
     return 1;
 }
 
-- 
2.1.4





More information about the pve-devel mailing list