]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Storage.pm
pass snapname to vdisk_clone and plugin clone_image
[pve-storage.git] / PVE / Storage.pm
index 3d01e37997bc8728ccf6b73baf7390c3105e3806..3cc9581dfa8f68470c46ff22b33d128a01f55921 100755 (executable)
@@ -1,6 +1,8 @@
 package PVE::Storage;
 
 use strict;
+use warnings;
+
 use POSIX;
 use IO::Select;
 use IO::File;
@@ -24,8 +26,8 @@ use PVE::Storage::ISCSIPlugin;
 use PVE::Storage::RBDPlugin;
 use PVE::Storage::SheepdogPlugin;
 use PVE::Storage::ISCSIDirectPlugin;
-use PVE::Storage::NexentaPlugin;
 use PVE::Storage::GlusterfsPlugin;
+use PVE::Storage::ZFSPlugin;
 
 # load and initialize all plugins
 PVE::Storage::DirPlugin->register();
@@ -35,8 +37,8 @@ PVE::Storage::ISCSIPlugin->register();
 PVE::Storage::RBDPlugin->register();
 PVE::Storage::SheepdogPlugin->register();
 PVE::Storage::ISCSIDirectPlugin->register();
-PVE::Storage::NexentaPlugin->register();
 PVE::Storage::GlusterfsPlugin->register();
+PVE::Storage::ZFSPlugin->register();
 PVE::Storage::Plugin->init();
 
 my $UDEVADM = '/sbin/udevadm';
@@ -259,6 +261,17 @@ sub parse_vmid {
     return int($vmid);
 }
 
+sub parse_volname {
+    my ($cfg, $volid) = @_;
+
+    my ($storeid, $volname) = parse_volume_id($volid);
+
+    my $scfg = storage_config($cfg, $storeid);
+
+    my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
+    return $plugin->parse_volname($volname);
+}
+
 sub parse_volume_id {
     my ($volid, $noerr) = @_;
 
@@ -361,6 +374,27 @@ sub path {
     return wantarray ? ($path, $owner, $vtype) : $path;
 }
 
+sub abs_filesystem_path {
+    my ($cfg, $volid) = @_;
+
+    my $path;
+    if (PVE::Storage::parse_volume_id ($volid, 1)) {
+       PVE::Storage::activate_volumes($cfg, [ $volid ]);
+       $path = PVE::Storage::path($cfg, $volid);
+    } else {
+       if (-f $volid) {
+           my $abspath = abs_path($volid);
+           if ($abspath && $abspath =~ m|^(/.+)$|) {
+               $path = $1; # untaint any path
+           }
+       }
+    }
+
+    die "can't find file '$volid'\n" if !($path && -f $path);
+
+    return $path;
+}
+
 sub storage_migrate {
     my ($cfg, $volid, $target_host, $target_storeid, $target_volname) = @_;
 
@@ -444,7 +478,7 @@ sub storage_migrate {
 }
 
 sub vdisk_clone {
-    my ($cfg, $volid, $vmid) = @_;
+    my ($cfg, $volid, $vmid, $snap) = @_;
 
     my ($storeid, $volname) = parse_volume_id($volid);
 
@@ -456,7 +490,7 @@ sub vdisk_clone {
 
     # lock shared storage
     return $plugin->cluster_lock_storage($storeid, $scfg->{shared}, undef, sub {
-       my $volname = $plugin->clone_image($scfg, $storeid, $volname, $vmid);
+       my $volname = $plugin->clone_image($scfg, $storeid, $volname, $vmid, $snap);
        return "$storeid:$volname";
     });
 }