X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=PVE%2FStorage%2FZFSPlugin.pm;h=383f0a0cde932da5ce34d792aafb7206517b74ee;hb=b0373adc714b5195ba88facc2f00ac71ee51ffc5;hp=77394b98be47155f447d96220b349706d1dba03b;hpb=a4034b9f195141ed5c44201af1d29602bf91938e;p=pve-storage.git diff --git a/PVE/Storage/ZFSPlugin.pm b/PVE/Storage/ZFSPlugin.pm index 77394b9..383f0a0 100644 --- a/PVE/Storage/ZFSPlugin.pm +++ b/PVE/Storage/ZFSPlugin.pm @@ -6,11 +6,14 @@ use IO::File; use POSIX; use PVE::Tools qw(run_command); use PVE::Storage::ZFSPoolPlugin; +use PVE::RPCEnvironment; 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}); } @@ -93,6 +101,8 @@ sub zfs_get_lu_name { 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); @@ -185,6 +195,10 @@ sub properties { description => "host group for comstar views", type => 'string', }, + lio_tpg => { + description => "target portal group for Linux LIO targets", + type => 'string', + }, }; } @@ -201,14 +215,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 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); @@ -254,10 +273,13 @@ sub create_base { sub clone_image { my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_; - my $name = $class->SUPER::clone_image($scfg, $storeid, $volname, $vmid, $snap); + my $name = $class->SUPER::clone_image($scfg, $storeid, $volname, $vmid, $snap); - my $guid = $class->zfs_create_lu($scfg, $name); - $class->zfs_add_lun_mapping_entry($scfg, $name, $guid); + # get ZFS dataset name from PVE volname + my (undef, $clonedname) = $class->parse_volname($name); + + my $guid = $class->zfs_create_lu($scfg, $clonedname); + $class->zfs_add_lun_mapping_entry($scfg, $clonedname, $guid); return $name; } @@ -270,9 +292,11 @@ sub alloc_image { die "illegal name '$name' - sould be 'vm-$vmid-*'\n" if $name && $name !~ m/^vm-$vmid-/; - my $volname = $class->zfs_find_free_diskname($storeid, $scfg, $vmid) if !$name; + my $volname = $name; + + $volname = $class->find_free_diskname($storeid, $scfg, $vmid, $fmt) if !$volname; - $class->zfs_create_zvol($scfg, $name, $size); + $class->zfs_create_zvol($scfg, $volname, $size); my $guid = $class->zfs_create_lu($scfg, $volname); $class->zfs_add_lun_mapping_entry($scfg, $volname, $guid); @@ -299,7 +323,9 @@ sub free_image { sub volume_resize { my ($class, $scfg, $storeid, $volname, $size, $running) = @_; - + + $volname = ($class->parse_volname($volname))[1]; + my $new_size = $class->SUPER::volume_resize($scfg, $storeid, $volname, $size, $running); $class->zfs_resize_lu($scfg, $volname, $new_size); @@ -307,24 +333,34 @@ sub volume_resize { return $new_size; } +sub volume_snapshot_delete { + my ($class, $scfg, $storeid, $volname, $snap, $running) = @_; + + $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 $recentsnap = $class->zfs_get_latest_snapshot($scfg, $volname); - if ($snap ne $recentsnap) { - die "cannot rollback, more recent snapshots exist\n"; - } + $volname = ($class->parse_volname($volname))[1]; $class->zfs_delete_lu($scfg, $volname); - $class->zfs_request($class, $scfg, undef, 'rollback', "$scfg->{pool}/$volname\@$snap"); + $class->zfs_request($scfg, undef, 'rollback', "$scfg->{pool}/$volname\@$snap"); $class->zfs_import_lu($scfg, $volname); $class->zfs_add_lun_mapping_entry($scfg, $volname); } +sub storage_can_replicate { + my ($class, $scfg, $storeid, $format) = @_; + + return 0; +} + sub volume_has_feature { my ($class, $scfg, $feature, $storeid, $volname, $snapname, $running) = @_; @@ -351,8 +387,37 @@ 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; }