]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Storage.pm
pvesm add: pass storage type as first argument
[pve-storage.git] / PVE / Storage.pm
index cea40f1f6644ca0bdc3ebf3de5febf840efb83f3..e46bc7767cafad6209a2e8506de295c0db7ccf3e 100755 (executable)
@@ -26,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::ZFSPoolPlugin;
 use PVE::Storage::ZFSPlugin;
 
 # load and initialize all plugins
@@ -38,8 +38,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::ZFSPoolPlugin->register();
 PVE::Storage::ZFSPlugin->register();
 PVE::Storage::Plugin->init();
 
@@ -138,9 +138,24 @@ sub volume_resize {
         my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
         return $plugin->volume_resize($scfg, $storeid, $volname, $size, $running);
     } elsif ($volid =~ m|^(/.+)$| && -e $volid) {
-        die "resize device is not possible";
+        die "resize file/device '$volid' is not possible\n";
     } else {
-        die "can't resize";
+       die "unable to parse volume ID '$volid'\n";
+    }
+}
+
+sub volume_rollback_is_possible {
+    my ($cfg, $volid, $snap) = @_;
+    
+    my ($storeid, $volname) = parse_volume_id($volid, 1);
+    if ($storeid) {
+        my $scfg = storage_config($cfg, $storeid);
+        my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
+        return $plugin->volume_rollback_is_possible($scfg, $storeid, $volname, $snap);
+    } elsif ($volid =~ m|^(/.+)$| && -e $volid) {
+        die "snapshot rollback file/device '$volid' is not possible\n";
+    } else {
+       die "unable to parse volume ID '$volid'\n";
     }
 }
 
@@ -153,9 +168,9 @@ sub volume_snapshot {
         my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
         return $plugin->volume_snapshot($scfg, $storeid, $volname, $snap, $running);
     } elsif ($volid =~ m|^(/.+)$| && -e $volid) {
-        die "snapshot device is not possible";
+        die "snapshot file/device '$volid' is not possible\n";
     } else {
-        die "can't snapshot";
+       die "unable to parse volume ID '$volid'\n";
     }
 }
 
@@ -166,11 +181,12 @@ sub volume_snapshot_rollback {
     if ($storeid) {
         my $scfg = storage_config($cfg, $storeid);
         my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
+       $plugin->volume_rollback_is_possible($scfg, $storeid, $volname, $snap);
         return $plugin->volume_snapshot_rollback($scfg, $storeid, $volname, $snap);
     } elsif ($volid =~ m|^(/.+)$| && -e $volid) {
-        die "snapshot rollback device is not possible";
+        die "snapshot rollback file/device '$volid' is not possible\n";
     } else {
-        die "can't snapshot";
+       die "unable to parse volume ID '$volid'\n";
     }
 }
 
@@ -183,9 +199,9 @@ sub volume_snapshot_delete {
         my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
         return $plugin->volume_snapshot_delete($scfg, $storeid, $volname, $snap, $running);
     } elsif ($volid =~ m|^(/.+)$| && -e $volid) {
-        die "snapshot delete device is not possible";
+        die "snapshot delete file/device '$volid' is not possible\n";
     } else {
-        die "can't delete snapshot";
+       die "unable to parse volume ID '$volid'\n";
     }
 }
 
@@ -480,7 +496,7 @@ sub storage_migrate {
 }
 
 sub vdisk_clone {
-    my ($cfg, $volid, $vmid) = @_;
+    my ($cfg, $volid, $vmid, $snap) = @_;
 
     my ($storeid, $volname) = parse_volume_id($volid);
 
@@ -492,7 +508,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";
     });
 }
@@ -579,7 +595,7 @@ sub vdisk_free {
                }
            }
        }
-       my $cleanup_worker = $plugin->free_image($storeid, $scfg, $volname, $isBase);
+       $cleanup_worker = $plugin->free_image($storeid, $scfg, $volname, $isBase);
     });
 
     return if !$cleanup_worker;
@@ -911,6 +927,25 @@ sub scan_nfs {
     return $res;
 }
 
+sub scan_zfs {
+
+    my $cmd = ['zpool',  'list', '-H', '-o', 'name,size,free'];
+
+    my $res = [];
+    run_command($cmd, outfunc => sub {
+       my $line = shift;
+
+       if ($line =~m/^(\S+)\s+(\S+)\s+(\S+)$/) {
+           my ($pool, $size_str, $free_str) = ($1, $2, $3);
+           my $size = PVE::Storage::ZFSPoolPlugin::zfs_parse_size($size_str);
+           my $free = PVE::Storage::ZFSPoolPlugin::zfs_parse_size($free_str);
+           push @$res, { pool => $pool, size => $size, free => $free };
+       }
+    });
+
+    return $res;
+}
+
 sub resolv_portal {
     my ($portal, $noerr) = @_;