From 70986fd9e49278d381d0dc705a748fa83b1a7eeb Mon Sep 17 00:00:00 2001 From: Chris Allen Date: Mon, 10 Mar 2014 12:07:35 -0700 Subject: [PATCH] Added "nowritecache" option to ZFS storage plugin. Turns off write caching on Comstar and Istgt LUNs created by the plugin. Has no effect on IET, as IET always uses write-through caching for blockio volumes not in read-only mode. Signed-off-by: Chris Allen --- PVE/Storage/LunCmd/Comstar.pm | 6 +++++- PVE/Storage/LunCmd/Istgt.pm | 16 +++++++++++++--- PVE/Storage/ZFSPlugin.pm | 9 ++++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/PVE/Storage/LunCmd/Comstar.pm b/PVE/Storage/LunCmd/Comstar.pm index 45ad6a5..aa1c614 100644 --- a/PVE/Storage/LunCmd/Comstar.pm +++ b/PVE/Storage/LunCmd/Comstar.pm @@ -50,11 +50,15 @@ sub run_lun_command { }; if ($method eq 'create_lu') { + my $wcd = 'false'; + if ($scfg->{nowritecache}) { + $wcd = 'true'; + } my $prefix = '600144f'; my $digest = md5_hex($params[0]); $digest =~ /(\w{7}(.*))/; $guid = "$prefix$2"; - @params = ('-p', 'wcd=false', '-p', "guid=$guid", @params); + @params = ('-p', "wcd=$wcd", '-p', "guid=$guid", @params); } elsif ($method eq 'modify_lu') { @params = ('-s', @params); } elsif ($method eq 'list_view') { diff --git a/PVE/Storage/LunCmd/Istgt.pm b/PVE/Storage/LunCmd/Istgt.pm index 9bbdfa0..b386b5d 100644 --- a/PVE/Storage/LunCmd/Istgt.pm +++ b/PVE/Storage/LunCmd/Istgt.pm @@ -173,6 +173,11 @@ my $lun_dumper = sub { foreach my $conf (@{$SETTINGS->{$lun}->{luns}}) { $config .= "$conf->{lun} Storage " . $conf->{Storage}; $config .= ' ' . $size_with_unit->($conf->{Size}) . "\n"; + foreach ($conf->{options}) { + if ($_) { + $config .= "$conf->{lun} Option " . $_ . "\n"; + } + } } $config .= "\n"; @@ -228,16 +233,21 @@ my $free_lu_name = sub { }; my $make_lun = sub { - my ($path) = @_; + my ($scfg, $path) = @_; my $target = $SETTINGS->{current}; die 'Maximum number of LUNs per target is 63' if scalar @{$SETTINGS->{$target}->{luns}} >= $MAX_LUNS; + my @options = (); my $lun = $get_lu_name->($target); + if ($scfg->{nowritecache}) { + push @options, "WriteCache Disable"; + } my $conf = { lun => $lun, Storage => $path, Size => 'AUTO', + options => @options, }; push @{$SETTINGS->{$target}->{luns}}, $conf; @@ -274,7 +284,7 @@ my $parser = sub { } elsif ($lun) { next if (($_ =~ /^\s*#/) || ($_ =~ /^\s*$/)); if ($_ =~ /^\s*(\w+)\s+(.+)\s*/) { - #next if $2 =~ /^Option.*/; + next if $2 =~ /^Option.*/; $SETTINGS->{$lun}->{$1} = $2; $SETTINGS->{$lun}->{$1} =~ s/^\s+|\s+$|"\s*//g; } else { @@ -349,7 +359,7 @@ my $create_lun = sub { die "$params[0]: LUN exists"; } my $lun = $params[0]; - $lun = $make_lun->($lun); + $lun = $make_lun->($scfg, $lun); my $config = $lun_dumper->($SETTINGS->{current}); open(my $fh, '>', $file) or die "Could not open file '$file' $!"; diff --git a/PVE/Storage/ZFSPlugin.pm b/PVE/Storage/ZFSPlugin.pm index 2d422d7..302d2d6 100644 --- a/PVE/Storage/ZFSPlugin.pm +++ b/PVE/Storage/ZFSPlugin.pm @@ -328,10 +328,16 @@ sub properties { description => "block size", type => 'string', }, + # this will disable write caching on comstar and istgt. + # it is not implemented for iet. iet blockio always operates with + # writethrough caching when not in readonly mode + nowritecache => { + description => "disable write caching on the target", + type => 'boolean', + }, sparse => { description => "use sparse volumes", type => 'boolean', - optional => 1, } }; } @@ -345,6 +351,7 @@ sub options { pool => { fixed => 1 }, blocksize => { fixed => 1 }, iscsiprovider => { fixed => 1 }, + nowritecache => { optional => 1 }, sparse => { optional => 1 }, content => { optional => 1 }, }; -- 2.39.2