]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Storage.pm
iSCSI ipv6 support
[pve-storage.git] / PVE / Storage.pm
index 55af5ee47efdf014d544eab4b7db76ff6a8c11f4..927219ab878fd99287973c5cccece722eb80eb40 100755 (executable)
@@ -2,6 +2,7 @@ package PVE::Storage;
 
 use strict;
 use warnings;
+use Data::Dumper;
 
 use POSIX;
 use IO::Select;
@@ -11,7 +12,7 @@ use File::Path;
 use Cwd 'abs_path';
 use Socket;
 
-use PVE::Tools qw(run_command file_read_firstline);
+use PVE::Tools qw(run_command file_read_firstline $IPV6RE);
 use PVE::Cluster qw(cfs_read_file cfs_lock_file);
 use PVE::Exception qw(raise_param_exc);
 use PVE::JSONSchema;
@@ -289,6 +290,9 @@ sub parse_volname {
     my $scfg = storage_config($cfg, $storeid);
 
     my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
+
+    # returns ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format)
+
     return $plugin->parse_volname($volname);
 }
 
@@ -612,7 +616,7 @@ sub vdisk_free {
     # lock shared storage
     $plugin->cluster_lock_storage($storeid, $scfg->{shared}, undef, sub {
 
-       my ($vtype, $name, $vmid, undef, undef, $isBase) =
+       my ($vtype, $name, $vmid, undef, undef, $isBase, $format) =
            $plugin->parse_volname($volname);
        if ($isBase) {
            my $vollist = $plugin->list_images($storeid, $scfg);
@@ -632,7 +636,7 @@ sub vdisk_free {
                }
            }
        }
-       $cleanup_worker = $plugin->free_image($storeid, $scfg, $volname, $isBase);
+       $cleanup_worker = $plugin->free_image($storeid, $scfg, $volname, $isBase, $format);
     });
 
     return if !$cleanup_worker;
@@ -982,17 +986,19 @@ sub scan_nfs {
 
 sub scan_zfs {
 
-    my $cmd = ['zpool',  'list', '-H', '-o', 'name,size,free'];
+    my $cmd = ['zfs',  'list', '-t', 'filesystem', '-H', '-o', 'name,avail,used'];
 
     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 ($pool, $size_str, $used_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 };
+           my $used = PVE::Storage::ZFSPoolPlugin::zfs_parse_size($used_str);
+           # ignore subvolumes generated by our ZFSPoolPlugin
+           return if $pool =~ m!/subvol-\d+-[^/]+$!; 
+           push @$res, { pool => $pool, size => $size, free => $size-$used };
        }
     });
 
@@ -1002,12 +1008,11 @@ sub scan_zfs {
 sub resolv_portal {
     my ($portal, $noerr) = @_;
 
-    if ($portal =~ m/^([^:]+)(:(\d+))?$/) {
-       my $server = $1;
-       my $port = $3;
-
+    my ($server, $port) = PVE::Tools::parse_host_and_port($portal);
+    if ($server) {
        if (my $ip = resolv_server($server)) {
            $server = $ip;
+           $server = "[$server]" if $server =~ /^$IPV6RE$/;
            return $port ? "$server:$port" : $server;
        }
     }