]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Storage/ZFSPlugin.pm
drbd: comment that the builtin plugin is depreacated
[pve-storage.git] / PVE / Storage / ZFSPlugin.pm
index 274deaa31b5489b857330ae2b06893159e572605..63b95517adad6a544bd15ba1d06328e1fcf9119a 100644 (file)
@@ -5,12 +5,15 @@ use warnings;
 use IO::File;
 use POSIX;
 use PVE::Tools qw(run_command);
-use PVE::Storage::ZFSDirPlugin;
+use PVE::Storage::ZFSPoolPlugin;
+use PVE::RPCEnvironment;
 
-use base qw(PVE::Storage::ZFSDirPlugin);
+use base qw(PVE::Storage::ZFSPoolPlugin);
 use PVE::Storage::LunCmd::Comstar;
 use PVE::Storage::LunCmd::Istgt;
 use PVE::Storage::LunCmd::Iet;
+use PVE::Storage::LunCmd::LIO;
+
 
 my @ssh_opts = ('-o', 'BatchMode=yes');
 my @ssh_cmd = ('/usr/bin/ssh', @ssh_opts);
@@ -29,7 +32,7 @@ my $lun_cmds = {
 my $zfs_unknown_scsi_provider = sub {
     my ($provider) = @_;
 
-    die "$provider: unknown iscsi provider. Available [comstar, istgt, iet]";
+    die "$provider: unknown iscsi provider. Available [comstar, istgt, iet, LIO]";
 };
 
 my $zfs_get_base = sub {
@@ -41,6 +44,8 @@ my $zfs_get_base = sub {
         return PVE::Storage::LunCmd::Istgt::get_base;
     } elsif ($scfg->{iscsiprovider} eq 'iet') {
         return PVE::Storage::LunCmd::Iet::get_base;
+    } elsif ($scfg->{iscsiprovider} eq 'LIO') {
+        return PVE::Storage::LunCmd::LIO::get_base;
     } else {
         $zfs_unknown_scsi_provider->($scfg->{iscsiprovider});
     }
@@ -49,7 +54,8 @@ my $zfs_get_base = sub {
 sub zfs_request {
     my ($class, $scfg, $timeout, $method, @params) = @_;
 
-    $timeout = 5 if !$timeout;
+    $timeout = PVE::RPCEnvironment->is_worker() ? 60*60 : 10
+       if !$timeout;
 
     my $msg = '';
 
@@ -60,6 +66,8 @@ sub zfs_request {
             $msg = PVE::Storage::LunCmd::Istgt::run_lun_command($scfg, $timeout, $method, @params);
         } elsif ($scfg->{iscsiprovider} eq 'iet') {
             $msg = PVE::Storage::LunCmd::Iet::run_lun_command($scfg, $timeout, $method, @params);
+        } elsif ($scfg->{iscsiprovider} eq 'LIO') {
+            $msg = PVE::Storage::LunCmd::LIO::run_lun_command($scfg, $timeout, $method, @params);
         } else {
             $zfs_unknown_scsi_provider->($scfg->{iscsiprovider});
         }
@@ -90,10 +98,11 @@ sub zfs_request {
 
 sub zfs_get_lu_name {
     my ($class, $scfg, $zvol) = @_;
-    my $object;
 
     my $base = $zfs_get_base->($scfg);
 
+    $zvol = ($class->parse_volname($zvol))[1];
+
     my $object = ($zvol =~ /^.+\/.+/) ? "$base/$zvol" : "$base/$scfg->{pool}/$zvol";
 
     my $lu_name = $class->zfs_request($scfg, undef, 'list_lu', $object);
@@ -150,7 +159,11 @@ sub zfs_get_lun_number {
 
     die "could not find lun_number for guid $guid" if !$guid;
 
-    return $class->zfs_request($scfg, undef, 'list_view', $guid);
+    if ($class->zfs_request($scfg, undef, 'list_view', $guid) =~ /^(\d+)$/) {
+       return $1;
+    }
+
+    die "lun_number for guid $guid is not a number";
 }
 
 # Configuration
@@ -186,6 +199,10 @@ sub properties {
            description => "host group for comstar views",
            type => 'string',
        },
+       lio_tpg => {
+           description => "target portal group for Linux LIO targets",
+           type => 'string',
+       },
     };
 }
 
@@ -202,24 +219,19 @@ sub options {
        sparse => { optional => 1 },
        comstar_hg => { optional => 1 },
        comstar_tg => { optional => 1 },
+       lio_tpg => { optional => 1 },
        content => { optional => 1 },
+       bwlimit => { optional => 1 },
     };
 }
 
 # Storage implementation
 
-sub parse_volname {
-    my ($class, $volname) = @_;
-
-    if ($volname =~ m/^(((base|vm)-(\d+)-\S+)\/)?((base)?(vm)?-(\d+)-\S+)$/) {
-       return ('images', $5, $8, $2, $4, $6);
-    }
-
-    die "unable to parse zfs volume name '$volname'\n";
-}
-
 sub path {
-    my ($class, $scfg, $volname) = @_;
+    my ($class, $scfg, $volname, $storeid, $snapname) = @_;
+
+    die "direct access to snapshots not implemented"
+       if defined($snapname);
 
     my ($vtype, $name, $vmid) = $class->parse_volname($volname);
 
@@ -265,40 +277,35 @@ sub create_base {
 sub clone_image {
     my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_;
 
-    $snap ||= '__base__';
+    my $name = $class->SUPER::clone_image($scfg, $storeid, $volname, $vmid, $snap);
 
-    my ($vtype, $basename, $basevmid, undef, undef, $isBase) =
-        $class->parse_volname($volname);
-
-    die "clone_image only works on base images\n" if !$isBase;
-
-    my $name = $class->zfs_find_free_diskname($storeid, $scfg, $vmid);
+    # get ZFS dataset name from PVE volname
+    my (undef, $clonedname) = $class->parse_volname($name);
 
-    warn "clone $volname: $basename to $name\n";
-
-    $class->zfs_request($scfg, undef, 'clone', "$scfg->{pool}/$basename\@$snap", "$scfg->{pool}/$name");
-
-    my $guid = $class->zfs_create_lu($scfg, $name);
-    $class->zfs_add_lun_mapping_entry($scfg, $name, $guid);
+    my $guid = $class->zfs_create_lu($scfg, $clonedname);
+    $class->zfs_add_lun_mapping_entry($scfg, $clonedname, $guid);
 
     return $name;
 }
 
 sub alloc_image {
     my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
-
+    
     die "unsupported format '$fmt'" if $fmt ne 'raw';
 
     die "illegal name '$name' - sould be 'vm-$vmid-*'\n"
     if $name && $name !~ m/^vm-$vmid-/;
 
-    $name = $class->zfs_find_free_diskname($storeid, $scfg, $vmid) if !$name;
+    my $volname = $name;
 
-    $class->zfs_create_zvol($scfg, $name, $size);
-    my $guid = $class->zfs_create_lu($scfg, $name);
-    $class->zfs_add_lun_mapping_entry($scfg, $name, $guid);
+    $volname = $class->find_free_diskname($storeid, $scfg, $vmid, $fmt) if !$volname;
+    
+    $class->zfs_create_zvol($scfg, $volname, $size);
+    my $guid = $class->zfs_create_lu($scfg, $volname);
+    $class->zfs_add_lun_mapping_entry($scfg, $volname, $guid);
 
-    return $name;
+    return $volname;
 }
 
 sub free_image {
@@ -318,121 +325,30 @@ sub free_image {
     return undef;
 }
 
-sub list_images {
-    my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
-
-    $cache->{zfs} = $class->zfs_list_zvol($scfg) if !$cache->{zfs};
-    my $zfspool = $scfg->{pool};
-    my $res = [];
-
-    if (my $dat = $cache->{zfs}->{$zfspool}) {
-
-       foreach my $image (keys %$dat) {
-
-           my $volname = $dat->{$image}->{name};
-           my $parent = $dat->{$image}->{parent};
-
-           my $volid = undef;
-            if ($parent && $parent =~ m/^(\S+)@(\S+)$/) {
-               my ($basename) = ($1);
-               $volid = "$storeid:$basename/$volname";
-           } else {
-               $volid = "$storeid:$volname";
-           }
-
-           my $owner = $dat->{$volname}->{vmid};
-           if ($vollist) {
-               my $found = grep { $_ eq $volid } @$vollist;
-               next if !$found;
-           } else {
-               next if defined ($vmid) && ($owner ne $vmid);
-           }
-
-           my $info = $dat->{$volname};
-           $info->{volid} = $volid;
-           push @$res, $info;
-       }
-    }
-
-    return $res;
-}
-
-sub status {
-    my ($class, $storeid, $scfg, $cache) = @_;
-
-    my $total = 0;
-    my $free = 0;
-    my $used = 0;
-    my $active = 0;
-
-    eval {
-       ($free, $used) = $class->zfs_get_pool_stats($scfg);
-       $active = 1;
-       $total = $free + $used;
-    };
-    warn $@ if $@;
-
-    return ($total, $free, $used, $active);
-}
-
-sub activate_storage {
-    my ($class, $storeid, $scfg, $cache) = @_;
-    return 1;
-}
-
-sub deactivate_storage {
-    my ($class, $storeid, $scfg, $cache) = @_;
-    return 1;
-}
-
-sub activate_volume {
-    my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
-    return 1;
-}
-
-sub deactivate_volume {
-    my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
-    return 1;
-}
-
-sub volume_size_info {
-    my ($class, $scfg, $storeid, $volname, $timeout) = @_;
-
-    return $class->zfs_get_zvol_size($scfg, $volname);
-}
-
 sub volume_resize {
     my ($class, $scfg, $storeid, $volname, $size, $running) = @_;
 
-    my $new_size = ($size/1024);
+    $volname = ($class->parse_volname($volname))[1];
+
+    my $new_size = $class->SUPER::volume_resize($scfg, $storeid, $volname, $size, $running);
 
-    $class->zfs_request($scfg, undef, 'set', 'volsize=' . $new_size . 'k', "$scfg->{pool}/$volname");
     $class->zfs_resize_lu($scfg, $volname, $new_size);
+
+    return $new_size;
 }
 
-sub volume_snapshot {
+sub volume_snapshot_delete {
     my ($class, $scfg, $storeid, $volname, $snap, $running) = @_;
 
-    $class->zfs_request($scfg, undef, 'snapshot', "$scfg->{pool}/$volname\@$snap");
+    $volname = ($class->parse_volname($volname))[1];
+
+    $class->zfs_request($scfg, undef, 'destroy', "$scfg->{pool}/$volname\@$snap");
 }
 
 sub volume_snapshot_rollback {
     my ($class, $scfg, $storeid, $volname, $snap) = @_;
 
-    # abort rollback if snapshot is not the latest
-    my @params = ('-t', 'snapshot', '-o', 'name', '-s', 'creation');
-    my $text = $class->zfs_request($scfg, undef, 'list', @params);
-    my @snapshots = split(/\n/, $text);
-    my $recentsnap = undef;
-    foreach (@snapshots) {
-        if (/$scfg->{pool}\/$volname/) {
-            s/^.*@//;
-            $recentsnap = $_;
-        }
-    }
-    if ($snap ne $recentsnap) {
-        die "cannot rollback, more recent snapshots exist\n";
-    }
+    $volname = ($class->parse_volname($volname))[1];
 
     $class->zfs_delete_lu($scfg, $volname);
 
@@ -443,10 +359,10 @@ sub volume_snapshot_rollback {
     $class->zfs_add_lun_mapping_entry($scfg, $volname);
 }
 
-sub volume_snapshot_delete {
-    my ($class, $scfg, $storeid, $volname, $snap, $running) = @_;
+sub storage_can_replicate {
+    my ($class, $scfg, $storeid, $format) = @_;
 
-    $class->zfs_request($scfg, undef, 'destroy', "$scfg->{pool}/$volname\@$snap");
+    return 0;
 }
 
 sub volume_has_feature {
@@ -475,4 +391,38 @@ sub volume_has_feature {
     return undef;
 }
 
+sub volume_snapshot_list {
+    my ($class, $scfg, $storeid, $volname) = @_;
+    # return an empty array if dataset does not exist.
+    die "Volume_snapshot_list is not implemented for ZFS over iSCSI.\n";
+}
+
+sub activate_storage {
+    my ($class, $storeid, $scfg, $cache) = @_;
+
+    return 1;
+}
+
+sub deactivate_storage {
+    my ($class, $storeid, $scfg, $cache) = @_;
+
+    return 1;
+}
+
+sub activate_volume {
+    my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
+
+    die "unable to activate snapshot from remote zfs storage" if $snapname;
+
+    return 1;
+}
+
+sub deactivate_volume {
+    my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
+
+    die "unable to deactivate snapshot from remote zfs storage" if $snapname;
+
+    return 1;
+}
+
 1;