diff --git a/plugins/dynamix/include/update.trim.php b/plugins/dynamix/include/update.trim.php
index 2d7235d32..b845e4fa4 100644
--- a/plugins/dynamix/include/update.trim.php
+++ b/plugins/dynamix/include/update.trim.php
@@ -19,9 +19,7 @@ if ($_POST['mode']>0) {
$min = isset($_POST['min']) ? $_POST['min'] : '*';
$dotm = isset($_POST['dotm']) ? $_POST['dotm'] : '*';
$day = isset($_POST['day']) ? $_POST['day'] : '*';
- $cron = "# Generated ssd trim schedule:\n$min $hour $dotm * $day /sbin/fstrim -a -v | logger &> /dev/null\n";
- exec("/usr/sbin/zpool status|grep -Po 'pool: \K.+'",$zfs_pools);
- foreach ($zfs_pools as $pool) if ($pool) $cron .= "$min $hour $dotm * $day /usr/sbin/zpool trim $pool 2> /dev/null\n";
+ $cron = "# Generated TRIM schedule:\n$min $hour $dotm * $day /usr/local/emhttp/plugins/dynamix/scripts/ssd_trim cron|logger &> /dev/null\n";
} else {
$cron = "";
}
diff --git a/plugins/dynamix/scripts/ssd_trim b/plugins/dynamix/scripts/ssd_trim
index 500856823..82a4d55c4 100755
--- a/plugins/dynamix/scripts/ssd_trim
+++ b/plugins/dynamix/scripts/ssd_trim
@@ -17,11 +17,32 @@ $docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
require_once "$docroot/webGui/include/Wrappers.php";
extract(parse_plugin_cfg('dynamix',true));
+// cron operation
+if ($argc==2 && $argv[1]=='cron') {
+ // trim btrfs
+ echo shell_exec("fstrim -va 2>/dev/null");
+ // trim zfs
+ exec("zpool status|grep -Po 'pool: \K.+'",$zfs_pools);
+ foreach ($zfs_pools as $pool) if ($pool) {
+ exec("zpool trim -w $pool 2>/dev/null");
+ echo zfs_info($pool)."\n";
+ }
+ exit(0);
+}
+
// add translations
$_SERVER['REQUEST_URI'] = 'settings';
$login_locale = _var($display,'locale');
require_once "$docroot/webGui/include/Translations.php";
+function zfs_info($pool) {
+ $trim = preg_replace('/(.$)/',' $1',exec("zfs list -Ho used $pool"))."iB";
+ $bytes = exec("zfs list -Hpo used $pool");
+ exec("zpool status -tP $pool|grep -Po '^\s+\K.+% trimmed'",$devs);
+ $devs = implode(', ',array_map(function($d){return strtok($d,' ');},$devs));
+ return "/mnt/$pool: $trim ($bytes bytes) trimmed on $devs";
+}
+
function write(...$messages){
$com = curl_init();
curl_setopt_array($com,[
@@ -39,30 +60,20 @@ function write(...$messages){
write(_("TRIM operation started").".\n","\n","\n");
-// trim btrfs pools
+// trim btrfs file system
exec("findmnt -lnt btrfs|sort -rk2|awk '$1!~\"btrfs\"{print $1,$2}'",$mounts);
foreach ($mounts as $mount) {
[$target,$source] = explode(' ',$mount);
write("$target: ... \r");
- write(exec("fstrim -v $target")." on $source\r","\n");
+ write(exec("fstrim -v $target 2>/dev/null")." on $source\r","\n");
}
-// trim zfs pools
+// trim zfs file system
exec("zpool status|grep -Po 'pool: \K.+'",$zfs_pools);
foreach ($zfs_pools as $pool) if ($pool) {
- unset($devs);
- exec("zpool trim $pool");
- while (true) {
- sleep(1);
- $trim = exec("zpool status -t $pool|grep -Pom1 '\d+% trimmed'");
- write("/mnt/$pool: $trim\r");
- if (substr($trim,0,3)==100) break;
- }
- $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("/mnt/$pool: ... \r");
+ exec("zpool trim -w $pool 2>/dev/null");
+ write(zfs_info($pool)."\r","\n");
}
write(_("Finished")."\n",'_DONE_','');
?>