]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Storage/Plugin.pm
plugin : has_feature : copy
[pve-storage.git] / PVE / Storage / Plugin.pm
index de2818cd62d0aab634258d27c54aba26ec123ed7..5ff114a5364c9562daed51755d96ed88228b2e14 100644 (file)
@@ -2,7 +2,7 @@ package PVE::Storage::Plugin;
 
 use strict;
 use warnings;
-use Cwd;
+use File::chdir;
 use File::Path;
 use PVE::Tools qw(run_command);
 use PVE::JSONSchema qw(get_standard_option);
@@ -506,10 +506,9 @@ sub clone_image {
 
     my $path = $class->path($scfg, $newvol);
 
-    # Note: we use relative paths, so we need to call chdir before qemu-img
-    my $oldcwd = cwd();
+    # Note: we use relative paths, so we need to call chdir before qemu-img  
     eval {
-       chdir $imagedir;
+       local $CWD = $imagedir;
 
        my $cmd = ['/usr/bin/qemu-img', 'create', '-b', "../$basevmid/$basename", 
                   '-f', 'qcow2', $path];
@@ -518,8 +517,6 @@ sub clone_image {
     };
     my $err = $@;
 
-    chdir $oldcwd;
-
     die $err if $err;
 
     return $newvol;
@@ -686,16 +683,26 @@ sub volume_has_feature {
 
     my $features = {
         snapshot => { current => { qcow2 => 1}, snap => { qcow2 => 1} },
-        clone => { current => {qcow2 => 1, raw => 1, vmdk => 1} },
+        clone => { base => {qcow2 => 1, raw => 1, vmdk => 1} },
+        copy => { base => {qcow2 => 1, raw => 1, vmdk => 1},
+                 current => {qcow2 => 1, raw => 1, vmdk => 1},
+                 snap => {qcow2 => 1} },
     };
 
-    if ($volname =~ m!^(\d+)/(\S+)$!) {
-        my ($vmid, $name) = ($1, $2);
-        my (undef, $format) = parse_name_dir($name);
-       my $snap = $snapname ? 'snap' : 'current';
-       return 1 if defined($features->{$feature}->{$snap}->{$format});
+    my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) =
+       $class->parse_volname($volname);
+
+    my (undef, $format) = parse_name_dir($name);
 
+    my $key = undef;
+    if($snapname){
+        $key = $snapname
+    }else{
+        $key =  $isBase ? 'base' : 'current';
     }
+
+    return 1 if defined($features->{$feature}->{$key}->{$format});
+
     return undef;
 }