]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Storage.pm
iscsidirect : add volume_snapshot_delete
[pve-storage.git] / PVE / Storage.pm
index 99f09da56c24d004ccd80b9b6738a2a735fd2885..2dfd56157bd6da59b1e7f0b35482701f057d16c6 100755 (executable)
@@ -21,12 +21,20 @@ use PVE::Storage::DirPlugin;
 use PVE::Storage::LVMPlugin;
 use PVE::Storage::NFSPlugin;
 use PVE::Storage::ISCSIPlugin;
+use PVE::Storage::RBDPlugin;
+use PVE::Storage::SheepdogPlugin;
+use PVE::Storage::ISCSIDirectPlugin;
+use PVE::Storage::NexentaPlugin;
 
 # load and initialize all plugins
 PVE::Storage::DirPlugin->register();
 PVE::Storage::LVMPlugin->register();
 PVE::Storage::NFSPlugin->register();
 PVE::Storage::ISCSIPlugin->register();
+PVE::Storage::RBDPlugin->register();
+PVE::Storage::SheepdogPlugin->register();
+PVE::Storage::ISCSIDirectPlugin->register();
+PVE::Storage::NexentaPlugin->register();
 PVE::Storage::Plugin->init();
 
 my $UDEVADM = '/sbin/udevadm';
@@ -100,6 +108,81 @@ sub file_size_info {
     return PVE::Storage::Plugin::file_size_info($filename, $timeout);
 }
 
+sub volume_size_info {
+    my ($cfg, $volid, $timeout) = @_;
+
+    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_size_info($scfg, $storeid, $volname, $timeout);
+    } elsif ($volid =~ m|^(/.+)$| && -e $volid) {
+       return file_size_info($volid, $timeout);
+    } else {
+       return 0;
+    }
+}
+
+sub volume_resize {
+    my ($cfg, $volid, $size, $running) = @_;
+
+    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_resize($scfg, $storeid, $volname, $size, $running);
+    } elsif ($volid =~ m|^(/.+)$| && -e $volid) {
+        die "resize device is not possible";
+    } else {
+        die "can't resize";
+    }
+}
+
+sub volume_snapshot {
+    my ($cfg, $volid, $snap, $running) = @_;
+
+    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_snapshot($scfg, $storeid, $volname, $snap, $running);
+    } elsif ($volid =~ m|^(/.+)$| && -e $volid) {
+        die "snapshot device is not possible";
+    } else {
+        die "can't snapshot";
+    }
+}
+
+sub volume_snapshot_rollback {
+    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_snapshot_rollback($scfg, $storeid, $volname, $snap);
+    } elsif ($volid =~ m|^(/.+)$| && -e $volid) {
+        die "snapshot rollback device is not possible";
+    } else {
+        die "can't snapshot";
+    }
+}
+
+sub volume_snapshot_delete {
+    my ($cfg, $volid, $snap, $running) = @_;
+
+    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_snapshot_rollback_delete($scfg, $storeid, $volname, $snap, $running);
+    } elsif ($volid =~ m|^(/.+)$| && -e $volid) {
+        die "snapshot delete device is not possible";
+    } else {
+        die "can't delete snapshot";
+    }
+}
+
 sub get_image_dir {
     my ($cfg, $storeid, $vmid) = @_;
 
@@ -233,22 +316,22 @@ sub path {
     my $scfg = storage_config($cfg, $storeid);
 
     my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
-    my ($path, $owner, $vtype) = $plugin->path($scfg, $volname);
+    my ($path, $owner, $vtype) = $plugin->path($scfg, $volname, $storeid);
     return wantarray ? ($path, $owner, $vtype) : $path;
 }
 
 sub storage_migrate {
     my ($cfg, $volid, $target_host, $target_storeid, $target_volname) = @_;
 
-    my ($storeid, $volname) = parse_volume_id ($volid);
+    my ($storeid, $volname) = parse_volume_id($volid);
     $target_volname = $volname if !$target_volname;
 
-    my $scfg = storage_config ($cfg, $storeid);
+    my $scfg = storage_config($cfg, $storeid);
 
     # no need to migrate shared content
     return if $storeid eq $target_storeid && $scfg->{shared};
 
-    my $tcfg = storage_config ($cfg, $target_storeid);
+    my $tcfg = storage_config($cfg, $target_storeid);
 
     my $target_volid = "${target_storeid}:${target_volname}";
 
@@ -266,8 +349,8 @@ sub storage_migrate {
 
            my $src_plugin = PVE::Storage::Plugin->lookup($scfg->{type});
            my $dst_plugin = PVE::Storage::Plugin->lookup($tcfg->{type});
-           my $src = $src_plugin->path($scfg, $volid);
-           my $dst = $dst_plugin->path($tcfg, $target_volid);
+           my $src = $src_plugin->path($scfg, $volname, $storeid);
+           my $dst = $dst_plugin->path($tcfg, $target_volname, $target_storeid);
 
            my $dirname = dirname($dst);
 
@@ -441,6 +524,7 @@ sub template_list {
     return $res;
 }
 
+
 sub vdisk_list {
     my ($cfg, $storeid, $vmid, $vollist) = @_;
 
@@ -500,9 +584,11 @@ sub uevent_seqnum {
     return $seqnum;
 }
 
-sub __activate_storage_full {
+sub activate_storage {
     my ($cfg, $storeid, $cache) = @_;
 
+    $cache = {} if !$cache;
+
     my $scfg = storage_check_enabled($cfg, $storeid);
 
     return if $cache->{activated}->{$storeid};
@@ -513,7 +599,11 @@ sub __activate_storage_full {
 
     if ($scfg->{base}) {
        my ($baseid, undef) = parse_volume_id ($scfg->{base});
-       __activate_storage_full ($cfg, $baseid, $cache);
+       activate_storage($cfg, $baseid, $cache);
+    }
+
+    if (!$plugin->check_connection($storeid, $scfg)) {
+       die "storage '$storeid' is not online\n";
     }
 
     $plugin->activate_storage($storeid, $scfg, $cache);
@@ -536,19 +626,10 @@ sub activate_storage_list {
     $cache = {} if !$cache;
 
     foreach my $storeid (@$storeid_list) {
-       __activate_storage_full ($cfg, $storeid, $cache);
+       activate_storage($cfg, $storeid, $cache);
     }
 }
 
-sub activate_storage {
-    my ($cfg, $storeid) = @_;
-
-    my $cache = {};
-
-    __activate_storage_full ($cfg, $storeid, $cache);
-}
-
-
 sub deactivate_storage {
     my ($cfg, $storeid) = @_;
 
@@ -640,14 +721,20 @@ sub storage_info {
 
     my $cache = {};
 
-    eval { activate_storage_list($cfg, $slist, $cache); };
-
     foreach my $storeid (keys %$ids) {
        my $scfg = $ids->{$storeid};
        next if !$info->{$storeid};
 
+       eval { activate_storage($cfg, $storeid, $cache); };
+       if (my $err = $@) {
+           warn $err;
+           next;
+       }
+
        my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
-       my ($total, $avail, $used, $active) = $plugin->status($storeid, $scfg, $cache);
+       my ($total, $avail, $used, $active);
+       eval { ($total, $avail, $used, $active) = $plugin->status($storeid, $scfg, $cache); };
+       warn $@ if $@;
        next if !$active;
        $info->{$storeid}->{total} = $total; 
        $info->{$storeid}->{avail} = $avail;