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:
committed by
Dietmar Maurer
parent
948a2dd0f1
commit
02e797b8e1
@ -831,7 +831,7 @@ sub deactivate_storage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub activate_volumes {
|
sub activate_volumes {
|
||||||
my ($cfg, $vollist) = @_;
|
my ($cfg, $vollist, $snapname) = @_;
|
||||||
|
|
||||||
return if !($vollist && scalar(@$vollist));
|
return if !($vollist && scalar(@$vollist));
|
||||||
|
|
||||||
@ -849,12 +849,12 @@ sub activate_volumes {
|
|||||||
my ($storeid, $volname) = parse_volume_id($volid);
|
my ($storeid, $volname) = parse_volume_id($volid);
|
||||||
my $scfg = storage_config($cfg, $storeid);
|
my $scfg = storage_config($cfg, $storeid);
|
||||||
my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
|
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 {
|
sub deactivate_volumes {
|
||||||
my ($cfg, $vollist) = @_;
|
my ($cfg, $vollist, $snapname) = @_;
|
||||||
|
|
||||||
return if !($vollist && scalar(@$vollist));
|
return if !($vollist && scalar(@$vollist));
|
||||||
|
|
||||||
@ -868,7 +868,7 @@ sub deactivate_volumes {
|
|||||||
my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
|
my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
|
||||||
|
|
||||||
eval {
|
eval {
|
||||||
$plugin->deactivate_volume($storeid, $scfg, $volname, $cache);
|
$plugin->deactivate_volume($storeid, $scfg, $volname, $snapname, $cache);
|
||||||
};
|
};
|
||||||
if (my $err = $@) {
|
if (my $err = $@) {
|
||||||
warn $err;
|
warn $err;
|
||||||
|
|||||||
@ -296,7 +296,9 @@ sub deactivate_storage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub activate_volume {
|
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);
|
my $path = $class->path($scfg, $volname);
|
||||||
|
|
||||||
@ -340,7 +342,9 @@ sub activate_volume {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub deactivate_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 ?
|
return undef; # fixme: should we unassign ?
|
||||||
|
|
||||||
|
|||||||
@ -300,13 +300,13 @@ sub deactivate_storage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub activate_volume {
|
sub activate_volume {
|
||||||
my ($class, $storeid, $scfg, $volname, $cache) = @_;
|
my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
|
||||||
|
|
||||||
# do nothing by default
|
# do nothing by default
|
||||||
}
|
}
|
||||||
|
|
||||||
sub deactivate_volume {
|
sub deactivate_volume {
|
||||||
my ($class, $storeid, $scfg, $volname, $cache) = @_;
|
my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
|
||||||
|
|
||||||
# do nothing by default
|
# do nothing by default
|
||||||
}
|
}
|
||||||
|
|||||||
@ -184,12 +184,18 @@ sub deactivate_storage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub activate_volume {
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub deactivate_volume {
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -421,9 +421,9 @@ sub deactivate_storage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub activate_volume {
|
sub activate_volume {
|
||||||
my ($class, $storeid, $scfg, $volname, $cache) = @_;
|
my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
|
||||||
#fix me lvmchange is not provided on
|
#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';
|
my $lvm_activate_mode = 'ey';
|
||||||
|
|
||||||
@ -432,9 +432,9 @@ sub activate_volume {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub deactivate_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;
|
return if ! -b $path;
|
||||||
|
|
||||||
my $cmd = ['/sbin/lvchange', '-aln', $path];
|
my $cmd = ['/sbin/lvchange', '-aln', $path];
|
||||||
|
|||||||
@ -832,9 +832,9 @@ sub deactivate_storage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub activate_volume {
|
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
|
# check is volume exists
|
||||||
if ($scfg->{path}) {
|
if ($scfg->{path}) {
|
||||||
@ -845,7 +845,7 @@ sub activate_volume {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub deactivate_volume {
|
sub deactivate_volume {
|
||||||
my ($class, $storeid, $scfg, $volname, $cache) = @_;
|
my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
|
||||||
|
|
||||||
# do nothing by default
|
# do nothing by default
|
||||||
}
|
}
|
||||||
|
|||||||
@ -489,7 +489,7 @@ sub deactivate_storage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub activate_volume {
|
sub activate_volume {
|
||||||
my ($class, $storeid, $scfg, $volname, $cache) = @_;
|
my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
|
||||||
|
|
||||||
return 1 if !$scfg->{krbd};
|
return 1 if !$scfg->{krbd};
|
||||||
|
|
||||||
@ -497,8 +497,10 @@ sub activate_volume {
|
|||||||
my $pool = $scfg->{pool} ? $scfg->{pool} : 'rbd';
|
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;
|
return if -b $path;
|
||||||
|
|
||||||
|
$name .= '@'.$snapname if $snapname;
|
||||||
my $cmd = &$rbd_cmd($scfg, $storeid, 'map', $name);
|
my $cmd = &$rbd_cmd($scfg, $storeid, 'map', $name);
|
||||||
run_rbd_command($cmd, errmsg => "can't mount rbd volume $name");
|
run_rbd_command($cmd, errmsg => "can't mount rbd volume $name");
|
||||||
|
|
||||||
@ -506,7 +508,7 @@ sub activate_volume {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub deactivate_volume {
|
sub deactivate_volume {
|
||||||
my ($class, $storeid, $scfg, $volname, $cache) = @_;
|
my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
|
||||||
|
|
||||||
return 1 if !$scfg->{krbd};
|
return 1 if !$scfg->{krbd};
|
||||||
|
|
||||||
@ -514,6 +516,7 @@ sub deactivate_volume {
|
|||||||
my $pool = $scfg->{pool} ? $scfg->{pool} : 'rbd';
|
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;
|
return if ! -b $path;
|
||||||
|
|
||||||
my $cmd = &$rbd_cmd($scfg, $storeid, 'unmap', $path);
|
my $cmd = &$rbd_cmd($scfg, $storeid, 'unmap', $path);
|
||||||
|
|||||||
@ -345,12 +345,12 @@ sub deactivate_storage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub activate_volume {
|
sub activate_volume {
|
||||||
my ($class, $storeid, $scfg, $volname, $cache) = @_;
|
my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub deactivate_volume {
|
sub deactivate_volume {
|
||||||
my ($class, $storeid, $scfg, $volname, $cache) = @_;
|
my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -352,6 +352,29 @@ sub volume_has_feature {
|
|||||||
|
|
||||||
sub activate_storage {
|
sub activate_storage {
|
||||||
my ($class, $storeid, $scfg, $cache) = @_;
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -505,12 +505,12 @@ sub deactivate_storage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub activate_volume {
|
sub activate_volume {
|
||||||
my ($class, $storeid, $scfg, $volname, $cache) = @_;
|
my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub deactivate_volume {
|
sub deactivate_volume {
|
||||||
my ($class, $storeid, $scfg, $volname, $cache) = @_;
|
my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user