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.
This commit is contained in:
Wolfgang Link
2015-09-18 11:57:07 +02:00
committed by Dietmar Maurer
parent 948a2dd0f1
commit 02e797b8e1
10 changed files with 59 additions and 23 deletions

View File

@ -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;

View File

@ -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 ?

View File

@ -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
}

View File

@ -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;
}

View File

@ -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];

View File

@ -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
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}