]> git.proxmox.com Git - pve-storage.git/commitdiff
Storage Plugins: extend clone_image by snap parameter and add support to RBDPlugin
authorStefan Priebe <s.priebe@profihost.ag>
Fri, 4 Jul 2014 08:30:54 +0000 (10:30 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 17 Jul 2014 05:54:36 +0000 (07:54 +0200)
Signed-off-by: Stefan Priebe <s.priebe@profihost.ag>
PVE/Storage/ISCSIDirectPlugin.pm
PVE/Storage/ISCSIPlugin.pm
PVE/Storage/LVMPlugin.pm
PVE/Storage/Plugin.pm
PVE/Storage/RBDPlugin.pm
PVE/Storage/SheepdogPlugin.pm
PVE/Storage/ZFSPlugin.pm

index cc6a8c3148d7698cf16021b3226c9145d9c50ac4..c957aded0a9bc03362fc7e8e08042fe14d4d3d4d 100644 (file)
@@ -104,7 +104,7 @@ sub create_base {
 }
 
 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";
 }
index 0fe8d697134fb62bc9e2bb8adbf40f9f41ba27a0..e5bb7bb4d31ce1cc5344792c74af120de7dc3dc5 100644 (file)
@@ -294,7 +294,7 @@ sub create_base {
 }
 
 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";
 }
index ff2a6ecd28f00e72272e33fcc8cd88ce160ee9ee..cbd40397cdfe0feee9317df81fe17ea56ac1cf2b 100644 (file)
@@ -241,7 +241,7 @@ sub create_base {
 }
 
 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";
 }
index a80aba453610ce8a74ca92a0caef0cec7cc88e5f..15c23d4fe17c880c74ae07b503550dc9b084704f 100644 (file)
@@ -487,7 +487,7 @@ my $find_free_diskname = sub {
 };
 
 sub clone_image {
-    my ($class, $scfg, $storeid, $volname, $vmid) = @_;
+    my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_;
 
     # this only works for file based storage types
     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 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');
     $imagedir .= "/$vmid";
index 7e28744a75f418574380e43a2964acbbf2570b89..b74833627e10bd2838e75380574118d84a2150a6 100644 (file)
@@ -340,20 +340,31 @@ sub create_base {
 }
 
 sub clone_image {
-    my ($class, $scfg, $storeid, $volname, $vmid) = @_;
+    my ($class, $scfg, $storeid, $volname, $vmid, $snapname) = @_;
 
     my $snap = '__base__';
+    $snap = $snapname if length $snapname;
 
     my ($vtype, $basename, $basevmid, undef, undef, $isBase) =
         $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);
 
-    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";
+    $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));
     run_rbd_command($cmd, errmsg => "rbd clone '$basename' error");
index 3bef2a8f16c0667747a5cd0d9983b5044e58f462..8e1ca0c11dbe84d000e5beef08dd3c946d451b1a 100644 (file)
@@ -215,9 +215,9 @@ sub create_base {
 }
 
 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) =
        $class->parse_volname($volname);
index cb733d156bf54676850d2742ce410139f57e24a8..b47f8148ade58960fb16f8d851b4282b8929eb63 100644 (file)
@@ -449,9 +449,9 @@ sub create_base {
 }
 
 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) =
         $class->parse_volname($volname);