5
0
mirror of git://git.proxmox.com/git/pve-storage.git synced 2025-01-14 19:24:33 +03:00

Storage Plugins: extend clone_image by snap parameter and add support to RBDPlugin

Signed-off-by: Stefan Priebe <s.priebe@profihost.ag>
This commit is contained in:
Stefan Priebe 2014-07-04 10:30:54 +02:00 committed by Dietmar Maurer
parent 2362bc8798
commit f236eaf80e
7 changed files with 25 additions and 12 deletions

View File

@ -104,7 +104,7 @@ sub create_base {
} }
sub clone_image { sub clone_image {
my ($class, $scfg, $storeid, $volname, $vmid) = @_; my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_;
die "can't clone images in iscsi storage\n"; die "can't clone images in iscsi storage\n";
} }

View File

@ -294,7 +294,7 @@ sub create_base {
} }
sub clone_image { sub clone_image {
my ($class, $scfg, $storeid, $volname, $vmid) = @_; my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_;
die "can't clone images in iscsi storage\n"; die "can't clone images in iscsi storage\n";
} }

View File

@ -241,7 +241,7 @@ sub create_base {
} }
sub clone_image { sub clone_image {
my ($class, $scfg, $storeid, $volname, $vmid) = @_; my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_;
die "can't clone images in lvm storage\n"; die "can't clone images in lvm storage\n";
} }

View File

@ -487,7 +487,7 @@ my $find_free_diskname = sub {
}; };
sub clone_image { sub clone_image {
my ($class, $scfg, $storeid, $volname, $vmid) = @_; my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_;
# this only works for file based storage types # this only works for file based storage types
die "storage definintion has no path\n" if !$scfg->{path}; die "storage definintion has no path\n" if !$scfg->{path};
@ -497,7 +497,9 @@ sub clone_image {
die "clone_image on wrong vtype '$vtype'\n" if $vtype ne 'images'; die "clone_image on wrong vtype '$vtype'\n" if $vtype ne 'images';
die "clone_image onyl works on base images\n" if !$isBase; die "this storage type does not support clone_image on snapshot\n" if $snap;
die "clone_image only works on base images\n" if !$isBase;
my $imagedir = $class->get_subdir($scfg, 'images'); my $imagedir = $class->get_subdir($scfg, 'images');
$imagedir .= "/$vmid"; $imagedir .= "/$vmid";

View File

@ -340,20 +340,31 @@ sub create_base {
} }
sub clone_image { sub clone_image {
my ($class, $scfg, $storeid, $volname, $vmid) = @_; my ($class, $scfg, $storeid, $volname, $vmid, $snapname) = @_;
my $snap = '__base__'; my $snap = '__base__';
$snap = $snapname if length $snapname;
my ($vtype, $basename, $basevmid, undef, undef, $isBase) = my ($vtype, $basename, $basevmid, undef, undef, $isBase) =
$class->parse_volname($volname); $class->parse_volname($volname);
die "clone_image onyl works on base images\n" if !$isBase; die "$volname is not a base image and snapname is not provided\n" if !$isBase && !length $snapname;
my $name = &$find_free_diskname($storeid, $scfg, $vmid); my $name = &$find_free_diskname($storeid, $scfg, $vmid);
warn "clone $volname: $basename to $name\n"; warn "clone $volname: $basename snapname $snap to $name\n";
if (length $snapname) {
my (undef, undef, undef, $protected) = rbd_volume_info($scfg, $storeid, $volname, $snapname);
if (!$protected){
my $cmd = &$rbd_cmd($scfg, $storeid, 'snap', 'protect', $volname, '--snap', $snapname);
run_rbd_command($cmd, errmsg => "rbd protect $volname snap $snapname error");
}
}
my $newvol = "$basename/$name"; my $newvol = "$basename/$name";
$newvol = $name if length $snapname;
my $cmd = &$rbd_cmd($scfg, $storeid, 'clone', &$add_pool_to_disk($scfg, $basename), '--snap', $snap, &$add_pool_to_disk($scfg, $name)); my $cmd = &$rbd_cmd($scfg, $storeid, 'clone', &$add_pool_to_disk($scfg, $basename), '--snap', $snap, &$add_pool_to_disk($scfg, $name));
run_rbd_command($cmd, errmsg => "rbd clone '$basename' error"); run_rbd_command($cmd, errmsg => "rbd clone '$basename' error");

View File

@ -215,9 +215,9 @@ sub create_base {
} }
sub clone_image { sub clone_image {
my ($class, $scfg, $storeid, $volname, $vmid) = @_; my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_;
my $snap = '__base__'; $snap ||= '__base__';
my ($vtype, $basename, $basevmid, undef, undef, $isBase) = my ($vtype, $basename, $basevmid, undef, undef, $isBase) =
$class->parse_volname($volname); $class->parse_volname($volname);

View File

@ -449,9 +449,9 @@ sub create_base {
} }
sub clone_image { sub clone_image {
my ($class, $scfg, $storeid, $volname, $vmid) = @_; my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_;
my $snap = '__base__'; $snap ||= '__base__';
my ($vtype, $basename, $basevmid, undef, undef, $isBase) = my ($vtype, $basename, $basevmid, undef, undef, $isBase) =
$class->parse_volname($volname); $class->parse_volname($volname);