From 3c13ab1adc087ed32e1b2b727e94fa8ca3ae487f Mon Sep 17 00:00:00 2001 From: bergware Date: Sat, 1 Dec 2018 11:21:30 +0100 Subject: [PATCH] Disable cache slots selection when cache disks are re-arranged --- plugins/dynamix/include/DeviceList.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/plugins/dynamix/include/DeviceList.php b/plugins/dynamix/include/DeviceList.php index 59dc3226b..c231d11b1 100644 --- a/plugins/dynamix/include/DeviceList.php +++ b/plugins/dynamix/include/DeviceList.php @@ -321,16 +321,17 @@ function array_slots() { $out .= ""; return $out; } -function cache_slots() { +function cache_slots($disabled) { global $var; + $off = $disabled ? ' disabled' : ''; $min = $var['cacheSbNumDisks']; $max = $var['MAX_CACHESZ']; $out = "
"; $out .= ""; $out .= ""; - $out .= ""; for ($n=$min; $n<=$max; $n++) { - $option = $n ? $n : 'none'; + $option = $n ?: 'none'; $selected = ($n == $var['SYS_CACHE_SLOTS'])? ' selected' : ''; $out .= ""; } @@ -373,12 +374,21 @@ case 'flash': break; case 'cache': $cache = array_filter($disks,'cache_only'); + $tmp = '/var/tmp/cache_log.tmp'; foreach ($cache as $disk) $crypto |= $disk['luksState']!=0 || vfs_luks($disk['fsType']); if ($var['fsState']=='Stopped') { - foreach ($cache as $disk) array_offline($disk); - echo "Slots:".cache_slots().""; + $log = file_exists($tmp) ? parse_ini_file($tmp) : []; + $off = false; + foreach ($cache as $disk) { + array_offline($disk); + if (isset($log[$disk['name']])) $off |= ($log[$disk['name']]!=$disk['id']); else $log[$disk['name']] = $disk['id']; + } + $data = []; foreach ($log as $key => $value) $data[] = "$key=\"$value\""; + file_put_contents($tmp,implode("\n",$data)); + echo "Slots:".cache_slots($off).""; } else { foreach ($cache as $disk) array_online($disk); + @unlink($tmp); if ($display['total'] && $var['cacheSbNumDisks']>1) show_totals('Pool of '.my_word($var['cacheNumDevices']).' devices'); } break;