From 5da32c59bdf6f8d9f8200ced2121a8a7076cd612 Mon Sep 17 00:00:00 2001 From: bergware Date: Sat, 18 Mar 2023 13:20:31 +0100 Subject: [PATCH] TRIM: improved ZFS trim reporting --- plugins/dynamix/scripts/ssd_trim | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/plugins/dynamix/scripts/ssd_trim b/plugins/dynamix/scripts/ssd_trim index 9a866ff34..036df0f53 100755 --- a/plugins/dynamix/scripts/ssd_trim +++ b/plugins/dynamix/scripts/ssd_trim @@ -37,24 +37,29 @@ function write(...$messages){ curl_close($com); } -write(_("SSD Trim started").". "._("Please wait")."...\n"); +write(_("SSD Trim started").". "._("Please wait")."...\n","\n"); // trim btrfs pools -$trim = popen('fstrim -a -v','r'); +$trim = popen('fstrim -va','r'); while (!feof($trim)) write(fgets($trim)); pclose($trim); -write("\n","\n"); +write("\n"); // trim zfs pools -exec("/usr/sbin/zpool status|grep -Po 'pool: \K.+'",$zfs_pools); +exec("zpool status|grep -Po 'pool: \K.+'",$zfs_pools); foreach ($zfs_pools as $pool) if ($pool) { - exec("/usr/sbin/zpool trim $pool"); + unset($devs); + exec("zpool trim $pool"); while (true) { sleep(1); - $trim = exec("/usr/sbin/zpool status -t $pool|grep -Pom1 '\d+% trimmed'"); - write("ZFS pool $pool $trim\r"); + $trim = exec("zpool status -t $pool|grep -Pom1 '\d+% trimmed'"); + write("/mnt/$pool: $trim\r"); if (substr($trim,0,3)==100) break; } - write("\n"); + $trim = preg_replace('/(.$)/',' $1',exec("zfs list $pool|grep -Pom1 '^$pool\s+\K\S+'"))."iB"; + $bytes = exec("zfs list -p $pool|grep -Pom1 '^$pool\s+\K\d+'"); + exec("zpool status -t $pool|grep -Po '^\s+\K.+100%'",$devs); + $devs = implode(', ',array_map(function($dev){return "/dev/".strtok($dev,' ');},$devs)); + write("/mnt/$pool: $trim ($bytes bytes) trimmed on $devs\r","\n"); } write(_("Finished")."\n",'_DONE_',''); ?>