From: Wolfgang Link Date: Fri, 18 Sep 2015 09:57:07 +0000 (+0200) Subject: extend functionality to (de)activate_volumes with snapshots X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=02e797b8e10d5fe326c3c054962371e253a11e57;hp=948a2dd0f1d5f1cefc7ac819f522d3e78d7b1ee5;p=pve-storage.git extend functionality to (de)activate_volumes with snapshots this extension provide the capability to activate or deactivate snapshot, so we can use this e.g. for LXC backup in snapshot mode. --- diff --git a/PVE/Storage.pm b/PVE/Storage.pm index 3637de2..c27e9cf 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, $snapname, $cache); } } 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, $snapname, $cache); }; if (my $err = $@) { warn $err; diff --git a/PVE/Storage/DRBDPlugin.pm b/PVE/Storage/DRBDPlugin.pm index c4a5ee1..89dfb62 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, $snapname, $cache) = @_; + + 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, $snapname, $cache) = @_; + + 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..3bae100 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, $snapname, $cache) = @_; # do nothing by default } sub deactivate_volume { - my ($class, $storeid, $scfg, $volname, $cache) = @_; + my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_; # do nothing by default } diff --git a/PVE/Storage/ISCSIDirectPlugin.pm b/PVE/Storage/ISCSIDirectPlugin.pm index cece023..f0c6c53 100644 --- a/PVE/Storage/ISCSIDirectPlugin.pm +++ b/PVE/Storage/ISCSIDirectPlugin.pm @@ -184,12 +184,18 @@ sub deactivate_storage { } sub activate_volume { - my ($class, $storeid, $scfg, $volname, $cache) = @_; + my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_; + + die "volume snapshot is not possible on iscsi device" if $snapname; + return 1; } sub deactivate_volume { - my ($class, $storeid, $scfg, $volname, $cache) = @_; + my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_; + + die "volume snapshot is not possible on iscsi device" if $snapname; + return 1; } diff --git a/PVE/Storage/LVMPlugin.pm b/PVE/Storage/LVMPlugin.pm index e59c4a9..5dc732e 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, $snapname, $cache) = @_; #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, $snapname, $cache) = @_; - 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 c921174..0eb9e73 100644 --- a/PVE/Storage/Plugin.pm +++ b/PVE/Storage/Plugin.pm @@ -832,9 +832,9 @@ sub deactivate_storage { } sub activate_volume { - my ($class, $storeid, $scfg, $volname, $cache) = @_; + my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_; - my $path = $class->filesystem_path($scfg, $volname); + my $path = $class->filesystem_path($scfg, $volname, $snapname); # check is volume exists if ($scfg->{path}) { @@ -845,7 +845,7 @@ sub activate_volume { } sub deactivate_volume { - my ($class, $storeid, $scfg, $volname, $cache) = @_; + my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_; # do nothing by default } diff --git a/PVE/Storage/RBDPlugin.pm b/PVE/Storage/RBDPlugin.pm index 4fe6345..71edc8b 100644 --- a/PVE/Storage/RBDPlugin.pm +++ b/PVE/Storage/RBDPlugin.pm @@ -489,7 +489,7 @@ sub deactivate_storage { } sub activate_volume { - my ($class, $storeid, $scfg, $volname, $cache) = @_; + my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_; return 1 if !$scfg->{krbd}; @@ -497,8 +497,10 @@ sub activate_volume { my $pool = $scfg->{pool} ? $scfg->{pool} : 'rbd'; 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, $snapname, $cache) = @_; 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..527c6c6 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, $snapname, $cache) = @_; return 1; } sub deactivate_volume { - my ($class, $storeid, $scfg, $volname, $cache) = @_; + my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_; return 1; } diff --git a/PVE/Storage/ZFSPlugin.pm b/PVE/Storage/ZFSPlugin.pm index 52e9090..df4c6d7 100644 --- a/PVE/Storage/ZFSPlugin.pm +++ b/PVE/Storage/ZFSPlugin.pm @@ -352,6 +352,29 @@ sub volume_has_feature { sub activate_storage { my ($class, $storeid, $scfg, $cache) = @_; + + return 1; +} + +sub deactivate_storage { + my ($class, $storeid, $scfg, $cache) = @_; + + return 1; +} + +sub activate_volume { + my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_; + + die "unable to activate snapshot from remote zfs storage" if $snapname; + + return 1; +} + +sub deactivate_volume { + my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_; + + die "unable to deactivate snapshot from remote zfs storage" if $snapname; + return 1; } diff --git a/PVE/Storage/ZFSPoolPlugin.pm b/PVE/Storage/ZFSPoolPlugin.pm index 880d504..632645f 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, $snapname, $cache) = @_; return 1; } sub deactivate_volume { - my ($class, $storeid, $scfg, $volname, $cache) = @_; + my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_; return 1; }