=mk_option($cfg['logging'],"no",_('No'))?>
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index 8cba3f80..23ded5a6 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -91,8 +91,6 @@ COUNT_SECONDARY_FILES=0
overrideFlag=0
UNRAID_MOVER_LOGLEVEL=0
UNRAID_MOVER=0
-# PHP requires escaped quotes (" -> \") for text fields
-DEFAULT_INVALID_FILE_CHARS=('$' '/' '<' '>' ':' '\"' '|' '?' '*')
# Variables for counts when delete folders
LAST_DIR=""
LAST_COUNT=-1
@@ -338,34 +336,6 @@ skiplist_share_lines() {
' "$list"
}
-# Sanitize input filename to prevent attacks
-validate_filename() {
- local filename="$1"
-
- ## Check filename length
- if [[ ${#filename} -gt 255 ]]; then
- mvlogger "Error: Filename too long: '$filename'"
- return 1
- fi
-
- # Invalid characters (Linux + Windows + macOS safe)
- if [[ "$filename" == *["$INVALID_FILE_CHARS_STR"]* ]]; then
- mvlogger "Error: Invalid characters in filename: '$filename'"
- return 1
- fi
-
- # Fast path traversal detection
- if [[ "$filename" == *".."* ]]; then
- # Only block if '..' is used as a path segment
- if [[ "$filename" == "../"* || "$filename" == *"/.."* || "$filename" == "..\\"* || "$filename" == *"\\.."* ]]; then
- mvlogger "Error: Path traversal attempt detected: '$filename'"
- return 1
- fi
- fi
-
- return 0
-}
-
# find's -path glob and the eval each strip one level, so a literal backslash
# needs four. Order matters: backslash first, then '[', then the shell's own three,
# whose escapes the eval consumes before find ever sees the name.
@@ -971,36 +941,6 @@ getMoverSettings() {
mvlogger "List files delete age: $LISTFILESAGE days"
fi
- if [ -z $(cfg validateFilenames) ]; then
- if [[ ! "$config_file" =~ shareOverrideConfig ]]; then
- mvlogger "No Validate Filenames argument provided, defaulting to yes"
- cfg_default validateFilenames yes
- VALIDATE_FILENAMES="yes"
- fi
- else
- VALIDATE_FILENAMES=$(cfg validateFilenames)
- mvlogger "Validate Filenames: $VALIDATE_FILENAMES"
- fi
-
- if [ -z "$(cfg invalidFileChars)" ]; then
- if [[ ! "$config_file" =~ shareOverrideConfig ]]; then
- # Print and unescape the array element \" -> "
- mvlogger "No Invalid characters argument provided, defaulting to: ${DEFAULT_INVALID_FILE_CHARS[*]//\\\"/\"}"
- cfg_default invalidFileChars "${DEFAULT_INVALID_FILE_CHARS[*]}"
- # Keep DEFAULT_INVALID_FILE_CHARS as an array
- INVALID_FILE_CHARS=("${DEFAULT_INVALID_FILE_CHARS[@]}")
- # Escape regex meta chars, first remove '\' from '\"', then add '\' to all characters
- INVALID_FILE_CHARS_STR=$(printf '%s' "${INVALID_FILE_CHARS[@]//\\\"/\"}" | sed 's/./\\&/g')
- fi
- else
- # Convert the string from cfg invalidFileChars to an array
- IFS=' ' read -r -a INVALID_FILE_CHARS <<<"$(cfg invalidFileChars)"
- # Print and unescape the array element \" -> "
- mvlogger "Invalid characters to block: ${INVALID_FILE_CHARS[*]//\\\"/\"}"
- # Escape regex meta chars, first remove '\' from '\"', then add '\' to all characters
- INVALID_FILE_CHARS_STR=$(printf '%s' "${INVALID_FILE_CHARS[@]//\\\"/\"}" | sed 's/./\\&/g')
- fi
-
if [ -z $(cfg movefilesTool) ]; then
if [[ ! "$config_file" =~ shareOverrideConfig ]]; then
mvlogger "No Move files tool argument provided, defaulting to rsync"
@@ -2590,7 +2530,10 @@ processTheMoves() {
# "keep on primary", "keep on secondary" and "keep misplaced" are not actions, so they are absent
for ACTION_PASS in "${MOVE_ACTIONS[@]}"; do
- while IFS="|" read -r PRIMARYSTORAGENAME SHARENAME SHAREUSECACHE MODIFYTIME FILESIZE POOLSUM THRESHOLD PROJECTED NBLINKS INODE ACTION SOURCE DESTINATION FILETYPE FILEPATH; do
+ while IFS= read -r ROW; do
+ IFS="|" read -r PRIMARYSTORAGENAME SHARENAME SHAREUSECACHE MODIFYTIME FILESIZE POOLSUM THRESHOLD PROJECTED NBLINKS INODE ACTION SOURCE DESTINATION FILETYPE FILEPATH <<<"$ROW"
+ # read can drop a | that ends the row, so a set path is cut whole from the row, as the awk lookups below take it
+ if [ -n "$FILEPATH" ]; then FILEPATH=$ROW; for _ in {1..14}; do FILEPATH=${FILEPATH#*|}; done; fi
# before the row's checks, so a long pause cannot leave them stale
pauseHold
if [ -e $SOFTSTOPFILE ]; then
@@ -2671,27 +2614,6 @@ processTheMoves() {
for f in "${SYNCED_FILES_ARR[@]}"; do SYNCED_FILES+="$(qp "$f") "; done
GUI_CURRENT_FILE="$SOURCE/$FILEPATH"
- # Check File by validate function and skip if error; rsync gets every hardlink name, so check them all
- if [ "$VALIDATE_FILENAMES" = "yes" ]; then
- for f in "${SYNCED_FILES_ARR[@]:-$SOURCE/./$FILEPATH}"; do
- # a name already gone is counted as vanished after the transfer, never as invalid
- [ -e "${f//\/.\//\/}" ] || continue
- validate_filename "$(basename "$f")" && continue
- mvlogger_t "Error: Invalid filename path: %s. Please either change the filename to valid or disable the 'Validate input filenames' option." "failure" "$(qp "${f//\/.\//\/}")"
- gone=0
- for g in "${SYNCED_FILES_ARR[@]}"; do [ -e "${g//\/.\//\/}" ] || gone=$((gone + 1)); done
- # a staged row is counted once, by its sync row, which finds the move incomplete and takes the gone names from here
- if [ "$STAGE_ROW" = 0 ]; then
- not_moved "$(( ${#SYNCED_FILES_ARR[@]} - gone > 0 ? ${#SYNCED_FILES_ARR[@]} - gone : 1 ))"
- [ "$FILETYPE" = "f" ] && VANISHEDFILES=$((VANISHEDFILES + gone))
- remaining_done "$gone" 0
- else
- STAGED_VANISHED[$chain_key]=$gone
- fi
- continue 2
- done
- fi
-
# Check if list is complete (array length is exact, unlike parsing the string)
NBFILES=${#SYNCED_FILES_ARR[@]}
if [ -f "${SOURCE}/${FILEPATH}" ] && [ $NBFILES != "$NBLINKS" ]; then
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/default.cfg b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/default.cfg
index 2db26e07..3b268454 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/default.cfg
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/default.cfg
@@ -1,7 +1,5 @@
moverDisabled="no"
testmode="no"
-validateFilenames="yes"
-invalidFileChars="$ / < > : \" | ? *"
logging="yes"
debuglogging="no"
notify="yes"
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt
index b903c435..06f3aa2e 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt
@@ -36,13 +36,11 @@ Delete Mover Log files over than this days old=Protokolldateien der Datenverschi
Disable Mover running on a schedule=Zeitplan für Datenverschiebung deaktivieren
disables test mode=deaktiviert den Testmodus
disables the plugins schedule=deaktiviert den Zeitplan des Plugins
-disables validation of input filenames=deaktiviert die Prüfung von Dateinamen
Download=Herunterladen
enable smart caching=Intelligentes Caching aktivieren
Error checking mover status Please refresh the page=Fehler beim Prüfen des Status der Datenverschiebung. Bitte Seite aktualisieren.
Error Config file %s not found=Fehler: Konfigurationsdatei %s wurde nicht gefunden.
Error Failed to convert CRLF line endings in %s Check file permissions=Fehler: CRLF‑Zeilenenden in %s konnten nicht konvertiert werden. Bitte Dateiberechtigungen prüfen.
-Error Invalid filename path %s Please either change the filename to valid or disable the Validate input filenames option=Fehler: Ungültiger Dateipfad %s. Bitte Dateinamen korrigieren oder die Prüfung von Dateinamen deaktivieren.
Error No files found to move for %s=Fehler: Keine Dateien zum Verschieben für %s gefunden.
Errors Only=Nur Fehler
Estimated Completion=Geschätzte Fertigstellung
@@ -75,7 +73,6 @@ If you want Mover Tuning to fully manage scheduling, disable it in Mover Setting
Ignore All hidden files and directories=Alle versteckten Dateien und Ordner ignorieren
Ignore files and folders listed inside of a text file=Dateien und Ordner ignorieren, die in einer Textdatei aufgelistet sind
Ignore file types=Dateitypen ignorieren
-Invalid characters to block=Ungültige Zeichen zum Blockieren
Largest first=Größte zuerst
Let scheduled mover run during a parity check rebuild=Zeitplan für Datenverschiebung während Paritätsprüfung/Wiederherstellung erlauben
Log files=Protokolldateien
@@ -181,7 +178,6 @@ Use CTIME change time=CTIME (Statusänderungszeit) verwenden
Use global=Global verwenden
Used IDE=Verwendete IDE
User shares not enabled=Benutzerfreigaben sind nicht aktiviert!
-Validate input filenames to prevent attacks=Eingabedateinamen validieren, um Angriffe zu verhindern
Very Low=Sehr niedrig
View=Anzeigen
Want to support the developer and say Thank You=Möchtest du den Entwickler unterstützen und **Danke** sagen?
@@ -244,31 +240,6 @@ Youre welcome 😊 Thanks for using=Gern geschehen 😊 Danke für die Nutzung!
Achtung – Der Testmodus hält den originalen Mover nicht auf: Er läuft trotzdem nach dem Zeitplan der Option Erzwungenes Verschieben aller Dateien nach Zeitplan und über die Schaltfläche „Jetzt verschieben“, wenn die Option „Jetzt verschieben“ folgt den Plugin‑Filtern auf Nein steht. Ab Unraid 7.2.1 starten der Mover‑Zeitplan und die Verschieben‑Schaltflächen von Unraid selbst immer den originalen Mover.
:end
-:mover_tune_validate_plug:
-In der Cybersicherheit können Dateinamen ein kritischer Angriffsvektor sein. Nicht geprüfte Dateinamen stellen ein erhebliches Risiko dar und können die Systemintegrität gefährden.
-Die Validierung von Dateinamen prüft jeden Dateinamen, bevor er vom Mover verarbeitet wird. Dadurch wird sichergestellt, dass nur gültige Dateinamen akzeptiert werden und das Risiko von Angriffen reduziert wird.
-Deaktiviere diese Option nur , wenn du sehr viele Dateien verschieben musst und sicher bist, dass alle Dateinamen gültig sind und keine Sicherheitsrisiken enthalten.
-1. Längenprüfung – Dateinamen über 255 Zeichen werden abgelehnt.
-2. Ungültige Zeichen – Dateinamen dürfen keine Zeichen enthalten wie
-($ ), (/ ), (< ), (> ), (: ), (" ), (| ), (? ), (* ).
-3. Pfad‑Traversal verhindern – Dateinamen dürfen keine Sequenzen wie (../ ) enthalten.
-Wenn eine dieser Prüfungen fehlschlägt, wird der Dateiname abgelehnt.
-:end
-
-:mover_tune_invalidfilechars_plug:
- Ungültige Zeichen in Dateinamen sind unter anderem:
- $
- /
- <
- >
- :
- "
- |
- ?
- * .
-
-:end
-
:mover_tune_logging_plug:
Aktiviert oder deaktiviert die Protokollierung des Plugins.
Datei (und Syslog) speichert sowohl im Syslog als auch in der Logdatei.
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt
index 26072628..d50a7771 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt
@@ -38,13 +38,11 @@ Delete Mover Log files over than this days old=
Disable Mover running on a schedule=
disables test mode=
disables the plugins schedule=disables the plugin's schedule
-disables validation of input filenames=
Download=
enable smart caching=
Error checking mover status Please refresh the page=Error checking mover status. Please refresh the page.
Error Config file %s not found=Error: Config file '%s' not found.
Error Failed to convert CRLF line endings in %s Check file permissions=Error: Failed to convert CRLF line endings in %s. Check file permissions.
-Error Invalid filename path %s Please either change the filename to valid or disable the Validate input filenames option=Error: Invalid filename path: %s. Please either change the filename to valid or disable the 'Validate input filenames' option.
Error No files found to move for %s=Error: No files found to move for %s
Errors Only=
Estimated Completion=
@@ -77,7 +75,6 @@ If you want Mover Tuning to fully manage scheduling, disable it in Mover Setting
Ignore All hidden files and directories=
Ignore files and folders listed inside of a text file=
Ignore file types=
-Invalid characters to block=
Largest first=
Let scheduled mover run during a parity check rebuild=Let scheduled mover run during a parity check / rebuild
Log files=
@@ -183,7 +180,6 @@ Use CTIME change time=Use CTIME (change time)
Use global=
Used IDE=
User shares not enabled=User shares not enabled!
-Validate input filenames to prevent attacks=
Very Low=
View=
Want to support the developer and say Thank You=Want to support the developer and say **Thank You**?
@@ -246,31 +242,6 @@ Youre welcome 😊 Thanks for using=You're welcome! 😊 Thanks for using!
Caution - Test Mode does not stop original Mover: it still runs on the "Force move of all files on a schedule" schedule, and from the Move Now button if "Move Now button follows plug-in filters" is set to No . On Unraid 7.2.1 and later, Unraid's own Mover schedule and Move buttons always run the original Mover.
:end
-:mover_tune_validate_plug:
- In cybersecurity, filenames can be a critical vector for potential attacks and system vulnerabilities. Unsanitized filenames pose significant risks that can compromise system integrity and security.
- Validate input filenames will check every filename before it is processed by the Mover. This ensures that only valid filenames are accepted, reducing the risk of attacks and vulnerabilities.
- Disable Only if you have many files to move and you are sure that all filenames are valid and do not contain any potential security risks.
- 1. Check filename length - If the filename exceeds 255 characters, it will be rejected.
- 2. Check for invalid characters - The filename should not contain any characters that are considered invalid for filenames, such as
-( $ ), ( / ), ( < ), ( > ), ( : ), ( " ), ( | ), ( ? ), ( * ).
- 3. Prevent path traversal - The filename should not contain any characters that can be used to traverse directories, such as ( ../ ).
- If one of these checks fails, the filename will be rejected.
-:end
-
-:mover_tune_invalidfilechars_plug:
- The filename characters such as:
- $
- /
- <
- >
- :
- "
- |
- ?
- * .
-
-:end
-
:mover_tune_logging_plug:
Enables or disables logging from this plugin.
File (and Syslog) will store to SYSLOG and to the log file.
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt
index 6a769b9e..2d108b40 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt
@@ -36,13 +36,11 @@ Delete Mover Log files over than this days old=Supprimer les journaux du mover p
Disable Mover running on a schedule=Désactiver l’exécution programmée du mover
disables test mode=désactive le mode test
disables the plugins schedule=désactive la planification du plugin
-disables validation of input filenames=désactive la validation des noms de fichiers
Download=Télécharger
enable smart caching=activer le cache intelligent
Error checking mover status Please refresh the page=Erreur lors de la vérification du statut du mover. Veuillez rafraîchir la page.
Error Config file %s not found=Erreur : fichier de configuration « %s » introuvable.
Error Failed to convert CRLF line endings in %s Check file permissions=Erreur : impossible de convertir les fins de ligne CRLF dans %s. Vérifiez les permissions du fichier.
-Error Invalid filename path %s Please either change the filename to valid or disable the Validate input filenames option=Erreur : chemin de fichier invalide %s. Corrigez le nom ou désactivez l’option de validation des noms de fichiers.
Error No files found to move for %s=Erreur : aucun fichier trouvé à déplacer pour %s
Errors Only=Erreurs uniquement
Estimated Completion=Fin estimée
@@ -75,7 +73,6 @@ If you want Mover Tuning to fully manage scheduling, disable it in Mover Setting
Ignore All hidden files and directories=Ignorer tous les fichiers et dossiers cachés
Ignore files and folders listed inside of a text file=Ignorer les fichiers et dossiers listés dans un fichier texte
Ignore file types=Ignorer les types de fichiers
-Invalid characters to block=Caractères invalides à bloquer
Largest first=Les plus gros d’abord
Let scheduled mover run during a parity check rebuild=Autoriser le mover programmé pendant une vérification/réparation de parité
Log files=Fichiers journaux
@@ -181,7 +178,6 @@ Use CTIME change time=Utiliser CTIME (date de changement d’état)
Use global=Réglage global
Used IDE=IDE utilisé
User shares not enabled=Les parts utilisateur ne sont pas activées !
-Validate input filenames to prevent attacks=Valider les noms de fichiers pour prévenir les attaques
Very Low=Très faible
View=Afficher
Want to support the developer and say Thank You=Vous souhaitez soutenir le développeur et dire **Merci** ?
@@ -244,30 +240,6 @@ Youre welcome 😊 Thanks for using=Avec plaisir 😊 Merci pour votre utilisati
Attention — le mode test n’arrête pas le mover original : il s’exécute quand même selon l’horaire de l’option Forcer le déplacement de tous les fichiers selon un horaire , et depuis le bouton « Déplacer maintenant » si l’option Le bouton « Déplacer maintenant » suit les filtres du plugin est réglée sur Non . À partir d’Unraid 7.2.1, la planification du mover et les boutons de déplacement d’Unraid lancent toujours le mover original.
:end
-:mover_tune_validate_plug:
-En cybersécurité, les noms de fichiers peuvent être un vecteur critique d’attaques et de vulnérabilités. Des noms non vérifiés peuvent compromettre l’intégrité et la sécurité du système.
-La validation des noms de fichiers vérifie chaque nom avant qu’il ne soit traité par le mover. Cela garantit que seuls des noms valides sont acceptés, réduisant les risques d’attaques.
-Désactivez cette option uniquement si vous avez beaucoup de fichiers à déplacer et que vous êtes certain que tous les noms sont valides et sans risque.
-1. Longueur du nom — si le nom dépasse 255 caractères, il est rejeté.
-2. Caractères invalides — le nom ne doit pas contenir des caractères interdits tels que ($ ), (/ ), (< ), (> ), (: ), (" ), (| ), (? ), (* ).
-3. Éviter la traversée de répertoires — le nom ne doit pas contenir (../ ).
-Si une vérification échoue, le nom est rejeté.
-:end
-
-:mover_tune_invalidfilechars_plug:
-Caractères invalides dans un nom de fichier :
- $
- /
- <
- >
- :
- "
- |
- ?
- * .
-
-:end
-
:mover_tune_logging_plug:
Active ou désactive la journalisation du plugin.
Fichier (et Syslog) enregistre dans le SYSLOG et dans le fichier journal.
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt
index c68ce129..679212b2 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt
@@ -36,13 +36,11 @@ Delete Mover Log files over than this days old=Удалять лог‑файл
Disable Mover running on a schedule=Отключить запуск Mover по расписанию
disables test mode=отключает тестовый режим
disables the plugins schedule=отключает расписание плагина
-disables validation of input filenames=отключает проверку имён входных файлов
Download=Скачать
enable smart caching=включить умное кэширование
Error checking mover status Please refresh the page=Ошибка проверки статуса mover. Обновите страницу.
Error Config file %s not found=Ошибка: файл конфигурации '%s' не найден.
Error Failed to convert CRLF line endings in %s Check file permissions=Ошибка: не удалось преобразовать окончания строк CRLF в %s. Проверьте права доступа к файлу.
-Error Invalid filename path %s Please either change the filename to valid or disable the Validate input filenames option=Ошибка: недопустимый путь имени файла: %s. Измените имя файла или отключите параметр «Проверять имена входных файлов».
Error No files found to move for %s=Ошибка: не найдено файлов для перемещения для %s
Errors Only=Только ошибки
Estimated Completion=Ожидаемое завершение
@@ -75,7 +73,6 @@ If you want Mover Tuning to fully manage scheduling, disable it in Mover Setting
Ignore All hidden files and directories=Игнорировать все скрытые файлы и каталоги
Ignore files and folders listed inside of a text file=Игнорировать файлы и каталоги, перечисленные в текстовом файле
Ignore file types=Игнорировать типы файлов
-Invalid characters to block=Недопустимые символы для блокировки
Largest first=Сначала самые большие
Let scheduled mover run during a parity check rebuild=Разрешить запуск Mover по расписанию во время проверки/восстановления паритета
Log files=Файлы журнала
@@ -181,7 +178,6 @@ Use CTIME change time=Использовать CTIME (время изменен
Use global=Глобальная настройка
Used IDE=Используемый IDE
User shares not enabled=Пользовательские шары не включены!
-Validate input filenames to prevent attacks=Проверять имена файлов для предотвращения атак
Very Low=Очень низкий
View=Просмотр
Want to support the developer and say Thank You=Хотите поддержать разработчика и сказать **Спасибо**?
@@ -243,31 +239,6 @@ Youre welcome 😊 Thanks for using=Пожалуйста! 😊 Спасибо,
Внимание — тестовый режим не останавливает оригинальный Mover: он всё равно запускается по расписанию параметра Принудительно перемещать все файлы по расписанию , а также кнопкой «Переместить сейчас», если параметр Кнопка «Переместить сейчас» учитывает фильтры плагина установлен в Нет . Начиная с Unraid 7.2.1, собственное расписание Mover и кнопки перемещения Unraid всегда запускают оригинальный Mover.
:end
-:mover_tune_validate_plug:
- В сфере кибербезопасности имена файлов могут являться критическим вектором для потенциальных атак и уязвимостей системы. Несанитизированные имена файлов создают значительные риски, способные нарушить целостность и безопасность системы.
- Проверка имён входных файлов проверяет каждое имя файла перед его обработкой Mover'ом. Это гарантирует, что принимаются только допустимые имена файлов, снижая риск атак и уязвимостей.
- Отключайте только если у вас много файлов для перемещения и вы уверены , что все имена файлов допустимы и не содержат потенциальных угроз безопасности.
- 1. Проверка длины имени файла — если имя файла превышает 255 символов, оно будет отклонено.
- 2. Проверка недопустимых символов — имя файла не должно содержать символы, считающиеся недопустимыми для имён файлов, такие как
-( $ ), ( / ), ( < ), ( > ), ( : ), ( " ), ( | ), ( ? ), ( * ).
- 3. Предотвращение обхода пути — имя файла не должно содержать символы, которые могут использоваться для обхода каталогов, такие как ( ../ ).
- Если одна из этих проверок не пройдена, имя файла будет отклонено.
-:end
-
-:mover_tune_invalidfilechars_plug:
- Символы имени файла, такие как:
- $
- /
- <
- >
- :
- "
- |
- ?
- * .
-
-:end
-
:mover_tune_logging_plug:
Включает или отключает журналирование этого плагина.
Файл (и Syslog) сохраняет записи в SYSLOG и в файл журнала.
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt
index 13860bf7..4455a8b0 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt
@@ -35,13 +35,11 @@ Delete Mover Log files over than this days old=日志文件保留天数
Disable Mover running on a schedule=禁用 Mover 按计划运行
disables test mode=禁用测试模式
disables the plugins schedule=禁用插件的计划
-disables validation of input filenames=禁用文件名验证
Download=下载
enable smart caching=启用智能缓存
Error checking mover status Please refresh the page=检查 Mover 状态时出错,请刷新页面。
Error Config file %s not found=错误:找不到配置文件“%s”。
Error Failed to convert CRLF line endings in %s Check file permissions=错误:无法转换 %s 中的 CRLF 换行符,请检查文件权限。
-Error Invalid filename path %s Please either change the filename to valid or disable the Validate input filenames option=错误:文件名路径无效:%s。请修改为有效的文件名,或禁用“验证文件名防止攻击”选项。
Error No files found to move for %s=错误:未找到 %s 中需要移动的文件
Errors Only=仅错误
Estimated Completion=预计完成
@@ -74,7 +72,6 @@ If you want Mover Tuning to fully manage scheduling, disable it in Mover Setting
Ignore All hidden files and directories=忽略隐藏文件和目录
Ignore files and folders listed inside of a text file=忽略列表中的文件和文件夹
Ignore file types=忽略指定文件类型
-Invalid characters to block=要阻止的无效字符
Largest first=最大的优先
Let scheduled mover run during a parity check rebuild=允许计划的 Mover 在奇偶校验/重建期间运行
Log files=日志文件
@@ -180,7 +177,6 @@ Use CTIME change time=使用状态更改时间(CTIME)
Use global=使用全局设置
Used IDE=开发工具
User shares not enabled=用户共享未启用
-Validate input filenames to prevent attacks=验证文件名防止攻击
Very Low=很低
View=查看
Want to support the developer and say Thank You=想支持开发者并说声**谢谢**吗?
@@ -243,31 +239,6 @@ Youre welcome 😊 Thanks for using=不客气!😊 感谢使用!
注意 - 测试模式不会阻止原始 Mover:它仍会按“定时强制移动所有文件”的计划运行;如果“立即移动按钮遵循过滤器”设为否 ,立即移动按钮也会运行原始 Mover。在 Unraid 7.2.1 及更高版本中,Unraid 自带的 Mover 计划和移动按钮始终运行原始 Mover。
:end
-:mover_tune_validate_plug:
- 在网络安全中,文件名可能成为潜在攻击和系统漏洞的重要途径。未经清理的文件名会带来重大风险,可能危及系统的完整性和安全性。
- 验证文件名会在 Mover 处理每个文件名之前进行检查,确保只接受有效 的文件名,降低 攻击和漏洞的风险 。
- 仅 当需要移动大量文件,并且确定 所有文件名都有效 、不含任何潜在安全风险时,才禁用此选项。
- 1. 检查文件名长度 - 文件名超过 255 个字符将被拒绝。
- 2. 检查无效字符 - 文件名不应包含任何被视为无效的字符,例如
-( $ ), ( / ), ( < ), ( > ), ( : ), ( " ), ( | ), ( ? ), ( * )。
- 3. 防止路径遍历 - 文件名不应包含可用于遍历目录的字符,例如 ( ../ )。
- 只要有一项检查失败,该文件名就会被拒绝。
-:end
-
-:mover_tune_invalidfilechars_plug:
- 文件名中的以下字符:
- $
- /
- <
- >
- :
- "
- |
- ?
- * 。
-
-:end
-
:mover_tune_logging_plug:
启用或禁用本插件的日志记录。
文件(及系统日志) 将同时记录到系统日志 和日志文件。
From 02ec1ed6039b934fd714b937d63ca3b823abb704 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Tue, 24 Nov 2026 07:55:11 +0800
Subject: [PATCH 05/94] Escape < and > in notification text before Unraid 7.2
Unraid before 7.2 shows a notification's description as raw HTML, in the
pop-up and on the Archived Notifications page, so a < in a file name would
start markup there. From 7.2 the Unraid API sanitizes the description
itself, and from API 4.26 it decodes entities in the notification file
first, which undoes an escape; so from 7.2 the text goes through
unchanged. When the version cannot be read, it is escaped.
The log keeps the name as it is. Before 7.2, email and agent notifications
show < or > for a name holding < or >; & and quotes are left alone,
so names like Tom & Jerry read the same everywhere.
---
.../usr/local/emhttp/plugins/ca.mover.tuning/age_mover | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index 8cba3f80..01a0c354 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -249,6 +249,12 @@ unraid_notify() {
else
severity="warning"
fi
+ # before 7.2 Unraid shows the description as raw HTML; from 7.2 its API sanitizes it (and from API 4.26 decodes
+ # entities first, undoing an escape). The quotes stop bash 5.2 reading & in the replacement as the matched text
+ if ! version_ge "$UNRAID_VERSION" 7.2; then
+ message=${message//"<"}
+ message=${message//>/">"}
+ fi
#
# Call the Unraid notification script
/usr/local/emhttp/webGui/scripts/notify -s "$(translate_text "Mover Tuning Notification")" -d "$message" -i "$severity" -l "/Settings/Scheduler"
From 3814885dba20af0d2e601fd124f5c2c878cc5a9f Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Tue, 24 Nov 2026 08:59:11 +0800
Subject: [PATCH 06/94] Retire Unraid's old schedule at the sync or Apply that
replaces it
The install kept Unraid's mover.cron when its sync failed, but it had
already saved moverTuneCron, so no later install tried again, and an
Apply that then wrote mover.tuning.cron left both schedules running. A
disabled schedule with an invalid forced schedule also kept it, because
the sync's exit status counted the forced schedule's error.
The migration now leaves a marker. A sync or apply that finds it renames
mover.cron to mover.cron.old once mover.tuning.cron exists or the
schedule is disabled, then removes the marker.
---
plugins/ca.mover.tuning.plg | 10 +++----
.../plugins/ca.mover.tuning/updateCron.php | 27 +++++++++++++++++++
2 files changed, 31 insertions(+), 6 deletions(-)
diff --git a/plugins/ca.mover.tuning.plg b/plugins/ca.mover.tuning.plg
index 1d82a649..137c53fa 100644
--- a/plugins/ca.mover.tuning.plg
+++ b/plugins/ca.mover.tuning.plg
@@ -825,7 +825,6 @@ if version_ge "$UNRAID_VERSION" "7.2.1"; then
TUNING_CRON_FILE="/boot/config/plugins/&name;/mover.tuning.cron"
DYNAMIX_CRON_FILE="/boot/config/plugins/dynamix/mover.cron"
- DYNAMIX_CRON_OLD="/boot/config/plugins/dynamix/mover.cron.old"
# Only perform migration if mover.tuning.cron does NOT exist
# AND old dynamix/mover.cron exists
@@ -842,12 +841,11 @@ if version_ge "$UNRAID_VERSION" "7.2.1"; then
echo "Setting moverTuneCron to: [$SHARE_MOV_SCHED]"
echo "moverTuneCron=\"$SHARE_MOV_SCHED\"" >> "$config_file"
- # the old schedule goes once the sync has written its replacement or found the Mover Tuning schedule disabled
- if /usr/bin/php -q /usr/local/emhttp/plugins/&name;/updateCron.php sync || [[ -f "$TUNING_CRON_FILE" ]]; then
- echo "Renaming old schedule: mover.cron → mover.cron.old"
- mv "$DYNAMIX_CRON_FILE" "$DYNAMIX_CRON_OLD"
+ # updateCron.php retires mover.cron at the first sync or apply that finds this marker and the schedule replaced or disabled
+ if touch /boot/config/plugins/&name;/retire.unraid.schedule; then
+ echo "mover.cron becomes mover.cron.old once mover.tuning.cron is written or the schedule is disabled."
else
- echo "mover.tuning.cron was not written (the reason is in the syslog), so the old schedule stays in mover.cron."
+ echo "The retirement marker could not be written, so mover.cron stays: rename it to mover.cron.old by hand."
fi
else
echo "shareMoverSchedule is empty — nothing to migrate."
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php
index f5858786..99fdcc87 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php
@@ -134,6 +134,7 @@ function sync_cron_files()
sync_forced_cron();
sync_tune_cron();
sync_watchdog_cron();
+ retire_unraid_cron();
return true;
}
@@ -184,6 +185,32 @@ function sync_watchdog_cron()
}
}
+/** From Unraid 7.2.1, after the install migrated Unraid's schedule: renames Unraid's mover.cron to mover.cron.old once mover.tuning.cron exists or the schedule is disabled */
+function retire_unraid_cron()
+{
+ global $vars, $cfg_moverDisabled;
+
+ $mark = "/boot/config/plugins/ca.mover.tuning/retire.unraid.schedule";
+ $unraidFile = "/boot/config/plugins/dynamix/mover.cron";
+ if (is_file($mark) === false || $vars['version'] === '' || version_compare($vars['version'], '7.2.1', '<') === true) {
+ return;
+ }
+ if ($cfg_moverDisabled !== 'yes' && is_file("/boot/config/plugins/ca.mover.tuning/mover.tuning.cron") === false) {
+ logger("Unraid's mover schedule in $unraidFile is kept: mover.tuning.cron is not written yet.");
+ return;
+ }
+ if (is_file($unraidFile) === true) {
+ if (@rename($unraidFile, "$unraidFile.old") === false) {
+ logger("Error: Failed to rename $unraidFile to mover.cron.old.");
+ return;
+ }
+ logger("Retired Unraid's mover schedule: $unraidFile is now mover.cron.old.");
+ }
+ if (@unlink($mark) === false) {
+ logger("Error: Failed to remove $mark.");
+ }
+}
+
/** Before Unraid 7.2.1, where Unraid's own mover.cron starts Mover Tuning: removed while the schedule is disabled, else written back when missing and the array is started */
function apply_unraid_cron()
{
From 474d41ac3133cd747087fe2879623b44a9308a46 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Tue, 24 Nov 2026 09:54:51 +0800
Subject: [PATCH 07/94] Retire Unraid's old schedule when the saved schedule is
cleared
While the retirement waited, Defaults or clearing the schedule left
Unraid's mover.cron running, though the tab showed no schedule and a
finished migration would have left none. Only a schedule that is on,
set and not written yet now keeps it.
---
plugins/ca.mover.tuning.plg | 4 ++--
.../usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/plugins/ca.mover.tuning.plg b/plugins/ca.mover.tuning.plg
index 137c53fa..86dc4c53 100644
--- a/plugins/ca.mover.tuning.plg
+++ b/plugins/ca.mover.tuning.plg
@@ -841,9 +841,9 @@ if version_ge "$UNRAID_VERSION" "7.2.1"; then
echo "Setting moverTuneCron to: [$SHARE_MOV_SCHED]"
echo "moverTuneCron=\"$SHARE_MOV_SCHED\"" >> "$config_file"
- # updateCron.php retires mover.cron at the first sync or apply that finds this marker and the schedule replaced or disabled
+ # updateCron.php retires mover.cron at the first sync or apply that finds this marker and the schedule written, cleared or disabled
if touch /boot/config/plugins/&name;/retire.unraid.schedule; then
- echo "mover.cron becomes mover.cron.old once mover.tuning.cron is written or the schedule is disabled."
+ echo "mover.cron becomes mover.cron.old once mover.tuning.cron is written, or the schedule is cleared or disabled."
else
echo "The retirement marker could not be written, so mover.cron stays: rename it to mover.cron.old by hand."
fi
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php
index 99fdcc87..e3a8b152 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php
@@ -185,17 +185,17 @@ function sync_watchdog_cron()
}
}
-/** From Unraid 7.2.1, after the install migrated Unraid's schedule: renames Unraid's mover.cron to mover.cron.old once mover.tuning.cron exists or the schedule is disabled */
+/** From Unraid 7.2.1, after the install migrated Unraid's schedule: renames Unraid's mover.cron to mover.cron.old unless the Mover Tuning schedule is on, set and not written yet */
function retire_unraid_cron()
{
- global $vars, $cfg_moverDisabled;
+ global $vars, $cfg_moverDisabled, $cfg_moverTuneCron;
$mark = "/boot/config/plugins/ca.mover.tuning/retire.unraid.schedule";
$unraidFile = "/boot/config/plugins/dynamix/mover.cron";
if (is_file($mark) === false || $vars['version'] === '' || version_compare($vars['version'], '7.2.1', '<') === true) {
return;
}
- if ($cfg_moverDisabled !== 'yes' && is_file("/boot/config/plugins/ca.mover.tuning/mover.tuning.cron") === false) {
+ if ($cfg_moverDisabled !== 'yes' && $cfg_moverTuneCron !== '' && is_file("/boot/config/plugins/ca.mover.tuning/mover.tuning.cron") === false) {
logger("Unraid's mover schedule in $unraidFile is kept: mover.tuning.cron is not written yet.");
return;
}
From 84c0f82897b220becaac81711dc2a3111656ece1 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Tue, 24 Nov 2026 16:02:56 +0800
Subject: [PATCH 08/94] Pin what age_mover's moves do today, through the real
processTheMoves
tests/age_mover runs each row shape the planner writes through the real
processTheMoves, rsync and getMoverSettings in a throwaway Debian
container, with only Unraid's move stood in. It pins where names land,
the counters and the log lines, including today's held collisions, so
later changes to the group lookup show up as deliberate test edits.
---
.github/workflows/ci.yml | 18 ++++
tests/age_mover/lib.sh | 165 ++++++++++++++++++++++++++++++
tests/age_mover/run.sh | 23 +++++
tests/age_mover/test_moves.sh | 187 ++++++++++++++++++++++++++++++++++
4 files changed, 393 insertions(+)
create mode 100644 tests/age_mover/lib.sh
create mode 100644 tests/age_mover/run.sh
create mode 100644 tests/age_mover/test_moves.sh
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index deb03328..86195a02 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -83,3 +83,21 @@ jobs:
- name: Run tests
run: python -m pytest .github/scripts/release/tests -q
+
+ age-mover:
+ name: age_mover tests
+ runs-on: ubuntu-latest
+ container: debian:bookworm-slim
+ steps:
+ - name: Install the tools the mover uses
+ run: apt-get update -qq && apt-get install -y -qq --no-install-recommends rsync gawk psmisc procps util-linux
+
+ - name: Checkout
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+
+ - name: Run the age_mover tests
+ env:
+ AGE_MOVER_TEST: '1'
+ run: bash tests/age_mover/run.sh
diff --git a/tests/age_mover/lib.sh b/tests/age_mover/lib.sh
new file mode 100644
index 00000000..c4b944c4
--- /dev/null
+++ b/tests/age_mover/lib.sh
@@ -0,0 +1,165 @@
+#!/bin/bash
+# Sourced by test_*.sh: each case runs the real processTheMoves with real rsync and the shipped default.cfg read by the real
+# getMoverSettings; Unraid's move is a stand-in. It deletes /mnt/cache, /mnt/user0 and /mnt/other.
+HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+PLUGIN=$HERE/../../source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning
+AM=${AM:-$PLUGIN/age_mover}
+T=/tmp/age_mover_test
+
+# a bind mount at or above one of these would put the host's files under the wipe
+same_fs_as_root() {
+ local d
+ for d in /mnt /mnt/cache /mnt/user0 /mnt/other; do
+ [ ! -e "$d" ] || [ "$(stat -c %d "$d")" = "$(stat -c %d /)" ] || return 1
+ done
+}
+if [ "${AGE_MOVER_TEST:-}" != 1 ] || [ ! -e /.dockerenv ] || ! same_fs_as_root; then
+ echo "lib.sh deletes /mnt/cache, /mnt/user0 and /mnt/other: start the tests with tests/age_mover/run.sh" >&2
+ exit 2
+fi
+
+mkdir -p "$T/bin" "$T/cwd" /usr/libexec/unraid
+cat >/usr/libexec/unraid/move <<'EOF'
+#!/bin/bash
+# stand-in for Unraid's move: a name on the cache goes to the array (/mnt/user0), a name anywhere else goes to the cache
+while IFS= read -r p; do
+ [ -n "$p" ] || continue
+ root=${p#/mnt/} root=${root%%/*}
+ rel=${p#/mnt/"$root"/} to=/mnt/cache
+ [ "$root" = cache ] && to=/mnt/user0
+ mkdir -p "$to/${rel%/*}"
+ if [ -d "$p" ] && [ ! -L "$p" ]; then
+ mkdir -p "$to/$rel" && rmdir "$p" 2>/dev/null
+ else
+ mv -- "$p" "$to/$rel"
+ fi && echo "move: $p Success"
+done
+EOF
+chmod 755 /usr/libexec/unraid/move
+PATH=$T/bin:$PATH
+
+# age_mover runs its command on load, so only its functions and its top-level counters are taken
+awk '/^[A-Za-z_][A-Za-z0-9_]*\(\) \{/,/^\}/' "$AM" >"$T/funcs.sh"
+. "$T/funcs.sh"
+grep -E '^[A-Z_]+=(-?[0-9]+|"")$' "$AM" >"$T/globals.sh"
+if ! declare -F processTheMoves getMoverSettings >/dev/null; then
+ echo "lib.sh: processTheMoves or getMoverSettings did not load from $AM" >&2
+ exit 2
+fi
+LOGLEVEL=1 IS_CRON=1 DEBUGLEVEL=${AGE_MOVER_DEBUG:-0} LOGFOLDER=$T MOVER_LOG=$T/log MOVER_DEBUG_LOG=$T/dlog
+MOVER_STATUS=$T/mover.ini STATS_FILE=$T/stats MOVER_ACTIONLIST=$T/actions SOFTSTOPFILE=$T/softstop SOFTSTOP_ACK=false
+PAUSEFILE=$T/pause MOVINGFILE=$T/moving PIDFILE=$T/pid MOVERTUNINGCFGFILE=$T/cfg MOVERTUNING_OVERRIDE_CFGFOLDER=$T/overrides
+MOVERTUNING_DEFAULT_CFGFILE=$PLUGIN/default.cfg NOW=2026-01-02T030405 UNRAID_VERSION=7.2.0
+HDR='PRIMARYSTORAGENAME|SHARENAME|SHAREUSECACHE|MODIFYTIME|FILESIZE|POOLSUM|THRESHOLD|PROJECTED|NBLINKS|INODE|ACTION|FROM|TO|FILETYPE|FILEPATH'
+FAILS=0 CHECKS=0
+
+# setting [key value]...: the shipped defaults with these keys changed, as getMoverSettings reads them
+setting() {
+ cp "$PLUGIN/default.cfg" "$T/cfg"
+ while [ $# -ge 2 ]; do
+ grep -q "^$1=" "$T/cfg" || { echo "setting: $1 is not in default.cfg" >&2; exit 2; }
+ sed -i "s|^$1=.*|$1=\"$2\"|" "$T/cfg"
+ shift 2
+ done
+ getMoverSettings "$T/cfg" >/dev/null 2>&1
+ MOVER_PROGRESS=yes
+}
+
+# begin [key value]...: empty cache, array and other pool, and the case's settings
+begin() {
+ CASE=$1
+ shift
+ rm -rf /mnt/cache /mnt/user0 /mnt/other "$SOFTSTOPFILE" "$PAUSEFILE" "$T/after_rsync" "$T/bin/rsync"
+ mkdir -p /mnt/cache /mnt/user0
+ setting "$@"
+}
+
+# mk ...: a 2-byte file at /mnt//
+mk() {
+ local r=$1 p
+ shift
+ for p; do
+ mkdir -p "/mnt/$r/${p%/*}" && printf 'x\n' >"/mnt/$r/$p"
+ done
+}
+
+# row [links inode mtime]: the planner's row for the name, stat'd where it is now
+row() {
+ local from to p m i n s
+ case "$1" in
+ "keep on primary") from=/mnt/cache to=none ;;
+ *"from primary" | "sync unattended to secondary") from=/mnt/cache to=/mnt/user0 ;;
+ *"from secondary") from=/mnt/user0 to=/mnt/cache ;;
+ "move unattended to primary") from=/mnt/other to=/mnt/cache ;;
+ *) from=/mnt/other to=/mnt/user0 ;;
+ esac
+ for p in "$from/$3" "/mnt/other/$3"; do [ -e "$p" ] && break; done
+ read -r m i n s < <(stat -c '%Y %i %h %s' "$p")
+ printf 'cache|%s|yes|%s|%s|0|0|0|%s|%s|%s|%s|%s|%s|%s\n' "${3%%/*}" "${6:-$m}" "$s" "${4:-$n}" "${5:-$i}" "$1" "$from" "$to" "$2" "$3"
+}
+
+list() { { echo "$HDR"; cat; } >"$MOVER_ACTIONLIST"; }
+
+# after_first_rsync : runs the command once, right after the pass's first rsync call ends
+after_first_rsync() {
+ printf '%s\n' "$1" >"$T/after_rsync"
+ printf '#!/bin/bash\n%q "$@"\nrc=$?\n[ -e %q ] && { bash %q; rm -f %q; }\nexit $rc\n' \
+ "$(PATH=${PATH#"$T/bin:"} command -v rsync)" "$T/after_rsync" "$T/after_rsync" "$T/after_rsync" >"$T/bin/rsync"
+ chmod 755 "$T/bin/rsync"
+}
+
+# the totals the planner counts per direction; a staged move to the primary is counted by its sync row
+run_moves() {
+ . "$T/globals.sh"
+ read -r TOTALPRIMARYFILES TOTALPRIMARYFOLDERS TOTALPRIMARYSIZE TOTALSECONDARYFILES TOTALSECONDARYFOLDERS TOTALSECONDARYSIZE \
+ TOTALUNATTENDEDFILES TOTALUNATTENDEDFOLDERS TOTALUNATTENDEDSIZE < <(awk -F'|' '
+ NR == FNR { if ($11 == "sync unattended to secondary") staged[$15] = 1; next }
+ FNR == 1 { next }
+ { d = "" }
+ $11 == "move from primary" || $11 == "sync from primary" { d = "p" }
+ $11 == "move from secondary" || $11 == "sync from secondary" { d = "s" }
+ $11 ~ /unattended/ && !($11 == "move unattended to primary" && ($15 in staged)) { d = "u" }
+ d != "" { n[d ($14 == "d" ? "d" : "f")]++; sz[d] += $5 }
+ END { print n["pf"] + 0, n["pd"] + 0, sz["p"] + 0, n["sf"] + 0, n["sd"] + 0, sz["s"] + 0, n["uf"] + 0, n["ud"] + 0, sz["u"] + 0 }
+ ' "$MOVER_ACTIONLIST" "$MOVER_ACTIONLIST")
+ TOTALFILES=$((TOTALPRIMARYFILES + TOTALSECONDARYFILES + TOTALUNATTENDEDFILES))
+ TOTALFOLDERS=$((TOTALPRIMARYFOLDERS + TOTALSECONDARYFOLDERS + TOTALUNATTENDEDFOLDERS))
+ START_TIME=$EPOCHSECONDS
+ : >"$MOVER_LOG"
+ : >"$MOVER_DEBUG_LOG"
+ (
+ cd "$T/cwd" || exit
+ processTheMoves
+ for v in MOVEDFILES MOVEDFOLDERS NOTMOVEDFILES NOTMOVEDFOLDERS VANISHEDFILES VANISHEDFOLDERS INUSEFILES \
+ REMAINING_CACHE_FILES REMAINING_CACHE_FOLDERS REMAINING_ARRAY_FILES REMAINING_UNATTENDED_FILES; do
+ echo "$v=${!v}"
+ done >"$T/counters"
+ ) >"$T/out" 2>"$T/err"
+ . "$T/counters"
+}
+
+check() { # check
+ CHECKS=$((CHECKS + 1))
+ if [ "$2" = "$3" ]; then
+ echo "ok - $CASE: $1"
+ else
+ FAILS=$((FAILS + 1))
+ echo "not ok - $CASE: $1"
+ printf '%s\n' " expected:" "${2:-(nothing)}" " got:" "${3:-(nothing)}" | sed 's/^/ /'
+ fi
+}
+tree() { (cd "/mnt/$1" 2>/dev/null && find . -mindepth 1 | sed 's|^\./||' | LC_ALL=C sort); }
+# cache_is / array_is [path]...: exactly these names under /mnt/cache or /mnt/user0, nothing else
+cache_is() { check "cache holds exactly${*:+ $*}" "$( (($#)) && printf '%s\n' "$@" | LC_ALL=C sort)" "$(tree cache)"; }
+array_is() { check "array holds exactly${*:+ $*}" "$( (($#)) && printf '%s\n' "$@" | LC_ALL=C sort)" "$(tree user0)"; }
+links() { check "$2 on the array has $1 links" "$1" "$(stat -c %h "/mnt/user0/$2" 2>&1)"; }
+counter() { check "$1 is $2" "$2" "${!1}"; }
+log() { sed -E 's/^[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3} //' "$MOVER_LOG"; }
+log_has() { check "log has: $1" 1 "$(log | grep -cF -- "$1" | sed 's/^[1-9][0-9]*$/1/')"; }
+log_lacks() { check "log lacks: $1" 0 "$(log | grep -cF -- "$1")"; }
+log_count() { check "log has $1 lines with: $2" "$1" "$(log | grep -cF -- "$2")"; }
+
+finish() {
+ echo "# $(basename "$0"): $((CHECKS - FAILS)) of $CHECKS checks passed"
+ [ "$FAILS" = 0 ]
+}
diff --git a/tests/age_mover/run.sh b/tests/age_mover/run.sh
new file mode 100644
index 00000000..50e9708c
--- /dev/null
+++ b/tests/age_mover/run.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+# Runs every test_*.sh with debug logging off, then on. Without AGE_MOVER_TEST=1 it starts a container first (CI sets it):
+# the tests delete /mnt/cache, /mnt/user0 and /mnt/other, so set it only inside a throwaway container.
+HERE=$(cd "$(dirname "$0")" && pwd)
+if [ "${AGE_MOVER_TEST:-}" != 1 ]; then
+ exec docker run --rm --init -e AGE_MOVER_TEST=1 -v "$(cd "$HERE/../.." && pwd):/src:ro" \
+ "${AGE_MOVER_IMAGE:-debian:bookworm-slim}" bash /src/tests/age_mover/run.sh
+fi
+for c in rsync fuser pgrep gawk runuser; do
+ command -v "$c" >/dev/null && continue
+ apt-get update -qq && apt-get install -y -qq --no-install-recommends rsync gawk psmisc procps util-linux >/dev/null || exit 2
+ break
+done
+# Unraid's awk is gawk; Debian's default mawk would test other awk behaviour
+awk --version 2>/dev/null | grep -q '^GNU Awk' || { echo "awk is not GNU awk" >&2; exit 2; }
+rc=0
+for debug in 0 2; do
+ for t in "$HERE"/test_*.sh; do
+ echo "# $(basename "$t"), debug logging $([ "$debug" = 2 ] && echo on || echo off)"
+ AGE_MOVER_DEBUG=$debug bash "$t" || rc=1
+ done
+done
+exit $rc
diff --git a/tests/age_mover/test_moves.sh b/tests/age_mover/test_moves.sh
new file mode 100644
index 00000000..7a35abfb
--- /dev/null
+++ b/tests/age_mover/test_moves.sh
@@ -0,0 +1,187 @@
+#!/bin/bash
+# What each row shape the planner writes does today: where the names land, the counters and the log lines.
+. "$(dirname "$0")/lib.sh"
+
+for tool in rsync move; do
+ begin "names with space, |, \$, quotes and Unicode ($tool)" movefilesTool "$tool"
+ names=('sh/o/a b.txt' 'sh/o/p|ipe.txt' 'sh/o/trail|' 'sh/o/$HOME.txt' "sh/o/q\"uote's.txt" 'sh/o/ünï.txt')
+ mk cache "${names[@]}"
+ for n in "${names[@]}"; do row 'move from primary' f "$n"; done | list
+ run_moves
+ array_is sh sh/o "${names[@]}"
+ cache_is sh sh/o
+ counter MOVEDFILES 6
+ counter REMAINING_CACHE_FILES 0
+ log_has 'Moving "/mnt/cache/./sh/o/trail|" to "/mnt/user0/"'
+ log_has "Moving \"/mnt/cache/./sh/o/q\\\"uote's.txt\" to \"/mnt/user0/\""
+
+ begin "hardlink group, every name listed ($tool)" movefilesTool "$tool"
+ mk cache sh/h/a.txt
+ ln /mnt/cache/sh/h/a.txt /mnt/cache/sh/h/b.txt
+ { row 'move from primary' f sh/h/a.txt; row 'move from primary' f sh/h/b.txt; } | list
+ run_moves
+ array_is sh sh/h sh/h/a.txt sh/h/b.txt
+ links 2 sh/h/b.txt
+ counter MOVEDFILES 2
+ log_count 1 'Moving "/mnt/cache/./sh/h/a.txt" "/mnt/cache/./sh/h/b.txt" to "/mnt/user0/" (preserving hardlinks)'
+
+ begin "hardlink group across shares, both moved ($tool)" movefilesTool "$tool"
+ mk cache sh1/h/a.txt sh2/k/z.txt
+ ln /mnt/cache/sh1/h/a.txt /mnt/cache/sh2/k/b.txt
+ { row 'move from primary' f sh1/h/a.txt; row 'move from primary' f sh2/k/b.txt; } | list
+ run_moves
+ array_is sh1 sh1/h sh1/h/a.txt sh2 sh2/k sh2/k/b.txt
+ links 2 sh2/k/b.txt
+ cache_is sh1 sh1/h sh2 sh2/k sh2/k/z.txt
+ counter MOVEDFILES 2
+ log_count 1 'Moving "/mnt/cache/./sh1/h/a.txt" "/mnt/cache/./sh2/k/b.txt" to "/mnt/user0/" (preserving hardlinks)'
+
+ begin "folder rows: empty, and one that gained a file after planning ($tool)" movefilesTool "$tool"
+ mkdir -p /mnt/cache/sh/e/sub
+ mk cache sh/g/new.txt
+ { row 'move from primary' d sh/e/sub; row 'move from primary' d sh/g; } | list
+ run_moves
+ array_is sh sh/e sh/e/sub sh/g
+ cache_is sh sh/g sh/g/new.txt
+ counter MOVEDFOLDERS 2
+ counter REMAINING_CACHE_FOLDERS 0
+ log_has 'Deleted empty moved folder: /mnt/cache/sh/e'
+ log_has 'Not deleting folder: contains 1 file(s), 0 subfolder(s): /mnt/cache/sh/g'
+
+ begin "test mode ($tool)" movefilesTool "$tool" testmode yes synchronizeCache yes
+ mk cache sh/t/f.txt sh/t/s.txt
+ mkdir -p /mnt/cache/sh/t/e
+ { row 'move from primary' f sh/t/f.txt; row 'move from primary' d sh/t/e; row 'sync from primary' f sh/t/s.txt; } | list
+ run_moves
+ array_is
+ cache_is sh sh/t sh/t/e sh/t/f.txt sh/t/s.txt
+ counter MOVEDFILES 0
+ log_has "$([ "$tool" = move ] && echo 'TEST MODE: Would move using Unraid move utility' || echo 'TEST MODE: Would Move using rsync utility')"
+ log_has 'TEST MODE: Would delete moved empty folder: /mnt/cache/sh/t/e'
+ log_lacks 'Set last sync date'
+
+ begin "move from secondary, cache:prefer ($tool)" movefilesTool "$tool"
+ mk user0 sh/p/f.txt
+ row 'move from secondary' f sh/p/f.txt | list
+ run_moves
+ cache_is sh sh/p sh/p/f.txt
+ array_is sh sh/p
+ log_has 'Moving "/mnt/user0/./sh/p/f.txt" to "/mnt/cache/"'
+ log_has '0 files remaining from array to caches'
+
+ begin "unattended file staged to the primary, then synced ($tool)" movefilesTool "$tool" synchronizeCache yes
+ mk other sh/x/f.txt
+ { row 'move unattended to primary' f sh/x/f.txt; row 'sync unattended to secondary' f sh/x/f.txt; } | list
+ run_moves
+ cache_is sh sh/x sh/x/f.txt
+ array_is sh sh/x sh/x/f.txt
+ counter MOVEDFILES 1
+ counter REMAINING_UNATTENDED_FILES 0
+ log_has 'Synchronizing "/mnt/cache/./sh/x/f.txt" to "/mnt/user0/"'
+ log_has 'Set last sync date in config file/s: 1767323045 = 2026-01-02T030405'
+done
+
+# bash read drops a | that ends the row, which would skip the check on a name like a|
+for n in a.txt 'a|'; do
+ begin "hardlink group with a name not listed, $n"
+ mk cache "sh/h/$n" sh/k/z.txt
+ ln "/mnt/cache/sh/h/$n" /mnt/cache/sh/k/b.txt
+ row 'move from primary' f "sh/h/$n" | list
+ run_moves
+ array_is
+ cache_is sh sh/h "sh/h/$n" sh/k sh/k/b.txt sh/k/z.txt
+ counter NOTMOVEDFILES 1
+ log_has "Expected 2 files, got 1. Not moving \"/mnt/cache/./sh/h/$n\" to prevent breaking hardlinks"
+done
+
+begin "hardlink group across shares, planned differently"
+mk cache sh1/h/a.txt
+mkdir -p /mnt/cache/sh2/k
+ln /mnt/cache/sh1/h/a.txt /mnt/cache/sh2/k/b.txt
+{ row 'move from primary' f sh1/h/a.txt; row 'keep on primary' f sh2/k/b.txt; } | list
+run_moves
+array_is
+counter NOTMOVEDFILES 1
+log_has 'Expected 2 files, got 1. Not moving "/mnt/cache/./sh1/h/a.txt"'
+
+# two ZFS datasets of one pool can give two single-link files the same inode number and mtime: today both are held
+begin "single-link files sharing inode and mtime across shares"
+mk cache sh1/d/a.txt sh2/d/b.txt
+{ row 'move from primary' f sh1/d/a.txt 1 777 1700000000; row 'move from primary' f sh2/d/b.txt 1 777 1700000000; } | list
+run_moves
+array_is
+counter NOTMOVEDFILES 4
+log_count 2 'Expected 1 files, got 2. Not moving "/mnt/cache/./sh1/d/a.txt" "/mnt/cache/./sh2/d/b.txt"'
+
+# the same for two empty folders: today both rows move the pair, and the second finds one gone
+begin "folder rows sharing inode and mtime across shares"
+mkdir -p /mnt/cache/sh1/e /mnt/cache/sh2/e
+{ row 'move from primary' d sh1/e 2 778 1700000000; row 'move from primary' d sh2/e 2 778 1700000000; } | list
+run_moves
+array_is sh1 sh1/e sh2 sh2/e
+cache_is sh1 sh2
+counter MOVEDFOLDERS 2
+counter VANISHEDFOLDERS 1
+counter REMAINING_CACHE_FOLDERS -2
+log_count 2 'Moving "/mnt/cache/./sh1/e" "/mnt/cache/./sh2/e" to "/mnt/user0/"'
+log_has 'Gone from the source before its turn: "/mnt/cache/sh1/e"'
+
+begin "a pass with nothing to move"
+mk cache sh/k/k.txt
+row 'keep on primary' f sh/k/k.txt | list
+run_moves
+array_is
+cache_is sh sh/k sh/k/k.txt
+log_lacks 'Moving'
+
+begin "sync from primary keeps the file and sets the sync date" synchronizeCache yes
+mk cache sh/y/f.txt
+row 'sync from primary' f sh/y/f.txt | list
+run_moves
+cache_is sh sh/y sh/y/f.txt
+array_is sh sh/y sh/y/f.txt
+counter MOVEDFILES 1
+check "lastCacheSync saved" 'lastCacheSync="1767323045"' "$(grep '^lastCacheSync=' "$T/cfg")"
+
+for inuse in no yes; do
+ begin "a file open in another process, moveInUse $inuse" moveInUse "$inuse"
+ mk cache sh/u/busy.txt sh/u/free.txt
+ sleep 300 3<"/mnt/cache/sh/u/busy.txt" >/dev/null 2>&1 &
+ holder=$!
+ { row 'move from primary' f sh/u/busy.txt; row 'move from primary' f sh/u/free.txt; } | list
+ run_moves
+ kill "$holder"
+ if [ "$inuse" = no ]; then
+ cache_is sh sh/u sh/u/busy.txt
+ array_is sh sh/u sh/u/free.txt
+ counter INUSEFILES 1
+ log_has 'In use, left for a later run: "/mnt/cache/./sh/u/busy.txt"'
+ log_has '1 files were in use and stay on the source until a later run'
+ else
+ cache_is sh sh/u
+ array_is sh sh/u sh/u/busy.txt sh/u/free.txt
+ counter INUSEFILES 0
+ fi
+done
+
+begin "soft stop after the first file"
+mk cache sh/s/1.txt sh/s/2.txt sh/s/3.txt
+for n in 1 2 3; do row 'move from primary' f "sh/s/$n.txt"; done | list
+after_first_rsync "touch $SOFTSTOPFILE"
+run_moves
+array_is sh sh/s sh/s/1.txt
+cache_is sh sh/s sh/s/2.txt sh/s/3.txt
+counter MOVEDFILES 1
+log_count 1 'Soft Stopping requested'
+
+begin "pause after the first file, resumed 2 s later"
+mk cache sh/s/1.txt sh/s/2.txt
+for n in 1 2; do row 'move from primary' f "sh/s/$n.txt"; done | list
+after_first_rsync "echo $$ >$PAUSEFILE; (sleep 2; rm -f $PAUSEFILE) >/dev/null 2>&1 &"
+run_moves
+array_is sh sh/s sh/s/1.txt sh/s/2.txt
+counter MOVEDFILES 2
+log_has 'Paused: no file moves until Resume'
+log_has 'Resumed after'
+
+finish
From e0e241e762b35c7e5fe1d41becb80363efc4c0e0 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Tue, 24 Nov 2026 16:28:46 +0800
Subject: [PATCH 09/94] Make the age_mover harness fail loudly, run debug for
real and pin byte counters
The move stand-in copies, so names of one inode stay linked only within one run. A row for a missing name, stderr or an early exit fails the case. Debug logging really turns on in the second pass, rows from the array come from a disk, a hardlink group's size counts once as in the planner, and the in-use, soft stop and pause cases wait for a later PR.
---
.github/workflows/ci.yml | 4 +-
tests/age_mover/lib.sh | 85 +++++++++++++++++------------------
tests/age_mover/run.sh | 6 ++-
tests/age_mover/test_moves.sh | 80 ++++++++++++++-------------------
4 files changed, 80 insertions(+), 95 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 86195a02..53140281 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -88,10 +88,8 @@ jobs:
name: age_mover tests
runs-on: ubuntu-latest
container: debian:bookworm-slim
+ timeout-minutes: 10
steps:
- - name: Install the tools the mover uses
- run: apt-get update -qq && apt-get install -y -qq --no-install-recommends rsync gawk psmisc procps util-linux
-
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
diff --git a/tests/age_mover/lib.sh b/tests/age_mover/lib.sh
index c4b944c4..91f669bd 100644
--- a/tests/age_mover/lib.sh
+++ b/tests/age_mover/lib.sh
@@ -1,27 +1,25 @@
#!/bin/bash
# Sourced by test_*.sh: each case runs the real processTheMoves with real rsync and the shipped default.cfg read by the real
-# getMoverSettings; Unraid's move is a stand-in. It deletes /mnt/cache, /mnt/user0 and /mnt/other.
+# getMoverSettings; Unraid's move is a stand-in. It deletes the folders in ROOTS.
HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
PLUGIN=$HERE/../../source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning
AM=${AM:-$PLUGIN/age_mover}
T=/tmp/age_mover_test
+ROOTS=(/mnt/cache /mnt/user0 /mnt/disk1 /mnt/disk2 /mnt/other)
-# a bind mount at or above one of these would put the host's files under the wipe
-same_fs_as_root() {
- local d
- for d in /mnt /mnt/cache /mnt/user0 /mnt/other; do
- [ ! -e "$d" ] || [ "$(stat -c %d "$d")" = "$(stat -c %d /)" ] || return 1
- done
-}
-if [ "${AGE_MOVER_TEST:-}" != 1 ] || [ ! -e /.dockerenv ] || ! same_fs_as_root; then
- echo "lib.sh deletes /mnt/cache, /mnt/user0 and /mnt/other: start the tests with tests/age_mover/run.sh" >&2
+# a mount at or under /mnt would put the host's files under the wipe; an unreadable mount table refuses too
+no_mount_under_mnt() { awk '$5 == "/mnt" || index($5, "/mnt/") == 1 { exit 1 }' /proc/self/mountinfo; }
+if [ "${AGE_MOVER_TEST:-}" != 1 ] || [ ! -e /.dockerenv ] || ! no_mount_under_mnt; then
+ echo "lib.sh deletes ${ROOTS[*]}: start the tests with tests/age_mover/run.sh" >&2
exit 2
fi
-mkdir -p "$T/bin" "$T/cwd" /usr/libexec/unraid
+mkdir -p "$T/cwd" /usr/libexec/unraid
cat >/usr/libexec/unraid/move <<'EOF'
#!/bin/bash
-# stand-in for Unraid's move: a name on the cache goes to the array (/mnt/user0), a name anywhere else goes to the cache
+# stand-in for Unraid's move: a name on the cache goes to the array (/mnt/user0), a name anywhere else to the cache.
+# A file is copied, as across disks, so names of one inode stay linked only when they come in the same run.
+declare -A linked
while IFS= read -r p; do
[ -n "$p" ] || continue
root=${p#/mnt/} root=${root%%/*}
@@ -31,14 +29,14 @@ while IFS= read -r p; do
if [ -d "$p" ] && [ ! -L "$p" ]; then
mkdir -p "$to/$rel" && rmdir "$p" 2>/dev/null
else
- mv -- "$p" "$to/$rel"
+ i=$(stat -c %i "$p")
+ if [ -n "${linked[$i]}" ]; then ln -- "${linked[$i]}" "$to/$rel"; else cp -a -- "$p" "$to/$rel"; fi && rm -- "$p" && linked[$i]=$to/$rel
fi && echo "move: $p Success"
done
EOF
chmod 755 /usr/libexec/unraid/move
-PATH=$T/bin:$PATH
-# age_mover runs its command on load, so only its functions and its top-level counters are taken
+# age_mover runs its command on load, so only its functions and its top-level start values are taken
awk '/^[A-Za-z_][A-Za-z0-9_]*\(\) \{/,/^\}/' "$AM" >"$T/funcs.sh"
. "$T/funcs.sh"
grep -E '^[A-Z_]+=(-?[0-9]+|"")$' "$AM" >"$T/globals.sh"
@@ -46,10 +44,13 @@ if ! declare -F processTheMoves getMoverSettings >/dev/null; then
echo "lib.sh: processTheMoves or getMoverSettings did not load from $AM" >&2
exit 2
fi
-LOGLEVEL=1 IS_CRON=1 DEBUGLEVEL=${AGE_MOVER_DEBUG:-0} LOGFOLDER=$T MOVER_LOG=$T/log MOVER_DEBUG_LOG=$T/dlog
+LOGFOLDER=$T MOVER_LOG=$T/log MOVER_DEBUG_LOG=$T/dlog
MOVER_STATUS=$T/mover.ini STATS_FILE=$T/stats MOVER_ACTIONLIST=$T/actions SOFTSTOPFILE=$T/softstop SOFTSTOP_ACK=false
PAUSEFILE=$T/pause MOVINGFILE=$T/moving PIDFILE=$T/pid MOVERTUNINGCFGFILE=$T/cfg MOVERTUNING_OVERRIDE_CFGFOLDER=$T/overrides
MOVERTUNING_DEFAULT_CFGFILE=$PLUGIN/default.cfg NOW=2026-01-02T030405 UNRAID_VERSION=7.2.0
+export TZ=UTC # NOW turns into the sync date in local time
+DEBUGLOGGING=no
+[ "${AGE_MOVER_DEBUG:-0}" != 2 ] || DEBUGLOGGING=fileOnly
HDR='PRIMARYSTORAGENAME|SHARENAME|SHAREUSECACHE|MODIFYTIME|FILESIZE|POOLSUM|THRESHOLD|PROJECTED|NBLINKS|INODE|ACTION|FROM|TO|FILETYPE|FILEPATH'
FAILS=0 CHECKS=0
@@ -61,17 +62,19 @@ setting() {
sed -i "s|^$1=.*|$1=\"$2\"|" "$T/cfg"
shift 2
done
- getMoverSettings "$T/cfg" >/dev/null 2>&1
+ getMoverSettings "$T/cfg" >/dev/null 2>&1 || { echo "setting: getMoverSettings failed on $T/cfg" >&2; exit 2; }
MOVER_PROGRESS=yes
}
-# begin [key value]...: empty cache, array and other pool, and the case's settings
+# begin [key value]...: empty pools and disks, age_mover's start values and the case's settings
begin() {
CASE=$1
shift
- rm -rf /mnt/cache /mnt/user0 /mnt/other "$SOFTSTOPFILE" "$PAUSEFILE" "$T/after_rsync" "$T/bin/rsync"
+ rm -rf "${ROOTS[@]}" "$SOFTSTOPFILE" "$PAUSEFILE" "$T/row_error"
mkdir -p /mnt/cache /mnt/user0
- setting "$@"
+ . "$T/globals.sh"
+ IS_CRON=1 # after the start values: as under cron, nothing goes to syslog
+ setting debuglogging "$DEBUGLOGGING" "$@"
}
# mk ...: a 2-byte file at /mnt//
@@ -83,42 +86,37 @@ mk() {
done
}
-# row [links inode mtime]: the planner's row for the name, stat'd where it is now
+# row [links inode mtime]: the planner's row for the name, stat'd where it is now; the
+# planner reads the array by disk, so a row from the secondary comes from /mnt/disk1 or /mnt/disk2
row() {
local from to p m i n s
case "$1" in
"keep on primary") from=/mnt/cache to=none ;;
*"from primary" | "sync unattended to secondary") from=/mnt/cache to=/mnt/user0 ;;
- *"from secondary") from=/mnt/user0 to=/mnt/cache ;;
+ *"from secondary") from=/mnt/disk1 to=/mnt/cache; [ -e "/mnt/disk2/$3" ] && from=/mnt/disk2 ;;
"move unattended to primary") from=/mnt/other to=/mnt/cache ;;
*) from=/mnt/other to=/mnt/user0 ;;
esac
- for p in "$from/$3" "/mnt/other/$3"; do [ -e "$p" ] && break; done
+ for p in "$from/$3" "/mnt/other/$3" ""; do [ -e "$p" ] && break; done
+ [ -n "$p" ] || { echo "row: no $3 under $from or /mnt/other" | tee -a "$T/row_error" >&2; return 1; }
read -r m i n s < <(stat -c '%Y %i %h %s' "$p")
printf 'cache|%s|yes|%s|%s|0|0|0|%s|%s|%s|%s|%s|%s|%s\n' "${3%%/*}" "${6:-$m}" "$s" "${4:-$n}" "${5:-$i}" "$1" "$from" "$to" "$2" "$3"
}
-list() { { echo "$HDR"; cat; } >"$MOVER_ACTIONLIST"; }
-
-# after_first_rsync : runs the command once, right after the pass's first rsync call ends
-after_first_rsync() {
- printf '%s\n' "$1" >"$T/after_rsync"
- printf '#!/bin/bash\n%q "$@"\nrc=$?\n[ -e %q ] && { bash %q; rm -f %q; }\nexit $rc\n' \
- "$(PATH=${PATH#"$T/bin:"} command -v rsync)" "$T/after_rsync" "$T/after_rsync" "$T/after_rsync" >"$T/bin/rsync"
- chmod 755 "$T/bin/rsync"
-}
+# list: the rows on stdin as the action list; as in the planner, a hardlink group's size counts on its first name only
+list() { { echo "$HDR"; awk -F'|' -v OFS='|' '$9 > 1 && seen[$12 "|" $9 "|" $10 "|" $4]++ { $5 = 0 } 1'; } >"$MOVER_ACTIONLIST"; }
# the totals the planner counts per direction; a staged move to the primary is counted by its sync row
run_moves() {
- . "$T/globals.sh"
read -r TOTALPRIMARYFILES TOTALPRIMARYFOLDERS TOTALPRIMARYSIZE TOTALSECONDARYFILES TOTALSECONDARYFOLDERS TOTALSECONDARYSIZE \
TOTALUNATTENDEDFILES TOTALUNATTENDEDFOLDERS TOTALUNATTENDEDSIZE < <(awk -F'|' '
- NR == FNR { if ($11 == "sync unattended to secondary") staged[$15] = 1; next }
+ function path( p, i) { p = $15; for (i = 16; i <= NF; i++) p = p "|" $i; return p }
+ NR == FNR { if ($11 == "sync unattended to secondary") staged[path()] = 1; next }
FNR == 1 { next }
{ d = "" }
$11 == "move from primary" || $11 == "sync from primary" { d = "p" }
$11 == "move from secondary" || $11 == "sync from secondary" { d = "s" }
- $11 ~ /unattended/ && !($11 == "move unattended to primary" && ($15 in staged)) { d = "u" }
+ $11 ~ /unattended/ && !($11 == "move unattended to primary" && (path() in staged)) { d = "u" }
d != "" { n[d ($14 == "d" ? "d" : "f")]++; sz[d] += $5 }
END { print n["pf"] + 0, n["pd"] + 0, sz["p"] + 0, n["sf"] + 0, n["sd"] + 0, sz["s"] + 0, n["uf"] + 0, n["ud"] + 0, sz["u"] + 0 }
' "$MOVER_ACTIONLIST" "$MOVER_ACTIONLIST")
@@ -127,15 +125,15 @@ run_moves() {
START_TIME=$EPOCHSECONDS
: >"$MOVER_LOG"
: >"$MOVER_DEBUG_LOG"
+ rm -f "$T/counters"
(
cd "$T/cwd" || exit
processTheMoves
- for v in MOVEDFILES MOVEDFOLDERS NOTMOVEDFILES NOTMOVEDFOLDERS VANISHEDFILES VANISHEDFOLDERS INUSEFILES \
- REMAINING_CACHE_FILES REMAINING_CACHE_FOLDERS REMAINING_ARRAY_FILES REMAINING_UNATTENDED_FILES; do
- echo "$v=${!v}"
- done >"$T/counters"
+ while IFS== read -r v _; do printf '%s=%q\n' "$v" "${!v}"; done <"$T/globals.sh" >"$T/counters"
) >"$T/out" 2>"$T/err"
- . "$T/counters"
+ check "the rows were built and processTheMoves returned with nothing on stderr" "" \
+ "$(cat "$T/row_error" "$T/err" 2>/dev/null; [ -f "$T/counters" ] || echo "processTheMoves did not return")"
+ [ ! -f "$T/counters" ] || . "$T/counters"
}
check() { # check
@@ -149,9 +147,10 @@ check() { # check
fi
}
tree() { (cd "/mnt/$1" 2>/dev/null && find . -mindepth 1 | sed 's|^\./||' | LC_ALL=C sort); }
-# cache_is / array_is [path]...: exactly these names under /mnt/cache or /mnt/user0, nothing else
-cache_is() { check "cache holds exactly${*:+ $*}" "$( (($#)) && printf '%s\n' "$@" | LC_ALL=C sort)" "$(tree cache)"; }
-array_is() { check "array holds exactly${*:+ $*}" "$( (($#)) && printf '%s\n' "$@" | LC_ALL=C sort)" "$(tree user0)"; }
+# holds [path]...: exactly these names under /mnt/, nothing else
+holds() { local r=$1; shift; check "$r holds exactly${*:+ $*}" "$( (($#)) && printf '%s\n' "$@" | LC_ALL=C sort)" "$(tree "$r")"; }
+cache_is() { holds cache "$@"; }
+array_is() { holds user0 "$@"; }
links() { check "$2 on the array has $1 links" "$1" "$(stat -c %h "/mnt/user0/$2" 2>&1)"; }
counter() { check "$1 is $2" "$2" "${!1}"; }
log() { sed -E 's/^[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3} //' "$MOVER_LOG"; }
diff --git a/tests/age_mover/run.sh b/tests/age_mover/run.sh
index 50e9708c..58dd27db 100644
--- a/tests/age_mover/run.sh
+++ b/tests/age_mover/run.sh
@@ -1,12 +1,14 @@
#!/bin/bash
# Runs every test_*.sh with debug logging off, then on. Without AGE_MOVER_TEST=1 it starts a container first (CI sets it):
-# the tests delete /mnt/cache, /mnt/user0 and /mnt/other, so set it only inside a throwaway container.
+# the tests delete folders under /mnt, so set it only inside a throwaway container.
HERE=$(cd "$(dirname "$0")" && pwd)
if [ "${AGE_MOVER_TEST:-}" != 1 ]; then
exec docker run --rm --init -e AGE_MOVER_TEST=1 -v "$(cd "$HERE/../.." && pwd):/src:ro" \
"${AGE_MOVER_IMAGE:-debian:bookworm-slim}" bash /src/tests/age_mover/run.sh
fi
-for c in rsync fuser pgrep gawk runuser; do
+# packages go in only inside a container: AGE_MOVER_TEST=1 on a host must not change its packages
+[ -e /.dockerenv ] || { echo "run.sh: AGE_MOVER_TEST=1 is set outside a container" >&2; exit 2; }
+for c in rsync fuser pgrep gawk; do
command -v "$c" >/dev/null && continue
apt-get update -qq && apt-get install -y -qq --no-install-recommends rsync gawk psmisc procps util-linux >/dev/null || exit 2
break
diff --git a/tests/age_mover/test_moves.sh b/tests/age_mover/test_moves.sh
index 7a35abfb..bbba7d28 100644
--- a/tests/age_mover/test_moves.sh
+++ b/tests/age_mover/test_moves.sh
@@ -1,5 +1,5 @@
#!/bin/bash
-# What each row shape the planner writes does today: where the names land, the counters and the log lines.
+# What processTheMoves does today with the planner's rows: where the names land, the counters and the log lines.
. "$(dirname "$0")/lib.sh"
for tool in rsync move; do
@@ -12,6 +12,9 @@ for tool in rsync move; do
cache_is sh sh/o
counter MOVEDFILES 6
counter REMAINING_CACHE_FILES 0
+ counter MOVEDSIZE 12
+ check "debug blocks written only with AGE_MOVER_DEBUG=2" "$([ "${AGE_MOVER_DEBUG:-0}" = 2 ] && echo yes || echo no)" \
+ "$(grep -qF Debugging "$MOVER_DEBUG_LOG" && echo yes || echo no)"
log_has 'Moving "/mnt/cache/./sh/o/trail|" to "/mnt/user0/"'
log_has "Moving \"/mnt/cache/./sh/o/q\\\"uote's.txt\" to \"/mnt/user0/\""
@@ -23,6 +26,8 @@ for tool in rsync move; do
array_is sh sh/h sh/h/a.txt sh/h/b.txt
links 2 sh/h/b.txt
counter MOVEDFILES 2
+ counter MOVEDSIZE 2
+ counter REMAINING_CACHE_SIZE 0
log_count 1 'Moving "/mnt/cache/./sh/h/a.txt" "/mnt/cache/./sh/h/b.txt" to "/mnt/user0/" (preserving hardlinks)'
begin "hardlink group across shares, both moved ($tool)" movefilesTool "$tool"
@@ -34,6 +39,7 @@ for tool in rsync move; do
links 2 sh2/k/b.txt
cache_is sh1 sh1/h sh2 sh2/k sh2/k/z.txt
counter MOVEDFILES 2
+ counter MOVEDSIZE 2
log_count 1 'Moving "/mnt/cache/./sh1/h/a.txt" "/mnt/cache/./sh2/k/b.txt" to "/mnt/user0/" (preserving hardlinks)'
begin "folder rows: empty, and one that gained a file after planning ($tool)" movefilesTool "$tool"
@@ -60,13 +66,13 @@ for tool in rsync move; do
log_has 'TEST MODE: Would delete moved empty folder: /mnt/cache/sh/t/e'
log_lacks 'Set last sync date'
- begin "move from secondary, cache:prefer ($tool)" movefilesTool "$tool"
- mk user0 sh/p/f.txt
+ begin "move from secondary ($tool)" movefilesTool "$tool"
+ mk disk1 sh/p/f.txt
row 'move from secondary' f sh/p/f.txt | list
run_moves
cache_is sh sh/p sh/p/f.txt
- array_is sh sh/p
- log_has 'Moving "/mnt/user0/./sh/p/f.txt" to "/mnt/cache/"'
+ holds disk1 sh sh/p
+ log_has 'Moving "/mnt/disk1/./sh/p/f.txt" to "/mnt/cache/"'
log_has '0 files remaining from array to caches'
begin "unattended file staged to the primary, then synced ($tool)" movefilesTool "$tool" synchronizeCache yes
@@ -77,6 +83,7 @@ for tool in rsync move; do
array_is sh sh/x sh/x/f.txt
counter MOVEDFILES 1
counter REMAINING_UNATTENDED_FILES 0
+ counter REMAINING_UNATTENDED_SIZE 0
log_has 'Synchronizing "/mnt/cache/./sh/x/f.txt" to "/mnt/user0/"'
log_has 'Set last sync date in config file/s: 1767323045 = 2026-01-02T030405'
done
@@ -91,6 +98,8 @@ for n in a.txt 'a|'; do
array_is
cache_is sh sh/h "sh/h/$n" sh/k sh/k/b.txt sh/k/z.txt
counter NOTMOVEDFILES 1
+ counter NOTMOVEDSIZE 2
+ counter REMAINING_CACHE_SIZE 2
log_has "Expected 2 files, got 1. Not moving \"/mnt/cache/./sh/h/$n\" to prevent breaking hardlinks"
done
@@ -104,13 +113,30 @@ array_is
counter NOTMOVEDFILES 1
log_has 'Expected 2 files, got 1. Not moving "/mnt/cache/./sh1/h/a.txt"'
-# two ZFS datasets of one pool can give two single-link files the same inode number and mtime: today both are held
+# each disk numbers its own inodes: the group lookup takes only the names on the row's disk
+begin "hardlink groups on two disks sharing inode and mtime"
+mk disk1 sh/p/a.txt
+mk disk2 sh/p/b.txt
+ln /mnt/disk1/sh/p/a.txt /mnt/disk1/sh/p/a2.txt
+ln /mnt/disk2/sh/p/b.txt /mnt/disk2/sh/p/b2.txt
+for n in a a2 b b2; do row 'move from secondary' f "sh/p/$n.txt" 2 777 1700000000; done | list
+run_moves
+cache_is sh sh/p sh/p/a.txt sh/p/a2.txt sh/p/b.txt sh/p/b2.txt
+holds disk1 sh sh/p
+holds disk2 sh sh/p
+counter MOVEDFILES 4
+counter MOVEDSIZE 4
+
+# two ZFS datasets of one pool can give two single-link files the same inode number and mtime: today both are held,
+# and their bytes count once
begin "single-link files sharing inode and mtime across shares"
mk cache sh1/d/a.txt sh2/d/b.txt
{ row 'move from primary' f sh1/d/a.txt 1 777 1700000000; row 'move from primary' f sh2/d/b.txt 1 777 1700000000; } | list
run_moves
array_is
counter NOTMOVEDFILES 4
+counter NOTMOVEDSIZE 2
+counter REMAINING_CACHE_SIZE 4
log_count 2 'Expected 1 files, got 2. Not moving "/mnt/cache/./sh1/d/a.txt" "/mnt/cache/./sh2/d/b.txt"'
# the same for two empty folders: today both rows move the pair, and the second finds one gone
@@ -141,47 +167,7 @@ run_moves
cache_is sh sh/y sh/y/f.txt
array_is sh sh/y sh/y/f.txt
counter MOVEDFILES 1
+counter MOVEDSIZE 2
check "lastCacheSync saved" 'lastCacheSync="1767323045"' "$(grep '^lastCacheSync=' "$T/cfg")"
-for inuse in no yes; do
- begin "a file open in another process, moveInUse $inuse" moveInUse "$inuse"
- mk cache sh/u/busy.txt sh/u/free.txt
- sleep 300 3<"/mnt/cache/sh/u/busy.txt" >/dev/null 2>&1 &
- holder=$!
- { row 'move from primary' f sh/u/busy.txt; row 'move from primary' f sh/u/free.txt; } | list
- run_moves
- kill "$holder"
- if [ "$inuse" = no ]; then
- cache_is sh sh/u sh/u/busy.txt
- array_is sh sh/u sh/u/free.txt
- counter INUSEFILES 1
- log_has 'In use, left for a later run: "/mnt/cache/./sh/u/busy.txt"'
- log_has '1 files were in use and stay on the source until a later run'
- else
- cache_is sh sh/u
- array_is sh sh/u sh/u/busy.txt sh/u/free.txt
- counter INUSEFILES 0
- fi
-done
-
-begin "soft stop after the first file"
-mk cache sh/s/1.txt sh/s/2.txt sh/s/3.txt
-for n in 1 2 3; do row 'move from primary' f "sh/s/$n.txt"; done | list
-after_first_rsync "touch $SOFTSTOPFILE"
-run_moves
-array_is sh sh/s sh/s/1.txt
-cache_is sh sh/s sh/s/2.txt sh/s/3.txt
-counter MOVEDFILES 1
-log_count 1 'Soft Stopping requested'
-
-begin "pause after the first file, resumed 2 s later"
-mk cache sh/s/1.txt sh/s/2.txt
-for n in 1 2; do row 'move from primary' f "sh/s/$n.txt"; done | list
-after_first_rsync "echo $$ >$PAUSEFILE; (sleep 2; rm -f $PAUSEFILE) >/dev/null 2>&1 &"
-run_moves
-array_is sh sh/s sh/s/1.txt sh/s/2.txt
-counter MOVEDFILES 2
-log_has 'Paused: no file moves until Resume'
-log_has 'Resumed after'
-
finish
From 076f94636decd373ca846c51b760155d92ff6cfc Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Tue, 24 Nov 2026 16:35:23 +0800
Subject: [PATCH 10/94] Tell ShellCheck that age_mover's functions read the
harness settings
---
tests/age_mover/lib.sh | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tests/age_mover/lib.sh b/tests/age_mover/lib.sh
index 91f669bd..8edb0b19 100644
--- a/tests/age_mover/lib.sh
+++ b/tests/age_mover/lib.sh
@@ -1,4 +1,5 @@
#!/bin/bash
+# shellcheck disable=SC2034 # the settings set here are read by age_mover's functions, sourced from funcs.sh
# Sourced by test_*.sh: each case runs the real processTheMoves with real rsync and the shipped default.cfg read by the real
# getMoverSettings; Unraid's move is a stand-in. It deletes the folders in ROOTS.
HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
@@ -129,7 +130,7 @@ run_moves() {
(
cd "$T/cwd" || exit
processTheMoves
- while IFS== read -r v _; do printf '%s=%q\n' "$v" "${!v}"; done <"$T/globals.sh" >"$T/counters"
+ while IFS='=' read -r v _; do printf '%s=%q\n' "$v" "${!v}"; done <"$T/globals.sh" >"$T/counters"
) >"$T/out" 2>"$T/err"
check "the rows were built and processTheMoves returned with nothing on stderr" "" \
"$(cat "$T/row_error" "$T/err" 2>/dev/null; [ -f "$T/counters" ] || echo "processTheMoves did not return")"
From 080e0e3463f840abae9411e778ec633e8bd94ab4 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Tue, 24 Nov 2026 17:08:23 +0800
Subject: [PATCH 11/94] Pin what age_mover's folder cleanup does today, through
the real processTheMoves
---
tests/age_mover/lib.sh | 54 +++++++---
tests/age_mover/run.sh | 4 +-
tests/age_mover/test_folders.sh | 179 ++++++++++++++++++++++++++++++++
3 files changed, 223 insertions(+), 14 deletions(-)
create mode 100644 tests/age_mover/test_folders.sh
diff --git a/tests/age_mover/lib.sh b/tests/age_mover/lib.sh
index 8edb0b19..0f1e0758 100644
--- a/tests/age_mover/lib.sh
+++ b/tests/age_mover/lib.sh
@@ -1,11 +1,11 @@
#!/bin/bash
# shellcheck disable=SC2034 # the settings set here are read by age_mover's functions, sourced from funcs.sh
# Sourced by test_*.sh: each case runs the real processTheMoves with real rsync and the shipped default.cfg read by the real
-# getMoverSettings; Unraid's move is a stand-in. It deletes the folders in ROOTS.
+# getMoverSettings; Unraid's move, findmnt and zfs are stand-ins. It deletes the folders in ROOTS.
HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
PLUGIN=$HERE/../../source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning
AM=${AM:-$PLUGIN/age_mover}
-T=/tmp/age_mover_test
+T=${T:-/tmp/age_mover_test} # test_folders.sh runs its plain-user half with its own T
ROOTS=(/mnt/cache /mnt/user0 /mnt/disk1 /mnt/disk2 /mnt/other)
# a mount at or under /mnt would put the host's files under the wipe; an unreadable mount table refuses too
@@ -15,8 +15,11 @@ if [ "${AGE_MOVER_TEST:-}" != 1 ] || [ ! -e /.dockerenv ] || ! no_mount_under_mn
exit 2
fi
-mkdir -p "$T/cwd" /usr/libexec/unraid
-cat >/usr/libexec/unraid/move <<'EOF'
+mkdir -p "$T/cwd" "$T/bin"
+# root installs the move stand-in; the plain-user run uses the one root installed before it
+if [ "$(id -u)" = 0 ]; then
+ mkdir -p /usr/libexec/unraid
+ cat >/usr/libexec/unraid/move <<'EOF'
#!/bin/bash
# stand-in for Unraid's move: a name on the cache goes to the array (/mnt/user0), a name anywhere else to the cache.
# A file is copied, as across disks, so names of one inode stay linked only when they come in the same run.
@@ -35,7 +38,27 @@ while IFS= read -r p; do
fi && echo "move: $p Success"
done
EOF
-chmod 755 /usr/libexec/unraid/move
+ chmod 755 /usr/libexec/unraid/move
+fi
+# a path listed in $T/zfs is a ZFS mountpoint whose dataset has no children; zfs records each call and fails on any it
+# has no answer for
+cat >"$T/bin/findmnt" <<'EOF'
+#!/bin/bash
+grep -qxF -- "${@: -1}" "${0%/bin/findmnt}/zfs" 2>/dev/null && echo zfs
+exit 0
+EOF
+cat >"$T/bin/zfs" <<'EOF'
+#!/bin/bash
+echo "zfs $*" >>"${0%/bin/zfs}/zfs.calls"
+case "$*" in
+"list -Hpo usedbychildren "*) echo 0 ;;
+"list -r -H -o name "*) echo "${@: -1}" ;;
+"unmount "* | "destroy "*) ;;
+*) echo "zfs stand-in has no answer for: zfs $*" >&2; exit 1 ;;
+esac
+EOF
+chmod 755 "$T/bin/findmnt" "$T/bin/zfs"
+PATH=$T/bin:$PATH
# age_mover runs its command on load, so only its functions and its top-level start values are taken
awk '/^[A-Za-z_][A-Za-z0-9_]*\(\) \{/,/^\}/' "$AM" >"$T/funcs.sh"
@@ -67,15 +90,20 @@ setting() {
MOVER_PROGRESS=yes
}
-# begin [key value]...: empty pools and disks, age_mover's start values and the case's settings
+# fresh [key value]...: age_mover's start values and the case's settings, on the folders as they are
+fresh() {
+ . "$T/globals.sh"
+ IS_CRON=1 # after the start values: as under cron, nothing goes to syslog
+ setting debuglogging "$DEBUGLOGGING" "$@"
+}
+
+# begin [key value]...: empty pools and disks, then fresh
begin() {
CASE=$1
shift
- rm -rf "${ROOTS[@]}" "$SOFTSTOPFILE" "$PAUSEFILE" "$T/row_error"
+ rm -rf "${ROOTS[@]}" "$SOFTSTOPFILE" "$PAUSEFILE" "$T/row_error" "$T/zfs" "$T/zfs.calls"
mkdir -p /mnt/cache /mnt/user0
- . "$T/globals.sh"
- IS_CRON=1 # after the start values: as under cron, nothing goes to syslog
- setting debuglogging "$DEBUGLOGGING" "$@"
+ fresh "$@"
}
# mk ...: a 2-byte file at /mnt//
@@ -107,7 +135,8 @@ row() {
# list: the rows on stdin as the action list; as in the planner, a hardlink group's size counts on its first name only
list() { { echo "$HDR"; awk -F'|' -v OFS='|' '$9 > 1 && seen[$12 "|" $9 "|" $10 "|" $4]++ { $5 = 0 } 1'; } >"$MOVER_ACTIONLIST"; }
-# the totals the planner counts per direction; a staged move to the primary is counted by its sync row
+# run_moves [stderr]: processTheMoves after the totals the planner counts per direction (a staged move to the primary is
+# counted by its sync row); stderr must be exactly the given text, nothing by default
run_moves() {
read -r TOTALPRIMARYFILES TOTALPRIMARYFOLDERS TOTALPRIMARYSIZE TOTALSECONDARYFILES TOTALSECONDARYFOLDERS TOTALSECONDARYSIZE \
TOTALUNATTENDEDFILES TOTALUNATTENDEDFOLDERS TOTALUNATTENDEDSIZE < <(awk -F'|' '
@@ -132,7 +161,7 @@ run_moves() {
processTheMoves
while IFS='=' read -r v _; do printf '%s=%q\n' "$v" "${!v}"; done <"$T/globals.sh" >"$T/counters"
) >"$T/out" 2>"$T/err"
- check "the rows were built and processTheMoves returned with nothing on stderr" "" \
+ check "the rows were built and processTheMoves returned with $([ -n "${1:-}" ] && echo the expected text || echo nothing) on stderr" "${1:-}" \
"$(cat "$T/row_error" "$T/err" 2>/dev/null; [ -f "$T/counters" ] || echo "processTheMoves did not return")"
[ ! -f "$T/counters" ] || . "$T/counters"
}
@@ -158,6 +187,7 @@ log() { sed -E 's/^[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3} //' "$MOVER_LOG"; }
log_has() { check "log has: $1" 1 "$(log | grep -cF -- "$1" | sed 's/^[1-9][0-9]*$/1/')"; }
log_lacks() { check "log lacks: $1" 0 "$(log | grep -cF -- "$1")"; }
log_count() { check "log has $1 lines with: $2" "$1" "$(log | grep -cF -- "$2")"; }
+dlog_has() { check "debug log has: $1" 1 "$(grep -cF -- "$1" "$MOVER_DEBUG_LOG" | sed 's/^[1-9][0-9]*$/1/')"; }
finish() {
echo "# $(basename "$0"): $((CHECKS - FAILS)) of $CHECKS checks passed"
diff --git a/tests/age_mover/run.sh b/tests/age_mover/run.sh
index 58dd27db..07204e2d 100644
--- a/tests/age_mover/run.sh
+++ b/tests/age_mover/run.sh
@@ -8,9 +8,9 @@ if [ "${AGE_MOVER_TEST:-}" != 1 ]; then
fi
# packages go in only inside a container: AGE_MOVER_TEST=1 on a host must not change its packages
[ -e /.dockerenv ] || { echo "run.sh: AGE_MOVER_TEST=1 is set outside a container" >&2; exit 2; }
-for c in rsync fuser pgrep gawk; do
+for c in rsync fuser pgrep gawk runuser useradd; do
command -v "$c" >/dev/null && continue
- apt-get update -qq && apt-get install -y -qq --no-install-recommends rsync gawk psmisc procps util-linux >/dev/null || exit 2
+ apt-get update -qq && apt-get install -y -qq --no-install-recommends rsync gawk psmisc procps util-linux passwd >/dev/null || exit 2
break
done
# Unraid's awk is gawk; Debian's default mawk would test other awk behaviour
diff --git a/tests/age_mover/test_folders.sh b/tests/age_mover/test_folders.sh
new file mode 100644
index 00000000..024432b4
--- /dev/null
+++ b/tests/age_mover/test_folders.sh
@@ -0,0 +1,179 @@
+#!/bin/bash
+# The folder cleanup after each row today: Clean Folders no / yes / topFolder, Move empty folders, Clean ZFS datasets.
+. "$(dirname "$0")/lib.sh"
+
+# the half of an unreadable-folder case that runs as a plain user, since root lists any folder
+if [ "${1:-}" = --as-tester ]; then
+ CASE=$2
+ fresh cleanFolders topFolder
+ # today find's error on the unreadable top folder reaches stderr, once for its files and once for its subfolders
+ run_moves "$(printf "find: '/mnt/cache/sh': Permission denied\n%.0s" 1 2)"
+ log_has 'Deleted empty folder: /mnt/cache/sh/only'
+ if [ "$3" = yes ]; then log_lacks 'top-level'; else log_has 'Deleted empty top-level folder: /mnt/cache/sh'; fi
+ [ "$FAILS" = 0 ]
+ exit
+fi
+
+for cf in no yes topFolder; do
+ begin "Clean Folders $cf, a share that empties" cleanFolders "$cf"
+ mk cache sh/only/f.txt sh/only/g.txt
+ { row 'move from primary' f sh/only/f.txt; row 'move from primary' f sh/only/g.txt; } | list
+ run_moves
+ array_is sh sh/only sh/only/f.txt sh/only/g.txt
+ case $cf in
+ no) cache_is sh sh/only; log_lacks 'Deleted' ;;
+ yes) cache_is sh; log_has 'Deleted empty folder: /mnt/cache/sh/only'; log_lacks 'top-level' ;;
+ topFolder) cache_is; log_has 'Deleted empty top-level folder: /mnt/cache/sh' ;;
+ esac
+ [ "$cf" = no ] || log_has 'Not deleting folder containing 1 files: /mnt/cache/sh/only'
+done
+
+begin "topFolder, a share that keeps a file elsewhere" cleanFolders topFolder
+mk cache sh/a/f.txt sh/keep/k.txt
+row 'move from primary' f sh/a/f.txt | list
+run_moves
+cache_is sh sh/keep sh/keep/k.txt
+log_has 'Not deleting top-level folder: contains 1 file(s), 1 subfolder(s): /mnt/cache/sh'
+
+begin "topFolder, the file's folder keeps another file" cleanFolders topFolder
+mk cache sh/a/f.txt sh/a/g.txt
+row 'move from primary' f sh/a/f.txt | list
+run_moves
+cache_is sh sh/a sh/a/g.txt
+log_has 'Not deleting folder containing 1 files: /mnt/cache/sh/a'
+log_lacks 'top-level'
+
+# the count takes files only, so the folder looks empty: rmdir alone keeps the subfolder's file
+begin "topFolder, the file's folder keeps a subfolder with a file" cleanFolders topFolder
+mk cache sh/a/f.txt sh/a/sub/g.txt
+row 'move from primary' f sh/a/f.txt | list
+run_moves
+cache_is sh sh/a sh/a/sub sh/a/sub/g.txt
+log_has 'Not deleting top-level folder: contains 1 file(s), 2 subfolder(s): /mnt/cache/sh'
+
+begin "topFolder, .placeholder in the file's folder" cleanFolders topFolder
+mk cache sh/a/f.txt sh/a/.placeholder
+row 'move from primary' f sh/a/f.txt | list
+run_moves
+cache_is sh sh/a sh/a/.placeholder
+log_has 'Not deleting folder containing .placeholder file: /mnt/cache/sh/a'
+log_lacks 'top-level'
+
+begin "topFolder, .placeholder in the top folder" cleanFolders topFolder
+mk cache sh/only/f.txt sh/.placeholder
+row 'move from primary' f sh/only/f.txt | list
+run_moves
+cache_is sh sh/.placeholder
+log_has 'Not deleting top-level folder: contains .placeholder: /mnt/cache/sh'
+
+begin "topFolder, a hidden file in the top folder" cleanFolders topFolder
+mk cache sh/only/f.txt sh/.hidden
+row 'move from primary' f sh/only/f.txt | list
+run_moves
+cache_is sh sh/.hidden
+log_has 'Not deleting top-level folder: contains 1 file(s), 0 subfolder(s): /mnt/cache/sh'
+
+# find counts no symlink, so the folder looks empty and only rmdir keeps it
+begin "topFolder, only a symlink left in the top folder" cleanFolders topFolder
+mk cache sh/only/f.txt
+ln -s /nowhere /mnt/cache/sh/dangling
+row 'move from primary' f sh/only/f.txt | list
+run_moves
+cache_is sh sh/dangling
+log_lacks 'top-level'
+[ "${AGE_MOVER_DEBUG:-0}" != 2 ] || dlog_has 'Failed to delete top-level folder (may not be empty): /mnt/cache/sh'
+
+for tm in no yes; do
+ begin "topFolder, the top folder is a ZFS dataset mountpoint, test mode $tm" cleanFolders topFolder testmode "$tm"
+ mk cache sh/only/f.txt
+ echo /mnt/cache/sh >"$T/zfs"
+ row 'move from primary' f sh/only/f.txt | list
+ run_moves
+ if [ "$tm" = no ]; then
+ cache_is sh
+ log_has 'Skipping deletion of ZFS dataset mountpoint: /mnt/cache/sh'
+ else
+ cache_is sh sh/only sh/only/f.txt
+ log_has 'Not deleting folder containing 1 files: /mnt/cache/sh/only'
+ log_lacks 'top-level'
+ fi
+done
+
+begin "topFolder in test mode, a share holding one empty folder" cleanFolders topFolder testmode yes
+mkdir -p /mnt/cache/sh/e
+row 'move from primary' d sh/e | list
+run_moves
+cache_is sh sh/e
+log_has 'TEST MODE: Would delete moved empty folder: /mnt/cache/sh/e'
+log_has 'Not deleting top-level folder: contains 0 file(s), 1 subfolder(s): /mnt/cache/sh'
+
+# with Move empty folders off the planner lists no folder rows, so an empty folder stays and keeps the top folder
+begin "topFolder, Move empty folders no, an empty folder not listed" cleanFolders topFolder moveEmptyFolders no
+mk cache sh/a/f.txt
+mkdir -p /mnt/cache/sh/e
+row 'move from primary' f sh/a/f.txt | list
+run_moves
+cache_is sh sh/e
+log_has 'Not deleting top-level folder: contains 0 file(s), 1 subfolder(s): /mnt/cache/sh'
+
+for tool in rsync move; do
+ begin "topFolder, a folder row empties the share last ($tool)" cleanFolders topFolder movefilesTool "$tool"
+ mk cache sh/a/f.txt
+ mkdir -p /mnt/cache/sh/e
+ { row 'move from primary' f sh/a/f.txt; row 'move from primary' d sh/e; } | list
+ run_moves
+ cache_is
+ array_is sh sh/a sh/a/f.txt sh/e
+ log_has 'Deleted empty top-level folder: /mnt/cache/sh'
+done
+
+# today the top folder is checked again on every later row once one file row emptied its folder
+for order in file-first folders-first; do
+ begin "topFolder, one file row and three folder rows, $order" cleanFolders topFolder
+ mk cache sh/a/f.txt sh/p/other.txt sh/keep/stay.txt
+ mkdir -p /mnt/cache/sh/p/e1 /mnt/cache/sh/p/e2 /mnt/cache/sh/p/e3
+ {
+ [ "$order" = file-first ] && row 'move from primary' f sh/a/f.txt
+ for d in e1 e2 e3; do row 'move from primary' d "sh/p/$d"; done
+ [ "$order" = folders-first ] && row 'move from primary' f sh/a/f.txt
+ } | list
+ run_moves
+ cache_is sh sh/keep sh/keep/stay.txt sh/p sh/p/other.txt
+ log_count "$([ "$order" = file-first ] && echo 4 || echo 1)" 'top-level folder'
+ log_has 'Not deleting top-level folder: contains 2 file(s), 2 subfolder(s): /mnt/cache/sh'
+done
+
+for left in no yes; do
+ begin "Clean ZFS datasets, $([ $left = yes ] && echo 'a file left in the share' || echo 'a share that empties')" \
+ cleanFolders topFolder cleanDatasets yes
+ mk cache sh/only/f.txt
+ [ "$left" = yes ] && mk cache sh/keep/k.txt
+ printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+ row 'move from primary' f sh/only/f.txt | list
+ run_moves
+ if [ "$left" = no ]; then
+ check "zfs calls" "$(printf 'zfs %s cache/sh\n' 'list -Hpo usedbychildren' 'list -r -H -o name' unmount destroy)" "$(cat "$T/zfs.calls")"
+ log_has 'ZFS dataset [cache/sh] successfully destroyed.'
+ log_has 'Skipping deletion of ZFS dataset mountpoint: /mnt/cache/sh'
+ else
+ check "no zfs calls" "" "$(cat "$T/zfs.calls" 2>/dev/null)"
+ fi
+done
+
+id tester >/dev/null 2>&1 || useradd -M tester
+U=/tmp/age_mover_tester
+for keep in no yes; do
+ begin "topFolder, a top folder its user cannot list, $([ $keep = yes ] && echo 'holding a file' || echo 'empty after the move')"
+ mk cache sh/only/f.txt
+ [ "$keep" = yes ] && mk cache sh/stay.txt
+ rm -rf "$U" && mkdir -p "$U"
+ row 'move from primary' f sh/only/f.txt | { echo "$HDR"; cat; } >"$U/actions"
+ chown -R tester /mnt/cache /mnt/user0 "$U"
+ chmod 0333 /mnt/cache/sh
+ runuser -u tester -- env AGE_MOVER_TEST=1 AGE_MOVER_DEBUG="${AGE_MOVER_DEBUG:-0}" T="$U" bash "$0" --as-tester "$CASE" "$keep"
+ check "the checks run as the mover's user pass" 0 "$?"
+ [ ! -d /mnt/cache/sh ] || chmod 0755 /mnt/cache/sh
+ if [ "$keep" = yes ]; then cache_is sh sh/stay.txt; else cache_is; fi
+done
+
+finish
From 25f0ac546e2d737653cc95e121973e3b970ea9cc Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Tue, 24 Nov 2026 17:19:49 +0800
Subject: [PATCH 12/94] Make the zfs stand-in follow OpenZFS after unmount and
destroy, and pin the dataset cases
---
tests/age_mover/lib.sh | 10 +++++----
tests/age_mover/test_folders.sh | 39 +++++++++++++++++++++++----------
2 files changed, 33 insertions(+), 16 deletions(-)
diff --git a/tests/age_mover/lib.sh b/tests/age_mover/lib.sh
index 0f1e0758..89654a9f 100644
--- a/tests/age_mover/lib.sh
+++ b/tests/age_mover/lib.sh
@@ -40,8 +40,8 @@ done
EOF
chmod 755 /usr/libexec/unraid/move
fi
-# a path listed in $T/zfs is a ZFS mountpoint whose dataset has no children; zfs records each call and fails on any it
-# has no answer for
+# a path listed in $T/zfs is a ZFS mountpoint whose dataset has no children; zfs records each call, and fails on any it
+# has no answer for. unmount unlists it and keeps its folder; destroy rmdirs the folder, as OpenZFS does when inherited
cat >"$T/bin/findmnt" <<'EOF'
#!/bin/bash
grep -qxF -- "${@: -1}" "${0%/bin/findmnt}/zfs" 2>/dev/null && echo zfs
@@ -49,11 +49,13 @@ exit 0
EOF
cat >"$T/bin/zfs" <<'EOF'
#!/bin/bash
-echo "zfs $*" >>"${0%/bin/zfs}/zfs.calls"
+d=${0%/bin/zfs}
+echo "zfs $*" >>"$d/zfs.calls"
case "$*" in
"list -Hpo usedbychildren "*) echo 0 ;;
"list -r -H -o name "*) echo "${@: -1}" ;;
-"unmount "* | "destroy "*) ;;
+"unmount "*) grep -vxF -- "/mnt/${*: -1}" "$d/zfs" >"$d/zfs.new"; mv "$d/zfs.new" "$d/zfs" ;;
+"destroy "*) rmdir -- "/mnt/${*: -1}" 2>/dev/null; exit 0 ;;
*) echo "zfs stand-in has no answer for: zfs $*" >&2; exit 1 ;;
esac
EOF
diff --git a/tests/age_mover/test_folders.sh b/tests/age_mover/test_folders.sh
index 024432b4..cfe5a3e2 100644
--- a/tests/age_mover/test_folders.sh
+++ b/tests/age_mover/test_folders.sh
@@ -127,7 +127,8 @@ for tool in rsync move; do
log_has 'Deleted empty top-level folder: /mnt/cache/sh'
done
-# today the top folder is checked again on every later row once one file row emptied its folder
+# today a file row that empties its folder leaves the top-folder check on for the move rows after it, until a file row
+# leaves files behind
for order in file-first folders-first; do
begin "topFolder, one file row and three folder rows, $order" cleanFolders topFolder
mk cache sh/a/f.txt sh/p/other.txt sh/keep/stay.txt
@@ -143,27 +144,41 @@ for order in file-first folders-first; do
log_has 'Not deleting top-level folder: contains 2 file(s), 2 subfolder(s): /mnt/cache/sh'
done
-for left in no yes; do
- begin "Clean ZFS datasets, $([ $left = yes ] && echo 'a file left in the share' || echo 'a share that empties')" \
- cleanFolders topFolder cleanDatasets yes
+# today the destroy counts regular files only: an empty folder and a symlink go with the dataset
+for left in nothing 'a file' 'an empty folder and a symlink'; do
+ begin "Clean ZFS datasets, $left left in the share" cleanFolders topFolder cleanDatasets yes
mk cache sh/only/f.txt
- [ "$left" = yes ] && mk cache sh/keep/k.txt
+ case $left in
+ 'a file') mk cache sh/keep/k.txt ;;
+ 'an empty folder'*) mkdir /mnt/cache/sh/e && ln -s /nowhere /mnt/cache/sh/link ;;
+ esac
printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
row 'move from primary' f sh/only/f.txt | list
run_moves
- if [ "$left" = no ]; then
- check "zfs calls" "$(printf 'zfs %s cache/sh\n' 'list -Hpo usedbychildren' 'list -r -H -o name' unmount destroy)" "$(cat "$T/zfs.calls")"
- log_has 'ZFS dataset [cache/sh] successfully destroyed.'
- log_has 'Skipping deletion of ZFS dataset mountpoint: /mnt/cache/sh'
- else
+ array_is sh sh/only sh/only/f.txt
+ if [ "$left" = 'a file' ]; then
check "no zfs calls" "" "$(cat "$T/zfs.calls" 2>/dev/null)"
+ cache_is sh sh/keep sh/keep/k.txt
+ log_has 'Not deleting top-level folder: contains 1 file(s), 1 subfolder(s): /mnt/cache/sh'
+ continue
fi
+ check "zfs calls" "$(printf 'zfs %s cache/sh\n' 'list -Hpo usedbychildren' 'list -r -H -o name' unmount destroy)" "$(cat "$T/zfs.calls")"
+ log_has 'ZFS dataset [cache/sh] successfully destroyed.'
+ if [ "$left" = nothing ]; then cache_is; log_lacks 'top-level'; fi
done
+begin "Clean ZFS datasets, a share that empties on a pool that is not ZFS" cleanFolders topFolder cleanDatasets yes
+mk cache sh/only/f.txt
+row 'move from primary' f sh/only/f.txt | list
+run_moves
+check "no zfs calls" "" "$(cat "$T/zfs.calls" 2>/dev/null)"
+cache_is
+log_has 'Deleted empty top-level folder: /mnt/cache/sh'
+
id tester >/dev/null 2>&1 || useradd -M tester
U=/tmp/age_mover_tester
for keep in no yes; do
- begin "topFolder, a top folder its user cannot list, $([ $keep = yes ] && echo 'holding a file' || echo 'empty after the move')"
+ begin "topFolder, a top folder a plain-user mover cannot list, $([ $keep = yes ] && echo 'holding a file' || echo 'empty after the move')"
mk cache sh/only/f.txt
[ "$keep" = yes ] && mk cache sh/stay.txt
rm -rf "$U" && mkdir -p "$U"
@@ -171,7 +186,7 @@ for keep in no yes; do
chown -R tester /mnt/cache /mnt/user0 "$U"
chmod 0333 /mnt/cache/sh
runuser -u tester -- env AGE_MOVER_TEST=1 AGE_MOVER_DEBUG="${AGE_MOVER_DEBUG:-0}" T="$U" bash "$0" --as-tester "$CASE" "$keep"
- check "the checks run as the mover's user pass" 0 "$?"
+ check "the checks run as the plain user pass" 0 "$?"
[ ! -d /mnt/cache/sh ] || chmod 0755 /mnt/cache/sh
if [ "$keep" = yes ]; then cache_is sh sh/stay.txt; else cache_is; fi
done
From 2dab2f6341735c539b57a4d50366bca09080a876 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Tue, 24 Nov 2026 17:27:50 +0800
Subject: [PATCH 13/94] age_mover: look up a hardlink group only for a
multi-link regular file
---
.../emhttp/plugins/ca.mover.tuning/age_mover | 23 ++++++++++-----
tests/age_mover/test_moves.sh | 29 +++++++++++--------
2 files changed, 32 insertions(+), 20 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index 096f5244..ecfdc7d0 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -2557,7 +2557,9 @@ processTheMoves() {
# a move, so later rows are matched on the SYNCED_FILES_ARR key below, not the file. The key
# carries the plan, so a group split across plans keeps every partition instead of dropping one.
NBLINKS="${NBLINKS:-0}"
- if [ "$FILETYPE" = "f" ] && [ "$NBLINKS" -gt 1 ]; then
+ link_group=0
+ [ "$FILETYPE" = "f" ] && [ "$NBLINKS" -gt 1 ] && link_group=1
+ if [ "$link_group" = 1 ]; then
link_key="$ACTION|$SOURCE|$DESTINATION|$NBLINKS|$INODE|$MODIFYTIME"
[ -n "${HANDLED_LINKS[$link_key]}" ] && continue
HANDLED_LINKS[$link_key]=1
@@ -2609,9 +2611,14 @@ processTheMoves() {
# via this array (instead of eval) stops the shell from interpreting
# spaces, backticks, $(...), redirections, etc. that appear in file names.
# every field is compared whole, so a name containing | cannot impersonate another row
- mapfile -t SYNCED_FILES_ARR < <(awk -F'|' -v links="$NBLINKS" -v inode="$INODE" -v mtime="$MODIFYTIME" -v action="$ACTION" -v src="$SOURCE" -v dst="$DESTINATION" '
- BEGIN { links = links ""; inode = inode ""; mtime = mtime "" }
- $4 == mtime && $9 == links && $10 == inode && $11 == action && $12 == src && $13 == dst { p = $15; for (i = 16; i <= NF; i++) p = p "|" $i; print src "/./" p }' "$MOVER_ACTIONLIST")
+ # a row that is not a link group moves only its own name, without a scan of the action list
+ if [ "$link_group" = 1 ]; then
+ mapfile -t SYNCED_FILES_ARR < <(awk -F'|' -v links="$NBLINKS" -v inode="$INODE" -v mtime="$MODIFYTIME" -v action="$ACTION" -v src="$SOURCE" -v dst="$DESTINATION" '
+ BEGIN { links = links ""; inode = inode ""; mtime = mtime "" }
+ $4 == mtime && $9 == links && $10 == inode && $11 == action && $12 == src && $13 == dst { p = $15; for (i = 16; i <= NF; i++) p = p "|" $i; print src "/./" p }' "$MOVER_ACTIONLIST")
+ else
+ SYNCED_FILES_ARR=("$SOURCE/./$FILEPATH")
+ fi
# SYNCED_FILES is a display/count string only, derived from the array so
# the extraction pipeline above runs only once per file.
@@ -2660,15 +2667,15 @@ processTheMoves() {
# Proceed with rsync
if [[ "$ACTION" =~ "move" ]]; then
# Some verbosity
- GUI_ACTION="Moving to $DESTINATION/ $([ "$NBLINKS" -gt 1 ] && [ "$FILETYPE" = "f" ] && echo '(preserving hardlinks)')"
- mvlogger "Moving $SYNCED_FILES to $(qp "$DESTINATION/") $([ "$NBLINKS" -gt 1 ] && [ "$FILETYPE" = "f" ] && echo '(preserving hardlinks)')"
+ GUI_ACTION="Moving to $DESTINATION/ $([ "$link_group" = 1 ] && echo '(preserving hardlinks)')"
+ mvlogger "Moving $SYNCED_FILES to $(qp "$DESTINATION/") $([ "$link_group" = 1 ] && echo '(preserving hardlinks)')"
rsync_action="Move"
# Finalize RSYNC_CMD
RSYNC_CMD+=(--remove-source-files)
elif [[ "$ACTION" =~ "sync" ]]; then
# Some verbosity
- GUI_ACTION="Synchronizing to $DESTINATION/ $([ "$NBLINKS" -gt 1 ] && [ "$FILETYPE" = "f" ] && echo '(preserving hardlinks)')"
- mvlogger "Synchronizing $SYNCED_FILES to $(qp "$DESTINATION/") $([ "$NBLINKS" -gt 1 ] && [ "$FILETYPE" = "f" ] && echo '(preserving hardlinks)')"
+ GUI_ACTION="Synchronizing to $DESTINATION/ $([ "$link_group" = 1 ] && echo '(preserving hardlinks)')"
+ mvlogger "Synchronizing $SYNCED_FILES to $(qp "$DESTINATION/") $([ "$link_group" = 1 ] && echo '(preserving hardlinks)')"
rsync_action="Sync"
fi
diff --git a/tests/age_mover/test_moves.sh b/tests/age_mover/test_moves.sh
index bbba7d28..5e74580d 100644
--- a/tests/age_mover/test_moves.sh
+++ b/tests/age_mover/test_moves.sh
@@ -127,19 +127,23 @@ holds disk2 sh sh/p
counter MOVEDFILES 4
counter MOVEDSIZE 4
-# two ZFS datasets of one pool can give two single-link files the same inode number and mtime: today both are held,
-# and their bytes count once
+# two ZFS datasets of one pool can give two single-link files the same inode number and mtime: each row moves its own file
begin "single-link files sharing inode and mtime across shares"
mk cache sh1/d/a.txt sh2/d/b.txt
{ row 'move from primary' f sh1/d/a.txt 1 777 1700000000; row 'move from primary' f sh2/d/b.txt 1 777 1700000000; } | list
run_moves
-array_is
-counter NOTMOVEDFILES 4
-counter NOTMOVEDSIZE 2
-counter REMAINING_CACHE_SIZE 4
-log_count 2 'Expected 1 files, got 2. Not moving "/mnt/cache/./sh1/d/a.txt" "/mnt/cache/./sh2/d/b.txt"'
+array_is sh1 sh1/d sh1/d/a.txt sh2 sh2/d sh2/d/b.txt
+cache_is sh1 sh1/d sh2 sh2/d
+counter MOVEDFILES 2
+counter MOVEDSIZE 4
+counter NOTMOVEDFILES 0
+counter REMAINING_CACHE_FILES 0
+counter REMAINING_CACHE_SIZE 0
+log_has 'Moving "/mnt/cache/./sh1/d/a.txt" to "/mnt/user0/"'
+log_has 'Moving "/mnt/cache/./sh2/d/b.txt" to "/mnt/user0/"'
+log_lacks 'Expected 1 files'
-# the same for two empty folders: today both rows move the pair, and the second finds one gone
+# the same for two empty folders
begin "folder rows sharing inode and mtime across shares"
mkdir -p /mnt/cache/sh1/e /mnt/cache/sh2/e
{ row 'move from primary' d sh1/e 2 778 1700000000; row 'move from primary' d sh2/e 2 778 1700000000; } | list
@@ -147,10 +151,11 @@ run_moves
array_is sh1 sh1/e sh2 sh2/e
cache_is sh1 sh2
counter MOVEDFOLDERS 2
-counter VANISHEDFOLDERS 1
-counter REMAINING_CACHE_FOLDERS -2
-log_count 2 'Moving "/mnt/cache/./sh1/e" "/mnt/cache/./sh2/e" to "/mnt/user0/"'
-log_has 'Gone from the source before its turn: "/mnt/cache/sh1/e"'
+counter VANISHEDFOLDERS 0
+counter REMAINING_CACHE_FOLDERS 0
+log_has 'Moving "/mnt/cache/./sh1/e" to "/mnt/user0/"'
+log_has 'Moving "/mnt/cache/./sh2/e" to "/mnt/user0/"'
+log_lacks 'Gone from the source'
begin "a pass with nothing to move"
mk cache sh/k/k.txt
From 386697b98b9112946500281cb6c9fa8e0a480cae Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Tue, 24 Nov 2026 18:03:59 +0800
Subject: [PATCH 14/94] Clear share_mover's ShellCheck findings, and stop its
rm of an unset SOFTSTOPFILE
- The two fatal exits ran `rm $SOFTSTOPFILE`, which share_mover never sets, so rm's
"missing operand" reached the syslog. Removed.
- Quoted the rest, split local from its assignment, counted the pool configs with a
glob instead of ls, and picked the move binary with || instead of && ... ||.
- tests/age_mover/test_share_mover.sh runs the real share_mover against Unraid's
config files. On beta's share_mover, only the rm and ls stderr checks fail.
---
.../plugins/ca.mover.tuning/share_mover | 51 +++--
tests/age_mover/lib.sh | 2 +-
tests/age_mover/test_share_mover.sh | 179 ++++++++++++++++++
3 files changed, 205 insertions(+), 27 deletions(-)
create mode 100644 tests/age_mover/test_share_mover.sh
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover
index 2822be66..9a56e9d0 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover
@@ -27,8 +27,9 @@ function titleLine() {
local line_length=71
local padding_left=$((line_length - ${#title} / 2))
local padding_right=$((padding_left - ${#title} % 2 - 1))
- local left_padding=$(printf "%*s" "$padding_left" | tr ' ' "$padding_char")
- local right_padding=$(printf "%*s" "$padding_right" | tr ' ' "$padding_char")
+ local left_padding right_padding
+ left_padding=$(printf "%*s" "$padding_left" "" | tr ' ' "$padding_char")
+ right_padding=$(printf "%*s" "$padding_right" "" | tr ' ' "$padding_char")
echo "${left_padding}$padding_char $title $padding_char${right_padding}"
}
@@ -55,8 +56,6 @@ getMoverSettings() {
echo "$1=\"$2\"" >>"$config_file"
}
- timezone=$(grep "timeZone=" "/boot/config/ident.cfg" | cut -d '"' -f 2)
-
if [[ ! -f "$config_file" ]]; then
mvlogger "Error: Config file '$config_file' not found."
return 1
@@ -64,7 +63,7 @@ getMoverSettings() {
## [[ ! "$config_file" =~ shareOverrideConfig ]] ensure that we are not reading share custom settings
- if [ -z $(cfg enableTurbo) ]; then
+ if [ -z "$(cfg enableTurbo)" ]; then
if [[ ! "$config_file" =~ shareOverrideConfig ]]; then
mvlogger "No Turbo Mode argument provided, defaulting to no"
ENABLETURBO="no"
@@ -72,10 +71,10 @@ getMoverSettings() {
fi
else
ENABLETURBO=$(cfg enableTurbo)
- [ $ENABLETURBO = "yes" ] && mvlogger "Enable Turbo: $ENABLETURBO"
+ [ "$ENABLETURBO" = "yes" ] && mvlogger "Enable Turbo: $ENABLETURBO"
fi
- if [ -z $(cfg testmode) ]; then
+ if [ -z "$(cfg testmode)" ]; then
if [[ ! "$config_file" =~ shareOverrideConfig ]]; then
mvlogger "No Test Mode argument provided, defaulting to yes"
# yes for this run only: written to the global cfg it would put the scheduled mover in test mode too
@@ -83,7 +82,7 @@ getMoverSettings() {
fi
else
TESTMODE=$(cfg testmode)
- [ $TESTMODE = "yes" ] && mvlogger "Test Mode: $TESTMODE"
+ [ "$TESTMODE" = "yes" ] && mvlogger "Test Mode: $TESTMODE"
fi
}
@@ -110,11 +109,11 @@ else
SHARECFG="/boot/config/shares/${SHARENAME}.cfg"
fi
-if [ -f $PIDFILE ]; then
- if ps h $(cat $PIDFILE) | grep mover; then
- mvlogger "already running"
- exit 1
- fi
+pid=$(cat "$PIDFILE" 2>/dev/null)
+# shellcheck disable=SC2009 # age_mover's start test; pgrep -f would match any mover, not only this pid
+if [ -n "$pid" ] && ps h "$pid" | grep -q mover; then
+ mvlogger "already running"
+ exit 1
fi
# Only start if config OK
@@ -124,7 +123,6 @@ if [ -f $UNRAIDCFGFILE ]; then
fi
else
mvlogger "Fatal error: $UNRAIDCFGFILE does not exist, check this."
- rm $SOFTSTOPFILE
exit 2
fi
if [ -f $MOVERTUNINGCFGFILE ]; then
@@ -133,16 +131,17 @@ if [ -f $MOVERTUNINGCFGFILE ]; then
getMoverSettings $MOVERTUNINGCFGFILE
else
mvlogger "Fatal error: $MOVERTUNINGCFGFILE does not exist, check this."
- rm $SOFTSTOPFILE
exit 3
fi
+shopt -s nullglob
+POOLCFGS=(/boot/config/pools/*.cfg)
# Only start if cache enabled and present
-if ! grep -qs 'shareCacheEnabled="yes"' $UNRAIDCFGFILE && [ $(ls /boot/config/pools/*.cfg | wc -l) -lt 2 ]; then
+if ! grep -qs 'shareCacheEnabled="yes"' $UNRAIDCFGFILE && [ ${#POOLCFGS[@]} -lt 2 ]; then
mvlogger "Fatal error: cache not enabled and less than 2 pools set up."
exit 4
fi
-if ! mountpoint -q /mnt/user0 && [ $(ls /boot/config/pools/*.cfg | wc -l) -lt 2 ]; then
+if ! mountpoint -q /mnt/user0 && [ ${#POOLCFGS[@]} -lt 2 ]; then
mvlogger "Fatal error: cache not present, or only cache present, and less than 2 pools set up."
exit 5
fi
@@ -155,8 +154,6 @@ trap pid_cleanup EXIT
trap 'exit 143' HUP INT TERM
echo $$ >"$PIDFILE"
-shopt -s nullglob
-
mvlogger "$(titleLine "Processing $SHARENAME share" '-')"
if grep -qs 'shareUseCache="yes\|shareUseCache="prefer"' "$SHARECFG"; then
mvlogger "Sharecfg: $SHARECFG"
@@ -180,7 +177,7 @@ if grep -qs 'shareUseCache="yes\|shareUseCache="prefer"' "$SHARECFG"; then
# Determine secondary storage
SECONDARYSTORAGENAME=$(grep "shareCachePool2=" "$SHARECFG" | cut -d'=' -f 2 | tr -d '"' | tr -d '\r')
if [ -z "$SECONDARYSTORAGENAME" ]; then
- if [ $SHAREUSECACHE = "only" ] || [ $SHAREUSECACHE = "no" ]; then
+ if [ "$SHAREUSECACHE" = "only" ] || [ "$SHAREUSECACHE" = "no" ]; then
SECONDARYSTORAGENAME="none"
else
SECONDARYSTORAGENAME="user0"
@@ -205,9 +202,9 @@ if grep -qs 'shareUseCache="yes\|shareUseCache="prefer"' "$SHARECFG"; then
mvlogger "=> Skipping"
else
mvlogger "$(titleLine 'LET THE MOVING SHOW BEGIN !' '*')"
- if [ $ENABLETURBO = "yes" ]; then
+ if [ "$ENABLETURBO" = "yes" ]; then
mvlogger "Forcing turbo write on"
- [ $TESTMODE != "yes" ] && /usr/local/sbin/mdcmd set md_write_method 1
+ [ "$TESTMODE" != "yes" ] && /usr/local/sbin/mdcmd set md_write_method 1
fi
#Base Find String
@@ -238,15 +235,17 @@ if grep -qs 'shareUseCache="yes\|shareUseCache="prefer"' "$SHARECFG"; then
eval "${FINDSTR}"
else
#Add Mover to find string
- FINDSTR="${FINDSTR} | $([ -f /usr/libexec/unraid/move ] && echo /usr/libexec/unraid/move || which move) -d $LOGLEVEL"
+ MOVE=/usr/libexec/unraid/move
+ [ -f "$MOVE" ] || MOVE=$(which move)
+ FINDSTR="${FINDSTR} | $MOVE -d $LOGLEVEL"
mvlogger "Complete Mover Command: $FINDSTR"
eval " ${FINDSTR}"
fi
- if [ $ENABLETURBO = "yes" ]; then
+ if [ "$ENABLETURBO" = "yes" ]; then
turbo_write_mode=$(cat /var/local/emhttp/var.ini | grep "md_write_method=" | cut -d'"' -f2)
- mvlogger "Restoring original turbo write mode $( ([ $turbo_write_mode = "auto" ] && echo "Auto (read/modify/write)") || ([ $turbo_write_mode -eq 1 ] && echo "Turbo writes (Reconstruct)") || echo "Read/modify/write")"
- [ $TESTMODE != "yes" ] && /usr/local/sbin/mdcmd set md_write_method $turbo_write_mode
+ mvlogger "Restoring original turbo write mode $( ([ "$turbo_write_mode" = "auto" ] && echo "Auto (read/modify/write)") || ([ "$turbo_write_mode" -eq 1 ] && echo "Turbo writes (Reconstruct)") || echo "Read/modify/write")"
+ [ "$TESTMODE" != "yes" ] && /usr/local/sbin/mdcmd set md_write_method "$turbo_write_mode"
fi
fi
diff --git a/tests/age_mover/lib.sh b/tests/age_mover/lib.sh
index 89654a9f..e62df125 100644
--- a/tests/age_mover/lib.sh
+++ b/tests/age_mover/lib.sh
@@ -1,6 +1,6 @@
#!/bin/bash
# shellcheck disable=SC2034 # the settings set here are read by age_mover's functions, sourced from funcs.sh
-# Sourced by test_*.sh: each case runs the real processTheMoves with real rsync and the shipped default.cfg read by the real
+# Sourced by test_*.sh: each age_mover case runs the real processTheMoves with real rsync and the shipped default.cfg read by the real
# getMoverSettings; Unraid's move, findmnt and zfs are stand-ins. It deletes the folders in ROOTS.
HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
PLUGIN=$HERE/../../source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning
diff --git a/tests/age_mover/test_share_mover.sh b/tests/age_mover/test_share_mover.sh
new file mode 100644
index 00000000..8cbda290
--- /dev/null
+++ b/tests/age_mover/test_share_mover.sh
@@ -0,0 +1,179 @@
+#!/bin/bash
+# shellcheck disable=SC1091,SC2034 # lib.sh is sourced from this folder and reads CASE
+# The per-share Move: the real share_mover on share sh, with Unraid's config files as each case writes them under /boot and
+# /var/local/emhttp, lib.sh's move stand-in and an mdcmd stand-in. SM= runs another copy of share_mover.
+. "$(dirname "$0")/lib.sh"
+SM=${SM:-$PLUGIN/share_mover}
+CFG=/boot/config/plugins/ca.mover.tuning/ca.mover.tuning.cfg
+# the cases rewrite /boot/config and /var/local/emhttp: a mount there (Unraid's flash drive) refuses
+if ! awk '$5 ~ "^/(boot|var/local)(/|$)" { exit 1 }' /proc/self/mountinfo; then
+ echo "test_share_mover.sh rewrites /boot/config: start it with tests/age_mover/run.sh" >&2
+ exit 2
+fi
+mkdir -p /usr/local/sbin
+cat >/usr/local/sbin/mdcmd <>$T/mdcmd.calls
+EOF
+chmod 755 /usr/local/sbin/mdcmd
+
+# share [key value]...: share sh on pool cache, two pools, and the shipped plugin defaults with these keys
+# changed; the value - removes the key
+share() {
+ CASE=$1
+ local use=$2
+ shift 2
+ rm -rf "${ROOTS[@]}" /boot/config /var/local/emhttp /var/run/mover.pid "$T/mdcmd.calls"
+ mkdir -p /mnt/cache /mnt/user0 /mnt/disk1 /boot/config/plugins/ca.mover.tuning /boot/config/shares /boot/config/pools /var/local/emhttp
+ printf '%s\n' 'shareCacheEnabled="yes"' 'shareMoverLogging="yes"' >/boot/config/share.cfg
+ printf '%s\n' 'NAME="Tower"' 'timeZone="UTC"' >/boot/config/ident.cfg
+ printf '%s\n' "shareUseCache=\"$use\"" 'shareCachePool="cache"' >/boot/config/shares/sh.cfg
+ : >/boot/config/pools/cache.cfg
+ : >/boot/config/pools/fast.cfg
+ printf '%s\n' 'md_write_method="auto"' >/var/local/emhttp/var.ini
+ cp "$PLUGIN/default.cfg" "$CFG"
+ while [ $# -ge 2 ]; do
+ grep -q "^$1=" "$CFG" || { echo "share: $1 is not in default.cfg" >&2; exit 2; }
+ if [ "$2" = - ]; then sed -i "/^$1=/d" "$CFG"; else sed -i "s|^$1=.*|$1=\"$2\"|" "$CFG"; fi
+ shift 2
+ done
+}
+
+# bg ...: the command in the background under that name, once it has replaced the forked test script, whose
+# path holds "mover" too
+bg() {
+ local a0
+ (exec -a "$1" "${@:2}") &
+ for _ in {1..100}; do
+ read -r -d '' a0 <"/proc/$!/cmdline"
+ [ "$a0" = "$1" ] && return
+ sleep 0.05
+ done
+ echo "bg: $1 did not start" >&2
+ exit 2
+}
+
+# run [stderr]: share_mover sh, its output without mvlogger's date as the log; stderr must be exactly the given
+# text, nothing by default
+run() {
+ local rc
+ (cd "$T/cwd" && bash "$SM" sh) >"$T/out" 2>"$T/err"
+ rc=$?
+ sed -E 's/^[A-Z][a-z]{2} [ 0-9][0-9] [0-9:]{8} Share mover: //' "$T/out" >"$MOVER_LOG"
+ check "share_mover exited $1" "$1" "$rc"
+ check "stderr held $([ -n "${2:-}" ] && echo only the expected text || echo nothing)" "${2:-}" "$(cat "$T/err")"
+}
+mdcmd_calls() { check "mdcmd calls: ${*:-none}" "$( (($#)) && printf 'mdcmd %s\n' "$@")" "$(cat "$T/mdcmd.calls" 2>/dev/null)"; }
+
+share 'a yes share in test mode' yes testmode yes version 2026.01.02
+mk cache sh/d/a.txt
+run 1 # 1 after a run too: the script ends on its LOGLEVEL=0 test
+log_has 'Running in Test Mode: find "/mnt/cache/sh" -type f -depth'
+log_has '/mnt/cache/sh/d/a.txt'
+check 'the title line' '***************************************************** Mover Tuning Plugin version 2026.01.02 ****************************************************' \
+ "$(grep -F 'Plugin version' "$MOVER_LOG")"
+check 'the last line' '****************************************************************** WE ARE DONE ! ****************************************************************' \
+ "$(tail -n 1 "$MOVER_LOG")"
+cache_is sh sh/d sh/d/a.txt
+array_is
+mdcmd_calls
+
+share 'a yes share' yes
+mk cache sh/d/a.txt sh/b.txt
+run 1
+log_has 'Complete Mover Command: find "/mnt/cache/sh" -type f -depth | /usr/libexec/unraid/move -d 1'
+log_count 2 'Success'
+cache_is sh sh/d
+array_is sh sh/b.txt sh/d sh/d/a.txt
+mdcmd_calls
+
+share 'a prefer share' prefer
+mk disk1 sh/c.txt
+mk user0 sh/u.txt
+run 1
+log_has "Complete Mover Command: find \"/mnt/disk1/sh\" \"/mnt/user0/sh\" -type f -not -path '/mnt/user*' -depth | /usr/libexec/unraid/move -d 1"
+cache_is sh sh/c.txt
+holds disk1 sh
+array_is sh sh/u.txt
+
+for wm in 'auto Auto (read/modify/write)' '1 Turbo writes (Reconstruct)' '0 Read/modify/write'; do
+ share "turbo on, md_write_method ${wm%% *}" yes enableTurbo yes
+ printf 'md_write_method="%s"\n' "${wm%% *}" >/var/local/emhttp/var.ini
+ mk cache sh/a.txt
+ run 1
+ log_has 'Forcing turbo write on'
+ log_has "Restoring original turbo write mode ${wm#* }"
+ mdcmd_calls 'set md_write_method 1' "set md_write_method ${wm%% *}"
+ array_is sh sh/a.txt
+done
+
+share 'turbo on in test mode' yes enableTurbo yes testmode yes
+mk cache sh/a.txt
+run 1
+log_has 'Forcing turbo write on'
+mdcmd_calls
+cache_is sh sh/a.txt
+
+share 'no enableTurbo or testmode in the plugin config' yes enableTurbo - testmode -
+mk cache sh/a.txt
+run 1
+log_has 'No Turbo Mode argument provided, defaulting to no'
+log_has 'No Test Mode argument provided, defaulting to yes'
+log_has 'Running in Test Mode'
+check 'enableTurbo="no" was written to the plugin config, testmode was not' 'enableTurbo="no"' "$(grep -E '^(enableTurbo|testmode)=' "$CFG")"
+cache_is sh sh/a.txt
+
+share 'another mover runs' yes
+mk cache sh/a.txt
+bg mover sleep 30
+echo $! >/var/run/mover.pid
+run 1
+kill $! 2>/dev/null
+wait $! 2>/dev/null
+log_has 'already running'
+log_lacks 'Processing sh share'
+cache_is sh sh/a.txt
+
+share 'the pid file names a process that is no mover' yes
+mk cache sh/a.txt
+bg sleep sleep 30
+echo $! >/var/run/mover.pid
+run 1
+kill $! 2>/dev/null
+wait $! 2>/dev/null
+log_lacks 'already running'
+array_is sh sh/a.txt
+
+share 'an empty pid file' yes
+mk cache sh/a.txt
+: >/var/run/mover.pid
+run 1
+log_lacks 'already running'
+array_is sh sh/a.txt
+
+share 'no share.cfg' yes
+rm /boot/config/share.cfg
+mk cache sh/a.txt
+run 2
+check 'nothing was logged' '' "$(cat "$MOVER_LOG")"
+cache_is sh sh/a.txt
+
+share 'no plugin config' yes
+rm "$CFG"
+mk cache sh/a.txt
+run 3 "grep: $CFG: No such file or directory"
+log_has "Fatal error: $CFG does not exist, check this."
+cache_is sh sh/a.txt
+
+for pools in 1 0; do
+ share "$pools pool config(s), and no /mnt/user0 mount" yes
+ rm /boot/config/pools/fast.cfg
+ [ "$pools" = 1 ] || rm -r /boot/config/pools
+ mk cache sh/a.txt
+ run 5
+ log_has 'Fatal error: cache not present, or only cache present, and less than 2 pools set up.'
+ cache_is sh sh/a.txt
+done
+
+rm -rf "${ROOTS[@]}" /boot/config /var/local/emhttp /var/run/mover.pid
+finish
From f426378089e394bab270d10668036667c6beb1f1 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Tue, 24 Nov 2026 18:06:23 +0800
Subject: [PATCH 15/94] Test share_mover's fallback to the move in PATH, and
refuse a mount at any path the test writes
---
tests/age_mover/test_share_mover.sh | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/tests/age_mover/test_share_mover.sh b/tests/age_mover/test_share_mover.sh
index 8cbda290..567a9f31 100644
--- a/tests/age_mover/test_share_mover.sh
+++ b/tests/age_mover/test_share_mover.sh
@@ -5,9 +5,9 @@
. "$(dirname "$0")/lib.sh"
SM=${SM:-$PLUGIN/share_mover}
CFG=/boot/config/plugins/ca.mover.tuning/ca.mover.tuning.cfg
-# the cases rewrite /boot/config and /var/local/emhttp: a mount there (Unraid's flash drive) refuses
-if ! awk '$5 ~ "^/(boot|var/local)(/|$)" { exit 1 }' /proc/self/mountinfo; then
- echo "test_share_mover.sh rewrites /boot/config: start it with tests/age_mover/run.sh" >&2
+# the cases write under /boot, /var/local and /usr/local, and /var/run/mover.pid: a mount at one (Unraid's flash drive) refuses
+if ! awk '$5 ~ "^/(boot|var/local|usr/local)(/|$)" || $5 ~ "^/(var/)?run(/mover\\.pid)?$" { exit 1 }' /proc/self/mountinfo; then
+ echo "test_share_mover.sh writes Unraid's paths and one is a mount here: start it with tests/age_mover/run.sh" >&2
exit 2
fi
mkdir -p /usr/local/sbin
@@ -87,6 +87,16 @@ cache_is sh sh/d
array_is sh sh/b.txt sh/d sh/d/a.txt
mdcmd_calls
+share 'no move at /usr/libexec/unraid, so the one in PATH' yes
+mk cache sh/a.txt
+mv /usr/libexec/unraid/move "$T/move.aside"
+cp "$T/move.aside" "$T/bin/move"
+run 1
+mv "$T/move.aside" /usr/libexec/unraid/move
+rm "$T/bin/move"
+log_has "Complete Mover Command: find \"/mnt/cache/sh\" -type f -depth | $T/bin/move -d 1"
+array_is sh sh/a.txt
+
share 'a prefer share' prefer
mk disk1 sh/c.txt
mk user0 sh/u.txt
From 1500d2e76ad0abce771fb4d1ac5225af6aea6473 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Tue, 24 Nov 2026 17:50:45 +0800
Subject: [PATCH 16/94] Pin what age_mover's soft stop and pause do today,
through the real processTheMoves
---
tests/age_mover/lib.sh | 13 +++++-
tests/age_mover/test_stops.sh | 83 +++++++++++++++++++++++++++++++++++
2 files changed, 95 insertions(+), 1 deletion(-)
create mode 100644 tests/age_mover/test_stops.sh
diff --git a/tests/age_mover/lib.sh b/tests/age_mover/lib.sh
index 89654a9f..39f5d4b4 100644
--- a/tests/age_mover/lib.sh
+++ b/tests/age_mover/lib.sh
@@ -103,11 +103,22 @@ fresh() {
begin() {
CASE=$1
shift
- rm -rf "${ROOTS[@]}" "$SOFTSTOPFILE" "$PAUSEFILE" "$T/row_error" "$T/zfs" "$T/zfs.calls"
+ rm -rf "${ROOTS[@]}" "$SOFTSTOPFILE" "$PAUSEFILE" "$T/row_error" "$T/zfs" "$T/zfs.calls" "$T/after_rsync" "$T/bin/rsync" \
+ "$MOVER_LOG"
mkdir -p /mnt/cache /mnt/user0
fresh "$@"
}
+# after_first_rsync : runs the command once, right after the case's first rsync ends; its errors go to the stderr
+# run_moves checks. The wrapper renames its process, or copyPids would take it for the copy
+after_first_rsync() {
+ local h=$T/after_rsync e=$T/row_error
+ printf '%s\n' "$1" >"$h"
+ printf '#!/bin/bash\nprintf hook >/proc/$$/comm\n%q "$@"\nrc=$?\n[ -e %q ] && { bash %q 2>>%q || echo "after_first_rsync: the command failed" >>%q; rm -f %q; }\nexit $rc\n' \
+ "$(PATH=${PATH#"$T/bin:"} command -v rsync)" "$h" "$h" "$e" "$e" "$h" >"$T/bin/rsync"
+ chmod 755 "$T/bin/rsync"
+}
+
# mk ...: a 2-byte file at /mnt//
mk() {
local r=$1 p
diff --git a/tests/age_mover/test_stops.sh b/tests/age_mover/test_stops.sh
new file mode 100644
index 00000000..5b8ed773
--- /dev/null
+++ b/tests/age_mover/test_stops.sh
@@ -0,0 +1,83 @@
+#!/bin/bash
+# What processTheMoves does today when a soft stop or a pause comes before or between its rows.
+. "$(dirname "$0")/lib.sh"
+
+HELPERS=()
+# after_pause ...: in the background, runs the command s after the run logs its pause; begin removed
+# the last case's log
+after_pause() {
+ local s=$1
+ shift
+ (until grep -qF 'Paused: no file moves until Resume' "$MOVER_LOG" 2>/dev/null; do sleep 0.1; done; sleep "$s"; "$@") >/dev/null 2>&1 &
+ HELPERS+=($!)
+}
+held() { log | sed -n 's/.*Resumed after \([0-9]*\) s.*/\1/p'; }
+# must run before the next case: a helper left running would lift or stop that case's pause
+stop_helpers() {
+ kill "${HELPERS[@]}" 2>/dev/null
+ wait "${HELPERS[@]}" 2>/dev/null
+ HELPERS=()
+}
+order() { log | grep -oE 'Moving "[^"]*"|Paused: no file moves until Resume|Resumed after|Soft Stopping requested'; }
+
+begin "soft stop after the first file" synchronizeCache yes
+mk cache sh/s/1.txt sh/s/2.txt sh/s/3.txt
+{ row 'move from primary' f sh/s/1.txt; row 'move from primary' f sh/s/2.txt; row 'sync from primary' f sh/s/3.txt; } | list
+after_first_rsync "touch '$SOFTSTOPFILE'"
+run_moves
+array_is sh sh/s sh/s/1.txt
+cache_is sh sh/s sh/s/2.txt sh/s/3.txt
+counter MOVEDFILES 1
+check "the order of the moves and the soft stop" "$(printf '%s\n' 'Moving "/mnt/cache/./sh/s/1.txt"' 'Soft Stopping requested')" "$(order)"
+log_lacks 'Set last sync date'
+
+# processTheMoves returns at its start, before its banner; its row loop would also hold the file at the first row
+begin "soft stop before the run"
+mk cache sh/s/1.txt
+row 'move from primary' f sh/s/1.txt | list
+touch "$SOFTSTOPFILE"
+run_moves
+array_is
+cache_is sh sh/s sh/s/1.txt
+check "the order of the moves and the soft stop" 'Soft Stopping requested' "$(order)"
+log_lacks 'LET THE MOVING SHOW BEGIN'
+
+begin "pause after the first file, lifted 2 s later"
+mk cache sh/s/1.txt sh/s/2.txt
+for n in 1 2; do row 'move from primary' f "sh/s/$n.txt"; done | list
+after_first_rsync "echo $$ >'$PAUSEFILE'"
+after_pause 2 rm -f "$PAUSEFILE"
+run_moves
+stop_helpers
+array_is sh sh/s sh/s/1.txt sh/s/2.txt
+counter MOVEDFILES 2
+check "the order of the moves and the pause" "$(printf '%s\n' 'Moving "/mnt/cache/./sh/s/1.txt"' 'Paused: no file moves until Resume' \
+ 'Resumed after' 'Moving "/mnt/cache/./sh/s/2.txt"')" "$(order)"
+check "the pause held from 2 s to under 10 s" yes "$([ "$(held)" -ge 2 ] 2>/dev/null && [ "$(held)" -lt 10 ] && echo yes || echo no)"
+
+# the lift only ends a pause the run should not have taken, so a broken check fails instead of hanging
+begin "a pause file naming another run"
+mk cache sh/s/1.txt
+row 'move from primary' f sh/s/1.txt | list
+echo 1 >"$PAUSEFILE"
+after_pause 2 rm -f "$PAUSEFILE"
+run_moves
+stop_helpers
+array_is sh sh/s sh/s/1.txt
+log_lacks 'Paused'
+
+begin "soft stop 2 s into a pause before the first file"
+mk cache sh/s/1.txt
+row 'move from primary' f sh/s/1.txt | list
+echo $$ >"$PAUSEFILE"
+after_pause 2 touch "$SOFTSTOPFILE"
+after_pause 20 rm -f "$PAUSEFILE"
+run_moves
+stop_helpers
+array_is
+cache_is sh sh/s sh/s/1.txt
+check "the order of the moves, the pause and the soft stop" "$(printf '%s\n' 'Paused: no file moves until Resume' 'Resumed after' \
+ 'Soft Stopping requested')" "$(order)"
+check "the pause held under 10 s: the soft stop ended it, not the 20 s lift" yes "$([ "$(held)" -lt 10 ] 2>/dev/null && echo yes || echo no)"
+
+finish
From aab7b6888afa8580dee12ff95d837a44d7a86f26 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Tue, 24 Nov 2026 18:11:09 +0800
Subject: [PATCH 17/94] Read only the pid's digits, as debug_mover does, so
spaces or a second line cannot hide a running mover
---
.../emhttp/plugins/ca.mover.tuning/share_mover | 4 ++--
tests/age_mover/test_share_mover.sh | 14 ++++++++++++--
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover
index 9a56e9d0..bd52fc7a 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover
@@ -109,8 +109,8 @@ else
SHARECFG="/boot/config/shares/${SHARENAME}.cfg"
fi
-pid=$(cat "$PIDFILE" 2>/dev/null)
-# shellcheck disable=SC2009 # age_mover's start test; pgrep -f would match any mover, not only this pid
+pid=$(tr -cd '0-9' 2>/dev/null <"$PIDFILE")
+# shellcheck disable=SC2009 # pgrep -f would match any mover, not only this pid
if [ -n "$pid" ] && ps h "$pid" | grep -q mover; then
mvlogger "already running"
exit 1
diff --git a/tests/age_mover/test_share_mover.sh b/tests/age_mover/test_share_mover.sh
index 567a9f31..3c63a28b 100644
--- a/tests/age_mover/test_share_mover.sh
+++ b/tests/age_mover/test_share_mover.sh
@@ -3,7 +3,7 @@
# The per-share Move: the real share_mover on share sh, with Unraid's config files as each case writes them under /boot and
# /var/local/emhttp, lib.sh's move stand-in and an mdcmd stand-in. SM= runs another copy of share_mover.
. "$(dirname "$0")/lib.sh"
-SM=${SM:-$PLUGIN/share_mover}
+SM=$(realpath "${SM:-$PLUGIN/share_mover}") # run starts it from $T/cwd
CFG=/boot/config/plugins/ca.mover.tuning/ca.mover.tuning.cfg
# the cases write under /boot, /var/local and /usr/local, and /var/run/mover.pid: a mount at one (Unraid's flash drive) refuses
if ! awk '$5 ~ "^/(boot|var/local|usr/local)(/|$)" || $5 ~ "^/(var/)?run(/mover\\.pid)?$" { exit 1 }' /proc/self/mountinfo; then
@@ -144,6 +144,16 @@ log_has 'already running'
log_lacks 'Processing sh share'
cache_is sh sh/a.txt
+share 'the pid file holds the running mover with spaces and a second line' yes
+mk cache sh/a.txt
+bg mover sleep 30
+printf ' %s \n\n' $! >/var/run/mover.pid
+run 1
+kill $! 2>/dev/null
+wait $! 2>/dev/null
+log_has 'already running'
+cache_is sh sh/a.txt
+
share 'the pid file names a process that is no mover' yes
mk cache sh/a.txt
bg sleep sleep 30
@@ -185,5 +195,5 @@ for pools in 1 0; do
cache_is sh sh/a.txt
done
-rm -rf "${ROOTS[@]}" /boot/config /var/local/emhttp /var/run/mover.pid
+rm -rf "${ROOTS[@]}" /boot/config /var/local/emhttp /var/run/mover.pid /usr/local/sbin/mdcmd
finish
From 758ad7bcce212b49c1570bf3d02ec150870688d7 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Tue, 24 Nov 2026 18:12:11 +0800
Subject: [PATCH 18/94] Take the pid from the pid file's first line, so a
second line cannot run into it
---
.../usr/local/emhttp/plugins/ca.mover.tuning/share_mover | 2 +-
tests/age_mover/test_share_mover.sh | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover
index bd52fc7a..5da805d6 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover
@@ -109,7 +109,7 @@ else
SHARECFG="/boot/config/shares/${SHARENAME}.cfg"
fi
-pid=$(tr -cd '0-9' 2>/dev/null <"$PIDFILE")
+pid=$(head -n 1 "$PIDFILE" 2>/dev/null | tr -cd '0-9')
# shellcheck disable=SC2009 # pgrep -f would match any mover, not only this pid
if [ -n "$pid" ] && ps h "$pid" | grep -q mover; then
mvlogger "already running"
diff --git a/tests/age_mover/test_share_mover.sh b/tests/age_mover/test_share_mover.sh
index 3c63a28b..21dcb179 100644
--- a/tests/age_mover/test_share_mover.sh
+++ b/tests/age_mover/test_share_mover.sh
@@ -144,10 +144,10 @@ log_has 'already running'
log_lacks 'Processing sh share'
cache_is sh sh/a.txt
-share 'the pid file holds the running mover with spaces and a second line' yes
+share 'the pid file holds the running mover with spaces, then a second line' yes
mk cache sh/a.txt
bg mover sleep 30
-printf ' %s \n\n' $! >/var/run/mover.pid
+printf ' %s \n99999999\n' $! >/var/run/mover.pid
run 1
kill $! 2>/dev/null
wait $! 2>/dev/null
From 4ce1f9c95399291a12535a07789f258ea099a2a0 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Tue, 24 Nov 2026 18:30:20 +0800
Subject: [PATCH 19/94] Remove validateFilenames and invalidFileChars from
saved configs at install
Nothing reads them since the filename check was removed, and a backtick saved in invalidFileChars stops debug_mover's source of the config at that line. test_install.sh runs the plg's post-install step, read by xmllint.
---
plugins/ca.mover.tuning.plg | 4 ++
tests/age_mover/run.sh | 4 +-
tests/age_mover/test_install.sh | 90 +++++++++++++++++++++++++++++++++
3 files changed, 96 insertions(+), 2 deletions(-)
create mode 100644 tests/age_mover/test_install.sh
diff --git a/plugins/ca.mover.tuning.plg b/plugins/ca.mover.tuning.plg
index 86dc4c53..d1376a7f 100644
--- a/plugins/ca.mover.tuning.plg
+++ b/plugins/ca.mover.tuning.plg
@@ -807,6 +807,10 @@ else
echo "- Updating freeingThreshold"
grep -m1 '^movingThreshold=' "$config_file" | sed 's/^movingThreshold/freeingThreshold/' >> "$config_file"
fi
+ if grep -qE '^(validateFilenames|invalidFileChars)=' "$config_file"; then
+ echo "- Removing the old filename check's settings"
+ sed -i -E '/^(validateFilenames|invalidFileChars)=/d' "$config_file"
+ fi
fi
# Read Unraid version
diff --git a/tests/age_mover/run.sh b/tests/age_mover/run.sh
index 07204e2d..f6c78f5e 100644
--- a/tests/age_mover/run.sh
+++ b/tests/age_mover/run.sh
@@ -8,9 +8,9 @@ if [ "${AGE_MOVER_TEST:-}" != 1 ]; then
fi
# packages go in only inside a container: AGE_MOVER_TEST=1 on a host must not change its packages
[ -e /.dockerenv ] || { echo "run.sh: AGE_MOVER_TEST=1 is set outside a container" >&2; exit 2; }
-for c in rsync fuser pgrep gawk runuser useradd; do
+for c in rsync fuser pgrep gawk runuser useradd xmllint; do
command -v "$c" >/dev/null && continue
- apt-get update -qq && apt-get install -y -qq --no-install-recommends rsync gawk psmisc procps util-linux passwd >/dev/null || exit 2
+ apt-get update -qq && apt-get install -y -qq --no-install-recommends rsync gawk psmisc procps util-linux passwd libxml2-utils >/dev/null || exit 2
break
done
# Unraid's awk is gawk; Debian's default mawk would test other awk behaviour
diff --git a/tests/age_mover/test_install.sh b/tests/age_mover/test_install.sh
new file mode 100644
index 00000000..3e18d869
--- /dev/null
+++ b/tests/age_mover/test_install.sh
@@ -0,0 +1,90 @@
+#!/bin/bash
+# shellcheck disable=SC1091,SC2034 # lib.sh is sourced from this folder and reads CASE
+# The plg's post-install step on a saved config, taken from the real plg by xmllint, a real XML parser, on Unraid
+# 7.2.1, with the plugin's files copied in place; php and update_cron are stand-ins. PLG= runs another plg. The step's
+# pgrep finds age_mover in this test's paths, so it always takes its "run in progress" branch and keeps /var/run's files.
+. "$(dirname "$0")/lib.sh"
+PLG=$(realpath "${PLG:-$HERE/../../plugins/ca.mover.tuning.plg}")
+CFG=/boot/config/plugins/ca.mover.tuning/ca.mover.tuning.cfg
+STANDINS=(/usr/bin/php /usr/local/sbin/update_cron)
+# the step writes under /boot, /usr/local and /var/run, and the test writes /usr/bin/php and /etc/unraid-version: a mount at
+# one (Unraid's flash drive) refuses, and so does a php or update_cron this test did not write
+if ! awk '$5 ~ "^/(boot|usr/local)(/|$)" || $5 ~ "^/(usr(/bin(/php)?)?|etc(/unraid-version)?|(var/)?run)$" { exit 1 }' /proc/self/mountinfo; then
+ echo "test_install.sh writes Unraid's paths and one is a mount here: start it with tests/age_mover/run.sh" >&2
+ exit 2
+fi
+for f in "${STANDINS[@]}"; do
+ [ ! -e "$f" ] || grep -qx '# test_install.sh stand-in' "$f" || { echo "test_install.sh: $f is not this test's stand-in" >&2; exit 2; }
+done
+trap 'rm -rf /boot/config /usr/local/emhttp/plugins/ca.mover.tuning /usr/local/sbin/age_mover /etc/unraid-version "${STANDINS[@]}"' EXIT
+
+xmllint --noent --xpath 'string(//comment()[contains(., "The '\''post-install'\'' script")]/following-sibling::FILE[1]/INLINE)' "$PLG" \
+ >"$T/post_install.sh"
+if ! grep -q 'Updating config file' "$T/post_install.sh"; then
+ echo "test_install.sh: no post-install step read from $PLG" >&2
+ exit 2
+fi
+VERSION=$(xmllint --noent --xpath 'string(/PLUGIN/@version)' "$PLG")
+for f in "${STANDINS[@]}"; do
+ # shellcheck disable=SC2016 # the stand-in expands its own name and arguments
+ printf '#!/bin/bash\n# test_install.sh stand-in\necho "${0##*/}${*:+ $*}" >>%q\n' "$T/install.calls" >"$f"
+ chmod 755 "$f"
+done
+echo 'version="7.2.1"' >/etc/unraid-version
+rm -rf /usr/local/emhttp/plugins/ca.mover.tuning
+mkdir -p /usr/local/emhttp/plugins
+cp -r "$PLUGIN" /usr/local/emhttp/plugins/
+
+# run_step ...: the step on a saved config of these lines, each ending in and \n; its output
+# is the log
+run_step() {
+ CASE=$1
+ local eol=$2 rc
+ shift 2
+ rm -rf /boot/config "$T/install.calls"
+ mkdir -p "${CFG%/*}"
+ printf "%s$eol\n" "$@" >"$CFG"
+ (cd "$T/cwd" && bash "$T/post_install.sh") >"$MOVER_LOG" 2>"$T/err"
+ rc=$?
+ check "the step exited 0" 0 "$rc"
+ check "stderr held nothing" "" "$(cat "$T/err")"
+ check "the step ran to its end: php and update_cron were called" \
+ "$(printf '%s\n' 'php -q /usr/local/emhttp/plugins/ca.mover.tuning/updateCron.php sync' update_cron)" "$(cat "$T/install.calls" 2>/dev/null)"
+}
+# cfg_is ...: the config holds exactly these lines besides version=, which every install sets to the plg's
+# version, and testmode=, which a major upgrade sets
+cfg_is() {
+ local eol=$1
+ shift
+ check "the config holds exactly $*" "$(printf "%s$eol\n" "$@" | cat -A)" "$(grep -vE '^(version|testmode)=' "$CFG" | cat -A)"
+ check "version is the plg's" "version=\"$VERSION\"" "$(grep '^version=' "$CFG" | tr -d '\r')"
+}
+REMOVING="- Removing the old filename check's settings"
+
+run_step "both keys among other keys" '' 'logging="yes"' 'validateFilenames="yes"' 'movenow="yes"' \
+ 'invalidFileChars="$ / < > : \" | ? *"' 'version="2026.01.01"' 'movingThreshold="80"' 'freeingThreshold="70"' 'migratedOverrideNo="yes"'
+cfg_is '' 'logging="yes"' 'movenow="yes"' 'movingThreshold="80"' 'freeingThreshold="70"' 'migratedOverrideNo="yes"'
+log_has "$REMOVING"
+
+run_step "a CRLF file" '\r' 'logging="yes"' 'invalidFileChars="*"' 'movenow="yes"' 'validateFilenames="no"' 'version="2026.01.01"' \
+ 'movingThreshold="80"' 'freeingThreshold="70"' 'migratedOverrideNo="yes"'
+cfg_is '\r' 'logging="yes"' 'movenow="yes"' 'movingThreshold="80"' 'freeingThreshold="70"' 'migratedOverrideNo="yes"'
+log_has "$REMOVING"
+
+run_step "validateFilenamesOld beside invalidFileChars" '' 'validateFilenamesOld="x"' 'invalidFileChars="*"' 'version="2026.01.01"' \
+ 'movingThreshold="80"' 'freeingThreshold="70"' 'migratedOverrideNo="yes"'
+cfg_is '' 'validateFilenamesOld="x"' 'movingThreshold="80"' 'freeingThreshold="70"' 'migratedOverrideNo="yes"'
+log_has "$REMOVING"
+
+# debug_mover sources the config: a backtick saved in invalidFileChars stopped it there, so every key below stayed empty
+run_step "a backtick in invalidFileChars" '' 'logging="yes"' 'invalidFileChars="`"' 'movenow="yes"' 'version="2026.01.01"' \
+ 'movingThreshold="80"' 'freeingThreshold="70"' 'migratedOverrideNo="yes"'
+cfg_is '' 'logging="yes"' 'movenow="yes"' 'movingThreshold="80"' 'freeingThreshold="70"' 'migratedOverrideNo="yes"'
+check "the config sources to its end, with nothing on stderr" 'movenow=yes' "$(bash -c '. "$1"; echo "movenow=$movenow"' _ "$CFG" 2>&1)"
+
+run_step "neither key, only validateFilenamesOld" '' 'logging="yes"' 'validateFilenamesOld="x"' 'version="2026.01.01"' \
+ 'movingThreshold="80"' 'freeingThreshold="70"' 'migratedOverrideNo="yes"'
+cfg_is '' 'logging="yes"' 'validateFilenamesOld="x"' 'movingThreshold="80"' 'freeingThreshold="70"' 'migratedOverrideNo="yes"'
+log_lacks "$REMOVING"
+
+finish
From 99a3831ab5663a0e96cbd0ae170632f4412860df Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Tue, 24 Nov 2026 19:03:47 +0800
Subject: [PATCH 20/94] Refuse a mount at /var or /usr in test_share_mover.sh's
guard
---
tests/age_mover/test_share_mover.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/age_mover/test_share_mover.sh b/tests/age_mover/test_share_mover.sh
index 21dcb179..45e52256 100644
--- a/tests/age_mover/test_share_mover.sh
+++ b/tests/age_mover/test_share_mover.sh
@@ -6,7 +6,7 @@
SM=$(realpath "${SM:-$PLUGIN/share_mover}") # run starts it from $T/cwd
CFG=/boot/config/plugins/ca.mover.tuning/ca.mover.tuning.cfg
# the cases write under /boot, /var/local and /usr/local, and /var/run/mover.pid: a mount at one (Unraid's flash drive) refuses
-if ! awk '$5 ~ "^/(boot|var/local|usr/local)(/|$)" || $5 ~ "^/(var/)?run(/mover\\.pid)?$" { exit 1 }' /proc/self/mountinfo; then
+if ! awk '$5 ~ "^/(boot|var/local|usr/local)(/|$)" || $5 ~ "^/(var|usr|(var/)?run(/mover\\.pid)?)$" { exit 1 }' /proc/self/mountinfo; then
echo "test_share_mover.sh writes Unraid's paths and one is a mount here: start it with tests/age_mover/run.sh" >&2
exit 2
fi
From dbfcb7cf8faf6c546affcc0161a1cb084df894ff Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Tue, 24 Nov 2026 19:03:50 +0800
Subject: [PATCH 21/94] Refuse a mount at /var in test_install.sh's guard
---
tests/age_mover/test_install.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/age_mover/test_install.sh b/tests/age_mover/test_install.sh
index 3e18d869..728ddeb9 100644
--- a/tests/age_mover/test_install.sh
+++ b/tests/age_mover/test_install.sh
@@ -9,7 +9,7 @@ CFG=/boot/config/plugins/ca.mover.tuning/ca.mover.tuning.cfg
STANDINS=(/usr/bin/php /usr/local/sbin/update_cron)
# the step writes under /boot, /usr/local and /var/run, and the test writes /usr/bin/php and /etc/unraid-version: a mount at
# one (Unraid's flash drive) refuses, and so does a php or update_cron this test did not write
-if ! awk '$5 ~ "^/(boot|usr/local)(/|$)" || $5 ~ "^/(usr(/bin(/php)?)?|etc(/unraid-version)?|(var/)?run)$" { exit 1 }' /proc/self/mountinfo; then
+if ! awk '$5 ~ "^/(boot|usr/local)(/|$)" || $5 ~ "^/(usr(/bin(/php)?)?|var|etc(/unraid-version)?|(var/)?run)$" { exit 1 }' /proc/self/mountinfo; then
echo "test_install.sh writes Unraid's paths and one is a mount here: start it with tests/age_mover/run.sh" >&2
exit 2
fi
From 4911cbaf3372c8face5cc749cdc9d8378965c8df Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Tue, 24 Nov 2026 19:06:42 +0800
Subject: [PATCH 22/94] Refuse a mount at /usr/libexec/unraid/move or above in
lib.sh's guard; note why SC2016 is off for the rsync wrapper
---
tests/age_mover/lib.sh | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/tests/age_mover/lib.sh b/tests/age_mover/lib.sh
index 39f5d4b4..9def7e78 100644
--- a/tests/age_mover/lib.sh
+++ b/tests/age_mover/lib.sh
@@ -8,10 +8,11 @@ AM=${AM:-$PLUGIN/age_mover}
T=${T:-/tmp/age_mover_test} # test_folders.sh runs its plain-user half with its own T
ROOTS=(/mnt/cache /mnt/user0 /mnt/disk1 /mnt/disk2 /mnt/other)
-# a mount at or under /mnt would put the host's files under the wipe; an unreadable mount table refuses too
-no_mount_under_mnt() { awk '$5 == "/mnt" || index($5, "/mnt/") == 1 { exit 1 }' /proc/self/mountinfo; }
-if [ "${AGE_MOVER_TEST:-}" != 1 ] || [ ! -e /.dockerenv ] || ! no_mount_under_mnt; then
- echo "lib.sh deletes ${ROOTS[*]}: start the tests with tests/age_mover/run.sh" >&2
+# a mount at or under /mnt would put the host's files under the wipe, and one at /usr/libexec/unraid/move or above it the
+# host's mover under the stand-in; an unreadable mount table refuses too
+no_host_mount() { awk '$5 == "/mnt" || index($5, "/mnt/") == 1 || $5 ~ "^/usr(/libexec(/unraid(/move)?)?)?$" { exit 1 }' /proc/self/mountinfo; }
+if [ "${AGE_MOVER_TEST:-}" != 1 ] || [ ! -e /.dockerenv ] || ! no_host_mount; then
+ echo "lib.sh deletes ${ROOTS[*]} and writes /usr/libexec/unraid/move: start the tests with tests/age_mover/run.sh" >&2
exit 2
fi
@@ -114,6 +115,7 @@ begin() {
after_first_rsync() {
local h=$T/after_rsync e=$T/row_error
printf '%s\n' "$1" >"$h"
+ # shellcheck disable=SC2016 # the wrapper expands its own $$, $@ and $?
printf '#!/bin/bash\nprintf hook >/proc/$$/comm\n%q "$@"\nrc=$?\n[ -e %q ] && { bash %q 2>>%q || echo "after_first_rsync: the command failed" >>%q; rm -f %q; }\nexit $rc\n' \
"$(PATH=${PATH#"$T/bin:"} command -v rsync)" "$h" "$h" "$e" "$e" "$h" >"$T/bin/rsync"
chmod 755 "$T/bin/rsync"
From 46cf4a3acf88e6a5ce32447d1b31f797278cf92f Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Tue, 24 Nov 2026 19:21:57 +0800
Subject: [PATCH 23/94] Check each share's top folder once, after the pass,
instead of after every move row
The per-row check fired on LAST_COUNT or EMPTY_DIR_COUNT being 0, and neither was reset per row, so one emptied
folder made every later move row scan the whole share again. In topFolder mode a file row now notes its share when a
name's folder is left with no files, and a folder row when its chain empties every folder up to the top folder. Each
noted top folder is checked once at Cleaning up, after a soft stop too.
---
.../emhttp/plugins/ca.mover.tuning/age_mover | 94 +++++++++----------
tests/age_mover/test_folders.sh | 49 +++++++++-
2 files changed, 90 insertions(+), 53 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index 096f5244..5ec8355f 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -95,7 +95,6 @@ UNRAID_MOVER=0
LAST_DIR=""
LAST_COUNT=-1
LAST_FOLDER_COUNT=-1
-EMPTY_DIR_COUNT=-1
declare -A POOL_FSTYPE_CACHE=()
# per cache:yes share, from createFilteredFilelist: "name|keeps its primary files|sync size limit in bytes|age filter days" lines for decideMoveActions
SHARE_PLAN_RULES=""
@@ -2477,6 +2476,40 @@ move_tool_said() {
done <<<"$MOVE_OUT"
}
+# In topFolder mode, notes this row's share top folder for the check after the pass; fills processTheMoves' TOP_SEEN
+# and TOP_FOLDERS
+note_top_folder() {
+ [ "$CLEANFOLDERS" = "topFolder" ] || return 0
+ local top="${SOURCE}/${SHARENAME}"
+ [ -n "${TOP_SEEN[$top]}" ] && return 0
+ TOP_SEEN[$top]=1
+ TOP_FOLDERS+=("$top")
+}
+
+# Deletes share top folder $1 if it is empty, unless it is a ZFS dataset mountpoint or test mode is on
+cleanTopFolder() {
+ local top_folder=$1 file_count dir_count
+ [ -d "$top_folder" ] || return 0
+ if [ -e "${top_folder}/.placeholder" ]; then
+ mvlogger "Not deleting top-level folder: contains .placeholder: ${top_folder}"
+ return 0
+ fi
+ file_count=$(find "$top_folder" -type f | wc -l)
+ dir_count=$(find "$top_folder" -mindepth 1 -type d | wc -l)
+ mvDebuglogger "Top folder: $(qp "$top_folder"), share file(s): $file_count, share folder(s): $dir_count" "Clean Top Folder"
+ if [ "$file_count" -ne 0 ] || [ "$dir_count" -ne 0 ]; then
+ mvlogger "Not deleting top-level folder: contains $file_count file(s), $dir_count subfolder(s): ${top_folder}"
+ elif [ "$TESTMODE" != "no" ]; then
+ mvlogger "TEST MODE: Would delete empty top-level folder: $top_folder"
+ elif is_zfs_dataset_mountpoint "$top_folder"; then
+ mvlogger "Skipping deletion of ZFS dataset mountpoint: $top_folder"
+ elif rmdir "$top_folder" 2>/dev/null; then
+ mvlogger "Deleted empty top-level folder: $top_folder"
+ else
+ mvDebuglogger "Failed to delete top-level folder (may not be empty): $top_folder" "Clean Top Folder"
+ fi
+}
+
# Internal move engine
processTheMoves() {
if [ -e $SOFTSTOPFILE ]; then
@@ -2510,6 +2543,9 @@ processTheMoves() {
local -A STAGED_OK=()
local -A STAGED_VANISHED=()
local -A STAGED_INUSE=()
+ local -A TOP_SEEN=()
+ local -a TOP_FOLDERS=()
+ local top
# without fuser an open file cannot be told apart, so none is moved while moveInUse is no
local fuser_missing=0
if [ "$MOVE_IN_USE" != "yes" ] && ! command -v fuser >/dev/null; then
@@ -2834,6 +2870,7 @@ processTheMoves() {
if [ "$count" = ".placeholder" ] || [ "$count" != 0 ]; then
mvlogger "Not deleting folder containing $count file$([ "$count" != ".placeholder" ] && echo "s"): ${DIR}"
else
+ note_top_folder
if [ "$TESTMODE" = "no" ]; then
# Check if empty folder exists and remove it (but skip ZFS dataset mountpoints)
if [ -d "${DIR}" ]; then
@@ -2902,7 +2939,6 @@ processTheMoves() {
START_DIR="${SOURCE}/${FILEPATH}"
LAST_FOLDER_COUNT=$((REMAINING_CACHE_FOLDERS + REMAINING_ARRAY_FOLDERS + REMAINING_UNATTENDED_FOLDERS))
- EMPTY_DIR_COUNT=-1
# If Unraid already deleted the folder (move mode) using upper folder, skip cleanup
if [ ! -d "$START_DIR" ]; then
@@ -2926,9 +2962,11 @@ processTheMoves() {
DIR="$(dirname "${DIR}")"
done
- # Process each directory using while read
+ # Process each directory using while read; a break leaves chain_emptied 0
+ chain_emptied=1
while IFS= read -r DIR; do
[ -z "$DIR" ] && continue
+ chain_emptied=0
mvDebuglogger "Empty folder ${DIR}" "Clean Empty Moved Folder"
# Stop at ZFS dataset boundaries
@@ -2959,6 +2997,7 @@ processTheMoves() {
else
mvlogger "TEST MODE: Would delete moved empty folder: ${DIR}"
fi
+ chain_emptied=1
mvDebuglogger "Cycle of delete empty folder, Previous count: $LAST_FOLDER_COUNT, Count of all empty folders: $((LAST_FOLDER_COUNT - 1))" "Clean Empty Moved Folder - End Loop"
else
@@ -2967,52 +3006,7 @@ processTheMoves() {
fi
done <<<"${DIR_LIST}"
-
- if [ -n "${empty_file_count+x}" ] && [ -n "${empty_dir_count+x}" ]; then
- EMPTY_DIR_COUNT=$((empty_file_count + empty_dir_count))
- else
- EMPTY_DIR_COUNT=-1
- fi
- fi
-
- # Clean top level folder if empty
- if [[ "$ACTION" =~ "move" ]] && [ "$CLEANFOLDERS" = "topFolder" ]; then
- # Check counters if equal to 0 then check top share
- if [[ "$LAST_COUNT" -eq 0 || "$EMPTY_DIR_COUNT" -eq 0 ]]; then
- # Determine top-level share folder
- top_folder="${SOURCE}/${SHARENAME}"
- # Skip if placeholder exists
- if [ -d "$top_folder" ]; then
- if [ -e "${top_folder}/.placeholder" ]; then
- mvlogger "Not deleting top-level folder: contains .placeholder: ${top_folder}"
- else
- # Count files and subfolders
- file_count=$(find "$top_folder" -type f | wc -l)
- dir_count=$(find "$top_folder" -mindepth 1 -type d | wc -l)
-
- mvDebuglogger "Top folder: $(qp "$top_folder"), share file(s): $file_count, share folder(s): $dir_count" "Clean Top Folder"
-
- # Delete only if truly empty
- if [ "$file_count" -eq 0 ] && [ "$dir_count" -eq 0 ]; then
- if [ "$TESTMODE" = "no" ]; then
- if ! is_zfs_dataset_mountpoint "$top_folder"; then
- if rmdir "$top_folder" 2>/dev/null; then
- mvlogger "Deleted empty top-level folder: $top_folder"
- else
- mvDebuglogger "Failed to delete top-level folder (may not be empty): $top_folder" "Clean Top Folder"
- fi
- else
- mvlogger "Skipping deletion of ZFS dataset mountpoint: $top_folder"
- fi
- else
- mvlogger "TEST MODE: Would delete empty top-level folder: $top_folder"
- fi
- else
- mvlogger "Not deleting top-level folder: contains $file_count file(s), $dir_count subfolder(s): ${top_folder}"
- fi
- fi
- fi
- fi
+ [ "$chain_emptied" = 1 ] && note_top_folder
fi
# Setting mover status: a name leaves the remaining-work counters once it arrived or was found gone,
@@ -3063,6 +3057,8 @@ processTheMoves() {
mvlogger "$(titleLine "Cleaning up" '-')"
movesEnd
moverStep "Cleaning up"
+ # once per noted share, after the pass: a soft stop's break 2 lands here too
+ for top in "${TOP_FOLDERS[@]}"; do cleanTopFolder "$top"; done
if [ "$TESTMODE" != "yes" ] && [ ! -e $SOFTSTOPFILE ] && [ "$SYNCFAILED" = 0 ] &&
awk -F'|' '$11 ~ /^sync / { found = 1; exit } END { exit !found }' "$MOVER_ACTIONLIST"; then
diff --git a/tests/age_mover/test_folders.sh b/tests/age_mover/test_folders.sh
index cfe5a3e2..e6914f5f 100644
--- a/tests/age_mover/test_folders.sh
+++ b/tests/age_mover/test_folders.sh
@@ -1,5 +1,6 @@
#!/bin/bash
-# The folder cleanup after each row today: Clean Folders no / yes / topFolder, Move empty folders, Clean ZFS datasets.
+# The folder cleanup after each row and the top-folder check after the pass: Clean Folders no / yes / topFolder, Move
+# empty folders, Clean ZFS datasets.
. "$(dirname "$0")/lib.sh"
# the half of an unreadable-folder case that runs as a plain user, since root lists any folder
@@ -127,8 +128,27 @@ for tool in rsync move; do
log_has 'Deleted empty top-level folder: /mnt/cache/sh'
done
-# today a file row that empties its folder leaves the top-folder check on for the move rows after it, until a file row
-# leaves files behind
+# with move the cleanup finds the folder already gone, and its parent is the top folder
+for tool in rsync move; do
+ begin "topFolder, a share holding only an empty folder ($tool)" cleanFolders topFolder movefilesTool "$tool"
+ mkdir -p /mnt/cache/sh/e
+ row 'move from primary' d sh/e | list
+ run_moves
+ cache_is
+ array_is sh sh/e
+ log_has 'Deleted empty top-level folder: /mnt/cache/sh'
+done
+
+begin "topFolder, a folder row whose parent keeps a file" cleanFolders topFolder
+mk cache sh/p/k.txt
+mkdir -p /mnt/cache/sh/p/e
+row 'move from primary' d sh/p/e | list
+run_moves
+cache_is sh sh/p sh/p/k.txt
+log_has 'Not deleting folder: contains 1 file(s), 0 subfolder(s): /mnt/cache/sh/p'
+log_lacks 'top-level'
+
+# the reporter's shape: one top-folder check for the share, whichever row empties a folder first
for order in file-first folders-first; do
begin "topFolder, one file row and three folder rows, $order" cleanFolders topFolder
mk cache sh/a/f.txt sh/p/other.txt sh/keep/stay.txt
@@ -140,10 +160,31 @@ for order in file-first folders-first; do
} | list
run_moves
cache_is sh sh/keep sh/keep/stay.txt sh/p sh/p/other.txt
- log_count "$([ "$order" = file-first ] && echo 4 || echo 1)" 'top-level folder'
+ log_count 1 'top-level folder'
log_has 'Not deleting top-level folder: contains 2 file(s), 2 subfolder(s): /mnt/cache/sh'
done
+begin "topFolder, two shares, their rows taking turns" cleanFolders topFolder
+mk cache s1/a/f.txt s1/b/g.txt s1/keep/k.txt s2/a/f.txt s2/b/g.txt
+for f in s1/a/f.txt s2/a/f.txt s1/b/g.txt s2/b/g.txt; do row 'move from primary' f "$f"; done | list
+run_moves
+cache_is s1 s1/keep s1/keep/k.txt
+array_is s1 s1/a s1/a/f.txt s1/b s1/b/g.txt s2 s2/a s2/a/f.txt s2/b s2/b/g.txt
+log_count 2 'top-level folder'
+log_has 'Not deleting top-level folder: contains 1 file(s), 1 subfolder(s): /mnt/cache/s1'
+log_has 'Deleted empty top-level folder: /mnt/cache/s2'
+
+begin "topFolder, a soft stop after the first row" cleanFolders topFolder
+mk cache sh/a/f.txt sh/b/g.txt
+{ row 'move from primary' f sh/a/f.txt; row 'move from primary' f sh/b/g.txt; } | list
+after_first_rsync "touch '$SOFTSTOPFILE'"
+run_moves
+array_is sh sh/a sh/a/f.txt
+cache_is sh sh/b sh/b/g.txt
+check "the top folder is checked after the soft stop" \
+ "$(printf '%s\n' 'Soft Stopping requested' 'Not deleting top-level folder: contains 1 file(s), 1 subfolder(s): /mnt/cache/sh')" \
+ "$(log | grep -oE 'Soft Stopping requested|Not deleting top-level folder.*')"
+
# today the destroy counts regular files only: an empty folder and a symlink go with the dataset
for left in nothing 'a file' 'an empty folder and a symlink'; do
begin "Clean ZFS datasets, $left left in the share" cleanFolders topFolder cleanDatasets yes
From 74d284948f61cbb3e20e064113f8db6279ab202c Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Tue, 24 Nov 2026 20:27:37 +0800
Subject: [PATCH 24/94] Destroy a share's ZFS dataset only when nothing in it
would be lost
Each entry left must be a folder the destination also has; before, a symlink or a folder only the primary held went with
the dataset. The check runs once per share after the pass, only for rows that moved off the primary, and only for
dataset pool/share mounted at /mnt/pool/share. Snapshots keep it as child datasets do. A failed zfs list, unmount or
destroy logs zfs's reason, and a failed unmount or destroy no longer skips the row's remaining count. Help text for
Clean empty ZFS datasets and Top Folder now says what each does, in all five languages.
---
.../plugins/ca.mover.tuning/Mover.tuning.page | 4 +-
.../emhttp/plugins/ca.mover.tuning/age_mover | 118 +++++++-----
.../ca.mover.tuning/languages/de_DE.txt | 4 +-
.../ca.mover.tuning/languages/en_US.txt | 4 +-
.../ca.mover.tuning/languages/fr_FR.txt | 4 +-
.../ca.mover.tuning/languages/ru_RU.txt | 4 +-
.../ca.mover.tuning/languages/zh_CN.txt | 4 +-
tests/age_mover/lib.sh | 38 +++-
tests/age_mover/test_folders.sh | 176 ++++++++++++++++--
9 files changed, 270 insertions(+), 86 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/Mover.tuning.page b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/Mover.tuning.page
index d523e410..656a5bd2 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/Mover.tuning.page
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/Mover.tuning.page
@@ -1301,7 +1301,7 @@ _(Clean empty folders)_:
:mover_tune_cleanfolders_plug:
Yes - Removes the parent folder only of moved files.
-Top Folder - Removes the top-level share folder of the moved content, including all empty subfolders on the primary storage.
+Top Folder - As Yes , and also removes the share's top-level folder where the files moved from, once it is empty, unless it is a ZFS dataset (see Clean empty ZFS datasets ).
:end
@@ -1314,7 +1314,7 @@ _(Clean empty ZFS datasets)_:
:mover_tune_cleandatasets_plug:
-> This will unmount and destroy the parent ZFS dataset on share of moved files, only if not contain child datasets within. Works only when Clean empty folders is set to Yes or Top Folder .
+> This will unmount and destroy the share's ZFS dataset on the primary storage after its files move, only if it has no child datasets or snapshots and each entry left in it is a folder that the secondary storage also has. The dataset's own ZFS settings, such as compression or quota, are deleted with it. Works only when Clean empty folders is set to Yes or Top Folder .
:end
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index 5ec8355f..1253d708 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -290,6 +290,11 @@ is_zfs_dataset_mountpoint() {
[ "$(findmnt -no fstype --mountpoint "$1" | tail -n 1)" = "zfs" ]
}
+# Prints the ZFS dataset mounted at exactly path $1; nothing for a folder inside one
+zfs_dataset_at() {
+ is_zfs_dataset_mountpoint "$1" && findmnt -no source --mountpoint "$1" | tail -n 1
+}
+
titleLine() {
local title="$1"
local padding_char="$2"
@@ -2486,6 +2491,16 @@ note_top_folder() {
TOP_FOLDERS+=("$top")
}
+# With Clean datasets on and test mode off, notes this row's pool/share and destination for cleanShareDataset after the
+# pass, if the row moved off the primary; fills processTheMoves' DATASET_DEST
+note_share_dataset() {
+ [ "$CLEANDATASETS" = "yes" ] && [ "$TESTMODE" = "no" ] && [ "$SOURCE" = "/mnt/$PRIMARYSTORAGENAME" ] || return 0
+ local ds="$PRIMARYSTORAGENAME/$SHARENAME"
+ [ -n "${DATASET_DEST[$ds]+x}" ] && return 0
+ DATASET_DEST[$ds]=$DESTINATION
+ SHARE_DATASETS+=("$ds")
+}
+
# Deletes share top folder $1 if it is empty, unless it is a ZFS dataset mountpoint or test mode is on
cleanTopFolder() {
local top_folder=$1 file_count dir_count
@@ -2510,6 +2525,58 @@ cleanTopFolder() {
fi
}
+# Prints folder $1's first entry that is not a folder, or is a folder that folder $2 lacks; $1 itself when cd or find fails
+dataset_loses() {
+ local src=$1 dest=$2 entry
+ # two passes: the destination is read only once nothing but folders is left
+ entry=$(cd "$src" && {
+ first=$(find . -mindepth 1 ! -type d -print -quit) || exit
+ [ -n "$first" ] && { printf '%s' "$first"; exit; }
+ find . -mindepth 1 -type d ! -exec test -d "$dest/{}" \; -print -quit
+ }) || { printf '%s' "$src"; return; }
+ [ -n "$entry" ] && printf '%s' "$src/${entry#./}"
+}
+
+# Destroys dataset $1/$2 if it is mounted at /mnt/$1/$2, has no children or snapshots, and dataset_loses against $3/$2 is empty
+cleanShareDataset() {
+ local folder="/mnt/$1/$2" dataset="$1/$2" mounted names lost err
+ mounted=$(zfs_dataset_at "$folder")
+ [ -n "$mounted" ] || return 0
+ if [ "$mounted" != "$dataset" ]; then
+ mvDebuglogger "Keeping the ZFS dataset mounted at $(qp "$folder"): it is not ${dataset}" "Clean Dataset"
+ return 0
+ fi
+ # listed first, so between the content check and the unmount only a log line is written
+ if ! names=$(zfs list -r -H -t filesystem,volume,snapshot -o name "$dataset" 2>&1); then
+ mvlogger "ZFS dataset [${dataset}] could not be listed, will not delete: ${names}"
+ return 0
+ fi
+ lost=$(dataset_loses "$folder" "$3/$2")
+ if [ -n "$lost" ]; then
+ mvDebuglogger "Keeping ZFS dataset [${dataset}]: a destroy could lose $(qp "$lost")" "Clean Dataset"
+ return 0
+ fi
+ if [[ $names == *$'\n'* ]]; then
+ mvlogger "ZFS dataset [${dataset}] has child datasets or snapshots, will not delete..."
+ return 0
+ fi
+ mvlogger "ZFS dataset [${dataset}] holds only folders the destination also has, attempting to unmount and delete..."
+ # stderr is discarded on both launch paths, so zfs's reason goes to the log
+ if ! err=$(zfs unmount "$dataset" 2>&1); then
+ mvlogger_t "Failed to unmount ZFS dataset [%s]" "failure" "$dataset"
+ mvlogger "zfs: ${err}"
+ return 0
+ fi
+ mvlogger "ZFS dataset [${dataset}] successfully unmounted."
+ if ! err=$(zfs destroy "$dataset" 2>&1); then
+ mvlogger_t "Failed to destroy ZFS dataset [%s] — attempting to remount." "failure" "$dataset"
+ mvlogger "zfs: ${err}"
+ zfs mount "$dataset" 2>/dev/null || mvlogger_t "Failed to remount dataset [%s]" "warning" "$dataset"
+ return 0
+ fi
+ mvlogger "ZFS dataset [${dataset}] successfully destroyed."
+}
+
# Internal move engine
processTheMoves() {
if [ -e $SOFTSTOPFILE ]; then
@@ -2545,7 +2612,9 @@ processTheMoves() {
local -A STAGED_INUSE=()
local -A TOP_SEEN=()
local -a TOP_FOLDERS=()
- local top
+ local -A DATASET_DEST=()
+ local -a SHARE_DATASETS=()
+ local top ds
# without fuser an open file cannot be told apart, so none is moved while moveInUse is no
local fuser_missing=0
if [ "$MOVE_IN_USE" != "yes" ] && ! command -v fuser >/dev/null; then
@@ -2871,6 +2940,7 @@ processTheMoves() {
mvlogger "Not deleting folder containing $count file$([ "$count" != ".placeholder" ] && echo "s"): ${DIR}"
else
note_top_folder
+ note_share_dataset
if [ "$TESTMODE" = "no" ]; then
# Check if empty folder exists and remove it (but skip ZFS dataset mountpoints)
if [ -d "${DIR}" ]; then
@@ -2889,51 +2959,6 @@ processTheMoves() {
done
fi
- # Clean parent ZFS dataset if empty
- if [[ "$ACTION" =~ "move" && "$FILETYPE" == "f" ]] && [ "$TESTMODE" = "no" ] && [ "$CLEANDATASETS" = "yes" ] && [[ "$CLEANFOLDERS" = "yes" || "$CLEANFOLDERS" = "topFolder" ]]; then
- # Check counter if equal to 0 then check datasets
- if [ "$LAST_COUNT" -eq 0 ]; then
- # Count files in share
- share_file_count=$(find "/mnt/${PRIMARYSTORAGENAME}/${SHARENAME}" -type f | wc -l)
- mvDebuglogger "Cycle of delete dataset" "Clean Dataset - Start Loop"
- # If no files in share
- if [ "${share_file_count}" -eq 0 ]; then
- # Check if mount point is ZFS
- if is_zfs_pool "$PRIMARYSTORAGENAME"; then
- DATASET="${PRIMARYSTORAGENAME}/${SHARENAME}"
- #echo "Checking if ZFS dataset [${DATASET}] is completely empty..."
- # If ZFS dataset children size is zero and No ZFS dataset children exist
- if [ "$(zfs list -Hpo usedbychildren "${DATASET}")" = 0 ] && [ -z "$(zfs list -r -H -o name "${DATASET}" | tail -n +2)" ]; then
- # Check for any files in the ZFS dataset avalible
- dataset_file_count=$(find "/mnt/${DATASET}" -type f | wc -l)
- if [ "${dataset_file_count}" -eq 0 ]; then
- mvlogger "ZFS dataset [${DATASET}] appears empty, attempting to unmount and delete..."
- # Unmount the ZFS dataset
- if ! zfs unmount "${DATASET}"; then
- mvlogger_t "Failed to unmount ZFS dataset [%s]" "failure" "${DATASET}"
- continue
- else
- mvlogger "ZFS dataset [${DATASET}] successfully unmounted."
- fi
- # Destroy the ZFS dataset
- if ! zfs destroy "${DATASET}"; then
- mvlogger_t "Failed to destroy ZFS dataset [%s] — attempting to remount." "failure" "${DATASET}"
- zfs mount "${DATASET}" 2>/dev/null || mvlogger_t "Failed to remount dataset [%s]" "warning" "${DATASET}"
- continue
- else
- mvlogger "ZFS dataset [${DATASET}] successfully destroyed."
- fi
- else
- mvlogger "ZFS dataset [${DATASET}] contains files or directories, will not delete..."
- fi
- else
- mvlogger "ZFS dataset [${DATASET}] contains child datasets, will not delete..."
- fi
- fi
- fi
- fi
- fi
-
# Clean moved empty folders
if [[ "$ACTION" =~ "move" && "$FILETYPE" == "d" ]] && [ "$MOVE_EMPTY_FOLDERS" = "yes" ]; then
START_DIR="${SOURCE}/${FILEPATH}"
@@ -3058,6 +3083,7 @@ processTheMoves() {
movesEnd
moverStep "Cleaning up"
# once per noted share, after the pass: a soft stop's break 2 lands here too
+ for ds in "${SHARE_DATASETS[@]}"; do cleanShareDataset "${ds%%/*}" "${ds#*/}" "${DATASET_DEST[$ds]}"; done
for top in "${TOP_FOLDERS[@]}"; do cleanTopFolder "$top"; done
if [ "$TESTMODE" != "yes" ] && [ ! -e $SOFTSTOPFILE ] && [ "$SYNCFAILED" = 0 ] &&
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt
index e408ba28..fdf9c962 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt
@@ -438,11 +438,11 @@ Youre welcome 😊 Thanks for using=Gern geschehen 😊 Danke für die Nutzung!
:mover_tune_cleanfolders_plug:
Ja – entfernt den übergeordneten Ordner nur der verschobenen Dateien .
-Oberster Ordner – entfernt den gesamten Freigabe‑Ordner einschließlich aller leeren Unterordner im Primärspeicher.
+Oberster Ordner – wie Ja , und entfernt zusätzlich den obersten Freigabe‑Ordner dort, woher die Dateien verschoben wurden, sobald er leer ist, außer er ist ein ZFS‑Dataset (siehe Leere ZFS‑Datasets bereinigen ).
:end
:mover_tune_cleandatasets_plug:
-> Hängt das übergeordnete ZFS‑Dataset aus und löscht es, sofern es keine Unter‑Datasets enthält. Funktioniert nur, wenn Leere Ordner bereinigen auf Ja oder Oberster Ordner steht.
+> Hängt das ZFS‑Dataset der Freigabe im Primärspeicher aus und löscht es, nachdem ihre Dateien verschoben wurden, nur wenn es keine Unter‑Datasets oder Snapshots enthält und alles, was darin übrig ist, ein Ordner ist, den es auch im Sekundärspeicher gibt. Die eigenen ZFS‑Einstellungen des Datasets, etwa Komprimierung oder Quota, werden mit gelöscht. Funktioniert nur, wenn Leere Ordner bereinigen auf Ja oder Oberster Ordner steht.
:end
:mover_tune_sharecalculation_plug:
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt
index 5d3d1f4c..479059eb 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt
@@ -439,11 +439,11 @@ Youre welcome 😊 Thanks for using=You're welcome! 😊 Thanks for using!
:mover_tune_cleanfolders_plug:
Yes - Removes the parent folder only of moved files.
-Top Folder - Removes the top-level share folder of the moved content, including all empty subfolders on the primary storage.
+Top Folder - As Yes , and also removes the share's top-level folder where the files moved from, once it is empty, unless it is a ZFS dataset (see Clean empty ZFS datasets ).
:end
:mover_tune_cleandatasets_plug:
-> This will unmount and destroy the parent ZFS dataset on share of moved files, only if not contain child datasets within. Works only when Clean empty folders is set to Yes or Top Folder .
+> This will unmount and destroy the share's ZFS dataset on the primary storage after its files move, only if it has no child datasets or snapshots and each entry left in it is a folder that the secondary storage also has. The dataset's own ZFS settings, such as compression or quota, are deleted with it. Works only when Clean empty folders is set to Yes or Top Folder .
:end
:mover_tune_sharecalculation_plug:
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt
index ae08b424..b8595fe1 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt
@@ -446,11 +446,11 @@ Youre welcome 😊 Thanks for using=Avec plaisir 😊 Merci pour votre utilisati
:mover_tune_cleanfolders_plug:
Oui — supprime le dossier parent des fichiers déplacés.
-Dossier principal — supprime le dossier de la part et tous les sous‑dossiers vides.
+Dossier principal — comme Oui , et supprime aussi le dossier de premier niveau de la part, là d’où les fichiers ont été déplacés, une fois vide, sauf s’il s’agit d’un dataset ZFS (voir Nettoyer les datasets ZFS vides ).
:end
:mover_tune_cleandatasets_plug:
-> Démonte et détruit le dataset ZFS parent si aucun dataset enfant n’existe. Fonctionne uniquement si Nettoyer les dossiers vides est réglé sur Oui ou Dossier principal .
+> Démonte et détruit le dataset ZFS de la part sur le stockage primaire après le déplacement de ses fichiers, uniquement s’il n’a ni dataset enfant ni snapshot et si chaque élément restant est un dossier qui existe aussi sur le stockage secondaire. Les réglages ZFS propres au dataset, comme la compression ou le quota, disparaissent avec lui. Fonctionne uniquement si Nettoyer les dossiers vides est réglé sur Oui ou Dossier principal .
:end
:mover_tune_sharecalculation_plug:
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt
index 53da46ea..32f38d27 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt
@@ -436,11 +436,11 @@ Youre welcome 😊 Thanks for using=Пожалуйста! 😊 Спасибо,
:mover_tune_cleanfolders_plug:
Да — удаляет родительскую папку только для перемещённых файлов.
-Верхняя папка — удаляет папку верхнего уровня шары перемещённого содержимого, включая все пустые вложенные папки на основном хранилище.
+Верхняя папка — как Да , а также удаляет папку верхнего уровня шары там, откуда перемещены файлы, когда она пуста, если только это не ZFS-датасет (см. Очистить пустые ZFS‑датасеты ).
:end
:mover_tune_cleandatasets_plug:
-> Это размонтирует и уничтожит родительский ZFS-датасет на шаре перемещённых файлов, только если он не содержит дочерних датасетов. Работает, только если параметр Очистить пустые папки установлен в Да или Верхняя папка .
+> Это размонтирует и уничтожит ZFS-датасет шары на основном хранилище после перемещения её файлов, только если у него нет дочерних датасетов или снапшотов и всё оставшееся в нём — папки, которые есть и на вторичном хранилище. Собственные настройки ZFS датасета, например сжатие или квота, удаляются вместе с ним. Работает, только если параметр Очистить пустые папки установлен в Да или Верхняя папка .
:end
:mover_tune_sharecalculation_plug:
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt
index 974e3232..2a16273e 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt
@@ -436,11 +436,11 @@ Youre welcome 😊 Thanks for using=不客气!😊 感谢使用!
:mover_tune_cleanfolders_plug:
是 - 仅 删除已移动 文件的父文件夹。
-顶层文件夹 - 删除已移动内容的顶层共享文件夹 ,包括主存储上的所有空子文件夹 。
+顶层文件夹 - 与是 相同,并在文件移出位置的顶层共享文件夹 变空后将其删除,除非它是 ZFS 数据集(见清理空的 ZFS 数据集 )。
:end
:mover_tune_cleandatasets_plug:
-> 移动文件后卸载 并销毁 空的父 ZFS 数据集,仅在不包含 子数据集时执行。仅在清理空文件夹 设为是 或顶层文件夹 时生效。
+> 移动文件后卸载 并销毁 主存储上该共享的 ZFS 数据集,仅在 其没有子数据集或快照、且剩下的每一项都是次存储上也存在的文件夹时执行。数据集自身的 ZFS 设置(如压缩或配额)会随之删除。仅在清理空文件夹 设为是 或顶层文件夹 时生效。
:end
:mover_tune_sharecalculation_plug:
diff --git a/tests/age_mover/lib.sh b/tests/age_mover/lib.sh
index 9def7e78..d18463f0 100644
--- a/tests/age_mover/lib.sh
+++ b/tests/age_mover/lib.sh
@@ -41,22 +41,41 @@ done
EOF
chmod 755 /usr/libexec/unraid/move
fi
-# a path listed in $T/zfs is a ZFS mountpoint whose dataset has no children; zfs records each call, and fails on any it
-# has no answer for. unmount unlists it and keeps its folder; destroy rmdirs the folder, as OpenZFS does when inherited
+# a path in $T/zfs is a ZFS mountpoint (a tab, then its dataset, else the path less /mnt/); zfs logs each call to
+# $T/zfs.calls and fails on calls it has no answer for and on the subcommand $T/zfs.fail names
cat >"$T/bin/findmnt" <<'EOF'
#!/bin/bash
-grep -qxF -- "${@: -1}" "${0%/bin/findmnt}/zfs" 2>/dev/null && echo zfs
-exit 0
+l=$(awk -F'\t' -v p="${*: -1}" '$1 == p {print; exit}' "${0%/bin/findmnt}/zfs" 2>/dev/null)
+[ -n "$l" ] || exit 0
+case "$2" in
+source) n=${l#*$'\t'}; [ "$n" != "$l" ] || n=${l#/mnt/}; echo "$n" ;;
+*) echo zfs ;;
+esac
EOF
cat >"$T/bin/zfs" <<'EOF'
#!/bin/bash
d=${0%/bin/zfs}
+n=${*: -1}
echo "zfs $*" >>"$d/zfs.calls"
+[ "$1" = "$(cat "$d/zfs.fail" 2>/dev/null)" ] && { echo "cannot $1 '$n': zfs.fail" >&2; exit 1; }
+# the line of file $1 for dataset $n
+entry() { awk -F'\t' -v n="$n" '(NF > 1 ? $2 : substr($1, 6)) == n' "$1" 2>/dev/null; }
case "$*" in
-"list -Hpo usedbychildren "*) echo 0 ;;
-"list -r -H -o name "*) echo "${@: -1}" ;;
-"unmount "*) grep -vxF -- "/mnt/${*: -1}" "$d/zfs" >"$d/zfs.new"; mv "$d/zfs.new" "$d/zfs" ;;
-"destroy "*) rmdir -- "/mnt/${*: -1}" 2>/dev/null; exit 0 ;;
+# $T/zfs.on_list runs first, as a write while zfs lists; $T/zfs.children holds the children and snapshots
+"list -r -H -t filesystem,volume,snapshot -o name "*)
+ [ ! -f "$d/zfs.on_list" ] || bash "$d/zfs.on_list"
+ echo "$n"; cat "$d/zfs.children" 2>/dev/null || :
+ ;;
+# unmount unlists the dataset and keeps its folder; mount lists it again
+"unmount "*)
+ l=$(entry "$d/zfs")
+ [ -n "$l" ] || { echo "cannot unmount '$n': not currently mounted" >&2; exit 1; }
+ echo "$l" >>"$d/zfs.off"
+ grep -vxF -- "$l" "$d/zfs" >"$d/zfs.new"; mv "$d/zfs.new" "$d/zfs"
+ ;;
+"mount "*) entry "$d/zfs.off" >>"$d/zfs" ;;
+# the dataset's files go with it, and OpenZFS removes an inherited mountpoint
+"destroy "*) rm -rf -- "$(entry "$d/zfs.off" | tail -n 1 | cut -f1)" ;;
*) echo "zfs stand-in has no answer for: zfs $*" >&2; exit 1 ;;
esac
EOF
@@ -104,7 +123,7 @@ fresh() {
begin() {
CASE=$1
shift
- rm -rf "${ROOTS[@]}" "$SOFTSTOPFILE" "$PAUSEFILE" "$T/row_error" "$T/zfs" "$T/zfs.calls" "$T/after_rsync" "$T/bin/rsync" \
+ rm -rf "${ROOTS[@]}" "$SOFTSTOPFILE" "$PAUSEFILE" "$T/row_error" "$T/zfs" "$T/zfs".* "$T/after_rsync" "$T/bin/rsync" \
"$MOVER_LOG"
mkdir -p /mnt/cache /mnt/user0
fresh "$@"
@@ -203,6 +222,7 @@ log_has() { check "log has: $1" 1 "$(log | grep -cF -- "$1" | sed 's/^[1-9][0-9]
log_lacks() { check "log lacks: $1" 0 "$(log | grep -cF -- "$1")"; }
log_count() { check "log has $1 lines with: $2" "$1" "$(log | grep -cF -- "$2")"; }
dlog_has() { check "debug log has: $1" 1 "$(grep -cF -- "$1" "$MOVER_DEBUG_LOG" | sed 's/^[1-9][0-9]*$/1/')"; }
+dlog_lacks() { check "debug log lacks: $1" 0 "$(grep -cF -- "$1" "$MOVER_DEBUG_LOG")"; }
finish() {
echo "# $(basename "$0"): $((CHECKS - FAILS)) of $CHECKS checks passed"
diff --git a/tests/age_mover/test_folders.sh b/tests/age_mover/test_folders.sh
index e6914f5f..9a830e2c 100644
--- a/tests/age_mover/test_folders.sh
+++ b/tests/age_mover/test_folders.sh
@@ -6,6 +6,16 @@
# the half of an unreadable-folder case that runs as a plain user, since root lists any folder
if [ "${1:-}" = --as-tester ]; then
CASE=$2
+ if [ "$3" = dataset ]; then
+ fresh cleanFolders topFolder cleanDatasets yes
+ # the dataset check's find, then the top-folder check's two, cannot list sh/locked
+ run_moves "$(printf '%s\n' "find: './locked': Permission denied" "find: '/mnt/cache/sh/locked': Permission denied" \
+ "find: '/mnt/cache/sh/locked': Permission denied")"
+ log_lacks 'ZFS dataset [cache/sh]'
+ [ "${AGE_MOVER_DEBUG:-0}" != 2 ] || dlog_has 'Keeping ZFS dataset [cache/sh]: a destroy could lose "/mnt/cache/sh"'
+ [ "$FAILS" = 0 ]
+ exit
+ fi
fresh cleanFolders topFolder
# today find's error on the unreadable top folder reaches stderr, once for its files and once for its subfolders
run_moves "$(printf "find: '/mnt/cache/sh': Permission denied\n%.0s" 1 2)"
@@ -185,36 +195,150 @@ check "the top folder is checked after the soft stop" \
"$(printf '%s\n' 'Soft Stopping requested' 'Not deleting top-level folder: contains 1 file(s), 1 subfolder(s): /mnt/cache/sh')" \
"$(log | grep -oE 'Soft Stopping requested|Not deleting top-level folder.*')"
-# today the destroy counts regular files only: an empty folder and a symlink go with the dataset
-for left in nothing 'a file' 'an empty folder and a symlink'; do
+LS='list -r -H -t filesystem,volume,snapshot -o name'
+# the destroy goes ahead only when it loses nothing: each entry left is a folder the array also has
+for left in nothing 'a middle folder the array has' 'a file' 'a file beside it' 'a symlink' 'an empty folder the array lacks'; do
begin "Clean ZFS datasets, $left left in the share" cleanFolders topFolder cleanDatasets yes
- mk cache sh/only/f.txt
+ f=sh/only/f.txt
+ [ "$left" = 'a middle folder the array has' ] && f=sh/a/b/f.txt
+ mk cache "$f"
case $left in
- 'a file') mk cache sh/keep/k.txt ;;
- 'an empty folder'*) mkdir /mnt/cache/sh/e && ln -s /nowhere /mnt/cache/sh/link ;;
+ 'a file') mk cache sh/keep/k.txt; kept=(sh/keep sh/keep/k.txt) ;;
+ 'a file beside it') mk cache sh/only/g.txt; kept=(sh/only sh/only/g.txt) ;;
+ 'a symlink') ln -s /nowhere /mnt/cache/sh/link; kept=(sh/link) ;;
+ 'an empty folder'*) mkdir /mnt/cache/sh/e; kept=(sh/e) ;;
esac
printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
- row 'move from primary' f sh/only/f.txt | list
+ row 'move from primary' f "$f" | list
run_moves
- array_is sh sh/only sh/only/f.txt
- if [ "$left" = 'a file' ]; then
- check "no zfs calls" "" "$(cat "$T/zfs.calls" 2>/dev/null)"
- cache_is sh sh/keep sh/keep/k.txt
- log_has 'Not deleting top-level folder: contains 1 file(s), 1 subfolder(s): /mnt/cache/sh'
- continue
- fi
- check "zfs calls" "$(printf 'zfs %s cache/sh\n' 'list -Hpo usedbychildren' 'list -r -H -o name' unmount destroy)" "$(cat "$T/zfs.calls")"
- log_has 'ZFS dataset [cache/sh] successfully destroyed.'
- if [ "$left" = nothing ]; then cache_is; log_lacks 'top-level'; fi
+ if [ "$f" = sh/a/b/f.txt ]; then array_is sh sh/a sh/a/b "$f"; else array_is sh sh/only "$f"; fi
+ case $left in
+ nothing | 'a middle'*)
+ check "zfs calls" "$(printf 'zfs %s cache/sh\n' "$LS" unmount destroy)" "$(cat "$T/zfs.calls")"
+ log_has 'ZFS dataset [cache/sh] successfully destroyed.'
+ cache_is
+ log_lacks 'top-level'
+ ;;
+ *)
+ if [ "$left" = 'a file beside it' ]; then calls=; else calls="zfs $LS cache/sh"; fi
+ check "zfs calls" "$calls" "$(cat "$T/zfs.calls" 2>/dev/null)"
+ log_lacks 'ZFS dataset [cache/sh]'
+ cache_is sh "${kept[@]}"
+ if [ "${AGE_MOVER_DEBUG:-0}" != 2 ]; then
+ :
+ elif [ "$left" = 'a file beside it' ]; then
+ # the row's folder keeps a file, so the row notes no dataset
+ dlog_lacks 'Keeping ZFS dataset'
+ else
+ dlog_has "Keeping ZFS dataset [cache/sh]: a destroy could lose \"/mnt/cache/${kept[-1]}\""
+ fi
+ ;;
+ esac
done
-begin "Clean ZFS datasets, a share that empties on a pool that is not ZFS" cleanFolders topFolder cleanDatasets yes
+# zfs lists before the content check, so that check sees a file written while it lists
+begin "Clean ZFS datasets, a file lands in the share while zfs lists its children" cleanFolders topFolder cleanDatasets yes
mk cache sh/only/f.txt
+printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+echo 'echo x >/mnt/cache/sh/new.txt' >"$T/zfs.on_list"
row 'move from primary' f sh/only/f.txt | list
run_moves
+check "zfs calls" "zfs $LS cache/sh" "$(cat "$T/zfs.calls")"
+cache_is sh sh/new.txt
+[ "${AGE_MOVER_DEBUG:-0}" != 2 ] || dlog_has 'Keeping ZFS dataset [cache/sh]: a destroy could lose "/mnt/cache/sh/new.txt"'
+
+for has in 'a snapshot' 'another name'; do
+ begin "Clean ZFS datasets, the share's dataset has $has" cleanFolders topFolder cleanDatasets yes
+ mk cache sh/only/f.txt
+ row 'move from primary' f sh/only/f.txt | list
+ if [ "$has" = 'a snapshot' ]; then
+ printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+ echo cache/sh@daily >"$T/zfs.children"
+ run_moves
+ check "zfs calls" "zfs $LS cache/sh" "$(cat "$T/zfs.calls")"
+ log_has 'ZFS dataset [cache/sh] has child datasets or snapshots, will not delete...'
+ cache_is sh
+ else
+ # only dataset pool/share at /mnt/pool/share is destroyed; another dataset mounted there is kept
+ printf '/mnt/cache\n/mnt/cache/sh\tcache/data/sh\n' >"$T/zfs"
+ run_moves
+ check "no zfs calls" "" "$(cat "$T/zfs.calls" 2>/dev/null)"
+ log_lacks 'ZFS dataset ['
+ cache_is sh
+ [ "${AGE_MOVER_DEBUG:-0}" != 2 ] || dlog_has 'Keeping the ZFS dataset mounted at "/mnt/cache/sh": it is not cache/sh'
+ fi
+done
+
+# once per share, after the pass, and only for rows that emptied a folder on the primary
+begin "Clean ZFS datasets, a pass empties two folders of a share that keeps a file" cleanFolders topFolder cleanDatasets yes
+mk cache sh/a/f.txt sh/b/g.txt sh/keep/k.txt
+printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+{ row 'move from primary' f sh/a/f.txt; row 'move from primary' f sh/b/g.txt; } | list
+run_moves
+check "zfs calls" "zfs $LS cache/sh" "$(cat "$T/zfs.calls")"
+cache_is sh sh/keep sh/keep/k.txt
+
+begin "Clean ZFS datasets, a .placeholder keeps the folder after a row that emptied another share's" cleanFolders topFolder cleanDatasets yes
+mk cache a/x/f.txt sh/y/g.txt sh/y/.placeholder
+printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+{ row 'move from primary' f a/x/f.txt; row 'move from primary' f sh/y/g.txt; } | list
+run_moves
check "no zfs calls" "" "$(cat "$T/zfs.calls" 2>/dev/null)"
-cache_is
-log_has 'Deleted empty top-level folder: /mnt/cache/sh'
+cache_is sh sh/y sh/y/.placeholder
+
+begin "Clean ZFS datasets, a move from the secondary empties its folder on the array" cleanFolders topFolder cleanDatasets yes
+mk disk1 sh/only/f.txt
+printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+row 'move from secondary' f sh/only/f.txt | list
+run_moves
+check "no zfs calls" "" "$(cat "$T/zfs.calls" 2>/dev/null)"
+cache_is sh sh/only sh/only/f.txt
+
+# test mode never destroys a dataset, even when the row's folder counts empty: here its file is gone before the run
+begin "Clean ZFS datasets in test mode, the row's file gone before the run" cleanFolders topFolder cleanDatasets yes testmode yes
+mk cache sh/f.txt
+printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+row 'move from primary' f sh/f.txt | list
+rm /mnt/cache/sh/f.txt
+run_moves
+check "no zfs calls" "" "$(cat "$T/zfs.calls" 2>/dev/null)"
+cache_is sh
+log_has 'TEST MODE: Would delete empty top-level folder: /mnt/cache/sh'
+
+for pool in 'not ZFS' 'ZFS, the share a plain folder on it'; do
+ begin "Clean ZFS datasets, a share that empties on a pool that is $pool" cleanFolders topFolder cleanDatasets yes
+ mk cache sh/only/f.txt
+ [ "$pool" = 'not ZFS' ] || echo /mnt/cache >"$T/zfs"
+ row 'move from primary' f sh/only/f.txt | list
+ run_moves
+ check "no zfs calls" "" "$(cat "$T/zfs.calls" 2>/dev/null)"
+ cache_is
+ log_has 'Deleted empty top-level folder: /mnt/cache/sh'
+ [ "${AGE_MOVER_DEBUG:-0}" != 2 ] || dlog_lacks 'Keeping'
+done
+
+for fail in list unmount destroy; do
+ begin "Clean ZFS datasets, zfs $fail fails" cleanFolders topFolder cleanDatasets yes notify no
+ mk cache sh/only/f.txt
+ printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+ echo "$fail" >"$T/zfs.fail"
+ row 'move from primary' f sh/only/f.txt | list
+ # age_mover's stderr is discarded in use, so zfs's message goes to the log
+ run_moves
+ if [ "$fail" = list ]; then
+ log_has "ZFS dataset [cache/sh] could not be listed, will not delete: cannot list 'cache/sh': zfs.fail"
+ else
+ log_has "Failed to $fail ZFS dataset [cache/sh]"
+ log_has "zfs: cannot $fail 'cache/sh': zfs.fail"
+ fi
+ array_is sh sh/only sh/only/f.txt
+ cache_is sh
+ log_lacks 'Failed to remount'
+ # the row still logs and counts what it moved; the dataset is mounted at the end, so its top folder stays
+ log_has '0 files remaining from caches to array'
+ counter REMAINING_CACHE_FILES 0
+ log_has 'Skipping deletion of ZFS dataset mountpoint: /mnt/cache/sh'
+done
id tester >/dev/null 2>&1 || useradd -M tester
U=/tmp/age_mover_tester
@@ -232,4 +356,18 @@ for keep in no yes; do
if [ "$keep" = yes ]; then cache_is sh sh/stay.txt; else cache_is; fi
done
+# a find that fails keeps the dataset: the file the plain user cannot see would go with it
+begin "Clean ZFS datasets, a subfolder a plain-user mover cannot list" cleanFolders topFolder cleanDatasets yes
+mk cache sh/only/f.txt sh/locked/k.txt
+rm -rf "$U" && mkdir -p "$U"
+printf '%s\n' /mnt/cache /mnt/cache/sh >"$U/zfs"
+row 'move from primary' f sh/only/f.txt | { echo "$HDR"; cat; } >"$U/actions"
+chown -R tester /mnt/cache /mnt/user0 "$U"
+chmod 0333 /mnt/cache/sh/locked
+runuser -u tester -- env AGE_MOVER_TEST=1 AGE_MOVER_DEBUG="${AGE_MOVER_DEBUG:-0}" T="$U" bash "$0" --as-tester "$CASE" dataset
+check "the checks run as the plain user pass" 0 "$?"
+check "zfs calls" "zfs $LS cache/sh" "$(cat "$U/zfs.calls" 2>/dev/null)"
+[ ! -d /mnt/cache/sh/locked ] || chmod 0755 /mnt/cache/sh/locked
+cache_is sh sh/locked sh/locked/k.txt
+
finish
From b92bd5620f6da6bff4a18cf366d84adc438b6bf9 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Tue, 24 Nov 2026 21:52:55 +0800
Subject: [PATCH 25/94] Keep the dataset on a busy destroy; note it on folder
rows; skip .zfs; log zfs's reason only
- A folder row that empties the share notes its dataset, as a file row does (Clean Folders on only, as the help says).
- dataset_loses skips the share's own .zfs (snapdir=visible); a nested .zfs still counts.
- A kept name's newline is escaped, so debug_mover mangles the whole name.
- zfs messages are logged as their first line's reason: later lines can name child datasets.
- A failed remount logs its reason. A busy destroy remounts and logs one line, with no failure notice.
---
.../emhttp/plugins/ca.mover.tuning/age_mover | 41 ++++++----
tests/age_mover/lib.sh | 9 ++-
tests/age_mover/test_folders.sh | 76 +++++++++++++++----
3 files changed, 96 insertions(+), 30 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index 1253d708..6af9ae9d 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -295,6 +295,10 @@ zfs_dataset_at() {
is_zfs_dataset_mountpoint "$1" && findmnt -no source --mountpoint "$1" | tail -n 1
}
+# Prints zfs message $1's first line, from after its quoted name if it has one: later lines can list children's names,
+# which debug_mover does not mangle
+zfs_reason() { local r=${1%%$'\n'*}; printf '%s' "${r#*\': }"; }
+
titleLine() {
local title="$1"
local padding_char="$2"
@@ -2491,10 +2495,11 @@ note_top_folder() {
TOP_FOLDERS+=("$top")
}
-# With Clean datasets on and test mode off, notes this row's pool/share and destination for cleanShareDataset after the
-# pass, if the row moved off the primary; fills processTheMoves' DATASET_DEST
+# With Clean datasets and Clean folders on and test mode off, notes this row's pool/share and destination for
+# cleanShareDataset after the pass, if the row moved off the primary; fills processTheMoves' DATASET_DEST and SHARE_DATASETS
note_share_dataset() {
- [ "$CLEANDATASETS" = "yes" ] && [ "$TESTMODE" = "no" ] && [ "$SOURCE" = "/mnt/$PRIMARYSTORAGENAME" ] || return 0
+ [ "$CLEANDATASETS" = "yes" ] && [ "$CLEANFOLDERS" != "no" ] && [ "$TESTMODE" = "no" ] &&
+ [ "$SOURCE" = "/mnt/$PRIMARYSTORAGENAME" ] || return 0
local ds="$PRIMARYSTORAGENAME/$SHARENAME"
[ -n "${DATASET_DEST[$ds]+x}" ] && return 0
DATASET_DEST[$ds]=$DESTINATION
@@ -2525,14 +2530,15 @@ cleanTopFolder() {
fi
}
-# Prints folder $1's first entry that is not a folder, or is a folder that folder $2 lacks; $1 itself when cd or find fails
+# Prints folder $1's first entry that is not a folder, or is a folder that folder $2 lacks; $1 itself when cd or find fails.
+# Skips $1/.zfs, which snapdir=visible shows: its snapshots keep the dataset at the children check
dataset_loses() {
local src=$1 dest=$2 entry
# two passes: the destination is read only once nothing but folders is left
entry=$(cd "$src" && {
- first=$(find . -mindepth 1 ! -type d -print -quit) || exit
+ first=$(find . -mindepth 1 -path ./.zfs -prune -o ! -type d -print -quit) || exit
[ -n "$first" ] && { printf '%s' "$first"; exit; }
- find . -mindepth 1 -type d ! -exec test -d "$dest/{}" \; -print -quit
+ find . -mindepth 1 -path ./.zfs -prune -o -type d ! -exec test -d "$dest/{}" \; -print -quit
}) || { printf '%s' "$src"; return; }
[ -n "$entry" ] && printf '%s' "$src/${entry#./}"
}
@@ -2548,12 +2554,13 @@ cleanShareDataset() {
fi
# listed first, so between the content check and the unmount only a log line is written
if ! names=$(zfs list -r -H -t filesystem,volume,snapshot -o name "$dataset" 2>&1); then
- mvlogger "ZFS dataset [${dataset}] could not be listed, will not delete: ${names}"
+ mvlogger "ZFS dataset [${dataset}] could not be listed, will not delete: $(zfs_reason "$names")"
return 0
fi
lost=$(dataset_loses "$folder" "$3/$2")
if [ -n "$lost" ]; then
- mvDebuglogger "Keeping ZFS dataset [${dataset}]: a destroy could lose $(qp "$lost")" "Clean Dataset"
+ # the planner never saw this name: a newline in it would end the debug line before debug_mover's mangling
+ mvDebuglogger "Keeping ZFS dataset [${dataset}]: a destroy could lose $(qp "${lost//$'\n'/\\n}")" "Clean Dataset"
return 0
fi
if [[ $names == *$'\n'* ]]; then
@@ -2564,14 +2571,22 @@ cleanShareDataset() {
# stderr is discarded on both launch paths, so zfs's reason goes to the log
if ! err=$(zfs unmount "$dataset" 2>&1); then
mvlogger_t "Failed to unmount ZFS dataset [%s]" "failure" "$dataset"
- mvlogger "zfs: ${err}"
+ mvlogger "zfs: $(zfs_reason "$err")"
return 0
fi
mvlogger "ZFS dataset [${dataset}] successfully unmounted."
if ! err=$(zfs destroy "$dataset" 2>&1); then
- mvlogger_t "Failed to destroy ZFS dataset [%s] — attempting to remount." "failure" "$dataset"
- mvlogger "zfs: ${err}"
- zfs mount "$dataset" 2>/dev/null || mvlogger_t "Failed to remount dataset [%s]" "warning" "$dataset"
+ err=$(zfs_reason "$err")
+ if [[ $err == *busy* ]]; then
+ mvlogger "ZFS dataset [${dataset}] is busy, will not delete: another mount, such as a container's, may hold it. Remounting..."
+ else
+ mvlogger_t "Failed to destroy ZFS dataset [%s] — attempting to remount." "failure" "$dataset"
+ mvlogger "zfs: ${err}"
+ fi
+ if ! err=$(zfs mount "$dataset" 2>&1); then
+ mvlogger_t "Failed to remount dataset [%s]" "warning" "$dataset"
+ mvlogger "zfs: $(zfs_reason "$err")"
+ fi
return 0
fi
mvlogger "ZFS dataset [${dataset}] successfully destroyed."
@@ -3031,7 +3046,7 @@ processTheMoves() {
fi
done <<<"${DIR_LIST}"
- [ "$chain_emptied" = 1 ] && note_top_folder
+ [ "$chain_emptied" = 1 ] && { note_top_folder; note_share_dataset; }
fi
# Setting mover status: a name leaves the remaining-work counters once it arrived or was found gone,
diff --git a/tests/age_mover/lib.sh b/tests/age_mover/lib.sh
index d18463f0..3168fdf6 100644
--- a/tests/age_mover/lib.sh
+++ b/tests/age_mover/lib.sh
@@ -42,7 +42,8 @@ EOF
chmod 755 /usr/libexec/unraid/move
fi
# a path in $T/zfs is a ZFS mountpoint (a tab, then its dataset, else the path less /mnt/); zfs logs each call to
-# $T/zfs.calls and fails on calls it has no answer for and on the subcommand $T/zfs.fail names
+# $T/zfs.calls and fails on calls it has no answer for and on each subcommand $T/zfs.fail lists, giving the reason in
+# $T/zfs.reason (else zfs.fail) and, as zfs can, a child's name on a second line
cat >"$T/bin/findmnt" <<'EOF'
#!/bin/bash
l=$(awk -F'\t' -v p="${*: -1}" '$1 == p {print; exit}' "${0%/bin/findmnt}/zfs" 2>/dev/null)
@@ -57,7 +58,11 @@ cat >"$T/bin/zfs" <<'EOF'
d=${0%/bin/zfs}
n=${*: -1}
echo "zfs $*" >>"$d/zfs.calls"
-[ "$1" = "$(cat "$d/zfs.fail" 2>/dev/null)" ] && { echo "cannot $1 '$n': zfs.fail" >&2; exit 1; }
+if grep -qxF -- "$1" "$d/zfs.fail" 2>/dev/null; then
+ r=$(cat "$d/zfs.reason" 2>/dev/null) || r=zfs.fail
+ printf "cannot %s '%s': %s\n%s/child\n" "$1" "$n" "$r" "$n" >&2
+ exit 1
+fi
# the line of file $1 for dataset $n
entry() { awk -F'\t' -v n="$n" '(NF > 1 ? $2 : substr($1, 6)) == n' "$1" 2>/dev/null; }
case "$*" in
diff --git a/tests/age_mover/test_folders.sh b/tests/age_mover/test_folders.sh
index 9a830e2c..19a85ec2 100644
--- a/tests/age_mover/test_folders.sh
+++ b/tests/age_mover/test_folders.sh
@@ -197,7 +197,8 @@ check "the top folder is checked after the soft stop" \
LS='list -r -H -t filesystem,volume,snapshot -o name'
# the destroy goes ahead only when it loses nothing: each entry left is a folder the array also has
-for left in nothing 'a middle folder the array has' 'a file' 'a file beside it' 'a symlink' 'an empty folder the array lacks'; do
+for left in nothing 'a middle folder the array has' '.zfs, as snapdir=visible shows it,' 'a file' 'a file beside it' 'a symlink' \
+ 'an empty folder the array lacks' 'a nested .zfs folder the array lacks'; do
begin "Clean ZFS datasets, $left left in the share" cleanFolders topFolder cleanDatasets yes
f=sh/only/f.txt
[ "$left" = 'a middle folder the array has' ] && f=sh/a/b/f.txt
@@ -207,13 +208,15 @@ for left in nothing 'a middle folder the array has' 'a file' 'a file beside it'
'a file beside it') mk cache sh/only/g.txt; kept=(sh/only sh/only/g.txt) ;;
'a symlink') ln -s /nowhere /mnt/cache/sh/link; kept=(sh/link) ;;
'an empty folder'*) mkdir /mnt/cache/sh/e; kept=(sh/e) ;;
+ .zfs*) mkdir -p /mnt/cache/sh/.zfs/snapshot /mnt/cache/sh/.zfs/shares ;;
+ 'a nested .zfs'*) mkdir /mnt/cache/sh/only/.zfs; kept=(sh/only sh/only/.zfs) ;;
esac
printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
row 'move from primary' f "$f" | list
run_moves
if [ "$f" = sh/a/b/f.txt ]; then array_is sh sh/a sh/a/b "$f"; else array_is sh sh/only "$f"; fi
case $left in
- nothing | 'a middle'*)
+ nothing | 'a middle'* | .zfs*)
check "zfs calls" "$(printf 'zfs %s cache/sh\n' "$LS" unmount destroy)" "$(cat "$T/zfs.calls")"
log_has 'ZFS dataset [cache/sh] successfully destroyed.'
cache_is
@@ -247,6 +250,33 @@ check "zfs calls" "zfs $LS cache/sh" "$(cat "$T/zfs.calls")"
cache_is sh sh/new.txt
[ "${AGE_MOVER_DEBUG:-0}" != 2 ] || dlog_has 'Keeping ZFS dataset [cache/sh]: a destroy could lose "/mnt/cache/sh/new.txt"'
+# the kept name never passed the planner: a newline in it must not end the debug line before debug_mover mangles it
+begin "Clean ZFS datasets, a file named with a newline left in the share" cleanFolders topFolder cleanDatasets yes
+mk cache sh/only/f.txt
+printf 'x\n' >$'/mnt/cache/sh/Tax\nSecret.pdf'
+printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+row 'move from primary' f sh/only/f.txt | list
+run_moves
+check "zfs calls" "zfs $LS cache/sh" "$(cat "$T/zfs.calls")"
+if [ "${AGE_MOVER_DEBUG:-0}" = 2 ]; then
+ sed -n "/^cat >\"\$ANONAWK\" <<'ANONEOF'\$/,/^ANONEOF\$/p" "$PLUGIN/debug_mover" | sed '1d;$d' >"$T/anon.awk"
+ anon=$(gawk -v POOLS='user user0 cache' -v SHARES=sh -v LIST=0 -f "$T/anon.awk" "$MOVER_DEBUG_LOG")
+ check "debug_mover mangles the whole name" 'could lose "/mnt/cache/sh/-----------.pdf"' "$(grep -o 'could lose .*' <<<"$anon")"
+fi
+
+# a folder row that empties the share notes its dataset as a file row does, with Clean empty folders on only
+for clean in topFolder no; do
+ begin "Clean ZFS datasets, Clean empty folders $clean, a folder row empties the share" cleanFolders $clean cleanDatasets yes
+ mkdir -p /mnt/cache/sh/new
+ printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+ row 'move from primary' d sh/new | list
+ run_moves
+ array_is sh sh/new
+ if [ $clean = no ]; then calls=; else calls=$(printf 'zfs %s cache/sh\n' "$LS" unmount destroy); fi
+ check "zfs calls" "$calls" "$(cat "$T/zfs.calls" 2>/dev/null)"
+ if [ $clean = no ]; then cache_is sh; else cache_is; fi
+done
+
for has in 'a snapshot' 'another name'; do
begin "Clean ZFS datasets, the share's dataset has $has" cleanFolders topFolder cleanDatasets yes
mk cache sh/only/f.txt
@@ -254,10 +284,12 @@ for has in 'a snapshot' 'another name'; do
if [ "$has" = 'a snapshot' ]; then
printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
echo cache/sh@daily >"$T/zfs.children"
+ # as snapdir=visible shows it: the content check skips .zfs, so the snapshot is what keeps the dataset
+ mk cache sh/.zfs/snapshot/daily/f.txt
run_moves
check "zfs calls" "zfs $LS cache/sh" "$(cat "$T/zfs.calls")"
log_has 'ZFS dataset [cache/sh] has child datasets or snapshots, will not delete...'
- cache_is sh
+ cache_is sh sh/.zfs sh/.zfs/snapshot sh/.zfs/snapshot/daily sh/.zfs/snapshot/daily/f.txt
else
# only dataset pool/share at /mnt/pool/share is destroyed; another dataset mounted there is kept
printf '/mnt/cache\n/mnt/cache/sh\tcache/data/sh\n' >"$T/zfs"
@@ -317,26 +349,40 @@ for pool in 'not ZFS' 'ZFS, the share a plain folder on it'; do
[ "${AGE_MOVER_DEBUG:-0}" != 2 ] || dlog_lacks 'Keeping'
done
-for fail in list unmount destroy; do
+for fail in list unmount destroy 'destroy and mount' 'destroy, busy,'; do
begin "Clean ZFS datasets, zfs $fail fails" cleanFolders topFolder cleanDatasets yes notify no
mk cache sh/only/f.txt
printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
- echo "$fail" >"$T/zfs.fail"
+ case $fail in
+ 'destroy and mount') printf '%s\n' destroy mount ;;
+ *busy*) echo destroy; echo 'dataset is busy' >"$T/zfs.reason" ;;
+ *) echo "$fail" ;;
+ esac >"$T/zfs.fail"
row 'move from primary' f sh/only/f.txt | list
- # age_mover's stderr is discarded in use, so zfs's message goes to the log
+ # age_mover's stderr is discarded in use, so zfs's reason goes to the log, without the child zfs names after it
run_moves
- if [ "$fail" = list ]; then
- log_has "ZFS dataset [cache/sh] could not be listed, will not delete: cannot list 'cache/sh': zfs.fail"
- else
- log_has "Failed to $fail ZFS dataset [cache/sh]"
- log_has "zfs: cannot $fail 'cache/sh': zfs.fail"
- fi
+ case $fail in
+ list) log_has "ZFS dataset [cache/sh] could not be listed, will not delete: zfs.fail" ;;
+ # the failure notice goes out with the "Failed to" line
+ *busy*)
+ log_has "ZFS dataset [cache/sh] is busy, will not delete: another mount, such as a container's, may hold it."
+ log_lacks 'Failed to destroy'
+ ;;
+ *) log_has "Failed to ${fail%% *} ZFS dataset [cache/sh]"; log_has 'zfs: zfs.fail' ;;
+ esac
+ log_lacks 'cache/sh/child'
array_is sh sh/only sh/only/f.txt
- cache_is sh
- log_lacks 'Failed to remount'
- # the row still logs and counts what it moved; the dataset is mounted at the end, so its top folder stays
+ # the row still logs and counts what it moved
log_has '0 files remaining from caches to array'
counter REMAINING_CACHE_FILES 0
+ if [ "$fail" = 'destroy and mount' ]; then
+ log_has 'Failed to remount dataset [cache/sh]'
+ log_count 2 'zfs: zfs.fail'
+ continue
+ fi
+ # the dataset is mounted at the end, so its top folder stays
+ cache_is sh
+ log_lacks 'Failed to remount'
log_has 'Skipping deletion of ZFS dataset mountpoint: /mnt/cache/sh'
done
From 9d84d417684a0cb07a206568ca192fb50cb6c66f Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 00:38:15 +0800
Subject: [PATCH 26/94] Treat a busy unmount as a busy destroy; remount only
over an empty folder; split dataset tests
- A busy unmount logs one line and sends no failure notice, as a busy destroy does (zfs_busy).
- After a failed destroy, a folder that gained files while unmounted is not remounted over: a warning says why.
- note_emptied_share owns the top-folder and dataset notes.
- test_datasets.sh takes the dataset cases; the zfs stand-in hides files on unmount and on mount as an overlay mount does.
---
.../emhttp/plugins/ca.mover.tuning/age_mover | 38 ++-
tests/age_mover/lib.sh | 23 +-
tests/age_mover/test_datasets.sh | 240 ++++++++++++++++++
tests/age_mover/test_folders.sh | 217 +---------------
4 files changed, 281 insertions(+), 237 deletions(-)
create mode 100644 tests/age_mover/test_datasets.sh
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index 7050470d..390bf5f1 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -299,6 +299,12 @@ zfs_dataset_at() {
# which debug_mover does not mangle
zfs_reason() { local r=${1%%$'\n'*}; printf '%s' "${r#*\': }"; }
+# When zfs message $2 says dataset $1 is busy, logs one plain line and succeeds: something else holds it, so no notice
+zfs_busy() {
+ [[ $(zfs_reason "$2") == *busy* ]] || return 1
+ mvlogger "ZFS dataset [$1] is busy, will not delete: a process or another mount, such as a container's, may hold it."
+}
+
titleLine() {
local title="$1"
local padding_char="$2"
@@ -2496,7 +2502,7 @@ note_top_folder() {
}
# With Clean datasets and Clean folders on and test mode off, notes this row's pool/share and destination for
-# cleanShareDataset after the pass, if the row moved off the primary; fills processTheMoves' DATASET_DEST and SHARE_DATASETS
+# cleanShareDataset after the pass when the row's source is the primary; fills processTheMoves' DATASET_DEST and SHARE_DATASETS
note_share_dataset() {
[ "$CLEANDATASETS" = "yes" ] && [ "$CLEANFOLDERS" != "no" ] && [ "$TESTMODE" = "no" ] &&
[ "$SOURCE" = "/mnt/$PRIMARYSTORAGENAME" ] || return 0
@@ -2506,6 +2512,10 @@ note_share_dataset() {
SHARE_DATASETS+=("$ds")
}
+# A folder in this row's share emptied: hands the share to the top-folder and dataset checks after the pass, each
+# under its own settings
+note_emptied_share() { note_top_folder; note_share_dataset; }
+
# Deletes share top folder $1 if it is empty, unless it is a ZFS dataset mountpoint or test mode is on
cleanTopFolder() {
local top_folder=$1 file_count dir_count
@@ -2570,20 +2580,23 @@ cleanShareDataset() {
mvlogger "ZFS dataset [${dataset}] holds only folders the destination also has, attempting to unmount and delete..."
# stderr is discarded on both launch paths, so zfs's reason goes to the log
if ! err=$(zfs unmount "$dataset" 2>&1); then
- mvlogger_t "Failed to unmount ZFS dataset [%s]" "failure" "$dataset"
- mvlogger "zfs: $(zfs_reason "$err")"
+ zfs_busy "$dataset" "$err" || {
+ mvlogger_t "Failed to unmount ZFS dataset [%s]" "failure" "$dataset"
+ mvlogger "zfs: $(zfs_reason "$err")"
+ }
return 0
fi
mvlogger "ZFS dataset [${dataset}] successfully unmounted."
if ! err=$(zfs destroy "$dataset" 2>&1); then
- err=$(zfs_reason "$err")
- if [[ $err == *busy* ]]; then
- mvlogger "ZFS dataset [${dataset}] is busy, will not delete: another mount, such as a container's, may hold it. Remounting..."
- else
+ zfs_busy "$dataset" "$err" || {
mvlogger_t "Failed to destroy ZFS dataset [%s] — attempting to remount." "failure" "$dataset"
- mvlogger "zfs: ${err}"
- fi
- if ! err=$(zfs mount "$dataset" 2>&1); then
+ mvlogger "zfs: $(zfs_reason "$err")"
+ }
+ # a write through /mnt/user while it was unmounted lands in the bare folder, and a mount over it would hide it
+ if [ -n "$(find "$folder" -mindepth 1 -print -quit 2>/dev/null)" ]; then
+ mvlogger_t "Failed to remount dataset [%s]" "warning" "$dataset"
+ mvlogger "Not remounting ZFS dataset [${dataset}]: its folder ${folder} holds files that a mount would hide"
+ elif ! err=$(zfs mount "$dataset" 2>&1); then
mvlogger_t "Failed to remount dataset [%s]" "warning" "$dataset"
mvlogger "zfs: $(zfs_reason "$err")"
fi
@@ -2961,8 +2974,7 @@ processTheMoves() {
if [ "$count" = ".placeholder" ] || [ "$count" != 0 ]; then
mvlogger "Not deleting folder containing $count file$([ "$count" != ".placeholder" ] && echo "s"): ${DIR}"
else
- note_top_folder
- note_share_dataset
+ note_emptied_share
if [ "$TESTMODE" = "no" ]; then
# Check if empty folder exists and remove it (but skip ZFS dataset mountpoints)
if [ -d "${DIR}" ]; then
@@ -3053,7 +3065,7 @@ processTheMoves() {
fi
done <<<"${DIR_LIST}"
- [ "$chain_emptied" = 1 ] && { note_top_folder; note_share_dataset; }
+ [ "$chain_emptied" = 1 ] && note_emptied_share
fi
# Setting mover status: a name leaves the remaining-work counters once it arrived or was found gone,
diff --git a/tests/age_mover/lib.sh b/tests/age_mover/lib.sh
index cc699de9..3f0179d2 100644
--- a/tests/age_mover/lib.sh
+++ b/tests/age_mover/lib.sh
@@ -41,9 +41,8 @@ done
EOF
chmod 755 /usr/libexec/unraid/move
fi
-# a path in $T/zfs is a ZFS mountpoint (a tab, then its dataset, else the path less /mnt/); zfs logs each call to
-# $T/zfs.calls and fails on calls it has no answer for and on each subcommand $T/zfs.fail lists, giving the reason in
-# $T/zfs.reason (else zfs.fail) and, as zfs can, a child's name on a second line
+# a path in $T/zfs is a ZFS mountpoint (a tab, then its dataset, else the path less /mnt/); zfs logs calls to $T/zfs.calls
+# and fails unanswered calls and each subcommand in $T/zfs.fail, with $T/zfs.reason (else zfs.fail) then a child's name
cat >"$T/bin/findmnt" <<'EOF'
#!/bin/bash
l=$(awk -F'\t' -v p="${*: -1}" '$1 == p {print; exit}' "${0%/bin/findmnt}/zfs" 2>/dev/null)
@@ -58,6 +57,8 @@ cat >"$T/bin/zfs" <<'EOF'
d=${0%/bin/zfs}
n=${*: -1}
echo "zfs $*" >>"$d/zfs.calls"
+# $T/zfs.on_ runs first, as a write while zfs works
+[ ! -f "$d/zfs.on_$1" ] || bash "$d/zfs.on_$1"
if grep -qxF -- "$1" "$d/zfs.fail" 2>/dev/null; then
r=$(cat "$d/zfs.reason" 2>/dev/null) || r=zfs.fail
printf "cannot %s '%s': %s\n%s/child\n" "$1" "$n" "$r" "$n" >&2
@@ -66,21 +67,27 @@ fi
# the line of file $1 for dataset $n
entry() { awk -F'\t' -v n="$n" '(NF > 1 ? $2 : substr($1, 6)) == n' "$1" 2>/dev/null; }
case "$*" in
-# $T/zfs.on_list runs first, as a write while zfs lists; $T/zfs.children holds the children and snapshots
+# $T/zfs.children holds the children and snapshots
"list -r -H -t filesystem,volume,snapshot -o name "*)
- [ ! -f "$d/zfs.on_list" ] || bash "$d/zfs.on_list"
echo "$n"; cat "$d/zfs.children" 2>/dev/null || :
;;
-# unmount unlists the dataset and keeps its folder; mount lists it again
+# unmount unlists the dataset and hides its files, keeping its folder; mount lists it and brings them back, hiding,
+# as an overlay mount does, what the folder gained meanwhile
"unmount "*)
l=$(entry "$d/zfs")
[ -n "$l" ] || { echo "cannot unmount '$n': not currently mounted" >&2; exit 1; }
echo "$l" >>"$d/zfs.off"
grep -vxF -- "$l" "$d/zfs" >"$d/zfs.new"; mv "$d/zfs.new" "$d/zfs"
+ mkdir -p "$d/zfs.store/$n" && find "${l%%$'\t'*}" -mindepth 1 -maxdepth 1 -exec mv -t "$d/zfs.store/$n" {} +
+ ;;
+"mount "*)
+ l=$(entry "$d/zfs.off" | tail -n 1) && f=${l%%$'\t'*}
+ mkdir -p "$d/zfs.hidden" "$f" && find "$f" -mindepth 1 -maxdepth 1 -exec mv -t "$d/zfs.hidden" {} +
+ find "$d/zfs.store/$n" -mindepth 1 -maxdepth 1 -exec mv -t "$f" {} +
+ echo "$l" >>"$d/zfs"
;;
-"mount "*) entry "$d/zfs.off" >>"$d/zfs" ;;
# the dataset's files go with it, and OpenZFS removes an inherited mountpoint
-"destroy "*) rm -rf -- "$(entry "$d/zfs.off" | tail -n 1 | cut -f1)" ;;
+"destroy "*) rm -rf -- "$(entry "$d/zfs.off" | tail -n 1 | cut -f1)" "$d/zfs.store/$n" ;;
*) echo "zfs stand-in has no answer for: zfs $*" >&2; exit 1 ;;
esac
EOF
diff --git a/tests/age_mover/test_datasets.sh b/tests/age_mover/test_datasets.sh
new file mode 100644
index 00000000..d05ae10a
--- /dev/null
+++ b/tests/age_mover/test_datasets.sh
@@ -0,0 +1,240 @@
+#!/bin/bash
+# Clean ZFS datasets: after the pass, a share's dataset is destroyed only when nothing in it would be lost.
+. "$(dirname "$0")/lib.sh"
+
+# the half of the unreadable-subfolder case that runs as a plain user, since root lists any folder
+if [ "${1:-}" = --as-tester ]; then
+ CASE=$2
+ fresh cleanFolders topFolder cleanDatasets yes
+ # the dataset check's find, then the top-folder check's two, cannot list sh/locked
+ run_moves "$(printf '%s\n' "find: './locked': Permission denied" "find: '/mnt/cache/sh/locked': Permission denied" \
+ "find: '/mnt/cache/sh/locked': Permission denied")"
+ log_lacks 'ZFS dataset [cache/sh]'
+ [ "${AGE_MOVER_DEBUG:-0}" != 2 ] || dlog_has 'Keeping ZFS dataset [cache/sh]: a destroy could lose "/mnt/cache/sh"'
+ [ "$FAILS" = 0 ]
+ exit
+fi
+
+LS='list -r -H -t filesystem,volume,snapshot -o name'
+# the destroy goes ahead only when it loses nothing: each entry left is a folder the array also has
+for left in nothing 'a middle folder the array has' '.zfs, as snapdir=visible shows it,' 'a file' 'a file beside it' 'a symlink' \
+ 'an empty folder the array lacks' 'a nested .zfs folder the array lacks'; do
+ begin "Clean ZFS datasets, $left left in the share" cleanFolders topFolder cleanDatasets yes
+ f=sh/only/f.txt
+ [ "$left" = 'a middle folder the array has' ] && f=sh/a/b/f.txt
+ mk cache "$f"
+ case $left in
+ 'a file') mk cache sh/keep/k.txt; kept=(sh/keep sh/keep/k.txt) ;;
+ 'a file beside it') mk cache sh/only/g.txt; kept=(sh/only sh/only/g.txt) ;;
+ 'a symlink') ln -s /nowhere /mnt/cache/sh/link; kept=(sh/link) ;;
+ 'an empty folder'*) mkdir /mnt/cache/sh/e; kept=(sh/e) ;;
+ .zfs*) mkdir -p /mnt/cache/sh/.zfs/snapshot /mnt/cache/sh/.zfs/shares ;;
+ 'a nested .zfs'*) mkdir /mnt/cache/sh/only/.zfs; kept=(sh/only sh/only/.zfs) ;;
+ esac
+ printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+ row 'move from primary' f "$f" | list
+ run_moves
+ if [ "$f" = sh/a/b/f.txt ]; then array_is sh sh/a sh/a/b "$f"; else array_is sh sh/only "$f"; fi
+ case $left in
+ nothing | 'a middle'* | .zfs*)
+ check "zfs calls" "$(printf 'zfs %s cache/sh\n' "$LS" unmount destroy)" "$(cat "$T/zfs.calls")"
+ log_has 'ZFS dataset [cache/sh] successfully destroyed.'
+ cache_is
+ log_lacks 'top-level'
+ ;;
+ *)
+ if [ "$left" = 'a file beside it' ]; then calls=; else calls="zfs $LS cache/sh"; fi
+ check "zfs calls" "$calls" "$(cat "$T/zfs.calls" 2>/dev/null)"
+ log_lacks 'ZFS dataset [cache/sh]'
+ cache_is sh "${kept[@]}"
+ if [ "${AGE_MOVER_DEBUG:-0}" != 2 ]; then
+ :
+ elif [ "$left" = 'a file beside it' ]; then
+ # the row's folder keeps a file, so the row notes no dataset
+ dlog_lacks 'Keeping ZFS dataset'
+ else
+ dlog_has "Keeping ZFS dataset [cache/sh]: a destroy could lose \"/mnt/cache/${kept[-1]}\""
+ fi
+ ;;
+ esac
+done
+
+# zfs lists before the content check, so that check sees a file written while it lists
+begin "Clean ZFS datasets, a file lands in the share while zfs lists its children" cleanFolders topFolder cleanDatasets yes
+mk cache sh/only/f.txt
+printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+echo 'echo x >/mnt/cache/sh/new.txt' >"$T/zfs.on_list"
+row 'move from primary' f sh/only/f.txt | list
+run_moves
+check "zfs calls" "zfs $LS cache/sh" "$(cat "$T/zfs.calls")"
+cache_is sh sh/new.txt
+[ "${AGE_MOVER_DEBUG:-0}" != 2 ] || dlog_has 'Keeping ZFS dataset [cache/sh]: a destroy could lose "/mnt/cache/sh/new.txt"'
+
+# the kept name never passed the planner: a newline in it must not end the debug line before debug_mover mangles it
+begin "Clean ZFS datasets, a file named with a newline left in the share" cleanFolders topFolder cleanDatasets yes
+mk cache sh/only/f.txt
+printf 'x\n' >$'/mnt/cache/sh/Tax\nSecret.pdf'
+printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+row 'move from primary' f sh/only/f.txt | list
+run_moves
+check "zfs calls" "zfs $LS cache/sh" "$(cat "$T/zfs.calls")"
+if [ "${AGE_MOVER_DEBUG:-0}" = 2 ]; then
+ sed -n "/^cat >\"\$ANONAWK\" <<'ANONEOF'\$/,/^ANONEOF\$/p" "$PLUGIN/debug_mover" | sed '1d;$d' >"$T/anon.awk"
+ anon=$(gawk -v POOLS='user user0 cache' -v SHARES=sh -v LIST=0 -f "$T/anon.awk" "$MOVER_DEBUG_LOG")
+ check "debug_mover mangles the whole name" 'could lose "/mnt/cache/sh/-----------.pdf"' "$(grep -o 'could lose .*' <<<"$anon")"
+fi
+
+# a folder row that empties the share notes its dataset as a file row does, with Clean empty folders on only
+for clean in topFolder no; do
+ begin "Clean ZFS datasets, Clean empty folders $clean, a folder row empties the share" cleanFolders $clean cleanDatasets yes
+ mkdir -p /mnt/cache/sh/new
+ printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+ row 'move from primary' d sh/new | list
+ run_moves
+ array_is sh sh/new
+ if [ $clean = no ]; then calls=; else calls=$(printf 'zfs %s cache/sh\n' "$LS" unmount destroy); fi
+ check "zfs calls" "$calls" "$(cat "$T/zfs.calls" 2>/dev/null)"
+ if [ $clean = no ]; then cache_is sh; else cache_is; fi
+done
+
+for has in 'a snapshot' 'another name'; do
+ begin "Clean ZFS datasets, the share's dataset has $has" cleanFolders topFolder cleanDatasets yes
+ mk cache sh/only/f.txt
+ row 'move from primary' f sh/only/f.txt | list
+ if [ "$has" = 'a snapshot' ]; then
+ printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+ echo cache/sh@daily >"$T/zfs.children"
+ # as snapdir=visible shows it: the content check skips .zfs, so the snapshot is what keeps the dataset
+ mk cache sh/.zfs/snapshot/daily/f.txt
+ run_moves
+ check "zfs calls" "zfs $LS cache/sh" "$(cat "$T/zfs.calls")"
+ log_has 'ZFS dataset [cache/sh] has child datasets or snapshots, will not delete...'
+ cache_is sh sh/.zfs sh/.zfs/snapshot sh/.zfs/snapshot/daily sh/.zfs/snapshot/daily/f.txt
+ else
+ # only dataset pool/share at /mnt/pool/share is destroyed; another dataset mounted there is kept
+ printf '/mnt/cache\n/mnt/cache/sh\tcache/data/sh\n' >"$T/zfs"
+ run_moves
+ check "no zfs calls" "" "$(cat "$T/zfs.calls" 2>/dev/null)"
+ log_lacks 'ZFS dataset ['
+ cache_is sh
+ [ "${AGE_MOVER_DEBUG:-0}" != 2 ] || dlog_has 'Keeping the ZFS dataset mounted at "/mnt/cache/sh": it is not cache/sh'
+ fi
+done
+
+# once per share, after the pass, and only for rows that emptied a folder on the primary
+begin "Clean ZFS datasets, a pass empties two folders of a share that keeps a file" cleanFolders topFolder cleanDatasets yes
+mk cache sh/a/f.txt sh/b/g.txt sh/keep/k.txt
+printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+{ row 'move from primary' f sh/a/f.txt; row 'move from primary' f sh/b/g.txt; } | list
+run_moves
+check "zfs calls" "zfs $LS cache/sh" "$(cat "$T/zfs.calls")"
+cache_is sh sh/keep sh/keep/k.txt
+
+begin "Clean ZFS datasets, a .placeholder keeps the folder after a row that emptied another share's" cleanFolders topFolder cleanDatasets yes
+mk cache a/x/f.txt sh/y/g.txt sh/y/.placeholder
+printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+{ row 'move from primary' f a/x/f.txt; row 'move from primary' f sh/y/g.txt; } | list
+run_moves
+check "no zfs calls" "" "$(cat "$T/zfs.calls" 2>/dev/null)"
+cache_is sh sh/y sh/y/.placeholder
+
+begin "Clean ZFS datasets, a move from the secondary empties its folder on the array" cleanFolders topFolder cleanDatasets yes
+mk disk1 sh/only/f.txt
+printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+row 'move from secondary' f sh/only/f.txt | list
+run_moves
+check "no zfs calls" "" "$(cat "$T/zfs.calls" 2>/dev/null)"
+cache_is sh sh/only sh/only/f.txt
+
+# test mode never destroys a dataset, even when the row's folder counts empty: here its file is gone before the run
+begin "Clean ZFS datasets in test mode, the row's file gone before the run" cleanFolders topFolder cleanDatasets yes testmode yes
+mk cache sh/f.txt
+printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+row 'move from primary' f sh/f.txt | list
+rm /mnt/cache/sh/f.txt
+run_moves
+check "no zfs calls" "" "$(cat "$T/zfs.calls" 2>/dev/null)"
+cache_is sh
+log_has 'TEST MODE: Would delete empty top-level folder: /mnt/cache/sh'
+
+for pool in 'not ZFS' 'ZFS, the share a plain folder on it'; do
+ begin "Clean ZFS datasets, a share that empties on a pool that is $pool" cleanFolders topFolder cleanDatasets yes
+ mk cache sh/only/f.txt
+ [ "$pool" = 'not ZFS' ] || echo /mnt/cache >"$T/zfs"
+ row 'move from primary' f sh/only/f.txt | list
+ run_moves
+ check "no zfs calls" "" "$(cat "$T/zfs.calls" 2>/dev/null)"
+ cache_is
+ log_has 'Deleted empty top-level folder: /mnt/cache/sh'
+ [ "${AGE_MOVER_DEBUG:-0}" != 2 ] || dlog_lacks 'Keeping'
+done
+
+for fail in list unmount 'unmount, busy,' destroy 'destroy and mount' 'destroy, busy,'; do
+ begin "Clean ZFS datasets, zfs $fail fails" cleanFolders topFolder cleanDatasets yes notify no
+ mk cache sh/only/f.txt
+ printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+ case $fail in
+ 'destroy and mount') printf '%s\n' destroy mount ;;
+ 'unmount, busy,') echo unmount; echo 'pool or dataset is busy' >"$T/zfs.reason" ;;
+ 'destroy, busy,') echo destroy; echo 'dataset is busy' >"$T/zfs.reason" ;;
+ *) echo "$fail" ;;
+ esac >"$T/zfs.fail"
+ row 'move from primary' f sh/only/f.txt | list
+ # age_mover's stderr is discarded in use, so zfs's reason goes to the log, without the child zfs names after it
+ run_moves
+ case $fail in
+ list) log_has "ZFS dataset [cache/sh] could not be listed, will not delete: zfs.fail" ;;
+ # the failure notice goes out with the "Failed to" line
+ *busy*)
+ log_has "ZFS dataset [cache/sh] is busy, will not delete: a process or another mount, such as a container's, may hold it."
+ log_lacks "Failed to ${fail%%,*}"
+ ;;
+ *) log_has "Failed to ${fail%% *} ZFS dataset [cache/sh]"; log_has 'zfs: zfs.fail' ;;
+ esac
+ log_lacks 'cache/sh/child'
+ array_is sh sh/only sh/only/f.txt
+ # the row still logs and counts what it moved
+ log_has '0 files remaining from caches to array'
+ counter REMAINING_CACHE_FILES 0
+ if [ "$fail" = 'destroy and mount' ]; then
+ log_has 'Failed to remount dataset [cache/sh]'
+ log_count 2 'zfs: zfs.fail'
+ continue
+ fi
+ # the dataset is mounted at the end, so its top folder stays
+ cache_is sh
+ log_lacks 'Failed to remount'
+ log_has 'Skipping deletion of ZFS dataset mountpoint: /mnt/cache/sh'
+done
+
+# a write through /mnt/user while the dataset is unmounted lands in its bare folder, which a remount would hide
+begin "Clean ZFS datasets, a file lands in the unmounted share's folder before a failed destroy" cleanFolders topFolder \
+ cleanDatasets yes notify no
+mk cache sh/only/f.txt
+printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+echo destroy >"$T/zfs.fail"
+echo 'echo x >/mnt/cache/sh/new.txt' >"$T/zfs.on_destroy"
+row 'move from primary' f sh/only/f.txt | list
+run_moves
+check "zfs calls" "$(printf 'zfs %s cache/sh\n' "$LS" unmount destroy)" "$(cat "$T/zfs.calls")"
+log_has 'Failed to remount dataset [cache/sh]'
+log_has 'Not remounting ZFS dataset [cache/sh]: its folder /mnt/cache/sh holds files that a mount would hide'
+cache_is sh sh/new.txt
+
+id tester >/dev/null 2>&1 || useradd -M tester
+U=/tmp/age_mover_tester
+# a find that fails keeps the dataset: the file the plain user cannot see would go with it
+begin "Clean ZFS datasets, a subfolder a plain-user mover cannot list" cleanFolders topFolder cleanDatasets yes
+mk cache sh/only/f.txt sh/locked/k.txt
+rm -rf "$U" && mkdir -p "$U"
+printf '%s\n' /mnt/cache /mnt/cache/sh >"$U/zfs"
+row 'move from primary' f sh/only/f.txt | { echo "$HDR"; cat; } >"$U/actions"
+chown -R tester /mnt/cache /mnt/user0 "$U"
+chmod 0333 /mnt/cache/sh/locked
+runuser -u tester -- env AGE_MOVER_TEST=1 AGE_MOVER_DEBUG="${AGE_MOVER_DEBUG:-0}" T="$U" bash "$0" --as-tester "$CASE"
+check "the checks run as the plain user pass" 0 "$?"
+check "zfs calls" "zfs $LS cache/sh" "$(cat "$U/zfs.calls" 2>/dev/null)"
+[ ! -d /mnt/cache/sh/locked ] || chmod 0755 /mnt/cache/sh/locked
+cache_is sh sh/locked sh/locked/k.txt
+
+finish
diff --git a/tests/age_mover/test_folders.sh b/tests/age_mover/test_folders.sh
index 19a85ec2..b920d9f2 100644
--- a/tests/age_mover/test_folders.sh
+++ b/tests/age_mover/test_folders.sh
@@ -1,21 +1,11 @@
#!/bin/bash
# The folder cleanup after each row and the top-folder check after the pass: Clean Folders no / yes / topFolder, Move
-# empty folders, Clean ZFS datasets.
+# empty folders. Clean ZFS datasets: test_datasets.sh.
. "$(dirname "$0")/lib.sh"
# the half of an unreadable-folder case that runs as a plain user, since root lists any folder
if [ "${1:-}" = --as-tester ]; then
CASE=$2
- if [ "$3" = dataset ]; then
- fresh cleanFolders topFolder cleanDatasets yes
- # the dataset check's find, then the top-folder check's two, cannot list sh/locked
- run_moves "$(printf '%s\n' "find: './locked': Permission denied" "find: '/mnt/cache/sh/locked': Permission denied" \
- "find: '/mnt/cache/sh/locked': Permission denied")"
- log_lacks 'ZFS dataset [cache/sh]'
- [ "${AGE_MOVER_DEBUG:-0}" != 2 ] || dlog_has 'Keeping ZFS dataset [cache/sh]: a destroy could lose "/mnt/cache/sh"'
- [ "$FAILS" = 0 ]
- exit
- fi
fresh cleanFolders topFolder
# today find's error on the unreadable top folder reaches stderr, once for its files and once for its subfolders
run_moves "$(printf "find: '/mnt/cache/sh': Permission denied\n%.0s" 1 2)"
@@ -195,197 +185,6 @@ check "the top folder is checked after the soft stop" \
"$(printf '%s\n' 'Soft Stopping requested' 'Not deleting top-level folder: contains 1 file(s), 1 subfolder(s): /mnt/cache/sh')" \
"$(log | grep -oE 'Soft Stopping requested|Not deleting top-level folder.*')"
-LS='list -r -H -t filesystem,volume,snapshot -o name'
-# the destroy goes ahead only when it loses nothing: each entry left is a folder the array also has
-for left in nothing 'a middle folder the array has' '.zfs, as snapdir=visible shows it,' 'a file' 'a file beside it' 'a symlink' \
- 'an empty folder the array lacks' 'a nested .zfs folder the array lacks'; do
- begin "Clean ZFS datasets, $left left in the share" cleanFolders topFolder cleanDatasets yes
- f=sh/only/f.txt
- [ "$left" = 'a middle folder the array has' ] && f=sh/a/b/f.txt
- mk cache "$f"
- case $left in
- 'a file') mk cache sh/keep/k.txt; kept=(sh/keep sh/keep/k.txt) ;;
- 'a file beside it') mk cache sh/only/g.txt; kept=(sh/only sh/only/g.txt) ;;
- 'a symlink') ln -s /nowhere /mnt/cache/sh/link; kept=(sh/link) ;;
- 'an empty folder'*) mkdir /mnt/cache/sh/e; kept=(sh/e) ;;
- .zfs*) mkdir -p /mnt/cache/sh/.zfs/snapshot /mnt/cache/sh/.zfs/shares ;;
- 'a nested .zfs'*) mkdir /mnt/cache/sh/only/.zfs; kept=(sh/only sh/only/.zfs) ;;
- esac
- printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
- row 'move from primary' f "$f" | list
- run_moves
- if [ "$f" = sh/a/b/f.txt ]; then array_is sh sh/a sh/a/b "$f"; else array_is sh sh/only "$f"; fi
- case $left in
- nothing | 'a middle'* | .zfs*)
- check "zfs calls" "$(printf 'zfs %s cache/sh\n' "$LS" unmount destroy)" "$(cat "$T/zfs.calls")"
- log_has 'ZFS dataset [cache/sh] successfully destroyed.'
- cache_is
- log_lacks 'top-level'
- ;;
- *)
- if [ "$left" = 'a file beside it' ]; then calls=; else calls="zfs $LS cache/sh"; fi
- check "zfs calls" "$calls" "$(cat "$T/zfs.calls" 2>/dev/null)"
- log_lacks 'ZFS dataset [cache/sh]'
- cache_is sh "${kept[@]}"
- if [ "${AGE_MOVER_DEBUG:-0}" != 2 ]; then
- :
- elif [ "$left" = 'a file beside it' ]; then
- # the row's folder keeps a file, so the row notes no dataset
- dlog_lacks 'Keeping ZFS dataset'
- else
- dlog_has "Keeping ZFS dataset [cache/sh]: a destroy could lose \"/mnt/cache/${kept[-1]}\""
- fi
- ;;
- esac
-done
-
-# zfs lists before the content check, so that check sees a file written while it lists
-begin "Clean ZFS datasets, a file lands in the share while zfs lists its children" cleanFolders topFolder cleanDatasets yes
-mk cache sh/only/f.txt
-printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
-echo 'echo x >/mnt/cache/sh/new.txt' >"$T/zfs.on_list"
-row 'move from primary' f sh/only/f.txt | list
-run_moves
-check "zfs calls" "zfs $LS cache/sh" "$(cat "$T/zfs.calls")"
-cache_is sh sh/new.txt
-[ "${AGE_MOVER_DEBUG:-0}" != 2 ] || dlog_has 'Keeping ZFS dataset [cache/sh]: a destroy could lose "/mnt/cache/sh/new.txt"'
-
-# the kept name never passed the planner: a newline in it must not end the debug line before debug_mover mangles it
-begin "Clean ZFS datasets, a file named with a newline left in the share" cleanFolders topFolder cleanDatasets yes
-mk cache sh/only/f.txt
-printf 'x\n' >$'/mnt/cache/sh/Tax\nSecret.pdf'
-printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
-row 'move from primary' f sh/only/f.txt | list
-run_moves
-check "zfs calls" "zfs $LS cache/sh" "$(cat "$T/zfs.calls")"
-if [ "${AGE_MOVER_DEBUG:-0}" = 2 ]; then
- sed -n "/^cat >\"\$ANONAWK\" <<'ANONEOF'\$/,/^ANONEOF\$/p" "$PLUGIN/debug_mover" | sed '1d;$d' >"$T/anon.awk"
- anon=$(gawk -v POOLS='user user0 cache' -v SHARES=sh -v LIST=0 -f "$T/anon.awk" "$MOVER_DEBUG_LOG")
- check "debug_mover mangles the whole name" 'could lose "/mnt/cache/sh/-----------.pdf"' "$(grep -o 'could lose .*' <<<"$anon")"
-fi
-
-# a folder row that empties the share notes its dataset as a file row does, with Clean empty folders on only
-for clean in topFolder no; do
- begin "Clean ZFS datasets, Clean empty folders $clean, a folder row empties the share" cleanFolders $clean cleanDatasets yes
- mkdir -p /mnt/cache/sh/new
- printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
- row 'move from primary' d sh/new | list
- run_moves
- array_is sh sh/new
- if [ $clean = no ]; then calls=; else calls=$(printf 'zfs %s cache/sh\n' "$LS" unmount destroy); fi
- check "zfs calls" "$calls" "$(cat "$T/zfs.calls" 2>/dev/null)"
- if [ $clean = no ]; then cache_is sh; else cache_is; fi
-done
-
-for has in 'a snapshot' 'another name'; do
- begin "Clean ZFS datasets, the share's dataset has $has" cleanFolders topFolder cleanDatasets yes
- mk cache sh/only/f.txt
- row 'move from primary' f sh/only/f.txt | list
- if [ "$has" = 'a snapshot' ]; then
- printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
- echo cache/sh@daily >"$T/zfs.children"
- # as snapdir=visible shows it: the content check skips .zfs, so the snapshot is what keeps the dataset
- mk cache sh/.zfs/snapshot/daily/f.txt
- run_moves
- check "zfs calls" "zfs $LS cache/sh" "$(cat "$T/zfs.calls")"
- log_has 'ZFS dataset [cache/sh] has child datasets or snapshots, will not delete...'
- cache_is sh sh/.zfs sh/.zfs/snapshot sh/.zfs/snapshot/daily sh/.zfs/snapshot/daily/f.txt
- else
- # only dataset pool/share at /mnt/pool/share is destroyed; another dataset mounted there is kept
- printf '/mnt/cache\n/mnt/cache/sh\tcache/data/sh\n' >"$T/zfs"
- run_moves
- check "no zfs calls" "" "$(cat "$T/zfs.calls" 2>/dev/null)"
- log_lacks 'ZFS dataset ['
- cache_is sh
- [ "${AGE_MOVER_DEBUG:-0}" != 2 ] || dlog_has 'Keeping the ZFS dataset mounted at "/mnt/cache/sh": it is not cache/sh'
- fi
-done
-
-# once per share, after the pass, and only for rows that emptied a folder on the primary
-begin "Clean ZFS datasets, a pass empties two folders of a share that keeps a file" cleanFolders topFolder cleanDatasets yes
-mk cache sh/a/f.txt sh/b/g.txt sh/keep/k.txt
-printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
-{ row 'move from primary' f sh/a/f.txt; row 'move from primary' f sh/b/g.txt; } | list
-run_moves
-check "zfs calls" "zfs $LS cache/sh" "$(cat "$T/zfs.calls")"
-cache_is sh sh/keep sh/keep/k.txt
-
-begin "Clean ZFS datasets, a .placeholder keeps the folder after a row that emptied another share's" cleanFolders topFolder cleanDatasets yes
-mk cache a/x/f.txt sh/y/g.txt sh/y/.placeholder
-printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
-{ row 'move from primary' f a/x/f.txt; row 'move from primary' f sh/y/g.txt; } | list
-run_moves
-check "no zfs calls" "" "$(cat "$T/zfs.calls" 2>/dev/null)"
-cache_is sh sh/y sh/y/.placeholder
-
-begin "Clean ZFS datasets, a move from the secondary empties its folder on the array" cleanFolders topFolder cleanDatasets yes
-mk disk1 sh/only/f.txt
-printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
-row 'move from secondary' f sh/only/f.txt | list
-run_moves
-check "no zfs calls" "" "$(cat "$T/zfs.calls" 2>/dev/null)"
-cache_is sh sh/only sh/only/f.txt
-
-# test mode never destroys a dataset, even when the row's folder counts empty: here its file is gone before the run
-begin "Clean ZFS datasets in test mode, the row's file gone before the run" cleanFolders topFolder cleanDatasets yes testmode yes
-mk cache sh/f.txt
-printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
-row 'move from primary' f sh/f.txt | list
-rm /mnt/cache/sh/f.txt
-run_moves
-check "no zfs calls" "" "$(cat "$T/zfs.calls" 2>/dev/null)"
-cache_is sh
-log_has 'TEST MODE: Would delete empty top-level folder: /mnt/cache/sh'
-
-for pool in 'not ZFS' 'ZFS, the share a plain folder on it'; do
- begin "Clean ZFS datasets, a share that empties on a pool that is $pool" cleanFolders topFolder cleanDatasets yes
- mk cache sh/only/f.txt
- [ "$pool" = 'not ZFS' ] || echo /mnt/cache >"$T/zfs"
- row 'move from primary' f sh/only/f.txt | list
- run_moves
- check "no zfs calls" "" "$(cat "$T/zfs.calls" 2>/dev/null)"
- cache_is
- log_has 'Deleted empty top-level folder: /mnt/cache/sh'
- [ "${AGE_MOVER_DEBUG:-0}" != 2 ] || dlog_lacks 'Keeping'
-done
-
-for fail in list unmount destroy 'destroy and mount' 'destroy, busy,'; do
- begin "Clean ZFS datasets, zfs $fail fails" cleanFolders topFolder cleanDatasets yes notify no
- mk cache sh/only/f.txt
- printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
- case $fail in
- 'destroy and mount') printf '%s\n' destroy mount ;;
- *busy*) echo destroy; echo 'dataset is busy' >"$T/zfs.reason" ;;
- *) echo "$fail" ;;
- esac >"$T/zfs.fail"
- row 'move from primary' f sh/only/f.txt | list
- # age_mover's stderr is discarded in use, so zfs's reason goes to the log, without the child zfs names after it
- run_moves
- case $fail in
- list) log_has "ZFS dataset [cache/sh] could not be listed, will not delete: zfs.fail" ;;
- # the failure notice goes out with the "Failed to" line
- *busy*)
- log_has "ZFS dataset [cache/sh] is busy, will not delete: another mount, such as a container's, may hold it."
- log_lacks 'Failed to destroy'
- ;;
- *) log_has "Failed to ${fail%% *} ZFS dataset [cache/sh]"; log_has 'zfs: zfs.fail' ;;
- esac
- log_lacks 'cache/sh/child'
- array_is sh sh/only sh/only/f.txt
- # the row still logs and counts what it moved
- log_has '0 files remaining from caches to array'
- counter REMAINING_CACHE_FILES 0
- if [ "$fail" = 'destroy and mount' ]; then
- log_has 'Failed to remount dataset [cache/sh]'
- log_count 2 'zfs: zfs.fail'
- continue
- fi
- # the dataset is mounted at the end, so its top folder stays
- cache_is sh
- log_lacks 'Failed to remount'
- log_has 'Skipping deletion of ZFS dataset mountpoint: /mnt/cache/sh'
-done
-
id tester >/dev/null 2>&1 || useradd -M tester
U=/tmp/age_mover_tester
for keep in no yes; do
@@ -402,18 +201,4 @@ for keep in no yes; do
if [ "$keep" = yes ]; then cache_is sh sh/stay.txt; else cache_is; fi
done
-# a find that fails keeps the dataset: the file the plain user cannot see would go with it
-begin "Clean ZFS datasets, a subfolder a plain-user mover cannot list" cleanFolders topFolder cleanDatasets yes
-mk cache sh/only/f.txt sh/locked/k.txt
-rm -rf "$U" && mkdir -p "$U"
-printf '%s\n' /mnt/cache /mnt/cache/sh >"$U/zfs"
-row 'move from primary' f sh/only/f.txt | { echo "$HDR"; cat; } >"$U/actions"
-chown -R tester /mnt/cache /mnt/user0 "$U"
-chmod 0333 /mnt/cache/sh/locked
-runuser -u tester -- env AGE_MOVER_TEST=1 AGE_MOVER_DEBUG="${AGE_MOVER_DEBUG:-0}" T="$U" bash "$0" --as-tester "$CASE" dataset
-check "the checks run as the plain user pass" 0 "$?"
-check "zfs calls" "zfs $LS cache/sh" "$(cat "$U/zfs.calls" 2>/dev/null)"
-[ ! -d /mnt/cache/sh/locked ] || chmod 0755 /mnt/cache/sh/locked
-cache_is sh sh/locked sh/locked/k.txt
-
finish
From 227b88bf7a4060fc8820c5000dc0cff4dba95311 Mon Sep 17 00:00:00 2001
From: David Coppit
Date: Sun, 22 Nov 2026 10:57:09 -0500
Subject: [PATCH 27/94] perf: make logging cheap, and free when it is off
Every debug block cost about 9 ms even with debug logging off:
mvDebuglogger built its block before checking DEBUGLEVEL, and each
block drew two title lines through printf | tr pipelines in subshells.
mvlogger also forked date for every line.
- mvDebuglogger returns first thing when debug logging is off.
- titleLine pads in bash alone (titleLineTo sets a variable, so the
debug block needs no subshell).
- timestamped prints a message after the time, formatted from
$EPOCHREALTIME with printf %()T instead of forking date. Each output
still takes its own timestamp, as before.
- Debug lines in the per-file path whose messages need a subshell, such
as qp for every rsync argument, are built only when debug logging is on.
Log and debug output is byte-for-byte unchanged.
Measured on a recreated 371,820-file tree, moving the first 1,500 rows of
a real action list from cache to /mnt/user0 with rsync, on top of #284
and #286. Time per file:
before after
logging and debug on 118.7 ms 88.7 ms (8.42 -> 11.27 files/s, +34%)
logging and debug off 115.2 ms 81.9 ms (8.68 -> 12.22 files/s, +41%)
Profiling the same runs (bash xtrace, which inflates shell code a little)
attributes this much of each file's time to logging, including building
the messages:
before after
logging and debug on 44.5 ms 12.4 ms
logging and debug off 41.1 ms 4.0 ms
Turning logging off saved only 3.5 ms per file before this change. What
remains with it off is messages built at call sites before mvlogger runs
(qp subshells, and numfmt for the remaining-size line).
The saving per file is the same without #284 and #286, but it is a smaller
share there, because those spend more time per file on top-folder scans
and action-list lookups.
Co-Authored-By: Claude Opus 5.5
---
.../emhttp/plugins/ca.mover.tuning/age_mover | 66 ++++++++++++-------
1 file changed, 41 insertions(+), 25 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index 390bf5f1..cbe05b7a 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -305,16 +305,29 @@ zfs_busy() {
mvlogger "ZFS dataset [$1] is busy, will not delete: a process or another mount, such as a container's, may hold it."
}
-titleLine() {
- local title="$1"
- local padding_char="$2"
- local line_length=71
+# titleLineTo VAR TITLE CHAR: sets VAR to TITLE centred in CHAR padding, in bash alone. The printf | tr
+# pipelines it replaces forked four processes per line, and every debug block draws two lines.
+titleLineTo() {
+ local title="$2" padding_char="$3" line_length=71 left_padding right_padding
local padding_left=$((line_length - ${#title} / 2))
local padding_right=$((padding_left - ${#title} % 2 - 1))
- local left_padding right_padding
- left_padding=$(printf "%*s" "$padding_left" "" | tr ' ' "$padding_char")
- right_padding=$(printf "%*s" "$padding_right" "" | tr ' ' "$padding_char")
- echo "${left_padding}$padding_char $title $padding_char${right_padding}"
+ # a negative width pads on the left, as printf | tr did
+ printf -v left_padding '%*s' "$padding_left" ""
+ printf -v right_padding '%*s' "$padding_right" ""
+ # the quoted replacement keeps a padding character such as & literal
+ printf -v "$1" '%s%s %s %s%s' "${left_padding// /"$padding_char"}" "$padding_char" "$title" "$padding_char" "${right_padding// /"$padding_char"}"
+}
+
+titleLine() {
+ local line
+ titleLineTo line "$1" "$2"
+ echo "$line"
+}
+
+# Prints MESSAGE after the current time as date +"%T.%3N" prints it, without forking date
+timestamped() {
+ local now=$EPOCHREALTIME
+ printf '%(%T)T.%.3s %s\n' "${now%[.,]*}" "${now#*[.,]}" "$1"
}
# Function to convert byte size to human-readable format
@@ -428,16 +441,16 @@ mvlogger() {
echo "$msg"
else
# CLI or BUTTON → echo + logger
- echo "$(date +"%T.%3N") $msg"
+ timestamped "$msg"
logger -t move -- "$msg"
fi
# Always append to mover log
- echo "$(date +"%T.%3N") $msg" >>"$MOVER_LOG"
+ timestamped "$msg" >>"$MOVER_LOG"
elif [ "$LOGLEVEL" = 2 ]; then
# Files-only mode
- echo "$(date +"%T.%3N") $msg" >>"$MOVER_LOG"
+ timestamped "$msg" >>"$MOVER_LOG"
fi
# Optional notification
@@ -455,10 +468,14 @@ mvlogger() {
# IS_CRON=0 → CLI or GUI button (echo + logger)
#
# DEBUGLEVEL:
+# 0 → nothing, and nothing is built
# 1 → echo + debug log
# 2 → debug log only
#
+# Arguments are expanded before the call, so a call site whose message needs a subshell
+# (such as $(qp ...)) on every file should test DEBUGLEVEL itself.
mvDebuglogger() {
+ [ "$DEBUGLEVEL" = 1 ] || [ "$DEBUGLEVEL" = 2 ] || return 0
local msg="$1"
local tag="$2"
@@ -468,13 +485,10 @@ mvDebuglogger() {
fi
# Build formatted debug block
- local block
- block="$(
- printf '%s\n%s\n%s\n' \
- "$(titleLine "Debugging $tag" '-')" \
- "$(date +"%T.%3N") $msg" \
- "$(titleLine " " ' ')"
- )"
+ local block title_line blank_line now=$EPOCHREALTIME
+ titleLineTo title_line "Debugging $tag" '-'
+ titleLineTo blank_line " " ' '
+ printf -v block '%s\n%(%T)T.%.3s %s\n%s' "$title_line" "${now%[.,]*}" "${now#*[.,]}" "$msg" "$blank_line"
if [ "$DEBUGLEVEL" = 1 ]; then
@@ -2835,7 +2849,7 @@ processTheMoves() {
if [ "$TESTMODE" = "yes" ]; then
mvlogger "TEST MODE: Would move using Unraid move utility"
else
- mvDebuglogger "Move cmd: move, Move $filetype: $SYNCED_FILES, Dest: $(qp "$DESTINATION/")" "Move Action"
+ [ "$DEBUGLEVEL" != 0 ] && mvDebuglogger "Move cmd: move, Move $filetype: $SYNCED_FILES, Dest: $(qp "$DESTINATION/")" "Move Action"
# Unraid move keeps hardlinks only among names given in one run and skips the file otherwise;
# a folder row sends only the folder, which move leaves on the source while anything is in it
MOVE_DEBUG_ARGS=()
@@ -2851,9 +2865,11 @@ processTheMoves() {
else
# one quoted token per argv element, like SYNCED_FILES above: [*] joins the
# paths with spaces, and the anonymiser cannot tell where one ends
- RSYNC_CMD_LOG=""
- for a in "${RSYNC_CMD[@]}"; do RSYNC_CMD_LOG+="$(qp "$a") "; done
- mvDebuglogger "Rsync cmd: $RSYNC_CMD_LOG, $rsync_action $filetype: $SYNCED_FILES, Dest: $(qp "$DESTINATION/")" "$rsync_action Action"
+ if [ "$DEBUGLEVEL" != 0 ]; then
+ RSYNC_CMD_LOG=""
+ for a in "${RSYNC_CMD[@]}"; do RSYNC_CMD_LOG+="$(qp "$a") "; done
+ mvDebuglogger "Rsync cmd: $RSYNC_CMD_LOG, $rsync_action $filetype: $SYNCED_FILES, Dest: $(qp "$DESTINATION/")" "$rsync_action Action"
+ fi
# Perform rsync. relative paths and hardlinks
if [ ${#SYNCED_FILES_ARR[@]} -gt 0 ]; then
if [ ${#present[@]} -gt 0 ]; then
@@ -2946,7 +2962,7 @@ processTheMoves() {
# Collapse the rsync --relative marker ("/./" -> "/")
FILE="${FILE//\/.\//\/}"
DIR=$(dirname "$FILE")
- mvDebuglogger "Current file: $(qp "$FILE"), Current folder: $(qp "$DIR"), Previous folder: $(qp "$LAST_DIR"), Previous count: $LAST_COUNT" "Clean Folder - Start Loop"
+ [ "$DEBUGLEVEL" != 0 ] && mvDebuglogger "Current file: $(qp "$FILE"), Current folder: $(qp "$DIR"), Previous folder: $(qp "$LAST_DIR"), Previous count: $LAST_COUNT" "Clean Folder - Start Loop"
if [ -e "${DIR}/.placeholder" ]; then
count=".placeholder"
@@ -3003,9 +3019,9 @@ processTheMoves() {
if [ ! -d "$START_DIR" ]; then
START_DIR="$(dirname "${START_DIR}")"
if [ -d "$START_DIR" ]; then
- mvDebuglogger "Skipping cleanup: $(qp "$START_DIR") no longer exists, using upper folder: $(qp "$(dirname "${START_DIR}")")" "Clean Empty Moved Folder"
+ [ "$DEBUGLEVEL" != 0 ] && mvDebuglogger "Skipping cleanup: $(qp "$START_DIR") no longer exists, using upper folder: $(qp "$(dirname "${START_DIR}")")" "Clean Empty Moved Folder"
else
- mvDebuglogger "Skipping cleanup: $(qp "$START_DIR") no longer exists" "Clean Empty Moved Folder"
+ [ "$DEBUGLEVEL" != 0 ] && mvDebuglogger "Skipping cleanup: $(qp "$START_DIR") no longer exists" "Clean Empty Moved Folder"
continue
fi
fi
From 3b75b3b93e86ebce56dc3f7687d39b7bf8aba1bc Mon Sep 17 00:00:00 2001
From: David Coppit
Date: Sun, 22 Nov 2026 13:16:37 -0500
Subject: [PATCH 28/94] perf: quote message lists without a subshell per item
The SYNCED_FILES display string and the rsync debug line quoted each
item with $(qp ...), a subshell per item. qpAll applies qp's escapes to
the whole list at once with array pattern substitution, then quotes and
joins it with one printf -v, so a list costs no subshells. The output is
unchanged, including for an empty list; a comparison with the old loop
over 208 lists, among them random binary strings, found no difference.
The SYNCED_FILES loop runs on every row whether or not logging is on.
Same benchmark as the previous commit (first 1,500 rows, on top of #284
and #286), time per file and the logging share of it:
before after this commit
logging and debug on 88.7 ms 85.3 ms (logging 12.4 -> 7.2 ms)
logging and debug off 81.9 ms 80.8 ms (logging 4.0 -> 3.2 ms)
Co-Authored-By: Claude Opus 5.5
---
.../emhttp/plugins/ca.mover.tuning/age_mover | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index cbe05b7a..7dfb21ad 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -396,6 +396,16 @@ escape_find_path() {
# embedded quote - an edge case, but the last redaction hole - would expose the rest.
qp() { local p=${1//\\/\\\\}; printf '"%s"' "${p//\"/\\\"}"; }
+# qpAll VAR ITEM...: sets VAR to each ITEM as qp quotes it, each followed by a space. The escapes
+# apply to every item at once, so a list costs no subshell per item.
+qpAll() {
+ local -a items=("${@:2}")
+ items=("${items[@]//\\/\\\\}")
+ items=("${items[@]//\"/\\\"}")
+ # printf with no arguments would still print the format once
+ if [ ${#items[@]} -gt 0 ]; then printf -v "$1" '"%s" ' "${items[@]}"; else printf -v "$1" ''; fi
+}
+
# Fills each %s in TEXT from the remaining arguments; an inserted argument is never rescanned.
fill_template() {
local text="$1" out="" arg
@@ -2769,9 +2779,7 @@ processTheMoves() {
# SYNCED_FILES is a display/count string only, derived from the array so
# the extraction pipeline above runs only once per file.
- SYNCED_FILES=""
- SYNCED_FILES=""
- for f in "${SYNCED_FILES_ARR[@]}"; do SYNCED_FILES+="$(qp "$f") "; done
+ qpAll SYNCED_FILES "${SYNCED_FILES_ARR[@]}"
GUI_CURRENT_FILE="$SOURCE/$FILEPATH"
# Check if list is complete (array length is exact, unlike parsing the string)
@@ -2866,8 +2874,7 @@ processTheMoves() {
# one quoted token per argv element, like SYNCED_FILES above: [*] joins the
# paths with spaces, and the anonymiser cannot tell where one ends
if [ "$DEBUGLEVEL" != 0 ]; then
- RSYNC_CMD_LOG=""
- for a in "${RSYNC_CMD[@]}"; do RSYNC_CMD_LOG+="$(qp "$a") "; done
+ qpAll RSYNC_CMD_LOG "${RSYNC_CMD[@]}"
mvDebuglogger "Rsync cmd: $RSYNC_CMD_LOG, $rsync_action $filetype: $SYNCED_FILES, Dest: $(qp "$DESTINATION/")" "$rsync_action Action"
fi
# Perform rsync. relative paths and hardlinks
From 6dac7a7be156402aaecde9db45a4bddad1ac6709 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 06:25:52 +0800
Subject: [PATCH 29/94] qp goes through qpAll, so the escapes have one owner;
pin the backslash escape
- qp is qpAll of one item without the trailing space.
- test_moves.sh: a backslash name joins the special-names case; nothing pinned that escape before.
- titleLineTo: a negative width pads by its size (printf left-justifies), not on the left.
---
.../usr/local/emhttp/plugins/ca.mover.tuning/age_mover | 8 ++++----
tests/age_mover/test_moves.sh | 9 +++++----
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index 7dfb21ad..d30f4a54 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -311,7 +311,7 @@ titleLineTo() {
local title="$2" padding_char="$3" line_length=71 left_padding right_padding
local padding_left=$((line_length - ${#title} / 2))
local padding_right=$((padding_left - ${#title} % 2 - 1))
- # a negative width pads on the left, as printf | tr did
+ # a negative width still pads by its size (printf left-justifies the empty string), as printf | tr did
printf -v left_padding '%*s' "$padding_left" ""
printf -v right_padding '%*s' "$padding_right" ""
# the quoted replacement keeps a padding character such as & literal
@@ -394,10 +394,10 @@ escape_find_path() {
#
# Wraps a path for a log message: the debug package ends a path at the quote, so an
# embedded quote - an edge case, but the last redaction hole - would expose the rest.
-qp() { local p=${1//\\/\\\\}; printf '"%s"' "${p//\"/\\\"}"; }
+qp() { local q; qpAll q "$1"; printf '%s' "${q% }"; }
-# qpAll VAR ITEM...: sets VAR to each ITEM as qp quotes it, each followed by a space. The escapes
-# apply to every item at once, so a list costs no subshell per item.
+# qpAll VAR ITEM...: sets VAR to each ITEM quoted for qp, each followed by a space. It owns the escapes,
+# which apply to every item at once, so a list costs no subshell per item.
qpAll() {
local -a items=("${@:2}")
items=("${items[@]//\\/\\\\}")
diff --git a/tests/age_mover/test_moves.sh b/tests/age_mover/test_moves.sh
index 5e74580d..1836f50b 100644
--- a/tests/age_mover/test_moves.sh
+++ b/tests/age_mover/test_moves.sh
@@ -3,20 +3,21 @@
. "$(dirname "$0")/lib.sh"
for tool in rsync move; do
- begin "names with space, |, \$, quotes and Unicode ($tool)" movefilesTool "$tool"
- names=('sh/o/a b.txt' 'sh/o/p|ipe.txt' 'sh/o/trail|' 'sh/o/$HOME.txt' "sh/o/q\"uote's.txt" 'sh/o/ünï.txt')
+ begin "names with space, |, \$, quotes, a backslash and Unicode ($tool)" movefilesTool "$tool"
+ names=('sh/o/a b.txt' 'sh/o/p|ipe.txt' 'sh/o/trail|' 'sh/o/$HOME.txt' "sh/o/q\"uote's.txt" 'sh/o/back\slash.txt' 'sh/o/ünï.txt')
mk cache "${names[@]}"
for n in "${names[@]}"; do row 'move from primary' f "$n"; done | list
run_moves
array_is sh sh/o "${names[@]}"
cache_is sh sh/o
- counter MOVEDFILES 6
+ counter MOVEDFILES 7
counter REMAINING_CACHE_FILES 0
- counter MOVEDSIZE 12
+ counter MOVEDSIZE 14
check "debug blocks written only with AGE_MOVER_DEBUG=2" "$([ "${AGE_MOVER_DEBUG:-0}" = 2 ] && echo yes || echo no)" \
"$(grep -qF Debugging "$MOVER_DEBUG_LOG" && echo yes || echo no)"
log_has 'Moving "/mnt/cache/./sh/o/trail|" to "/mnt/user0/"'
log_has "Moving \"/mnt/cache/./sh/o/q\\\"uote's.txt\" to \"/mnt/user0/\""
+ log_has 'Moving "/mnt/cache/./sh/o/back\\slash.txt" to "/mnt/user0/"'
begin "hardlink group, every name listed ($tool)" movefilesTool "$tool"
mk cache sh/h/a.txt
From b1a83f2cd001b1d21acd0f228f891f386b9edc46 Mon Sep 17 00:00:00 2001
From: David Coppit
Date: Sat, 21 Nov 2026 21:25:17 -0500
Subject: [PATCH 30/94] perf: use file leases for faster in-use checks
If "Move files that are in use" is set to "no", then before moving a file,
age_mover checks whether any process has it open. It used fuser, which scans
/proc for every process on the system. On a busy Unraid host (~1,600 processes,
dozens of containers) each call takes ~145 ms, so when moving small files the
check can cost more than the move itself.
The new files_in_use helper asks the kernel instead: Linux grants a write lease
(fcntl F_SETLEASE) only when no other descriptor for the file is open, which
takes microseconds. If the kernel or filesystem cannot grant leases, the helper
falls back to fuser (if fuser is available). It keeps fuser -s exit codes (0 in
use, 1 clear) and adds 2 to indicate that neither leases nor fuser is available.
The helper thus fully encapsulates the mechanism by which "in use" is
determined--leases or fuser.
Measured on Unraid 7.4 (host-PID test container with SYS_PTRACE, so fuser
behaves as on the host), 450 tiny files, three alternating runs each: ~220 ms
per file with fuser at 8b9cfed vs ~80 ms with leases, about 64% less elapsed
time and 2.75x throughput. Additional speedups can be had by making the helper a
persistent process, but for this initial change I wanted to keep things simple.
Bash cannot call fcntl(F_SETLEASE), so the helper is Perl. Perl joined
Unraid's base distribution in 6.11.0, so that is the new minimum version.
Implemented with Codex and Claude.
---
.github/scripts/test_files_in_use.sh | 150 ++++++++++++++++++
.github/workflows/ci.yml | 9 +-
README.md | 4 +-
plugins/ca.mover.tuning.plg | 6 +-
.../emhttp/plugins/ca.mover.tuning/age_mover | 35 ++--
.../plugins/ca.mover.tuning/files_in_use | 96 +++++++++++
6 files changed, 283 insertions(+), 17 deletions(-)
create mode 100644 .github/scripts/test_files_in_use.sh
create mode 100755 source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/files_in_use
diff --git a/.github/scripts/test_files_in_use.sh b/.github/scripts/test_files_in_use.sh
new file mode 100644
index 00000000..6ca34e24
--- /dev/null
+++ b/.github/scripts/test_files_in_use.sh
@@ -0,0 +1,150 @@
+#!/bin/bash
+set -euo pipefail
+
+ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)
+HELPER="$ROOT/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/files_in_use"
+MOVER="$ROOT/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover"
+TMP=$(mktemp -d)
+HOLDER=""
+
+cleanup() {
+ if [ -n "$HOLDER" ]; then
+ kill "$HOLDER" 2>/dev/null || true
+ wait "$HOLDER" 2>/dev/null || true
+ fi
+ rm -rf -- "$TMP"
+}
+trap cleanup EXIT
+
+expect_status() {
+ local expected=$1 actual
+ shift
+ set +e
+ perl "$HELPER" "$@"
+ actual=$?
+ set -e
+ if [ "$actual" -ne "$expected" ]; then
+ echo "expected status $expected, got $actual" >&2
+ return 1
+ fi
+}
+
+hold_file() {
+ local mode=$1 file=$2 ready="$TMP/ready"
+ rm -f -- "$ready"
+ if [ "$mode" = read ]; then
+ ( exec 9<"$file"; : >"$ready"; sleep 30 ) &
+ else
+ ( exec 9<>"$file"; : >"$ready"; sleep 30 ) &
+ fi
+ HOLDER=$!
+ for _ in {1..100}; do
+ [ -e "$ready" ] && return
+ sleep 0.01
+ done
+ echo "holder did not start" >&2
+ return 1
+}
+
+release_holder() {
+ kill "$HOLDER" 2>/dev/null || true
+ wait "$HOLDER" 2>/dev/null || true
+ HOLDER=""
+}
+
+plain="$TMP/plain"
+space="$TMP/a space [*] \$(name)"
+newline="$TMP/line
+break"
+leading="$TMP/--leading"
+printf x >"$plain"
+printf x >"$space"
+printf x >"$newline"
+printf x >"$leading"
+
+perl -c "$HELPER"
+
+# F_SETLEASE and fuser -s are Linux interfaces. macOS development machines can
+# still validate syntax and the intentionally small age_mover integration.
+if [ "$(uname -s)" != Linux ]; then
+ grep -q '"$FILES_IN_USE_HELPER" "$@"' "$MOVER"
+ ! grep -qE 'FILE_IN_USE_MODE|FILE_IN_USE_CHECK|FUSER_BATCH_SAFE|actionRows' "$MOVER"
+ ! grep -qE 'coproc|--server|fileLease(Start|Stop|Request)' "$MOVER"
+ echo "file lease Linux tests skipped on $(uname -s)"
+ exit
+fi
+
+expect_status 1 "$plain" "$space" "$newline" "$leading"
+expect_status 1 "$TMP/vanished"
+
+hold_file read "$plain"
+expect_status 0 "$plain"
+release_holder
+expect_status 1 "$plain"
+
+hold_file write "$plain"
+expect_status 0 "$plain"
+release_holder
+
+alias="$TMP/hardlink"
+ln "$plain" "$alias"
+hold_file read "$alias"
+expect_status 0 "$plain" "$alias"
+release_holder
+
+# A device cannot be leased. A distinctive fake fuser status proves that the
+# one-shot helper immediately replaces itself with the compatibility command.
+mkdir "$TMP/bin"
+printf '#!/bin/sh\nexit 7\n' >"$TMP/bin/fuser"
+chmod +x "$TMP/bin/fuser"
+set +e
+PATH="$TMP/bin:$PATH" perl "$HELPER" /dev/null
+fallback_status=$?
+set -e
+[ "$fallback_status" -eq 7 ]
+
+# If leases cannot answer and fuser cannot be executed, status 2 tells
+# age_mover not to mistake the file for clear.
+mkdir "$TMP/empty-bin"
+set +e
+PATH="$TMP/empty-bin" "$(command -v perl)" "$HELPER" /dev/null 2>/dev/null
+uncheckable_status=$?
+set -e
+[ "$uncheckable_status" -eq 2 ]
+
+# Keep age_mover's integration deliberately small: it knows only the helper's
+# result contract, not whether a lease or fuser produced the answer.
+grep -q '"$FILES_IN_USE_HELPER" "$@"' "$MOVER"
+! grep -qE 'FILE_IN_USE_MODE|FILE_IN_USE_CHECK|FUSER_BATCH_SAFE|actionRows' "$MOVER"
+! grep -qE 'coproc|--server|fileLease(Start|Stop|Request)' "$MOVER"
+
+# age_mover treats an unavailable answer as in-use, and reports it only once.
+source <(sed -n '/^filesInUse() {/,/^}/p' "$MOVER")
+fake_helper="$TMP/fake-helper"
+printf '#!/bin/sh\nexit "$CHECK_STATUS"\n' >"$fake_helper"
+chmod +x "$fake_helper"
+FILES_IN_USE_HELPER=$fake_helper
+LOG_COUNT=0
+mvlogger() { LOG_COUNT=$((LOG_COUNT + 1)); }
+# Stands in for processTheMoves, which owns the once-per-run flag as a local.
+mover_run() {
+ local FILE_IN_USE_FAILURE_LOGGED=no
+ export CHECK_STATUS=0
+ filesInUse "$plain"
+ export CHECK_STATUS=1
+ if filesInUse "$plain"; then
+ echo "clear helper result was reported in use" >&2
+ exit 1
+ fi
+ export CHECK_STATUS=2
+ filesInUse "$plain"
+ filesInUse "$plain"
+}
+mover_run
+[ "$LOG_COUNT" -eq 1 ]
+# The next run warns again, and the flag does not leak out of the run.
+mover_run
+[ "$LOG_COUNT" -eq 2 ]
+[ -z "${FILE_IN_USE_FAILURE_LOGGED+set}" ]
+
+echo "file lease tests passed"
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 53140281..5d28dbbb 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -19,12 +19,17 @@ jobs:
with:
persist-credentials: false
- - name: Install xmllint
- run: sudo apt-get update -qq && sudo apt-get install -y -qq libxml2-utils
+ - name: Install test tools
+ run: sudo apt-get update -qq && sudo apt-get install -y -qq libxml2-utils perl
- name: Validate plugin manifest (XML)
run: xmllint --noout plugins/ca.mover.tuning.plg
+ - name: Test mover file leases
+ run: |
+ bash -n source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+ bash .github/scripts/test_files_in_use.sh
+
# CHANGELOG.md must render to the committed CHANGES block for this branch's channel,
# pluginURL must point at this branch, and the manifest md5 must match the served package.
- name: Verify changelog, manifest and served package agree
diff --git a/README.md b/README.md
index 1ae045d5..6c186ab2 100644
--- a/README.md
+++ b/README.md
@@ -17,7 +17,7 @@ This is an [Unraid](https://unraid.net/) plugin that lets you fine-tune the oper
This fork merges all [pull requests](https://github.com/R3yn4ld/ca.mover.tuning/pulls) from [R3yn4ld](https://github.com/R3yn4ld/ca.mover.tuning) after review (cosmetics, per-share skipfiletypes merge, automatic age threshold, Unraid 7.x compatibility) and adds many new features. See [CHANGELOG.md](CHANGELOG.md) for the full history.
-**Requires Unraid 6.9.0-rc2 or newer.** Unraid 7.2.1+ and the 7.4 rc1 are supported (see [Unraid 7.2.1 and newer](#unraid-721-and-newer)).
+**Requires Unraid 6.11.0 or newer.** Perl is part of Unraid's base distribution starting with 6.11.0 and is used to call Linux's `fcntl(F_SETLEASE)` interface; Bash cannot issue that system call directly. Unraid 7.2.1+ and the 7.4 rc1 are supported (see [Unraid 7.2.1 and newer](#unraid-721-and-newer)).
> **Tip:** click on any option or press **F1** on the settings page to read a detailed description of all settings.
@@ -82,7 +82,7 @@ Please note that if the age setting is set to something other than "Auto (smart
Files at the top level of the cache or an array disk (i.e. not in a share) are never moved.
The list is then passed to the original Unraid mover.
-For each file, if the file is not "in use" by any process (as detected by the 'fuser' command), then the file is moved and, upon success, deleted from the source disk. If the file already exists on the target, it is not moved and the source is not deleted. All metadata of moved files/directories is preserved: permissions, ownership, extended attributes, and access/modified timestamps.
+For each file, if the file is not "in use" by any process (as detected by an exclusive Linux file lease, with `fuser` as a compatibility fallback when leases are unavailable), then the file is moved and, upon success, deleted from the source disk. If the file already exists on the target, it is not moved and the source is not deleted. All metadata of moved files/directories is preserved: permissions, ownership, extended attributes, and access/modified timestamps.
If an error occurs while copying a file, the partial file, if present, is deleted and the operation continues on to the next file.
## Changelog
diff --git a/plugins/ca.mover.tuning.plg b/plugins/ca.mover.tuning.plg
index d1376a7f..5dbfc3df 100644
--- a/plugins/ca.mover.tuning.plg
+++ b/plugins/ca.mover.tuning.plg
@@ -11,7 +11,7 @@
]>
-
+
###2026.11.13
@@ -703,11 +703,11 @@
$displayversion = $version['version'];
echo "Unraid v$displayversion \n";
- if ( version_compare($version['version'],"6.9.0-rc2", "<") )
+ if ( version_compare($version['version'],"6.11.0", "<") )
{
echo "********************************************************************\n";
echo "\n";
- echo "CA Mover Tuning Requires unRaid version 6.9.0-rc2 or greater to run\n";
+ echo "CA Mover Tuning Requires unRaid version 6.11.0 or greater to run\n";
echo "\n";
echo "********************************************************************\n";
exit(1);
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index d30f4a54..931daad8 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -28,7 +28,8 @@
# Files at the top level of the cache or an array disk (i.e not in a share) are never moved.
# The list is then passed to original unraid mover.
-# For each file, if the file is not "in use" by any process (as detected by 'fuser' command),
+# For each file, if the file is not "in use" by any process (as detected by an exclusive file lease,
+# with fuser as a compatibility fallback),
# then the file is moved, and upon success, deleted from the source disk. If the file already
# exists on the target, it is not moved and the sourceis not deleted. All meta-data of moved
# files/directories is preserved: permissions, ownership, extended attributes, and access/modified
@@ -46,6 +47,7 @@ PAUSEFILE="/var/run/mover.pause"
MOVINGFILE="/var/run/mover.moving"
HOLD_SINCE=""
AGEMOVER="/usr/local/emhttp/plugins/ca.mover.tuning/age_mover"
+FILES_IN_USE_HELPER="/usr/local/emhttp/plugins/ca.mover.tuning/files_in_use"
SOFTSTOP_ACK=false
UNRAIDCFGFILE="/boot/config/share.cfg"
MOVERTUNINGCFGFILE="/boot/config/plugins/ca.mover.tuning/ca.mover.tuning.cfg"
@@ -2515,6 +2517,23 @@ move_tool_said() {
done <<<"$MOVE_OUT"
}
+# Returns success when at least one path is in use, or when no reliable answer is
+# available. The helper owns both the lease check and its fuser fallback.
+# FILE_IN_USE_FAILURE_LOGGED is a local of processTheMoves, so the warning appears at most once per run.
+filesInUse() {
+ local rc
+ if "$FILES_IN_USE_HELPER" "$@" 2>/dev/null; then rc=0; else rc=$?; fi
+ case "$rc" in
+ 0) return 0 ;;
+ 1) return 1 ;;
+ esac
+ if [ "$FILE_IN_USE_FAILURE_LOGGED" != yes ]; then
+ mvlogger "A file could not be checked with either a lease or fuser, so it stays where it is until a later run. Set 'Move files that are in use' to Yes to move such files anyway."
+ FILE_IN_USE_FAILURE_LOGGED=yes
+ fi
+ return 0
+}
+
# In topFolder mode, notes this row's share top folder for the check after the pass; fills processTheMoves' TOP_SEEN
# and TOP_FOLDERS
note_top_folder() {
@@ -2667,12 +2686,8 @@ processTheMoves() {
local -A DATASET_DEST=()
local -a SHARE_DATASETS=()
local top ds
- # without fuser an open file cannot be told apart, so none is moved while moveInUse is no
- local fuser_missing=0
- if [ "$MOVE_IN_USE" != "yes" ] && ! command -v fuser >/dev/null; then
- fuser_missing=1
- mvlogger "fuser not found: files stay where they are, since they cannot be checked for use. Set 'Move files that are in use' to Yes to move them anyway."
- fi
+ # set by filesInUse the first time a file cannot be checked
+ local FILE_IN_USE_FAILURE_LOGGED=no
# Dry mode info:
if [ "$TESTMODE" = "yes" ]; then
@@ -2790,9 +2805,9 @@ processTheMoves() {
continue
fi
- # an open name keeps its source copy alive, so moving it frees nothing: skip it like Unraid's move
- # (fuser takes no "--": with it, psmisc fuser reports an open file as not in use)
- if [ "$MOVE_IN_USE" != "yes" ] && [[ "$ACTION" =~ "move" && "$FILETYPE" = "f" ]] && [ "$NBFILES" -gt 0 ] && { [ "$fuser_missing" = 1 ] || fuser -s "${SYNCED_FILES_ARR[@]//\/.\//\/}" 2>/dev/null; }; then
+ # An open name keeps its source copy alive, so moving it frees nothing: skip it like Unraid's move.
+ # filesInUse takes an exclusive lease at this point, or uses fuser when leases are unavailable.
+ if [ "$MOVE_IN_USE" != "yes" ] && [[ "$ACTION" =~ "move" && "$FILETYPE" = "f" ]] && [ "$NBFILES" -gt 0 ] && filesInUse "${SYNCED_FILES_ARR[@]//\/.\//\/}"; then
mvlogger "In use, left for a later run: $SYNCED_FILES"
# a move from primary left in place was not synced either, so lastCacheSync must wait; a staged row leaves that to its sync row
if [ "$STAGE_ROW" = 1 ]; then STAGED_INUSE[$chain_key]=1; else INUSEFILES=$((INUSEFILES + NBFILES)); fi
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/files_in_use b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/files_in_use
new file mode 100755
index 00000000..d32a3693
--- /dev/null
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/files_in_use
@@ -0,0 +1,96 @@
+#!/usr/bin/perl
+# SPDX-License-Identifier: GPL-2.0-only
+# Copyright (C) 2026 Mover Tuning contributors
+#
+# files_in_use FILE...
+#
+# A faster stand-in for "fuser -s FILE...": answers whether any other process has one of the files
+# open, so age_mover can leave such files for a later run.
+#
+# Exit status (0 and 1 match fuser -s; 2 is specific to this tool):
+# 0 at least one file is in use
+# 1 no file is in use (files that have vanished count as not in use)
+# 2 no reliable answer: neither a lease nor fuser could check the files; the caller treats the
+# files as in use. (Once we exec fuser, its own exit status is returned, whatever it is.)
+#
+# Why not just run fuser?
+# fuser walks /proc for every process on the system. On a busy Unraid host (thousands of
+# processes, dozens of containers) that measured ~146 ms per call, which nearly doubled the time
+# to move many small files. Asking the kernel for a lease is a few microseconds.
+#
+# How the lease test works:
+# Linux grants a write lease (fcntl F_SETLEASE with F_WRLCK) only when the caller's descriptor is
+# the only open one for the file. So:
+# - lease granted -> nobody else has the file open -> not in use. We release the lease at
+# once; we never hold it.
+# - EAGAIN -> someone else has it open -> in use.
+# - any other error -> the kernel or filesystem cannot answer (for example leases are disabled,
+# or the filesystem does not support them, as with FUSE and network
+# filesystems) -> hand the whole question to fuser.
+# This needs Perl because Bash has no way to call fcntl(F_SETLEASE).
+#
+# EAGAIN and EWOULDBLOCK are the same value on Linux. Both are checked only for portability.
+# Neither is a transient "try again" here: each means "in use".
+use strict;
+use warnings;
+
+use Errno qw(EAGAIN EWOULDBLOCK ENOENT ENOTDIR);
+use Fcntl qw(O_NONBLOCK O_RDONLY F_UNLCK F_WRLCK);
+
+# Linux-specific fcntl command. The plugin package is x86_64-only, where F_SETLEASE is
+# F_LINUX_SPECIFIC_BASE + 0.
+use constant F_SETLEASE => 1024;
+# The kernel sends SIGIO to a lease holder when another process opens the file and so asks for the
+# lease to be broken. SIGIO kills the process by default. That can happen in the few instructions
+# between taking and releasing the lease, so ignore it. Closing the descriptor releases the lease
+# anyway.
+$SIG{IO} = 'IGNORE';
+
+@ARGV or die "Usage: $0 FILE...\n";
+
+# Hand every file to fuser, not just the rest, so its exit status answers for all of them. exec
+# only returns if fuser cannot be run, so exit 2 (no answer).
+sub fall_back_to_fuser {
+ exec 'fuser', '-s', @ARGV;
+ exit 2;
+}
+
+for my $path (@ARGV) {
+ my $file;
+ # Open read-only, so the check itself never changes the file. O_NONBLOCK matters if another
+ # process (Samba with oplocks, for example) already holds a lease on the file. A plain open
+ # would block until that lease is broken, which disturbs the holder. With O_NONBLOCK the open
+ # fails at once with EWOULDBLOCK, and someone holding a lease is in use.
+ if (!sysopen($file, $path, O_RDONLY | O_NONBLOCK)) {
+ my $error = 0 + $!;
+ # The file was removed or renamed since the move list was made, so nothing has it open.
+ # age_mover deals with the missing file itself.
+ next if $error == ENOENT || $error == ENOTDIR;
+ # Another process holds a lease on it: in use.
+ exit 0 if $error == EAGAIN || $error == EWOULDBLOCK;
+ # Any other failure to open (permissions, I/O error): let fuser try.
+ fall_back_to_fuser();
+ }
+
+ # The actual test: a write lease is refused with EAGAIN while any other descriptor for the file
+ # is open, in this process or any other.
+ if (!fcntl($file, F_SETLEASE, F_WRLCK)) {
+ my $error = 0 + $!;
+ close $file;
+ # Another process has the file open: in use.
+ exit 0 if $error == EAGAIN || $error == EWOULDBLOCK;
+ # Typically EINVAL: this filesystem or kernel does not support leases.
+ fall_back_to_fuser();
+ }
+
+ # We got the lease, so the file was not in use. Release it at once. If releasing fails,
+ # something unexpected is going on: don't trust our answer, let fuser decide.
+ if (!fcntl($file, F_SETLEASE, F_UNLCK)) {
+ close $file;
+ fall_back_to_fuser();
+ }
+ close $file;
+}
+
+# Every file was free (or gone). As with fuser -s, 1 means "not in use".
+exit 1;
From 41712e9c72305fc106beb6d15544d9715cad4dae Mon Sep 17 00:00:00 2001
From: David Coppit
Date: Sat, 21 Nov 2026 21:53:29 -0500
Subject: [PATCH 31/94] fix: don't break existing leases when checking files
Opening a file that another process holds a lease on (Samba with kernel
oplocks, for example) makes the kernel start breaking that lease and signal
the holder, even with O_NONBLOCK, which only skips the wait. files_in_use now
reads /proc/locks once and reports files with a lease as in use without
opening them. If /proc/locks cannot be read, it falls back to fuser, which
never opens the files it checks.
Reading /proc/locks adds ~0.3 ms per call with a typical few hundred locks; it
grows with the system's lock count (~10 ms at 10,000 locks).
Also silence ShellCheck's SC2034 for the test's FILES_IN_USE_HELPER, which
only the sourced filesInUse reads.
Co-Authored-By: Claude Opus 5.5
---
.github/scripts/test_files_in_use.sh | 32 +++++++++++++
.../plugins/ca.mover.tuning/files_in_use | 45 ++++++++++++++++---
2 files changed, 70 insertions(+), 7 deletions(-)
diff --git a/.github/scripts/test_files_in_use.sh b/.github/scripts/test_files_in_use.sh
index 6ca34e24..9ad57f94 100644
--- a/.github/scripts/test_files_in_use.sh
+++ b/.github/scripts/test_files_in_use.sh
@@ -92,6 +92,36 @@ hold_file read "$alias"
expect_status 0 "$plain" "$alias"
release_holder
+# A file that another process holds a lease on is in use, and checking it must not disturb that
+# lease: opening it would make the kernel signal the holder to give the lease up.
+leased="$TMP/leased"
+printf x >"$leased"
+rm -f -- "$TMP/ready" "$TMP/broken"
+perl -e '
+ use Fcntl qw(F_WRLCK);
+ my ($file, $ready, $broken) = @ARGV;
+ open(my $fh, "<", $file) or die "open: $!";
+ $SIG{IO} = sub { open(my $m, ">", $broken); close $m };
+ fcntl($fh, 1024, F_WRLCK) or die "lease: $!";
+ open(my $r, ">", $ready); close $r;
+ sleep 30;
+' "$leased" "$TMP/ready" "$TMP/broken" &
+HOLDER=$!
+for _ in {1..100}; do
+ [ -e "$TMP/ready" ] && break
+ sleep 0.01
+done
+[ -e "$TMP/ready" ] || { echo "lease holder did not start" >&2; exit 1; }
+grep -q LEASE /proc/locks
+expect_status 0 "$leased"
+expect_status 0 "$plain" "$leased"
+sleep 0.2
+if [ -e "$TMP/broken" ]; then
+ echo "checking a leased file broke its lease" >&2
+ exit 1
+fi
+release_holder
+
# A device cannot be leased. A distinctive fake fuser status proves that the
# one-shot helper immediately replaces itself with the compatibility command.
mkdir "$TMP/bin"
@@ -123,6 +153,8 @@ source <(sed -n '/^filesInUse() {/,/^}/p' "$MOVER")
fake_helper="$TMP/fake-helper"
printf '#!/bin/sh\nexit "$CHECK_STATUS"\n' >"$fake_helper"
chmod +x "$fake_helper"
+# Read by the sourced filesInUse, which ShellCheck cannot see.
+# shellcheck disable=SC2034
FILES_IN_USE_HELPER=$fake_helper
LOG_COUNT=0
mvlogger() { LOG_COUNT=$((LOG_COUNT + 1)); }
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/files_in_use b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/files_in_use
index d32a3693..0258a60c 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/files_in_use
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/files_in_use
@@ -29,6 +29,13 @@
# filesystems) -> hand the whole question to fuser.
# This needs Perl because Bash has no way to call fcntl(F_SETLEASE).
#
+# Files someone else already holds a lease on:
+# Opening such a file would disturb the holder (Samba with oplocks, for example). Linux starts
+# breaking the lease and signals the holder as part of the open, even with O_NONBLOCK, which
+# only skips the wait. So first look the file up in /proc/locks without opening it. A lease
+# holder has the file open, so a file with a lease is in use and is never opened. If /proc/locks
+# cannot be read, hand the whole question to fuser, which never opens the files it checks.
+#
# EAGAIN and EWOULDBLOCK are the same value on Linux. Both are checked only for portability.
# Neither is a transient "try again" here: each means "in use".
use strict;
@@ -55,18 +62,42 @@ sub fall_back_to_fuser {
exit 2;
}
+# Inode numbers of files that some process holds a lease (or NFS delegation) on, read once from
+# /proc/locks. Its lines look like "3: LEASE ACTIVE WRITE 1234 00:2d:5678 0 EOF", where
+# 00:2d:5678 is the filesystem's major:minor device and the inode. Only the inode is compared:
+# stat's device differs from that of /proc/locks on some filesystems (btrfs subvolumes, for
+# example). Two files with the same inode number on different filesystems can make a file look
+# in use, which only leaves it for a later run; missing a lease would break it.
+my %leased_inodes;
+open(my $locks, '<', '/proc/locks') or fall_back_to_fuser();
+while (my $line = <$locks>) {
+ next unless $line =~ /\b(?:LEASE|DELEG)\b/;
+ $leased_inodes{$1} = 1 if $line =~ /\s[0-9a-f]+:[0-9a-f]+:(\d+)\s/;
+}
+close $locks;
+
for my $path (@ARGV) {
- my $file;
- # Open read-only, so the check itself never changes the file. O_NONBLOCK matters if another
- # process (Samba with oplocks, for example) already holds a lease on the file. A plain open
- # would block until that lease is broken, which disturbs the holder. With O_NONBLOCK the open
- # fails at once with EWOULDBLOCK, and someone holding a lease is in use.
- if (!sysopen($file, $path, O_RDONLY | O_NONBLOCK)) {
+ # stat does not open the file, so it cannot disturb a lease holder.
+ my @stat = stat($path);
+ if (!@stat) {
my $error = 0 + $!;
# The file was removed or renamed since the move list was made, so nothing has it open.
# age_mover deals with the missing file itself.
next if $error == ENOENT || $error == ENOTDIR;
- # Another process holds a lease on it: in use.
+ fall_back_to_fuser();
+ }
+ # Someone holds a lease on it, so they have it open: in use. Don't open it.
+ exit 0 if $leased_inodes{$stat[1]};
+
+ my $file;
+ # Open read-only, so the check itself never changes the file. O_NONBLOCK covers a lease taken
+ # after /proc/locks was read: the open still disturbs that holder, but fails at once with
+ # EWOULDBLOCK instead of waiting for the lease to be given up.
+ if (!sysopen($file, $path, O_RDONLY | O_NONBLOCK)) {
+ my $error = 0 + $!;
+ # Removed or renamed since the stat above: not in use, as above.
+ next if $error == ENOENT || $error == ENOTDIR;
+ # A lease was taken after /proc/locks was read: in use.
exit 0 if $error == EAGAIN || $error == EWOULDBLOCK;
# Any other failure to open (permissions, I/O error): let fuser try.
fall_back_to_fuser();
From 38640d7af78fb5413ddd4619ac8286d2bb5eb437 Mon Sep 17 00:00:00 2001
From: David Coppit
Date: Tue, 24 Nov 2026 12:23:25 -0500
Subject: [PATCH 32/94] test: point the age_mover harness at files_in_use
lib.sh takes only numeric or empty globals from age_mover, so
FILES_IN_USE_HELPER was unset in the harness, and every move counted as in
use.
Co-Authored-By: Claude Opus 5.5
---
tests/age_mover/lib.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/age_mover/lib.sh b/tests/age_mover/lib.sh
index 3f0179d2..58455e15 100644
--- a/tests/age_mover/lib.sh
+++ b/tests/age_mover/lib.sh
@@ -105,7 +105,7 @@ fi
LOGFOLDER=$T MOVER_LOG=$T/log MOVER_DEBUG_LOG=$T/dlog
MOVER_STATUS=$T/mover.ini STATS_FILE=$T/stats MOVER_ACTIONLIST=$T/actions SOFTSTOPFILE=$T/softstop SOFTSTOP_ACK=false
PAUSEFILE=$T/pause MOVINGFILE=$T/moving PIDFILE=$T/pid MOVERTUNINGCFGFILE=$T/cfg MOVERTUNING_OVERRIDE_CFGFOLDER=$T/overrides
-MOVERTUNING_DEFAULT_CFGFILE=$PLUGIN/default.cfg NOW=2026-01-02T030405 UNRAID_VERSION=7.2.0
+MOVERTUNING_DEFAULT_CFGFILE=$PLUGIN/default.cfg FILES_IN_USE_HELPER=$PLUGIN/files_in_use NOW=2026-01-02T030405 UNRAID_VERSION=7.2.0
export TZ=UTC # NOW turns into the sync date in local time
DEBUGLOGGING=no
[ "${AGE_MOVER_DEBUG:-0}" != 2 ] || DEBUGLOGGING=fileOnly
From 9439c7bd08c6ea68959e92f73d586a15a3a9e4aa Mon Sep 17 00:00:00 2001
From: David Coppit
Date: Tue, 24 Nov 2026 11:59:42 -0500
Subject: [PATCH 33/94] test: make the files_in_use negative checks able to
fail
Under set -e, a command starting with ! never stops the script, so these
checks for leftovers from an earlier design always passed.
Co-Authored-By: Claude Opus 5.5
---
.github/scripts/test_files_in_use.sh | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/.github/scripts/test_files_in_use.sh b/.github/scripts/test_files_in_use.sh
index 9ad57f94..293b7e09 100644
--- a/.github/scripts/test_files_in_use.sh
+++ b/.github/scripts/test_files_in_use.sh
@@ -68,8 +68,8 @@ perl -c "$HELPER"
# still validate syntax and the intentionally small age_mover integration.
if [ "$(uname -s)" != Linux ]; then
grep -q '"$FILES_IN_USE_HELPER" "$@"' "$MOVER"
- ! grep -qE 'FILE_IN_USE_MODE|FILE_IN_USE_CHECK|FUSER_BATCH_SAFE|actionRows' "$MOVER"
- ! grep -qE 'coproc|--server|fileLease(Start|Stop|Request)' "$MOVER"
+ grep -qE 'FILE_IN_USE_MODE|FILE_IN_USE_CHECK|FUSER_BATCH_SAFE|actionRows' "$MOVER" && exit 1
+ grep -qE 'coproc|--server|fileLease(Start|Stop|Request)' "$MOVER" && exit 1
echo "file lease Linux tests skipped on $(uname -s)"
exit
fi
@@ -145,8 +145,8 @@ set -e
# Keep age_mover's integration deliberately small: it knows only the helper's
# result contract, not whether a lease or fuser produced the answer.
grep -q '"$FILES_IN_USE_HELPER" "$@"' "$MOVER"
-! grep -qE 'FILE_IN_USE_MODE|FILE_IN_USE_CHECK|FUSER_BATCH_SAFE|actionRows' "$MOVER"
-! grep -qE 'coproc|--server|fileLease(Start|Stop|Request)' "$MOVER"
+grep -qE 'FILE_IN_USE_MODE|FILE_IN_USE_CHECK|FUSER_BATCH_SAFE|actionRows' "$MOVER" && exit 1
+grep -qE 'coproc|--server|fileLease(Start|Stop|Request)' "$MOVER" && exit 1
# age_mover treats an unavailable answer as in-use, and reports it only once.
source <(sed -n '/^filesInUse() {/,/^}/p' "$MOVER")
From 4d2421ec2e7266d18939792f2475f8c4d3feb024 Mon Sep 17 00:00:00 2001
From: David Coppit
Date: Tue, 24 Nov 2026 11:59:24 -0500
Subject: [PATCH 34/94] fix: keep supporting Unraid before 6.11.0
files_in_use needs Perl, which joined Unraid's base distribution in 6.11.0.
Instead of raising the minimum Unraid version to 6.11.0, age_mover now uses
the helper whenever Perl is in PATH, so it also works on older releases where
the user installed Perl. Without Perl it checks with fuser -s, as before, and
the run log says once that the check is slower there. The helper runs through
the perl in PATH, so a Perl outside /usr/bin works too.
The minimum version goes back to 6.9.0-rc2 in the .plg and README.
Reverting this commit raises the minimum to 6.11.0 again, and always uses the
helper.
Co-Authored-By: Claude Opus 5.5
---
.github/scripts/test_files_in_use.sh | 54 +++++++++++++++++--
README.md | 4 +-
plugins/ca.mover.tuning.plg | 6 +--
.../emhttp/plugins/ca.mover.tuning/age_mover | 22 ++++++--
4 files changed, 74 insertions(+), 12 deletions(-)
diff --git a/.github/scripts/test_files_in_use.sh b/.github/scripts/test_files_in_use.sh
index 293b7e09..297695e9 100644
--- a/.github/scripts/test_files_in_use.sh
+++ b/.github/scripts/test_files_in_use.sh
@@ -67,7 +67,7 @@ perl -c "$HELPER"
# F_SETLEASE and fuser -s are Linux interfaces. macOS development machines can
# still validate syntax and the intentionally small age_mover integration.
if [ "$(uname -s)" != Linux ]; then
- grep -q '"$FILES_IN_USE_HELPER" "$@"' "$MOVER"
+ grep -q '"${FILES_IN_USE_CMD\[@\]}" "$@"' "$MOVER"
grep -qE 'FILE_IN_USE_MODE|FILE_IN_USE_CHECK|FUSER_BATCH_SAFE|actionRows' "$MOVER" && exit 1
grep -qE 'coproc|--server|fileLease(Start|Stop|Request)' "$MOVER" && exit 1
echo "file lease Linux tests skipped on $(uname -s)"
@@ -144,14 +144,16 @@ set -e
# Keep age_mover's integration deliberately small: it knows only the helper's
# result contract, not whether a lease or fuser produced the answer.
-grep -q '"$FILES_IN_USE_HELPER" "$@"' "$MOVER"
+grep -q '"${FILES_IN_USE_CMD\[@\]}" "$@"' "$MOVER"
grep -qE 'FILE_IN_USE_MODE|FILE_IN_USE_CHECK|FUSER_BATCH_SAFE|actionRows' "$MOVER" && exit 1
grep -qE 'coproc|--server|fileLease(Start|Stop|Request)' "$MOVER" && exit 1
# age_mover treats an unavailable answer as in-use, and reports it only once.
-source <(sed -n '/^filesInUse() {/,/^}/p' "$MOVER")
+source <(sed -n '/^\(chooseFilesInUseCheck\|filesInUse\)() {/,/^}/p' "$MOVER")
+MOVE_IN_USE=no
fake_helper="$TMP/fake-helper"
-printf '#!/bin/sh\nexit "$CHECK_STATUS"\n' >"$fake_helper"
+# age_mover runs the helper through perl
+printf 'exit $ENV{CHECK_STATUS};\n' >"$fake_helper"
chmod +x "$fake_helper"
# Read by the sourced filesInUse, which ShellCheck cannot see.
# shellcheck disable=SC2034
@@ -161,6 +163,8 @@ mvlogger() { LOG_COUNT=$((LOG_COUNT + 1)); }
# Stands in for processTheMoves, which owns the once-per-run flag as a local.
mover_run() {
local FILE_IN_USE_FAILURE_LOGGED=no
+ local -a FILES_IN_USE_CMD=()
+ chooseFilesInUseCheck
export CHECK_STATUS=0
filesInUse "$plain"
export CHECK_STATUS=1
@@ -178,5 +182,47 @@ mover_run
mover_run
[ "$LOG_COUNT" -eq 2 ]
[ -z "${FILE_IN_USE_FAILURE_LOGGED+set}" ]
+[ -z "${FILES_IN_USE_CMD+set}" ]
+
+# Without Perl, as before Unraid 6.11.0, age_mover runs fuser -s itself, and says so once per run.
+old_run() {
+ local FILE_IN_USE_FAILURE_LOGGED=no
+ local -a FILES_IN_USE_CMD=()
+ chooseFilesInUseCheck
+ [ "${FILES_IN_USE_CMD[*]}" = "fuser -s" ]
+ export FUSER_STATUS=0
+ filesInUse "$plain"
+ export FUSER_STATUS=1
+ if filesInUse "$plain"; then
+ echo "clear fuser result was reported in use" >&2
+ exit 1
+ fi
+}
+printf '#!/bin/sh\n[ "$1" = -s ] || exit 9\nexit "$FUSER_STATUS"\n' >"$TMP/bin/fuser"
+LOG_COUNT=0
+PATH="$TMP/bin" old_run
+[ "$LOG_COUNT" -eq 1 ]
+# Without fuser either, the file stays put and the unchecked-file warning follows the fuser one.
+no_fuser_run() {
+ local FILE_IN_USE_FAILURE_LOGGED=no
+ local -a FILES_IN_USE_CMD=()
+ PATH="$TMP/empty-bin" chooseFilesInUseCheck
+ PATH="$TMP/empty-bin" filesInUse "$plain"
+ PATH="$TMP/empty-bin" filesInUse "$plain"
+}
+LOG_COUNT=0
+no_fuser_run
+[ "$LOG_COUNT" -eq 2 ]
+# With "Move files that are in use" on, nothing is checked, so the fuser note is not logged.
+# shellcheck disable=SC2034 # read by the sourced chooseFilesInUseCheck
+MOVE_IN_USE=yes
+LOG_COUNT=0
+PATH="$TMP/empty-bin" chooseFilesInUseCheck
+[ "$LOG_COUNT" -eq 0 ]
+# With Perl in PATH, wherever it is, the helper runs through it.
+mkdir "$TMP/perl-bin"
+ln -s "$(command -v perl)" "$TMP/perl-bin/perl"
+PATH="$TMP/perl-bin" chooseFilesInUseCheck
+[ "${FILES_IN_USE_CMD[*]}" = "perl $FILES_IN_USE_HELPER" ]
echo "file lease tests passed"
diff --git a/README.md b/README.md
index 6c186ab2..a80e6962 100644
--- a/README.md
+++ b/README.md
@@ -17,7 +17,7 @@ This is an [Unraid](https://unraid.net/) plugin that lets you fine-tune the oper
This fork merges all [pull requests](https://github.com/R3yn4ld/ca.mover.tuning/pulls) from [R3yn4ld](https://github.com/R3yn4ld/ca.mover.tuning) after review (cosmetics, per-share skipfiletypes merge, automatic age threshold, Unraid 7.x compatibility) and adds many new features. See [CHANGELOG.md](CHANGELOG.md) for the full history.
-**Requires Unraid 6.11.0 or newer.** Perl is part of Unraid's base distribution starting with 6.11.0 and is used to call Linux's `fcntl(F_SETLEASE)` interface; Bash cannot issue that system call directly. Unraid 7.2.1+ and the 7.4 rc1 are supported (see [Unraid 7.2.1 and newer](#unraid-721-and-newer)).
+**Requires Unraid 6.9.0-rc2 or newer.** With Perl, which is part of Unraid's base distribution from 6.11.0, the mover checks whether a file is in use faster, with a Linux file lease. Unraid 7.2.1+ and the 7.4 rc1 are supported (see [Unraid 7.2.1 and newer](#unraid-721-and-newer)).
> **Tip:** click on any option or press **F1** on the settings page to read a detailed description of all settings.
@@ -82,7 +82,7 @@ Please note that if the age setting is set to something other than "Auto (smart
Files at the top level of the cache or an array disk (i.e. not in a share) are never moved.
The list is then passed to the original Unraid mover.
-For each file, if the file is not "in use" by any process (as detected by an exclusive Linux file lease, with `fuser` as a compatibility fallback when leases are unavailable), then the file is moved and, upon success, deleted from the source disk. If the file already exists on the target, it is not moved and the source is not deleted. All metadata of moved files/directories is preserved: permissions, ownership, extended attributes, and access/modified timestamps.
+For each file, if the file is not "in use" by any process (as detected by an exclusive Linux file lease, with `fuser` as a compatibility fallback when leases or Perl are unavailable), then the file is moved and, upon success, deleted from the source disk. If the file already exists on the target, it is not moved and the source is not deleted. All metadata of moved files/directories is preserved: permissions, ownership, extended attributes, and access/modified timestamps.
If an error occurs while copying a file, the partial file, if present, is deleted and the operation continues on to the next file.
## Changelog
diff --git a/plugins/ca.mover.tuning.plg b/plugins/ca.mover.tuning.plg
index 5dbfc3df..d1376a7f 100644
--- a/plugins/ca.mover.tuning.plg
+++ b/plugins/ca.mover.tuning.plg
@@ -11,7 +11,7 @@
]>
-
+
###2026.11.13
@@ -703,11 +703,11 @@
$displayversion = $version['version'];
echo "Unraid v$displayversion \n";
- if ( version_compare($version['version'],"6.11.0", "<") )
+ if ( version_compare($version['version'],"6.9.0-rc2", "<") )
{
echo "********************************************************************\n";
echo "\n";
- echo "CA Mover Tuning Requires unRaid version 6.11.0 or greater to run\n";
+ echo "CA Mover Tuning Requires unRaid version 6.9.0-rc2 or greater to run\n";
echo "\n";
echo "********************************************************************\n";
exit(1);
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index 931daad8..1e54ad93 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -29,7 +29,7 @@
# The list is then passed to original unraid mover.
# For each file, if the file is not "in use" by any process (as detected by an exclusive file lease,
-# with fuser as a compatibility fallback),
+# with fuser as a compatibility fallback, and when Perl is missing, as before Unraid 6.11.0),
# then the file is moved, and upon success, deleted from the source disk. If the file already
# exists on the target, it is not moved and the sourceis not deleted. All meta-data of moved
# files/directories is preserved: permissions, ownership, extended attributes, and access/modified
@@ -2517,12 +2517,26 @@ move_tool_said() {
done <<<"$MOVE_OUT"
}
+# files_in_use is Perl, which is part of Unraid's base distribution from 6.11.0; older releases have it only if the user
+# installed it. Without Perl, files are checked with fuser -s, as before the helper. The helper runs through the perl in
+# PATH, so one installed outside /usr/bin works too. Sets processTheMoves' FILES_IN_USE_CMD.
+chooseFilesInUseCheck() {
+ if command -v perl >/dev/null; then
+ FILES_IN_USE_CMD=(perl "$FILES_IN_USE_HELPER")
+ return
+ fi
+ FILES_IN_USE_CMD=(fuser -s)
+ [ "$MOVE_IN_USE" = yes ] ||
+ mvlogger "Perl not found, so files are checked for use with fuser, which is slower on busy servers. Perl is part of Unraid 6.11.0 and newer."
+}
+
# Returns success when at least one path is in use, or when no reliable answer is
# available. The helper owns both the lease check and its fuser fallback.
-# FILE_IN_USE_FAILURE_LOGGED is a local of processTheMoves, so the warning appears at most once per run.
+# FILE_IN_USE_FAILURE_LOGGED and FILES_IN_USE_CMD are locals of processTheMoves, so the warning appears at most once
+# per run.
filesInUse() {
local rc
- if "$FILES_IN_USE_HELPER" "$@" 2>/dev/null; then rc=0; else rc=$?; fi
+ if "${FILES_IN_USE_CMD[@]}" "$@" 2>/dev/null; then rc=0; else rc=$?; fi
case "$rc" in
0) return 0 ;;
1) return 1 ;;
@@ -2688,6 +2702,8 @@ processTheMoves() {
local top ds
# set by filesInUse the first time a file cannot be checked
local FILE_IN_USE_FAILURE_LOGGED=no
+ local -a FILES_IN_USE_CMD=()
+ chooseFilesInUseCheck
# Dry mode info:
if [ "$TESTMODE" = "yes" ]; then
From 07e4d22006f3933babc22cceaf86ea4cdb28039e Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 07:08:17 +0800
Subject: [PATCH 35/94] fix: check files with fuser when the lease helper
cannot start
- A missing helper or Perl module made perl exit 2, the helper's own "no answer", so every file stayed where it was on every run
- The no-answer warning no longer says both a lease and fuser were tried
- New mover case: a hardlink group with one name held open stays together, through the shipped helper and through fuser
- hold_file execs its sleep, so killing the holder always closes the file
---
.github/scripts/test_files_in_use.sh | 11 +++++--
.../emhttp/plugins/ca.mover.tuning/age_mover | 21 ++++++------
tests/age_mover/test_moves.sh | 33 +++++++++++++++++++
3 files changed, 53 insertions(+), 12 deletions(-)
diff --git a/.github/scripts/test_files_in_use.sh b/.github/scripts/test_files_in_use.sh
index 297695e9..d6133e77 100644
--- a/.github/scripts/test_files_in_use.sh
+++ b/.github/scripts/test_files_in_use.sh
@@ -33,9 +33,9 @@ hold_file() {
local mode=$1 file=$2 ready="$TMP/ready"
rm -f -- "$ready"
if [ "$mode" = read ]; then
- ( exec 9<"$file"; : >"$ready"; sleep 30 ) &
+ ( exec 9<"$file"; : >"$ready"; exec sleep 30 ) &
else
- ( exec 9<>"$file"; : >"$ready"; sleep 30 ) &
+ ( exec 9<>"$file"; : >"$ready"; exec sleep 30 ) &
fi
HOLDER=$!
for _ in {1..100}; do
@@ -213,6 +213,13 @@ no_fuser_run() {
LOG_COUNT=0
no_fuser_run
[ "$LOG_COUNT" -eq 2 ]
+# A helper that does not compile would fail closed on every file, so fuser checks them, said once per run.
+FILES_IN_USE_HELPER=$TMP/missing-helper
+LOG_COUNT=0
+chooseFilesInUseCheck
+[ "${FILES_IN_USE_CMD[*]}" = "fuser -s" ]
+[ "$LOG_COUNT" -eq 1 ]
+FILES_IN_USE_HELPER=$fake_helper
# With "Move files that are in use" on, nothing is checked, so the fuser note is not logged.
# shellcheck disable=SC2034 # read by the sourced chooseFilesInUseCheck
MOVE_IN_USE=yes
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index 1e54ad93..0abb62f8 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -2517,23 +2517,24 @@ move_tool_said() {
done <<<"$MOVE_OUT"
}
-# files_in_use is Perl, which is part of Unraid's base distribution from 6.11.0; older releases have it only if the user
-# installed it. Without Perl, files are checked with fuser -s, as before the helper. The helper runs through the perl in
-# PATH, so one installed outside /usr/bin works too. Sets processTheMoves' FILES_IN_USE_CMD.
+# Sets processTheMoves' FILES_IN_USE_CMD: the files_in_use helper through the perl in PATH (Unraid 6.11.0 and newer have
+# Perl), else fuser -s as before the helper. A helper that does not compile would fail closed on every file
chooseFilesInUseCheck() {
- if command -v perl >/dev/null; then
+ if command -v perl >/dev/null && perl -c "$FILES_IN_USE_HELPER" >/dev/null 2>&1; then
FILES_IN_USE_CMD=(perl "$FILES_IN_USE_HELPER")
return
fi
FILES_IN_USE_CMD=(fuser -s)
- [ "$MOVE_IN_USE" = yes ] ||
+ [ "$MOVE_IN_USE" = yes ] && return
+ if command -v perl >/dev/null; then
+ mvlogger "The file lease helper could not start, so files are checked for use with fuser, which is slower on busy servers."
+ else
mvlogger "Perl not found, so files are checked for use with fuser, which is slower on busy servers. Perl is part of Unraid 6.11.0 and newer."
+ fi
}
-# Returns success when at least one path is in use, or when no reliable answer is
-# available. The helper owns both the lease check and its fuser fallback.
-# FILE_IN_USE_FAILURE_LOGGED and FILES_IN_USE_CMD are locals of processTheMoves, so the warning appears at most once
-# per run.
+# Succeeds when a path is in use or when FILES_IN_USE_CMD gives no answer, which it logs once per run through
+# processTheMoves' FILE_IN_USE_FAILURE_LOGGED
filesInUse() {
local rc
if "${FILES_IN_USE_CMD[@]}" "$@" 2>/dev/null; then rc=0; else rc=$?; fi
@@ -2542,7 +2543,7 @@ filesInUse() {
1) return 1 ;;
esac
if [ "$FILE_IN_USE_FAILURE_LOGGED" != yes ]; then
- mvlogger "A file could not be checked with either a lease or fuser, so it stays where it is until a later run. Set 'Move files that are in use' to Yes to move such files anyway."
+ mvlogger "A file could not be checked for use, so it stays where it is until a later run. Set 'Move files that are in use' to Yes to move such files anyway."
FILE_IN_USE_FAILURE_LOGGED=yes
fi
return 0
diff --git a/tests/age_mover/test_moves.sh b/tests/age_mover/test_moves.sh
index 1836f50b..982c0761 100644
--- a/tests/age_mover/test_moves.sh
+++ b/tests/age_mover/test_moves.sh
@@ -176,4 +176,37 @@ counter MOVEDFILES 1
counter MOVEDSIZE 2
check "lastCacheSync saved" 'lastCacheSync="1767323045"' "$(grep '^lastCacheSync=' "$T/cfg")"
+# the in-use check covers every name of a hardlink group: here only the second name is open. A helper that does not
+# compile leaves the check to fuser
+shipped=$FILES_IN_USE_HELPER
+for helper in shipped 'not compiling'; do
+ begin "a hardlink group with one name held open, beside a free file, $helper helper"
+ [ "$helper" = shipped ] || FILES_IN_USE_HELPER=$T/no_such_helper
+ mk cache sh/u/a.txt sh/u/free.txt
+ ln /mnt/cache/sh/u/a.txt /mnt/cache/sh/u/b.txt
+ for n in a b free; do row 'move from primary' f "sh/u/$n.txt"; done | list
+ sleep 60 9/dev/null)" = /mnt/cache/sh/u/b.txt ] && break; sleep 0.05; done
+ check "the holder has b.txt open" /mnt/cache/sh/u/b.txt "$(readlink "/proc/$holder/fd/9" 2>/dev/null)"
+ run_moves
+ kill "$holder"
+ wait "$holder" 2>/dev/null
+ FILES_IN_USE_HELPER=$shipped
+ cache_is sh sh/u sh/u/a.txt sh/u/b.txt
+ array_is sh sh/u sh/u/free.txt
+ counter INUSEFILES 2
+ counter MOVEDFILES 1
+ log_has 'In use, left for a later run: "/mnt/cache/./sh/u/a.txt" "/mnt/cache/./sh/u/b.txt"'
+ log_has '2 files were in use and stay on the source until a later run'
+ if [ "$helper" = shipped ]; then
+ log_lacks 'helper could not start'
+ elif command -v perl >/dev/null; then
+ log_has 'The file lease helper could not start'
+ else
+ log_has 'Perl not found'
+ fi
+ log_lacks 'could not be checked for use'
+done
+
finish
From 01ca41abe0c26ab3ff4e9bcdf380f4380bf4f630 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 07:11:40 +0800
Subject: [PATCH 36/94] style: clear CodeFactor's Perl::Critic findings in
files_in_use
- F_SETLEASE is a plain variable, $SIG{IO} is set with local, and the /proc/locks patterns take /x
---
.../emhttp/plugins/ca.mover.tuning/files_in_use | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/files_in_use b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/files_in_use
index 0258a60c..5b584857 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/files_in_use
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/files_in_use
@@ -46,12 +46,12 @@ use Fcntl qw(O_NONBLOCK O_RDONLY F_UNLCK F_WRLCK);
# Linux-specific fcntl command. The plugin package is x86_64-only, where F_SETLEASE is
# F_LINUX_SPECIFIC_BASE + 0.
-use constant F_SETLEASE => 1024;
+my $F_SETLEASE = 1024;
# The kernel sends SIGIO to a lease holder when another process opens the file and so asks for the
# lease to be broken. SIGIO kills the process by default. That can happen in the few instructions
# between taking and releasing the lease, so ignore it. Closing the descriptor releases the lease
# anyway.
-$SIG{IO} = 'IGNORE';
+local $SIG{IO} = 'IGNORE';
@ARGV or die "Usage: $0 FILE...\n";
@@ -71,8 +71,8 @@ sub fall_back_to_fuser {
my %leased_inodes;
open(my $locks, '<', '/proc/locks') or fall_back_to_fuser();
while (my $line = <$locks>) {
- next unless $line =~ /\b(?:LEASE|DELEG)\b/;
- $leased_inodes{$1} = 1 if $line =~ /\s[0-9a-f]+:[0-9a-f]+:(\d+)\s/;
+ next unless $line =~ /\b(?:LEASE|DELEG)\b/x;
+ $leased_inodes{$1} = 1 if $line =~ /\s[0-9a-f]+:[0-9a-f]+:(\d+)\s/x;
}
close $locks;
@@ -105,7 +105,7 @@ for my $path (@ARGV) {
# The actual test: a write lease is refused with EAGAIN while any other descriptor for the file
# is open, in this process or any other.
- if (!fcntl($file, F_SETLEASE, F_WRLCK)) {
+ if (!fcntl($file, $F_SETLEASE, F_WRLCK)) {
my $error = 0 + $!;
close $file;
# Another process has the file open: in use.
@@ -116,7 +116,7 @@ for my $path (@ARGV) {
# We got the lease, so the file was not in use. Release it at once. If releasing fails,
# something unexpected is going on: don't trust our answer, let fuser decide.
- if (!fcntl($file, F_SETLEASE, F_UNLCK)) {
+ if (!fcntl($file, $F_SETLEASE, F_UNLCK)) {
close $file;
fall_back_to_fuser();
}
From 01d9ca0702dbc28df424af5f1c396bcbc325ff52 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 07:22:44 +0800
Subject: [PATCH 37/94] fix: check a ZFS dataset again once unmounted, before
destroying it
- A file written between the content check and the unmount was destroyed with the dataset
- After the unmount, the dataset is mounted read-only at a private folder and checked there; it is destroyed only when that check is clean, else mounted back (not over a folder that gained files)
- Dataset problems log their details and send one notice per run, at the worst level, naming the datasets
- Tests: mount and umount stand-ins, a notify stand-in, writes during the unmount and the private mount, each step failing
---
.../emhttp/plugins/ca.mover.tuning/age_mover | 98 +++++++++++++++----
.../ca.mover.tuning/languages/de_DE.txt | 3 -
.../ca.mover.tuning/languages/en_US.txt | 4 +-
.../ca.mover.tuning/languages/fr_FR.txt | 3 -
.../ca.mover.tuning/languages/ru_RU.txt | 3 -
.../ca.mover.tuning/languages/zh_CN.txt | 3 -
tests/age_mover/lib.sh | 79 +++++++++++++--
tests/age_mover/test_datasets.sh | 93 ++++++++++++++++--
8 files changed, 235 insertions(+), 51 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index d30f4a54..2baa923e 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -2577,7 +2577,65 @@ dataset_loses() {
[ -n "$entry" ] && printf '%s' "$src/${entry#./}"
}
-# Destroys dataset $1/$2 if it is mounted at /mnt/$1/$2, has no children or snapshots, and dataset_loses against $3/$2 is empty
+# Mounts the unmounted dataset $1 read-only at a private folder and prints dataset_loses there against $3, with that
+# folder shown as $2; prints why and fails when it cannot make the folder, mount or unmount
+dataset_loses_unmounted() {
+ local private err lost
+ if ! private=$(mktemp -d -t ca.mover.tuning.XXXXXX 2>&1); then
+ printf 'mktemp: %s' "$(zfs_reason "${private#mktemp: }")"
+ return 1
+ fi
+ if ! err=$(mount -t zfs -o ro,zfsutil "$1" "$private" 2>&1); then
+ rmdir "$private"
+ printf 'mount: %s' "$(zfs_reason "${err#mount: }")"
+ return 1
+ fi
+ lost=$(dataset_loses "$private" "$3")
+ # the folder stays while the dataset is still mounted on it
+ if ! err=$(umount "$private" 2>&1); then
+ printf 'umount: %s' "$(zfs_reason "${err#umount: }")"
+ return 1
+ fi
+ rmdir "$private"
+ [ -z "$lost" ] || printf '%s' "$2${lost#"$private"}"
+}
+
+# Logs lines $3... and notes dataset $2 for dataset_problems_notice at severity $1 (failure outranks warning); fills
+# processTheMoves' DATASET_PROBLEM and DATASET_PROBLEM_LEVEL
+dataset_problem() {
+ DATASET_PROBLEM[$2]=1
+ [ "$DATASET_PROBLEM_LEVEL" = failure ] || DATASET_PROBLEM_LEVEL=$1
+ local line
+ for line in "${@:3}"; do mvlogger "$line"; done
+}
+
+# One notice for the run's dataset problems, which the log details: a problem that repeats notifies once a run
+dataset_problems_notice() {
+ local ds names=""
+ for ds in "${SHARE_DATASETS[@]}"; do [ -z "${DATASET_PROBLEM[$ds]}" ] || names+="${names:+ }[$ds]"; done
+ [ -z "$names" ] || mvlogger_t "Clean ZFS datasets did not finish for %s: see the mover log." "$DATASET_PROBLEM_LEVEL" "$names"
+}
+
+# Mounts dataset $1 again at its folder $2, unless the folder gained files that a mount would hide
+remount_dataset() {
+ local err
+ # a write through /mnt/user while it was unmounted lands in the bare folder
+ if [ -n "$(find "$2" -mindepth 1 -print -quit 2>/dev/null)" ]; then
+ dataset_problem warning "$1" "Failed to remount dataset [$1]" \
+ "Not remounting ZFS dataset [$1]: its folder $2 holds files that a mount would hide"
+ elif ! err=$(zfs mount "$1" 2>&1); then
+ dataset_problem warning "$1" "Failed to remount dataset [$1]" "zfs: $(zfs_reason "$err")"
+ fi
+}
+
+# Logs at debug level why dataset $1 is kept: entry $2 that a destroy could lose
+dataset_kept() {
+ # the planner never saw this name: a newline in it would end the debug line before debug_mover's mangling
+ mvDebuglogger "Keeping ZFS dataset [$1]: a destroy could lose $(qp "${2//$'\n'/\\n}")" "Clean Dataset"
+}
+
+# Destroys dataset $1/$2 if it is mounted at /mnt/$1/$2, has no children or snapshots, and dataset_loses against $3/$2
+# is empty both before the unmount and after it; else keeps it mounted
cleanShareDataset() {
local folder="/mnt/$1/$2" dataset="$1/$2" mounted names lost err
mounted=$(zfs_dataset_at "$folder")
@@ -2593,8 +2651,7 @@ cleanShareDataset() {
fi
lost=$(dataset_loses "$folder" "$3/$2")
if [ -n "$lost" ]; then
- # the planner never saw this name: a newline in it would end the debug line before debug_mover's mangling
- mvDebuglogger "Keeping ZFS dataset [${dataset}]: a destroy could lose $(qp "${lost//$'\n'/\\n}")" "Clean Dataset"
+ dataset_kept "$dataset" "$lost"
return 0
fi
if [[ $names == *$'\n'* ]]; then
@@ -2604,29 +2661,25 @@ cleanShareDataset() {
mvlogger "ZFS dataset [${dataset}] holds only folders the destination also has, attempting to unmount and delete..."
# stderr is discarded on both launch paths, so zfs's reason goes to the log
if ! err=$(zfs unmount "$dataset" 2>&1); then
- zfs_busy "$dataset" "$err" || {
- mvlogger_t "Failed to unmount ZFS dataset [%s]" "failure" "$dataset"
- mvlogger "zfs: $(zfs_reason "$err")"
- }
+ zfs_busy "$dataset" "$err" ||
+ dataset_problem failure "$dataset" "Failed to unmount ZFS dataset [${dataset}]" "zfs: $(zfs_reason "$err")"
return 0
fi
mvlogger "ZFS dataset [${dataset}] successfully unmounted."
- if ! err=$(zfs destroy "$dataset" 2>&1); then
- zfs_busy "$dataset" "$err" || {
- mvlogger_t "Failed to destroy ZFS dataset [%s] — attempting to remount." "failure" "$dataset"
- mvlogger "zfs: $(zfs_reason "$err")"
- }
- # a write through /mnt/user while it was unmounted lands in the bare folder, and a mount over it would hide it
- if [ -n "$(find "$folder" -mindepth 1 -print -quit 2>/dev/null)" ]; then
- mvlogger_t "Failed to remount dataset [%s]" "warning" "$dataset"
- mvlogger "Not remounting ZFS dataset [${dataset}]: its folder ${folder} holds files that a mount would hide"
- elif ! err=$(zfs mount "$dataset" 2>&1); then
- mvlogger_t "Failed to remount dataset [%s]" "warning" "$dataset"
- mvlogger "zfs: $(zfs_reason "$err")"
- fi
+ # a file written between the check above and the unmount is in the dataset: checked again where nothing can write
+ if ! lost=$(dataset_loses_unmounted "$dataset" "$folder" "$3/$2"); then
+ dataset_problem warning "$dataset" "ZFS dataset [${dataset}] could not be checked once unmounted, will not delete: $lost"
+ elif [ -n "$lost" ]; then
+ mvlogger "Keeping ZFS dataset [${dataset}]: the check after the unmount found something a destroy could lose."
+ dataset_kept "$dataset" "$lost"
+ elif ! err=$(zfs destroy "$dataset" 2>&1); then
+ zfs_busy "$dataset" "$err" || dataset_problem failure "$dataset" \
+ "Failed to destroy ZFS dataset [${dataset}] — attempting to remount." "zfs: $(zfs_reason "$err")"
+ else
+ mvlogger "ZFS dataset [${dataset}] successfully destroyed."
return 0
fi
- mvlogger "ZFS dataset [${dataset}] successfully destroyed."
+ remount_dataset "$dataset" "$folder"
}
# Internal move engine
@@ -2666,6 +2719,8 @@ processTheMoves() {
local -a TOP_FOLDERS=()
local -A DATASET_DEST=()
local -a SHARE_DATASETS=()
+ local -A DATASET_PROBLEM=()
+ local DATASET_PROBLEM_LEVEL=""
local top ds
# without fuser an open file cannot be told apart, so none is moved while moveInUse is no
local fuser_missing=0
@@ -3141,6 +3196,7 @@ processTheMoves() {
moverStep "Cleaning up"
# once per noted share, after the pass: a soft stop's break 2 lands here too
for ds in "${SHARE_DATASETS[@]}"; do cleanShareDataset "${ds%%/*}" "${ds#*/}" "${DATASET_DEST[$ds]}"; done
+ dataset_problems_notice
for top in "${TOP_FOLDERS[@]}"; do cleanTopFolder "$top"; done
if [ "$TESTMODE" != "yes" ] && [ ! -e $SOFTSTOPFILE ] && [ "$SYNCFAILED" = 0 ] &&
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt
index fdf9c962..418c69ae 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt
@@ -45,11 +45,8 @@ Error No files found to move for %s=Fehler: Keine Dateien zum Verschieben für %
Errors Only=Nur Fehler
Estimated Completion=Geschätzte Fertigstellung
ETA=Restzeit
-Failed to destroy ZFS dataset %s — attempting to remount=ZFS‑Dataset %s konnte nicht gelöscht werden — erneutes Einhängen wird versucht.
-Failed to remount dataset %s=Dataset %s konnte nicht erneut eingehängt werden.
Failed to reset Mover Tuning Check the logs=Zurücksetzen von Mover Tuning fehlgeschlagen. Bitte Protokolle prüfen.
Failed to start Mover Tuning Check the logs=Start des Mover‑Tunings fehlgeschlagen. Bitte Protokolle prüfen.
-Failed to unmount ZFS dataset %s=ZFS‑Dataset %s konnte nicht ausgehängt werden.
Fatal error %s does not exist, check this=Schwerer Fehler: %s existiert nicht. Bitte prüfen.
Fatal error cache not enabled and less than 2 pools set up=Schwerer Fehler: Cache‑Pool nicht aktiviert und weniger als zwei Pools eingerichtet.
Fatal error cache not present, or only cache present, and less than 2 pools set up=Schwerer Fehler: Cache‑Pool fehlt oder nur Cache‑Pool vorhanden und weniger als zwei Pools eingerichtet.
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt
index 479059eb..3d38d5d6 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt
@@ -27,6 +27,7 @@ Cache → Array=
Cancel=
Clean empty folders=
Clean empty ZFS datasets=
+Clean ZFS datasets did not finish for %s see the mover log=Clean ZFS datasets did not finish for %s: see the mover log.
CLI help commands=
Comma separated list of file types=
Cron Schedule to force move all of files=
@@ -47,11 +48,8 @@ Error No files found to move for %s=Error: No files found to move for %s
Errors Only=
Estimated Completion=
ETA=
-Failed to destroy ZFS dataset %s — attempting to remount=Failed to destroy ZFS dataset [%s] — attempting to remount.
-Failed to remount dataset %s=Failed to remount dataset [%s]
Failed to reset Mover Tuning Check the logs=Failed to reset Mover Tuning. Check the logs.
Failed to start Mover Tuning Check the logs=Failed to start Mover Tuning. Check the logs.
-Failed to unmount ZFS dataset %s=Failed to unmount ZFS dataset [%s]
Fatal error %s does not exist, check this=Fatal error: %s does not exist, check this.
Fatal error cache not enabled and less than 2 pools set up=Fatal error: cache not enabled and less than 2 pools set up.
Fatal error cache not present, or only cache present, and less than 2 pools set up=Fatal error: cache not present, or only cache present, and less than 2 pools set up.
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt
index b8595fe1..edb3beec 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt
@@ -45,11 +45,8 @@ Error No files found to move for %s=Erreur : aucun fichier trouvé à déplacer
Errors Only=Erreurs uniquement
Estimated Completion=Fin estimée
ETA=Temps restant
-Failed to destroy ZFS dataset %s — attempting to remount=Échec de la destruction du dataset ZFS [%s] — tentative de remontage.
-Failed to remount dataset %s=Échec du remontage du dataset [%s]
Failed to reset Mover Tuning Check the logs=Échec de la réinitialisation de Mover Tuning. Consultez les journaux.
Failed to start Mover Tuning Check the logs=Échec du démarrage de Mover Tuning. Consultez les journaux.
-Failed to unmount ZFS dataset %s=Échec du démontage du dataset ZFS [%s]
Fatal error %s does not exist, check this=Erreur fatale : %s n’existe pas, vérifiez cela.
Fatal error cache not enabled and less than 2 pools set up=Erreur fatale : cache non activé et moins de deux pools configurés.
Fatal error cache not present, or only cache present, and less than 2 pools set up=Erreur fatale : cache absent, ou uniquement cache présent, et moins de deux pools configurés.
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt
index 32f38d27..9301a914 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt
@@ -45,11 +45,8 @@ Error No files found to move for %s=Ошибка: не найдено файло
Errors Only=Только ошибки
Estimated Completion=Ожидаемое завершение
ETA=Осталось
-Failed to destroy ZFS dataset %s — attempting to remount=Не удалось уничтожить ZFS‑датасет [%s] — выполняется попытка перемонтирования.
-Failed to remount dataset %s=Не удалось перемонтировать датасет [%s]
Failed to reset Mover Tuning Check the logs=Не удалось сбросить Mover Tuning. Проверьте журналы.
Failed to start Mover Tuning Check the logs=Не удалось запустить Mover Tuning. Проверьте журналы.
-Failed to unmount ZFS dataset %s=Не удалось размонтировать ZFS‑датасет [%s]
Fatal error %s does not exist, check this=Критическая ошибка: %s не существует, проверьте это.
Fatal error cache not enabled and less than 2 pools set up=Критическая ошибка: кэш-пул не включён и настроено менее двух пулов.
Fatal error cache not present, or only cache present, and less than 2 pools set up=Критическая ошибка: кэш-пул отсутствует или присутствует только кэш-пул, и настроено менее двух пулов.
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt
index 2a16273e..38fa8250 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt
@@ -44,11 +44,8 @@ Error No files found to move for %s=错误:未找到 %s 中需要移动的文
Errors Only=仅错误
Estimated Completion=预计完成
ETA=剩余时间
-Failed to destroy ZFS dataset %s — attempting to remount=销毁 ZFS 数据集 [%s] 失败,正在尝试重新挂载。
-Failed to remount dataset %s=重新挂载数据集 [%s] 失败
Failed to reset Mover Tuning Check the logs=重置 Mover Tuning 失败,请查看日志。
Failed to start Mover Tuning Check the logs=启动 Mover Tuning 失败,请查看日志。
-Failed to unmount ZFS dataset %s=卸载 ZFS 数据集 [%s] 失败
Fatal error %s does not exist, check this=严重错误:%s 不存在,请检查。
Fatal error cache not enabled and less than 2 pools set up=严重错误:未启用缓存,且设置的存储池少于 2 个。
Fatal error cache not present, or only cache present, and less than 2 pools set up=严重错误:缓存不存在或只有缓存,且设置的存储池少于 2 个。
diff --git a/tests/age_mover/lib.sh b/tests/age_mover/lib.sh
index 3f0179d2..a8f78d43 100644
--- a/tests/age_mover/lib.sh
+++ b/tests/age_mover/lib.sh
@@ -1,18 +1,22 @@
#!/bin/bash
# shellcheck disable=SC2034 # the settings set here are read by age_mover's functions, sourced from funcs.sh
# Sourced by test_*.sh: each age_mover case runs the real processTheMoves with real rsync and the shipped default.cfg read by the real
-# getMoverSettings; Unraid's move, findmnt and zfs are stand-ins. It deletes the folders in ROOTS.
+# getMoverSettings; Unraid's move and notify, findmnt, zfs, mount and umount are stand-ins. It deletes the folders in ROOTS.
HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
PLUGIN=$HERE/../../source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning
AM=${AM:-$PLUGIN/age_mover}
T=${T:-/tmp/age_mover_test} # test_folders.sh runs its plain-user half with its own T
ROOTS=(/mnt/cache /mnt/user0 /mnt/disk1 /mnt/disk2 /mnt/other)
-# a mount at or under /mnt would put the host's files under the wipe, and one at /usr/libexec/unraid/move or above it the
-# host's mover under the stand-in; an unreadable mount table refuses too
-no_host_mount() { awk '$5 == "/mnt" || index($5, "/mnt/") == 1 || $5 ~ "^/usr(/libexec(/unraid(/move)?)?)?$" { exit 1 }' /proc/self/mountinfo; }
+# a mount at or under /mnt would put the host's files under the wipe, and one at a stand-in's path or above it the
+# host's own under the stand-in; an unreadable mount table refuses too
+no_host_mount() {
+ awk '$5 == "/mnt" || index($5, "/mnt/") == 1 || $5 ~ "^/usr(/libexec(/unraid(/move)?)?)?$" ||
+ $5 ~ "^/usr/local(/emhttp(/webGui(/scripts(/notify)?)?)?)?$" { exit 1 }' /proc/self/mountinfo
+}
if [ "${AGE_MOVER_TEST:-}" != 1 ] || [ ! -e /.dockerenv ] || ! no_host_mount; then
- echo "lib.sh deletes ${ROOTS[*]} and writes /usr/libexec/unraid/move: start the tests with tests/age_mover/run.sh" >&2
+ echo "lib.sh deletes ${ROOTS[*]} and writes /usr/libexec/unraid/move and /usr/local/emhttp/webGui/scripts/notify: start" \
+ "the tests with tests/age_mover/run.sh" >&2
exit 2
fi
@@ -40,6 +44,16 @@ while IFS= read -r p; do
done
EOF
chmod 755 /usr/libexec/unraid/move
+ mkdir -p /usr/local/emhttp/webGui/scripts
+ cat >/usr/local/emhttp/webGui/scripts/notify <<'EOF'
+#!/bin/bash
+# stand-in for Unraid's notify: each notice's importance and description, as one line in $NOTIFY_LOG
+while getopts 's:d:i:l:' o; do
+ case $o in d) desc=$OPTARG ;; i) imp=$OPTARG ;; s | l) ;; *) exit 1 ;; esac
+done
+printf '%s|%s\n' "$imp" "$desc" >>"${NOTIFY_LOG:?}"
+EOF
+ chmod 755 /usr/local/emhttp/webGui/scripts/notify
fi
# a path in $T/zfs is a ZFS mountpoint (a tab, then its dataset, else the path less /mnt/); zfs logs calls to $T/zfs.calls
# and fails unanswered calls and each subcommand in $T/zfs.fail, with $T/zfs.reason (else zfs.fail) then a child's name
@@ -72,7 +86,7 @@ case "$*" in
echo "$n"; cat "$d/zfs.children" 2>/dev/null || :
;;
# unmount unlists the dataset and hides its files, keeping its folder; mount lists it and brings them back, hiding,
-# as an overlay mount does, what the folder gained meanwhile
+# as an overlay mount does, what the folder gained meanwhile, and fails while mount has it at a private folder
"unmount "*)
l=$(entry "$d/zfs")
[ -n "$l" ] || { echo "cannot unmount '$n': not currently mounted" >&2; exit 1; }
@@ -81,6 +95,8 @@ case "$*" in
mkdir -p "$d/zfs.store/$n" && find "${l%%$'\t'*}" -mindepth 1 -maxdepth 1 -exec mv -t "$d/zfs.store/$n" {} +
;;
"mount "*)
+ [ -z "$(awk -F'\t' -v n="$n" '$2 == n' "$d/zfs.private" 2>/dev/null)" ] ||
+ { echo "cannot mount '$n': filesystem already mounted" >&2; exit 1; }
l=$(entry "$d/zfs.off" | tail -n 1) && f=${l%%$'\t'*}
mkdir -p "$d/zfs.hidden" "$f" && find "$f" -mindepth 1 -maxdepth 1 -exec mv -t "$d/zfs.hidden" {} +
find "$d/zfs.store/$n" -mindepth 1 -maxdepth 1 -exec mv -t "$f" {} +
@@ -91,8 +107,55 @@ case "$*" in
*) echo "zfs stand-in has no answer for: zfs $*" >&2; exit 1 ;;
esac
EOF
-chmod 755 "$T/bin/findmnt" "$T/bin/zfs"
+# age_mover's only mount: mount -t zfs -o ro,zfsutil brings the dataset's
+# files into the folder, noted in $T/zfs.private; umount takes them back. Both log to zfs.calls, a mktemp folder as
+# PRIVATE, run $T/zfs.on_mount.zfs or zfs.on_umount first and fail on mount.zfs or umount in zfs.fail
+cat >"$T/bin/mount" <<'EOF'
+#!/bin/bash
+d=${0%/bin/mount}
+p=${*: -1}
+[[ $p == "${TMPDIR:-/tmp}"/ca.mover.tuning.?????? ]] && shown=PRIVATE || shown=$p
+echo "mount ${*:1:$#-1} $shown" >>"$d/zfs.calls"
+[ ! -f "$d/zfs.on_mount.zfs" ] || bash "$d/zfs.on_mount.zfs"
+[ $# = 6 ] && [ "$1 $2 $3 $4" = "-t zfs -o ro,zfsutil" ] || { echo "mount stand-in has no answer for: mount $*" >&2; exit 1; }
+n=$5
+if grep -qxF mount.zfs "$d/zfs.fail" 2>/dev/null; then
+ r=$(cat "$d/zfs.reason" 2>/dev/null) || r=zfs.fail
+ echo "filesystem '$n' cannot be mounted: $r" >&2
+ exit 1
+fi
+case $p in /mnt | /mnt/*) echo "mount stand-in: $p is under /mnt" >&2; exit 1 ;; esac
+[ -d "$p" ] && [ -z "$(find "$p" -mindepth 1 -print -quit)" ] || { echo "mount stand-in: $p is not an empty folder" >&2; exit 1; }
+if [ ! -d "$d/zfs.store/$n" ] || [ -n "$(awk -F'\t' -v n="$n" '$2 == n' "$d/zfs.private" 2>/dev/null)" ] ||
+ [ -n "$(awk -F'\t' -v n="$n" '(NF > 1 ? $2 : substr($1, 6)) == n' "$d/zfs" 2>/dev/null)" ]; then
+ echo "filesystem '$n' is already mounted" >&2
+ exit 1
+fi
+find "$d/zfs.store/$n" -mindepth 1 -maxdepth 1 -exec mv -t "$p" {} +
+printf '%s\t%s\n' "$p" "$n" >>"$d/zfs.private"
+EOF
+cat >"$T/bin/umount" <<'EOF'
+#!/bin/bash
+d=${0%/bin/umount}
+p=$1
+l=$(awk -F'\t' -v p="$p" '$1 == p' "$d/zfs.private" 2>/dev/null)
+[ -n "$l" ] && shown=PRIVATE || shown=$p
+echo "umount $shown" >>"$d/zfs.calls"
+[ ! -f "$d/zfs.on_umount" ] || bash "$d/zfs.on_umount"
+[ $# = 1 ] || { echo "umount stand-in has no answer for: umount $*" >&2; exit 1; }
+if grep -qxF umount "$d/zfs.fail" 2>/dev/null; then
+ r=$(cat "$d/zfs.reason" 2>/dev/null) || r=zfs.fail
+ echo "umount: $p: $r" >&2
+ exit 32
+fi
+[ -n "$l" ] || { echo "umount: $p: not mounted." >&2; exit 32; }
+find "$p" -mindepth 1 -maxdepth 1 -exec mv -t "$d/zfs.store/${l#*$'\t'}" {} +
+grep -vxF -- "$l" "$d/zfs.private" >"$d/zfs.new"
+mv "$d/zfs.new" "$d/zfs.private"
+EOF
+chmod 755 "$T/bin/findmnt" "$T/bin/zfs" "$T/bin/mount" "$T/bin/umount"
PATH=$T/bin:$PATH
+export NOTIFY_LOG=$T/notify
# age_mover runs its command on load, so only its functions and its top-level start values are taken
awk '/^[A-Za-z_][A-Za-z0-9_]*\(\) \{/,/^\}/' "$AM" >"$T/funcs.sh"
@@ -136,7 +199,7 @@ begin() {
CASE=$1
shift
rm -rf "${ROOTS[@]}" "$SOFTSTOPFILE" "$PAUSEFILE" "$T/row_error" "$T/zfs" "$T/zfs".* "$T/after_rsync" "$T/bin/rsync" \
- "$MOVER_LOG"
+ "$MOVER_LOG" "$NOTIFY_LOG" "${TMPDIR:-/tmp}"/ca.mover.tuning.*
mkdir -p /mnt/cache /mnt/user0
fresh "$@"
}
diff --git a/tests/age_mover/test_datasets.sh b/tests/age_mover/test_datasets.sh
index d05ae10a..ccab80e1 100644
--- a/tests/age_mover/test_datasets.sh
+++ b/tests/age_mover/test_datasets.sh
@@ -16,6 +16,12 @@ if [ "${1:-}" = --as-tester ]; then
fi
LS='list -r -H -t filesystem,volume,snapshot -o name'
+# a destroy's calls: list, unmount, the check at a private read-only mount, destroy
+DESTROYED=$(printf '%s\n' "zfs $LS cache/sh" 'zfs unmount cache/sh' 'mount -t zfs -o ro,zfsutil cache/sh PRIVATE' 'umount PRIVATE' \
+ 'zfs destroy cache/sh')
+NOTICE='warning|Clean ZFS datasets did not finish for [cache/sh]: see the mover log.'
+no_private() { check "no private mount folder left" "" "$(find "${TMPDIR:-/tmp}" -maxdepth 1 -name 'ca.mover.tuning.*')"; }
+notices() { check "notices" "$1" "$(cat "$NOTIFY_LOG" 2>/dev/null)"; }
# the destroy goes ahead only when it loses nothing: each entry left is a folder the array also has
for left in nothing 'a middle folder the array has' '.zfs, as snapdir=visible shows it,' 'a file' 'a file beside it' 'a symlink' \
'an empty folder the array lacks' 'a nested .zfs folder the array lacks'; do
@@ -37,9 +43,10 @@ for left in nothing 'a middle folder the array has' '.zfs, as snapdir=visible sh
if [ "$f" = sh/a/b/f.txt ]; then array_is sh sh/a sh/a/b "$f"; else array_is sh sh/only "$f"; fi
case $left in
nothing | 'a middle'* | .zfs*)
- check "zfs calls" "$(printf 'zfs %s cache/sh\n' "$LS" unmount destroy)" "$(cat "$T/zfs.calls")"
+ check "zfs calls" "$DESTROYED" "$(cat "$T/zfs.calls")"
log_has 'ZFS dataset [cache/sh] successfully destroyed.'
cache_is
+ no_private
log_lacks 'top-level'
;;
*)
@@ -70,6 +77,54 @@ check "zfs calls" "zfs $LS cache/sh" "$(cat "$T/zfs.calls")"
cache_is sh sh/new.txt
[ "${AGE_MOVER_DEBUG:-0}" != 2 ] || dlog_has 'Keeping ZFS dataset [cache/sh]: a destroy could lose "/mnt/cache/sh/new.txt"'
+# a file written after the content check, as zfs unmounts, is in the dataset: the check at the private mount keeps it
+begin "Clean ZFS datasets, a file lands in the share while zfs unmounts it" cleanFolders topFolder cleanDatasets yes
+mk cache sh/only/f.txt
+printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+echo 'echo x >/mnt/cache/sh/new.txt' >"$T/zfs.on_unmount"
+row 'move from primary' f sh/only/f.txt | list
+run_moves
+check "zfs calls" "$(sed '$d' <<<"$DESTROYED"; echo 'zfs mount cache/sh')" "$(cat "$T/zfs.calls")"
+log_has 'Keeping ZFS dataset [cache/sh]: the check after the unmount found something a destroy could lose.'
+log_lacks 'successfully destroyed'
+log_lacks 'Failed to'
+cache_is sh sh/new.txt
+no_private
+notices ''
+[ "${AGE_MOVER_DEBUG:-0}" != 2 ] || dlog_has 'Keeping ZFS dataset [cache/sh]: a destroy could lose "/mnt/cache/sh/new.txt"'
+
+# the same, and a write through /mnt/user lands in the bare folder while the dataset is away: kept, not mounted over it
+begin "Clean ZFS datasets, files land in the dataset and in its bare folder while it is unmounted" cleanFolders topFolder \
+ cleanDatasets yes
+mk cache sh/only/f.txt
+printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+echo 'echo x >/mnt/cache/sh/new.txt' >"$T/zfs.on_unmount"
+echo 'echo y >/mnt/cache/sh/bare.txt' >"$T/zfs.on_mount.zfs"
+row 'move from primary' f sh/only/f.txt | list
+run_moves
+check "zfs calls" "$(sed '$d' <<<"$DESTROYED")" "$(cat "$T/zfs.calls")"
+log_has 'Keeping ZFS dataset [cache/sh]: the check after the unmount found something a destroy could lose.'
+log_has 'Not remounting ZFS dataset [cache/sh]: its folder /mnt/cache/sh holds files that a mount would hide'
+cache_is sh sh/bare.txt
+check "the unmounted dataset keeps its file" new.txt "$(ls "$T/zfs.store/cache/sh")"
+no_private
+notices "$NOTICE"
+
+# one notice for the run at its worst level: an unmount that fails, then a check that fails, still reach errorsOnly
+begin "Clean ZFS datasets, two datasets fail" cleanFolders topFolder cleanDatasets yes notify errorsOnly
+mk cache a/only/f.txt sh/only/g.txt
+printf '%s\n' /mnt/cache /mnt/cache/a /mnt/cache/sh >"$T/zfs"
+# cache/a leaves the mount table as zfs starts to unmount it; cache/sh unmounts, then its read-only mount fails
+printf "sed -i '\\|^/mnt/cache/a$|d' %q\n" "$T/zfs" >"$T/zfs.on_unmount"
+echo mount.zfs >"$T/zfs.fail"
+{ row 'move from primary' f a/only/f.txt; row 'move from primary' f sh/only/g.txt; } | list
+run_moves
+log_has 'Failed to unmount ZFS dataset [cache/a]'
+log_has 'zfs: not currently mounted'
+log_has "ZFS dataset [cache/sh] could not be checked once unmounted, will not delete: mount: filesystem 'cache/sh' cannot be mounted: zfs.fail"
+notices 'warning|Clean ZFS datasets did not finish for [cache/a] [cache/sh]: see the mover log.'
+no_private
+
# the kept name never passed the planner: a newline in it must not end the debug line before debug_mover mangles it
begin "Clean ZFS datasets, a file named with a newline left in the share" cleanFolders topFolder cleanDatasets yes
mk cache sh/only/f.txt
@@ -92,7 +147,7 @@ for clean in topFolder no; do
row 'move from primary' d sh/new | list
run_moves
array_is sh sh/new
- if [ $clean = no ]; then calls=; else calls=$(printf 'zfs %s cache/sh\n' "$LS" unmount destroy); fi
+ if [ $clean = no ]; then calls=; else calls=$DESTROYED; fi
check "zfs calls" "$calls" "$(cat "$T/zfs.calls" 2>/dev/null)"
if [ $clean = no ]; then cache_is sh; else cache_is; fi
done
@@ -169,21 +224,33 @@ for pool in 'not ZFS' 'ZFS, the share a plain folder on it'; do
[ "${AGE_MOVER_DEBUG:-0}" != 2 ] || dlog_lacks 'Keeping'
done
-for fail in list unmount 'unmount, busy,' destroy 'destroy and mount' 'destroy, busy,'; do
- begin "Clean ZFS datasets, zfs $fail fails" cleanFolders topFolder cleanDatasets yes notify no
+# errorsOnly sends only a failure: a failed unmount or destroy notifies, a failed check or remount only warns
+for fail in list unmount 'unmount, busy,' destroy 'destroy and mount' 'destroy, busy,' 'the read-only mount' \
+ 'the read-only unmount' mktemp; do
+ what="zfs $fail"
+ [[ $fail != the* && $fail != mktemp ]] || what=$fail
+ begin "Clean ZFS datasets, $what fails" cleanFolders topFolder cleanDatasets yes notify errorsOnly
mk cache sh/only/f.txt
printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
case $fail in
'destroy and mount') printf '%s\n' destroy mount ;;
'unmount, busy,') echo unmount; echo 'pool or dataset is busy' >"$T/zfs.reason" ;;
'destroy, busy,') echo destroy; echo 'dataset is busy' >"$T/zfs.reason" ;;
+ 'the read-only mount') echo mount.zfs ;;
+ 'the read-only unmount') echo umount ;;
+ mktemp) ;;
*) echo "$fail" ;;
esac >"$T/zfs.fail"
row 'move from primary' f sh/only/f.txt | list
# age_mover's stderr is discarded in use, so zfs's reason goes to the log, without the child zfs names after it
- run_moves
+ if [ "$fail" = mktemp ]; then TMPDIR=/nowhere run_moves; else run_moves; fi
+ private=$(find "${TMPDIR:-/tmp}" -maxdepth 1 -name 'ca.mover.tuning.*')
+ unchecked="ZFS dataset [cache/sh] could not be checked once unmounted, will not delete:"
case $fail in
list) log_has "ZFS dataset [cache/sh] could not be listed, will not delete: zfs.fail" ;;
+ 'the read-only mount') log_has "$unchecked mount: filesystem 'cache/sh' cannot be mounted: zfs.fail" ;;
+ 'the read-only unmount') log_has "$unchecked umount: $private: zfs.fail" ;;
+ mktemp) log_has "$unchecked mktemp: No such file or directory" ;;
# the failure notice goes out with the "Failed to" line
*busy*)
log_has "ZFS dataset [cache/sh] is busy, will not delete: a process or another mount, such as a container's, may hold it."
@@ -196,11 +263,21 @@ for fail in list unmount 'unmount, busy,' destroy 'destroy and mount' 'destroy,
# the row still logs and counts what it moved
log_has '0 files remaining from caches to array'
counter REMAINING_CACHE_FILES 0
+ case $fail in unmount | destroy | 'destroy and mount') notices "$NOTICE" ;; *) notices '' ;; esac
if [ "$fail" = 'destroy and mount' ]; then
log_has 'Failed to remount dataset [cache/sh]'
log_count 2 'zfs: zfs.fail'
+ no_private
+ continue
+ fi
+ # an unmount that fails leaves the dataset at the private folder, which zfs mount then refuses
+ if [ "$fail" = 'the read-only unmount' ]; then
+ check "the dataset stays at the private folder" "$private"$'\t'cache/sh "$(cat "$T/zfs.private")"
+ log_has 'Failed to remount dataset [cache/sh]'
+ log_has 'zfs: filesystem already mounted'
continue
fi
+ no_private
# the dataset is mounted at the end, so its top folder stays
cache_is sh
log_lacks 'Failed to remount'
@@ -209,17 +286,19 @@ done
# a write through /mnt/user while the dataset is unmounted lands in its bare folder, which a remount would hide
begin "Clean ZFS datasets, a file lands in the unmounted share's folder before a failed destroy" cleanFolders topFolder \
- cleanDatasets yes notify no
+ cleanDatasets yes
mk cache sh/only/f.txt
printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
echo destroy >"$T/zfs.fail"
echo 'echo x >/mnt/cache/sh/new.txt' >"$T/zfs.on_destroy"
row 'move from primary' f sh/only/f.txt | list
run_moves
-check "zfs calls" "$(printf 'zfs %s cache/sh\n' "$LS" unmount destroy)" "$(cat "$T/zfs.calls")"
+check "zfs calls" "$DESTROYED" "$(cat "$T/zfs.calls")"
log_has 'Failed to remount dataset [cache/sh]'
log_has 'Not remounting ZFS dataset [cache/sh]: its folder /mnt/cache/sh holds files that a mount would hide'
cache_is sh sh/new.txt
+no_private
+notices "$NOTICE"
id tester >/dev/null 2>&1 || useradd -M tester
U=/tmp/age_mover_tester
From cf795c77878338ed063303cb021373a6be1180b4 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 07:25:57 +0800
Subject: [PATCH 38/94] Name the dataset notice after its setting and translate
it
- The notice says "Clean empty ZFS datasets", as the settings page does, in all five languages
---
.../usr/local/emhttp/plugins/ca.mover.tuning/age_mover | 2 +-
.../local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt | 1 +
.../local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt | 2 +-
.../local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt | 1 +
.../local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt | 1 +
.../local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt | 1 +
tests/age_mover/test_datasets.sh | 4 ++--
7 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index 2baa923e..3c3e6070 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -2613,7 +2613,7 @@ dataset_problem() {
dataset_problems_notice() {
local ds names=""
for ds in "${SHARE_DATASETS[@]}"; do [ -z "${DATASET_PROBLEM[$ds]}" ] || names+="${names:+ }[$ds]"; done
- [ -z "$names" ] || mvlogger_t "Clean ZFS datasets did not finish for %s: see the mover log." "$DATASET_PROBLEM_LEVEL" "$names"
+ [ -z "$names" ] || mvlogger_t "Clean empty ZFS datasets did not finish for %s: see the mover log." "$DATASET_PROBLEM_LEVEL" "$names"
}
# Mounts dataset $1 again at its folder $2, unless the folder gained files that a mount would hide
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt
index 418c69ae..5442874a 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt
@@ -25,6 +25,7 @@ Cache → Array=Cache → Speicherverbund
Cancel=Abbrechen
Clean empty folders=Leere Ordner bereinigen
Clean empty ZFS datasets=Leere ZFS‑Datasets bereinigen
+Clean empty ZFS datasets did not finish for %s see the mover log=Leere ZFS‑Datasets bereinigen wurde für %s nicht abgeschlossen: siehe Protokoll.
CLI help commands=CLI‑Hilfebefehle
Comma separated list of file types=Kommagetrennte Liste von Dateitypen
Cron Schedule to force move all of files=Cron‑Zeitplan zum erzwungenen Verschieben aller Dateien
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt
index 3d38d5d6..f2e323e2 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt
@@ -27,7 +27,7 @@ Cache → Array=
Cancel=
Clean empty folders=
Clean empty ZFS datasets=
-Clean ZFS datasets did not finish for %s see the mover log=Clean ZFS datasets did not finish for %s: see the mover log.
+Clean empty ZFS datasets did not finish for %s see the mover log=Clean empty ZFS datasets did not finish for %s: see the mover log.
CLI help commands=
Comma separated list of file types=
Cron Schedule to force move all of files=
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt
index edb3beec..10a4d6c3 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt
@@ -25,6 +25,7 @@ Cache → Array=Cache → Array
Cancel=Annuler
Clean empty folders=Nettoyer les dossiers vides
Clean empty ZFS datasets=Nettoyer les datasets ZFS vides
+Clean empty ZFS datasets did not finish for %s see the mover log=Nettoyer les datasets ZFS vides n'a pas abouti pour %s : voir le journal.
CLI help commands=Commandes d’aide CLI
Comma separated list of file types=Liste de types de fichiers séparés par des virgules
Cron Schedule to force move all of files=Cron pour forcer le déplacement de tous les fichiers
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt
index 9301a914..e82e26d6 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt
@@ -25,6 +25,7 @@ Cache → Array=Кэш → Массив
Cancel=Отмена
Clean empty folders=Очистить пустые папки
Clean empty ZFS datasets=Очистить пустые ZFS‑датасеты
+Clean empty ZFS datasets did not finish for %s see the mover log=Очистка пустых ZFS‑датасетов не завершена для %s: см. журнал.
CLI help commands=Команды помощи CLI
Comma separated list of file types=Список типов файлов через запятую
Cron Schedule to force move all of files=Расписание Cron для принудительного перемещения всех файлов
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt
index 38fa8250..ee3e1a7e 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt
@@ -24,6 +24,7 @@ Cache → Array=缓存 → 阵列
Cancel=取消
Clean empty folders=清理空文件夹
Clean empty ZFS datasets=清理空的 ZFS 数据集
+Clean empty ZFS datasets did not finish for %s see the mover log=清理空的 ZFS 数据集未能完成:%s,请查看日志。
CLI help commands=命令行帮助
Comma separated list of file types=以逗号分隔的文件扩展名列表
Cron Schedule to force move all of files=强制移动所有文件的 Cron 计划
diff --git a/tests/age_mover/test_datasets.sh b/tests/age_mover/test_datasets.sh
index ccab80e1..3776c862 100644
--- a/tests/age_mover/test_datasets.sh
+++ b/tests/age_mover/test_datasets.sh
@@ -19,7 +19,7 @@ LS='list -r -H -t filesystem,volume,snapshot -o name'
# a destroy's calls: list, unmount, the check at a private read-only mount, destroy
DESTROYED=$(printf '%s\n' "zfs $LS cache/sh" 'zfs unmount cache/sh' 'mount -t zfs -o ro,zfsutil cache/sh PRIVATE' 'umount PRIVATE' \
'zfs destroy cache/sh')
-NOTICE='warning|Clean ZFS datasets did not finish for [cache/sh]: see the mover log.'
+NOTICE='warning|Clean empty ZFS datasets did not finish for [cache/sh]: see the mover log.'
no_private() { check "no private mount folder left" "" "$(find "${TMPDIR:-/tmp}" -maxdepth 1 -name 'ca.mover.tuning.*')"; }
notices() { check "notices" "$1" "$(cat "$NOTIFY_LOG" 2>/dev/null)"; }
# the destroy goes ahead only when it loses nothing: each entry left is a folder the array also has
@@ -122,7 +122,7 @@ run_moves
log_has 'Failed to unmount ZFS dataset [cache/a]'
log_has 'zfs: not currently mounted'
log_has "ZFS dataset [cache/sh] could not be checked once unmounted, will not delete: mount: filesystem 'cache/sh' cannot be mounted: zfs.fail"
-notices 'warning|Clean ZFS datasets did not finish for [cache/a] [cache/sh]: see the mover log.'
+notices 'warning|Clean empty ZFS datasets did not finish for [cache/a] [cache/sh]: see the mover log.'
no_private
# the kept name never passed the planner: a newline in it must not end the debug line before debug_mover mangles it
From fd95cd5433bd8a8ddbaaec191bd28a102f39cb29 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 07:43:33 +0800
Subject: [PATCH 39/94] test: make the lease tests fail if a regular file falls
back to fuser
- expect_status runs the helper with a fake fuser that exits 7, so a regular file must be answered by a lease
---
.github/scripts/test_files_in_use.sh | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/.github/scripts/test_files_in_use.sh b/.github/scripts/test_files_in_use.sh
index d6133e77..42b820fd 100644
--- a/.github/scripts/test_files_in_use.sh
+++ b/.github/scripts/test_files_in_use.sh
@@ -20,7 +20,7 @@ expect_status() {
local expected=$1 actual
shift
set +e
- perl "$HELPER" "$@"
+ PATH="$TMP/bin:$PATH" perl "$HELPER" "$@"
actual=$?
set -e
if [ "$actual" -ne "$expected" ]; then
@@ -74,6 +74,11 @@ if [ "$(uname -s)" != Linux ]; then
exit
fi
+# expect_status runs the helper with this fuser first in PATH: a regular file answered by fuser, not a lease, gets its 7
+mkdir "$TMP/bin"
+printf '#!/bin/sh\nexit 7\n' >"$TMP/bin/fuser"
+chmod +x "$TMP/bin/fuser"
+
expect_status 1 "$plain" "$space" "$newline" "$leading"
expect_status 1 "$TMP/vanished"
@@ -124,14 +129,7 @@ release_holder
# A device cannot be leased. A distinctive fake fuser status proves that the
# one-shot helper immediately replaces itself with the compatibility command.
-mkdir "$TMP/bin"
-printf '#!/bin/sh\nexit 7\n' >"$TMP/bin/fuser"
-chmod +x "$TMP/bin/fuser"
-set +e
-PATH="$TMP/bin:$PATH" perl "$HELPER" /dev/null
-fallback_status=$?
-set -e
-[ "$fallback_status" -eq 7 ]
+expect_status 7 /dev/null
# If leases cannot answer and fuser cannot be executed, status 2 tells
# age_mover not to mistake the file for clear.
From 1c4786fb321d7e22e39a447ac8ac7426b2c34f53 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 07:52:11 +0800
Subject: [PATCH 40/94] Check a dataset again at a private read-only mount, and
put it back on a stop
A failed umount of the private mount is a failure that names the path and the fix, and is not remounted over. A remount
that cannot follow is a failure too, since the share then lacks the dataset's files. A mover stop during the unmount,
check or destroy lets that step finish, mounts the dataset back and ends the run with the notice. A check that cannot
read the dataset counts as one that could not run.
---
.../emhttp/plugins/ca.mover.tuning/age_mover | 102 +++++++++------
tests/age_mover/lib.sh | 18 ++-
tests/age_mover/test_datasets.sh | 121 +++++++++++++++---
3 files changed, 180 insertions(+), 61 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index 3c3e6070..12924dd2 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -2577,27 +2577,22 @@ dataset_loses() {
[ -n "$entry" ] && printf '%s' "$src/${entry#./}"
}
-# Mounts the unmounted dataset $1 read-only at a private folder and prints dataset_loses there against $3, with that
-# folder shown as $2; prints why and fails when it cannot make the folder, mount or unmount
+# Mounts the unmounted dataset $1 read-only at empty folder $2 and prints dataset_loses there against $4, with $2 shown
+# as $3; prints why and fails when it cannot mount or read it, and returns 2, still mounted, with umount's reason
dataset_loses_unmounted() {
- local private err lost
- if ! private=$(mktemp -d -t ca.mover.tuning.XXXXXX 2>&1); then
- printf 'mktemp: %s' "$(zfs_reason "${private#mktemp: }")"
- return 1
- fi
- if ! err=$(mount -t zfs -o ro,zfsutil "$1" "$private" 2>&1); then
- rmdir "$private"
+ local err lost
+ if ! err=$(mount -t zfs -o ro,zfsutil "$1" "$2" 2>&1); then
printf 'mount: %s' "$(zfs_reason "${err#mount: }")"
return 1
fi
- lost=$(dataset_loses "$private" "$3")
- # the folder stays while the dataset is still mounted on it
- if ! err=$(umount "$private" 2>&1); then
- printf 'umount: %s' "$(zfs_reason "${err#umount: }")"
- return 1
+ lost=$(dataset_loses "$2" "$4")
+ if ! err=$(umount "$2" 2>&1); then
+ printf '%s' "$(zfs_reason "${err#umount: }")"
+ return 2
fi
- rmdir "$private"
- [ -z "$lost" ] || printf '%s' "$2${lost#"$private"}"
+ # dataset_loses names its folder itself when it cannot read it
+ [ "$lost" != "$2" ] || { printf 'find: the dataset could not be read'; return 1; }
+ [ -z "$lost" ] || printf '%s' "$3${lost#"$2"}"
}
# Logs lines $3... and notes dataset $2 for dataset_problems_notice at severity $1 (failure outranks warning); fills
@@ -2621,10 +2616,10 @@ remount_dataset() {
local err
# a write through /mnt/user while it was unmounted lands in the bare folder
if [ -n "$(find "$2" -mindepth 1 -print -quit 2>/dev/null)" ]; then
- dataset_problem warning "$1" "Failed to remount dataset [$1]" \
+ dataset_problem failure "$1" "Failed to remount dataset [$1]" \
"Not remounting ZFS dataset [$1]: its folder $2 holds files that a mount would hide"
elif ! err=$(zfs mount "$1" 2>&1); then
- dataset_problem warning "$1" "Failed to remount dataset [$1]" "zfs: $(zfs_reason "$err")"
+ dataset_problem failure "$1" "Failed to remount dataset [$1]" "zfs: $(zfs_reason "$err")"
fi
}
@@ -2634,10 +2629,48 @@ dataset_kept() {
mvDebuglogger "Keeping ZFS dataset [$1]: a destroy could lose $(qp "${2//$'\n'/\\n}")" "Clean Dataset"
}
+# Unmounts dataset $1 from folder $2 and destroys it if dataset_loses_unmounted at private folder $4 against $3 is empty;
+# else mounts it back. cleanShareDataset's stopped, set by a stop, skips the destroy
+unmount_check_destroy() {
+ local dataset=$1 folder=$2 private=$4 err lost rc
+ # stderr is discarded on both launch paths, so zfs's reason goes to the log
+ if ! err=$(zfs unmount "$dataset" 2>&1); then
+ zfs_busy "$dataset" "$err" ||
+ dataset_problem failure "$dataset" "Failed to unmount ZFS dataset [${dataset}]" "zfs: $(zfs_reason "$err")"
+ return 0
+ fi
+ mvlogger "ZFS dataset [${dataset}] successfully unmounted."
+ # a file written between the first check and the unmount is in the dataset: checked again where nothing can write
+ lost=$(dataset_loses_unmounted "$dataset" "$private" "$folder" "$3")
+ rc=$?
+ # the plugin's mover stop ends the check too, maybe while mounted
+ [ "$rc" -le 2 ] || { umount "$private" 2>/dev/null; lost="the check was cut short"; }
+ if [ "$rc" = 2 ]; then
+ dataset_problem failure "$dataset" \
+ "ZFS dataset [${dataset}] is still mounted read-only at ${private}, not at ${folder}: umount: $lost" \
+ "To mount it back: umount ${private}, then zfs mount ${dataset}"
+ return 0
+ elif [ -n "$stopped" ]; then
+ mvlogger "Mover stopped while ZFS dataset [${dataset}] was unmounted: not deleting it, attempting to remount"
+ elif [ "$rc" != 0 ]; then
+ dataset_problem warning "$dataset" "ZFS dataset [${dataset}] could not be checked once unmounted, will not delete: $lost"
+ elif [ -n "$lost" ]; then
+ mvlogger "Keeping ZFS dataset [${dataset}]: the check after the unmount found something a destroy could lose."
+ dataset_kept "$dataset" "$lost"
+ elif ! err=$(zfs destroy "$dataset" 2>&1); then
+ zfs_busy "$dataset" "$err" || dataset_problem failure "$dataset" \
+ "Failed to destroy ZFS dataset [${dataset}] — attempting to remount." "zfs: $(zfs_reason "$err")"
+ else
+ mvlogger "ZFS dataset [${dataset}] successfully destroyed."
+ return 0
+ fi
+ remount_dataset "$dataset" "$folder"
+}
+
# Destroys dataset $1/$2 if it is mounted at /mnt/$1/$2, has no children or snapshots, and dataset_loses against $3/$2
# is empty both before the unmount and after it; else keeps it mounted
cleanShareDataset() {
- local folder="/mnt/$1/$2" dataset="$1/$2" mounted names lost err
+ local folder="/mnt/$1/$2" dataset="$1/$2" mounted names lost private stopped=""
mounted=$(zfs_dataset_at "$folder")
[ -n "$mounted" ] || return 0
if [ "$mounted" != "$dataset" ]; then
@@ -2658,28 +2691,19 @@ cleanShareDataset() {
mvlogger "ZFS dataset [${dataset}] has child datasets or snapshots, will not delete..."
return 0
fi
- mvlogger "ZFS dataset [${dataset}] holds only folders the destination also has, attempting to unmount and delete..."
- # stderr is discarded on both launch paths, so zfs's reason goes to the log
- if ! err=$(zfs unmount "$dataset" 2>&1); then
- zfs_busy "$dataset" "$err" ||
- dataset_problem failure "$dataset" "Failed to unmount ZFS dataset [${dataset}]" "zfs: $(zfs_reason "$err")"
- return 0
- fi
- mvlogger "ZFS dataset [${dataset}] successfully unmounted."
- # a file written between the check above and the unmount is in the dataset: checked again where nothing can write
- if ! lost=$(dataset_loses_unmounted "$dataset" "$folder" "$3/$2"); then
- dataset_problem warning "$dataset" "ZFS dataset [${dataset}] could not be checked once unmounted, will not delete: $lost"
- elif [ -n "$lost" ]; then
- mvlogger "Keeping ZFS dataset [${dataset}]: the check after the unmount found something a destroy could lose."
- dataset_kept "$dataset" "$lost"
- elif ! err=$(zfs destroy "$dataset" 2>&1); then
- zfs_busy "$dataset" "$err" || dataset_problem failure "$dataset" \
- "Failed to destroy ZFS dataset [${dataset}] — attempting to remount." "zfs: $(zfs_reason "$err")"
- else
- mvlogger "ZFS dataset [${dataset}] successfully destroyed."
+ if ! private=$(mktemp -d -t ca.mover.tuning.XXXXXX 2>&1); then
+ dataset_problem warning "$dataset" \
+ "ZFS dataset [${dataset}] could not be checked once unmounted, will not delete: mktemp: $(zfs_reason "${private#mktemp: }")"
return 0
fi
- remount_dataset "$dataset" "$folder"
+ mvlogger "ZFS dataset [${dataset}] holds only folders the destination also has, attempting to unmount and delete..."
+ # a stop lets the step in hand finish and the dataset go back: Unraid's mover stop signals the run, the plugin's all
+ trap 'stopped=1' TERM HUP INT
+ unmount_check_destroy "$dataset" "$folder" "$3/$2" "$private"
+ trap - TERM HUP INT
+ # a folder the dataset is still mounted on stays
+ rmdir "$private" 2>/dev/null
+ [ -z "$stopped" ] || { dataset_problems_notice; exit 0; }
}
# Internal move engine
diff --git a/tests/age_mover/lib.sh b/tests/age_mover/lib.sh
index a8f78d43..656b3ba8 100644
--- a/tests/age_mover/lib.sh
+++ b/tests/age_mover/lib.sh
@@ -107,9 +107,8 @@ case "$*" in
*) echo "zfs stand-in has no answer for: zfs $*" >&2; exit 1 ;;
esac
EOF
-# age_mover's only mount: mount -t zfs -o ro,zfsutil brings the dataset's
-# files into the folder, noted in $T/zfs.private; umount takes them back. Both log to zfs.calls, a mktemp folder as
-# PRIVATE, run $T/zfs.on_mount.zfs or zfs.on_umount first and fail on mount.zfs or umount in zfs.fail
+# mount -t zfs -o ro,zfsutil DATASET DIR moves an unmounted dataset's files into an empty DIR outside /mnt, umount back; both
+# log to zfs.calls with a mktemp DIR as PRIVATE, run zfs.on_mount.zfs or zfs.on_umount, and fail on mount.zfs or umount
cat >"$T/bin/mount" <<'EOF'
#!/bin/bash
d=${0%/bin/mount}
@@ -121,7 +120,7 @@ echo "mount ${*:1:$#-1} $shown" >>"$d/zfs.calls"
n=$5
if grep -qxF mount.zfs "$d/zfs.fail" 2>/dev/null; then
r=$(cat "$d/zfs.reason" 2>/dev/null) || r=zfs.fail
- echo "filesystem '$n' cannot be mounted: $r" >&2
+ echo "filesystem '$n' cannot be mounted, $r" >&2
exit 1
fi
case $p in /mnt | /mnt/*) echo "mount stand-in: $p is under /mnt" >&2; exit 1 ;; esac
@@ -153,7 +152,16 @@ find "$p" -mindepth 1 -maxdepth 1 -exec mv -t "$d/zfs.store/${l#*$'\t'}" {} +
grep -vxF -- "$l" "$d/zfs.private" >"$d/zfs.new"
mv "$d/zfs.new" "$d/zfs.private"
EOF
-chmod 755 "$T/bin/findmnt" "$T/bin/zfs" "$T/bin/mount" "$T/bin/umount"
+# as Linux does, rmdir refuses a folder something is mounted on
+cat >"$T/bin/rmdir" <<'EOF'
+#!/bin/bash
+if [ -n "$(awk -F'\t' -v p="${*: -1}" '$1 == p' "${0%/bin/rmdir}/zfs.private" 2>/dev/null)" ]; then
+ echo "rmdir: failed to remove '${*: -1}': Device or resource busy" >&2
+ exit 1
+fi
+exec /bin/rmdir "$@"
+EOF
+chmod 755 "$T/bin/findmnt" "$T/bin/zfs" "$T/bin/mount" "$T/bin/umount" "$T/bin/rmdir"
PATH=$T/bin:$PATH
export NOTIFY_LOG=$T/notify
diff --git a/tests/age_mover/test_datasets.sh b/tests/age_mover/test_datasets.sh
index 3776c862..17b4d1b3 100644
--- a/tests/age_mover/test_datasets.sh
+++ b/tests/age_mover/test_datasets.sh
@@ -6,6 +6,15 @@
if [ "${1:-}" = --as-tester ]; then
CASE=$2
fresh cleanFolders topFolder cleanDatasets yes
+ if [ "${3:-}" = private ]; then
+ # only the check at the private mount meets sh/locked, which zfs.on_unmount made; the top-folder check's two follow
+ run_moves "$(printf '%s\n' "find: './locked': Permission denied" "find: '/mnt/cache/sh/locked': Permission denied" \
+ "find: '/mnt/cache/sh/locked': Permission denied")"
+ log_has 'ZFS dataset [cache/sh] could not be checked once unmounted, will not delete: find: the dataset could not be read'
+ log_lacks 'found something a destroy could lose'
+ [ "$FAILS" = 0 ]
+ exit
+ fi
# the dataset check's find, then the top-folder check's two, cannot list sh/locked
run_moves "$(printf '%s\n' "find: './locked': Permission denied" "find: '/mnt/cache/sh/locked': Permission denied" \
"find: '/mnt/cache/sh/locked': Permission denied")"
@@ -22,6 +31,17 @@ DESTROYED=$(printf '%s\n' "zfs $LS cache/sh" 'zfs unmount cache/sh' 'mount -t zf
NOTICE='warning|Clean empty ZFS datasets did not finish for [cache/sh]: see the mover log.'
no_private() { check "no private mount folder left" "" "$(find "${TMPDIR:-/tmp}" -maxdepth 1 -name 'ca.mover.tuning.*')"; }
notices() { check "notices" "$1" "$(cat "$NOTIFY_LOG" 2>/dev/null)"; }
+# a hook, run once, that stops the mover: Unraid's stop signals the run alone, the plugin's every process from the hook's
+# caller up to the run
+stop_hook() {
+ cat <"$T/zfs"
+ echo 'echo x >/mnt/cache/sh/new.txt' >"$T/zfs.on_unmount"
+ if [ "$after" = 'zfs mount fails' ]; then
+ echo mount >"$T/zfs.fail"
+ else
+ echo 'echo y >/mnt/cache/sh/bare.txt' >"$T/zfs.on_mount.zfs"
+ fi
+ row 'move from primary' f sh/only/f.txt | list
+ run_moves
+ log_has 'Keeping ZFS dataset [cache/sh]: the check after the unmount found something a destroy could lose.'
+ log_has 'Failed to remount dataset [cache/sh]'
+ check "the unmounted dataset keeps its file" new.txt "$(ls "$T/zfs.store/cache/sh")"
+ no_private
+ notices "$NOTICE"
+ if [ "$after" = 'zfs mount fails' ]; then
+ check "zfs calls" "$(sed '$d' <<<"$DESTROYED"; echo 'zfs mount cache/sh')" "$(cat "$T/zfs.calls")"
+ log_has 'zfs: zfs.fail'
+ else
+ check "zfs calls" "$(sed '$d' <<<"$DESTROYED")" "$(cat "$T/zfs.calls")"
+ log_has 'Not remounting ZFS dataset [cache/sh]: its folder /mnt/cache/sh holds files that a mount would hide'
+ cache_is sh sh/bare.txt
+ fi
+done
+
+# a stop during the check after the unmount lets the step in hand finish, then puts the dataset back and ends the run,
+# with the notice for what went wrong: here Unraid's stop, and a write through /mnt/user meanwhile, which keeps it unmounted
+begin "Clean ZFS datasets, Unraid's mover stop during the check after the unmount" cleanFolders topFolder cleanDatasets yes \
+ notify errorsOnly
mk cache sh/only/f.txt
printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
-echo 'echo x >/mnt/cache/sh/new.txt' >"$T/zfs.on_unmount"
-echo 'echo y >/mnt/cache/sh/bare.txt' >"$T/zfs.on_mount.zfs"
+{ stop_hook run; echo 'echo y >/mnt/cache/sh/bare.txt'; } >"$T/zfs.on_mount.zfs"
row 'move from primary' f sh/only/f.txt | list
-run_moves
+run_moves 'processTheMoves did not return'
check "zfs calls" "$(sed '$d' <<<"$DESTROYED")" "$(cat "$T/zfs.calls")"
-log_has 'Keeping ZFS dataset [cache/sh]: the check after the unmount found something a destroy could lose.'
+log_has 'Mover stopped while ZFS dataset [cache/sh] was unmounted: not deleting it, attempting to remount'
log_has 'Not remounting ZFS dataset [cache/sh]: its folder /mnt/cache/sh holds files that a mount would hide'
+log_lacks 'successfully destroyed'
+check "the dataset is kept, unmounted" yes "$([ -d "$T/zfs.store/cache/sh" ] && echo yes)"
cache_is sh sh/bare.txt
-check "the unmounted dataset keeps its file" new.txt "$(ls "$T/zfs.store/cache/sh")"
no_private
notices "$NOTICE"
+# the plugin's stop also ends the check, here as it unmounts the private folder: the run unmounts it, then mounts the dataset
+begin "Clean ZFS datasets, the plugin's mover stop during the check after the unmount" cleanFolders topFolder cleanDatasets yes
+mk cache sh/only/f.txt
+printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+stop_hook tree >"$T/zfs.on_umount"
+row 'move from primary' f sh/only/f.txt | list
+run_moves 'processTheMoves did not return'
+check "zfs calls" "$(sed '$d' <<<"$DESTROYED"; printf '%s\n' 'umount PRIVATE' 'zfs mount cache/sh')" "$(cat "$T/zfs.calls")"
+log_has 'Mover stopped while ZFS dataset [cache/sh] was unmounted: not deleting it, attempting to remount'
+log_lacks 'Failed to'
+check "no private mount left" "" "$(cat "$T/zfs.private" 2>/dev/null)"
+check "the dataset is mounted again" /mnt/cache/sh "$(grep -x /mnt/cache/sh "$T/zfs")"
+cache_is sh
+no_private
+notices ''
+
# one notice for the run at its worst level: an unmount that fails, then a check that fails, still reach errorsOnly
begin "Clean ZFS datasets, two datasets fail" cleanFolders topFolder cleanDatasets yes notify errorsOnly
mk cache a/only/f.txt sh/only/g.txt
@@ -121,7 +188,7 @@ echo mount.zfs >"$T/zfs.fail"
run_moves
log_has 'Failed to unmount ZFS dataset [cache/a]'
log_has 'zfs: not currently mounted'
-log_has "ZFS dataset [cache/sh] could not be checked once unmounted, will not delete: mount: filesystem 'cache/sh' cannot be mounted: zfs.fail"
+log_has "ZFS dataset [cache/sh] could not be checked once unmounted, will not delete: mount: filesystem 'cache/sh' cannot be mounted, zfs.fail"
notices 'warning|Clean empty ZFS datasets did not finish for [cache/a] [cache/sh]: see the mover log.'
no_private
@@ -224,7 +291,8 @@ for pool in 'not ZFS' 'ZFS, the share a plain folder on it'; do
[ "${AGE_MOVER_DEBUG:-0}" != 2 ] || dlog_lacks 'Keeping'
done
-# errorsOnly sends only a failure: a failed unmount or destroy notifies, a failed check or remount only warns
+# errorsOnly sends only a failure: a failed unmount, destroy or remount, or a dataset left at the private folder, notifies;
+# a check that cannot run only warns
for fail in list unmount 'unmount, busy,' destroy 'destroy and mount' 'destroy, busy,' 'the read-only mount' \
'the read-only unmount' mktemp; do
what="zfs $fail"
@@ -248,9 +316,12 @@ for fail in list unmount 'unmount, busy,' destroy 'destroy and mount' 'destroy,
unchecked="ZFS dataset [cache/sh] could not be checked once unmounted, will not delete:"
case $fail in
list) log_has "ZFS dataset [cache/sh] could not be listed, will not delete: zfs.fail" ;;
- 'the read-only mount') log_has "$unchecked mount: filesystem 'cache/sh' cannot be mounted: zfs.fail" ;;
- 'the read-only unmount') log_has "$unchecked umount: $private: zfs.fail" ;;
- mktemp) log_has "$unchecked mktemp: No such file or directory" ;;
+ 'the read-only mount') log_has "$unchecked mount: filesystem 'cache/sh' cannot be mounted, zfs.fail" ;;
+ 'the read-only unmount')
+ log_has "ZFS dataset [cache/sh] is still mounted read-only at $private, not at /mnt/cache/sh: umount: $private: zfs.fail"
+ log_has "To mount it back: umount $private, then zfs mount cache/sh"
+ ;;
+ mktemp) log_has "$unchecked mktemp: No such file or directory"; log_lacks 'attempting to unmount' ;;
# the failure notice goes out with the "Failed to" line
*busy*)
log_has "ZFS dataset [cache/sh] is busy, will not delete: a process or another mount, such as a container's, may hold it."
@@ -263,18 +334,18 @@ for fail in list unmount 'unmount, busy,' destroy 'destroy and mount' 'destroy,
# the row still logs and counts what it moved
log_has '0 files remaining from caches to array'
counter REMAINING_CACHE_FILES 0
- case $fail in unmount | destroy | 'destroy and mount') notices "$NOTICE" ;; *) notices '' ;; esac
+ case $fail in unmount | destroy | 'destroy and mount' | 'the read-only unmount') notices "$NOTICE" ;; *) notices '' ;; esac
if [ "$fail" = 'destroy and mount' ]; then
log_has 'Failed to remount dataset [cache/sh]'
log_count 2 'zfs: zfs.fail'
no_private
continue
fi
- # an unmount that fails leaves the dataset at the private folder, which zfs mount then refuses
+ # an unmount that fails leaves the dataset at the private folder, which zfs mount would refuse
if [ "$fail" = 'the read-only unmount' ]; then
check "the dataset stays at the private folder" "$private"$'\t'cache/sh "$(cat "$T/zfs.private")"
- log_has 'Failed to remount dataset [cache/sh]'
- log_has 'zfs: filesystem already mounted'
+ check "zfs calls" "$(sed '$d' <<<"$DESTROYED")" "$(cat "$T/zfs.calls")"
+ log_lacks 'Failed to remount'
continue
fi
no_private
@@ -316,4 +387,20 @@ check "zfs calls" "zfs $LS cache/sh" "$(cat "$U/zfs.calls" 2>/dev/null)"
[ ! -d /mnt/cache/sh/locked ] || chmod 0755 /mnt/cache/sh/locked
cache_is sh sh/locked sh/locked/k.txt
+# a check at the private mount that cannot read the dataset counts as one that could not run, not as a file a destroy loses
+begin "Clean ZFS datasets, a subfolder a plain-user mover cannot list lands in the dataset as it unmounts" cleanFolders \
+ topFolder cleanDatasets yes
+mk cache sh/only/f.txt
+rm -rf "$U" && mkdir -p "$U"
+printf '%s\n' /mnt/cache /mnt/cache/sh >"$U/zfs"
+echo 'mkdir -m 0333 /mnt/cache/sh/locked' >"$U/zfs.on_unmount"
+row 'move from primary' f sh/only/f.txt | { echo "$HDR"; cat; } >"$U/actions"
+chown -R tester /mnt/cache /mnt/user0 "$U"
+runuser -u tester -- env AGE_MOVER_TEST=1 AGE_MOVER_DEBUG="${AGE_MOVER_DEBUG:-0}" T="$U" bash "$0" --as-tester "$CASE" private
+check "the checks run as the plain user pass" 0 "$?"
+check "zfs calls" "$(sed '$d' <<<"$DESTROYED"; echo 'zfs mount cache/sh')" "$(cat "$U/zfs.calls" 2>/dev/null)"
+[ ! -d /mnt/cache/sh/locked ] || chmod 0755 /mnt/cache/sh/locked
+cache_is sh sh/locked
+no_private
+
finish
From e880c065d2e1b45dc42c9eba057ba3bc7c2ed206 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 08:06:21 +0800
Subject: [PATCH 41/94] ci: clear CodeFactor's workflow findings
- discord-notify drops its workflow_run trigger: release.yml announces a failed release itself, and published
releases were already announced from the release event.
- PR cleanup sweeps hourly for test builds of closed pull requests instead of running on pull_request_target.
- PR publish keeps workflow_run, with a zizmor ignore: it takes only the build artifact.
- The Dependabot merge moves into CI, after every job passes, and checks the PR's author, not github.actor.
---
.github/workflows/auto-merge.yml | 20 -----
.github/workflows/ci.yml | 22 +++++
.github/workflows/discord-notify.yml | 117 +--------------------------
.github/workflows/pr-cleanup.yml | 57 ++++++++-----
.github/workflows/pr-publish.yml | 8 +-
.github/workflows/release.yml | 26 ++++++
6 files changed, 92 insertions(+), 158 deletions(-)
delete mode 100644 .github/workflows/auto-merge.yml
diff --git a/.github/workflows/auto-merge.yml b/.github/workflows/auto-merge.yml
deleted file mode 100644
index 970771f1..00000000
--- a/.github/workflows/auto-merge.yml
+++ /dev/null
@@ -1,20 +0,0 @@
-name: Auto-merge Dependabot PRs
-
-on:
- pull_request:
- types: [opened, synchronize]
-
-permissions:
- contents: write
- pull-requests: write
-
-jobs:
- automerge:
- if: github.actor == 'dependabot[bot]'
- runs-on: ubuntu-latest
- steps:
- - name: Enable auto-merge
- run: gh pr merge --merge "$PR_URL"
- env:
- PR_URL: ${{ github.event.pull_request.html_url }}
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 5d28dbbb..2616bb52 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -104,3 +104,25 @@ jobs:
env:
AGE_MOVER_TEST: '1'
run: bash tests/age_mover/run.sh
+
+ # Dependabot's pull requests merge once the jobs above pass; release-notes runs only for the stable release PR.
+ # The PR's author, not github.actor: the actor is whoever acted last and can be spoofed
+ dependabot-merge:
+ name: Merge Dependabot pull request
+ needs: [validate, release-notes, release-scripts, age-mover]
+ if: >-
+ always() && github.event_name == 'pull_request'
+ && github.event.pull_request.user.login == 'dependabot[bot]'
+ && github.repository == github.event.pull_request.head.repo.full_name
+ && needs.validate.result == 'success' && needs.release-scripts.result == 'success'
+ && needs.age-mover.result == 'success' && contains(fromJSON('["success", "skipped"]'), needs.release-notes.result)
+ runs-on: ubuntu-latest
+ permissions:
+ contents: write
+ pull-requests: write
+ steps:
+ - name: Merge
+ env:
+ PR_URL: ${{ github.event.pull_request.html_url }}
+ GH_TOKEN: ${{ github.token }}
+ run: gh pr merge --merge "$PR_URL"
diff --git a/.github/workflows/discord-notify.yml b/.github/workflows/discord-notify.yml
index 0e9c0a1c..50b1eeef 100644
--- a/.github/workflows/discord-notify.yml
+++ b/.github/workflows/discord-notify.yml
@@ -7,57 +7,16 @@ on:
types: [opened, closed, reopened]
issues:
types: [opened, closed, reopened]
- workflow_run:
- workflows: ["Release"]
- types: [completed]
workflow_dispatch:
-permissions:
- actions: read
+permissions: {}
jobs:
notify_discord:
runs-on: ubuntu-latest
steps:
- # ---------------------------------------------------------
- # 1. Download release info artifact (workflow_run only)
- # ---------------------------------------------------------
- - name: Download release info artifact
- id: release_artifact
- if: ${{ github.event_name == 'workflow_run' }}
- continue-on-error: true
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
- with:
- name: release_info
- github-token: ${{ secrets.GITHUB_TOKEN }}
- run-id: ${{ github.event.workflow_run.id }}
-
- # ---------------------------------------------------------
- # 2. Parse release info JSON
- # ---------------------------------------------------------
- - name: Read release info
- if: ${{ github.event_name == 'workflow_run' && steps.release_artifact.outcome == 'success' }}
- id: release_info
- run: |
- RELEASE_TAG=$(jq -r '.release_tag' release_info.json)
- RELEASE_NAME=$(jq -r '.release_name' release_info.json)
- NEW_RELEASE=$(jq -r '.new_release' release_info.json)
-
- {
- echo "RELEASE_TAG=${RELEASE_TAG}"
- echo "RELEASE_NAME=${RELEASE_NAME}"
- echo "NEW_RELEASE=${NEW_RELEASE}"
- } >> "${GITHUB_ENV}"
-
- # ---------------------------------------------------------
- # 3. Build & send Discord embed
- # ---------------------------------------------------------
-
- # Notify unless workflow_run succeeded without a new release, or was cancelled or skipped
- name: Send Discord Notification
- if: ${{ github.event_name != 'workflow_run' || env.NEW_RELEASE == 'true' || !contains(fromJSON('["success", "cancelled", "skipped"]'), github.event.workflow_run.conclusion) }}
-
env:
WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
EVENT: ${{ github.event_name }}
@@ -68,9 +27,8 @@ jobs:
# Release info
RELEASE_URL: ${{ github.event.release.html_url || '' }}
RELEASE_BODY: ${{ github.event.release.body || '' }}
- RELEASE_TAG: ${{ github.event.release.tag_name || env.RELEASE_TAG || '' }}
- RELEASE_NAME: ${{ github.event.release.name || env.RELEASE_NAME || '' }}
- NEW_RELEASE: ${{ github.event_name == 'release' && 'true' || env.NEW_RELEASE || 'false' }}
+ RELEASE_TAG: ${{ github.event.release.tag_name || '' }}
+ RELEASE_NAME: ${{ github.event.release.name || '' }}
# PR / Issue info
PR_TITLE: ${{ github.event.pull_request.title || '' }}
@@ -82,13 +40,6 @@ jobs:
ISSUE_URL: ${{ github.event.issue.html_url || '' }}
ISSUE_BODY: ${{ github.event.issue.body || '' }}
- # Workflow run info
- WORKFLOW_NAME: ${{ github.event.workflow_run.name || '' }}
- WORKFLOW_CONCLUSION: ${{ github.event.workflow_run.conclusion || '' }}
- WORKFLOW_URL: ${{ github.event.workflow_run.html_url || '' }}
- WORKFLOW_STARTED: ${{ github.event.workflow_run.run_started_at || '' }}
- WORKFLOW_FINISHED: ${{ github.event.workflow_run.updated_at || '' }}
-
run: |
# -----------------------------------------------------
# Guard: Webhook must exist
@@ -159,27 +110,6 @@ jobs:
COLOR=9807270
fi
;;
- workflow_run)
- URL="${WORKFLOW_URL:-https://github.com/${REPO}/actions}"
- TITLE="${WORKFLOW_NAME}"
- BODY="Workflow completed with conclusion: ${WORKFLOW_CONCLUSION}"
-
- if [ "${WORKFLOW_CONCLUSION}" = "success" ]; then
- ICON="✅"
- CONTENT="Workflow Succeeded"
- COLOR=5763719
- else
- ICON="❌"
- CONTENT="Workflow Failed"
- COLOR=10038562
- fi
-
- if [ "${NEW_RELEASE}" = "true" ]; then
- BODY="${BODY}"$'\n'"Built Version: ${RELEASE_TAG}"
- TITLE="${TITLE} — ${RELEASE_TAG}"
- CONTENT="Workflow Succeeded — New Release"
- fi
- ;;
*)
ICON="🧭"
CONTENT="Manual Trigger"
@@ -190,33 +120,6 @@ jobs:
;;
esac
- # -----------------------------------------------------
- # Compute workflow duration (guard null)
- # -----------------------------------------------------
- DURATION=""
- if [ "${EVENT}" = "workflow_run" ] &&
- [ "${WORKFLOW_STARTED}" != "null" ] &&
- [ "${WORKFLOW_FINISHED}" != "null" ] &&
- [ -n "${WORKFLOW_STARTED}" ] &&
- [ -n "${WORKFLOW_FINISHED}" ]; then
-
- START=$(date -d "${WORKFLOW_STARTED}" +%s)
- END=$(date -d "${WORKFLOW_FINISHED}" +%s)
- ELAPSED=$((END - START))
-
- H=$((ELAPSED / 3600))
- M=$(((ELAPSED % 3600) / 60))
- S=$((ELAPSED % 60))
-
- if [ ${H} -gt 0 ]; then
- DURATION="${H}h ${M}m ${S}s"
- elif [ ${M} -gt 0 ]; then
- DURATION="${M}m ${S}s"
- else
- DURATION="${S}s"
- fi
- fi
-
# -----------------------------------------------------
# Build JSON using jq (safe & correct)
# -----------------------------------------------------
@@ -231,8 +134,6 @@ jobs:
--arg release_tag "${RELEASE_TAG}" \
--arg release_name "${RELEASE_NAME}" \
--arg event "${EVENT}" \
- --arg new_release "${NEW_RELEASE}" \
- --arg duration "${DURATION}" \
--argjson color "${COLOR}" \
'
{
@@ -251,7 +152,7 @@ jobs:
]
+
(
- if ($event == "release" or $new_release == "true") then
+ if $event == "release" then
[
{name: "Release Tag", value: $release_tag, inline: true},
{name: "Release Name", value: $release_name, inline: true}
@@ -260,16 +161,6 @@ jobs:
[]
end
)
- +
- (
- if ($event == "workflow_run" and $duration != "") then
- [
- {name: "Duration", value: $duration, inline: true}
- ]
- else
- []
- end
- )
)
}
]
diff --git a/.github/workflows/pr-cleanup.yml b/.github/workflows/pr-cleanup.yml
index f0b7e86f..31588c23 100644
--- a/.github/workflows/pr-cleanup.yml
+++ b/.github/workflows/pr-cleanup.yml
@@ -1,14 +1,20 @@
name: PR cleanup
-# Removes the pr-- test builds when a pull request closes. Checks out nothing.
+# Every hour, removes the pr-- test builds of closed pull requests and says so in their build
+# comment. Checks out nothing. A schedule runs the default branch's copy of this file.
on:
- pull_request_target:
- types: [closed]
+ schedule:
+ - cron: '17 * * * *'
+ workflow_dispatch:
permissions:
contents: write
pull-requests: write
+concurrency:
+ group: pr-cleanup
+ cancel-in-progress: false
+
env:
GH_TOKEN: ${{ github.token }}
@@ -16,24 +22,33 @@ jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- - name: Remove the pull request releases, their tags and the note
- env:
- PR: ${{ github.event.pull_request.number }}
+ - name: Remove closed pull requests' releases, their tags and the note
run: |
set -euo pipefail
- # listed first: a failing call inside a process substitution would read as "nothing to remove"
- tags=$(gh api --paginate "repos/$GITHUB_REPOSITORY/releases" --jq ".[] | select(.prerelease and (.tag_name | startswith(\"pr-$PR-\"))) | .tag_name")
- [ -n "$tags" ] || echo "No test build for #$PR."
- while read -r tag; do
- [ -n "$tag" ] || continue
- # a publish run that saw the close may have removed it already: "release not found" is that outcome
- out=$(gh release delete --repo "$GITHUB_REPOSITORY" "$tag" --yes --cleanup-tag 2>&1) \
- || [[ "$out" == *"release not found"* ]] || { echo "$out" >&2; exit 1; }
- echo "removed $tag"
- done <<< "$tags"
- # also when nothing was left: an earlier attempt may have removed the builds and failed before this
marker=""
- id=$(gh api --paginate "repos/$GITHUB_REPOSITORY/issues/$PR/comments?per_page=100" --jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | startswith(\"$marker\"))) | .id" | head -n 1)
- if [ -n "$id" ] && [ "$id" != "null" ]; then
- gh api "repos/$GITHUB_REPOSITORY/issues/comments/$id" -X PATCH -f body="$marker"$'\n'"The test build for this pull request has been removed." >/dev/null
- fi
+ # set -e does not reach into a function called with ||, so every failure returns 1 itself
+ clean() { # $1 pull request, $2 its tags
+ local id tag out
+ id=$(gh api --paginate "repos/$GITHUB_REPOSITORY/issues/$1/comments?per_page=100" --jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | startswith(\"$marker\"))) | .id") || return 1
+ id=${id%%$'\n'*}
+ # the note first: once the builds are gone, this pull request is not visited again
+ if [ -n "$id" ] && [ "$id" != "null" ]; then
+ gh api "repos/$GITHUB_REPOSITORY/issues/comments/$id" -X PATCH -f body="$marker"$'\n'"The test build for this pull request has been removed." >/dev/null || return 1
+ fi
+ while read -r tag; do
+ # a publish run that saw the close may have removed it already: "release not found" is that outcome
+ out=$(gh release delete --repo "$GITHUB_REPOSITORY" "$tag" --yes --cleanup-tag 2>&1) \
+ || [[ "$out" == *"release not found"* ]] || { echo "$out" >&2; return 1; }
+ echo "removed $tag"
+ done <<< "$2"
+ }
+ # listed first: a failing call inside a process substitution would read as "nothing to remove"
+ tags=$(gh api --paginate "repos/$GITHUB_REPOSITORY/releases" --jq '.[] | select(.prerelease and (.tag_name | test("^pr-[0-9]+-"))) | .tag_name')
+ [ -n "$tags" ] || { echo "No test builds."; exit 0; }
+ rc=0
+ while read -r -u 3 pr; do
+ state=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$pr" --jq .state) || { echo "::error::cannot read #$pr"; rc=1; continue; }
+ [ "$state" = closed ] || continue
+ clean "$pr" "$(grep "^pr-$pr-" <<< "$tags")" || { echo "::error::could not clean up #$pr"; rc=1; }
+ done 3<<< "$(sed -E 's/^pr-([0-9]+)-.*/\1/' <<< "$tags" | sort -un)"
+ exit $rc
diff --git a/.github/workflows/pr-publish.yml b/.github/workflows/pr-publish.yml
index 6bcfe000..a8727eb8 100644
--- a/.github/workflows/pr-publish.yml
+++ b/.github/workflows/pr-publish.yml
@@ -4,7 +4,7 @@ name: PR publish
# publishes it as the pr-- pre-release, verifies what a server will fetch and keeps one
# comment on the pull request current. Never checks out or runs pull request code.
on:
- workflow_run:
+ workflow_run: # zizmor: ignore[dangerous-triggers] takes only the build artifact and never runs pull request code
workflows: ["PR build"]
types: [completed]
@@ -113,7 +113,7 @@ jobs:
set -euo pipefail
notes=$(mktemp)
{
- echo "Test build of pull request #$PR at ${HEAD_SHA::7}. Not a release: the next build of this pull request replaces it, closing the pull request removes it, and the next real release supersedes it on installed servers."
+ echo "Test build of pull request #$PR at ${HEAD_SHA::7}. Not a release: the next build of this pull request replaces it, PR cleanup removes it within an hour of the pull request closing, and the next real release supersedes it on installed servers."
echo
echo "Install: Plugins > Install Plugin > paste \`$INSTALL_URL\`"
} > "$notes"
@@ -180,8 +180,8 @@ jobs:
TAG: ${{ steps.meta.outputs.tag }}
run: |
set -euo pipefail
- # PR cleanup also runs on close; whichever gets there first removes the build, so "release not found"
- # here means cleanup did, and the build is gone either way
+ # PR cleanup's hourly sweep may get there first: "release not found" here means it did, and the build is gone
+ # either way
if [ "$(gh api "repos/$GITHUB_REPOSITORY/pulls/$PR" --jq .state)" != "open" ]; then
out=$(gh release delete --repo "$GITHUB_REPOSITORY" "$TAG" --cleanup-tag --yes 2>&1) \
|| [[ "$out" == *"release not found"* ]] || { echo "$out" >&2; exit 1; }
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 39d59c61..0f3a62ee 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -181,3 +181,29 @@ jobs:
CHANNEL: beta
BASE: ${{ env.BETA_BRANCH }}
run: bash "$SCRIPTS/plg_release_pr.sh"
+
+ # discord-notify.yml announces each published release; a failed run is announced only here
+ notify-failure:
+ name: Tell Discord the release failed
+ needs: release
+ if: failure()
+ runs-on: ubuntu-latest
+ permissions: {}
+ steps:
+ - name: Send the Discord notification
+ env:
+ WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
+ RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
+ run: |
+ set -euo pipefail
+ if [ -z "$WEBHOOK" ]; then
+ echo "::warning::DISCORD_WEBHOOK is not set, skipping notification"
+ exit 0
+ fi
+ json=$(jq -n --arg title "Release on $GITHUB_REF_NAME" --arg url "$RUN_URL" --arg actor "$GITHUB_ACTOR" \
+ --arg repo "$GITHUB_REPOSITORY" --arg timestamp "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
+ '{content: "❌ Release Failed", embeds: [{title: $title, url: $url, description: "The Release run failed: see its log.",
+ color: 10038562, timestamp: $timestamp,
+ fields: [{name: "Repository", value: $repo, inline: true}, {name: "Actor", value: $actor, inline: true}]}]}')
+ curl --fail-with-body --silent --show-error --connect-timeout 10 --max-time 30 \
+ -H "Content-Type: application/json" -d "$json" "$WEBHOOK"
From 4a614b93d9576805abf4dae8e2ca1c4452878301 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 08:15:14 +0800
Subject: [PATCH 42/94] ci: merge only the tested Dependabot head, and sweep
builds of deleted pull requests
A deleted pull request answers 404 and would fail every hourly sweep; its builds now go too. The release notes
and comments claim only what the sweep and the failure alert cover.
---
.github/workflows/ci.yml | 4 +++-
.github/workflows/pr-cleanup.yml | 23 +++++++++++++++--------
.github/workflows/pr-publish.yml | 2 +-
.github/workflows/release.yml | 2 +-
4 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 2616bb52..fbc3178e 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -124,5 +124,7 @@ jobs:
- name: Merge
env:
PR_URL: ${{ github.event.pull_request.html_url }}
+ # the head this run tested: a newer push merges only after its own run passes
+ HEAD_SHA: ${{ github.event.pull_request.head.sha }}
GH_TOKEN: ${{ github.token }}
- run: gh pr merge --merge "$PR_URL"
+ run: gh pr merge --merge --match-head-commit "$HEAD_SHA" "$PR_URL"
diff --git a/.github/workflows/pr-cleanup.yml b/.github/workflows/pr-cleanup.yml
index 31588c23..a096d977 100644
--- a/.github/workflows/pr-cleanup.yml
+++ b/.github/workflows/pr-cleanup.yml
@@ -1,7 +1,8 @@
name: PR cleanup
# Every hour, removes the pr-- test builds of closed pull requests and says so in their build
-# comment. Checks out nothing. A schedule runs the default branch's copy of this file.
+# comment. Checks out nothing. A schedule runs the default branch's copy of this file, and GitHub turns it off after
+# 60 days without repository activity: turn it back on from the Actions tab.
on:
schedule:
- cron: '17 * * * *'
@@ -27,10 +28,12 @@ jobs:
set -euo pipefail
marker=""
# set -e does not reach into a function called with ||, so every failure returns 1 itself
- clean() { # $1 pull request, $2 its tags
- local id tag out
- id=$(gh api --paginate "repos/$GITHUB_REPOSITORY/issues/$1/comments?per_page=100" --jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | startswith(\"$marker\"))) | .id") || return 1
- id=${id%%$'\n'*}
+ clean() { # $1 pull request, $2 its tags, $3 closed or gone (deleted, so no note to update)
+ local id="" tag out
+ if [ "$3" = closed ]; then
+ id=$(gh api --paginate "repos/$GITHUB_REPOSITORY/issues/$1/comments?per_page=100" --jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | startswith(\"$marker\"))) | .id") || return 1
+ id=${id%%$'\n'*}
+ fi
# the note first: once the builds are gone, this pull request is not visited again
if [ -n "$id" ] && [ "$id" != "null" ]; then
gh api "repos/$GITHUB_REPOSITORY/issues/comments/$id" -X PATCH -f body="$marker"$'\n'"The test build for this pull request has been removed." >/dev/null || return 1
@@ -47,8 +50,12 @@ jobs:
[ -n "$tags" ] || { echo "No test builds."; exit 0; }
rc=0
while read -r -u 3 pr; do
- state=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$pr" --jq .state) || { echo "::error::cannot read #$pr"; rc=1; continue; }
- [ "$state" = closed ] || continue
- clean "$pr" "$(grep "^pr-$pr-" <<< "$tags")" || { echo "::error::could not clean up #$pr"; rc=1; }
+ if ! state=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$pr" --jq .state 2>&1); then
+ # a deleted pull request answers 404: its builds go too, else every sweep would fail on it
+ [[ "$state" == *"(HTTP 404)"* ]] || { echo "::error::cannot read #$pr: $state"; rc=1; continue; }
+ state=gone
+ fi
+ case $state in closed | gone) ;; *) continue ;; esac
+ clean "$pr" "$(grep "^pr-$pr-" <<< "$tags")" "$state" || { echo "::error::could not clean up #$pr"; rc=1; }
done 3<<< "$(sed -E 's/^pr-([0-9]+)-.*/\1/' <<< "$tags" | sort -un)"
exit $rc
diff --git a/.github/workflows/pr-publish.yml b/.github/workflows/pr-publish.yml
index a8727eb8..0c250da7 100644
--- a/.github/workflows/pr-publish.yml
+++ b/.github/workflows/pr-publish.yml
@@ -113,7 +113,7 @@ jobs:
set -euo pipefail
notes=$(mktemp)
{
- echo "Test build of pull request #$PR at ${HEAD_SHA::7}. Not a release: the next build of this pull request replaces it, PR cleanup removes it within an hour of the pull request closing, and the next real release supersedes it on installed servers."
+ echo "Test build of pull request #$PR at ${HEAD_SHA::7}. Not a release: the next build of this pull request replaces it, PR cleanup's hourly sweep removes it after the pull request closes, and the next real release supersedes it on installed servers."
echo
echo "Install: Plugins > Install Plugin > paste \`$INSTALL_URL\`"
} > "$notes"
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 0f3a62ee..525a5f0d 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -182,7 +182,7 @@ jobs:
BASE: ${{ env.BETA_BRANCH }}
run: bash "$SCRIPTS/plg_release_pr.sh"
- # discord-notify.yml announces each published release; a failed run is announced only here
+ # discord-notify.yml announces each published release; a failed release job only here, a run that cannot start not at all
notify-failure:
name: Tell Discord the release failed
needs: release
From 10b8b4c16797817ab4c3c763062c62eb5d34a3a0 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 10:15:32 +0800
Subject: [PATCH 43/94] Finish each dataset step on a stop, and tell a busy
read-only mount from a failed check
The plugin's stop signals every process, so it could end zfs unmount, destroy or the remount part-way and log the
wrong outcome: each step now ignores the stop signals and the run ends once the step is done. The stop trap covers the
whole dataset loop, so a stop at a later share still sends the notice for an earlier one. A check killed outright
unmounts the private folder only when the dataset is there, and says where it is when that fails. A busy read-only
mount logs one plain line, as a busy destroy does. The notice no longer points to a log that Logging set to No leaves
empty.
---
.../emhttp/plugins/ca.mover.tuning/age_mover | 69 ++++--
.../ca.mover.tuning/languages/de_DE.txt | 2 +-
.../ca.mover.tuning/languages/en_US.txt | 2 +-
.../ca.mover.tuning/languages/fr_FR.txt | 2 +-
.../ca.mover.tuning/languages/ru_RU.txt | 2 +-
.../ca.mover.tuning/languages/zh_CN.txt | 2 +-
tests/age_mover/lib.sh | 31 ++-
tests/age_mover/test_dataset_stops.sh | 234 ++++++++++++++++++
tests/age_mover/test_datasets.sh | 84 +++----
9 files changed, 335 insertions(+), 93 deletions(-)
create mode 100644 tests/age_mover/test_dataset_stops.sh
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index ca458a6c..ddcbec3f 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -303,7 +303,8 @@ zfs_reason() { local r=${1%%$'\n'*}; printf '%s' "${r#*\': }"; }
# When zfs message $2 says dataset $1 is busy, logs one plain line and succeeds: something else holds it, so no notice
zfs_busy() {
- [[ $(zfs_reason "$2") == *busy* ]] || return 1
+ # at the end: mount.zfs's messages keep the dataset's name, which may hold the word
+ [[ $(zfs_reason "$2") == *busy ]] || return 1
mvlogger "ZFS dataset [$1] is busy, will not delete: a process or another mount, such as a container's, may hold it."
}
@@ -2629,6 +2630,12 @@ dataset_loses_unmounted() {
[ -z "$lost" ] || printf '%s' "$3${lost#"$2"}"
}
+# Run only inside $( ): ignores the stop signals there, so a stop that signals every process cannot end step $@ part-way
+finish_on_stop() {
+ trap '' TERM HUP INT
+ "$@"
+}
+
# Logs lines $3... and notes dataset $2 for dataset_problems_notice at severity $1 (failure outranks warning); fills
# processTheMoves' DATASET_PROBLEM and DATASET_PROBLEM_LEVEL
dataset_problem() {
@@ -2638,21 +2645,22 @@ dataset_problem() {
for line in "${@:3}"; do mvlogger "$line"; done
}
-# One notice for the run's dataset problems, which the log details: a problem that repeats notifies once a run
+# One notice naming the run's datasets with a problem: a problem that repeats notifies once a run
dataset_problems_notice() {
local ds names=""
for ds in "${SHARE_DATASETS[@]}"; do [ -z "${DATASET_PROBLEM[$ds]}" ] || names+="${names:+ }[$ds]"; done
- [ -z "$names" ] || mvlogger_t "Clean empty ZFS datasets did not finish for %s: see the mover log." "$DATASET_PROBLEM_LEVEL" "$names"
+ [ -z "$names" ] || mvlogger_t "Clean empty ZFS datasets did not finish for %s. The mover log has the details unless Log Mover Tuning plugin actions is set to No." \
+ "$DATASET_PROBLEM_LEVEL" "$names"
}
# Mounts dataset $1 again at its folder $2, unless the folder gained files that a mount would hide
remount_dataset() {
local err
# a write through /mnt/user while it was unmounted lands in the bare folder
- if [ -n "$(find "$2" -mindepth 1 -print -quit 2>/dev/null)" ]; then
+ if [ -n "$(finish_on_stop find "$2" -mindepth 1 -print -quit 2>/dev/null)" ]; then
dataset_problem failure "$1" "Failed to remount dataset [$1]" \
"Not remounting ZFS dataset [$1]: its folder $2 holds files that a mount would hide"
- elif ! err=$(zfs mount "$1" 2>&1); then
+ elif ! err=$(finish_on_stop zfs mount "$1" 2>&1); then
dataset_problem failure "$1" "Failed to remount dataset [$1]" "zfs: $(zfs_reason "$err")"
fi
}
@@ -2664,21 +2672,27 @@ dataset_kept() {
}
# Unmounts dataset $1 from folder $2 and destroys it if dataset_loses_unmounted at private folder $4 against $3 is empty;
-# else mounts it back. cleanShareDataset's stopped, set by a stop, skips the destroy
+# else tries to mount it back. processTheMoves' stopped, set by a stop, skips the destroy
unmount_check_destroy() {
local dataset=$1 folder=$2 private=$4 err lost rc
# stderr is discarded on both launch paths, so zfs's reason goes to the log
- if ! err=$(zfs unmount "$dataset" 2>&1); then
+ if ! err=$(finish_on_stop zfs unmount "$dataset" 2>&1); then
zfs_busy "$dataset" "$err" ||
dataset_problem failure "$dataset" "Failed to unmount ZFS dataset [${dataset}]" "zfs: $(zfs_reason "$err")"
return 0
fi
mvlogger "ZFS dataset [${dataset}] successfully unmounted."
# a file written between the first check and the unmount is in the dataset: checked again where nothing can write
- lost=$(dataset_loses_unmounted "$dataset" "$private" "$folder" "$3")
+ lost=$(finish_on_stop dataset_loses_unmounted "$dataset" "$private" "$folder" "$3")
rc=$?
- # the plugin's mover stop ends the check too, maybe while mounted
- [ "$rc" -le 2 ] || { umount "$private" 2>/dev/null; lost="the check was cut short"; }
+ # a check killed outright may leave the dataset at the private folder
+ if [ "$rc" -gt 2 ]; then
+ lost="the check was cut short"
+ if [ -n "$(finish_on_stop findmnt -no source --mountpoint "$private")" ] && ! err=$(finish_on_stop umount "$private" 2>&1); then
+ lost=$(zfs_reason "${err#umount: }")
+ rc=2
+ fi
+ fi
if [ "$rc" = 2 ]; then
dataset_problem failure "$dataset" \
"ZFS dataset [${dataset}] is still mounted read-only at ${private}, not at ${folder}: umount: $lost" \
@@ -2687,11 +2701,13 @@ unmount_check_destroy() {
elif [ -n "$stopped" ]; then
mvlogger "Mover stopped while ZFS dataset [${dataset}] was unmounted: not deleting it, attempting to remount"
elif [ "$rc" != 0 ]; then
- dataset_problem warning "$dataset" "ZFS dataset [${dataset}] could not be checked once unmounted, will not delete: $lost"
+ # a hold by something else, such as a container's mount, makes the read-only mount busy
+ zfs_busy "$dataset" "$lost" ||
+ dataset_problem warning "$dataset" "ZFS dataset [${dataset}] could not be checked once unmounted, will not delete: $lost"
elif [ -n "$lost" ]; then
mvlogger "Keeping ZFS dataset [${dataset}]: the check after the unmount found something a destroy could lose."
dataset_kept "$dataset" "$lost"
- elif ! err=$(zfs destroy "$dataset" 2>&1); then
+ elif ! err=$(finish_on_stop zfs destroy "$dataset" 2>&1); then
zfs_busy "$dataset" "$err" || dataset_problem failure "$dataset" \
"Failed to destroy ZFS dataset [${dataset}] — attempting to remount." "zfs: $(zfs_reason "$err")"
else
@@ -2702,9 +2718,9 @@ unmount_check_destroy() {
}
# Destroys dataset $1/$2 if it is mounted at /mnt/$1/$2, has no children or snapshots, and dataset_loses against $3/$2
-# is empty both before the unmount and after it; else keeps it mounted
+# is empty both before the unmount and after it; else keeps it, and the log says when it stays unmounted
cleanShareDataset() {
- local folder="/mnt/$1/$2" dataset="$1/$2" mounted names lost private stopped=""
+ local folder="/mnt/$1/$2" dataset="$1/$2" mounted names lost private
mounted=$(zfs_dataset_at "$folder")
[ -n "$mounted" ] || return 0
if [ "$mounted" != "$dataset" ]; then
@@ -2712,11 +2728,11 @@ cleanShareDataset() {
return 0
fi
# listed first, so between the content check and the unmount only a log line is written
- if ! names=$(zfs list -r -H -t filesystem,volume,snapshot -o name "$dataset" 2>&1); then
+ if ! names=$(finish_on_stop zfs list -r -H -t filesystem,volume,snapshot -o name "$dataset" 2>&1); then
mvlogger "ZFS dataset [${dataset}] could not be listed, will not delete: $(zfs_reason "$names")"
return 0
fi
- lost=$(dataset_loses "$folder" "$3/$2")
+ lost=$(finish_on_stop dataset_loses "$folder" "$3/$2")
if [ -n "$lost" ]; then
dataset_kept "$dataset" "$lost"
return 0
@@ -2725,19 +2741,17 @@ cleanShareDataset() {
mvlogger "ZFS dataset [${dataset}] has child datasets or snapshots, will not delete..."
return 0
fi
- if ! private=$(mktemp -d -t ca.mover.tuning.XXXXXX 2>&1); then
+ # a stop during the checks above ends the run before the unmount
+ [ -z "$stopped" ] || return 0
+ if ! private=$(finish_on_stop mktemp -d -t ca.mover.tuning.XXXXXX 2>&1); then
dataset_problem warning "$dataset" \
"ZFS dataset [${dataset}] could not be checked once unmounted, will not delete: mktemp: $(zfs_reason "${private#mktemp: }")"
return 0
fi
mvlogger "ZFS dataset [${dataset}] holds only folders the destination also has, attempting to unmount and delete..."
- # a stop lets the step in hand finish and the dataset go back: Unraid's mover stop signals the run, the plugin's all
- trap 'stopped=1' TERM HUP INT
unmount_check_destroy "$dataset" "$folder" "$3/$2" "$private"
- trap - TERM HUP INT
# a folder the dataset is still mounted on stays
rmdir "$private" 2>/dev/null
- [ -z "$stopped" ] || { dataset_problems_notice; exit 0; }
}
# Internal move engine
@@ -2779,7 +2793,7 @@ processTheMoves() {
local -a SHARE_DATASETS=()
local -A DATASET_PROBLEM=()
local DATASET_PROBLEM_LEVEL=""
- local top ds
+ local top ds stopped=""
# set by filesInUse the first time a file cannot be checked
local FILE_IN_USE_FAILURE_LOGGED=no
local -a FILES_IN_USE_CMD=()
@@ -3250,9 +3264,16 @@ processTheMoves() {
mvlogger "$(titleLine "Cleaning up" '-')"
movesEnd
moverStep "Cleaning up"
- # once per noted share, after the pass: a soft stop's break 2 lands here too
- for ds in "${SHARE_DATASETS[@]}"; do cleanShareDataset "${ds%%/*}" "${ds#*/}" "${DATASET_DEST[$ds]}"; done
+ # once per noted share, after the pass: a soft stop's break 2 lands here too. A stop lets the step in hand finish
+ # (Unraid's mover stop signals the run, the plugin's every process), tries the remount if one is due, then ends the run
+ trap 'stopped=1' TERM HUP INT
+ for ds in "${SHARE_DATASETS[@]}"; do
+ [ -z "$stopped" ] || break
+ cleanShareDataset "${ds%%/*}" "${ds#*/}" "${DATASET_DEST[$ds]}"
+ done
+ trap - TERM HUP INT
dataset_problems_notice
+ [ -z "$stopped" ] || exit 0
for top in "${TOP_FOLDERS[@]}"; do cleanTopFolder "$top"; done
if [ "$TESTMODE" != "yes" ] && [ ! -e $SOFTSTOPFILE ] && [ "$SYNCFAILED" = 0 ] &&
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt
index 5442874a..e4a89f52 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt
@@ -25,7 +25,7 @@ Cache → Array=Cache → Speicherverbund
Cancel=Abbrechen
Clean empty folders=Leere Ordner bereinigen
Clean empty ZFS datasets=Leere ZFS‑Datasets bereinigen
-Clean empty ZFS datasets did not finish for %s see the mover log=Leere ZFS‑Datasets bereinigen wurde für %s nicht abgeschlossen: siehe Protokoll.
+Clean empty ZFS datasets did not finish for %s The mover log has the details unless Log Mover Tuning plugin actions is set to No=Leere ZFS‑Datasets bereinigen wurde für %s nicht abgeschlossen. Details stehen im Protokoll, außer wenn „Aktionen des Mover‑Tuning‑Plugins protokollieren“ auf Nein steht.
CLI help commands=CLI‑Hilfebefehle
Comma separated list of file types=Kommagetrennte Liste von Dateitypen
Cron Schedule to force move all of files=Cron‑Zeitplan zum erzwungenen Verschieben aller Dateien
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt
index f2e323e2..3aa9ead2 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt
@@ -27,7 +27,7 @@ Cache → Array=
Cancel=
Clean empty folders=
Clean empty ZFS datasets=
-Clean empty ZFS datasets did not finish for %s see the mover log=Clean empty ZFS datasets did not finish for %s: see the mover log.
+Clean empty ZFS datasets did not finish for %s The mover log has the details unless Log Mover Tuning plugin actions is set to No=Clean empty ZFS datasets did not finish for %s. The mover log has the details unless Log Mover Tuning plugin actions is set to No.
CLI help commands=
Comma separated list of file types=
Cron Schedule to force move all of files=
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt
index 10a4d6c3..bd7dacbc 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt
@@ -25,7 +25,7 @@ Cache → Array=Cache → Array
Cancel=Annuler
Clean empty folders=Nettoyer les dossiers vides
Clean empty ZFS datasets=Nettoyer les datasets ZFS vides
-Clean empty ZFS datasets did not finish for %s see the mover log=Nettoyer les datasets ZFS vides n'a pas abouti pour %s : voir le journal.
+Clean empty ZFS datasets did not finish for %s The mover log has the details unless Log Mover Tuning plugin actions is set to No=Nettoyer les datasets ZFS vides n'a pas abouti pour %s. Le journal donne les détails, sauf si « Journaliser les actions du plugin Mover Tuning » est sur Non.
CLI help commands=Commandes d’aide CLI
Comma separated list of file types=Liste de types de fichiers séparés par des virgules
Cron Schedule to force move all of files=Cron pour forcer le déplacement de tous les fichiers
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt
index e82e26d6..f0662450 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt
@@ -25,7 +25,7 @@ Cache → Array=Кэш → Массив
Cancel=Отмена
Clean empty folders=Очистить пустые папки
Clean empty ZFS datasets=Очистить пустые ZFS‑датасеты
-Clean empty ZFS datasets did not finish for %s see the mover log=Очистка пустых ZFS‑датасетов не завершена для %s: см. журнал.
+Clean empty ZFS datasets did not finish for %s The mover log has the details unless Log Mover Tuning plugin actions is set to No=Очистка пустых ZFS‑датасетов не завершена для %s. Подробности в журнале, если «Журналировать действия плагина Mover Tuning» не установлено в Нет.
CLI help commands=Команды помощи CLI
Comma separated list of file types=Список типов файлов через запятую
Cron Schedule to force move all of files=Расписание Cron для принудительного перемещения всех файлов
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt
index ee3e1a7e..43d3992d 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt
@@ -24,7 +24,7 @@ Cache → Array=缓存 → 阵列
Cancel=取消
Clean empty folders=清理空文件夹
Clean empty ZFS datasets=清理空的 ZFS 数据集
-Clean empty ZFS datasets did not finish for %s see the mover log=清理空的 ZFS 数据集未能完成:%s,请查看日志。
+Clean empty ZFS datasets did not finish for %s The mover log has the details unless Log Mover Tuning plugin actions is set to No=清理空的 ZFS 数据集未能完成:%s。详情见日志,除非“记录 Mover Tuning 插件日志”设为“否”。
CLI help commands=命令行帮助
Comma separated list of file types=以逗号分隔的文件扩展名列表
Cron Schedule to force move all of files=强制移动所有文件的 Cron 计划
diff --git a/tests/age_mover/lib.sh b/tests/age_mover/lib.sh
index 392de61a..17b12e10 100644
--- a/tests/age_mover/lib.sh
+++ b/tests/age_mover/lib.sh
@@ -1,7 +1,7 @@
#!/bin/bash
# shellcheck disable=SC2034 # the settings set here are read by age_mover's functions, sourced from funcs.sh
# Sourced by test_*.sh: each age_mover case runs the real processTheMoves with real rsync and the shipped default.cfg read by the real
-# getMoverSettings; Unraid's move and notify, findmnt, zfs, mount and umount are stand-ins. It deletes the folders in ROOTS.
+# getMoverSettings; Unraid's move, notify, findmnt, zfs, mount, umount and rmdir are stand-ins. It deletes the folders in ROOTS.
HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
PLUGIN=$HERE/../../source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning
AM=${AM:-$PLUGIN/age_mover}
@@ -20,7 +20,9 @@ if [ "${AGE_MOVER_TEST:-}" != 1 ] || [ ! -e /.dockerenv ] || ! no_host_mount; th
exit 2
fi
-mkdir -p "$T/cwd" "$T/bin"
+mkdir -p "$T/cwd" "$T/bin" "$T/tmp"
+# mktemp's private folders stay inside the test folder
+export TMPDIR=$T/tmp
# root installs the move stand-in; the plain-user run uses the one root installed before it
if [ "$(id -u)" = 0 ]; then
mkdir -p /usr/libexec/unraid
@@ -59,7 +61,8 @@ fi
# and fails unanswered calls and each subcommand in $T/zfs.fail, with $T/zfs.reason (else zfs.fail) then a child's name
cat >"$T/bin/findmnt" <<'EOF'
#!/bin/bash
-l=$(awk -F'\t' -v p="${*: -1}" '$1 == p {print; exit}' "${0%/bin/findmnt}/zfs" 2>/dev/null)
+# zfs.private's lines are mount's, at a private folder
+l=$(cat "${0%/bin/findmnt}/zfs" "${0%/bin/findmnt}/zfs.private" 2>/dev/null | awk -F'\t' -v p="${*: -1}" '$1 == p {print; exit}')
[ -n "$l" ] || exit 0
case "$2" in
source) n=${l#*$'\t'}; [ "$n" != "$l" ] || n=${l#/mnt/}; echo "$n" ;;
@@ -102,13 +105,13 @@ case "$*" in
find "$d/zfs.store/$n" -mindepth 1 -maxdepth 1 -exec mv -t "$f" {} +
echo "$l" >>"$d/zfs"
;;
-# the dataset's files go with it, and OpenZFS removes an inherited mountpoint
-"destroy "*) rm -rf -- "$(entry "$d/zfs.off" | tail -n 1 | cut -f1)" "$d/zfs.store/$n" ;;
+# the dataset's files go with it; OpenZFS removes its folder only when nothing is in it
+"destroy "*) rmdir -- "$(entry "$d/zfs.off" | tail -n 1 | cut -f1)" 2>/dev/null; rm -rf -- "$d/zfs.store/$n" ;;
*) echo "zfs stand-in has no answer for: zfs $*" >&2; exit 1 ;;
esac
EOF
-# mount -t zfs -o ro,zfsutil DATASET DIR moves an unmounted dataset's files into an empty DIR outside /mnt, umount back; both
-# log to zfs.calls with a mktemp DIR as PRIVATE, run zfs.on_mount.zfs or zfs.on_umount, and fail on mount.zfs or umount
+# mount -t zfs -o ro,zfsutil DATASET DIR moves an unmounted dataset's files into an empty DIR outside /mnt, umount back. Both log
+# to zfs.calls (a mktemp DIR as PRIVATE), run zfs.on_mount.zfs or zfs.on_umount, fail on mount.zfs (zfs.reason: all it says) or umount
cat >"$T/bin/mount" <<'EOF'
#!/bin/bash
d=${0%/bin/mount}
@@ -119,8 +122,7 @@ echo "mount ${*:1:$#-1} $shown" >>"$d/zfs.calls"
[ $# = 6 ] && [ "$1 $2 $3 $4" = "-t zfs -o ro,zfsutil" ] || { echo "mount stand-in has no answer for: mount $*" >&2; exit 1; }
n=$5
if grep -qxF mount.zfs "$d/zfs.fail" 2>/dev/null; then
- r=$(cat "$d/zfs.reason" 2>/dev/null) || r=zfs.fail
- echo "filesystem '$n' cannot be mounted, $r" >&2
+ cat "$d/zfs.reason" >&2 2>/dev/null || echo "filesystem '$n' cannot be mounted, zfs.fail" >&2
exit 1
fi
case $p in /mnt | /mnt/*) echo "mount stand-in: $p is under /mnt" >&2; exit 1 ;; esac
@@ -165,6 +167,15 @@ chmod 755 "$T/bin/findmnt" "$T/bin/zfs" "$T/bin/mount" "$T/bin/umount" "$T/bin/r
PATH=$T/bin:$PATH
export NOTIFY_LOG=$T/notify
+# for the Clean ZFS datasets cases: a destroy's calls are list, unmount, the check at a private read-only mount, destroy
+LS='list -r -H -t filesystem,volume,snapshot -o name'
+DESTROYED=$(printf '%s\n' "zfs $LS cache/sh" 'zfs unmount cache/sh' 'mount -t zfs -o ro,zfsutil cache/sh PRIVATE' 'umount PRIVATE' \
+ 'zfs destroy cache/sh')
+notice_for() { echo "warning|Clean empty ZFS datasets did not finish for $1. The mover log has the details unless Log Mover Tuning plugin actions is set to No."; }
+NOTICE=$(notice_for '[cache/sh]')
+no_private() { check "no private mount folder left" "" "$(find "$TMPDIR" -maxdepth 1 -name 'ca.mover.tuning.*')"; }
+notices() { check "notices" "$1" "$(cat "$NOTIFY_LOG" 2>/dev/null)"; }
+
# age_mover runs its command on load, so only its functions and its top-level start values are taken
awk '/^[A-Za-z_][A-Za-z0-9_]*\(\) \{/,/^\}/' "$AM" >"$T/funcs.sh"
. "$T/funcs.sh"
@@ -207,7 +218,7 @@ begin() {
CASE=$1
shift
rm -rf "${ROOTS[@]}" "$SOFTSTOPFILE" "$PAUSEFILE" "$T/row_error" "$T/zfs" "$T/zfs".* "$T/after_rsync" "$T/bin/rsync" \
- "$MOVER_LOG" "$NOTIFY_LOG" "${TMPDIR:-/tmp}"/ca.mover.tuning.*
+ "$MOVER_LOG" "$NOTIFY_LOG" "$TMPDIR"/ca.mover.tuning.*
mkdir -p /mnt/cache /mnt/user0
fresh "$@"
}
diff --git a/tests/age_mover/test_dataset_stops.sh b/tests/age_mover/test_dataset_stops.sh
new file mode 100644
index 00000000..8777b42d
--- /dev/null
+++ b/tests/age_mover/test_dataset_stops.sh
@@ -0,0 +1,234 @@
+#!/bin/bash
+# Clean ZFS datasets: a stop lets the step in hand finish, mounts the dataset back where it can and ends the run after the
+# notice.
+. "$(dirname "$0")/lib.sh"
+
+# a hook, run once, that stops the mover: Unraid's stop signals the run alone; the plugin's is age_mover stop, run outside
+# the run, which signals every process of it. The hook waits for that stop to end
+stop_hook() {
+ cat <"$T/pid"
+( setsid bash -c '. "$T/funcs.sh"; PIDFILE="$T/pid" MOVER_STATUS="$T/mover.ini" PAUSEFILE="$T/pause" MOVINGFILE="$T/moving"; stop' \\
+ "$T/stop.out" 2>&1 & )
+for _ in \$(seq 100); do grep -qs 'mover: stopped' "$T/stop.out" && break; sleep 0.1; done
+EOF
+}
+# the plugin's stop ends with a sleep, then removes the pid and status files: it must end before the next case
+stop_done() {
+ local _
+ for _ in $(seq 100); do grep -qs 'mover: stopped' "$T/stop.out" && break; sleep 0.1; done
+ check "the plugin's stop ended" 'mover: stopped' "$(cat "$T/stop.out" 2>/dev/null)"
+ rm -f "$T/stop.out"
+}
+# a hook, run once after command $2, that sends signal $1 to every process from its caller up to, not including, the run
+kill_hook() {
+ cat <"$T/wrap/$1" <"$T/zfs"
+ row 'move from primary' f sh/only/f.txt | list
+}
+mounted_again() { check "the dataset is mounted at its folder again" /mnt/cache/sh "$(grep -x /mnt/cache/sh "$T/zfs")"; }
+REMOUNTED=$(sed '$d' <<<"$DESTROYED"; echo 'zfs mount cache/sh')
+
+# Unraid's stop during the check after the unmount, and a write through /mnt/user meanwhile, which keeps it unmounted
+begin "Clean ZFS datasets, Unraid's mover stop during the check after the unmount" cleanFolders topFolder cleanDatasets yes \
+ notify errorsOnly
+one_share
+{ stop_hook run; echo 'echo y >/mnt/cache/sh/bare.txt'; } >"$T/zfs.on_mount.zfs"
+run_moves 'processTheMoves did not return'
+check "zfs calls" "$(sed '$d' <<<"$DESTROYED")" "$(cat "$T/zfs.calls")"
+log_has 'Mover stopped while ZFS dataset [cache/sh] was unmounted: not deleting it, attempting to remount'
+log_has 'Not remounting ZFS dataset [cache/sh]: its folder /mnt/cache/sh holds files that a mount would hide'
+log_lacks 'successfully destroyed'
+check "the dataset is kept, unmounted" yes "$([ -d "$T/zfs.store/cache/sh" ] && echo yes)"
+cache_is sh sh/bare.txt
+no_private
+notices "$NOTICE"
+
+# the plugin's stop as each step runs: the step finishes, a destroy that finished stays done, else the dataset goes back
+for step in 'zfs list' 'zfs unmount' 'the read-only umount' 'zfs destroy' 'the remount'; do
+ begin "Clean ZFS datasets, the plugin's mover stop during $step" cleanFolders topFolder cleanDatasets yes
+ one_share
+ case $step in
+ 'zfs list') stop_hook plugin >"$T/zfs.on_list" ;;
+ 'zfs unmount') stop_hook plugin >"$T/zfs.on_unmount" ;;
+ 'the read-only umount') stop_hook plugin >"$T/zfs.on_umount" ;;
+ 'zfs destroy') stop_hook plugin >"$T/zfs.on_destroy" ;;
+ # a file that lands in the dataset as it unmounts keeps it, so it is mounted again
+ *) echo 'echo x >/mnt/cache/sh/new.txt' >"$T/zfs.on_unmount"; stop_hook plugin >"$T/zfs.on_mount" ;;
+ esac
+ run_moves 'processTheMoves did not return'
+ stop_done
+ log_lacks 'Failed to'
+ log_lacks 'could not be checked'
+ no_private
+ notices ''
+ # the run ends after the dataset checks, before the top-folder check
+ log_lacks 'top-level'
+ if [ "$step" = 'zfs list' ]; then
+ check "zfs calls" "zfs $LS cache/sh" "$(cat "$T/zfs.calls")"
+ log_lacks 'could not be listed'
+ check "the dataset stays mounted" /mnt/cache/sh "$(grep -x /mnt/cache/sh "$T/zfs")"
+ continue
+ fi
+ if [ "$step" = 'zfs destroy' ]; then
+ check "zfs calls" "$DESTROYED" "$(cat "$T/zfs.calls")"
+ log_has 'ZFS dataset [cache/sh] successfully destroyed.'
+ cache_is
+ continue
+ fi
+ check "zfs calls" "$REMOUNTED" "$(cat "$T/zfs.calls")"
+ check "no private mount left" "" "$(cat "$T/zfs.private" 2>/dev/null)"
+ mounted_again
+ if [ "$step" = 'the remount' ]; then
+ log_has 'Keeping ZFS dataset [cache/sh]: the check after the unmount found something a destroy could lose.'
+ cache_is sh sh/new.txt
+ else
+ log_has 'Mover stopped while ZFS dataset [cache/sh] was unmounted: not deleting it, attempting to remount'
+ cache_is sh
+ fi
+done
+
+# the plugin's stop as the remount's look into the bare folder runs: the look finishes and finds what a mount would hide
+begin "Clean ZFS datasets, the plugin's mover stop as the remount looks into the bare folder" cleanFolders topFolder \
+ cleanDatasets yes
+one_share
+wrap_hook find "/mnt/cache/sh -mindepth 1 -print -quit"
+echo 'echo x >/mnt/cache/sh/new.txt' >"$T/zfs.on_unmount"
+echo 'echo y >/mnt/cache/sh/bare.txt' >"$T/zfs.on_mount.zfs"
+stop_hook plugin >"$T/find.hook"
+PATH=$T/wrap:$PATH run_moves 'processTheMoves did not return'
+stop_done
+check "zfs calls" "$(sed '$d' <<<"$DESTROYED")" "$(cat "$T/zfs.calls")"
+log_has 'Not remounting ZFS dataset [cache/sh]: its folder /mnt/cache/sh holds files that a mount would hide'
+cache_is sh sh/bare.txt
+no_private
+notices "$NOTICE"
+
+# the plugin's stop as mktemp makes the private folder: it is made, so the unmount goes ahead and the dataset goes back
+begin "Clean ZFS datasets, the plugin's mover stop as the private folder is made" cleanFolders topFolder cleanDatasets yes
+one_share
+wrap_hook mktemp "-d -t ca.mover.tuning.XXXXXX"
+stop_hook plugin >"$T/mktemp.hook"
+PATH=$T/wrap:$PATH run_moves 'processTheMoves did not return'
+stop_done
+check "zfs calls" "$REMOUNTED" "$(cat "$T/zfs.calls")"
+log_has 'Mover stopped while ZFS dataset [cache/sh] was unmounted: not deleting it, attempting to remount'
+log_lacks 'could not be checked'
+mounted_again
+no_private
+notices ''
+
+# the plugin's stop signals the first check before the run: the check still finishes, so its find keeps the dataset
+# mounted, where a cut-short check would read as nothing to lose and unmount it
+begin "Clean ZFS datasets, a TERM to the first check before the run's" cleanFolders topFolder cleanDatasets yes
+mk cache sh/only/f.txt sh/keep.txt
+printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+row 'move from primary' f sh/only/f.txt | list
+wrap_hook find ". -mindepth 1 -path ./.zfs -prune -o ! -type d -print -quit"
+kill_hook TERM : >"$T/find.hook"
+PATH=$T/wrap:$PATH run_moves
+check "zfs calls" "zfs $LS cache/sh" "$(cat "$T/zfs.calls")"
+log_lacks 'attempting to unmount'
+cache_is sh sh/keep.txt
+notices ''
+
+# a stop during the next share's checks ends the run before its unmount and before the share after it, and still sends
+# the notice for the earlier one
+begin "Clean ZFS datasets, Unraid's mover stop during the next share's checks" cleanFolders topFolder cleanDatasets yes
+mk cache a/only/f.txt sh/only/g.txt z/only/h.txt
+printf '%s\n' /mnt/cache /mnt/cache/a /mnt/cache/sh /mnt/cache/z >"$T/zfs"
+# cache/a is kept, as a file lands in it as it unmounts, and cannot be mounted again
+echo 'echo x >/mnt/cache/a/new.txt' >"$T/zfs.on_unmount"
+echo mount >"$T/zfs.fail"
+{ echo "tail -n 1 \"$T/zfs.calls\" | grep -q ' cache/sh\$' || exit 0"; stop_hook run; } >"$T/zfs.on_list"
+{ row 'move from primary' f a/only/f.txt; row 'move from primary' f sh/only/g.txt; row 'move from primary' f z/only/h.txt; } | list
+run_moves 'processTheMoves did not return'
+log_has 'Failed to remount dataset [cache/a]'
+log_lacks 'ZFS dataset [cache/sh] holds only folders'
+check "cache/sh is still mounted" /mnt/cache/sh "$(grep -x /mnt/cache/sh "$T/zfs")"
+check "the share after it is not looked at" "" "$(grep -F cache/z "$T/zfs.calls")"
+notices "$(notice_for '[cache/a]')"
+no_private
+
+# a check killed outright, not by a stop: the run unmounts the private folder if the dataset is there, then mounts it back,
+# or says where it is and how to mount it back when that umount fails
+for when in 'before the read-only mount' 'while it is mounted' 'while it is mounted, and the clean-up umount fails' \
+ 'while it is mounted, and the plugin stops the mover during the clean-up umount' \
+ 'while it is mounted, and the plugin stops the mover as the run looks for the private mount'; do
+ begin "Clean ZFS datasets, the check after the unmount is killed $when" cleanFolders topFolder cleanDatasets yes
+ one_share
+ case $when in
+ before*) kill_hook KILL : >"$T/zfs.on_mount.zfs" ;;
+ *fails) kill_hook KILL "echo umount >\"$T/zfs.fail\"" >"$T/zfs.on_umount" ;;
+ # the stop's hook takes the hook's place for the clean-up umount, which finishes and puts the dataset back
+ *during*) stop_hook plugin >"$T/stop.hook"; kill_hook KILL "cp \"$T/stop.hook\" \"$T/zfs.on_umount\"" >"$T/zfs.on_umount" ;;
+ # the look finishes, so the clean-up umount runs
+ *looks*)
+ wrap_hook findmnt "-no source --mountpoint $TMPDIR/ca.mover.tuning."
+ stop_hook plugin >"$T/stop.hook"
+ kill_hook KILL "cp \"$T/stop.hook\" \"$T/findmnt.hook\"" >"$T/zfs.on_umount"
+ ;;
+ *) kill_hook KILL : >"$T/zfs.on_umount" ;;
+ esac
+ if [[ $when == *mover* ]]; then
+ PATH=$T/wrap:$PATH run_moves 'processTheMoves did not return'
+ stop_done
+ else
+ run_moves
+ fi
+ private=$(find "$TMPDIR" -maxdepth 1 -name 'ca.mover.tuning.*')
+ case $when in
+ before*) calls=$(sed '$d' <<<"$REMOUNTED" | sed '$d'; echo 'zfs mount cache/sh') ;;
+ *fails) calls=$(sed '$d' <<<"$DESTROYED"; echo 'umount PRIVATE') ;;
+ *) calls=$(sed '$d' <<<"$DESTROYED"; printf '%s\n' 'umount PRIVATE' 'zfs mount cache/sh') ;;
+ esac
+ check "zfs calls" "$calls" "$(cat "$T/zfs.calls")"
+ log_lacks 'successfully destroyed'
+ if [[ $when == *mover* ]]; then
+ log_has 'Mover stopped while ZFS dataset [cache/sh] was unmounted: not deleting it, attempting to remount'
+ log_lacks 'still mounted read-only'
+ notices ''
+ mounted_again
+ no_private
+ continue
+ fi
+ notices "$NOTICE"
+ if [[ $when == *fails ]]; then
+ log_has "ZFS dataset [cache/sh] is still mounted read-only at $private, not at /mnt/cache/sh: umount: $private: zfs.fail"
+ log_has "To mount it back: umount $private, then zfs mount cache/sh"
+ check "the dataset stays at the private folder" "$private"$'\t'cache/sh "$(cat "$T/zfs.private")"
+ continue
+ fi
+ log_has 'ZFS dataset [cache/sh] could not be checked once unmounted, will not delete: the check was cut short'
+ mounted_again
+ no_private
+done
+
+finish
diff --git a/tests/age_mover/test_datasets.sh b/tests/age_mover/test_datasets.sh
index 17b4d1b3..4ac607dd 100644
--- a/tests/age_mover/test_datasets.sh
+++ b/tests/age_mover/test_datasets.sh
@@ -24,24 +24,6 @@ if [ "${1:-}" = --as-tester ]; then
exit
fi
-LS='list -r -H -t filesystem,volume,snapshot -o name'
-# a destroy's calls: list, unmount, the check at a private read-only mount, destroy
-DESTROYED=$(printf '%s\n' "zfs $LS cache/sh" 'zfs unmount cache/sh' 'mount -t zfs -o ro,zfsutil cache/sh PRIVATE' 'umount PRIVATE' \
- 'zfs destroy cache/sh')
-NOTICE='warning|Clean empty ZFS datasets did not finish for [cache/sh]: see the mover log.'
-no_private() { check "no private mount folder left" "" "$(find "${TMPDIR:-/tmp}" -maxdepth 1 -name 'ca.mover.tuning.*')"; }
-notices() { check "notices" "$1" "$(cat "$NOTIFY_LOG" 2>/dev/null)"; }
-# a hook, run once, that stops the mover: Unraid's stop signals the run alone, the plugin's every process from the hook's
-# caller up to the run
-stop_hook() {
- cat <"$T/zfs"
-{ stop_hook run; echo 'echo y >/mnt/cache/sh/bare.txt'; } >"$T/zfs.on_mount.zfs"
-row 'move from primary' f sh/only/f.txt | list
-run_moves 'processTheMoves did not return'
-check "zfs calls" "$(sed '$d' <<<"$DESTROYED")" "$(cat "$T/zfs.calls")"
-log_has 'Mover stopped while ZFS dataset [cache/sh] was unmounted: not deleting it, attempting to remount'
-log_has 'Not remounting ZFS dataset [cache/sh]: its folder /mnt/cache/sh holds files that a mount would hide'
-log_lacks 'successfully destroyed'
-check "the dataset is kept, unmounted" yes "$([ -d "$T/zfs.store/cache/sh" ] && echo yes)"
-cache_is sh sh/bare.txt
-no_private
-notices "$NOTICE"
-
-# the plugin's stop also ends the check, here as it unmounts the private folder: the run unmounts it, then mounts the dataset
-begin "Clean ZFS datasets, the plugin's mover stop during the check after the unmount" cleanFolders topFolder cleanDatasets yes
-mk cache sh/only/f.txt
-printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
-stop_hook tree >"$T/zfs.on_umount"
-row 'move from primary' f sh/only/f.txt | list
-run_moves 'processTheMoves did not return'
-check "zfs calls" "$(sed '$d' <<<"$DESTROYED"; printf '%s\n' 'umount PRIVATE' 'zfs mount cache/sh')" "$(cat "$T/zfs.calls")"
-log_has 'Mover stopped while ZFS dataset [cache/sh] was unmounted: not deleting it, attempting to remount'
-log_lacks 'Failed to'
-check "no private mount left" "" "$(cat "$T/zfs.private" 2>/dev/null)"
-check "the dataset is mounted again" /mnt/cache/sh "$(grep -x /mnt/cache/sh "$T/zfs")"
-cache_is sh
-no_private
-notices ''
-
# one notice for the run at its worst level: an unmount that fails, then a check that fails, still reach errorsOnly
begin "Clean ZFS datasets, two datasets fail" cleanFolders topFolder cleanDatasets yes notify errorsOnly
mk cache a/only/f.txt sh/only/g.txt
@@ -189,7 +137,7 @@ run_moves
log_has 'Failed to unmount ZFS dataset [cache/a]'
log_has 'zfs: not currently mounted'
log_has "ZFS dataset [cache/sh] could not be checked once unmounted, will not delete: mount: filesystem 'cache/sh' cannot be mounted, zfs.fail"
-notices 'warning|Clean empty ZFS datasets did not finish for [cache/a] [cache/sh]: see the mover log.'
+notices "$(notice_for '[cache/a] [cache/sh]')"
no_private
# the kept name never passed the planner: a newline in it must not end the debug line before debug_mover mangles it
@@ -294,7 +242,7 @@ done
# errorsOnly sends only a failure: a failed unmount, destroy or remount, or a dataset left at the private folder, notifies;
# a check that cannot run only warns
for fail in list unmount 'unmount, busy,' destroy 'destroy and mount' 'destroy, busy,' 'the read-only mount' \
- 'the read-only unmount' mktemp; do
+ 'the read-only mount, busy,' 'the read-only unmount' mktemp; do
what="zfs $fail"
[[ $fail != the* && $fail != mktemp ]] || what=$fail
begin "Clean ZFS datasets, $what fails" cleanFolders topFolder cleanDatasets yes notify errorsOnly
@@ -305,6 +253,8 @@ for fail in list unmount 'unmount, busy,' destroy 'destroy and mount' 'destroy,
'unmount, busy,') echo unmount; echo 'pool or dataset is busy' >"$T/zfs.reason" ;;
'destroy, busy,') echo destroy; echo 'dataset is busy' >"$T/zfs.reason" ;;
'the read-only mount') echo mount.zfs ;;
+ # as OpenZFS says it while a container's mount holds the dataset
+ 'the read-only mount, busy,') echo mount.zfs; echo 'zfs_mount_at() failed: mountpoint or dataset is busy' >"$T/zfs.reason" ;;
'the read-only unmount') echo umount ;;
mktemp) ;;
*) echo "$fail" ;;
@@ -326,6 +276,7 @@ for fail in list unmount 'unmount, busy,' destroy 'destroy and mount' 'destroy,
*busy*)
log_has "ZFS dataset [cache/sh] is busy, will not delete: a process or another mount, such as a container's, may hold it."
log_lacks "Failed to ${fail%%,*}"
+ log_lacks "$unchecked"
;;
*) log_has "Failed to ${fail%% *} ZFS dataset [cache/sh]"; log_has 'zfs: zfs.fail' ;;
esac
@@ -371,6 +322,31 @@ cache_is sh sh/new.txt
no_private
notices "$NOTICE"
+# a write through /mnt/user during the check lands in the bare folder: the destroy goes ahead, and OpenZFS keeps a folder
+# that is not empty
+begin "Clean ZFS datasets, a file lands in the unmounted share's folder during the check" cleanFolders topFolder cleanDatasets yes
+mk cache sh/only/f.txt
+printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+echo 'echo y >/mnt/cache/sh/bare.txt' >"$T/zfs.on_mount.zfs"
+row 'move from primary' f sh/only/f.txt | list
+run_moves
+check "zfs calls" "$DESTROYED" "$(cat "$T/zfs.calls")"
+log_has 'ZFS dataset [cache/sh] successfully destroyed.'
+cache_is sh sh/bare.txt
+no_private
+notices ''
+
+# only a reason that ends in busy is a hold: mount.zfs's message names the dataset, here one with busy in its name
+begin "Clean ZFS datasets, the read-only mount of a dataset named busybox fails" cleanFolders topFolder cleanDatasets yes
+mk cache busybox/only/f.txt
+printf '%s\n' /mnt/cache /mnt/cache/busybox >"$T/zfs"
+echo mount.zfs >"$T/zfs.fail"
+row 'move from primary' f busybox/only/f.txt | list
+run_moves
+log_has "ZFS dataset [cache/busybox] could not be checked once unmounted, will not delete: mount: filesystem 'cache/busybox' cannot be mounted, zfs.fail"
+log_lacks 'is busy'
+notices "$(notice_for '[cache/busybox]')"
+
id tester >/dev/null 2>&1 || useradd -M tester
U=/tmp/age_mover_tester
# a find that fails keeps the dataset: the file the plain user cannot see would go with it
From 05441cd8a466090b986655aad51896404dcd6a64 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 14:42:20 +0800
Subject: [PATCH 44/94] Report a write the remount hides, and let stop wait for
the run
- The remount looks inside the folder after mounting, so a file written
as it is mounted is logged with the steps to reach it.
- A check whose mount is made but reported as failed is found at the
private folder and unmounted; a dataset left there is named, with its
location, in the notice.
- A failed check is reported even when a stop arrives; the notice is
sent under the stop's protection, and turbo write is put back.
- stop waits up to a minute for the run, and removes the pid and status
files only while they still name it.
---
.../emhttp/plugins/ca.mover.tuning/age_mover | 90 +++++++++++++-----
.../ca.mover.tuning/languages/de_DE.txt | 1 +
.../ca.mover.tuning/languages/en_US.txt | 1 +
.../ca.mover.tuning/languages/fr_FR.txt | 1 +
.../ca.mover.tuning/languages/ru_RU.txt | 1 +
.../ca.mover.tuning/languages/zh_CN.txt | 1 +
tests/age_mover/lib.sh | 18 +++-
tests/age_mover/test_dataset_stops.sh | 95 +++++++++++++++----
tests/age_mover/test_datasets.sh | 59 +++++++++++-
9 files changed, 214 insertions(+), 53 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index ddcbec3f..c3684b71 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -2637,9 +2637,9 @@ finish_on_stop() {
}
# Logs lines $3... and notes dataset $2 for dataset_problems_notice at severity $1 (failure outranks warning); fills
-# processTheMoves' DATASET_PROBLEM and DATASET_PROBLEM_LEVEL
+# processTheMoves' DATASET_PROBLEM (the dataset's entry in the notice) and DATASET_PROBLEM_LEVEL
dataset_problem() {
- DATASET_PROBLEM[$2]=1
+ DATASET_PROBLEM[$2]=${DATASET_PROBLEM[$2]:-[$2]}
[ "$DATASET_PROBLEM_LEVEL" = failure ] || DATASET_PROBLEM_LEVEL=$1
local line
for line in "${@:3}"; do mvlogger "$line"; done
@@ -2648,20 +2648,33 @@ dataset_problem() {
# One notice naming the run's datasets with a problem: a problem that repeats notifies once a run
dataset_problems_notice() {
local ds names=""
- for ds in "${SHARE_DATASETS[@]}"; do [ -z "${DATASET_PROBLEM[$ds]}" ] || names+="${names:+ }[$ds]"; done
+ for ds in "${SHARE_DATASETS[@]}"; do [ -z "${DATASET_PROBLEM[$ds]}" ] || names+="${names:+ }${DATASET_PROBLEM[$ds]}"; done
[ -z "$names" ] || mvlogger_t "Clean empty ZFS datasets did not finish for %s. The mover log has the details unless Log Mover Tuning plugin actions is set to No." \
"$DATASET_PROBLEM_LEVEL" "$names"
}
+# Mounts dataset $1 at its folder $2 and prints the first entry the mount hides, seen through . from inside the folder
+# (none when there is no folder); prints zfs's message and fails when the mount fails
+mount_back() {
+ local err inside=""
+ cd "$2" 2>/dev/null && inside=1
+ err=$(zfs mount "$1" 2>&1) || { printf '%s' "$err"; return 1; }
+ [ -z "$inside" ] || find . -mindepth 1 -print -quit 2>/dev/null
+ return 0
+}
+
# Mounts dataset $1 again at its folder $2, unless the folder gained files that a mount would hide
remount_dataset() {
- local err
+ local out
# a write through /mnt/user while it was unmounted lands in the bare folder
if [ -n "$(finish_on_stop find "$2" -mindepth 1 -print -quit 2>/dev/null)" ]; then
dataset_problem failure "$1" "Failed to remount dataset [$1]" \
"Not remounting ZFS dataset [$1]: its folder $2 holds files that a mount would hide"
- elif ! err=$(finish_on_stop zfs mount "$1" 2>&1); then
- dataset_problem failure "$1" "Failed to remount dataset [$1]" "zfs: $(zfs_reason "$err")"
+ elif ! out=$(finish_on_stop mount_back "$1" "$2"); then
+ dataset_problem failure "$1" "Failed to remount dataset [$1]" "zfs: $(zfs_reason "$out")"
+ elif [ -n "$out" ]; then
+ dataset_problem failure "$1" "ZFS dataset [$1] is mounted again, but $2/${out#./}, written as it was mounted, is hidden under it" \
+ "To reach it: stop writes to the share, zfs unmount $1, move anything in $2 aside, zfs mount $1, then move it back into $2"
fi
}
@@ -2685,25 +2698,28 @@ unmount_check_destroy() {
# a file written between the first check and the unmount is in the dataset: checked again where nothing can write
lost=$(finish_on_stop dataset_loses_unmounted "$dataset" "$private" "$folder" "$3")
rc=$?
- # a check killed outright may leave the dataset at the private folder
- if [ "$rc" -gt 2 ]; then
- lost="the check was cut short"
- if [ -n "$(finish_on_stop findmnt -no source --mountpoint "$private")" ] && ! err=$(finish_on_stop umount "$private" 2>&1); then
+ # a failed or killed check may leave the dataset at the private folder: mount.zfs can fail after mounting
+ if [ "$rc" != 0 ] && [ "$rc" != 2 ]; then
+ [ "$rc" = 1 ] || lost="the check was cut short"
+ if [ "$(finish_on_stop findmnt -no source --mountpoint "$private")" = "$dataset" ] &&
+ ! err=$(finish_on_stop umount "$private" 2>&1); then
lost=$(zfs_reason "${err#umount: }")
rc=2
fi
fi
if [ "$rc" = 2 ]; then
+ # with action logging off the notice is all there is, so it says where the dataset is
+ DATASET_PROBLEM[$dataset]="[$dataset] ($(translate_text "mounted read-only at %s" "$private"))"
dataset_problem failure "$dataset" \
"ZFS dataset [${dataset}] is still mounted read-only at ${private}, not at ${folder}: umount: $lost" \
- "To mount it back: umount ${private}, then zfs mount ${dataset}"
+ "To mount it back: stop writes to the share, umount ${private}, move anything in ${folder} aside, zfs mount ${dataset}, then move it back into ${folder}"
return 0
- elif [ -n "$stopped" ]; then
- mvlogger "Mover stopped while ZFS dataset [${dataset}] was unmounted: not deleting it, attempting to remount"
elif [ "$rc" != 0 ]; then
# a hold by something else, such as a container's mount, makes the read-only mount busy
zfs_busy "$dataset" "$lost" ||
dataset_problem warning "$dataset" "ZFS dataset [${dataset}] could not be checked once unmounted, will not delete: $lost"
+ elif [ -n "$stopped" ]; then
+ mvlogger "Mover stopped while ZFS dataset [${dataset}] was unmounted: not deleting it, attempting to remount"
elif [ -n "$lost" ]; then
mvlogger "Keeping ZFS dataset [${dataset}]: the check after the unmount found something a destroy could lose."
dataset_kept "$dataset" "$lost"
@@ -2793,7 +2809,7 @@ processTheMoves() {
local -a SHARE_DATASETS=()
local -A DATASET_PROBLEM=()
local DATASET_PROBLEM_LEVEL=""
- local top ds stopped=""
+ local top ds notice_lines stopped=""
# set by filesInUse the first time a file cannot be checked
local FILE_IN_USE_FAILURE_LOGGED=no
local -a FILES_IN_USE_CMD=()
@@ -3264,16 +3280,24 @@ processTheMoves() {
mvlogger "$(titleLine "Cleaning up" '-')"
movesEnd
moverStep "Cleaning up"
- # once per noted share, after the pass: a soft stop's break 2 lands here too. A stop lets the step in hand finish
- # (Unraid's mover stop signals the run, the plugin's every process), tries the remount if one is due, then ends the run
+ # once per noted share, after the pass: a soft stop's break 2 lands here too. A stop, whether it signals the run alone
+ # or every process (the plugin's), lets the step in hand finish, then the remount if one is due and the notice, and
+ # ends the run
trap 'stopped=1' TERM HUP INT
for ds in "${SHARE_DATASETS[@]}"; do
[ -z "$stopped" ] || break
cleanShareDataset "${ds%%/*}" "${ds#*/}" "${DATASET_DEST[$ds]}"
done
+ # the notice's log lines come back out of the $( )
+ notice_lines=$(finish_on_stop dataset_problems_notice)
+ [ -z "$notice_lines" ] || printf '%s\n' "$notice_lines"
trap - TERM HUP INT
- dataset_problems_notice
- [ -z "$stopped" ] || exit 0
+ if [ -n "$stopped" ]; then
+ restore_turbo
+ # the plugin's stop removes these once the run has ended; a stop that signals the run alone leaves them
+ [ "$(cat "$PIDFILE" 2>/dev/null)" != "$$" ] || rm -f "$PIDFILE" "$MOVER_STATUS" "$PAUSEFILE" "$MOVINGFILE"
+ exit 0
+ fi
for top in "${TOP_FOLDERS[@]}"; do cleanTopFolder "$top"; done
if [ "$TESTMODE" != "yes" ] && [ ! -e $SOFTSTOPFILE ] && [ "$SYNCFAILED" = 0 ] &&
@@ -3300,11 +3324,15 @@ processTheMoves() {
done
fi
- if [ $ENABLETURBO = "yes" ]; then
- turbo_write_mode=$(cat /var/local/emhttp/var.ini | grep "md_write_method=" | cut -d'"' -f2)
- mvlogger "Restoring original turbo write mode $( ([ $turbo_write_mode = "auto" ] && echo "Auto (read/modify/write)") || ([ $turbo_write_mode -eq 1 ] && echo "Turbo writes (Reconstruct)") || echo "Read/modify/write")"
- [ $TESTMODE != "yes" ] && /usr/local/sbin/mdcmd set md_write_method $turbo_write_mode
- fi
+ restore_turbo
+}
+
+# Sets the write method back from the turbo write that processTheMoves forced on
+restore_turbo() {
+ [ "$ENABLETURBO" = "yes" ] || return 0
+ turbo_write_mode=$(cat /var/local/emhttp/var.ini | grep "md_write_method=" | cut -d'"' -f2)
+ mvlogger "Restoring original turbo write mode $( ([ $turbo_write_mode = "auto" ] && echo "Auto (read/modify/write)") || ([ $turbo_write_mode -eq 1 ] && echo "Turbo writes (Reconstruct)") || echo "Read/modify/write")"
+ [ $TESTMODE != "yes" ] && /usr/local/sbin/mdcmd set md_write_method $turbo_write_mode
}
# The settings pages cannot offer this combination, so it only arrives by saving a
@@ -3598,13 +3626,25 @@ killtree() {
# Caution: stopping mover like this can lead to partial files on the destination
# and possible incomplete hard link transfer. Not recommended to do this.
stop() {
+ local pid waited=0
if [ ! -f $PIDFILE ]; then
echo "mover: not running"
exit 0
fi
- killtree $(cat $PIDFILE)
+ pid=$(cat $PIDFILE)
+ killtree $pid
sleep 2
- rm -f $PIDFILE $MOVER_STATUS $PAUSEFILE $MOVINGFILE
+ # a run cleaning ZFS datasets first finishes the step in hand and mounts the dataset back; its pid file keeps another
+ # run from starting meanwhile
+ if kill -0 "$pid" 2>/dev/null; then
+ echo "mover: waiting for the run to end"
+ while kill -0 "$pid" 2>/dev/null; do
+ [ $((waited += 1)) -le 60 ] || { echo "mover: the run (pid $pid) has not ended after a minute"; exit 1; }
+ sleep 1
+ done
+ fi
+ # a run started since this one ended owns them now; a run stopped while cleaning datasets has removed its own
+ [ "$(cat $PIDFILE 2>/dev/null)" != "$pid" ] || rm -f $PIDFILE $MOVER_STATUS $PAUSEFILE $MOVINGFILE
echo "mover: stopped"
exit
}
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt
index e4a89f52..ae559352 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt
@@ -79,6 +79,7 @@ Logs parent folder for Mover Tuning plugin=Übergeordneter Ordner für Protokoll
Low=Niedrig
Maintainers=Betreuer
make those plugins with ❤️ and a lot of ☕=machen diese Plugins mit ❤️ und viel ☕
+mounted read-only at %s=schreibgeschützt eingehängt unter %s
Move ALL files from current pool ignores filters and thresholds=ALLE Dateien aus dem aktuellen Pool verschieben (ohne Filter und Schwellenwerte)
Move ALL files to current pool ignores filters and thresholds=ALLE Dateien in den aktuellen Pool verschieben (ohne Filter und Schwellenwerte)
Move All from Primary->Secondary cacheyes shares pool percentage=Alles vom Primärspeicher → Sekundärspeicher verschieben (cache:yes) – Pool‑Prozent
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt
index 3aa9ead2..1022cbc8 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt
@@ -81,6 +81,7 @@ Logs parent folder for Mover Tuning plugin=
Low=
Maintainers=
make those plugins with ❤️ and a lot of ☕=make those plugins with ❤️ (and a lot of ☕).
+mounted read-only at %s=mounted read-only at %s
Move ALL files from current pool ignores filters and thresholds=Move **ALL** files from current pool (ignores filters and thresholds)
Move ALL files to current pool ignores filters and thresholds=Move **ALL** files to current pool (ignores filters and thresholds)
Move All from Primary->Secondary cacheyes shares pool percentage=Move All from Primary->Secondary (cache:yes) shares pool percentage
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt
index bd7dacbc..776d5b02 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt
@@ -79,6 +79,7 @@ Logs parent folder for Mover Tuning plugin=Dossier parent des journaux du plugin
Low=Faible
Maintainers=Mainteneurs
make those plugins with ❤️ and a lot of ☕=créent ces plugins avec ❤️ et beaucoup de ☕
+mounted read-only at %s=monté en lecture seule sur %s
Move ALL files from current pool ignores filters and thresholds=Déplacer **TOUS** les fichiers du pool actuel (en ignorant les filtres et les seuils)
Move ALL files to current pool ignores filters and thresholds=Déplacer **TOUS** les fichiers vers le pool actuel (en ignorant les filtres et les seuils)
Move All from Primary->Secondary cacheyes shares pool percentage=Déplacer tout depuis Primaire→Secondaire (cache:yes) selon le pourcentage du pool
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt
index f0662450..8540dcae 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt
@@ -79,6 +79,7 @@ Logs parent folder for Mover Tuning plugin=Родительская папка
Low=Низкий
Maintainers=Сопровождающие
make those plugins with ❤️ and a lot of ☕=создаём эти плагины с ❤️ (и большим количеством ☕).
+mounted read-only at %s=смонтирован только для чтения в %s
Move ALL files from current pool ignores filters and thresholds=Переместить **ВСЕ** файлы из текущего пула (независимо от фильтров и порогов)
Move ALL files to current pool ignores filters and thresholds=Переместить **ВСЕ** файлы в текущий пул (независимо от фильтров и порогов)
Move All from Primary->Secondary cacheyes shares pool percentage=Переместить всё из Основного->Вторичного (cache:yes) — процент заполнения пула шар
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt
index 43d3992d..ad44a215 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt
@@ -78,6 +78,7 @@ Logs parent folder for Mover Tuning plugin=日志文件保存路径
Low=低
Maintainers=维护者
make those plugins with ❤️ and a lot of ☕=用 ❤️(和很多 ☕)制作了这些插件。
+mounted read-only at %s=以只读方式挂载于 %s
Move ALL files from current pool ignores filters and thresholds=从当前存储池移出**所有**文件(无视过滤条件和阈值)
Move ALL files to current pool ignores filters and thresholds=将**所有**文件移入当前存储池(无视过滤条件和阈值)
Move All from Primary->Secondary cacheyes shares pool percentage=主存储->次存储(cache:yes)共享全部移动的存储池百分比
diff --git a/tests/age_mover/lib.sh b/tests/age_mover/lib.sh
index 17b12e10..02cba1c0 100644
--- a/tests/age_mover/lib.sh
+++ b/tests/age_mover/lib.sh
@@ -49,7 +49,9 @@ EOF
mkdir -p /usr/local/emhttp/webGui/scripts
cat >/usr/local/emhttp/webGui/scripts/notify <<'EOF'
#!/bin/bash
-# stand-in for Unraid's notify: each notice's importance and description, as one line in $NOTIFY_LOG
+# stand-in for Unraid's notify: each notice's importance and description, as one line in $NOTIFY_LOG, after the
+# $NOTIFY_LOG.hook a case puts there
+[ ! -f "${NOTIFY_LOG:?}.hook" ] || bash "$NOTIFY_LOG.hook"
while getopts 's:d:i:l:' o; do
case $o in d) desc=$OPTARG ;; i) imp=$OPTARG ;; s | l) ;; *) exit 1 ;; esac
done
@@ -89,7 +91,8 @@ case "$*" in
echo "$n"; cat "$d/zfs.children" 2>/dev/null || :
;;
# unmount unlists the dataset and hides its files, keeping its folder; mount lists it and brings them back, hiding,
-# as an overlay mount does, what the folder gained meanwhile, and fails while mount has it at a private folder
+# as an overlay mount does, what the folder gained meanwhile, and fails while mount has it at a private folder. The
+# hidden folder is the old one, moved away, so a process inside it sees, as on Linux, what the mount hides
"unmount "*)
l=$(entry "$d/zfs")
[ -n "$l" ] || { echo "cannot unmount '$n': not currently mounted" >&2; exit 1; }
@@ -101,7 +104,7 @@ case "$*" in
[ -z "$(awk -F'\t' -v n="$n" '$2 == n' "$d/zfs.private" 2>/dev/null)" ] ||
{ echo "cannot mount '$n': filesystem already mounted" >&2; exit 1; }
l=$(entry "$d/zfs.off" | tail -n 1) && f=${l%%$'\t'*}
- mkdir -p "$d/zfs.hidden" "$f" && find "$f" -mindepth 1 -maxdepth 1 -exec mv -t "$d/zfs.hidden" {} +
+ mkdir -p "$d/zfs.hidden" && { [ ! -d "$f" ] || mv -- "$f" "$(mktemp -u "$d/zfs.hidden/XXXXXX")"; } && mkdir -- "$f"
find "$d/zfs.store/$n" -mindepth 1 -maxdepth 1 -exec mv -t "$f" {} +
echo "$l" >>"$d/zfs"
;;
@@ -111,7 +114,8 @@ case "$*" in
esac
EOF
# mount -t zfs -o ro,zfsutil DATASET DIR moves an unmounted dataset's files into an empty DIR outside /mnt, umount back. Both log
-# to zfs.calls (a mktemp DIR as PRIVATE), run zfs.on_mount.zfs or zfs.on_umount, fail on mount.zfs (zfs.reason: all it says) or umount
+# to zfs.calls (a mktemp DIR as PRIVATE), run zfs.on_mount.zfs or zfs.on_umount, fail on mount.zfs (zfs.reason: all it says) or umount;
+# mount.zfs.late mounts, then fails, as mount.zfs does when it cannot update /etc/mtab
cat >"$T/bin/mount" <<'EOF'
#!/bin/bash
d=${0%/bin/mount}
@@ -134,6 +138,10 @@ if [ ! -d "$d/zfs.store/$n" ] || [ -n "$(awk -F'\t' -v n="$n" '$2 == n' "$d/zfs.
fi
find "$d/zfs.store/$n" -mindepth 1 -maxdepth 1 -exec mv -t "$p" {} +
printf '%s\t%s\n' "$p" "$n" >>"$d/zfs.private"
+if grep -qxF mount.zfs.late "$d/zfs.fail" 2>/dev/null; then
+ echo "filesystem '$n' was mounted, but /etc/mtab could not be updated" >&2
+ exit 1
+fi
EOF
cat >"$T/bin/umount" <<'EOF'
#!/bin/bash
@@ -218,7 +226,7 @@ begin() {
CASE=$1
shift
rm -rf "${ROOTS[@]}" "$SOFTSTOPFILE" "$PAUSEFILE" "$T/row_error" "$T/zfs" "$T/zfs".* "$T/after_rsync" "$T/bin/rsync" \
- "$MOVER_LOG" "$NOTIFY_LOG" "$TMPDIR"/ca.mover.tuning.*
+ "$MOVER_LOG" "$NOTIFY_LOG" "$NOTIFY_LOG.hook" "$T/pid.kept" "$TMPDIR"/ca.mover.tuning.*
mkdir -p /mnt/cache /mnt/user0
fresh "$@"
}
diff --git a/tests/age_mover/test_dataset_stops.sh b/tests/age_mover/test_dataset_stops.sh
index 8777b42d..2c4a0340 100644
--- a/tests/age_mover/test_dataset_stops.sh
+++ b/tests/age_mover/test_dataset_stops.sh
@@ -2,9 +2,15 @@
# Clean ZFS datasets: a stop lets the step in hand finish, mounts the dataset back where it can and ends the run after the
# notice.
. "$(dirname "$0")/lib.sh"
+# a case writes under /usr/local and /var/local: a mount at either refuses
+if ! awk '$5 ~ "^/(usr|var)/local(/|$)" || $5 ~ "^/(usr|var)$" { exit 1 }' /proc/self/mountinfo; then
+ echo "test_dataset_stops.sh writes Unraid's paths and one is a mount here: start it with tests/age_mover/run.sh" >&2
+ exit 2
+fi
-# a hook, run once, that stops the mover: Unraid's stop signals the run alone; the plugin's is age_mover stop, run outside
-# the run, which signals every process of it. The hook waits for that stop to end
+# a hook, run once, that stops the mover: one stop signals the run alone, as a kill of its pid does; the plugin's is
+# age_mover stop, run outside the run, which signals every process of it. The hook waits until that stop says it waits
+# for the run or has ended, and notes whether the run's pid file is still there
stop_hook() {
cat <"$T/pid"
( setsid bash -c '. "$T/funcs.sh"; PIDFILE="$T/pid" MOVER_STATUS="$T/mover.ini" PAUSEFILE="$T/pause" MOVINGFILE="$T/moving"; stop' \\
"$T/stop.out" 2>&1 & )
-for _ in \$(seq 100); do grep -qs 'mover: stopped' "$T/stop.out" && break; sleep 0.1; done
+for _ in \$(seq 100); do grep -qs -e 'mover: stopped' -e 'mover: waiting' "$T/stop.out" && break; sleep 0.1; done
+[ ! -f "$T/pid" ] || echo kept >"$T/pid.kept"
EOF
}
-# the plugin's stop ends with a sleep, then removes the pid and status files: it must end before the next case
+# the plugin's stop waits for the run to end, then removes the pid and status files: it must end before the next case
stop_done() {
local _
for _ in $(seq 100); do grep -qs 'mover: stopped' "$T/stop.out" && break; sleep 0.1; done
- check "the plugin's stop ended" 'mover: stopped' "$(cat "$T/stop.out" 2>/dev/null)"
- rm -f "$T/stop.out"
+ check "the plugin's stop waited for the run, then ended" \
+ "mover: waiting for the run to end"$'\n''mover: stopped' "$(cat "$T/stop.out" 2>/dev/null)"
+ check "the pid file stayed while the run finished" kept "$(cat "$T/pid.kept" 2>/dev/null)"
+ check "the plugin's stop removed the pid file" "" "$(ls "$T/pid" 2>/dev/null)"
+ rm -f "$T/stop.out" "$T/pid.kept"
}
# a hook, run once after command $2, that sends signal $1 to every process from its caller up to, not including, the run
kill_hook() {
@@ -56,12 +66,22 @@ one_share() {
mounted_again() { check "the dataset is mounted at its folder again" /mnt/cache/sh "$(grep -x /mnt/cache/sh "$T/zfs")"; }
REMOUNTED=$(sed '$d' <<<"$DESTROYED"; echo 'zfs mount cache/sh')
-# Unraid's stop during the check after the unmount, and a write through /mnt/user meanwhile, which keeps it unmounted
-begin "Clean ZFS datasets, Unraid's mover stop during the check after the unmount" cleanFolders topFolder cleanDatasets yes \
- notify errorsOnly
+# a stop of the run alone during the check after the unmount, and a write through /mnt/user meanwhile, which keeps it
+# unmounted. The run puts back the write method it forced and removes its pid file
+begin "Clean ZFS datasets, a stop of the run alone during the check after the unmount" cleanFolders topFolder \
+ cleanDatasets yes notify errorsOnly enableTurbo yes
one_share
+mkdir -p /usr/local/sbin /var/local/emhttp
+echo 'md_write_method="0"' >/var/local/emhttp/var.ini
+printf '#!/bin/bash\necho "mdcmd $*" >>%q\n' "$T/mdcmd.calls" >/usr/local/sbin/mdcmd
+chmod 755 /usr/local/sbin/mdcmd
+echo $$ >"$T/pid"
{ stop_hook run; echo 'echo y >/mnt/cache/sh/bare.txt'; } >"$T/zfs.on_mount.zfs"
run_moves 'processTheMoves did not return'
+check "turbo write forced, then put back" "$(printf '%s\n' 'mdcmd set md_write_method 1' 'mdcmd set md_write_method 0')" \
+ "$(cat "$T/mdcmd.calls")"
+check "the run removed its pid file" "" "$(ls "$T/pid" 2>/dev/null)"
+rm -rf /usr/local/sbin/mdcmd /var/local/emhttp "$T/mdcmd.calls"
check "zfs calls" "$(sed '$d' <<<"$DESTROYED")" "$(cat "$T/zfs.calls")"
log_has 'Mover stopped while ZFS dataset [cache/sh] was unmounted: not deleting it, attempting to remount'
log_has 'Not remounting ZFS dataset [cache/sh]: its folder /mnt/cache/sh holds files that a mount would hide'
@@ -161,8 +181,10 @@ notices ''
# a stop during the next share's checks ends the run before its unmount and before the share after it, and still sends
# the notice for the earlier one
-begin "Clean ZFS datasets, Unraid's mover stop during the next share's checks" cleanFolders topFolder cleanDatasets yes
+begin "Clean ZFS datasets, a stop of the run alone during the next share's checks" cleanFolders topFolder cleanDatasets yes
mk cache a/only/f.txt sh/only/g.txt z/only/h.txt
+# the pid file names another run, as after Unraid's mover stop removes it and a new run starts: it stays
+echo 1 >"$T/pid"
printf '%s\n' /mnt/cache /mnt/cache/a /mnt/cache/sh /mnt/cache/z >"$T/zfs"
# cache/a is kept, as a file lands in it as it unmounts, and cannot be mounted again
echo 'echo x >/mnt/cache/a/new.txt' >"$T/zfs.on_unmount"
@@ -176,6 +198,44 @@ check "cache/sh is still mounted" /mnt/cache/sh "$(grep -x /mnt/cache/sh "$T/zfs
check "the share after it is not looked at" "" "$(grep -F cache/z "$T/zfs.calls")"
notices "$(notice_for '[cache/a]')"
no_private
+check "another run's pid file stays" 1 "$(cat "$T/pid" 2>/dev/null)"
+rm -f "$T/pid"
+
+# a check that fails as a stop comes is still reported
+begin "Clean ZFS datasets, a stop of the run alone as the check after the unmount fails" cleanFolders topFolder \
+ cleanDatasets yes
+one_share
+stop_hook run >"$T/zfs.on_mount.zfs"
+echo mount.zfs >"$T/zfs.fail"
+run_moves 'processTheMoves did not return'
+check "zfs calls" "$(grep -vx 'umount PRIVATE' <<<"$REMOUNTED")" "$(cat "$T/zfs.calls")"
+log_has "ZFS dataset [cache/sh] could not be checked once unmounted, will not delete: mount: filesystem 'cache/sh' cannot be mounted, zfs.fail"
+log_lacks 'Mover stopped while'
+mounted_again
+no_private
+notices "$NOTICE"
+
+# the plugin's stop as the notice goes out: the notice is still sent, then the run ends
+begin "Clean ZFS datasets, the plugin's mover stop as the notice goes out" cleanFolders topFolder cleanDatasets yes
+one_share
+echo unmount >"$T/zfs.fail"
+stop_hook plugin >"$NOTIFY_LOG.hook"
+run_moves 'processTheMoves did not return'
+stop_done
+log_has 'Failed to unmount ZFS dataset [cache/sh]'
+log_lacks 'top-level'
+notices "$NOTICE"
+
+# a run that starts as the stopped one ends writes its own pid file, which the plugin's stop then leaves
+begin "Clean ZFS datasets, the plugin's mover stop, and another run starts as the stopped one ends" cleanFolders topFolder \
+ cleanDatasets yes
+one_share
+{ stop_hook plugin; echo "echo 1 >\"$T/pid\""; } >"$T/zfs.on_unmount"
+run_moves 'processTheMoves did not return'
+for _ in $(seq 100); do grep -qs 'mover: stopped' "$T/stop.out" && break; sleep 0.1; done
+check "the other run's pid file stays" 1 "$(cat "$T/pid" 2>/dev/null)"
+rm -f "$T/stop.out" "$T/pid"
+mounted_again
# a check killed outright, not by a stop: the run unmounts the private folder if the dataset is there, then mounts it back,
# or says where it is and how to mount it back when that umount fails
@@ -211,21 +271,16 @@ for when in 'before the read-only mount' 'while it is mounted' 'while it is moun
esac
check "zfs calls" "$calls" "$(cat "$T/zfs.calls")"
log_lacks 'successfully destroyed'
- if [[ $when == *mover* ]]; then
- log_has 'Mover stopped while ZFS dataset [cache/sh] was unmounted: not deleting it, attempting to remount'
- log_lacks 'still mounted read-only'
- notices ''
- mounted_again
- no_private
- continue
- fi
- notices "$NOTICE"
+ # a stop after the kill ends the run once the dataset is back; the cut-short check is still reported
+ [[ $when != *mover* ]] || log_lacks 'top-level'
if [[ $when == *fails ]]; then
+ notices "$(notice_for "[cache/sh] (mounted read-only at $private)")"
log_has "ZFS dataset [cache/sh] is still mounted read-only at $private, not at /mnt/cache/sh: umount: $private: zfs.fail"
- log_has "To mount it back: umount $private, then zfs mount cache/sh"
+ log_has "To mount it back: stop writes to the share, umount $private, move anything in /mnt/cache/sh aside, zfs mount cache/sh, then move it back into /mnt/cache/sh"
check "the dataset stays at the private folder" "$private"$'\t'cache/sh "$(cat "$T/zfs.private")"
continue
fi
+ notices "$NOTICE"
log_has 'ZFS dataset [cache/sh] could not be checked once unmounted, will not delete: the check was cut short'
mounted_again
no_private
diff --git a/tests/age_mover/test_datasets.sh b/tests/age_mover/test_datasets.sh
index 4ac607dd..7c9ccadf 100644
--- a/tests/age_mover/test_datasets.sh
+++ b/tests/age_mover/test_datasets.sh
@@ -125,6 +125,54 @@ for after in 'a file lands in its bare folder' 'zfs mount fails'; do
fi
done
+# a file written between the look into the bare folder and the mount: the mount hides it, so the log says where it is
+begin "Clean ZFS datasets, a file lands in the dataset as zfs unmounts it, and in its folder as zfs mounts it back" \
+ cleanFolders topFolder cleanDatasets yes notify errorsOnly
+mk cache sh/only/f.txt
+printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+echo 'echo x >/mnt/cache/sh/new.txt' >"$T/zfs.on_unmount"
+echo 'echo y >/mnt/cache/sh/late.txt' >"$T/zfs.on_mount"
+row 'move from primary' f sh/only/f.txt | list
+run_moves
+check "zfs calls" "$(sed '$d' <<<"$DESTROYED"; echo 'zfs mount cache/sh')" "$(cat "$T/zfs.calls")"
+log_has 'ZFS dataset [cache/sh] is mounted again, but /mnt/cache/sh/late.txt, written as it was mounted, is hidden under it'
+log_has 'To reach it: stop writes to the share, zfs unmount cache/sh, move anything in /mnt/cache/sh aside, zfs mount cache/sh, then move it back into /mnt/cache/sh'
+cache_is sh sh/new.txt
+no_private
+notices "$NOTICE"
+
+# a folder gone by the remount holds nothing a mount could hide: zfs mount makes it, and the run looks nowhere else
+begin "Clean ZFS datasets, a file lands in the dataset as zfs unmounts it, and its folder is gone by the remount" \
+ cleanFolders topFolder cleanDatasets yes
+mk cache sh/only/f.txt
+printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+echo 'echo x >/mnt/cache/sh/new.txt' >"$T/zfs.on_unmount"
+echo 'rmdir /mnt/cache/sh' >"$T/zfs.on_umount"
+touch "$T/cwd/elsewhere.txt"
+row 'move from primary' f sh/only/f.txt | list
+run_moves
+rm -f "$T/cwd/elsewhere.txt"
+check "zfs calls" "$(sed '$d' <<<"$DESTROYED"; echo 'zfs mount cache/sh')" "$(cat "$T/zfs.calls")"
+log_lacks 'hidden under it'
+log_lacks 'Failed to'
+cache_is sh sh/new.txt
+no_private
+notices ''
+
+# mount.zfs can make the read-only mount and still fail: the run finds the dataset there and unmounts it before the remount
+begin "Clean ZFS datasets, the read-only mount is made but reported as failed" cleanFolders topFolder cleanDatasets yes
+mk cache sh/only/f.txt
+printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+echo mount.zfs.late >"$T/zfs.fail"
+row 'move from primary' f sh/only/f.txt | list
+run_moves
+check "zfs calls" "$(sed '$d' <<<"$DESTROYED"; echo 'zfs mount cache/sh')" "$(cat "$T/zfs.calls")"
+log_has "ZFS dataset [cache/sh] could not be checked once unmounted, will not delete: mount: filesystem 'cache/sh' was mounted, but /etc/mtab could not be updated"
+log_lacks 'Failed to remount'
+check "the dataset is mounted at its folder again" /mnt/cache/sh "$(grep -x /mnt/cache/sh "$T/zfs")"
+no_private
+notices "$NOTICE"
+
# one notice for the run at its worst level: an unmount that fails, then a check that fails, still reach errorsOnly
begin "Clean ZFS datasets, two datasets fail" cleanFolders topFolder cleanDatasets yes notify errorsOnly
mk cache a/only/f.txt sh/only/g.txt
@@ -269,7 +317,7 @@ for fail in list unmount 'unmount, busy,' destroy 'destroy and mount' 'destroy,
'the read-only mount') log_has "$unchecked mount: filesystem 'cache/sh' cannot be mounted, zfs.fail" ;;
'the read-only unmount')
log_has "ZFS dataset [cache/sh] is still mounted read-only at $private, not at /mnt/cache/sh: umount: $private: zfs.fail"
- log_has "To mount it back: umount $private, then zfs mount cache/sh"
+ log_has "To mount it back: stop writes to the share, umount $private, move anything in /mnt/cache/sh aside, zfs mount cache/sh, then move it back into /mnt/cache/sh"
;;
mktemp) log_has "$unchecked mktemp: No such file or directory"; log_lacks 'attempting to unmount' ;;
# the failure notice goes out with the "Failed to" line
@@ -285,7 +333,12 @@ for fail in list unmount 'unmount, busy,' destroy 'destroy and mount' 'destroy,
# the row still logs and counts what it moved
log_has '0 files remaining from caches to array'
counter REMAINING_CACHE_FILES 0
- case $fail in unmount | destroy | 'destroy and mount' | 'the read-only unmount') notices "$NOTICE" ;; *) notices '' ;; esac
+ # with action logging off the notice is all there is, so it says where a dataset left at the private folder is
+ case $fail in
+ unmount | destroy | 'destroy and mount') notices "$NOTICE" ;;
+ 'the read-only unmount') notices "$(notice_for "[cache/sh] (mounted read-only at $private)")" ;;
+ *) notices '' ;;
+ esac
if [ "$fail" = 'destroy and mount' ]; then
log_has 'Failed to remount dataset [cache/sh]'
log_count 2 'zfs: zfs.fail'
@@ -377,6 +430,6 @@ check "the checks run as the plain user pass" 0 "$?"
check "zfs calls" "$(sed '$d' <<<"$DESTROYED"; echo 'zfs mount cache/sh')" "$(cat "$U/zfs.calls" 2>/dev/null)"
[ ! -d /mnt/cache/sh/locked ] || chmod 0755 /mnt/cache/sh/locked
cache_is sh sh/locked
-no_private
+TMPDIR=$U/tmp no_private
finish
From a590559d83b1513c99773f22e411036c730d419d Mon Sep 17 00:00:00 2001
From: DaRK AnGeL <28630321+masterwishx@users.noreply.github.com>
Date: Wed, 25 Nov 2026 09:30:05 +0200
Subject: [PATCH 45/94] update readme
Signed-off-by: DaRK AnGeL <28630321+masterwishx@users.noreply.github.com>
---
README.md | 2 +-
.../usr/local/emhttp/plugins/ca.mover.tuning/age_mover | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index a80e6962..fb462f6c 100644
--- a/README.md
+++ b/README.md
@@ -180,4 +180,4 @@ This was originally created by [Squid](https://github.com/Squidly271).
@2025 – Updated by [masterwishx](https://github.com/masterwishx/ca.mover.tuning).
-@2026 – Updated by [masterwishx](https://github.com/masterwishx/ca.mover.tuning) and [chodeus](https://github.com/chodeus), with contributions by [Joly0](https://github.com/Joly0).
+@2026 – Updated by [masterwishx](https://github.com/masterwishx/ca.mover.tuning) and [chodeus](https://github.com/chodeus), with contributions by [Joly0](https://github.com/Joly0), [coppit](https://github.com/coppit).
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index 0abb62f8..fff03cee 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -5,7 +5,7 @@
# 2023 - hugenbd (parts of code from mover tuning package)
# 2024 - R3yn4ld (parts of code from mover tuning package)
# 2025 - masterwishx (as current author and maintainer of this file)
-# 2026 - masterwishx and chodeus (as current authors and maintainers of this file), with contributions by Joly0 (parts of code from mover tuning package)
+# 2026 - masterwishx and chodeus (as current authors and maintainers of this file)
#License: GPLv2 only
# This is the 'mover tuning' script used for moving files between the cache disk and main array.
From 08df5c5148a290a337c6bc2dcb7e13e7d547f54c Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 15:34:42 +0800
Subject: [PATCH 46/94] Look inside the share folder at the remount even when
it was gone
The remount now makes the share folder if it is gone and mounts from
inside it, so a file a writer puts there just before the mount is
found and reported. A folder that cannot be made or entered fails the
remount with that reason instead of mounting without the look.
---
.../emhttp/plugins/ca.mover.tuning/age_mover | 15 ++++----
tests/age_mover/test_datasets.sh | 35 ++++++++++++++++++-
2 files changed, 42 insertions(+), 8 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index c3684b71..b2261dfe 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -2653,13 +2653,14 @@ dataset_problems_notice() {
"$DATASET_PROBLEM_LEVEL" "$names"
}
-# Mounts dataset $1 at its folder $2 and prints the first entry the mount hides, seen through . from inside the folder
-# (none when there is no folder); prints zfs's message and fails when the mount fails
+# Mounts dataset $1 at its folder $2 from inside the folder and prints the first entry the mount hides, seen through .;
+# prints why and fails when the folder cannot be entered or the mount fails
mount_back() {
- local err inside=""
- cd "$2" 2>/dev/null && inside=1
- err=$(zfs mount "$1" 2>&1) || { printf '%s' "$err"; return 1; }
- [ -z "$inside" ] || find . -mindepth 1 -print -quit 2>/dev/null
+ local err
+ # made if gone: a write through /mnt/user can make it again, with a file in it, before the mount
+ { mkdir -p "$2" && cd "$2"; } 2>/dev/null || { printf 'cannot enter its folder %s' "$2"; return 1; }
+ err=$(zfs mount "$1" 2>&1) || { printf 'zfs: %s' "$(zfs_reason "$err")"; return 1; }
+ find . -mindepth 1 -print -quit 2>/dev/null
return 0
}
@@ -2671,7 +2672,7 @@ remount_dataset() {
dataset_problem failure "$1" "Failed to remount dataset [$1]" \
"Not remounting ZFS dataset [$1]: its folder $2 holds files that a mount would hide"
elif ! out=$(finish_on_stop mount_back "$1" "$2"); then
- dataset_problem failure "$1" "Failed to remount dataset [$1]" "zfs: $(zfs_reason "$out")"
+ dataset_problem failure "$1" "Failed to remount dataset [$1]" "$out"
elif [ -n "$out" ]; then
dataset_problem failure "$1" "ZFS dataset [$1] is mounted again, but $2/${out#./}, written as it was mounted, is hidden under it" \
"To reach it: stop writes to the share, zfs unmount $1, move anything in $2 aside, zfs mount $1, then move it back into $2"
diff --git a/tests/age_mover/test_datasets.sh b/tests/age_mover/test_datasets.sh
index 7c9ccadf..ce9f5593 100644
--- a/tests/age_mover/test_datasets.sh
+++ b/tests/age_mover/test_datasets.sh
@@ -141,7 +141,7 @@ cache_is sh sh/new.txt
no_private
notices "$NOTICE"
-# a folder gone by the remount holds nothing a mount could hide: zfs mount makes it, and the run looks nowhere else
+# a folder gone by the remount is made again before the mount and looked in; the run looks nowhere else
begin "Clean ZFS datasets, a file lands in the dataset as zfs unmounts it, and its folder is gone by the remount" \
cleanFolders topFolder cleanDatasets yes
mk cache sh/only/f.txt
@@ -159,6 +159,39 @@ cache_is sh sh/new.txt
no_private
notices ''
+# a write through /mnt/user makes the gone folder again as zfs mounts the dataset: the mount hides it, and the run says so
+begin "Clean ZFS datasets, its folder is gone by the remount, and a file lands in it again as zfs mounts it back" \
+ cleanFolders topFolder cleanDatasets yes notify errorsOnly
+mk cache sh/only/f.txt
+printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+echo 'echo x >/mnt/cache/sh/new.txt' >"$T/zfs.on_unmount"
+echo 'rmdir /mnt/cache/sh' >"$T/zfs.on_umount"
+echo 'mkdir -p /mnt/cache/sh && echo y >/mnt/cache/sh/late.txt' >"$T/zfs.on_mount"
+row 'move from primary' f sh/only/f.txt | list
+run_moves
+check "zfs calls" "$(sed '$d' <<<"$DESTROYED"; echo 'zfs mount cache/sh')" "$(cat "$T/zfs.calls")"
+log_has 'ZFS dataset [cache/sh] is mounted again, but /mnt/cache/sh/late.txt, written as it was mounted, is hidden under it'
+cache_is sh sh/new.txt
+no_private
+notices "$NOTICE"
+
+# a file where the gone folder was: no folder to look in, so no mount
+begin "Clean ZFS datasets, its folder is gone by the remount and a file has its name" \
+ cleanFolders topFolder cleanDatasets yes notify errorsOnly
+mk cache sh/only/f.txt
+printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+echo 'echo x >/mnt/cache/sh/new.txt' >"$T/zfs.on_unmount"
+echo 'rmdir /mnt/cache/sh && touch /mnt/cache/sh' >"$T/zfs.on_umount"
+row 'move from primary' f sh/only/f.txt | list
+run_moves
+check "zfs calls" "$(sed '$d' <<<"$DESTROYED")" "$(cat "$T/zfs.calls")"
+log_has 'Failed to remount dataset [cache/sh]'
+log_has 'cannot enter its folder /mnt/cache/sh'
+check "the unmounted dataset keeps its file" new.txt "$(ls "$T/zfs.store/cache/sh")"
+no_private
+notices "$NOTICE"
+rm -f /mnt/cache/sh
+
# mount.zfs can make the read-only mount and still fail: the run finds the dataset there and unmounts it before the remount
begin "Clean ZFS datasets, the read-only mount is made but reported as failed" cleanFolders topFolder cleanDatasets yes
mk cache sh/only/f.txt
From 50a8156e346a89d96235ede7a481dd5ed552aa3c Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 15:35:54 +0800
Subject: [PATCH 47/94] ci: close the gaps the test-build sweep left
- PR cleanup also removes a pr- tag whose release went without it,
treats a 404 from a delete another run won as removed, and marks the
build note removed before and after its deletes.
- PR publish stops when the pull request cannot be read instead of
removing an open one's build, and checks after writing its note that
the build it offers is still there.
- The Dependabot merge skips a cancelled run; the release failure post
says the Release run failed rather than the release.
---
.github/workflows/ci.yml | 2 +-
.github/workflows/pr-cleanup.yml | 33 ++++++++++++++++++++++----------
.github/workflows/pr-publish.yml | 29 +++++++++++++++++++---------
.github/workflows/release.yml | 4 ++--
4 files changed, 46 insertions(+), 22 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index fbc3178e..f4ff6383 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -111,7 +111,7 @@ jobs:
name: Merge Dependabot pull request
needs: [validate, release-notes, release-scripts, age-mover]
if: >-
- always() && github.event_name == 'pull_request'
+ !cancelled() && github.event_name == 'pull_request'
&& github.event.pull_request.user.login == 'dependabot[bot]'
&& github.repository == github.event.pull_request.head.repo.full_name
&& needs.validate.result == 'success' && needs.release-scripts.result == 'success'
diff --git a/.github/workflows/pr-cleanup.yml b/.github/workflows/pr-cleanup.yml
index a096d977..bb69023c 100644
--- a/.github/workflows/pr-cleanup.yml
+++ b/.github/workflows/pr-cleanup.yml
@@ -23,10 +23,11 @@ jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- - name: Remove closed pull requests' releases, their tags and the note
+ - name: Remove closed pull requests' releases and tags, and mark their notes removed
run: |
set -euo pipefail
marker=""
+ note() { [ -z "$1" ] || gh api "repos/$GITHUB_REPOSITORY/issues/comments/$1" -X PATCH -f body="$marker"$'\n'"The test build for this pull request has been removed." >/dev/null; }
# set -e does not reach into a function called with ||, so every failure returns 1 itself
clean() { # $1 pull request, $2 its tags, $3 closed or gone (deleted, so no note to update)
local id="" tag out
@@ -34,19 +35,31 @@ jobs:
id=$(gh api --paginate "repos/$GITHUB_REPOSITORY/issues/$1/comments?per_page=100" --jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | startswith(\"$marker\"))) | .id") || return 1
id=${id%%$'\n'*}
fi
- # the note first: once the builds are gone, this pull request is not visited again
- if [ -n "$id" ] && [ "$id" != "null" ]; then
- gh api "repos/$GITHUB_REPOSITORY/issues/comments/$id" -X PATCH -f body="$marker"$'\n'"The test build for this pull request has been removed." >/dev/null || return 1
- fi
+ [ "$id" != null ] || id=""
+ # the note before the deletes, as this pull request is not visited again once they are done, and after
+ # them, as a publish run may have written its own note in between
+ note "$id" || return 1
while read -r tag; do
- # a publish run that saw the close may have removed it already: "release not found" is that outcome
- out=$(gh release delete --repo "$GITHUB_REPOSITORY" "$tag" --yes --cleanup-tag 2>&1) \
- || [[ "$out" == *"release not found"* ]] || { echo "$out" >&2; return 1; }
+ if grep -qxF -- "$tag" <<< "$builds"; then
+ # a publish run that saw the close may remove it first: "release not found", or a 404 when it does so
+ # between gh's lookup and its delete, is that outcome
+ out=$(gh release delete --repo "$GITHUB_REPOSITORY" "$tag" --yes --cleanup-tag 2>&1) \
+ || [[ "$out" == *"release not found"* || "$out" == *"HTTP 404"* ]] || { echo "$out" >&2; return 1; }
+ else
+ gh api -X DELETE "repos/$GITHUB_REPOSITORY/git/refs/tags/$tag" >/dev/null || return 1
+ fi
echo "removed $tag"
done <<< "$2"
+ note "$id" || return 1
}
- # listed first: a failing call inside a process substitution would read as "nothing to remove"
- tags=$(gh api --paginate "repos/$GITHUB_REPOSITORY/releases" --jq '.[] | select(.prerelease and (.tag_name | test("^pr-[0-9]+-"))) | .tag_name')
+ # listed first: a failing call inside a process substitution would read as "nothing to remove". Tags before
+ # releases, so a release published between the two lists is never taken for a tag without one
+ refs=$(gh api --paginate "repos/$GITHUB_REPOSITORY/git/matching-refs/tags/pr-" --jq '.[].ref | ltrimstr("refs/tags/") | select(test("^pr-[0-9]+-"))')
+ listed=$(gh api --paginate "repos/$GITHUB_REPOSITORY/releases" --jq '.[] | select(.tag_name | test("^pr-[0-9]+-")) | "\(.prerelease) \(.tag_name)"')
+ builds=$(sed -n 's/^true //p' <<< "$listed")
+ # a tag no release has: gh deletes the release first, so a failed tag delete leaves the tag behind
+ orphans=$(grep -vxF -f <(sed 's/^[a-z]* //' <<< "$listed") <<< "$refs") || [ $? = 1 ]
+ tags=$(printf '%s\n' "$builds" "$orphans" | sed '/^$/d' | sort -u)
[ -n "$tags" ] || { echo "No test builds."; exit 0; }
rc=0
while read -r -u 3 pr; do
diff --git a/.github/workflows/pr-publish.yml b/.github/workflows/pr-publish.yml
index 0c250da7..8661bda7 100644
--- a/.github/workflows/pr-publish.yml
+++ b/.github/workflows/pr-publish.yml
@@ -153,9 +153,10 @@ jobs:
env:
TAG: ${{ steps.meta.outputs.tag }}
run: |
- # PR cleanup may have removed it already: "release not found" is that outcome, anything else is not
+ # PR cleanup may remove it first: "release not found", or a 404 when it does so between gh's lookup and its
+ # delete, is that outcome, anything else is not
out=$(gh release delete --repo "$GITHUB_REPOSITORY" "$TAG" --cleanup-tag --yes 2>&1) \
- || [[ "$out" == *"release not found"* ]] || { echo "$out" >&2; exit 1; }
+ || [[ "$out" == *"release not found"* || "$out" == *"HTTP 404"* ]] || { echo "$out" >&2; exit 1; }
- name: Remove older builds of this pull request
if: steps.pr.outputs.number != ''
@@ -168,7 +169,7 @@ jobs:
--jq ".[] | select(.prerelease and .tag_name != \"$TAG\" and (.tag_name | startswith(\"pr-$PR-\"))) | .tag_name" \
| while read -r old; do
out=$(gh release delete --repo "$GITHUB_REPOSITORY" "$old" --cleanup-tag --yes 2>&1) \
- || [[ "$out" == *"release not found"* ]] || { echo "$out" >&2; exit 1; }
+ || [[ "$out" == *"release not found"* || "$out" == *"HTTP 404"* ]] || { echo "$out" >&2; exit 1; }
echo "removed $old"
done
@@ -180,11 +181,13 @@ jobs:
TAG: ${{ steps.meta.outputs.tag }}
run: |
set -euo pipefail
- # PR cleanup's hourly sweep may get there first: "release not found" here means it did, and the build is gone
- # either way
- if [ "$(gh api "repos/$GITHUB_REPOSITORY/pulls/$PR" --jq .state)" != "open" ]; then
+ # its own line, so set -e stops on an unreadable pull request instead of removing an open one's build
+ state=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$PR" --jq .state)
+ # PR cleanup's hourly sweep may get there first: "release not found", or a 404 when it removes it between
+ # gh's lookup and its delete, means it did, and the build is gone either way
+ if [ "$state" != "open" ]; then
out=$(gh release delete --repo "$GITHUB_REPOSITORY" "$TAG" --cleanup-tag --yes 2>&1) \
- || [[ "$out" == *"release not found"* ]] || { echo "$out" >&2; exit 1; }
+ || [[ "$out" == *"release not found"* || "$out" == *"HTTP 404"* ]] || { echo "$out" >&2; exit 1; }
echo "closed=true" >> "$GITHUB_OUTPUT"
echo "Pull request #$PR closed while publishing; the release was removed again."
fi
@@ -199,10 +202,12 @@ jobs:
BUILD_LOG: ${{ github.event.workflow_run.html_url }}
VERIFIED: ${{ steps.verify.outcome == 'success' }}
CLOSED: ${{ steps.closed.outputs.closed == 'true' }}
+ TAG: ${{ steps.meta.outputs.tag }}
run: |
set -euo pipefail
+ removed=$(printf '%s\n' "$MARKER" "The test build for this pull request has been removed.")
if [ "$CLOSED" = true ]; then
- body=$(printf '%s\n' "$MARKER" "The test build for this pull request has been removed.")
+ body=$removed
elif [ "$VERIFIED" = true ]; then
body=$(printf '%s\n' "$MARKER" "Test build \`$VERSION\` of ${HEAD_SHA::7} ([build log]($BUILD_LOG)). Install from Plugins, Install Plugin, with this URL:" "" '```' "$INSTALL_URL" '```' "" "It installs over the current release and the next real release supersedes it. Add the \`$LABEL\` label again for a new build.")
else
@@ -213,8 +218,14 @@ jobs:
if [ -n "$id" ]; then
gh api "repos/$GITHUB_REPOSITORY/issues/comments/$id" -X PATCH -f body="$body" >/dev/null
else
- gh api "repos/$GITHUB_REPOSITORY/issues/$PR/comments" -X POST -f body="$body" >/dev/null
+ id=$(gh api "repos/$GITHUB_REPOSITORY/issues/$PR/comments" -X POST -f body="$body" --jq .id)
fi
+ # checked after the write: PR cleanup may have removed the build since the closed check, and it notes after
+ # its deletes, so whichever note lands last says what is there
+ [ "$VERIFIED" = true ] && [ "$CLOSED" != true ] || exit 0
+ out=$(gh release view --repo "$GITHUB_REPOSITORY" "$TAG" 2>&1 >/dev/null) && exit 0
+ [[ "$out" == *"release not found"* ]] || { echo "$out" >&2; exit 1; }
+ gh api "repos/$GITHUB_REPOSITORY/issues/comments/$id" -X PATCH -f body="$removed" >/dev/null
- name: Take the label off so the next build needs a new go
if: always() && steps.pr.outputs.number != ''
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 525a5f0d..19a5fff4 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -184,7 +184,7 @@ jobs:
# discord-notify.yml announces each published release; a failed release job only here, a run that cannot start not at all
notify-failure:
- name: Tell Discord the release failed
+ name: Tell Discord the Release run failed
needs: release
if: failure()
runs-on: ubuntu-latest
@@ -202,7 +202,7 @@ jobs:
fi
json=$(jq -n --arg title "Release on $GITHUB_REF_NAME" --arg url "$RUN_URL" --arg actor "$GITHUB_ACTOR" \
--arg repo "$GITHUB_REPOSITORY" --arg timestamp "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
- '{content: "❌ Release Failed", embeds: [{title: $title, url: $url, description: "The Release run failed: see its log.",
+ '{content: "❌ Release run failed", embeds: [{title: $title, url: $url, description: "The Release run failed: see its log.",
color: 10038562, timestamp: $timestamp,
fields: [{name: "Repository", value: $repo, inline: true}, {name: "Actor", value: $actor, inline: true}]}]}')
curl --fail-with-body --silent --show-error --connect-timeout 10 --max-time 30 \
From 02b5b01ad382d2af5b099da87868fe3539e672ac Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 17:12:54 +0800
Subject: [PATCH 48/94] Say in the notice why a dataset is out of view and how
to mount it back
With action logging off the notice is all the user gets, so a dataset
left unmounted, with a file hidden under it, or at the private
read-only mount now has its reason and the steps to mount it back in
its notice entry, in all five languages. The log gets the same steps.
The translation finishes on a stop, so the entry keeps its reason, and
the language check now sees templates passed to dataset_out_of_view.
---
.github/scripts/check-languages.php | 2 +-
.../emhttp/plugins/ca.mover.tuning/age_mover | 33 ++++++++++++-------
.../ca.mover.tuning/languages/de_DE.txt | 4 ++-
.../ca.mover.tuning/languages/en_US.txt | 4 ++-
.../ca.mover.tuning/languages/fr_FR.txt | 4 ++-
.../ca.mover.tuning/languages/ru_RU.txt | 4 ++-
.../ca.mover.tuning/languages/zh_CN.txt | 4 ++-
tests/age_mover/lib.sh | 5 +++
tests/age_mover/test_dataset_stops.sh | 29 +++++++++++++---
tests/age_mover/test_datasets.sh | 22 +++++++------
10 files changed, 79 insertions(+), 32 deletions(-)
diff --git a/.github/scripts/check-languages.php b/.github/scripts/check-languages.php
index 6e28fc3a..058c540a 100644
--- a/.github/scripts/check-languages.php
+++ b/.github/scripts/check-languages.php
@@ -176,7 +176,7 @@ function mover_texts(string $pluginDir): array
}
$used = [];
$code = file_get_contents($mover);
- preg_match_all('/(?:translate_text|mvlogger_t) "((?:[^"\\\\]|\\\\.)*)"/', $code, $m, PREG_OFFSET_CAPTURE);
+ preg_match_all('/(?:translate_text|mvlogger_t|dataset_out_of_view) "((?:[^"\\\\]|\\\\.)*)"/', $code, $m, PREG_OFFSET_CAPTURE);
foreach ($m[1] as [$text, $offset]) {
// an unescaped $ is a shell variable: the text is only known at run time
if (preg_match('/(?/dev/null)" ]; then
- dataset_problem failure "$1" "Failed to remount dataset [$1]" \
- "Not remounting ZFS dataset [$1]: its folder $2 holds files that a mount would hide"
- elif ! out=$(finish_on_stop mount_back "$1" "$2"); then
- dataset_problem failure "$1" "Failed to remount dataset [$1]" "$out"
- elif [ -n "$out" ]; then
- dataset_problem failure "$1" "ZFS dataset [$1] is mounted again, but $2/${out#./}, written as it was mounted, is hidden under it" \
- "To reach it: stop writes to the share, zfs unmount $1, move anything in $2 aside, zfs mount $1, then move it back into $2"
+ out="Not remounting ZFS dataset [$1]: its folder $2 holds files that a mount would hide"
+ elif out=$(finish_on_stop mount_back "$1" "$2"); then
+ [ -n "$out" ] || return 0
+ dataset_problem failure "$1" "ZFS dataset [$1] is mounted again, but $2/${out#./}, written as it was mounted, is hidden under it"
+ dataset_out_of_view "a file is hidden under it: stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s" \
+ "$1" "$1" "$2" "$1" "$2"
+ return 0
fi
+ dataset_problem failure "$1" "Failed to remount dataset [$1]" "$out"
+ dataset_out_of_view "not mounted: stop writes to the share, move anything in %s aside, zfs mount %s, then move it back into %s" \
+ "$1" "$2" "$1" "$2"
}
# Logs at debug level why dataset $1 is kept: entry $2 that a destroy could lose
@@ -2709,11 +2721,10 @@ unmount_check_destroy() {
fi
fi
if [ "$rc" = 2 ]; then
- # with action logging off the notice is all there is, so it says where the dataset is
- DATASET_PROBLEM[$dataset]="[$dataset] ($(translate_text "mounted read-only at %s" "$private"))"
dataset_problem failure "$dataset" \
- "ZFS dataset [${dataset}] is still mounted read-only at ${private}, not at ${folder}: umount: $lost" \
- "To mount it back: stop writes to the share, umount ${private}, move anything in ${folder} aside, zfs mount ${dataset}, then move it back into ${folder}"
+ "ZFS dataset [${dataset}] is still mounted read-only at ${private}, not at ${folder}: umount: $lost"
+ dataset_out_of_view "mounted read-only at %s: stop writes to the share, umount %s, move anything in %s aside, zfs mount %s, then move it back into %s" \
+ "$dataset" "$private" "$private" "$folder" "$dataset" "$folder"
return 0
elif [ "$rc" != 0 ]; then
# a hold by something else, such as a container's mount, makes the read-only mount busy
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt
index ae559352..03643dbb 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt
@@ -8,6 +8,7 @@
%s files and %s folders representing %s could not be movedsynced by Mover Tuning plugin=%s Dateien und %s Ordner mit einer Größe von %s konnten vom Mover Tuning Plugin nicht verschoben/synchronisiert werden.
Action=Aktion
+a file is hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=eine Datei ist darunter verdeckt: Schreibzugriffe auf die Freigabe stoppen, zfs unmount %s ausführen, alles in %s beiseite verschieben, zfs mount %s ausführen, dann alles zurück nach %s verschieben
All community developers=Alle Entwickler der Community
%s files and %s folders were movedsynced, but rsync reported errors for them Check the Mover Tuning log=%s Dateien und %s Ordner wurden verschoben/synchronisiert, aber rsync hat dabei Fehler gemeldet. Bitte das Mover‑Tuning‑Protokoll prüfen.
Allow force mover schedule to run during a parity checkrebuild=Erlaubt das erzwungene Ausführen der Datenverschiebung während einer Paritätsprüfung oder Wiederherstellung
@@ -79,7 +80,7 @@ Logs parent folder for Mover Tuning plugin=Übergeordneter Ordner für Protokoll
Low=Niedrig
Maintainers=Betreuer
make those plugins with ❤️ and a lot of ☕=machen diese Plugins mit ❤️ und viel ☕
-mounted read-only at %s=schreibgeschützt eingehängt unter %s
+mounted read-only at %s stop writes to the share, umount %s, move anything in %s aside, zfs mount %s, then move it back into %s=schreibgeschützt eingehängt unter %s: Schreibzugriffe auf die Freigabe stoppen, umount %s ausführen, alles in %s beiseite verschieben, zfs mount %s ausführen, dann alles zurück nach %s verschieben
Move ALL files from current pool ignores filters and thresholds=ALLE Dateien aus dem aktuellen Pool verschieben (ohne Filter und Schwellenwerte)
Move ALL files to current pool ignores filters and thresholds=ALLE Dateien in den aktuellen Pool verschieben (ohne Filter und Schwellenwerte)
Move All from Primary->Secondary cacheyes shares pool percentage=Alles vom Primärspeicher → Sekundärspeicher verschieben (cache:yes) – Pool‑Prozent
@@ -123,6 +124,7 @@ No log files yet=Noch keine Protokolldateien
Not Applicable Share Does Not Exist Yet=Nicht anwendbar (Freigabe existiert noch nicht)
Not a valid cron schedule it is not applied=Kein gültiger Cron‑Zeitplan: Er wird nicht übernommen.
Notify Mover Tuning plugin actions=Aktionen des Mover‑Tuning‑Plugins melden
+not mounted stop writes to the share, move anything in %s aside, zfs mount %s, then move it back into %s=nicht eingehängt: Schreibzugriffe auf die Freigabe stoppen, alles in %s beiseite verschieben, zfs mount %s ausführen, dann alles zurück nach %s verschieben
Oldest first=Älteste zuerst
Only move files larger than this in MB=Nur Dateien verschieben, die größer sind als dieser Wert (in MB)
Only move files that are older than this in days=Nur Dateien verschieben, die älter sind als dieser Wert (in Tagen)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt
index 1022cbc8..be6ae7dd 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt
@@ -11,6 +11,7 @@
%s files and %s folders representing %s could not be movedsynced by Mover Tuning plugin=%s files and %s folders representing %s could not be moved/synced by Mover Tuning plugin.
%s files and %s folders were movedsynced, but rsync reported errors for them Check the Mover Tuning log=%s files and %s folders were moved/synced, but rsync reported errors for them. Check the Mover Tuning log.
Action=
+a file is hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=a file is hidden under it: stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s
All community developers=
Allow force mover schedule to run during a parity checkrebuild=Allow force mover schedule to run during a parity check/rebuild
All plugin settings return to their defaults, including the Mover Tuning schedule, the forced move schedule and the cache watchdog, and the override settings of every share are deleted=All plugin settings return to their defaults, including the Mover Tuning schedule, the forced move schedule and the cache watchdog, and the override settings of every share are deleted.
@@ -81,7 +82,7 @@ Logs parent folder for Mover Tuning plugin=
Low=
Maintainers=
make those plugins with ❤️ and a lot of ☕=make those plugins with ❤️ (and a lot of ☕).
-mounted read-only at %s=mounted read-only at %s
+mounted read-only at %s stop writes to the share, umount %s, move anything in %s aside, zfs mount %s, then move it back into %s=mounted read-only at %s: stop writes to the share, umount %s, move anything in %s aside, zfs mount %s, then move it back into %s
Move ALL files from current pool ignores filters and thresholds=Move **ALL** files from current pool (ignores filters and thresholds)
Move ALL files to current pool ignores filters and thresholds=Move **ALL** files to current pool (ignores filters and thresholds)
Move All from Primary->Secondary cacheyes shares pool percentage=Move All from Primary->Secondary (cache:yes) shares pool percentage
@@ -125,6 +126,7 @@ No log files yet=
Not Applicable Share Does Not Exist Yet=Not Applicable (Share Does Not Exist Yet)
Not a valid cron schedule it is not applied=Not a valid cron schedule: it is not applied.
Notify Mover Tuning plugin actions=
+not mounted stop writes to the share, move anything in %s aside, zfs mount %s, then move it back into %s=not mounted: stop writes to the share, move anything in %s aside, zfs mount %s, then move it back into %s
Oldest first=
Only move files larger than this in MB=Only move files larger than this (in MB)
Only move files that are older than this in days=Only move files that are older than this (in days)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt
index 776d5b02..c646d941 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt
@@ -9,6 +9,7 @@
%s files and %s folders representing %s could not be movedsynced by Mover Tuning plugin=%s fichiers et %s dossiers représentant %s n’ont pas pu être déplacés/synchronisés par le plugin Mover Tuning.
%s files and %s folders were movedsynced, but rsync reported errors for them Check the Mover Tuning log=%s fichiers et %s dossiers ont été déplacés/synchronisés, mais rsync a signalé des erreurs les concernant. Consultez le journal de Mover Tuning.
Action=Action
+a file is hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=un fichier est masqué dessous : arrêtez les écritures sur le partage, lancez zfs unmount %s, mettez de côté tout ce qui est dans %s, lancez zfs mount %s, puis remettez le tout dans %s
All community developers=Tous les développeurs de la communauté
Allow force mover schedule to run during a parity checkrebuild=Autoriser l’exécution forcée du mover pendant une vérification/réparation de parité
All plugin settings return to their defaults, including the Mover Tuning schedule, the forced move schedule and the cache watchdog, and the override settings of every share are deleted=Tous les paramètres du plugin reviennent à leurs valeurs par défaut, y compris la planification Mover Tuning, l’horaire du déplacement forcé et la surveillance du cache, et les paramètres remplacés de chaque part sont supprimés.
@@ -79,7 +80,7 @@ Logs parent folder for Mover Tuning plugin=Dossier parent des journaux du plugin
Low=Faible
Maintainers=Mainteneurs
make those plugins with ❤️ and a lot of ☕=créent ces plugins avec ❤️ et beaucoup de ☕
-mounted read-only at %s=monté en lecture seule sur %s
+mounted read-only at %s stop writes to the share, umount %s, move anything in %s aside, zfs mount %s, then move it back into %s=monté en lecture seule sur %s : arrêtez les écritures sur le partage, lancez umount %s, mettez de côté tout ce qui est dans %s, lancez zfs mount %s, puis remettez le tout dans %s
Move ALL files from current pool ignores filters and thresholds=Déplacer **TOUS** les fichiers du pool actuel (en ignorant les filtres et les seuils)
Move ALL files to current pool ignores filters and thresholds=Déplacer **TOUS** les fichiers vers le pool actuel (en ignorant les filtres et les seuils)
Move All from Primary->Secondary cacheyes shares pool percentage=Déplacer tout depuis Primaire→Secondaire (cache:yes) selon le pourcentage du pool
@@ -123,6 +124,7 @@ No log files yet=Aucun fichier journal pour le moment
Not Applicable Share Does Not Exist Yet=Non applicable (la part n’existe pas encore)
Not a valid cron schedule it is not applied=Planification cron invalide : elle n’est pas appliquée.
Notify Mover Tuning plugin actions=Notifier les actions du plugin Mover Tuning
+not mounted stop writes to the share, move anything in %s aside, zfs mount %s, then move it back into %s=non monté : arrêtez les écritures sur le partage, mettez de côté tout ce qui est dans %s, lancez zfs mount %s, puis remettez le tout dans %s
Oldest first=Les plus anciens d’abord
Only move files larger than this in MB=Déplacer uniquement les fichiers plus grands que cette taille (en Mo)
Only move files that are older than this in days=Déplacer uniquement les fichiers plus anciens que ce nombre de jours
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt
index 8540dcae..721eb9c2 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt
@@ -8,6 +8,7 @@
%s files and %s folders representing %s could not be movedsynced by Mover Tuning plugin=Плагину Mover Tuning не удалось переместить/синхронизировать %s файлов и %s папок общим объёмом %s.
Action=Действие
+a file is hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=под ним скрыт файл: остановите запись в общий ресурс, выполните zfs unmount %s, переместите всё из %s в другое место, выполните zfs mount %s, затем верните всё обратно в %s
All community developers=Все разработчики сообщества
%s files and %s folders were movedsynced, but rsync reported errors for them Check the Mover Tuning log=%s файлов и %s папок были перемещены/синхронизированы, но rsync сообщил об ошибках при их обработке. Проверьте журнал Mover Tuning.
Allow force mover schedule to run during a parity checkrebuild=Разрешить запуск расписания принудительного перемещения во время проверки/восстановления четности
@@ -79,7 +80,7 @@ Logs parent folder for Mover Tuning plugin=Родительская папка
Low=Низкий
Maintainers=Сопровождающие
make those plugins with ❤️ and a lot of ☕=создаём эти плагины с ❤️ (и большим количеством ☕).
-mounted read-only at %s=смонтирован только для чтения в %s
+mounted read-only at %s stop writes to the share, umount %s, move anything in %s aside, zfs mount %s, then move it back into %s=смонтирован только для чтения в %s: остановите запись в общий ресурс, выполните umount %s, переместите всё из %s в другое место, выполните zfs mount %s, затем верните всё обратно в %s
Move ALL files from current pool ignores filters and thresholds=Переместить **ВСЕ** файлы из текущего пула (независимо от фильтров и порогов)
Move ALL files to current pool ignores filters and thresholds=Переместить **ВСЕ** файлы в текущий пул (независимо от фильтров и порогов)
Move All from Primary->Secondary cacheyes shares pool percentage=Переместить всё из Основного->Вторичного (cache:yes) — процент заполнения пула шар
@@ -123,6 +124,7 @@ No log files yet=Файлов журнала пока нет
Not Applicable Share Does Not Exist Yet=Не применимо (шара ещё не существует)
Not a valid cron schedule it is not applied=Некорректное расписание cron: оно не применяется.
Notify Mover Tuning plugin actions=Уведомлять о действиях плагина Mover Tuning
+not mounted stop writes to the share, move anything in %s aside, zfs mount %s, then move it back into %s=не смонтирован: остановите запись в общий ресурс, переместите всё из %s в другое место, выполните zfs mount %s, затем верните всё обратно в %s
Oldest first=Сначала самые старые
Only move files larger than this in MB=Перемещать только файлы больше указанного размера (в МБ)
Only move files that are older than this in days=Перемещать только файлы старше указанного количества дней
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt
index ad44a215..bb7c03af 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt
@@ -8,6 +8,7 @@
%s files and %s folders representing %s could not be movedsynced by Mover Tuning plugin=Mover Tuning 插件未能移动/同步 %s 个文件和 %s 个文件夹,共 %s。
%s files and %s folders were movedsynced, but rsync reported errors for them Check the Mover Tuning log=%s 个文件和 %s 个文件夹已移动/同步,但 rsync 报告了错误。请查看 Mover Tuning 日志。
Action=操作
+a file is hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=其下有文件被遮盖:停止向该共享写入,运行 zfs unmount %s,将 %s 中的所有内容移到别处,运行 zfs mount %s,然后移回 %s
All community developers=所有社区开发者
Allow force mover schedule to run during a parity checkrebuild=允许强制移动计划在奇偶校验/重建期间运行
All plugin settings return to their defaults, including the Mover Tuning schedule, the forced move schedule and the cache watchdog, and the override settings of every share are deleted=所有插件设置都将恢复为默认值,包括 Mover Tuning 计划、强制移动计划和缓存看门狗,并且所有共享的覆盖设置都将被删除。
@@ -78,7 +79,7 @@ Logs parent folder for Mover Tuning plugin=日志文件保存路径
Low=低
Maintainers=维护者
make those plugins with ❤️ and a lot of ☕=用 ❤️(和很多 ☕)制作了这些插件。
-mounted read-only at %s=以只读方式挂载于 %s
+mounted read-only at %s stop writes to the share, umount %s, move anything in %s aside, zfs mount %s, then move it back into %s=以只读方式挂载于 %s:停止向该共享写入,运行 umount %s,将 %s 中的所有内容移到别处,运行 zfs mount %s,然后移回 %s
Move ALL files from current pool ignores filters and thresholds=从当前存储池移出**所有**文件(无视过滤条件和阈值)
Move ALL files to current pool ignores filters and thresholds=将**所有**文件移入当前存储池(无视过滤条件和阈值)
Move All from Primary->Secondary cacheyes shares pool percentage=主存储->次存储(cache:yes)共享全部移动的存储池百分比
@@ -122,6 +123,7 @@ No log files yet=暂无日志文件
Not Applicable Share Does Not Exist Yet=不适用(共享尚不存在)
Not a valid cron schedule it is not applied=无效的 cron 计划:不会生效。
Notify Mover Tuning plugin actions=通知设置
+not mounted stop writes to the share, move anything in %s aside, zfs mount %s, then move it back into %s=未挂载:停止向该共享写入,将 %s 中的所有内容移到别处,运行 zfs mount %s,然后移回 %s
Oldest first=最旧的优先
Only move files larger than this in MB=仅移动大于此大小的文件(MB)
Only move files that are older than this in days=仅移动早于此天数的文件(天)
diff --git a/tests/age_mover/lib.sh b/tests/age_mover/lib.sh
index 02cba1c0..31a68a73 100644
--- a/tests/age_mover/lib.sh
+++ b/tests/age_mover/lib.sh
@@ -181,6 +181,11 @@ DESTROYED=$(printf '%s\n' "zfs $LS cache/sh" 'zfs unmount cache/sh' 'mount -t zf
'zfs destroy cache/sh')
notice_for() { echo "warning|Clean empty ZFS datasets did not finish for $1. The mover log has the details unless Log Mover Tuning plugin actions is set to No."; }
NOTICE=$(notice_for '[cache/sh]')
+# the notice of a cache/sh left out of view: why, and how to mount it back
+BACK='move anything in /mnt/cache/sh aside, zfs mount cache/sh, then move it back into /mnt/cache/sh'
+NOT_MOUNTED=$(notice_for "[cache/sh] (not mounted: stop writes to the share, $BACK)")
+HIDDEN=$(notice_for "[cache/sh] (a file is hidden under it: stop writes to the share, zfs unmount cache/sh, $BACK)")
+read_only_notice() { notice_for "[cache/sh] (mounted read-only at $1: stop writes to the share, umount $1, $BACK)"; }
no_private() { check "no private mount folder left" "" "$(find "$TMPDIR" -maxdepth 1 -name 'ca.mover.tuning.*')"; }
notices() { check "notices" "$1" "$(cat "$NOTIFY_LOG" 2>/dev/null)"; }
diff --git a/tests/age_mover/test_dataset_stops.sh b/tests/age_mover/test_dataset_stops.sh
index 2c4a0340..8a5ec80d 100644
--- a/tests/age_mover/test_dataset_stops.sh
+++ b/tests/age_mover/test_dataset_stops.sh
@@ -89,7 +89,7 @@ log_lacks 'successfully destroyed'
check "the dataset is kept, unmounted" yes "$([ -d "$T/zfs.store/cache/sh" ] && echo yes)"
cache_is sh sh/bare.txt
no_private
-notices "$NOTICE"
+notices "$NOT_MOUNTED"
# the plugin's stop as each step runs: the step finishes, a destroy that finished stays done, else the dataset goes back
for step in 'zfs list' 'zfs unmount' 'the read-only umount' 'zfs destroy' 'the remount'; do
@@ -149,7 +149,7 @@ check "zfs calls" "$(sed '$d' <<<"$DESTROYED")" "$(cat "$T/zfs.calls")"
log_has 'Not remounting ZFS dataset [cache/sh]: its folder /mnt/cache/sh holds files that a mount would hide'
cache_is sh sh/bare.txt
no_private
-notices "$NOTICE"
+notices "$NOT_MOUNTED"
# the plugin's stop as mktemp makes the private folder: it is made, so the unmount goes ahead and the dataset goes back
begin "Clean ZFS datasets, the plugin's mover stop as the private folder is made" cleanFolders topFolder cleanDatasets yes
@@ -196,7 +196,7 @@ log_has 'Failed to remount dataset [cache/a]'
log_lacks 'ZFS dataset [cache/sh] holds only folders'
check "cache/sh is still mounted" /mnt/cache/sh "$(grep -x /mnt/cache/sh "$T/zfs")"
check "the share after it is not looked at" "" "$(grep -F cache/z "$T/zfs.calls")"
-notices "$(notice_for '[cache/a]')"
+notices "$(notice_for '[cache/a] (not mounted: stop writes to the share, move anything in /mnt/cache/a aside, zfs mount cache/a, then move it back into /mnt/cache/a)')"
no_private
check "another run's pid file stays" 1 "$(cat "$T/pid" 2>/dev/null)"
rm -f "$T/pid"
@@ -226,6 +226,25 @@ log_has 'Failed to unmount ZFS dataset [cache/sh]'
log_lacks 'top-level'
notices "$NOTICE"
+# the plugin's stop as a dataset's notice entry is translated: the translation finishes, so the entry keeps its reason
+begin "Clean ZFS datasets, the plugin's mover stop as a dataset's notice entry is translated" cleanFolders topFolder \
+ cleanDatasets yes
+one_share
+echo 'echo x >/mnt/cache/sh/new.txt' >"$T/zfs.on_unmount"
+echo mount >"$T/zfs.fail"
+stop_hook plugin >"$T/php.hook"
+# translate_text runs /usr/bin/php -q translate.php TEMPLATE; this one prints the template back
+# shellcheck disable=SC2016 # the stand-in expands its own $3
+printf '#!/bin/bash\ncase $3 in "not mounted:"*) [ ! -f %q ] || bash %q ;; esac\nprintf %%s "$3"\n' "$T/php.hook" "$T/php.hook" \
+ >/usr/bin/php
+chmod 755 /usr/bin/php
+run_moves 'processTheMoves did not return'
+rm -f /usr/bin/php
+stop_done
+check "the stop came during the translation" "" "$(ls "$T/php.hook" 2>/dev/null)"
+log_has 'Failed to remount dataset [cache/sh]'
+notices "$NOT_MOUNTED"
+
# a run that starts as the stopped one ends writes its own pid file, which the plugin's stop then leaves
begin "Clean ZFS datasets, the plugin's mover stop, and another run starts as the stopped one ends" cleanFolders topFolder \
cleanDatasets yes
@@ -274,9 +293,9 @@ for when in 'before the read-only mount' 'while it is mounted' 'while it is moun
# a stop after the kill ends the run once the dataset is back; the cut-short check is still reported
[[ $when != *mover* ]] || log_lacks 'top-level'
if [[ $when == *fails ]]; then
- notices "$(notice_for "[cache/sh] (mounted read-only at $private)")"
+ notices "$(read_only_notice "$private")"
log_has "ZFS dataset [cache/sh] is still mounted read-only at $private, not at /mnt/cache/sh: umount: $private: zfs.fail"
- log_has "To mount it back: stop writes to the share, umount $private, move anything in /mnt/cache/sh aside, zfs mount cache/sh, then move it back into /mnt/cache/sh"
+ log_has "ZFS dataset [cache/sh]: mounted read-only at $private: stop writes to the share, umount $private, $BACK"
check "the dataset stays at the private folder" "$private"$'\t'cache/sh "$(cat "$T/zfs.private")"
continue
fi
diff --git a/tests/age_mover/test_datasets.sh b/tests/age_mover/test_datasets.sh
index ce9f5593..2e524c92 100644
--- a/tests/age_mover/test_datasets.sh
+++ b/tests/age_mover/test_datasets.sh
@@ -112,9 +112,10 @@ for after in 'a file lands in its bare folder' 'zfs mount fails'; do
run_moves
log_has 'Keeping ZFS dataset [cache/sh]: the check after the unmount found something a destroy could lose.'
log_has 'Failed to remount dataset [cache/sh]'
+ log_has "ZFS dataset [cache/sh]: not mounted: stop writes to the share, $BACK"
check "the unmounted dataset keeps its file" new.txt "$(ls "$T/zfs.store/cache/sh")"
no_private
- notices "$NOTICE"
+ notices "$NOT_MOUNTED"
if [ "$after" = 'zfs mount fails' ]; then
check "zfs calls" "$(sed '$d' <<<"$DESTROYED"; echo 'zfs mount cache/sh')" "$(cat "$T/zfs.calls")"
log_has 'zfs: zfs.fail'
@@ -136,10 +137,10 @@ row 'move from primary' f sh/only/f.txt | list
run_moves
check "zfs calls" "$(sed '$d' <<<"$DESTROYED"; echo 'zfs mount cache/sh')" "$(cat "$T/zfs.calls")"
log_has 'ZFS dataset [cache/sh] is mounted again, but /mnt/cache/sh/late.txt, written as it was mounted, is hidden under it'
-log_has 'To reach it: stop writes to the share, zfs unmount cache/sh, move anything in /mnt/cache/sh aside, zfs mount cache/sh, then move it back into /mnt/cache/sh'
+log_has "ZFS dataset [cache/sh]: a file is hidden under it: stop writes to the share, zfs unmount cache/sh, $BACK"
cache_is sh sh/new.txt
no_private
-notices "$NOTICE"
+notices "$HIDDEN"
# a folder gone by the remount is made again before the mount and looked in; the run looks nowhere else
begin "Clean ZFS datasets, a file lands in the dataset as zfs unmounts it, and its folder is gone by the remount" \
@@ -173,7 +174,7 @@ check "zfs calls" "$(sed '$d' <<<"$DESTROYED"; echo 'zfs mount cache/sh')" "$(ca
log_has 'ZFS dataset [cache/sh] is mounted again, but /mnt/cache/sh/late.txt, written as it was mounted, is hidden under it'
cache_is sh sh/new.txt
no_private
-notices "$NOTICE"
+notices "$HIDDEN"
# a file where the gone folder was: no folder to look in, so no mount
begin "Clean ZFS datasets, its folder is gone by the remount and a file has its name" \
@@ -189,7 +190,7 @@ log_has 'Failed to remount dataset [cache/sh]'
log_has 'cannot enter its folder /mnt/cache/sh'
check "the unmounted dataset keeps its file" new.txt "$(ls "$T/zfs.store/cache/sh")"
no_private
-notices "$NOTICE"
+notices "$NOT_MOUNTED"
rm -f /mnt/cache/sh
# mount.zfs can make the read-only mount and still fail: the run finds the dataset there and unmounts it before the remount
@@ -350,7 +351,7 @@ for fail in list unmount 'unmount, busy,' destroy 'destroy and mount' 'destroy,
'the read-only mount') log_has "$unchecked mount: filesystem 'cache/sh' cannot be mounted, zfs.fail" ;;
'the read-only unmount')
log_has "ZFS dataset [cache/sh] is still mounted read-only at $private, not at /mnt/cache/sh: umount: $private: zfs.fail"
- log_has "To mount it back: stop writes to the share, umount $private, move anything in /mnt/cache/sh aside, zfs mount cache/sh, then move it back into /mnt/cache/sh"
+ log_has "ZFS dataset [cache/sh]: mounted read-only at $private: stop writes to the share, umount $private, $BACK"
;;
mktemp) log_has "$unchecked mktemp: No such file or directory"; log_lacks 'attempting to unmount' ;;
# the failure notice goes out with the "Failed to" line
@@ -366,10 +367,11 @@ for fail in list unmount 'unmount, busy,' destroy 'destroy and mount' 'destroy,
# the row still logs and counts what it moved
log_has '0 files remaining from caches to array'
counter REMAINING_CACHE_FILES 0
- # with action logging off the notice is all there is, so it says where a dataset left at the private folder is
+ # with action logging off the notice is all there is, so it says why a dataset is out of view and how to mount it back
case $fail in
- unmount | destroy | 'destroy and mount') notices "$NOTICE" ;;
- 'the read-only unmount') notices "$(notice_for "[cache/sh] (mounted read-only at $private)")" ;;
+ unmount | destroy) notices "$NOTICE" ;;
+ 'destroy and mount') notices "$NOT_MOUNTED" ;;
+ 'the read-only unmount') notices "$(read_only_notice "$private")" ;;
*) notices '' ;;
esac
if [ "$fail" = 'destroy and mount' ]; then
@@ -406,7 +408,7 @@ log_has 'Failed to remount dataset [cache/sh]'
log_has 'Not remounting ZFS dataset [cache/sh]: its folder /mnt/cache/sh holds files that a mount would hide'
cache_is sh sh/new.txt
no_private
-notices "$NOTICE"
+notices "$NOT_MOUNTED"
# a write through /mnt/user during the check lands in the bare folder: the destroy goes ahead, and OpenZFS keeps a folder
# that is not empty
From dfdc4050e53bb80d97d7309ad0fd44b2c4d31940 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 18:13:18 +0800
Subject: [PATCH 49/94] Fix the folder cleanup's failed-move, top-folder and
count gaps
- An empty folder whose move failed is no longer deleted from the source, so it no longer ends up nowhere.
- A moved folder whose parent is also gone no longer skips the row's progress update.
- Clean Folders Yes keeps the share's top folder; Top Folder mode still removes it after the pass.
- The top-folder check no longer walks a dataset's .zfs snapshots or mounts inside the share.
- The per-folder file count only drops for names that left the source, and not twice for a hardlink group.
---
.../emhttp/plugins/ca.mover.tuning/age_mover | 62 +++++++-------
tests/age_mover/test_folders.sh | 84 +++++++++++++++++++
2 files changed, 114 insertions(+), 32 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index fff03cee..44fa3edc 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -2576,20 +2576,30 @@ note_emptied_share() { note_top_folder; note_share_dataset; }
# Deletes share top folder $1 if it is empty, unless it is a ZFS dataset mountpoint or test mode is on
cleanTopFolder() {
- local top_folder=$1 file_count dir_count
+ local top_folder=$1 file_count dir_count dataset=no pat skip=()
[ -d "$top_folder" ] || return 0
if [ -e "${top_folder}/.placeholder" ]; then
mvlogger "Not deleting top-level folder: contains .placeholder: ${top_folder}"
return 0
fi
- file_count=$(find "$top_folder" -type f | wc -l)
- dir_count=$(find "$top_folder" -mindepth 1 -type d | wc -l)
+ # a dataset's .zfs holds the snapshots snapdir=visible shows, and a walk would mount each one. -path is a glob, so
+ # the folder's own \ * ? [ are escaped
+ if is_zfs_dataset_mountpoint "$top_folder"; then
+ dataset=yes
+ pat=${top_folder//\\/\\\\}
+ pat=${pat//\*/\\*}
+ pat=${pat//\?/\\?}
+ skip=(-path "${pat//\[/\\[}/.zfs" -prune -o)
+ fi
+ # -xdev: a mount inside, such as a child dataset, is counted but not walked
+ file_count=$(find "$top_folder" -xdev "${skip[@]}" -type f -print | wc -l)
+ dir_count=$(find "$top_folder" -xdev -mindepth 1 "${skip[@]}" -type d -print | wc -l)
mvDebuglogger "Top folder: $(qp "$top_folder"), share file(s): $file_count, share folder(s): $dir_count" "Clean Top Folder"
if [ "$file_count" -ne 0 ] || [ "$dir_count" -ne 0 ]; then
mvlogger "Not deleting top-level folder: contains $file_count file(s), $dir_count subfolder(s): ${top_folder}"
elif [ "$TESTMODE" != "no" ]; then
mvlogger "TEST MODE: Would delete empty top-level folder: $top_folder"
- elif is_zfs_dataset_mountpoint "$top_folder"; then
+ elif [ "$dataset" = yes ]; then
mvlogger "Skipping deletion of ZFS dataset mountpoint: $top_folder"
elif rmdir "$top_folder" 2>/dev/null; then
mvlogger "Deleted empty top-level folder: $top_folder"
@@ -2997,6 +3007,7 @@ processTheMoves() {
# Define a function to handle the directory cleanup logic.
# Iterate the array directly (was: echo "$SYNCED_FILES" | xargs),
# so filenames with quotes/spaces/special chars are handled safely.
+ counted_in_row=0
for FILE in "${SYNCED_FILES_ARR[@]}"; do
# Collapse the rsync --relative marker ("/./" -> "/")
FILE="${FILE//\/.\//\/}"
@@ -3005,24 +3016,15 @@ processTheMoves() {
if [ -e "${DIR}/.placeholder" ]; then
count=".placeholder"
+ elif [ "${LAST_DIR}" != "${DIR}" ]; then
+ LAST_COUNT=$(find "$DIR" -maxdepth 1 -type f | wc -l)
+ LAST_DIR=$DIR
+ counted_in_row=1
+ count=$LAST_COUNT
else
- # Check if the current directory is same as the previous one
- if [ "${LAST_DIR}" == "${DIR}" ]; then
- # Check if the counter is greater than 0 to avoid counting files in the folder using wc -l
- if [ "$LAST_COUNT" -gt 0 ]; then
- count=$((LAST_COUNT - 1))
- # Save current counter
- LAST_COUNT="$count"
- fi
- else
- #count=$(ls -A "$DIR" | wc -l)
- count=$(find "$DIR" -maxdepth 1 -type f | wc -l)
- # Save current counter
- LAST_COUNT="$count"
- # Save current Folder
- LAST_DIR="$DIR"
- # echo "Directory changed to: ${DIR}, Count of files: $count"
- fi
+ # a count taken in this row already left out its moved names; a later row's name lowers it once it left
+ [ "$counted_in_row" = 1 ] || [ -e "$FILE" ] || [ "$LAST_COUNT" = 0 ] || LAST_COUNT=$((LAST_COUNT - 1))
+ count=$LAST_COUNT
fi
mvDebuglogger "Cycle of delete folder, Previous count: $LAST_COUNT, Count of file(s): $count" "Clean Folder - End Loop"
@@ -3030,7 +3032,8 @@ processTheMoves() {
mvlogger "Not deleting folder containing $count file$([ "$count" != ".placeholder" ] && echo "s"): ${DIR}"
else
note_emptied_share
- if [ "$TESTMODE" = "no" ]; then
+ # the share's top folder is cleanTopFolder's, after the pass and in topFolder mode only
+ if [ "$TESTMODE" = "no" ] && [ "$DIR" != "${SOURCE}/${SHARENAME}" ]; then
# Check if empty folder exists and remove it (but skip ZFS dataset mountpoints)
if [ -d "${DIR}" ]; then
if ! is_zfs_dataset_mountpoint "${DIR}"; then
@@ -3048,21 +3051,16 @@ processTheMoves() {
done
fi
- # Clean moved empty folders
- if [[ "$ACTION" =~ "move" && "$FILETYPE" == "d" ]] && [ "$MOVE_EMPTY_FOLDERS" = "yes" ]; then
+ # Clean moved empty folders, once the folder arrived: a failed move's would exist nowhere
+ if [[ "$ACTION" =~ "move" && "$FILETYPE" == "d" ]] && [ "$MOVE_EMPTY_FOLDERS" = "yes" ] && [ "$arrived" -gt 0 ]; then
START_DIR="${SOURCE}/${FILEPATH}"
LAST_FOLDER_COUNT=$((REMAINING_CACHE_FOLDERS + REMAINING_ARRAY_FOLDERS + REMAINING_UNATTENDED_FOLDERS))
- # If Unraid already deleted the folder (move mode) using upper folder, skip cleanup
+ # Unraid's move deletes the folder itself; a parent gone too leaves the walk below nothing to do
if [ ! -d "$START_DIR" ]; then
- START_DIR="$(dirname "${START_DIR}")"
- if [ -d "$START_DIR" ]; then
- [ "$DEBUGLEVEL" != 0 ] && mvDebuglogger "Skipping cleanup: $(qp "$START_DIR") no longer exists, using upper folder: $(qp "$(dirname "${START_DIR}")")" "Clean Empty Moved Folder"
- else
- [ "$DEBUGLEVEL" != 0 ] && mvDebuglogger "Skipping cleanup: $(qp "$START_DIR") no longer exists" "Clean Empty Moved Folder"
- continue
- fi
+ [ "$DEBUGLEVEL" != 0 ] && mvDebuglogger "$(qp "$START_DIR") is gone from the source: cleaning from $(qp "$(dirname "$START_DIR")")" "Clean Empty Moved Folder"
+ START_DIR=$(dirname "$START_DIR")
fi
# Build list of parent directories
diff --git a/tests/age_mover/test_folders.sh b/tests/age_mover/test_folders.sh
index b920d9f2..95f37abb 100644
--- a/tests/age_mover/test_folders.sh
+++ b/tests/age_mover/test_folders.sh
@@ -29,6 +29,23 @@ for cf in no yes topFolder; do
[ "$cf" = no ] || log_has 'Not deleting folder containing 1 files: /mnt/cache/sh/only'
done
+# the share's top folder is the top-folder check's, after the pass: Yes never deletes it
+for cf in yes topFolder; do
+ begin "Clean Folders $cf, a file in the share's top folder" cleanFolders "$cf"
+ mk cache sh/f.txt
+ row 'move from primary' f sh/f.txt | list
+ run_moves
+ array_is sh sh/f.txt
+ log_lacks 'Deleted empty folder: /mnt/cache/sh'
+ if [ "$cf" = yes ]; then
+ cache_is sh
+ log_lacks 'top-level'
+ else
+ cache_is
+ log_has 'Deleted empty top-level folder: /mnt/cache/sh'
+ fi
+done
+
begin "topFolder, a share that keeps a file elsewhere" cleanFolders topFolder
mk cache sh/a/f.txt sh/keep/k.txt
row 'move from primary' f sh/a/f.txt | list
@@ -44,6 +61,27 @@ cache_is sh sh/a sh/a/g.txt
log_has 'Not deleting folder containing 1 files: /mnt/cache/sh/a'
log_lacks 'top-level'
+# a folder on the array where b.txt goes makes its move fail: b.txt stays, and the count after it keeps it
+begin "topFolder, three rows in one folder, the middle one fails" cleanFolders topFolder
+mk cache sh/d/a.txt sh/d/b.txt sh/d/c.txt
+mkdir -p /mnt/user0/sh/d/b.txt/x
+for f in a b c; do row 'move from primary' f "sh/d/$f.txt"; done | list
+run_moves
+cache_is sh sh/d sh/d/b.txt
+log_count 2 'Not deleting folder containing 2 files: /mnt/cache/sh/d'
+log_has 'Not deleting folder containing 1 files: /mnt/cache/sh/d'
+log_lacks 'top-level'
+
+# both names leave in one row, so the count taken after it already lacks the second
+begin "topFolder, a hardlink group in one folder beside another file" cleanFolders topFolder
+mk cache sh/h/a.txt sh/h/k.txt
+ln /mnt/cache/sh/h/a.txt /mnt/cache/sh/h/b.txt
+{ row 'move from primary' f sh/h/a.txt; row 'move from primary' f sh/h/b.txt; } | list
+run_moves
+cache_is sh sh/h sh/h/k.txt
+log_count 2 'Not deleting folder containing 1 files: /mnt/cache/sh/h'
+log_lacks 'top-level'
+
# the count takes files only, so the folder looks empty: rmdir alone keeps the subfolder's file
begin "topFolder, the file's folder keeps a subfolder with a file" cleanFolders topFolder
mk cache sh/a/f.txt sh/a/sub/g.txt
@@ -100,6 +138,26 @@ for tm in no yes; do
fi
done
+# a dataset's .zfs is not counted: with snapdir=visible a walk would mount and count every snapshot. The name's [ ]
+# would make a glob of the path
+for s in sh 'sh[1]'; do
+ begin "topFolder, the top folder $s is a ZFS dataset showing a snapshot" cleanFolders topFolder
+ mk cache "$s/only/f.txt" "$s/.zfs/snapshot/s1/only/f.txt"
+ echo "/mnt/cache/$s" >"$T/zfs"
+ row 'move from primary' f "$s/only/f.txt" | list
+ run_moves
+ log_has "Skipping deletion of ZFS dataset mountpoint: /mnt/cache/$s"
+ log_lacks 'Not deleting top-level folder'
+done
+
+# only a dataset has snapshots in .zfs: in a plain folder it is a folder like any other
+begin "topFolder, a plain top folder holding a folder named .zfs" cleanFolders topFolder
+mk cache sh/only/f.txt sh/.zfs/k.txt
+row 'move from primary' f sh/only/f.txt | list
+run_moves
+cache_is sh sh/.zfs sh/.zfs/k.txt
+log_has 'Not deleting top-level folder: contains 1 file(s), 1 subfolder(s): /mnt/cache/sh'
+
begin "topFolder in test mode, a share holding one empty folder" cleanFolders topFolder testmode yes
mkdir -p /mnt/cache/sh/e
row 'move from primary' d sh/e | list
@@ -148,6 +206,32 @@ cache_is sh sh/p sh/p/k.txt
log_has 'Not deleting folder: contains 1 file(s), 0 subfolder(s): /mnt/cache/sh/p'
log_lacks 'top-level'
+# the folder stays, or it would exist nowhere. Unraid's move cannot make the share's folder over a file; rsync
+# replaces the file, so its copy is taken away instead
+for tool in rsync move; do
+ begin "topFolder, a folder row that does not arrive ($tool)" cleanFolders topFolder movefilesTool "$tool"
+ mkdir -p /mnt/cache/sh/p/e
+ if [ "$tool" = move ]; then printf 'x\n' >/mnt/user0/sh; else after_first_rsync 'rm -r /mnt/user0/sh'; fi
+ row 'move from primary' d sh/p/e | list
+ run_moves
+ cache_is sh sh/p sh/p/e
+ log_has 'Did not arrive: "/mnt/cache/sh/p/e"'
+ log_lacks 'Deleted empty moved folder'
+ log_lacks 'top-level'
+done
+
+# the folder's parent goes during its move: the row still leaves the remaining counters
+begin "Clean Folders yes, a folder row whose parent is gone after its move" cleanFolders yes
+mkdir -p /mnt/cache/sh/p/e
+row 'move from primary' d sh/p/e | list
+after_first_rsync 'rm -r /mnt/cache/sh/p'
+run_moves
+cache_is sh
+array_is sh sh/p sh/p/e
+counter REMAINING_CACHE_FOLDERS 0
+log_has '0 folders remaining from caches to array'
+[ "${AGE_MOVER_DEBUG:-0}" != 2 ] || dlog_has '"/mnt/cache/sh/p/e" is gone from the source: cleaning from "/mnt/cache/sh/p"'
+
# the reporter's shape: one top-folder check for the share, whichever row empties a folder first
for order in file-first folders-first; do
begin "topFolder, one file row and three folder rows, $order" cleanFolders topFolder
From e07de529db5074906fbdbdca6d6a80301266dab2 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 18:31:51 +0800
Subject: [PATCH 50/94] Recount a folder after a name gone before its turn;
keep test mode's countdown
---
.../emhttp/plugins/ca.mover.tuning/age_mover | 14 +++++++------
tests/age_mover/test_folders.sh | 21 ++++++++++++++++++-
2 files changed, 28 insertions(+), 7 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index 44fa3edc..3505ecc2 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -3008,22 +3008,24 @@ processTheMoves() {
# Iterate the array directly (was: echo "$SYNCED_FILES" | xargs),
# so filenames with quotes/spaces/special chars are handled safely.
counted_in_row=0
- for FILE in "${SYNCED_FILES_ARR[@]}"; do
+ for key in "${SYNCED_FILES_ARR[@]}"; do
# Collapse the rsync --relative marker ("/./" -> "/")
- FILE="${FILE//\/.\//\/}"
+ FILE="${key//\/.\//\/}"
DIR=$(dirname "$FILE")
[ "$DEBUGLEVEL" != 0 ] && mvDebuglogger "Current file: $(qp "$FILE"), Current folder: $(qp "$DIR"), Previous folder: $(qp "$LAST_DIR"), Previous count: $LAST_COUNT" "Clean Folder - Start Loop"
if [ -e "${DIR}/.placeholder" ]; then
count=".placeholder"
- elif [ "${LAST_DIR}" != "${DIR}" ]; then
+ # a name gone before its turn may have left before an earlier row's count: its folder is counted again
+ elif [ "${LAST_DIR}" != "${DIR}" ] || [ -n "${GONE_BEFORE[$key]}" ]; then
LAST_COUNT=$(find "$DIR" -maxdepth 1 -type f | wc -l)
LAST_DIR=$DIR
counted_in_row=1
count=$LAST_COUNT
else
- # a count taken in this row already left out its moved names; a later row's name lowers it once it left
- [ "$counted_in_row" = 1 ] || [ -e "$FILE" ] || [ "$LAST_COUNT" = 0 ] || LAST_COUNT=$((LAST_COUNT - 1))
+ # a count taken in this row already left out its moved names; a later row's name lowers it once it
+ # left. Test mode moves nothing: each later name lowers it
+ [ "$LAST_COUNT" = 0 ] || { [ "$TESTMODE" = no ] && { [ "$counted_in_row" = 1 ] || [ -e "$FILE" ]; }; } || LAST_COUNT=$((LAST_COUNT - 1))
count=$LAST_COUNT
fi
mvDebuglogger "Cycle of delete folder, Previous count: $LAST_COUNT, Count of file(s): $count" "Clean Folder - End Loop"
@@ -3059,7 +3061,7 @@ processTheMoves() {
# Unraid's move deletes the folder itself; a parent gone too leaves the walk below nothing to do
if [ ! -d "$START_DIR" ]; then
- [ "$DEBUGLEVEL" != 0 ] && mvDebuglogger "$(qp "$START_DIR") is gone from the source: cleaning from $(qp "$(dirname "$START_DIR")")" "Clean Empty Moved Folder"
+ [ "$DEBUGLEVEL" != 0 ] && mvDebuglogger "$(qp "$START_DIR") is gone from the source: the walk starts at its parent $(qp "$(dirname "$START_DIR")")" "Clean Empty Moved Folder"
START_DIR=$(dirname "$START_DIR")
fi
diff --git a/tests/age_mover/test_folders.sh b/tests/age_mover/test_folders.sh
index 95f37abb..80bce166 100644
--- a/tests/age_mover/test_folders.sh
+++ b/tests/age_mover/test_folders.sh
@@ -72,6 +72,25 @@ log_count 2 'Not deleting folder containing 2 files: /mnt/cache/sh/d'
log_has 'Not deleting folder containing 1 files: /mnt/cache/sh/d'
log_lacks 'top-level'
+# a name gone before its turn may have left before the count: its folder is counted again
+begin "topFolder, a row's file gone before the run, beside a file that stays" cleanFolders topFolder
+mk cache sh/d/x.txt sh/d/y.txt sh/d/z.txt
+{ row 'move from primary' f sh/d/x.txt; row 'move from primary' f sh/d/y.txt; } | list
+rm /mnt/cache/sh/d/y.txt
+run_moves
+cache_is sh sh/d sh/d/z.txt
+log_has 'Gone from the source before its turn: "/mnt/cache/sh/d/y.txt"'
+log_count 2 'Not deleting folder containing 1 files: /mnt/cache/sh/d'
+
+# test mode moves nothing, so each later row lowers the count by one
+begin "Clean Folders yes in test mode, three rows in one folder" cleanFolders yes testmode yes
+mk cache sh/d/a.txt sh/d/b.txt sh/d/c.txt
+for f in a b c; do row 'move from primary' f "sh/d/$f.txt"; done | list
+run_moves
+cache_is sh sh/d sh/d/a.txt sh/d/b.txt sh/d/c.txt
+check "the folder's counts, one a row" "$(printf '%s\n' 3 2 1)" \
+ "$(log | grep -oE 'Not deleting folder containing [0-9]+ files: /mnt/cache/sh/d' | grep -oE '[0-9]+')"
+
# both names leave in one row, so the count taken after it already lacks the second
begin "topFolder, a hardlink group in one folder beside another file" cleanFolders topFolder
mk cache sh/h/a.txt sh/h/k.txt
@@ -230,7 +249,7 @@ cache_is sh
array_is sh sh/p sh/p/e
counter REMAINING_CACHE_FOLDERS 0
log_has '0 folders remaining from caches to array'
-[ "${AGE_MOVER_DEBUG:-0}" != 2 ] || dlog_has '"/mnt/cache/sh/p/e" is gone from the source: cleaning from "/mnt/cache/sh/p"'
+[ "${AGE_MOVER_DEBUG:-0}" != 2 ] || dlog_has '"/mnt/cache/sh/p/e" is gone from the source: the walk starts at its parent "/mnt/cache/sh/p"'
# the reporter's shape: one top-folder check for the share, whichever row empties a folder first
for order in file-first folders-first; do
From ea1090416ad6cde6ea92c1b1b25eca899dfe0abc Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 18:48:42 +0800
Subject: [PATCH 51/94] Probe the private mount after a failed umount; guard
the php stand-in's path
- A umount that unmounts but exits nonzero no longer reports the dataset as still mounted at the private folder: the mount table decides, and the dataset is mounted back.
- The tests refuse a host mount at /usr/bin or /usr/bin/php, where the php stand-in is written.
- The pid-file stop case checks the stop ended before it checks the pid file.
---
.../emhttp/plugins/ca.mover.tuning/age_mover | 15 +++++++++------
tests/age_mover/lib.sh | 10 +++++++---
tests/age_mover/test_dataset_stops.sh | 1 +
tests/age_mover/test_datasets.sh | 8 +++++++-
4 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index 629ebc82..2a610d8f 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -2613,7 +2613,7 @@ dataset_loses() {
}
# Mounts the unmounted dataset $1 read-only at empty folder $2 and prints dataset_loses there against $4, with $2 shown
-# as $3; prints why and fails when it cannot mount or read it, and returns 2, still mounted, with umount's reason
+# as $3; prints why and fails when it cannot mount or read it, and returns 2 with umount's reason when umount fails
dataset_loses_unmounted() {
local err lost
if ! err=$(mount -t zfs -o ro,zfsutil "$1" "$2" 2>&1); then
@@ -2711,11 +2711,14 @@ unmount_check_destroy() {
# a file written between the first check and the unmount is in the dataset: checked again where nothing can write
lost=$(finish_on_stop dataset_loses_unmounted "$dataset" "$private" "$folder" "$3")
rc=$?
- # a failed or killed check may leave the dataset at the private folder: mount.zfs can fail after mounting
- if [ "$rc" != 0 ] && [ "$rc" != 2 ]; then
- [ "$rc" = 1 ] || lost="the check was cut short"
- if [ "$(finish_on_stop findmnt -no source --mountpoint "$private")" = "$dataset" ] &&
- ! err=$(finish_on_stop umount "$private" 2>&1); then
+ # a failed or killed check may leave the dataset at the private folder: mount.zfs can fail after mounting, and
+ # umount after unmounting, so the mount table decides
+ if [ "$rc" != 0 ]; then
+ [ "$rc" = 1 ] || [ "$rc" = 2 ] || lost="the check was cut short"
+ if [ "$(finish_on_stop findmnt -no source --mountpoint "$private")" != "$dataset" ]; then
+ # unmounted after all, but what the check found was not kept
+ [ "$rc" != 2 ] || { lost="umount: $lost"; rc=1; }
+ elif [ "$rc" != 2 ] && ! err=$(finish_on_stop umount "$private" 2>&1); then
lost=$(zfs_reason "${err#umount: }")
rc=2
fi
diff --git a/tests/age_mover/lib.sh b/tests/age_mover/lib.sh
index 31a68a73..6232a155 100644
--- a/tests/age_mover/lib.sh
+++ b/tests/age_mover/lib.sh
@@ -11,11 +11,11 @@ ROOTS=(/mnt/cache /mnt/user0 /mnt/disk1 /mnt/disk2 /mnt/other)
# a mount at or under /mnt would put the host's files under the wipe, and one at a stand-in's path or above it the
# host's own under the stand-in; an unreadable mount table refuses too
no_host_mount() {
- awk '$5 == "/mnt" || index($5, "/mnt/") == 1 || $5 ~ "^/usr(/libexec(/unraid(/move)?)?)?$" ||
+ awk '$5 == "/mnt" || index($5, "/mnt/") == 1 || $5 ~ "^/usr(/bin(/php)?|/libexec(/unraid(/move)?)?)?$" ||
$5 ~ "^/usr/local(/emhttp(/webGui(/scripts(/notify)?)?)?)?$" { exit 1 }' /proc/self/mountinfo
}
if [ "${AGE_MOVER_TEST:-}" != 1 ] || [ ! -e /.dockerenv ] || ! no_host_mount; then
- echo "lib.sh deletes ${ROOTS[*]} and writes /usr/libexec/unraid/move and /usr/local/emhttp/webGui/scripts/notify: start" \
+ echo "lib.sh deletes ${ROOTS[*]} and writes /usr/bin/php, /usr/libexec/unraid/move and /usr/local/emhttp/webGui/scripts/notify: start" \
"the tests with tests/age_mover/run.sh" >&2
exit 2
fi
@@ -115,7 +115,7 @@ esac
EOF
# mount -t zfs -o ro,zfsutil DATASET DIR moves an unmounted dataset's files into an empty DIR outside /mnt, umount back. Both log
# to zfs.calls (a mktemp DIR as PRIVATE), run zfs.on_mount.zfs or zfs.on_umount, fail on mount.zfs (zfs.reason: all it says) or umount;
-# mount.zfs.late mounts, then fails, as mount.zfs does when it cannot update /etc/mtab
+# mount.zfs.late mounts, then fails, as mount.zfs does when it cannot update /etc/mtab; umount.late, as umount does
cat >"$T/bin/mount" <<'EOF'
#!/bin/bash
d=${0%/bin/mount}
@@ -161,6 +161,10 @@ fi
find "$p" -mindepth 1 -maxdepth 1 -exec mv -t "$d/zfs.store/${l#*$'\t'}" {} +
grep -vxF -- "$l" "$d/zfs.private" >"$d/zfs.new"
mv "$d/zfs.new" "$d/zfs.private"
+if grep -qxF umount.late "$d/zfs.fail" 2>/dev/null; then
+ echo "umount: $p: filesystem was unmounted, but failed to update userspace mount table" >&2
+ exit 16
+fi
EOF
# as Linux does, rmdir refuses a folder something is mounted on
cat >"$T/bin/rmdir" <<'EOF'
diff --git a/tests/age_mover/test_dataset_stops.sh b/tests/age_mover/test_dataset_stops.sh
index 8a5ec80d..fa08f6d4 100644
--- a/tests/age_mover/test_dataset_stops.sh
+++ b/tests/age_mover/test_dataset_stops.sh
@@ -252,6 +252,7 @@ one_share
{ stop_hook plugin; echo "echo 1 >\"$T/pid\""; } >"$T/zfs.on_unmount"
run_moves 'processTheMoves did not return'
for _ in $(seq 100); do grep -qs 'mover: stopped' "$T/stop.out" && break; sleep 0.1; done
+check "the plugin's stop ended" 1 "$(grep -cs 'mover: stopped' "$T/stop.out")"
check "the other run's pid file stays" 1 "$(cat "$T/pid" 2>/dev/null)"
rm -f "$T/stop.out" "$T/pid"
mounted_again
diff --git a/tests/age_mover/test_datasets.sh b/tests/age_mover/test_datasets.sh
index 2e524c92..fe418506 100644
--- a/tests/age_mover/test_datasets.sh
+++ b/tests/age_mover/test_datasets.sh
@@ -324,7 +324,7 @@ done
# errorsOnly sends only a failure: a failed unmount, destroy or remount, or a dataset left at the private folder, notifies;
# a check that cannot run only warns
for fail in list unmount 'unmount, busy,' destroy 'destroy and mount' 'destroy, busy,' 'the read-only mount' \
- 'the read-only mount, busy,' 'the read-only unmount' mktemp; do
+ 'the read-only mount, busy,' 'the read-only unmount' 'the read-only unmount, after unmounting,' mktemp; do
what="zfs $fail"
[[ $fail != the* && $fail != mktemp ]] || what=$fail
begin "Clean ZFS datasets, $what fails" cleanFolders topFolder cleanDatasets yes notify errorsOnly
@@ -338,6 +338,7 @@ for fail in list unmount 'unmount, busy,' destroy 'destroy and mount' 'destroy,
# as OpenZFS says it while a container's mount holds the dataset
'the read-only mount, busy,') echo mount.zfs; echo 'zfs_mount_at() failed: mountpoint or dataset is busy' >"$T/zfs.reason" ;;
'the read-only unmount') echo umount ;;
+ 'the read-only unmount, after unmounting,') echo umount.late ;;
mktemp) ;;
*) echo "$fail" ;;
esac >"$T/zfs.fail"
@@ -353,6 +354,11 @@ for fail in list unmount 'unmount, busy,' destroy 'destroy and mount' 'destroy,
log_has "ZFS dataset [cache/sh] is still mounted read-only at $private, not at /mnt/cache/sh: umount: $private: zfs.fail"
log_has "ZFS dataset [cache/sh]: mounted read-only at $private: stop writes to the share, umount $private, $BACK"
;;
+ # unmounted after all: what the check found was lost with umount's answer, so the dataset is mounted back
+ *after\ unmounting*)
+ check "the late umount's reason" 1 "$(log | grep -F -- "$unchecked umount: ${TMPDIR:-/tmp}/ca.mover.tuning." |
+ grep -cF ': filesystem was unmounted, but failed to update userspace mount table')"
+ ;;
mktemp) log_has "$unchecked mktemp: No such file or directory"; log_lacks 'attempting to unmount' ;;
# the failure notice goes out with the "Failed to" line
*busy*)
From 6483f79c1be973f6537fdbd49a9c151099a20fb3 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 19:05:42 +0800
Subject: [PATCH 52/94] Count a folder's own subfolders only in the
moved-folder walk
A count over the whole tree walked a child dataset's visible snapshots, mounting each one.
---
.../usr/local/emhttp/plugins/ca.mover.tuning/age_mover | 4 ++--
tests/age_mover/test_folders.sh | 9 +++++++++
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index 3505ecc2..3776f2dd 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -3095,9 +3095,9 @@ processTheMoves() {
break
fi
- # Count files and subdirectories
+ # the folder's own entries only: a walk below would mount each snapshot a child dataset shows
empty_file_count=$(find "$DIR" -maxdepth 1 -type f | wc -l)
- empty_dir_count=$(find "$DIR" -mindepth 1 -type d | wc -l)
+ empty_dir_count=$(find "$DIR" -mindepth 1 -maxdepth 1 -type d | wc -l)
# Folder is truly empty
if [ "$empty_file_count" -eq 0 ] && [ "$empty_dir_count" -eq 0 ]; then
diff --git a/tests/age_mover/test_folders.sh b/tests/age_mover/test_folders.sh
index 80bce166..fb546f53 100644
--- a/tests/age_mover/test_folders.sh
+++ b/tests/age_mover/test_folders.sh
@@ -225,6 +225,15 @@ cache_is sh sh/p sh/p/k.txt
log_has 'Not deleting folder: contains 1 file(s), 0 subfolder(s): /mnt/cache/sh/p'
log_lacks 'top-level'
+# the parent's own subfolder counts once: the walk does not go below it
+begin "topFolder, a folder row whose parent keeps a nested subfolder" cleanFolders topFolder
+mkdir -p /mnt/cache/sh/p/e /mnt/cache/sh/p/k/a/b
+row 'move from primary' d sh/p/e | list
+run_moves
+cache_is sh sh/p sh/p/k sh/p/k/a sh/p/k/a/b
+log_has 'Not deleting folder: contains 0 file(s), 1 subfolder(s): /mnt/cache/sh/p'
+log_lacks 'top-level'
+
# the folder stays, or it would exist nowhere. Unraid's move cannot make the share's folder over a file; rsync
# replaces the file, so its copy is taken away instead
for tool in rsync move; do
From 7845dc09a76d09e76460c17410603a14bfccab09 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 19:52:07 +0800
Subject: [PATCH 53/94] Keep a dataset whose scan was killed before it finished
dataset_loses now succeeds once it has looked, so an empty result with a failed status means the scan never finished. At the private mount that is reported as a cut-short check; the first check keeps the dataset, as it keeps one it cannot read.
---
.../emhttp/plugins/ca.mover.tuning/age_mover | 15 +++++----
tests/age_mover/test_dataset_stops.sh | 33 +++++++++++++++++--
2 files changed, 40 insertions(+), 8 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index 2a610d8f..0fb7fa20 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -2600,7 +2600,7 @@ cleanTopFolder() {
}
# Prints folder $1's first entry that is not a folder, or is a folder that folder $2 lacks; $1 itself when cd or find fails.
-# Skips $1/.zfs, which snapdir=visible shows: its snapshots keep the dataset at the children check
+# Succeeds once it has looked. Skips $1/.zfs, which snapdir=visible shows: its snapshots keep the dataset at the children check
dataset_loses() {
local src=$1 dest=$2 entry
# two passes: the destination is read only once nothing but folders is left
@@ -2608,23 +2608,25 @@ dataset_loses() {
first=$(find . -mindepth 1 -path ./.zfs -prune -o ! -type d -print -quit) || exit
[ -n "$first" ] && { printf '%s' "$first"; exit; }
find . -mindepth 1 -path ./.zfs -prune -o -type d ! -exec test -d "$dest/{}" \; -print -quit
- }) || { printf '%s' "$src"; return; }
- [ -n "$entry" ] && printf '%s' "$src/${entry#./}"
+ }) || { printf '%s' "$src"; return 0; }
+ [ -z "$entry" ] || printf '%s' "$src/${entry#./}"
}
# Mounts the unmounted dataset $1 read-only at empty folder $2 and prints dataset_loses there against $4, with $2 shown
# as $3; prints why and fails when it cannot mount or read it, and returns 2 with umount's reason when umount fails
dataset_loses_unmounted() {
- local err lost
+ local err lost scanned=yes
if ! err=$(mount -t zfs -o ro,zfsutil "$1" "$2" 2>&1); then
printf 'mount: %s' "$(zfs_reason "${err#mount: }")"
return 1
fi
- lost=$(dataset_loses "$2" "$4")
+ # a scan cut short prints nothing, as a clean one does: only its status tells them apart
+ lost=$(dataset_loses "$2" "$4") || scanned=
if ! err=$(umount "$2" 2>&1); then
printf '%s' "$(zfs_reason "${err#umount: }")"
return 2
fi
+ [ -n "$scanned" ] || { printf 'the check was cut short'; return 1; }
# dataset_loses names its folder itself when it cannot read it
[ "$lost" != "$2" ] || { printf 'find: the dataset could not be read'; return 1; }
[ -z "$lost" ] || printf '%s' "$3${lost#"$2"}"
@@ -2763,7 +2765,8 @@ cleanShareDataset() {
mvlogger "ZFS dataset [${dataset}] could not be listed, will not delete: $(zfs_reason "$names")"
return 0
fi
- lost=$(finish_on_stop dataset_loses "$folder" "$3/$2")
+ # cut short, it is kept as a folder it cannot read is
+ lost=$(finish_on_stop dataset_loses "$folder" "$3/$2") || lost=$folder
if [ -n "$lost" ]; then
dataset_kept "$dataset" "$lost"
return 0
diff --git a/tests/age_mover/test_dataset_stops.sh b/tests/age_mover/test_dataset_stops.sh
index fa08f6d4..ebd053f6 100644
--- a/tests/age_mover/test_dataset_stops.sh
+++ b/tests/age_mover/test_dataset_stops.sh
@@ -38,14 +38,14 @@ stop_done() {
rm -f "$T/stop.out" "$T/pid.kept"
}
# a hook, run once after command $2, that sends signal $1 to every process from its caller up to, not including, the run
+# and its $3 (default 0) nearest
kill_hook() {
cat <"$T/find.hook"
+ else
+ kill_hook KILL : 1 >"$T/kill.hook"
+ printf '%s\n' 'echo x >/mnt/cache/sh/new.txt' "cp \"$T/kill.hook\" \"$T/find.hook\"" >"$T/zfs.on_unmount"
+ fi
+ PATH=$T/wrap:$PATH run_moves
+ log_lacks 'successfully destroyed'
+ if [ "$which" = 'first check' ]; then
+ check "zfs calls" "zfs $LS cache/sh" "$(cat "$T/zfs.calls")"
+ log_lacks 'attempting to unmount'
+ notices ''
+ continue
+ fi
+ check "zfs calls" "$REMOUNTED" "$(cat "$T/zfs.calls")"
+ log_has 'ZFS dataset [cache/sh] could not be checked once unmounted, will not delete: the check was cut short'
+ notices "$NOTICE"
+ mounted_again
+ cache_is sh sh/new.txt
+ no_private
+done
+
finish
From 4a1b1a9e57e67c2afa100bdb205da3ae8204a68e Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 19:52:51 +0800
Subject: [PATCH 54/94] Say a cut-short scan can print nothing
---
.../usr/local/emhttp/plugins/ca.mover.tuning/age_mover | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index 0fb7fa20..07be6f64 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -2620,7 +2620,7 @@ dataset_loses_unmounted() {
printf 'mount: %s' "$(zfs_reason "${err#mount: }")"
return 1
fi
- # a scan cut short prints nothing, as a clean one does: only its status tells them apart
+ # a scan cut short can print nothing, as a clean one does: only its status tells them apart
lost=$(dataset_loses "$2" "$4") || scanned=
if ! err=$(umount "$2" 2>&1); then
printf '%s' "$(zfs_reason "${err#umount: }")"
From 09aaf896ad151ca72626d9c3d25dd4a2a0bbc5fc Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 19:57:08 +0800
Subject: [PATCH 55/94] Count nothing in a folder an earlier row deleted
The recount after a name gone before its turn ran find on a folder the row before had emptied and deleted, which printed an error.
---
.../usr/local/emhttp/plugins/ca.mover.tuning/age_mover | 4 +++-
tests/age_mover/test_folders.sh | 9 +++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index 3776f2dd..121dab25 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -3018,7 +3018,9 @@ processTheMoves() {
count=".placeholder"
# a name gone before its turn may have left before an earlier row's count: its folder is counted again
elif [ "${LAST_DIR}" != "${DIR}" ] || [ -n "${GONE_BEFORE[$key]}" ]; then
- LAST_COUNT=$(find "$DIR" -maxdepth 1 -type f | wc -l)
+ # an earlier row may have emptied and deleted it
+ LAST_COUNT=0
+ [ ! -d "$DIR" ] || LAST_COUNT=$(find "$DIR" -maxdepth 1 -type f | wc -l)
LAST_DIR=$DIR
counted_in_row=1
count=$LAST_COUNT
diff --git a/tests/age_mover/test_folders.sh b/tests/age_mover/test_folders.sh
index fb546f53..f220639a 100644
--- a/tests/age_mover/test_folders.sh
+++ b/tests/age_mover/test_folders.sh
@@ -91,6 +91,15 @@ cache_is sh sh/d sh/d/a.txt sh/d/b.txt sh/d/c.txt
check "the folder's counts, one a row" "$(printf '%s\n' 3 2 1)" \
"$(log | grep -oE 'Not deleting folder containing [0-9]+ files: /mnt/cache/sh/d' | grep -oE '[0-9]+')"
+# the earlier row deletes the folder, so the vanished name's recount finds no folder and counts nothing
+begin "topFolder, a row's file gone before the run, in a folder an earlier row empties" cleanFolders topFolder
+mk cache sh/d/a.txt sh/d/b.txt sh/keep.txt
+{ row 'move from primary' f sh/d/a.txt; row 'move from primary' f sh/d/b.txt; } | list
+rm /mnt/cache/sh/d/b.txt
+run_moves
+cache_is sh sh/keep.txt
+log_count 1 'Deleted empty folder: /mnt/cache/sh/d'
+
# both names leave in one row, so the count taken after it already lacks the second
begin "topFolder, a hardlink group in one folder beside another file" cleanFolders topFolder
mk cache sh/h/a.txt sh/h/k.txt
From ec13d05ccf133a5a647234be7290c436c0a67569 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 19:35:16 +0800
Subject: [PATCH 56/94] Make test mode's folder lines predict a real run's
Test mode notes what a real move or folder deletion would take off the source, and each folder count leaves it out. A ZFS dataset's top folder is skipped in test mode too.
---
.../emhttp/plugins/ca.mover.tuning/age_mover | 72 +++++---
tests/age_mover/test_datasets.sh | 2 +-
tests/age_mover/test_folders.sh | 166 ++++++++++++++----
tests/age_mover/test_moves.sh | 9 +-
4 files changed, 191 insertions(+), 58 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index 121dab25..a61f96de 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -2549,6 +2549,21 @@ filesInUse() {
return 0
}
+# Whether a real run would find path $1 on the source: test mode leaves out processTheMoves' TEST_GONE, what its moves
+# and deletions would have taken off it
+on_source() { [ -e "$1" ] && [ -z "${TEST_GONE[$1]+x}" ]; }
+
+# Prints how many of the paths find prints for args $@ a real run would find, as on_source does
+count_left() {
+ local - out p n=0 IFS=$'\n'
+ [ "$TESTMODE" = "yes" ] || { find "$@" | wc -l; return; }
+ # one read of find's output, split here: a read loop on a pipe takes a syscall per byte
+ out=$(find "$@")
+ set -f
+ for p in $out; do [ -n "${TEST_GONE[$p]+x}" ] || n=$((n + 1)); done
+ echo "$n"
+}
+
# In topFolder mode, notes this row's share top folder for the check after the pass; fills processTheMoves' TOP_SEEN
# and TOP_FOLDERS
note_top_folder() {
@@ -2592,15 +2607,15 @@ cleanTopFolder() {
skip=(-path "${pat//\[/\\[}/.zfs" -prune -o)
fi
# -xdev: a mount inside, such as a child dataset, is counted but not walked
- file_count=$(find "$top_folder" -xdev "${skip[@]}" -type f -print | wc -l)
- dir_count=$(find "$top_folder" -xdev -mindepth 1 "${skip[@]}" -type d -print | wc -l)
+ file_count=$(count_left "$top_folder" -xdev "${skip[@]}" -type f -print)
+ dir_count=$(count_left "$top_folder" -xdev -mindepth 1 "${skip[@]}" -type d -print)
mvDebuglogger "Top folder: $(qp "$top_folder"), share file(s): $file_count, share folder(s): $dir_count" "Clean Top Folder"
if [ "$file_count" -ne 0 ] || [ "$dir_count" -ne 0 ]; then
mvlogger "Not deleting top-level folder: contains $file_count file(s), $dir_count subfolder(s): ${top_folder}"
- elif [ "$TESTMODE" != "no" ]; then
- mvlogger "TEST MODE: Would delete empty top-level folder: $top_folder"
elif [ "$dataset" = yes ]; then
mvlogger "Skipping deletion of ZFS dataset mountpoint: $top_folder"
+ elif [ "$TESTMODE" != "no" ]; then
+ mvlogger "TEST MODE: Would delete empty top-level folder: $top_folder"
elif rmdir "$top_folder" 2>/dev/null; then
mvlogger "Deleted empty top-level folder: $top_folder"
else
@@ -2702,6 +2717,7 @@ processTheMoves() {
REMAINING_UNATTENDED_FOLDERS=$TOTALUNATTENDEDFOLDERS
local -A HANDLED_LINKS=()
local -A GONE_BEFORE=()
+ local -A TEST_GONE=()
local -A CHARGED_BYTES=()
local -A STAGED_OK=()
local -A STAGED_VANISHED=()
@@ -2934,6 +2950,14 @@ processTheMoves() {
fi
fi
copyWatchStop
+ # test mode notes what a real move takes off the source: every file, and with Unraid's move a folder that
+ # holds nothing, as move leaves one that does
+ if [ "$TESTMODE" = "yes" ] && [[ "$ACTION" =~ "move" ]] && { [ "$FILETYPE" = "f" ] || [ "$MOVE_FILES_TOOL" = "move" ]; }; then
+ for f in "${present[@]}"; do
+ f=${f//\/.\//\/}
+ [ "$FILETYPE" = "f" ] || [ "$(count_left "$f" -mindepth 1 -maxdepth 1)" = 0 ] && TEST_GONE[$f]=1
+ done
+ fi
# a dry run counts every name as done; a real run counts only verified arrivals below
names=${#SYNCED_FILES_ARR[@]}
@@ -3020,14 +3044,14 @@ processTheMoves() {
elif [ "${LAST_DIR}" != "${DIR}" ] || [ -n "${GONE_BEFORE[$key]}" ]; then
# an earlier row may have emptied and deleted it
LAST_COUNT=0
- [ ! -d "$DIR" ] || LAST_COUNT=$(find "$DIR" -maxdepth 1 -type f | wc -l)
+ [ ! -d "$DIR" ] || LAST_COUNT=$(count_left "$DIR" -maxdepth 1 -type f)
LAST_DIR=$DIR
counted_in_row=1
count=$LAST_COUNT
else
# a count taken in this row already left out its moved names; a later row's name lowers it once it
- # left. Test mode moves nothing: each later name lowers it
- [ "$LAST_COUNT" = 0 ] || { [ "$TESTMODE" = no ] && { [ "$counted_in_row" = 1 ] || [ -e "$FILE" ]; }; } || LAST_COUNT=$((LAST_COUNT - 1))
+ # left
+ [ "$LAST_COUNT" = 0 ] || [ "$counted_in_row" = 1 ] || on_source "$FILE" || LAST_COUNT=$((LAST_COUNT - 1))
count=$LAST_COUNT
fi
mvDebuglogger "Cycle of delete folder, Previous count: $LAST_COUNT, Count of file(s): $count" "Clean Folder - End Loop"
@@ -3037,18 +3061,21 @@ processTheMoves() {
else
note_emptied_share
# the share's top folder is cleanTopFolder's, after the pass and in topFolder mode only
- if [ "$TESTMODE" = "no" ] && [ "$DIR" != "${SOURCE}/${SHARENAME}" ]; then
- # Check if empty folder exists and remove it (but skip ZFS dataset mountpoints)
- if [ -d "${DIR}" ]; then
- if ! is_zfs_dataset_mountpoint "${DIR}"; then
- if rmdir "${DIR}" 2>/dev/null; then
- mvlogger "Deleted empty folder: ${DIR}"
- else
- mvDebuglogger "Failed to delete folder (may not be empty): ${DIR}" "Clean Folder"
- fi
+ if [ "$DIR" != "${SOURCE}/${SHARENAME}" ] && [ -d "${DIR}" ] && on_source "$DIR"; then
+ if is_zfs_dataset_mountpoint "${DIR}"; then
+ mvlogger "Skipping deletion of ZFS dataset mountpoint: ${DIR}"
+ # test mode asks what rmdir would: anything left in the folder keeps it
+ elif [ "$TESTMODE" = "yes" ]; then
+ if [ "$(count_left "$DIR" -mindepth 1 -maxdepth 1)" = 0 ]; then
+ TEST_GONE[$DIR]=1
+ mvlogger "TEST MODE: Would delete empty folder: ${DIR}"
else
- mvlogger "Skipping deletion of ZFS dataset mountpoint: ${DIR}"
+ mvDebuglogger "TEST MODE: Would fail to delete folder (not empty): ${DIR}" "Clean Folder"
fi
+ elif rmdir "${DIR}" 2>/dev/null; then
+ mvlogger "Deleted empty folder: ${DIR}"
+ else
+ mvDebuglogger "Failed to delete folder (may not be empty): ${DIR}" "Clean Folder"
fi
fi
fi
@@ -3062,8 +3089,8 @@ processTheMoves() {
LAST_FOLDER_COUNT=$((REMAINING_CACHE_FOLDERS + REMAINING_ARRAY_FOLDERS + REMAINING_UNATTENDED_FOLDERS))
# Unraid's move deletes the folder itself; a parent gone too leaves the walk below nothing to do
- if [ ! -d "$START_DIR" ]; then
- [ "$DEBUGLEVEL" != 0 ] && mvDebuglogger "$(qp "$START_DIR") is gone from the source: the walk starts at its parent $(qp "$(dirname "$START_DIR")")" "Clean Empty Moved Folder"
+ if [ ! -d "$START_DIR" ] || ! on_source "$START_DIR"; then
+ [ "$DEBUGLEVEL" != 0 ] && mvDebuglogger "$(qp "$START_DIR") $([ -d "$START_DIR" ] && echo "would be" || echo is) gone from the source: the walk starts at its parent $(qp "$(dirname "$START_DIR")")" "Clean Empty Moved Folder"
START_DIR=$(dirname "$START_DIR")
fi
@@ -3073,7 +3100,7 @@ processTheMoves() {
mvDebuglogger "Cycle of delete empty folder: ${DIR}" "Clean Empty Moved Folder - Start Loop"
- while [[ -d "$DIR" && "$DIR" != "${SOURCE}/${SHARENAME}" ]]; do
+ while [[ -d "$DIR" && "$DIR" != "${SOURCE}/${SHARENAME}" ]] && on_source "$DIR"; do
DIR_LIST+="${DIR}"$'\n'
DIR="$(dirname "${DIR}")"
done
@@ -3098,8 +3125,8 @@ processTheMoves() {
fi
# the folder's own entries only: a walk below would mount each snapshot a child dataset shows
- empty_file_count=$(find "$DIR" -maxdepth 1 -type f | wc -l)
- empty_dir_count=$(find "$DIR" -mindepth 1 -maxdepth 1 -type d | wc -l)
+ empty_file_count=$(count_left "$DIR" -maxdepth 1 -type f)
+ empty_dir_count=$(count_left "$DIR" -mindepth 1 -maxdepth 1 -type d)
# Folder is truly empty
if [ "$empty_file_count" -eq 0 ] && [ "$empty_dir_count" -eq 0 ]; then
@@ -3111,6 +3138,7 @@ processTheMoves() {
break
fi
else
+ TEST_GONE[$DIR]=1
mvlogger "TEST MODE: Would delete moved empty folder: ${DIR}"
fi
chain_emptied=1
diff --git a/tests/age_mover/test_datasets.sh b/tests/age_mover/test_datasets.sh
index d05ae10a..b5f53271 100644
--- a/tests/age_mover/test_datasets.sh
+++ b/tests/age_mover/test_datasets.sh
@@ -155,7 +155,7 @@ rm /mnt/cache/sh/f.txt
run_moves
check "no zfs calls" "" "$(cat "$T/zfs.calls" 2>/dev/null)"
cache_is sh
-log_has 'TEST MODE: Would delete empty top-level folder: /mnt/cache/sh'
+log_has 'Skipping deletion of ZFS dataset mountpoint: /mnt/cache/sh'
for pool in 'not ZFS' 'ZFS, the share a plain folder on it'; do
begin "Clean ZFS datasets, a share that empties on a pool that is $pool" cleanFolders topFolder cleanDatasets yes
diff --git a/tests/age_mover/test_folders.sh b/tests/age_mover/test_folders.sh
index f220639a..a71a6ab2 100644
--- a/tests/age_mover/test_folders.sh
+++ b/tests/age_mover/test_folders.sh
@@ -1,6 +1,6 @@
#!/bin/bash
# The folder cleanup after each row and the top-folder check after the pass: Clean Folders no / yes / topFolder, Move
-# empty folders. Clean ZFS datasets: test_datasets.sh.
+# empty folders, and test mode's predictions of them. Clean ZFS datasets: test_datasets.sh.
. "$(dirname "$0")/lib.sh"
# the half of an unreadable-folder case that runs as a plain user, since root lists any folder
@@ -15,6 +15,30 @@ if [ "${1:-}" = --as-tester ]; then
exit
fi
+# a case's folder lines, a test-mode prediction written as the line a real run logs
+folder_lines() {
+ log | grep -E 'empty (top-level |moved )?folder: |^Not deleting |^Skipping deletion ' |
+ sed -e 's/^TEST MODE: Would delete moved empty folder/Deleted empty moved folder/' -e 's/^TEST MODE: Would delete empty/Deleted empty/'
+}
+# same_in_test_mode ...: setup's shape runs for real, whose folder lines must be
+# these, then in test mode, which must predict each of them and change nothing
+same_in_test_mode() {
+ local name=$1 want=$2 setup=$3 real tree
+ shift 3
+ begin "$name" "$@"
+ "$setup"
+ run_moves
+ real=$(folder_lines)
+ check "the real run's folder lines" "$want" "$real"
+ begin "$name, test mode" "$@" testmode yes
+ "$setup"
+ tree=$(find /mnt | sort)
+ run_moves
+ check "test mode predicts the real run's folder lines" "$real" "$(folder_lines)"
+ check "test mode leaves the disks as they were" "$tree" "$(find /mnt | sort)"
+ log_lacks 'Deleted empty'
+}
+
for cf in no yes topFolder; do
begin "Clean Folders $cf, a share that empties" cleanFolders "$cf"
mk cache sh/only/f.txt sh/only/g.txt
@@ -82,15 +106,6 @@ cache_is sh sh/d sh/d/z.txt
log_has 'Gone from the source before its turn: "/mnt/cache/sh/d/y.txt"'
log_count 2 'Not deleting folder containing 1 files: /mnt/cache/sh/d'
-# test mode moves nothing, so each later row lowers the count by one
-begin "Clean Folders yes in test mode, three rows in one folder" cleanFolders yes testmode yes
-mk cache sh/d/a.txt sh/d/b.txt sh/d/c.txt
-for f in a b c; do row 'move from primary' f "sh/d/$f.txt"; done | list
-run_moves
-cache_is sh sh/d sh/d/a.txt sh/d/b.txt sh/d/c.txt
-check "the folder's counts, one a row" "$(printf '%s\n' 3 2 1)" \
- "$(log | grep -oE 'Not deleting folder containing [0-9]+ files: /mnt/cache/sh/d' | grep -oE '[0-9]+')"
-
# the earlier row deletes the folder, so the vanished name's recount finds no folder and counts nothing
begin "topFolder, a row's file gone before the run, in a folder an earlier row empties" cleanFolders topFolder
mk cache sh/d/a.txt sh/d/b.txt sh/keep.txt
@@ -150,22 +165,6 @@ cache_is sh sh/dangling
log_lacks 'top-level'
[ "${AGE_MOVER_DEBUG:-0}" != 2 ] || dlog_has 'Failed to delete top-level folder (may not be empty): /mnt/cache/sh'
-for tm in no yes; do
- begin "topFolder, the top folder is a ZFS dataset mountpoint, test mode $tm" cleanFolders topFolder testmode "$tm"
- mk cache sh/only/f.txt
- echo /mnt/cache/sh >"$T/zfs"
- row 'move from primary' f sh/only/f.txt | list
- run_moves
- if [ "$tm" = no ]; then
- cache_is sh
- log_has 'Skipping deletion of ZFS dataset mountpoint: /mnt/cache/sh'
- else
- cache_is sh sh/only sh/only/f.txt
- log_has 'Not deleting folder containing 1 files: /mnt/cache/sh/only'
- log_lacks 'top-level'
- fi
-done
-
# a dataset's .zfs is not counted: with snapdir=visible a walk would mount and count every snapshot. The name's [ ]
# would make a glob of the path
for s in sh 'sh[1]'; do
@@ -186,14 +185,6 @@ run_moves
cache_is sh sh/.zfs sh/.zfs/k.txt
log_has 'Not deleting top-level folder: contains 1 file(s), 1 subfolder(s): /mnt/cache/sh'
-begin "topFolder in test mode, a share holding one empty folder" cleanFolders topFolder testmode yes
-mkdir -p /mnt/cache/sh/e
-row 'move from primary' d sh/e | list
-run_moves
-cache_is sh sh/e
-log_has 'TEST MODE: Would delete moved empty folder: /mnt/cache/sh/e'
-log_has 'Not deleting top-level folder: contains 0 file(s), 1 subfolder(s): /mnt/cache/sh'
-
# with Move empty folders off the planner lists no folder rows, so an empty folder stays and keeps the top folder
begin "topFolder, Move empty folders no, an empty folder not listed" cleanFolders topFolder moveEmptyFolders no
mk cache sh/a/f.txt
@@ -322,4 +313,111 @@ for keep in no yes; do
if [ "$keep" = yes ]; then cache_is sh sh/stay.txt; else cache_is; fi
done
+# test mode's predictions: what a real move or deletion would take off the source is left out of each count
+three_rows() {
+ mk cache sh/d/a.txt sh/d/b.txt sh/d/c.txt
+ for f in a b c; do row 'move from primary' f "sh/d/$f.txt"; done | list
+}
+same_in_test_mode "Clean Folders yes, three rows in one folder" "$(printf '%s\n' 'Not deleting folder containing 2 files: /mnt/cache/sh/d' \
+ 'Not deleting folder containing 1 files: /mnt/cache/sh/d' 'Deleted empty folder: /mnt/cache/sh/d')" three_rows cleanFolders yes
+
+taking_turns() {
+ mk cache sh/a/1.txt sh/a/2.txt sh/b/1.txt
+ for f in a/1 b/1 a/2; do row 'move from primary' f "sh/$f.txt"; done | list
+}
+same_in_test_mode "Clean Folders yes, rows taking turns between two folders" "$(printf '%s\n' \
+ 'Not deleting folder containing 1 files: /mnt/cache/sh/a' 'Deleted empty folder: /mnt/cache/sh/b' \
+ 'Deleted empty folder: /mnt/cache/sh/a')" taking_turns cleanFolders yes
+
+# both names leave in the first one's row; the second finds the folder gone
+link_pair() {
+ mk cache sh/h/a.txt
+ ln /mnt/cache/sh/h/a.txt /mnt/cache/sh/h/b.txt
+ { row 'move from primary' f sh/h/a.txt; row 'move from primary' f sh/h/b.txt; } | list
+}
+same_in_test_mode "Clean Folders yes, a hardlink group alone in its folder" 'Deleted empty folder: /mnt/cache/sh/h' link_pair \
+ cleanFolders yes
+
+one_name_gone() {
+ mk cache sh/d/a.txt sh/d/b.txt sh/keep.txt
+ { row 'move from primary' f sh/d/a.txt; row 'move from primary' f sh/d/b.txt; } | list
+ rm /mnt/cache/sh/d/b.txt
+}
+same_in_test_mode "topFolder, a row's file gone before the run, in a folder an earlier row empties" "$(printf '%s\n' \
+ 'Deleted empty folder: /mnt/cache/sh/d' 'Not deleting top-level folder: contains 1 file(s), 0 subfolder(s): /mnt/cache/sh')" \
+ one_name_gone cleanFolders topFolder
+
+nested_file() {
+ mk cache sh/p/q/f.txt
+ row 'move from primary' f sh/p/q/f.txt | list
+}
+same_in_test_mode "topFolder, a file two folders down" "$(printf '%s\n' 'Deleted empty folder: /mnt/cache/sh/p/q' \
+ 'Not deleting top-level folder: contains 0 file(s), 1 subfolder(s): /mnt/cache/sh')" nested_file cleanFolders topFolder
+
+# rmdir refuses the file's folder, which keeps a subfolder
+keeps_subfolder() {
+ mk cache sh/d/f.txt
+ mkdir -p /mnt/cache/sh/d/sub
+ row 'move from primary' f sh/d/f.txt | list
+}
+same_in_test_mode "topFolder, the file's folder keeps an empty subfolder" \
+ 'Not deleting top-level folder: contains 0 file(s), 2 subfolder(s): /mnt/cache/sh' keeps_subfolder cleanFolders topFolder
+
+dataset_top() {
+ mk cache sh/only/f.txt
+ echo /mnt/cache/sh >"$T/zfs"
+ row 'move from primary' f sh/only/f.txt | list
+}
+same_in_test_mode "topFolder, the top folder is a ZFS dataset mountpoint" "$(printf '%s\n' \
+ 'Deleted empty folder: /mnt/cache/sh/only' 'Skipping deletion of ZFS dataset mountpoint: /mnt/cache/sh')" dataset_top cleanFolders topFolder
+
+# Unraid's move takes the folder itself; with rsync the walk deletes it
+one_empty_folder() {
+ mkdir -p /mnt/cache/sh/e
+ row 'move from primary' d sh/e | list
+}
+folder_row_alone() {
+ mkdir -p /mnt/cache/sh/p/e
+ row 'move from primary' d sh/p/e | list
+}
+for tool in rsync move; do
+ want='Deleted empty top-level folder: /mnt/cache/sh'
+ [ "$tool" = move ] || want=$'Deleted empty moved folder: /mnt/cache/sh/e\n'$want
+ same_in_test_mode "topFolder, a share holding only an empty folder ($tool)" "$want" one_empty_folder cleanFolders topFolder \
+ movefilesTool "$tool"
+ want=$'Deleted empty moved folder: /mnt/cache/sh/p\nDeleted empty top-level folder: /mnt/cache/sh'
+ [ "$tool" = move ] || want=$'Deleted empty moved folder: /mnt/cache/sh/p/e\n'$want
+ same_in_test_mode "topFolder, a folder row whose parent holds nothing else ($tool)" "$want" folder_row_alone \
+ cleanFolders topFolder movefilesTool "$tool"
+ [ "$tool" = rsync ] || [ "${AGE_MOVER_DEBUG:-0}" != 2 ] ||
+ dlog_has '"/mnt/cache/sh/p/e" would be gone from the source: the walk starts at its parent "/mnt/cache/sh/p"'
+done
+
+# the second folder row's folder is gone before its turn, and the first row's walk deleted its parent
+folder_rows_one_gone() {
+ mkdir -p /mnt/cache/sh/p/e /mnt/cache/sh/p/g
+ mk cache sh/keep.txt
+ { row 'move from primary' d sh/p/e; row 'move from primary' d sh/p/g; } | list
+ rmdir /mnt/cache/sh/p/g
+}
+for tool in rsync move; do
+ want=$'Deleted empty moved folder: /mnt/cache/sh/p\nNot deleting top-level folder: contains 1 file(s), 0 subfolder(s): /mnt/cache/sh'
+ [ "$tool" = move ] || want=$'Deleted empty moved folder: /mnt/cache/sh/p/e\n'$want
+ same_in_test_mode "topFolder, a folder row's folder gone before its turn, its parent deleted ($tool)" "$want" \
+ folder_rows_one_gone cleanFolders topFolder movefilesTool "$tool"
+ [ "${AGE_MOVER_DEBUG:-0}" != 2 ] ||
+ dlog_has '"/mnt/cache/sh/p/g" is gone from the source: the walk starts at its parent "/mnt/cache/sh/p"'
+done
+
+# move leaves a folder that holds something, here a file written after the planning: nothing in the share empties, so
+# the top-folder check does not run
+folder_row_gains_file() {
+ mkdir -p /mnt/cache/sh/p/e
+ row 'move from primary' d sh/p/e | list
+ mk cache sh/p/e/new.txt
+}
+same_in_test_mode "topFolder, a folder row's folder gains a file after the planning (move)" \
+ 'Not deleting folder: contains 1 file(s), 0 subfolder(s): /mnt/cache/sh/p/e' folder_row_gains_file \
+ cleanFolders topFolder movefilesTool move
+
finish
diff --git a/tests/age_mover/test_moves.sh b/tests/age_mover/test_moves.sh
index 982c0761..997de798 100644
--- a/tests/age_mover/test_moves.sh
+++ b/tests/age_mover/test_moves.sh
@@ -64,7 +64,14 @@ for tool in rsync move; do
cache_is sh sh/t sh/t/e sh/t/f.txt sh/t/s.txt
counter MOVEDFILES 0
log_has "$([ "$tool" = move ] && echo 'TEST MODE: Would move using Unraid move utility' || echo 'TEST MODE: Would Move using rsync utility')"
- log_has 'TEST MODE: Would delete moved empty folder: /mnt/cache/sh/t/e'
+ # Unraid's move would take the folder itself, so only rsync's would be left for the walk; the synced file keeps the
+ # parent either way
+ if [ "$tool" = move ]; then
+ log_lacks 'TEST MODE: Would delete moved empty folder'
+ else
+ log_has 'TEST MODE: Would delete moved empty folder: /mnt/cache/sh/t/e'
+ fi
+ log_has 'Not deleting folder: contains 1 file(s), 0 subfolder(s): /mnt/cache/sh/t'
log_lacks 'Set last sync date'
begin "move from secondary ($tool)" movefilesTool "$tool"
From 17cdc8e401e9a5159be70ce51a7ca60187292a1b Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 19:18:05 +0800
Subject: [PATCH 57/94] Put the write method back when a stop ends the run
during the moves
An EXIT trap, set before turbo write is forced on, runs the restore once. The tests' stop hook moves to lib.sh for test_stops.sh.
---
.../emhttp/plugins/ca.mover.tuning/age_mover | 11 +++--
tests/age_mover/lib.sh | 20 ++++++++
tests/age_mover/test_dataset_stops.sh | 27 ++---------
tests/age_mover/test_stops.sh | 48 ++++++++++++++++++-
4 files changed, 80 insertions(+), 26 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index 2a610d8f..f4d369f4 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -2796,6 +2796,8 @@ processTheMoves() {
echo "$$ 0" >"$MOVINGFILE"
mvlogger "$(titleLine 'LET THE MOVING SHOW BEGIN !' '*')"
if [ "$ENABLETURBO" = "yes" ]; then
+ # set first: a stop that ends the run from here on puts the write method back on its way out; a KILL cannot
+ trap restore_turbo EXIT
mvlogger "Forcing turbo write on"
[ "$TESTMODE" != "yes" ] && /usr/local/sbin/mdcmd set md_write_method 1
fi
@@ -3308,6 +3310,7 @@ processTheMoves() {
[ -z "$notice_lines" ] || printf '%s\n' "$notice_lines"
trap - TERM HUP INT
if [ -n "$stopped" ]; then
+ # before the pid file goes: a run that starts once it has gone may force turbo write again
restore_turbo
# the plugin's stop removes these once the run has ended; a stop that signals the run alone leaves them
[ "$(cat "$PIDFILE" 2>/dev/null)" != "$$" ] || rm -f "$PIDFILE" "$MOVER_STATUS" "$PAUSEFILE" "$MOVINGFILE"
@@ -3342,12 +3345,14 @@ processTheMoves() {
restore_turbo
}
-# Sets the write method back from the turbo write that processTheMoves forced on
+# Sets the write method back from the turbo write that processTheMoves forced on, where the run ends or from the EXIT
+# trap of a run a signal ends sooner; it clears the trap
restore_turbo() {
[ "$ENABLETURBO" = "yes" ] || return 0
turbo_write_mode=$(cat /var/local/emhttp/var.ini | grep "md_write_method=" | cut -d'"' -f2)
- mvlogger "Restoring original turbo write mode $( ([ $turbo_write_mode = "auto" ] && echo "Auto (read/modify/write)") || ([ $turbo_write_mode -eq 1 ] && echo "Turbo writes (Reconstruct)") || echo "Read/modify/write")"
- [ $TESTMODE != "yes" ] && /usr/local/sbin/mdcmd set md_write_method $turbo_write_mode
+ mvlogger "Restoring original turbo write mode $( ([ "$turbo_write_mode" = "auto" ] && echo "Auto (read/modify/write)") || ([ "$turbo_write_mode" -eq 1 ] && echo "Turbo writes (Reconstruct)") || echo "Read/modify/write")"
+ [ "$TESTMODE" != "yes" ] && /usr/local/sbin/mdcmd set md_write_method "$turbo_write_mode"
+ trap - EXIT
}
# The settings pages cannot offer this combination, so it only arrives by saving a
diff --git a/tests/age_mover/lib.sh b/tests/age_mover/lib.sh
index 6232a155..253b2853 100644
--- a/tests/age_mover/lib.sh
+++ b/tests/age_mover/lib.sh
@@ -251,6 +251,26 @@ after_first_rsync() {
chmod 755 "$T/bin/rsync"
}
+# a hook, run once, that stops the mover: one stop signals the run alone, as a kill of its pid does; the plugin's is
+# age_mover stop, run outside the run, which signals every process of it. The hook waits until that stop says it waits
+# for the run or has ended, and notes whether the run's pid file is still there
+stop_hook() {
+ cat <"$T/pid"
+( setsid bash -c '. "$T/funcs.sh"; PIDFILE="$T/pid" MOVER_STATUS="$T/mover.ini" PAUSEFILE="$T/pause" MOVINGFILE="$T/moving"; stop' \\
+ "$T/stop.out" 2>&1 & )
+for _ in \$(seq 100); do grep -qs -e 'mover: stopped' -e 'mover: waiting' "$T/stop.out" && break; sleep 0.1; done
+[ ! -f "$T/pid" ] || echo kept >"$T/pid.kept"
+EOF
+}
+
# mk ...: a 2-byte file at /mnt//
mk() {
local r=$1 p
diff --git a/tests/age_mover/test_dataset_stops.sh b/tests/age_mover/test_dataset_stops.sh
index fa08f6d4..586b664e 100644
--- a/tests/age_mover/test_dataset_stops.sh
+++ b/tests/age_mover/test_dataset_stops.sh
@@ -8,25 +8,6 @@ if ! awk '$5 ~ "^/(usr|var)/local(/|$)" || $5 ~ "^/(usr|var)$" { exit 1 }' /proc
exit 2
fi
-# a hook, run once, that stops the mover: one stop signals the run alone, as a kill of its pid does; the plugin's is
-# age_mover stop, run outside the run, which signals every process of it. The hook waits until that stop says it waits
-# for the run or has ended, and notes whether the run's pid file is still there
-stop_hook() {
- cat <"$T/pid"
-( setsid bash -c '. "$T/funcs.sh"; PIDFILE="$T/pid" MOVER_STATUS="$T/mover.ini" PAUSEFILE="$T/pause" MOVINGFILE="$T/moving"; stop' \\
- "$T/stop.out" 2>&1 & )
-for _ in \$(seq 100); do grep -qs -e 'mover: stopped' -e 'mover: waiting' "$T/stop.out" && break; sleep 0.1; done
-[ ! -f "$T/pid" ] || echo kept >"$T/pid.kept"
-EOF
-}
# the plugin's stop waits for the run to end, then removes the pid and status files: it must end before the next case
stop_done() {
local _
@@ -67,18 +48,20 @@ mounted_again() { check "the dataset is mounted at its folder again" /mnt/cache/
REMOUNTED=$(sed '$d' <<<"$DESTROYED"; echo 'zfs mount cache/sh')
# a stop of the run alone during the check after the unmount, and a write through /mnt/user meanwhile, which keeps it
-# unmounted. The run puts back the write method it forced and removes its pid file
+# unmounted. The run puts back the write method it forced, then removes its pid file
begin "Clean ZFS datasets, a stop of the run alone during the check after the unmount" cleanFolders topFolder \
cleanDatasets yes notify errorsOnly enableTurbo yes
one_share
mkdir -p /usr/local/sbin /var/local/emhttp
echo 'md_write_method="0"' >/var/local/emhttp/var.ini
-printf '#!/bin/bash\necho "mdcmd $*" >>%q\n' "$T/mdcmd.calls" >/usr/local/sbin/mdcmd
+# shellcheck disable=SC2016 # the stand-in expands its own $* and $w
+printf '#!/bin/bash\n[ ! -e %q ] || w=" (pid file there)"\necho "mdcmd $*$w" >>%q\n' "$T/pid" "$T/mdcmd.calls" >/usr/local/sbin/mdcmd
chmod 755 /usr/local/sbin/mdcmd
echo $$ >"$T/pid"
{ stop_hook run; echo 'echo y >/mnt/cache/sh/bare.txt'; } >"$T/zfs.on_mount.zfs"
run_moves 'processTheMoves did not return'
-check "turbo write forced, then put back" "$(printf '%s\n' 'mdcmd set md_write_method 1' 'mdcmd set md_write_method 0')" \
+check "turbo write forced, then put back before the pid file goes" \
+ "$(printf '%s\n' 'mdcmd set md_write_method 1 (pid file there)' 'mdcmd set md_write_method 0 (pid file there)')" \
"$(cat "$T/mdcmd.calls")"
check "the run removed its pid file" "" "$(ls "$T/pid" 2>/dev/null)"
rm -rf /usr/local/sbin/mdcmd /var/local/emhttp "$T/mdcmd.calls"
diff --git a/tests/age_mover/test_stops.sh b/tests/age_mover/test_stops.sh
index 5b8ed773..a31f34c5 100644
--- a/tests/age_mover/test_stops.sh
+++ b/tests/age_mover/test_stops.sh
@@ -1,6 +1,11 @@
#!/bin/bash
-# What processTheMoves does today when a soft stop or a pause comes before or between its rows.
+# What processTheMoves does today when a stop, a soft stop or a pause comes before or between its rows.
. "$(dirname "$0")/lib.sh"
+# a case writes under /usr/local and /var/local: a mount at either refuses
+if ! awk '$5 ~ "^/(usr|var)/local(/|$)" || $5 ~ "^/(usr|var)$" { exit 1 }' /proc/self/mountinfo; then
+ echo "test_stops.sh writes Unraid's paths and one is a mount here: start it with tests/age_mover/run.sh" >&2
+ exit 2
+fi
HELPERS=()
# after_pause ...: in the background, runs the command s after the run logs its pause; begin removed
@@ -80,4 +85,45 @@ check "the order of the moves, the pause and the soft stop" "$(printf '%s\n' 'Pa
'Soft Stopping requested')" "$(order)"
check "the pause held under 10 s: the soft stop ended it, not the 20 s lift" yes "$([ "$(held)" -lt 10 ] 2>/dev/null && echo yes || echo no)"
+# Unraid's write method, read/modify/write, and an mdcmd that notes its calls
+turbo_standin() {
+ mkdir -p /usr/local/sbin /var/local/emhttp
+ echo 'md_write_method="0"' >/var/local/emhttp/var.ini
+ printf '#!/bin/bash\necho "mdcmd $*" >>%q\n' "$T/mdcmd.calls" >/usr/local/sbin/mdcmd
+ chmod 755 /usr/local/sbin/mdcmd
+}
+put_back_once() {
+ check "turbo write forced, then put back once" "$(printf '%s\n' 'mdcmd set md_write_method 1' 'mdcmd set md_write_method 0')" \
+ "$(cat "$T/mdcmd.calls")"
+ log_count 1 'Restoring original turbo write mode Read/modify/write'
+ rm -rf /usr/local/sbin/mdcmd /var/local/emhttp "$T/mdcmd.calls"
+}
+
+begin "turbo write on, no stop" enableTurbo yes
+mk cache sh/s/1.txt
+row 'move from primary' f sh/s/1.txt | list
+turbo_standin
+run_moves
+put_back_once
+array_is sh sh/s sh/s/1.txt
+
+# a stop that ends the run during the moves: the run puts back the write method it forced. The plugin's stop also
+# signals the hook, which ignores it, so the rsync wrapper ends by the signal and not by reporting a failed hook
+for who in plugin run; do
+ begin "turbo write on, a stop ($who) after the first file" enableTurbo yes
+ mk cache sh/s/1.txt sh/s/2.txt
+ for n in 1 2; do row 'move from primary' f "sh/s/$n.txt"; done | list
+ turbo_standin
+ if [ "$who" = plugin ]; then after_first_rsync "trap '' TERM; $(stop_hook plugin)"; else after_first_rsync "$(stop_hook run)"; fi
+ run_moves 'processTheMoves did not return'
+ if [ "$who" = plugin ]; then
+ for _ in $(seq 100); do grep -qs 'mover: stopped' "$T/stop.out" && break; sleep 0.1; done
+ check "the plugin's stop ended" 1 "$(grep -cs 'mover: stopped' "$T/stop.out")"
+ rm -f "$T/stop.out"
+ fi
+ put_back_once
+ array_is sh sh/s sh/s/1.txt
+ cache_is sh sh/s sh/s/2.txt
+done
+
finish
From d518c2b1b45de5fdc543ce5886e91f293cffd2d8 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 20:39:27 +0800
Subject: [PATCH 58/94] Force turbo write only when the write method can be set
back; mark test mode's turbo lines
---
.../emhttp/plugins/ca.mover.tuning/age_mover | 56 +++++++++++++++----
tests/age_mover/test_stops.sh | 42 ++++++++++++++
2 files changed, 86 insertions(+), 12 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index f4d369f4..e9f4fba4 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -2795,12 +2795,7 @@ processTheMoves() {
# the Pause button shows from here until movesEnd
echo "$$ 0" >"$MOVINGFILE"
mvlogger "$(titleLine 'LET THE MOVING SHOW BEGIN !' '*')"
- if [ "$ENABLETURBO" = "yes" ]; then
- # set first: a stop that ends the run from here on puts the write method back on its way out; a KILL cannot
- trap restore_turbo EXIT
- mvlogger "Forcing turbo write on"
- [ "$TESTMODE" != "yes" ] && /usr/local/sbin/mdcmd set md_write_method 1
- fi
+ force_turbo
# MOVER_ACTIONLIST header:
# PRIMARYSTORAGENAME|SHARENAME|SHAREUSECACHE|MODIFYTIME|FILESIZE|POOLSUM|THRESHOLD|PROJECTED|NBLINKS|INODE|ACTION|FROM|TO|FILETYPE|FILEPATH
@@ -3345,13 +3340,50 @@ processTheMoves() {
restore_turbo
}
-# Sets the write method back from the turbo write that processTheMoves forced on, where the run ends or from the EXIT
-# trap of a run a signal ends sooner; it clears the trap
-restore_turbo() {
+# Prints the write method var.ini gives when it is one mdcmd can set back: 0, 1 or auto, as mover.php checks
+write_method() {
+ local m
+ m=$(grep -s '^md_write_method=' /var/local/emhttp/var.ini | cut -d'"' -f2)
+ case $m in 0 | 1 | auto) echo "$m" ;; *) return 1 ;; esac
+}
+
+# With Turbo Mode on, forces turbo write for the moves, only when the write method can be set back after
+force_turbo() {
+ TURBO_WAS=""
[ "$ENABLETURBO" = "yes" ] || return 0
- turbo_write_mode=$(cat /var/local/emhttp/var.ini | grep "md_write_method=" | cut -d'"' -f2)
- mvlogger "Restoring original turbo write mode $( ([ "$turbo_write_mode" = "auto" ] && echo "Auto (read/modify/write)") || ([ "$turbo_write_mode" -eq 1 ] && echo "Turbo writes (Reconstruct)") || echo "Read/modify/write")"
- [ "$TESTMODE" != "yes" ] && /usr/local/sbin/mdcmd set md_write_method "$turbo_write_mode"
+ if ! TURBO_WAS=$(write_method); then
+ mvlogger "Not forcing turbo write on: /var/local/emhttp/var.ini gives no write method (0, 1 or auto) to set back after"
+ return 0
+ fi
+ if [ "$TESTMODE" = "yes" ]; then
+ mvlogger "TEST MODE: Would force turbo write on"
+ return 0
+ fi
+ # set first: a stop that ends the run from here on puts the write method back on its way out; a KILL cannot
+ trap restore_turbo EXIT
+ mvlogger "Forcing turbo write on"
+ /usr/local/sbin/mdcmd set md_write_method 1
+}
+
+# Sets the write method back after force_turbo, where the run ends or from the EXIT trap of a run a signal ends sooner;
+# it clears the trap
+restore_turbo() {
+ local m name
+ [ -n "$TURBO_WAS" ] || return 0
+ # var.ini's now, which Settings may have changed during the moves; the one read before when it gives none
+ m=$(write_method) || m=$TURBO_WAS
+ case $m in
+ auto) name="Auto (read/modify/write)" ;;
+ 1) name="Turbo writes (Reconstruct)" ;;
+ *) name="Read/modify/write" ;;
+ esac
+ if [ "$TESTMODE" = "yes" ]; then
+ mvlogger "TEST MODE: Would restore original turbo write mode $name"
+ else
+ mvlogger "Restoring original turbo write mode $name"
+ /usr/local/sbin/mdcmd set md_write_method "$m"
+ fi
+ TURBO_WAS=""
trap - EXIT
}
diff --git a/tests/age_mover/test_stops.sh b/tests/age_mover/test_stops.sh
index a31f34c5..178273eb 100644
--- a/tests/age_mover/test_stops.sh
+++ b/tests/age_mover/test_stops.sh
@@ -126,4 +126,46 @@ for who in plugin run; do
cache_is sh sh/s sh/s/2.txt
done
+begin "turbo write on, var.ini gives no write method" enableTurbo yes
+mk cache sh/s/1.txt
+row 'move from primary' f sh/s/1.txt | list
+turbo_standin
+: >/var/local/emhttp/var.ini
+run_moves
+check "mdcmd was not called" "" "$(cat "$T/mdcmd.calls" 2>/dev/null)"
+log_has 'Not forcing turbo write on: /var/local/emhttp/var.ini gives no write method (0, 1 or auto) to set back after'
+log_lacks 'Restoring original turbo write mode'
+rm -rf /usr/local/sbin/mdcmd /var/local/emhttp "$T/mdcmd.calls"
+array_is sh sh/s sh/s/1.txt
+
+begin "turbo write on, in test mode" enableTurbo yes testmode yes
+mk cache sh/s/1.txt
+row 'move from primary' f sh/s/1.txt | list
+turbo_standin
+run_moves
+check "mdcmd was not called" "" "$(cat "$T/mdcmd.calls" 2>/dev/null)"
+log_has 'TEST MODE: Would force turbo write on'
+log_has 'TEST MODE: Would restore original turbo write mode Read/modify/write'
+log_lacks 'Forcing turbo write on'
+log_lacks 'Restoring original turbo write mode'
+rm -rf /usr/local/sbin/mdcmd /var/local/emhttp "$T/mdcmd.calls"
+cache_is sh sh/s sh/s/1.txt
+
+# a save in Settings during the moves changes var.ini's write method: that one is set back, or the one read before
+# when var.ini then gives none
+for now in 'auto Auto (read/modify/write)' ' Read/modify/write'; do
+ begin "turbo write on, var.ini gives \"${now%% *}\" during the moves" enableTurbo yes
+ mk cache sh/s/1.txt
+ row 'move from primary' f sh/s/1.txt | list
+ turbo_standin
+ after_first_rsync "echo 'md_write_method=\"${now%% *}\"' >/var/local/emhttp/var.ini"
+ run_moves
+ w=${now%% *}
+ check "turbo write forced, then set back to ${w:-0}" "$(printf '%s\n' 'mdcmd set md_write_method 1' \
+ "mdcmd set md_write_method ${w:-0}")" "$(cat "$T/mdcmd.calls")"
+ log_count 1 "Restoring original turbo write mode ${now#* }"
+ rm -rf /usr/local/sbin/mdcmd /var/local/emhttp "$T/mdcmd.calls"
+ array_is sh sh/s sh/s/1.txt
+done
+
finish
From 80370d89c487b70bc585a8dd8c46318c2e903679 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 20:55:05 +0800
Subject: [PATCH 59/94] Report a look at the mount back that was cut short
---
.../emhttp/plugins/ca.mover.tuning/age_mover | 36 +++++++++++++------
tests/age_mover/test_dataset_stops.sh | 30 ++++++++++++++++
2 files changed, 56 insertions(+), 10 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index 07be6f64..b2e01d67 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -2665,14 +2665,15 @@ dataset_problems_notice() {
}
# Mounts dataset $1 at its folder $2 from inside the folder and prints the first entry the mount hides, seen through .;
-# prints why and fails when the folder cannot be entered or the mount fails
+# prints why and fails when the folder cannot be entered or the mount fails; fails with 2 when the look is cut short
mount_back() {
- local err
+ local err entry
# made if gone: a write through /mnt/user can make it again, with a file in it, before the mount
{ mkdir -p "$2" && cd "$2"; } 2>/dev/null || { printf 'cannot enter its folder %s' "$2"; return 1; }
err=$(zfs mount "$1" 2>&1) || { printf 'zfs: %s' "$(zfs_reason "$err")"; return 1; }
- find . -mindepth 1 -print -quit 2>/dev/null
- return 0
+ # a look cut short can print nothing, as a clean one does: only its status tells them apart
+ entry=$(find . -mindepth 1 -print -quit 2>/dev/null) || return 2
+ printf '%s' "$entry"
}
# Mounts dataset $1 again at its folder $2, unless the folder gained files that a mount would hide
@@ -2681,12 +2682,27 @@ remount_dataset() {
# a write through /mnt/user while it was unmounted lands in the bare folder
if [ -n "$(finish_on_stop find "$2" -mindepth 1 -print -quit 2>/dev/null)" ]; then
out="Not remounting ZFS dataset [$1]: its folder $2 holds files that a mount would hide"
- elif out=$(finish_on_stop mount_back "$1" "$2"); then
- [ -n "$out" ] || return 0
- dataset_problem failure "$1" "ZFS dataset [$1] is mounted again, but $2/${out#./}, written as it was mounted, is hidden under it"
- dataset_out_of_view "a file is hidden under it: stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s" \
- "$1" "$1" "$2" "$1" "$2"
- return 0
+ else
+ out=$(finish_on_stop mount_back "$1" "$2")
+ case $? in
+ 0)
+ [ -n "$out" ] || return 0
+ dataset_problem failure "$1" "ZFS dataset [$1] is mounted again, but $2/${out#./}, written as it was mounted, is hidden under it"
+ dataset_out_of_view "a file is hidden under it: stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s" \
+ "$1" "$1" "$2" "$1" "$2"
+ return 0
+ ;;
+ 1) ;;
+ 2)
+ dataset_problem warning "$1" "ZFS dataset [$1] is mounted again, but the look for a file written to $2 as it was mounted was cut short: one may be hidden under it"
+ return 0
+ ;;
+ *)
+ # killed outright, it may have mounted it or not
+ dataset_problem failure "$1" "Remounting ZFS dataset [$1] was cut short: if zfs mount does not list it at $2, stop writes to the share, move anything in $2 aside, zfs mount $1, then move it back into $2"
+ return 0
+ ;;
+ esac
fi
dataset_problem failure "$1" "Failed to remount dataset [$1]" "$out"
dataset_out_of_view "not mounted: stop writes to the share, move anything in %s aside, zfs mount %s, then move it back into %s" \
diff --git a/tests/age_mover/test_dataset_stops.sh b/tests/age_mover/test_dataset_stops.sh
index ebd053f6..feeac6cc 100644
--- a/tests/age_mover/test_dataset_stops.sh
+++ b/tests/age_mover/test_dataset_stops.sh
@@ -335,4 +335,34 @@ for which in 'first check' 'check at the private mount'; do
no_private
done
+# a file lands in the folder as the dataset is mounted back. The look after the mount killed printed nothing because it
+# never looked; the whole remount killed leaves the run unable to tell whether the mount happened
+for what in look remount; do
+ begin "Clean ZFS datasets, the $what at the mount back is killed" cleanFolders topFolder cleanDatasets yes
+ one_share
+ echo 'echo x >/mnt/cache/sh/new.txt' >"$T/zfs.on_unmount"
+ echo 'echo y >/mnt/cache/sh/late.txt' >"$T/zfs.on_mount"
+ wrap_hook find ". -mindepth 1 -print -quit"
+ if [ "$what" = look ]; then
+ cat >"$T/find.hook" <<'EOF'
+rm -f "$0"
+kill -KILL "$PPID"
+EOF
+ else
+ kill_hook KILL : >"$T/find.hook"
+ fi
+ PATH=$T/wrap:$PATH run_moves
+ check "zfs calls" "$REMOUNTED" "$(cat "$T/zfs.calls")"
+ if [ "$what" = look ]; then
+ log_has 'ZFS dataset [cache/sh] is mounted again, but the look for a file written to /mnt/cache/sh as it was mounted was cut short: one may be hidden under it'
+ else
+ log_has 'Remounting ZFS dataset [cache/sh] was cut short: if zfs mount does not list it at /mnt/cache/sh, stop writes to the share, move anything in /mnt/cache/sh aside, zfs mount cache/sh, then move it back into /mnt/cache/sh'
+ fi
+ log_lacks 'Failed to remount'
+ notices "$NOTICE"
+ mounted_again
+ cache_is sh sh/new.txt
+ no_private
+done
+
finish
From bd920c2020a9c5971eb2eecee3e2e7018796f057 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 21:07:18 +0800
Subject: [PATCH 60/94] share_mover: run find without eval, force turbo write
only when it can be set back, exit 0 after a run
---
.../plugins/ca.mover.tuning/share_mover | 98 +++++++++++++------
tests/age_mover/test_share_mover.sh | 98 ++++++++++++++++---
2 files changed, 151 insertions(+), 45 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover
index 5da805d6..c7cbf021 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover
@@ -98,7 +98,7 @@ if [ -f $UNRAIDCFGFILE ]; then
fi
fi
-mvlogger "$(titleLine "Mover Tuning Plugin version $(grep "version=" "$MOVERTUNINGCFGFILE" | cut -d '"' -f 2)" '*')"
+[ ! -f "$MOVERTUNINGCFGFILE" ] || mvlogger "$(titleLine "Mover Tuning Plugin version $(grep "version=" "$MOVERTUNINGCFGFILE" | cut -d '"' -f 2)" '*')"
#Test input variables
if [ -z "$1" ]; then
@@ -150,6 +150,55 @@ fi
pid_cleanup() {
[ "$(cat "$PIDFILE" 2>/dev/null)" = "$$" ] && rm -f "$PIDFILE"
}
+
+# Prints the write method var.ini gives when it is one mdcmd can set back: 0, 1 or auto, as mover.php checks
+write_method() {
+ local m
+ m=$(grep -s '^md_write_method=' /var/local/emhttp/var.ini | cut -d'"' -f2)
+ case $m in 0 | 1 | auto) echo "$m" ;; *) return 1 ;; esac
+}
+
+# With Turbo Mode on, forces turbo write for the moves, only when the write method can be set back after; mirrors
+# age_mover's force_turbo
+force_turbo() {
+ TURBO_WAS=""
+ [ "$ENABLETURBO" = "yes" ] || return 0
+ if ! TURBO_WAS=$(write_method); then
+ mvlogger "Not forcing turbo write on: /var/local/emhttp/var.ini gives no write method (0, 1 or auto) to set back after"
+ return 0
+ fi
+ if [ "$TESTMODE" = "yes" ]; then
+ mvlogger "TEST MODE: Would force turbo write on"
+ return 0
+ fi
+ # set first: a stop that ends the run from here on puts the write method back before the pid file goes; a KILL cannot
+ trap 'restore_turbo; pid_cleanup' EXIT
+ mvlogger "Forcing turbo write on"
+ /usr/local/sbin/mdcmd set md_write_method 1
+}
+
+# Sets the write method back after force_turbo, where the moves end or from the EXIT trap of a run a signal ends sooner;
+# the EXIT trap goes back to pid_cleanup alone
+restore_turbo() {
+ local m name
+ [ -n "$TURBO_WAS" ] || return 0
+ # var.ini's now, which Settings may have changed during the moves; the one read before when it gives none
+ m=$(write_method) || m=$TURBO_WAS
+ case $m in
+ auto) name="Auto (read/modify/write)" ;;
+ 1) name="Turbo writes (Reconstruct)" ;;
+ *) name="Read/modify/write" ;;
+ esac
+ if [ "$TESTMODE" = "yes" ]; then
+ mvlogger "TEST MODE: Would restore original turbo write mode $name"
+ else
+ mvlogger "Restoring original turbo write mode $name"
+ /usr/local/sbin/mdcmd set md_write_method "$m"
+ fi
+ TURBO_WAS=""
+ trap pid_cleanup EXIT
+}
+
trap pid_cleanup EXIT
trap 'exit 143' HUP INT TERM
echo $$ >"$PIDFILE"
@@ -202,54 +251,41 @@ if grep -qs 'shareUseCache="yes\|shareUseCache="prefer"' "$SHARECFG"; then
mvlogger "=> Skipping"
else
mvlogger "$(titleLine 'LET THE MOVING SHOW BEGIN !' '*')"
- if [ "$ENABLETURBO" = "yes" ]; then
- mvlogger "Forcing turbo write on"
- [ "$TESTMODE" != "yes" ] && /usr/local/sbin/mdcmd set md_write_method 1
- fi
+ force_turbo
- #Base Find String
- # Alterate SHAREPATH on Cache=prefer
+ # the share name reaches find only as an argument, never parsed as shell
if [ "$SHAREUSECACHE" = "prefer" ]; then
- #"cache=prefer" pool, we replace path to list files in /mnt/user and process later
-
- # Check if SHAREPATH is in the format "/mnt/*/$SHARENAME"
- # Initialize FINDSTR with the base find command
- FINDSTR="find"
- # Iterate over all directories in /mnt/*
+ # "cache=prefer": the share's folder on every other disk and pool, for the move to the primary
+ paths=()
for dir in /mnt/*; do
- # Check if the directory contains a subdirectory named $SHARENAME and not equal to "/mnt/$PRIMARYSTORAGENAME/$SHARENAME"
if [ -d "$dir/$SHARENAME" ] && [ "$dir/$SHARENAME" != "/mnt/$PRIMARYSTORAGENAME/$SHARENAME" ]; then
- # Append the path to FINDSTR, ensuring it's quoted and separated by spaces
- FINDSTR+=" \"$dir/$SHARENAME\""
+ paths+=("$dir/$SHARENAME")
fi
done
- # Add the depth option at the end
- FINDSTR+=" -type f -not -path '/mnt/user*' -depth"
+ opts=(-type f -not -path '/mnt/user*' -depth)
else
- # Alterate SHAREPATH on Cache=yes
- FINDSTR="find \"${SHAREPATH}\" -type f -depth"
+ paths=("$SHAREPATH")
+ opts=(-type f -depth)
fi
+ # the log shows each path in qp's quotes, for the debug package's redaction
+ FINDSTR="find"
+ for p in "${paths[@]}"; do FINDSTR+=" $(qp "$p")"; done
+ FINDSTR+=$(printf ' %q' "${opts[@]}")
if [ "$TESTMODE" = "yes" ]; then
mvlogger "Running in Test Mode: $FINDSTR"
- eval "${FINDSTR}"
+ find "${paths[@]}" "${opts[@]}"
else
- #Add Mover to find string
MOVE=/usr/libexec/unraid/move
[ -f "$MOVE" ] || MOVE=$(which move)
- FINDSTR="${FINDSTR} | $MOVE -d $LOGLEVEL"
- mvlogger "Complete Mover Command: $FINDSTR"
- eval " ${FINDSTR}"
+ mvlogger "Complete Mover Command: $FINDSTR | $MOVE -d $LOGLEVEL"
+ find "${paths[@]}" "${opts[@]}" | "$MOVE" -d "$LOGLEVEL"
fi
- if [ "$ENABLETURBO" = "yes" ]; then
- turbo_write_mode=$(cat /var/local/emhttp/var.ini | grep "md_write_method=" | cut -d'"' -f2)
- mvlogger "Restoring original turbo write mode $( ([ "$turbo_write_mode" = "auto" ] && echo "Auto (read/modify/write)") || ([ "$turbo_write_mode" -eq 1 ] && echo "Turbo writes (Reconstruct)") || echo "Read/modify/write")"
- [ "$TESTMODE" != "yes" ] && /usr/local/sbin/mdcmd set md_write_method "$turbo_write_mode"
- fi
+ restore_turbo
fi
fi
mvlogger "$(titleLine 'WE ARE DONE !' '*')"
-[ $LOGLEVEL = 0 ] && echo "Mover tuning plugin done!"
+[ "$LOGLEVEL" = 1 ] || echo "Mover tuning plugin done!"
diff --git a/tests/age_mover/test_share_mover.sh b/tests/age_mover/test_share_mover.sh
index 45e52256..7ccde426 100644
--- a/tests/age_mover/test_share_mover.sh
+++ b/tests/age_mover/test_share_mover.sh
@@ -53,21 +53,32 @@ bg() {
exit 2
}
-# run [stderr]: share_mover sh, its output without mvlogger's date as the log; stderr must be exactly the given
+# run [stderr]: share_mover sh (or $NAME), its output without mvlogger's date as the log; stderr must be exactly the given
# text, nothing by default
run() {
local rc
- (cd "$T/cwd" && bash "$SM" sh) >"$T/out" 2>"$T/err"
+ (cd "$T/cwd" && bash "$SM" "${NAME:-sh}") >"$T/out" 2>"$T/err"
rc=$?
sed -E 's/^[A-Z][a-z]{2} [ 0-9][0-9] [0-9:]{8} Share mover: //' "$T/out" >"$MOVER_LOG"
check "share_mover exited $1" "$1" "$rc"
check "stderr held $([ -n "${2:-}" ] && echo only the expected text || echo nothing)" "${2:-}" "$(cat "$T/err")"
}
mdcmd_calls() { check "mdcmd calls: ${*:-none}" "$( (($#)) && printf 'mdcmd %s\n' "$@")" "$(cat "$T/mdcmd.calls" 2>/dev/null)"; }
+# move_hook : Unraid's move runs the command first, until move_unhook
+move_hook() {
+ mv /usr/libexec/unraid/move "$T/move.real"
+ cat >/usr/libexec/unraid/move </var/local/emhttp/var.ini
mk cache sh/a.txt
- run 1
+ run 0
log_has 'Forcing turbo write on'
log_has "Restoring original turbo write mode ${wm#* }"
mdcmd_calls 'set md_write_method 1' "set md_write_method ${wm%% *}"
@@ -119,14 +130,72 @@ done
share 'turbo on in test mode' yes enableTurbo yes testmode yes
mk cache sh/a.txt
-run 1
-log_has 'Forcing turbo write on'
+run 0
+log_has 'TEST MODE: Would force turbo write on'
+log_has 'TEST MODE: Would restore original turbo write mode Auto (read/modify/write)'
+log_lacks 'Forcing turbo write on'
+log_lacks 'Restoring original turbo write mode'
mdcmd_calls
cache_is sh sh/a.txt
+share 'turbo on, var.ini gives no write method' yes enableTurbo yes
+: >/var/local/emhttp/var.ini
+mk cache sh/a.txt
+run 0
+log_has 'Not forcing turbo write on: /var/local/emhttp/var.ini gives no write method (0, 1 or auto) to set back after'
+log_lacks 'Restoring original turbo write mode'
+mdcmd_calls
+array_is sh sh/a.txt
+
+# a save in Settings during the moves changes var.ini's write method: that one is set back, or the one read before
+# when var.ini then gives none
+for now in '0 Read/modify/write' ' Auto (read/modify/write)'; do
+ share "turbo on, var.ini gives \"${now%% *}\" during the moves" yes enableTurbo yes
+ mk cache sh/a.txt
+ move_hook "echo 'md_write_method=\"${now%% *}\"' >/var/local/emhttp/var.ini"
+ run 0
+ move_unhook
+ w=${now%% *}
+ mdcmd_calls 'set md_write_method 1' "set md_write_method ${w:-auto}"
+ log_count 1 "Restoring original turbo write mode ${now#* }"
+ array_is sh sh/a.txt
+done
+
+# a stop of the run during the moves: it ends once the move does, and sets the write method back before its pid file goes
+share 'turbo on, a stop during the moves' yes enableTurbo yes
+mk cache sh/a.txt
+# shellcheck disable=SC2016 # the hook expands it
+move_hook 'kill -TERM "$(cat /var/run/mover.pid)"'
+cat >/usr/local/sbin/mdcmd </dev/null)
+echo "mdcmd \$*\${w:+ (pid file there)}" >>$T/mdcmd.calls
+EOF
+run 143
+move_unhook
+mdcmd_calls 'set md_write_method 1 (pid file there)' 'set md_write_method auto (pid file there)'
+log_count 1 'Restoring original turbo write mode Auto (read/modify/write)'
+check 'the run removed its pid file' '' "$(ls /var/run/mover.pid 2>/dev/null)"
+array_is sh sh/a.txt
+cat >/usr/local/sbin/mdcmd <>$T/mdcmd.calls
+EOF
+
+# a share name with shell in it is a name: the run moves its files and runs nothing
+share 'a share name that holds a command' yes
+# shellcheck disable=SC2016 # the name holds shell text on purpose
+n='a $(touch ran)'
+mv /boot/config/shares/sh.cfg "/boot/config/shares/$n.cfg"
+mk cache "$n/b.txt"
+NAME=$n run 0
+log_has "Complete Mover Command: find \"/mnt/cache/$n\" -type f -depth | /usr/libexec/unraid/move -d 1"
+check 'the name ran nothing' no "$([ -e "$T/cwd/ran" ] && echo yes || echo no)"
+array_is "$n" "$n/b.txt"
+
share 'no enableTurbo or testmode in the plugin config' yes enableTurbo - testmode -
mk cache sh/a.txt
-run 1
+run 0
log_has 'No Turbo Mode argument provided, defaulting to no'
log_has 'No Test Mode argument provided, defaulting to yes'
log_has 'Running in Test Mode'
@@ -158,7 +227,7 @@ share 'the pid file names a process that is no mover' yes
mk cache sh/a.txt
bg sleep sleep 30
echo $! >/var/run/mover.pid
-run 1
+run 0
kill $! 2>/dev/null
wait $! 2>/dev/null
log_lacks 'already running'
@@ -167,7 +236,7 @@ array_is sh sh/a.txt
share 'an empty pid file' yes
mk cache sh/a.txt
: >/var/run/mover.pid
-run 1
+run 0
log_lacks 'already running'
array_is sh sh/a.txt
@@ -181,8 +250,9 @@ cache_is sh sh/a.txt
share 'no plugin config' yes
rm "$CFG"
mk cache sh/a.txt
-run 3 "grep: $CFG: No such file or directory"
+run 3
log_has "Fatal error: $CFG does not exist, check this."
+log_lacks 'Plugin version'
cache_is sh sh/a.txt
for pools in 1 0; do
From 2299eb7fb0e734e7ebf98360092c3f67e0e3c311 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 21:21:05 +0800
Subject: [PATCH 61/94] share_mover: move a prefer share only from array disks
and pools, run no find without a folder, let a second stop wait for the write
method
---
.../plugins/ca.mover.tuning/share_mover | 39 ++++++-----
tests/age_mover/test_share_mover.sh | 65 +++++++++++++++----
2 files changed, 74 insertions(+), 30 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover
index c7cbf021..8e931464 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover
@@ -158,8 +158,7 @@ write_method() {
case $m in 0 | 1 | auto) echo "$m" ;; *) return 1 ;; esac
}
-# With Turbo Mode on, forces turbo write for the moves, only when the write method can be set back after; mirrors
-# age_mover's force_turbo
+# With Turbo Mode on, forces turbo write for the moves, only when the write method can be set back after
force_turbo() {
TURBO_WAS=""
[ "$ENABLETURBO" = "yes" ] || return 0
@@ -171,8 +170,9 @@ force_turbo() {
mvlogger "TEST MODE: Would force turbo write on"
return 0
fi
- # set first: a stop that ends the run from here on puts the write method back before the pid file goes; a KILL cannot
- trap 'restore_turbo; pid_cleanup' EXIT
+ # set first: a stop that ends the run from here on puts the write method back before the pid file goes, and a second
+ # stop waits for it; a KILL cannot
+ trap 'trap "" HUP INT TERM; restore_turbo; pid_cleanup' EXIT
mvlogger "Forcing turbo write on"
/usr/local/sbin/mdcmd set md_write_method 1
}
@@ -251,39 +251,44 @@ if grep -qs 'shareUseCache="yes\|shareUseCache="prefer"' "$SHARECFG"; then
mvlogger "=> Skipping"
else
mvlogger "$(titleLine 'LET THE MOVING SHOW BEGIN !' '*')"
- force_turbo
# the share name reaches find only as an argument, never parsed as shell
if [ "$SHAREUSECACHE" = "prefer" ]; then
- # "cache=prefer": the share's folder on every other disk and pool, for the move to the primary
+ # "cache=prefer": the share's folder on each array disk and each other pool, never on a mount such as
+ # Unassigned Devices' that only shares its name, for the move to the primary
paths=()
- for dir in /mnt/*; do
+ for dir in /mnt/disk[0-9] /mnt/disk[1-9][0-9] "${POOLCFGS[@]}"; do
+ dir=/mnt/${dir##*/}
+ dir=${dir%.cfg}
if [ -d "$dir/$SHARENAME" ] && [ "$dir/$SHARENAME" != "/mnt/$PRIMARYSTORAGENAME/$SHARENAME" ]; then
paths+=("$dir/$SHARENAME")
fi
done
- opts=(-type f -not -path '/mnt/user*' -depth)
else
paths=("$SHAREPATH")
- opts=(-type f -depth)
fi
- # the log shows each path in qp's quotes, for the debug package's redaction
FINDSTR="find"
for p in "${paths[@]}"; do FINDSTR+=" $(qp "$p")"; done
- FINDSTR+=$(printf ' %q' "${opts[@]}")
-
- if [ "$TESTMODE" = "yes" ]; then
+ FINDSTR+=" -type f -depth"
+
+ # find given no folder would list the one it runs in
+ if [ ${#paths[@]} -eq 0 ]; then
+ mvlogger "No array disk or other pool holds a folder of the share: nothing to move"
+ mvlogger "=> Skipping"
+ elif [ "$TESTMODE" = "yes" ]; then
+ force_turbo
mvlogger "Running in Test Mode: $FINDSTR"
- find "${paths[@]}" "${opts[@]}"
+ find "${paths[@]}" -type f -depth
+ restore_turbo
else
MOVE=/usr/libexec/unraid/move
[ -f "$MOVE" ] || MOVE=$(which move)
+ force_turbo
mvlogger "Complete Mover Command: $FINDSTR | $MOVE -d $LOGLEVEL"
- find "${paths[@]}" "${opts[@]}" | "$MOVE" -d "$LOGLEVEL"
+ find "${paths[@]}" -type f -depth | "$MOVE" -d "$LOGLEVEL"
+ restore_turbo
fi
- restore_turbo
-
fi
fi
diff --git a/tests/age_mover/test_share_mover.sh b/tests/age_mover/test_share_mover.sh
index 7ccde426..81e68f7a 100644
--- a/tests/age_mover/test_share_mover.sh
+++ b/tests/age_mover/test_share_mover.sh
@@ -108,14 +108,41 @@ rm "$T/bin/move"
log_has "Complete Mover Command: find \"/mnt/cache/sh\" -type f -depth | $T/bin/move -d 1"
array_is sh sh/a.txt
+# /mnt/other is no array disk or pool, as Unassigned Devices' mounts: a folder there that only shares the name stays
share 'a prefer share' prefer
mk disk1 sh/c.txt
+mk disk2 sh/d.txt
mk user0 sh/u.txt
+mk other sh/o.txt
run 0
-log_has 'Complete Mover Command: find "/mnt/disk1/sh" "/mnt/user0/sh" -type f -not -path /mnt/user\* -depth | /usr/libexec/unraid/move -d 1'
-cache_is sh sh/c.txt
+log_has 'Complete Mover Command: find "/mnt/disk1/sh" "/mnt/disk2/sh" -type f -depth | /usr/libexec/unraid/move -d 1'
+cache_is sh sh/c.txt sh/d.txt
holds disk1 sh
+holds disk2 sh
array_is sh sh/u.txt
+holds other sh sh/o.txt
+
+share 'a prefer share, from a second pool' prefer
+: >/boot/config/pools/other.cfg
+echo 'shareCachePool2="other"' >>/boot/config/shares/sh.cfg
+mk other sh/o.txt
+run 0
+log_has 'Complete Mover Command: find "/mnt/other/sh" -type f -depth | /usr/libexec/unraid/move -d 1'
+cache_is sh sh/o.txt
+holds other sh
+
+# find given no folder lists the one it runs in: the run must not reach it
+share 'a prefer share, no array disk or other pool holds its folder' prefer enableTurbo yes
+mk cache sh/a.txt
+mkdir -p /mnt/user0/sh
+touch "$T/cwd/stray.txt"
+run 0
+log_has 'No array disk or other pool holds a folder of the share: nothing to move'
+log_lacks 'Complete Mover Command'
+mdcmd_calls
+cache_is sh sh/a.txt
+check 'the folder the run starts in keeps its file' stray.txt "$(ls "$T/cwd")"
+rm -f "$T/cwd/stray.txt"
for wm in 'auto Auto (read/modify/write)' '1 Turbo writes (Reconstruct)' '0 Read/modify/write'; do
share "turbo on, md_write_method ${wm%% *}" yes enableTurbo yes
@@ -161,22 +188,34 @@ for now in '0 Read/modify/write' ' Auto (read/modify/write)'; do
array_is sh sh/a.txt
done
-# a stop of the run during the moves: it ends once the move does, and sets the write method back before its pid file goes
-share 'turbo on, a stop during the moves' yes enableTurbo yes
-mk cache sh/a.txt
-# shellcheck disable=SC2016 # the hook expands it
-move_hook 'kill -TERM "$(cat /var/run/mover.pid)"'
+# a stop of the run during the moves: it ends once the move does, and sets the write method back before its pid file goes.
+# A second stop, at the read of var.ini for that, waits for it
cat >/usr/local/sbin/mdcmd </dev/null)
echo "mdcmd \$*\${w:+ (pid file there)}" >>$T/mdcmd.calls
EOF
-run 143
-move_unhook
-mdcmd_calls 'set md_write_method 1 (pid file there)' 'set md_write_method auto (pid file there)'
-log_count 1 'Restoring original turbo write mode Auto (read/modify/write)'
-check 'the run removed its pid file' '' "$(ls /var/run/mover.pid 2>/dev/null)"
-array_is sh sh/a.txt
+mkdir -p "$T/wrap"
+cat >"$T/wrap/grep" </dev/null)"
+ mdcmd_calls 'set md_write_method 1 (pid file there)' 'set md_write_method auto (pid file there)'
+ log_count 1 'Restoring original turbo write mode Auto (read/modify/write)'
+ check 'the run removed its pid file' '' "$(ls /var/run/mover.pid 2>/dev/null)"
+ array_is sh sh/a.txt
+done
+rm -rf "$T/wrap"
cat >/usr/local/sbin/mdcmd <>$T/mdcmd.calls
From 8ddc0e500e93c17dd2f08737edb75b539d772d65 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Wed, 25 Nov 2026 21:29:03 +0800
Subject: [PATCH 62/94] Let a second stop wait while the run puts the write
method back
---
.../emhttp/plugins/ca.mover.tuning/age_mover | 5 ++--
tests/age_mover/test_stops.sh | 28 +++++++++++++++++++
2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index e9f4fba4..897561bf 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -3359,8 +3359,9 @@ force_turbo() {
mvlogger "TEST MODE: Would force turbo write on"
return 0
fi
- # set first: a stop that ends the run from here on puts the write method back on its way out; a KILL cannot
- trap restore_turbo EXIT
+ # set first: a stop that ends the run from here on puts the write method back on its way out, and a second stop
+ # waits for it; a KILL cannot
+ trap 'trap "" HUP INT TERM; restore_turbo' EXIT
mvlogger "Forcing turbo write on"
/usr/local/sbin/mdcmd set md_write_method 1
}
diff --git a/tests/age_mover/test_stops.sh b/tests/age_mover/test_stops.sh
index 178273eb..dbc84825 100644
--- a/tests/age_mover/test_stops.sh
+++ b/tests/age_mover/test_stops.sh
@@ -126,6 +126,34 @@ for who in plugin run; do
cache_is sh sh/s sh/s/2.txt
done
+# a second stop, at the read of var.ini that puts the write method back, waits for it
+begin "turbo write on, a second stop as the run puts it back" enableTurbo yes
+mk cache sh/s/1.txt sh/s/2.txt
+for n in 1 2; do row 'move from primary' f "sh/s/$n.txt"; done | list
+turbo_standin
+cat >"$T/bin/grep" </dev/null)"
+put_back_once
+array_is sh sh/s sh/s/1.txt
+cache_is sh sh/s sh/s/2.txt
+
begin "turbo write on, var.ini gives no write method" enableTurbo yes
mk cache sh/s/1.txt
row 'move from primary' f sh/s/1.txt | list
From 17e84494a1307aa33605258a8fff5aebbecddaab Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Thu, 26 Nov 2026 00:53:37 +0800
Subject: [PATCH 63/94] Give a cut-short remount's notice its steps, and send
it under Notify errors only
---
.../usr/local/emhttp/plugins/ca.mover.tuning/age_mover | 9 +++++++--
.../emhttp/plugins/ca.mover.tuning/languages/de_DE.txt | 2 ++
.../emhttp/plugins/ca.mover.tuning/languages/en_US.txt | 2 ++
.../emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt | 2 ++
.../emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt | 2 ++
.../emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt | 2 ++
tests/age_mover/test_dataset_stops.sh | 10 ++++++----
7 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index b2e01d67..47aa61c3 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -2694,12 +2694,17 @@ remount_dataset() {
;;
1) ;;
2)
- dataset_problem warning "$1" "ZFS dataset [$1] is mounted again, but the look for a file written to $2 as it was mounted was cut short: one may be hidden under it"
+ # a failure, as a found file is: Notify errors only must still say a file may be out of view
+ dataset_problem failure "$1"
+ dataset_out_of_view "mounted again, but the look for a file written to %s as it was mounted was cut short, so one may be hidden under it: stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s" \
+ "$1" "$2" "$1" "$2" "$1" "$2"
return 0
;;
*)
# killed outright, it may have mounted it or not
- dataset_problem failure "$1" "Remounting ZFS dataset [$1] was cut short: if zfs mount does not list it at $2, stop writes to the share, move anything in $2 aside, zfs mount $1, then move it back into $2"
+ dataset_problem failure "$1"
+ dataset_out_of_view "the remount was cut short, so it may not be mounted or may hide a file: stop writes to the share, if zfs mount lists it at %s run zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s" \
+ "$1" "$2" "$1" "$2" "$1" "$2"
return 0
;;
esac
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt
index 03643dbb..6b276ecf 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt
@@ -9,6 +9,8 @@
%s files and %s folders representing %s could not be movedsynced by Mover Tuning plugin=%s Dateien und %s Ordner mit einer Größe von %s konnten vom Mover Tuning Plugin nicht verschoben/synchronisiert werden.
Action=Aktion
a file is hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=eine Datei ist darunter verdeckt: Schreibzugriffe auf die Freigabe stoppen, zfs unmount %s ausführen, alles in %s beiseite verschieben, zfs mount %s ausführen, dann alles zurück nach %s verschieben
+mounted again, but the look for a file written to %s as it was mounted was cut short, so one may be hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=wieder eingehängt, aber die Suche nach einer beim Einhängen nach %s geschriebenen Datei wurde abgebrochen, eine Datei ist darunter vielleicht verdeckt: Schreibzugriffe auf die Freigabe stoppen, zfs unmount %s ausführen, alles in %s beiseite verschieben, zfs mount %s ausführen, dann alles zurück nach %s verschieben
+the remount was cut short, so it may not be mounted or may hide a file stop writes to the share, if zfs mount lists it at %s run zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=das erneute Einhängen wurde abgebrochen, es ist also vielleicht nicht eingehängt oder verdeckt eine Datei: Schreibzugriffe auf die Freigabe stoppen, wenn zfs mount es unter %s auflistet, zfs unmount %s ausführen, alles in %s beiseite verschieben, zfs mount %s ausführen, dann alles zurück nach %s verschieben
All community developers=Alle Entwickler der Community
%s files and %s folders were movedsynced, but rsync reported errors for them Check the Mover Tuning log=%s Dateien und %s Ordner wurden verschoben/synchronisiert, aber rsync hat dabei Fehler gemeldet. Bitte das Mover‑Tuning‑Protokoll prüfen.
Allow force mover schedule to run during a parity checkrebuild=Erlaubt das erzwungene Ausführen der Datenverschiebung während einer Paritätsprüfung oder Wiederherstellung
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt
index be6ae7dd..3b933b3a 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt
@@ -12,6 +12,8 @@
%s files and %s folders were movedsynced, but rsync reported errors for them Check the Mover Tuning log=%s files and %s folders were moved/synced, but rsync reported errors for them. Check the Mover Tuning log.
Action=
a file is hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=a file is hidden under it: stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s
+mounted again, but the look for a file written to %s as it was mounted was cut short, so one may be hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=mounted again, but the look for a file written to %s as it was mounted was cut short, so one may be hidden under it: stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s
+the remount was cut short, so it may not be mounted or may hide a file stop writes to the share, if zfs mount lists it at %s run zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=the remount was cut short, so it may not be mounted or may hide a file: stop writes to the share, if zfs mount lists it at %s run zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s
All community developers=
Allow force mover schedule to run during a parity checkrebuild=Allow force mover schedule to run during a parity check/rebuild
All plugin settings return to their defaults, including the Mover Tuning schedule, the forced move schedule and the cache watchdog, and the override settings of every share are deleted=All plugin settings return to their defaults, including the Mover Tuning schedule, the forced move schedule and the cache watchdog, and the override settings of every share are deleted.
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt
index c646d941..e933ba8c 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt
@@ -10,6 +10,8 @@
%s files and %s folders were movedsynced, but rsync reported errors for them Check the Mover Tuning log=%s fichiers et %s dossiers ont été déplacés/synchronisés, mais rsync a signalé des erreurs les concernant. Consultez le journal de Mover Tuning.
Action=Action
a file is hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=un fichier est masqué dessous : arrêtez les écritures sur le partage, lancez zfs unmount %s, mettez de côté tout ce qui est dans %s, lancez zfs mount %s, puis remettez le tout dans %s
+mounted again, but the look for a file written to %s as it was mounted was cut short, so one may be hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=monté à nouveau, mais la recherche de fichiers écrits dans %s pendant le montage a été interrompue, un fichier y est peut-être masqué : arrêtez les écritures sur le partage, lancez zfs unmount %s, mettez de côté tout ce qui est dans %s, lancez zfs mount %s, puis remettez le tout dans %s
+the remount was cut short, so it may not be mounted or may hide a file stop writes to the share, if zfs mount lists it at %s run zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=le remontage a été interrompu, il peut donc ne pas être monté ou masquer un fichier : arrêtez les écritures sur le partage, si zfs mount le montre sur %s lancez zfs unmount %s, mettez de côté tout ce qui est dans %s, lancez zfs mount %s, puis remettez le tout dans %s
All community developers=Tous les développeurs de la communauté
Allow force mover schedule to run during a parity checkrebuild=Autoriser l’exécution forcée du mover pendant une vérification/réparation de parité
All plugin settings return to their defaults, including the Mover Tuning schedule, the forced move schedule and the cache watchdog, and the override settings of every share are deleted=Tous les paramètres du plugin reviennent à leurs valeurs par défaut, y compris la planification Mover Tuning, l’horaire du déplacement forcé et la surveillance du cache, et les paramètres remplacés de chaque part sont supprimés.
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt
index 721eb9c2..bdb30e93 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt
@@ -9,6 +9,8 @@
%s files and %s folders representing %s could not be movedsynced by Mover Tuning plugin=Плагину Mover Tuning не удалось переместить/синхронизировать %s файлов и %s папок общим объёмом %s.
Action=Действие
a file is hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=под ним скрыт файл: остановите запись в общий ресурс, выполните zfs unmount %s, переместите всё из %s в другое место, выполните zfs mount %s, затем верните всё обратно в %s
+mounted again, but the look for a file written to %s as it was mounted was cut short, so one may be hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=снова смонтирован, но поиск файла, записанного в %s во время монтирования, был прерван, под ним может быть скрыт файл: остановите запись в общий ресурс, выполните zfs unmount %s, переместите всё из %s в другое место, выполните zfs mount %s, затем верните всё обратно в %s
+the remount was cut short, so it may not be mounted or may hide a file stop writes to the share, if zfs mount lists it at %s run zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=повторное монтирование прервано, поэтому он может быть не смонтирован или скрывать файл: остановите запись в общий ресурс, если zfs mount показывает его в %s, выполните zfs unmount %s, переместите всё из %s в другое место, выполните zfs mount %s, затем верните всё обратно в %s
All community developers=Все разработчики сообщества
%s files and %s folders were movedsynced, but rsync reported errors for them Check the Mover Tuning log=%s файлов и %s папок были перемещены/синхронизированы, но rsync сообщил об ошибках при их обработке. Проверьте журнал Mover Tuning.
Allow force mover schedule to run during a parity checkrebuild=Разрешить запуск расписания принудительного перемещения во время проверки/восстановления четности
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt
index bb7c03af..2c21a86a 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt
@@ -9,6 +9,8 @@
%s files and %s folders were movedsynced, but rsync reported errors for them Check the Mover Tuning log=%s 个文件和 %s 个文件夹已移动/同步,但 rsync 报告了错误。请查看 Mover Tuning 日志。
Action=操作
a file is hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=其下有文件被遮盖:停止向该共享写入,运行 zfs unmount %s,将 %s 中的所有内容移到别处,运行 zfs mount %s,然后移回 %s
+mounted again, but the look for a file written to %s as it was mounted was cut short, so one may be hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=已重新挂载,但对挂载期间写入 %s 的文件的检查被中断,其下可能有文件被遮盖:停止向该共享写入,运行 zfs unmount %s,将 %s 中的所有内容移到别处,运行 zfs mount %s,然后移回 %s
+the remount was cut short, so it may not be mounted or may hide a file stop writes to the share, if zfs mount lists it at %s run zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=重新挂载被中断,因此它可能未挂载,或其下有文件被遮盖:停止向该共享写入,如果 zfs mount 列出它挂载在 %s,运行 zfs unmount %s,将 %s 中的所有内容移到别处,运行 zfs mount %s,然后移回 %s
All community developers=所有社区开发者
Allow force mover schedule to run during a parity checkrebuild=允许强制移动计划在奇偶校验/重建期间运行
All plugin settings return to their defaults, including the Mover Tuning schedule, the forced move schedule and the cache watchdog, and the override settings of every share are deleted=所有插件设置都将恢复为默认值,包括 Mover Tuning 计划、强制移动计划和缓存看门狗,并且所有共享的覆盖设置都将被删除。
diff --git a/tests/age_mover/test_dataset_stops.sh b/tests/age_mover/test_dataset_stops.sh
index feeac6cc..ca67bc23 100644
--- a/tests/age_mover/test_dataset_stops.sh
+++ b/tests/age_mover/test_dataset_stops.sh
@@ -337,8 +337,9 @@ done
# a file lands in the folder as the dataset is mounted back. The look after the mount killed printed nothing because it
# never looked; the whole remount killed leaves the run unable to tell whether the mount happened
+# Notify errors only: a failure still sends the notice, which alone carries the steps when action logging is off
for what in look remount; do
- begin "Clean ZFS datasets, the $what at the mount back is killed" cleanFolders topFolder cleanDatasets yes
+ begin "Clean ZFS datasets, the $what at the mount back is killed" cleanFolders topFolder cleanDatasets yes notify errorsOnly
one_share
echo 'echo x >/mnt/cache/sh/new.txt' >"$T/zfs.on_unmount"
echo 'echo y >/mnt/cache/sh/late.txt' >"$T/zfs.on_mount"
@@ -354,12 +355,13 @@ EOF
PATH=$T/wrap:$PATH run_moves
check "zfs calls" "$REMOUNTED" "$(cat "$T/zfs.calls")"
if [ "$what" = look ]; then
- log_has 'ZFS dataset [cache/sh] is mounted again, but the look for a file written to /mnt/cache/sh as it was mounted was cut short: one may be hidden under it'
+ why="mounted again, but the look for a file written to /mnt/cache/sh as it was mounted was cut short, so one may be hidden under it: stop writes to the share, zfs unmount cache/sh, $BACK"
else
- log_has 'Remounting ZFS dataset [cache/sh] was cut short: if zfs mount does not list it at /mnt/cache/sh, stop writes to the share, move anything in /mnt/cache/sh aside, zfs mount cache/sh, then move it back into /mnt/cache/sh'
+ why="the remount was cut short, so it may not be mounted or may hide a file: stop writes to the share, if zfs mount lists it at /mnt/cache/sh run zfs unmount cache/sh, $BACK"
fi
+ log_has "ZFS dataset [cache/sh]: $why"
log_lacks 'Failed to remount'
- notices "$NOTICE"
+ notices "$(notice_for "[cache/sh] ($why)")"
mounted_again
cache_is sh sh/new.txt
no_private
From 32ee7be97ca9c91c955686875f9e30acfbd6ea35 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Thu, 26 Nov 2026 05:38:29 +0800
Subject: [PATCH 64/94] Check the mount table after a failed recovery umount,
so a detached dataset is mounted back
---
.../emhttp/plugins/ca.mover.tuning/age_mover | 7 +++--
tests/age_mover/test_datasets.sh | 31 +++++++++++--------
2 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index 47aa61c3..1b60560e 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -2720,6 +2720,9 @@ dataset_kept() {
mvDebuglogger "Keeping ZFS dataset [$1]: a destroy could lose $(qp "${2//$'\n'/\\n}")" "Clean Dataset"
}
+# Succeeds if dataset $1 is mounted at folder $2; a stop does not cut the read short
+mounted_at() { [ "$(finish_on_stop findmnt -no source --mountpoint "$2")" = "$1" ]; }
+
# Unmounts dataset $1 from folder $2 and destroys it if dataset_loses_unmounted at private folder $4 against $3 is empty;
# else tries to mount it back. processTheMoves' stopped, set by a stop, skips the destroy
unmount_check_destroy() {
@@ -2738,10 +2741,10 @@ unmount_check_destroy() {
# umount after unmounting, so the mount table decides
if [ "$rc" != 0 ]; then
[ "$rc" = 1 ] || [ "$rc" = 2 ] || lost="the check was cut short"
- if [ "$(finish_on_stop findmnt -no source --mountpoint "$private")" != "$dataset" ]; then
+ if ! mounted_at "$dataset" "$private"; then
# unmounted after all, but what the check found was not kept
[ "$rc" != 2 ] || { lost="umount: $lost"; rc=1; }
- elif [ "$rc" != 2 ] && ! err=$(finish_on_stop umount "$private" 2>&1); then
+ elif [ "$rc" != 2 ] && ! err=$(finish_on_stop umount "$private" 2>&1) && mounted_at "$dataset" "$private"; then
lost=$(zfs_reason "${err#umount: }")
rc=2
fi
diff --git a/tests/age_mover/test_datasets.sh b/tests/age_mover/test_datasets.sh
index fe418506..36eaac62 100644
--- a/tests/age_mover/test_datasets.sh
+++ b/tests/age_mover/test_datasets.sh
@@ -193,19 +193,24 @@ no_private
notices "$NOT_MOUNTED"
rm -f /mnt/cache/sh
-# mount.zfs can make the read-only mount and still fail: the run finds the dataset there and unmounts it before the remount
-begin "Clean ZFS datasets, the read-only mount is made but reported as failed" cleanFolders topFolder cleanDatasets yes
-mk cache sh/only/f.txt
-printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
-echo mount.zfs.late >"$T/zfs.fail"
-row 'move from primary' f sh/only/f.txt | list
-run_moves
-check "zfs calls" "$(sed '$d' <<<"$DESTROYED"; echo 'zfs mount cache/sh')" "$(cat "$T/zfs.calls")"
-log_has "ZFS dataset [cache/sh] could not be checked once unmounted, will not delete: mount: filesystem 'cache/sh' was mounted, but /etc/mtab could not be updated"
-log_lacks 'Failed to remount'
-check "the dataset is mounted at its folder again" /mnt/cache/sh "$(grep -x /mnt/cache/sh "$T/zfs")"
-no_private
-notices "$NOTICE"
+# mount.zfs can make the read-only mount and still fail, and umount can take it off and still fail: the mount table
+# decides, so the run unmounts the dataset from the private folder if it is there and mounts it back
+for late in '' ', and so is its unmount'; do
+ begin "Clean ZFS datasets, the read-only mount is made but reported as failed$late" cleanFolders topFolder cleanDatasets yes
+ mk cache sh/only/f.txt
+ printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+ echo mount.zfs.late >"$T/zfs.fail"
+ [ -z "$late" ] || echo umount.late >>"$T/zfs.fail"
+ row 'move from primary' f sh/only/f.txt | list
+ run_moves
+ check "zfs calls" "$(sed '$d' <<<"$DESTROYED"; echo 'zfs mount cache/sh')" "$(cat "$T/zfs.calls")"
+ log_has "ZFS dataset [cache/sh] could not be checked once unmounted, will not delete: mount: filesystem 'cache/sh' was mounted, but /etc/mtab could not be updated"
+ log_lacks 'still mounted read-only'
+ log_lacks 'Failed to remount'
+ check "the dataset is mounted at its folder again" /mnt/cache/sh "$(grep -x /mnt/cache/sh "$T/zfs")"
+ no_private
+ notices "$NOTICE"
+done
# one notice for the run at its worst level: an unmount that fails, then a check that fails, still reach errorsOnly
begin "Clean ZFS datasets, two datasets fail" cleanFolders topFolder cleanDatasets yes notify errorsOnly
From 54d7772862138e82ca35de9a48af87dbd843b863 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Thu, 26 Nov 2026 06:01:08 +0800
Subject: [PATCH 65/94] Tell the recovery steps to keep both copies of a file
the dataset already has
---
.../usr/local/emhttp/plugins/ca.mover.tuning/age_mover | 10 +++++-----
.../emhttp/plugins/ca.mover.tuning/languages/de_DE.txt | 10 +++++-----
.../emhttp/plugins/ca.mover.tuning/languages/en_US.txt | 10 +++++-----
.../emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt | 10 +++++-----
.../emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt | 10 +++++-----
.../emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt | 10 +++++-----
tests/age_mover/lib.sh | 2 +-
tests/age_mover/test_dataset_stops.sh | 2 +-
8 files changed, 32 insertions(+), 32 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index 1b60560e..21e70e7e 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -2688,7 +2688,7 @@ remount_dataset() {
0)
[ -n "$out" ] || return 0
dataset_problem failure "$1" "ZFS dataset [$1] is mounted again, but $2/${out#./}, written as it was mounted, is hidden under it"
- dataset_out_of_view "a file is hidden under it: stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s" \
+ dataset_out_of_view "a file is hidden under it: stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there: keep both copies and compare them" \
"$1" "$1" "$2" "$1" "$2"
return 0
;;
@@ -2696,21 +2696,21 @@ remount_dataset() {
2)
# a failure, as a found file is: Notify errors only must still say a file may be out of view
dataset_problem failure "$1"
- dataset_out_of_view "mounted again, but the look for a file written to %s as it was mounted was cut short, so one may be hidden under it: stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s" \
+ dataset_out_of_view "mounted again, but the look for a file written to %s as it was mounted was cut short, so one may be hidden under it: stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there: keep both copies and compare them" \
"$1" "$2" "$1" "$2" "$1" "$2"
return 0
;;
*)
# killed outright, it may have mounted it or not
dataset_problem failure "$1"
- dataset_out_of_view "the remount was cut short, so it may not be mounted or may hide a file: stop writes to the share, if zfs mount lists it at %s run zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s" \
+ dataset_out_of_view "the remount was cut short, so it may not be mounted or may hide a file: stop writes to the share, if zfs mount lists it at %s run zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there: keep both copies and compare them" \
"$1" "$2" "$1" "$2" "$1" "$2"
return 0
;;
esac
fi
dataset_problem failure "$1" "Failed to remount dataset [$1]" "$out"
- dataset_out_of_view "not mounted: stop writes to the share, move anything in %s aside, zfs mount %s, then move it back into %s" \
+ dataset_out_of_view "not mounted: stop writes to the share, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there: keep both copies and compare them" \
"$1" "$2" "$1" "$2"
}
@@ -2752,7 +2752,7 @@ unmount_check_destroy() {
if [ "$rc" = 2 ]; then
dataset_problem failure "$dataset" \
"ZFS dataset [${dataset}] is still mounted read-only at ${private}, not at ${folder}: umount: $lost"
- dataset_out_of_view "mounted read-only at %s: stop writes to the share, umount %s, move anything in %s aside, zfs mount %s, then move it back into %s" \
+ dataset_out_of_view "mounted read-only at %s: stop writes to the share, umount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there: keep both copies and compare them" \
"$dataset" "$private" "$private" "$folder" "$dataset" "$folder"
return 0
elif [ "$rc" != 0 ]; then
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt
index 6b276ecf..a4e1f3c5 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/de_DE.txt
@@ -8,9 +8,9 @@
%s files and %s folders representing %s could not be movedsynced by Mover Tuning plugin=%s Dateien und %s Ordner mit einer Größe von %s konnten vom Mover Tuning Plugin nicht verschoben/synchronisiert werden.
Action=Aktion
-a file is hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=eine Datei ist darunter verdeckt: Schreibzugriffe auf die Freigabe stoppen, zfs unmount %s ausführen, alles in %s beiseite verschieben, zfs mount %s ausführen, dann alles zurück nach %s verschieben
-mounted again, but the look for a file written to %s as it was mounted was cut short, so one may be hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=wieder eingehängt, aber die Suche nach einer beim Einhängen nach %s geschriebenen Datei wurde abgebrochen, eine Datei ist darunter vielleicht verdeckt: Schreibzugriffe auf die Freigabe stoppen, zfs unmount %s ausführen, alles in %s beiseite verschieben, zfs mount %s ausführen, dann alles zurück nach %s verschieben
-the remount was cut short, so it may not be mounted or may hide a file stop writes to the share, if zfs mount lists it at %s run zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=das erneute Einhängen wurde abgebrochen, es ist also vielleicht nicht eingehängt oder verdeckt eine Datei: Schreibzugriffe auf die Freigabe stoppen, wenn zfs mount es unter %s auflistet, zfs unmount %s ausführen, alles in %s beiseite verschieben, zfs mount %s ausführen, dann alles zurück nach %s verschieben
+a file is hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there keep both copies and compare them=eine Datei ist darunter verdeckt: Schreibzugriffe auf die Freigabe stoppen, zfs unmount %s ausführen, alles in %s beiseite verschieben, zfs mount %s ausführen, dann alles zurück nach %s verschieben, ohne eine dort vorhandene Datei zu ersetzen: beide Kopien behalten und vergleichen
+mounted again, but the look for a file written to %s as it was mounted was cut short, so one may be hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there keep both copies and compare them=wieder eingehängt, aber die Suche nach einer beim Einhängen nach %s geschriebenen Datei wurde abgebrochen, eine Datei ist darunter vielleicht verdeckt: Schreibzugriffe auf die Freigabe stoppen, zfs unmount %s ausführen, alles in %s beiseite verschieben, zfs mount %s ausführen, dann alles zurück nach %s verschieben, ohne eine dort vorhandene Datei zu ersetzen: beide Kopien behalten und vergleichen
+the remount was cut short, so it may not be mounted or may hide a file stop writes to the share, if zfs mount lists it at %s run zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there keep both copies and compare them=das erneute Einhängen wurde abgebrochen, es ist also vielleicht nicht eingehängt oder verdeckt eine Datei: Schreibzugriffe auf die Freigabe stoppen, wenn zfs mount es unter %s auflistet, zfs unmount %s ausführen, alles in %s beiseite verschieben, zfs mount %s ausführen, dann alles zurück nach %s verschieben, ohne eine dort vorhandene Datei zu ersetzen: beide Kopien behalten und vergleichen
All community developers=Alle Entwickler der Community
%s files and %s folders were movedsynced, but rsync reported errors for them Check the Mover Tuning log=%s Dateien und %s Ordner wurden verschoben/synchronisiert, aber rsync hat dabei Fehler gemeldet. Bitte das Mover‑Tuning‑Protokoll prüfen.
Allow force mover schedule to run during a parity checkrebuild=Erlaubt das erzwungene Ausführen der Datenverschiebung während einer Paritätsprüfung oder Wiederherstellung
@@ -82,7 +82,7 @@ Logs parent folder for Mover Tuning plugin=Übergeordneter Ordner für Protokoll
Low=Niedrig
Maintainers=Betreuer
make those plugins with ❤️ and a lot of ☕=machen diese Plugins mit ❤️ und viel ☕
-mounted read-only at %s stop writes to the share, umount %s, move anything in %s aside, zfs mount %s, then move it back into %s=schreibgeschützt eingehängt unter %s: Schreibzugriffe auf die Freigabe stoppen, umount %s ausführen, alles in %s beiseite verschieben, zfs mount %s ausführen, dann alles zurück nach %s verschieben
+mounted read-only at %s stop writes to the share, umount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there keep both copies and compare them=schreibgeschützt eingehängt unter %s: Schreibzugriffe auf die Freigabe stoppen, umount %s ausführen, alles in %s beiseite verschieben, zfs mount %s ausführen, dann alles zurück nach %s verschieben, ohne eine dort vorhandene Datei zu ersetzen: beide Kopien behalten und vergleichen
Move ALL files from current pool ignores filters and thresholds=ALLE Dateien aus dem aktuellen Pool verschieben (ohne Filter und Schwellenwerte)
Move ALL files to current pool ignores filters and thresholds=ALLE Dateien in den aktuellen Pool verschieben (ohne Filter und Schwellenwerte)
Move All from Primary->Secondary cacheyes shares pool percentage=Alles vom Primärspeicher → Sekundärspeicher verschieben (cache:yes) – Pool‑Prozent
@@ -126,7 +126,7 @@ No log files yet=Noch keine Protokolldateien
Not Applicable Share Does Not Exist Yet=Nicht anwendbar (Freigabe existiert noch nicht)
Not a valid cron schedule it is not applied=Kein gültiger Cron‑Zeitplan: Er wird nicht übernommen.
Notify Mover Tuning plugin actions=Aktionen des Mover‑Tuning‑Plugins melden
-not mounted stop writes to the share, move anything in %s aside, zfs mount %s, then move it back into %s=nicht eingehängt: Schreibzugriffe auf die Freigabe stoppen, alles in %s beiseite verschieben, zfs mount %s ausführen, dann alles zurück nach %s verschieben
+not mounted stop writes to the share, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there keep both copies and compare them=nicht eingehängt: Schreibzugriffe auf die Freigabe stoppen, alles in %s beiseite verschieben, zfs mount %s ausführen, dann alles zurück nach %s verschieben, ohne eine dort vorhandene Datei zu ersetzen: beide Kopien behalten und vergleichen
Oldest first=Älteste zuerst
Only move files larger than this in MB=Nur Dateien verschieben, die größer sind als dieser Wert (in MB)
Only move files that are older than this in days=Nur Dateien verschieben, die älter sind als dieser Wert (in Tagen)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt
index 3b933b3a..4a5d54ea 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/en_US.txt
@@ -11,9 +11,9 @@
%s files and %s folders representing %s could not be movedsynced by Mover Tuning plugin=%s files and %s folders representing %s could not be moved/synced by Mover Tuning plugin.
%s files and %s folders were movedsynced, but rsync reported errors for them Check the Mover Tuning log=%s files and %s folders were moved/synced, but rsync reported errors for them. Check the Mover Tuning log.
Action=
-a file is hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=a file is hidden under it: stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s
-mounted again, but the look for a file written to %s as it was mounted was cut short, so one may be hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=mounted again, but the look for a file written to %s as it was mounted was cut short, so one may be hidden under it: stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s
-the remount was cut short, so it may not be mounted or may hide a file stop writes to the share, if zfs mount lists it at %s run zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=the remount was cut short, so it may not be mounted or may hide a file: stop writes to the share, if zfs mount lists it at %s run zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s
+a file is hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there keep both copies and compare them=a file is hidden under it: stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there: keep both copies and compare them
+mounted again, but the look for a file written to %s as it was mounted was cut short, so one may be hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there keep both copies and compare them=mounted again, but the look for a file written to %s as it was mounted was cut short, so one may be hidden under it: stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there: keep both copies and compare them
+the remount was cut short, so it may not be mounted or may hide a file stop writes to the share, if zfs mount lists it at %s run zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there keep both copies and compare them=the remount was cut short, so it may not be mounted or may hide a file: stop writes to the share, if zfs mount lists it at %s run zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there: keep both copies and compare them
All community developers=
Allow force mover schedule to run during a parity checkrebuild=Allow force mover schedule to run during a parity check/rebuild
All plugin settings return to their defaults, including the Mover Tuning schedule, the forced move schedule and the cache watchdog, and the override settings of every share are deleted=All plugin settings return to their defaults, including the Mover Tuning schedule, the forced move schedule and the cache watchdog, and the override settings of every share are deleted.
@@ -84,7 +84,7 @@ Logs parent folder for Mover Tuning plugin=
Low=
Maintainers=
make those plugins with ❤️ and a lot of ☕=make those plugins with ❤️ (and a lot of ☕).
-mounted read-only at %s stop writes to the share, umount %s, move anything in %s aside, zfs mount %s, then move it back into %s=mounted read-only at %s: stop writes to the share, umount %s, move anything in %s aside, zfs mount %s, then move it back into %s
+mounted read-only at %s stop writes to the share, umount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there keep both copies and compare them=mounted read-only at %s: stop writes to the share, umount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there: keep both copies and compare them
Move ALL files from current pool ignores filters and thresholds=Move **ALL** files from current pool (ignores filters and thresholds)
Move ALL files to current pool ignores filters and thresholds=Move **ALL** files to current pool (ignores filters and thresholds)
Move All from Primary->Secondary cacheyes shares pool percentage=Move All from Primary->Secondary (cache:yes) shares pool percentage
@@ -128,7 +128,7 @@ No log files yet=
Not Applicable Share Does Not Exist Yet=Not Applicable (Share Does Not Exist Yet)
Not a valid cron schedule it is not applied=Not a valid cron schedule: it is not applied.
Notify Mover Tuning plugin actions=
-not mounted stop writes to the share, move anything in %s aside, zfs mount %s, then move it back into %s=not mounted: stop writes to the share, move anything in %s aside, zfs mount %s, then move it back into %s
+not mounted stop writes to the share, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there keep both copies and compare them=not mounted: stop writes to the share, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there: keep both copies and compare them
Oldest first=
Only move files larger than this in MB=Only move files larger than this (in MB)
Only move files that are older than this in days=Only move files that are older than this (in days)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt
index e933ba8c..a8848318 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/fr_FR.txt
@@ -9,9 +9,9 @@
%s files and %s folders representing %s could not be movedsynced by Mover Tuning plugin=%s fichiers et %s dossiers représentant %s n’ont pas pu être déplacés/synchronisés par le plugin Mover Tuning.
%s files and %s folders were movedsynced, but rsync reported errors for them Check the Mover Tuning log=%s fichiers et %s dossiers ont été déplacés/synchronisés, mais rsync a signalé des erreurs les concernant. Consultez le journal de Mover Tuning.
Action=Action
-a file is hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=un fichier est masqué dessous : arrêtez les écritures sur le partage, lancez zfs unmount %s, mettez de côté tout ce qui est dans %s, lancez zfs mount %s, puis remettez le tout dans %s
-mounted again, but the look for a file written to %s as it was mounted was cut short, so one may be hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=monté à nouveau, mais la recherche de fichiers écrits dans %s pendant le montage a été interrompue, un fichier y est peut-être masqué : arrêtez les écritures sur le partage, lancez zfs unmount %s, mettez de côté tout ce qui est dans %s, lancez zfs mount %s, puis remettez le tout dans %s
-the remount was cut short, so it may not be mounted or may hide a file stop writes to the share, if zfs mount lists it at %s run zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=le remontage a été interrompu, il peut donc ne pas être monté ou masquer un fichier : arrêtez les écritures sur le partage, si zfs mount le montre sur %s lancez zfs unmount %s, mettez de côté tout ce qui est dans %s, lancez zfs mount %s, puis remettez le tout dans %s
+a file is hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there keep both copies and compare them=un fichier est masqué dessous : arrêtez les écritures sur le partage, lancez zfs unmount %s, mettez de côté tout ce qui est dans %s, lancez zfs mount %s, puis remettez le tout dans %s sans remplacer un fichier déjà présent : gardez les deux copies et comparez-les
+mounted again, but the look for a file written to %s as it was mounted was cut short, so one may be hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there keep both copies and compare them=monté à nouveau, mais la recherche de fichiers écrits dans %s pendant le montage a été interrompue, un fichier y est peut-être masqué : arrêtez les écritures sur le partage, lancez zfs unmount %s, mettez de côté tout ce qui est dans %s, lancez zfs mount %s, puis remettez le tout dans %s sans remplacer un fichier déjà présent : gardez les deux copies et comparez-les
+the remount was cut short, so it may not be mounted or may hide a file stop writes to the share, if zfs mount lists it at %s run zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there keep both copies and compare them=le remontage a été interrompu, il peut donc ne pas être monté ou masquer un fichier : arrêtez les écritures sur le partage, si zfs mount le montre sur %s lancez zfs unmount %s, mettez de côté tout ce qui est dans %s, lancez zfs mount %s, puis remettez le tout dans %s sans remplacer un fichier déjà présent : gardez les deux copies et comparez-les
All community developers=Tous les développeurs de la communauté
Allow force mover schedule to run during a parity checkrebuild=Autoriser l’exécution forcée du mover pendant une vérification/réparation de parité
All plugin settings return to their defaults, including the Mover Tuning schedule, the forced move schedule and the cache watchdog, and the override settings of every share are deleted=Tous les paramètres du plugin reviennent à leurs valeurs par défaut, y compris la planification Mover Tuning, l’horaire du déplacement forcé et la surveillance du cache, et les paramètres remplacés de chaque part sont supprimés.
@@ -82,7 +82,7 @@ Logs parent folder for Mover Tuning plugin=Dossier parent des journaux du plugin
Low=Faible
Maintainers=Mainteneurs
make those plugins with ❤️ and a lot of ☕=créent ces plugins avec ❤️ et beaucoup de ☕
-mounted read-only at %s stop writes to the share, umount %s, move anything in %s aside, zfs mount %s, then move it back into %s=monté en lecture seule sur %s : arrêtez les écritures sur le partage, lancez umount %s, mettez de côté tout ce qui est dans %s, lancez zfs mount %s, puis remettez le tout dans %s
+mounted read-only at %s stop writes to the share, umount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there keep both copies and compare them=monté en lecture seule sur %s : arrêtez les écritures sur le partage, lancez umount %s, mettez de côté tout ce qui est dans %s, lancez zfs mount %s, puis remettez le tout dans %s sans remplacer un fichier déjà présent : gardez les deux copies et comparez-les
Move ALL files from current pool ignores filters and thresholds=Déplacer **TOUS** les fichiers du pool actuel (en ignorant les filtres et les seuils)
Move ALL files to current pool ignores filters and thresholds=Déplacer **TOUS** les fichiers vers le pool actuel (en ignorant les filtres et les seuils)
Move All from Primary->Secondary cacheyes shares pool percentage=Déplacer tout depuis Primaire→Secondaire (cache:yes) selon le pourcentage du pool
@@ -126,7 +126,7 @@ No log files yet=Aucun fichier journal pour le moment
Not Applicable Share Does Not Exist Yet=Non applicable (la part n’existe pas encore)
Not a valid cron schedule it is not applied=Planification cron invalide : elle n’est pas appliquée.
Notify Mover Tuning plugin actions=Notifier les actions du plugin Mover Tuning
-not mounted stop writes to the share, move anything in %s aside, zfs mount %s, then move it back into %s=non monté : arrêtez les écritures sur le partage, mettez de côté tout ce qui est dans %s, lancez zfs mount %s, puis remettez le tout dans %s
+not mounted stop writes to the share, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there keep both copies and compare them=non monté : arrêtez les écritures sur le partage, mettez de côté tout ce qui est dans %s, lancez zfs mount %s, puis remettez le tout dans %s sans remplacer un fichier déjà présent : gardez les deux copies et comparez-les
Oldest first=Les plus anciens d’abord
Only move files larger than this in MB=Déplacer uniquement les fichiers plus grands que cette taille (en Mo)
Only move files that are older than this in days=Déplacer uniquement les fichiers plus anciens que ce nombre de jours
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt
index bdb30e93..cbfada34 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/ru_RU.txt
@@ -8,9 +8,9 @@
%s files and %s folders representing %s could not be movedsynced by Mover Tuning plugin=Плагину Mover Tuning не удалось переместить/синхронизировать %s файлов и %s папок общим объёмом %s.
Action=Действие
-a file is hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=под ним скрыт файл: остановите запись в общий ресурс, выполните zfs unmount %s, переместите всё из %s в другое место, выполните zfs mount %s, затем верните всё обратно в %s
-mounted again, but the look for a file written to %s as it was mounted was cut short, so one may be hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=снова смонтирован, но поиск файла, записанного в %s во время монтирования, был прерван, под ним может быть скрыт файл: остановите запись в общий ресурс, выполните zfs unmount %s, переместите всё из %s в другое место, выполните zfs mount %s, затем верните всё обратно в %s
-the remount was cut short, so it may not be mounted or may hide a file stop writes to the share, if zfs mount lists it at %s run zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=повторное монтирование прервано, поэтому он может быть не смонтирован или скрывать файл: остановите запись в общий ресурс, если zfs mount показывает его в %s, выполните zfs unmount %s, переместите всё из %s в другое место, выполните zfs mount %s, затем верните всё обратно в %s
+a file is hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there keep both copies and compare them=под ним скрыт файл: остановите запись в общий ресурс, выполните zfs unmount %s, переместите всё из %s в другое место, выполните zfs mount %s, затем верните всё обратно в %s, не заменяя уже имеющийся там файл: сохраните обе копии и сравните их
+mounted again, but the look for a file written to %s as it was mounted was cut short, so one may be hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there keep both copies and compare them=снова смонтирован, но поиск файла, записанного в %s во время монтирования, был прерван, под ним может быть скрыт файл: остановите запись в общий ресурс, выполните zfs unmount %s, переместите всё из %s в другое место, выполните zfs mount %s, затем верните всё обратно в %s, не заменяя уже имеющийся там файл: сохраните обе копии и сравните их
+the remount was cut short, so it may not be mounted or may hide a file stop writes to the share, if zfs mount lists it at %s run zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there keep both copies and compare them=повторное монтирование прервано, поэтому он может быть не смонтирован или скрывать файл: остановите запись в общий ресурс, если zfs mount показывает его в %s, выполните zfs unmount %s, переместите всё из %s в другое место, выполните zfs mount %s, затем верните всё обратно в %s, не заменяя уже имеющийся там файл: сохраните обе копии и сравните их
All community developers=Все разработчики сообщества
%s files and %s folders were movedsynced, but rsync reported errors for them Check the Mover Tuning log=%s файлов и %s папок были перемещены/синхронизированы, но rsync сообщил об ошибках при их обработке. Проверьте журнал Mover Tuning.
Allow force mover schedule to run during a parity checkrebuild=Разрешить запуск расписания принудительного перемещения во время проверки/восстановления четности
@@ -82,7 +82,7 @@ Logs parent folder for Mover Tuning plugin=Родительская папка
Low=Низкий
Maintainers=Сопровождающие
make those plugins with ❤️ and a lot of ☕=создаём эти плагины с ❤️ (и большим количеством ☕).
-mounted read-only at %s stop writes to the share, umount %s, move anything in %s aside, zfs mount %s, then move it back into %s=смонтирован только для чтения в %s: остановите запись в общий ресурс, выполните umount %s, переместите всё из %s в другое место, выполните zfs mount %s, затем верните всё обратно в %s
+mounted read-only at %s stop writes to the share, umount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there keep both copies and compare them=смонтирован только для чтения в %s: остановите запись в общий ресурс, выполните umount %s, переместите всё из %s в другое место, выполните zfs mount %s, затем верните всё обратно в %s, не заменяя уже имеющийся там файл: сохраните обе копии и сравните их
Move ALL files from current pool ignores filters and thresholds=Переместить **ВСЕ** файлы из текущего пула (независимо от фильтров и порогов)
Move ALL files to current pool ignores filters and thresholds=Переместить **ВСЕ** файлы в текущий пул (независимо от фильтров и порогов)
Move All from Primary->Secondary cacheyes shares pool percentage=Переместить всё из Основного->Вторичного (cache:yes) — процент заполнения пула шар
@@ -126,7 +126,7 @@ No log files yet=Файлов журнала пока нет
Not Applicable Share Does Not Exist Yet=Не применимо (шара ещё не существует)
Not a valid cron schedule it is not applied=Некорректное расписание cron: оно не применяется.
Notify Mover Tuning plugin actions=Уведомлять о действиях плагина Mover Tuning
-not mounted stop writes to the share, move anything in %s aside, zfs mount %s, then move it back into %s=не смонтирован: остановите запись в общий ресурс, переместите всё из %s в другое место, выполните zfs mount %s, затем верните всё обратно в %s
+not mounted stop writes to the share, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there keep both copies and compare them=не смонтирован: остановите запись в общий ресурс, переместите всё из %s в другое место, выполните zfs mount %s, затем верните всё обратно в %s, не заменяя уже имеющийся там файл: сохраните обе копии и сравните их
Oldest first=Сначала самые старые
Only move files larger than this in MB=Перемещать только файлы больше указанного размера (в МБ)
Only move files that are older than this in days=Перемещать только файлы старше указанного количества дней
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt
index 2c21a86a..36a2127b 100644
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/languages/zh_CN.txt
@@ -8,9 +8,9 @@
%s files and %s folders representing %s could not be movedsynced by Mover Tuning plugin=Mover Tuning 插件未能移动/同步 %s 个文件和 %s 个文件夹,共 %s。
%s files and %s folders were movedsynced, but rsync reported errors for them Check the Mover Tuning log=%s 个文件和 %s 个文件夹已移动/同步,但 rsync 报告了错误。请查看 Mover Tuning 日志。
Action=操作
-a file is hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=其下有文件被遮盖:停止向该共享写入,运行 zfs unmount %s,将 %s 中的所有内容移到别处,运行 zfs mount %s,然后移回 %s
-mounted again, but the look for a file written to %s as it was mounted was cut short, so one may be hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=已重新挂载,但对挂载期间写入 %s 的文件的检查被中断,其下可能有文件被遮盖:停止向该共享写入,运行 zfs unmount %s,将 %s 中的所有内容移到别处,运行 zfs mount %s,然后移回 %s
-the remount was cut short, so it may not be mounted or may hide a file stop writes to the share, if zfs mount lists it at %s run zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s=重新挂载被中断,因此它可能未挂载,或其下有文件被遮盖:停止向该共享写入,如果 zfs mount 列出它挂载在 %s,运行 zfs unmount %s,将 %s 中的所有内容移到别处,运行 zfs mount %s,然后移回 %s
+a file is hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there keep both copies and compare them=其下有文件被遮盖:停止向该共享写入,运行 zfs unmount %s,将 %s 中的所有内容移到别处,运行 zfs mount %s,然后移回 %s,不要覆盖其中已有的文件:保留两份副本并加以比较
+mounted again, but the look for a file written to %s as it was mounted was cut short, so one may be hidden under it stop writes to the share, zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there keep both copies and compare them=已重新挂载,但对挂载期间写入 %s 的文件的检查被中断,其下可能有文件被遮盖:停止向该共享写入,运行 zfs unmount %s,将 %s 中的所有内容移到别处,运行 zfs mount %s,然后移回 %s,不要覆盖其中已有的文件:保留两份副本并加以比较
+the remount was cut short, so it may not be mounted or may hide a file stop writes to the share, if zfs mount lists it at %s run zfs unmount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there keep both copies and compare them=重新挂载被中断,因此它可能未挂载,或其下有文件被遮盖:停止向该共享写入,如果 zfs mount 列出它挂载在 %s,运行 zfs unmount %s,将 %s 中的所有内容移到别处,运行 zfs mount %s,然后移回 %s,不要覆盖其中已有的文件:保留两份副本并加以比较
All community developers=所有社区开发者
Allow force mover schedule to run during a parity checkrebuild=允许强制移动计划在奇偶校验/重建期间运行
All plugin settings return to their defaults, including the Mover Tuning schedule, the forced move schedule and the cache watchdog, and the override settings of every share are deleted=所有插件设置都将恢复为默认值,包括 Mover Tuning 计划、强制移动计划和缓存看门狗,并且所有共享的覆盖设置都将被删除。
@@ -81,7 +81,7 @@ Logs parent folder for Mover Tuning plugin=日志文件保存路径
Low=低
Maintainers=维护者
make those plugins with ❤️ and a lot of ☕=用 ❤️(和很多 ☕)制作了这些插件。
-mounted read-only at %s stop writes to the share, umount %s, move anything in %s aside, zfs mount %s, then move it back into %s=以只读方式挂载于 %s:停止向该共享写入,运行 umount %s,将 %s 中的所有内容移到别处,运行 zfs mount %s,然后移回 %s
+mounted read-only at %s stop writes to the share, umount %s, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there keep both copies and compare them=以只读方式挂载于 %s:停止向该共享写入,运行 umount %s,将 %s 中的所有内容移到别处,运行 zfs mount %s,然后移回 %s,不要覆盖其中已有的文件:保留两份副本并加以比较
Move ALL files from current pool ignores filters and thresholds=从当前存储池移出**所有**文件(无视过滤条件和阈值)
Move ALL files to current pool ignores filters and thresholds=将**所有**文件移入当前存储池(无视过滤条件和阈值)
Move All from Primary->Secondary cacheyes shares pool percentage=主存储->次存储(cache:yes)共享全部移动的存储池百分比
@@ -125,7 +125,7 @@ No log files yet=暂无日志文件
Not Applicable Share Does Not Exist Yet=不适用(共享尚不存在)
Not a valid cron schedule it is not applied=无效的 cron 计划:不会生效。
Notify Mover Tuning plugin actions=通知设置
-not mounted stop writes to the share, move anything in %s aside, zfs mount %s, then move it back into %s=未挂载:停止向该共享写入,将 %s 中的所有内容移到别处,运行 zfs mount %s,然后移回 %s
+not mounted stop writes to the share, move anything in %s aside, zfs mount %s, then move it back into %s without replacing a file already there keep both copies and compare them=未挂载:停止向该共享写入,将 %s 中的所有内容移到别处,运行 zfs mount %s,然后移回 %s,不要覆盖其中已有的文件:保留两份副本并加以比较
Oldest first=最旧的优先
Only move files larger than this in MB=仅移动大于此大小的文件(MB)
Only move files that are older than this in days=仅移动早于此天数的文件(天)
diff --git a/tests/age_mover/lib.sh b/tests/age_mover/lib.sh
index 6232a155..87c651a6 100644
--- a/tests/age_mover/lib.sh
+++ b/tests/age_mover/lib.sh
@@ -186,7 +186,7 @@ DESTROYED=$(printf '%s\n' "zfs $LS cache/sh" 'zfs unmount cache/sh' 'mount -t zf
notice_for() { echo "warning|Clean empty ZFS datasets did not finish for $1. The mover log has the details unless Log Mover Tuning plugin actions is set to No."; }
NOTICE=$(notice_for '[cache/sh]')
# the notice of a cache/sh left out of view: why, and how to mount it back
-BACK='move anything in /mnt/cache/sh aside, zfs mount cache/sh, then move it back into /mnt/cache/sh'
+BACK='move anything in /mnt/cache/sh aside, zfs mount cache/sh, then move it back into /mnt/cache/sh without replacing a file already there: keep both copies and compare them'
NOT_MOUNTED=$(notice_for "[cache/sh] (not mounted: stop writes to the share, $BACK)")
HIDDEN=$(notice_for "[cache/sh] (a file is hidden under it: stop writes to the share, zfs unmount cache/sh, $BACK)")
read_only_notice() { notice_for "[cache/sh] (mounted read-only at $1: stop writes to the share, umount $1, $BACK)"; }
diff --git a/tests/age_mover/test_dataset_stops.sh b/tests/age_mover/test_dataset_stops.sh
index ca67bc23..e1d4133c 100644
--- a/tests/age_mover/test_dataset_stops.sh
+++ b/tests/age_mover/test_dataset_stops.sh
@@ -196,7 +196,7 @@ log_has 'Failed to remount dataset [cache/a]'
log_lacks 'ZFS dataset [cache/sh] holds only folders'
check "cache/sh is still mounted" /mnt/cache/sh "$(grep -x /mnt/cache/sh "$T/zfs")"
check "the share after it is not looked at" "" "$(grep -F cache/z "$T/zfs.calls")"
-notices "$(notice_for '[cache/a] (not mounted: stop writes to the share, move anything in /mnt/cache/a aside, zfs mount cache/a, then move it back into /mnt/cache/a)')"
+notices "$(notice_for '[cache/a] (not mounted: stop writes to the share, move anything in /mnt/cache/a aside, zfs mount cache/a, then move it back into /mnt/cache/a without replacing a file already there: keep both copies and compare them)')"
no_private
check "another run's pid file stays" 1 "$(cat "$T/pid" 2>/dev/null)"
rm -f "$T/pid"
From d057092a8f88d41eb96941e26304e7e7ddc29acc Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Thu, 26 Nov 2026 07:09:37 +0800
Subject: [PATCH 66/94] Ignore a second stop while the stopped run puts the
write method back
A TERM that landed after the stopped branch reset the traps ended the run,
or its mdcmd, before turbo write was set back.
---
.../emhttp/plugins/ca.mover.tuning/age_mover | 4 ++-
tests/age_mover/test_dataset_stops.sh | 34 +++++++++++++++++++
2 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index 21e70e7e..9425c61a 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -3333,13 +3333,15 @@ processTheMoves() {
# the notice's log lines come back out of the $( )
notice_lines=$(finish_on_stop dataset_problems_notice)
[ -z "$notice_lines" ] || printf '%s\n' "$notice_lines"
- trap - TERM HUP INT
if [ -n "$stopped" ]; then
+ # a second stop must not end the run, or its mdcmd, before the write method is back
+ trap '' TERM HUP INT
restore_turbo
# the plugin's stop removes these once the run has ended; a stop that signals the run alone leaves them
[ "$(cat "$PIDFILE" 2>/dev/null)" != "$$" ] || rm -f "$PIDFILE" "$MOVER_STATUS" "$PAUSEFILE" "$MOVINGFILE"
exit 0
fi
+ trap - TERM HUP INT
for top in "${TOP_FOLDERS[@]}"; do cleanTopFolder "$top"; done
if [ "$TESTMODE" != "yes" ] && [ ! -e $SOFTSTOPFILE ] && [ "$SYNCFAILED" = 0 ] &&
diff --git a/tests/age_mover/test_dataset_stops.sh b/tests/age_mover/test_dataset_stops.sh
index e1d4133c..925f9aef 100644
--- a/tests/age_mover/test_dataset_stops.sh
+++ b/tests/age_mover/test_dataset_stops.sh
@@ -91,6 +91,40 @@ cache_is sh sh/bare.txt
no_private
notices "$NOT_MOUNTED"
+# a second stop, at the read of var.ini that puts the write method back, waits for it
+begin "Clean ZFS datasets, a second stop as the stopped run puts the write method back" cleanFolders topFolder \
+ cleanDatasets yes enableTurbo yes
+one_share
+mkdir -p /usr/local/sbin /var/local/emhttp
+echo 'md_write_method="0"' >/var/local/emhttp/var.ini
+printf '#!/bin/bash\necho "mdcmd $*" >>%q\n' "$T/mdcmd.calls" >/usr/local/sbin/mdcmd
+chmod 755 /usr/local/sbin/mdcmd
+echo $$ >"$T/pid"
+cat >"$T/bin/grep" <"$T/zfs.on_mount.zfs"
+run_moves 'processTheMoves did not return'
+rm -f "$T/bin/grep"
+hash -r
+check "the second stop came" "" "$(ls "$T/stop2" 2>/dev/null)"
+check "turbo write forced, then put back" "$(printf '%s\n' 'mdcmd set md_write_method 1' 'mdcmd set md_write_method 0')" \
+ "$(cat "$T/mdcmd.calls")"
+check "the run removed its pid file" "" "$(ls "$T/pid" 2>/dev/null)"
+rm -rf /usr/local/sbin/mdcmd /var/local/emhttp "$T/mdcmd.calls"
+log_lacks 'successfully destroyed'
+no_private
+
# the plugin's stop as each step runs: the step finishes, a destroy that finished stays done, else the dataset goes back
for step in 'zfs list' 'zfs unmount' 'the read-only umount' 'zfs destroy' 'the remount'; do
begin "Clean ZFS datasets, the plugin's mover stop during $step" cleanFolders topFolder cleanDatasets yes
From de310e63f1137bc8bb0c1133b70e27fc4deea4de Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Thu, 26 Nov 2026 08:17:58 +0800
Subject: [PATCH 67/94] Say in test mode which ZFS dataset a real run would
check for deletion
Test mode skipped the dataset step without a word. It now notes the share as a
real run does and logs the dataset it would check, running no zfs command.
---
.../emhttp/plugins/ca.mover.tuning/age_mover | 13 ++++++++----
tests/age_mover/test_datasets.sh | 20 +++++++++++++++++++
2 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index b9003f27..b8a3effd 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -2575,10 +2575,10 @@ note_top_folder() {
TOP_FOLDERS+=("$top")
}
-# With Clean datasets and Clean folders on and test mode off, notes this row's pool/share and destination for
-# cleanShareDataset after the pass when the row's source is the primary; fills processTheMoves' DATASET_DEST and SHARE_DATASETS
+# With Clean datasets and Clean folders on, notes this row's pool/share and destination for cleanShareDataset after
+# the pass when the row's source is the primary; fills processTheMoves' DATASET_DEST and SHARE_DATASETS
note_share_dataset() {
- [ "$CLEANDATASETS" = "yes" ] && [ "$CLEANFOLDERS" != "no" ] && [ "$TESTMODE" = "no" ] &&
+ [ "$CLEANDATASETS" = "yes" ] && [ "$CLEANFOLDERS" != "no" ] &&
[ "$SOURCE" = "/mnt/$PRIMARYSTORAGENAME" ] || return 0
local ds="$PRIMARYSTORAGENAME/$SHARENAME"
[ -n "${DATASET_DEST[$ds]+x}" ] && return 0
@@ -2800,7 +2800,8 @@ unmount_check_destroy() {
}
# Destroys dataset $1/$2 if it is mounted at /mnt/$1/$2, has no children or snapshots, and dataset_loses against $3/$2
-# is empty both before the unmount and after it; else keeps it, and the log says when it stays unmounted
+# is empty both before the unmount and after it; else keeps it, and the log says when it stays unmounted. Test mode
+# runs no zfs command: it says the dataset would be checked
cleanShareDataset() {
local folder="/mnt/$1/$2" dataset="$1/$2" mounted names lost private
mounted=$(zfs_dataset_at "$folder")
@@ -2809,6 +2810,10 @@ cleanShareDataset() {
mvDebuglogger "Keeping the ZFS dataset mounted at $(qp "$folder"): it is not ${dataset}" "Clean Dataset"
return 0
fi
+ if [ "$TESTMODE" != "no" ]; then
+ mvlogger "TEST MODE: Would check ZFS dataset [${dataset}] for deletion"
+ return 0
+ fi
# listed first, so between the content check and the unmount only a log line is written
if ! names=$(finish_on_stop zfs list -r -H -t filesystem,volume,snapshot -o name "$dataset" 2>&1); then
mvlogger "ZFS dataset [${dataset}] could not be listed, will not delete: $(zfs_reason "$names")"
diff --git a/tests/age_mover/test_datasets.sh b/tests/age_mover/test_datasets.sh
index de4f95c5..2f214840 100644
--- a/tests/age_mover/test_datasets.sh
+++ b/tests/age_mover/test_datasets.sh
@@ -312,8 +312,28 @@ rm /mnt/cache/sh/f.txt
run_moves
check "no zfs calls" "" "$(cat "$T/zfs.calls" 2>/dev/null)"
cache_is sh
+log_has 'TEST MODE: Would check ZFS dataset [cache/sh] for deletion'
log_has 'Skipping deletion of ZFS dataset mountpoint: /mnt/cache/sh'
+# test mode says it would check the dataset a real run would, and runs no zfs command
+begin "Clean ZFS datasets in test mode, the share's last file would move" cleanFolders topFolder cleanDatasets yes testmode yes
+mk cache sh/only/f.txt
+printf '%s\n' /mnt/cache /mnt/cache/sh >"$T/zfs"
+row 'move from primary' f sh/only/f.txt | list
+run_moves
+check "no zfs calls" "" "$(cat "$T/zfs.calls" 2>/dev/null)"
+cache_is sh sh/only sh/only/f.txt
+log_has 'TEST MODE: Would check ZFS dataset [cache/sh] for deletion'
+
+begin "Clean ZFS datasets in test mode, the share a plain folder on a ZFS pool" cleanFolders topFolder cleanDatasets yes \
+ testmode yes
+mk cache sh/only/f.txt
+echo /mnt/cache >"$T/zfs"
+row 'move from primary' f sh/only/f.txt | list
+run_moves
+check "no zfs calls" "" "$(cat "$T/zfs.calls" 2>/dev/null)"
+log_lacks 'Would check ZFS dataset'
+
for pool in 'not ZFS' 'ZFS, the share a plain folder on it'; do
begin "Clean ZFS datasets, a share that empties on a pool that is $pool" cleanFolders topFolder cleanDatasets yes
mk cache sh/only/f.txt
From 9b625783761f4a9c88e60648f674df42253cf2b4 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Thu, 26 Nov 2026 08:34:41 +0800
Subject: [PATCH 68/94] Let the second-stop test's TERM reach mdcmd, as the
plugin's stop does
It signalled the run alone, so the stopped branch's ignore, which mdcmd
inherits, had no check that failed without it.
---
tests/age_mover/test_dataset_stops.sh | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/tests/age_mover/test_dataset_stops.sh b/tests/age_mover/test_dataset_stops.sh
index a2fd10c9..aeea578c 100644
--- a/tests/age_mover/test_dataset_stops.sh
+++ b/tests/age_mover/test_dataset_stops.sh
@@ -74,32 +74,27 @@ cache_is sh sh/bare.txt
no_private
notices "$NOT_MOUNTED"
-# a second stop, at the read of var.ini that puts the write method back, waits for it
+# a second stop that signals every process, as the plugin's does, reaches the run and the mdcmd that puts the write
+# method back: both wait for it
begin "Clean ZFS datasets, a second stop as the stopped run puts the write method back" cleanFolders topFolder \
cleanDatasets yes enableTurbo yes
one_share
mkdir -p /usr/local/sbin /var/local/emhttp
echo 'md_write_method="0"' >/var/local/emhttp/var.ini
-printf '#!/bin/bash\necho "mdcmd $*" >>%q\n' "$T/mdcmd.calls" >/usr/local/sbin/mdcmd
-chmod 755 /usr/local/sbin/mdcmd
-echo $$ >"$T/pid"
-cat >"$T/bin/grep" </usr/local/sbin/mdcmd <>$T/mdcmd.calls
EOF
-chmod 755 "$T/bin/grep"
-# the run is a subshell of this script: it would keep the grep this script found before
-hash -r
+chmod 755 /usr/local/sbin/mdcmd
+echo $$ >"$T/pid"
{ stop_hook run; echo "touch $T/stop2"; } >"$T/zfs.on_mount.zfs"
run_moves 'processTheMoves did not return'
-rm -f "$T/bin/grep"
-hash -r
check "the second stop came" "" "$(ls "$T/stop2" 2>/dev/null)"
check "turbo write forced, then put back" "$(printf '%s\n' 'mdcmd set md_write_method 1' 'mdcmd set md_write_method 0')" \
"$(cat "$T/mdcmd.calls")"
From e7d5b1cfd554714b562b4f2fd31807d63823f840 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Thu, 26 Nov 2026 09:05:51 +0800
Subject: [PATCH 69/94] Test a missing middle name among four rows in both
modes
---
tests/age_mover/test_folders.sh | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/tests/age_mover/test_folders.sh b/tests/age_mover/test_folders.sh
index a71a6ab2..31564c9f 100644
--- a/tests/age_mover/test_folders.sh
+++ b/tests/age_mover/test_folders.sh
@@ -347,6 +347,18 @@ same_in_test_mode "topFolder, a row's file gone before the run, in a folder an e
'Deleted empty folder: /mnt/cache/sh/d' 'Not deleting top-level folder: contains 1 file(s), 0 subfolder(s): /mnt/cache/sh')" \
one_name_gone cleanFolders topFolder
+# the gone name's recount takes the count back to the two still on the source; the later rows lower it to 0
+middle_name_gone() {
+ mk cache sh/d/a.txt sh/d/b.txt sh/d/c.txt sh/d/d.txt sh/keep.txt
+ for f in a b c d; do row 'move from primary' f "sh/d/$f.txt"; done | list
+ rm /mnt/cache/sh/d/b.txt
+}
+same_in_test_mode "topFolder, the middle one of four rows in one folder gone before the run" "$(printf '%s\n' \
+ 'Not deleting folder containing 2 files: /mnt/cache/sh/d' 'Not deleting folder containing 2 files: /mnt/cache/sh/d' \
+ 'Not deleting folder containing 1 files: /mnt/cache/sh/d' 'Deleted empty folder: /mnt/cache/sh/d' \
+ 'Not deleting top-level folder: contains 1 file(s), 0 subfolder(s): /mnt/cache/sh')" middle_name_gone \
+ cleanFolders topFolder
+
nested_file() {
mk cache sh/p/q/f.txt
row 'move from primary' f sh/p/q/f.txt | list
From 8553c5fb0ede3df617c2f1ba06b67d05201adf44 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Thu, 26 Nov 2026 09:15:56 +0800
Subject: [PATCH 70/94] Say what the missing-name case's recount keeps
---
tests/age_mover/test_folders.sh | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tests/age_mover/test_folders.sh b/tests/age_mover/test_folders.sh
index 31564c9f..761bb827 100644
--- a/tests/age_mover/test_folders.sh
+++ b/tests/age_mover/test_folders.sh
@@ -347,7 +347,8 @@ same_in_test_mode "topFolder, a row's file gone before the run, in a folder an e
'Deleted empty folder: /mnt/cache/sh/d' 'Not deleting top-level folder: contains 1 file(s), 0 subfolder(s): /mnt/cache/sh')" \
one_name_gone cleanFolders topFolder
-# the gone name's recount takes the count back to the two still on the source; the later rows lower it to 0
+# the gone name's recount keeps the count at the two still on the source, where lowering it would give 1; the later
+# rows lower it to 0
middle_name_gone() {
mk cache sh/d/a.txt sh/d/b.txt sh/d/c.txt sh/d/d.txt sh/keep.txt
for f in a b c d; do row 'move from primary' f "sh/d/$f.txt"; done | list
From 893dcec0433caafcbd9e3bda0655924373c167a3 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Thu, 26 Nov 2026 10:28:52 +0800
Subject: [PATCH 71/94] Let test mode keep a folder rmdir would refuse
A folder row that is a ZFS mountpoint, and a walked or top folder that
holds only a symlink, were predicted deleted where a real run keeps them.
would_rmdir now decides at all four test-mode sites; the tests' rmdir
stand-in refuses every ZFS mountpoint, as Linux does.
---
.../emhttp/plugins/ca.mover.tuning/age_mover | 23 +++++++++----
tests/age_mover/lib.sh | 2 +-
tests/age_mover/test_folders.sh | 32 +++++++++++++++++++
3 files changed, 50 insertions(+), 7 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index b8a3effd..6fae2e09 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -2565,6 +2565,9 @@ count_left() {
echo "$n"
}
+# Whether a real run's rmdir would take folder $1: nothing left in it, as count_left sees, and nothing mounted on it
+would_rmdir() { [ "$(count_left "$1" -mindepth 1 -maxdepth 1)" = 0 ] && ! is_zfs_dataset_mountpoint "$1"; }
+
# In topFolder mode, notes this row's share top folder for the check after the pass; fills processTheMoves' TOP_SEEN
# and TOP_FOLDERS
note_top_folder() {
@@ -2616,7 +2619,11 @@ cleanTopFolder() {
elif [ "$dataset" = yes ]; then
mvlogger "Skipping deletion of ZFS dataset mountpoint: $top_folder"
elif [ "$TESTMODE" != "no" ]; then
- mvlogger "TEST MODE: Would delete empty top-level folder: $top_folder"
+ if would_rmdir "$top_folder"; then
+ mvlogger "TEST MODE: Would delete empty top-level folder: $top_folder"
+ else
+ mvDebuglogger "TEST MODE: Would fail to delete top-level folder (not empty): $top_folder" "Clean Top Folder"
+ fi
elif rmdir "$top_folder" 2>/dev/null; then
mvlogger "Deleted empty top-level folder: $top_folder"
else
@@ -3106,12 +3113,12 @@ processTheMoves() {
fi
fi
copyWatchStop
- # test mode notes what a real move takes off the source: every file, and with Unraid's move a folder that
- # holds nothing, as move leaves one that does
+ # test mode notes what a real move takes off the source: every file, and with Unraid's move a folder
+ # its rmdir would take, as move leaves any other
if [ "$TESTMODE" = "yes" ] && [[ "$ACTION" =~ "move" ]] && { [ "$FILETYPE" = "f" ] || [ "$MOVE_FILES_TOOL" = "move" ]; }; then
for f in "${present[@]}"; do
f=${f//\/.\//\/}
- [ "$FILETYPE" = "f" ] || [ "$(count_left "$f" -mindepth 1 -maxdepth 1)" = 0 ] && TEST_GONE[$f]=1
+ [ "$FILETYPE" = "f" ] || would_rmdir "$f" && TEST_GONE[$f]=1
done
fi
@@ -3222,7 +3229,7 @@ processTheMoves() {
mvlogger "Skipping deletion of ZFS dataset mountpoint: ${DIR}"
# test mode asks what rmdir would: anything left in the folder keeps it
elif [ "$TESTMODE" = "yes" ]; then
- if [ "$(count_left "$DIR" -mindepth 1 -maxdepth 1)" = 0 ]; then
+ if would_rmdir "$DIR"; then
TEST_GONE[$DIR]=1
mvlogger "TEST MODE: Would delete empty folder: ${DIR}"
else
@@ -3293,9 +3300,13 @@ processTheMoves() {
mvDebuglogger "Failed to delete moved folder (may not be empty): ${DIR}" "Clean Empty Moved Folder"
break
fi
- else
+ # test mode asks what rmdir would: anything left in the folder, such as a symlink, keeps it
+ elif would_rmdir "$DIR"; then
TEST_GONE[$DIR]=1
mvlogger "TEST MODE: Would delete moved empty folder: ${DIR}"
+ else
+ mvDebuglogger "TEST MODE: Would fail to delete moved folder (not empty): ${DIR}" "Clean Empty Moved Folder"
+ break
fi
chain_emptied=1
diff --git a/tests/age_mover/lib.sh b/tests/age_mover/lib.sh
index 87c651a6..e14b1762 100644
--- a/tests/age_mover/lib.sh
+++ b/tests/age_mover/lib.sh
@@ -169,7 +169,7 @@ EOF
# as Linux does, rmdir refuses a folder something is mounted on
cat >"$T/bin/rmdir" <<'EOF'
#!/bin/bash
-if [ -n "$(awk -F'\t' -v p="${*: -1}" '$1 == p' "${0%/bin/rmdir}/zfs.private" 2>/dev/null)" ]; then
+if [ -n "$(cat "${0%/bin/rmdir}/zfs" "${0%/bin/rmdir}/zfs.private" 2>/dev/null | awk -F'\t' -v p="${*: -1}" '$1 == p')" ]; then
echo "rmdir: failed to remove '${*: -1}': Device or resource busy" >&2
exit 1
fi
diff --git a/tests/age_mover/test_folders.sh b/tests/age_mover/test_folders.sh
index 761bb827..e51988ed 100644
--- a/tests/age_mover/test_folders.sh
+++ b/tests/age_mover/test_folders.sh
@@ -384,6 +384,16 @@ dataset_top() {
same_in_test_mode "topFolder, the top folder is a ZFS dataset mountpoint" "$(printf '%s\n' \
'Deleted empty folder: /mnt/cache/sh/only' 'Skipping deletion of ZFS dataset mountpoint: /mnt/cache/sh')" dataset_top cleanFolders topFolder
+# no file or folder is left in the top folder, but rmdir refuses it for the symlink
+top_symlink() {
+ mk cache sh/only/f.txt
+ ln -s gone /mnt/cache/sh/link
+ row 'move from primary' f sh/only/f.txt | list
+}
+same_in_test_mode "topFolder, the top folder keeps only a symlink" 'Deleted empty folder: /mnt/cache/sh/only' top_symlink \
+ cleanFolders topFolder
+[ "${AGE_MOVER_DEBUG:-0}" != 2 ] || dlog_has 'TEST MODE: Would fail to delete top-level folder (not empty): /mnt/cache/sh'
+
# Unraid's move takes the folder itself; with rsync the walk deletes it
one_empty_folder() {
mkdir -p /mnt/cache/sh/e
@@ -406,6 +416,28 @@ for tool in rsync move; do
dlog_has '"/mnt/cache/sh/p/e" would be gone from the source: the walk starts at its parent "/mnt/cache/sh/p"'
done
+# rmdir, in move or the walk, refuses a folder a dataset is mounted on, and one that holds a symlink
+empty_mountpoint_row() {
+ mkdir -p /mnt/cache/sh/p/e
+ echo /mnt/cache/sh/p/e >"$T/zfs"
+ row 'move from primary' d sh/p/e | list
+}
+symlink_beside_row() {
+ mkdir -p /mnt/cache/sh/g/p/e
+ ln -s gone /mnt/cache/sh/g/p/link
+ row 'move from primary' d sh/g/p/e | list
+}
+for tool in rsync move; do
+ same_in_test_mode "topFolder, a folder row that is an empty ZFS dataset mountpoint ($tool)" \
+ 'Skipping deletion of ZFS dataset mountpoint: /mnt/cache/sh/p/e' empty_mountpoint_row cleanFolders topFolder \
+ movefilesTool "$tool"
+ want=""
+ [ "$tool" = move ] || want='Deleted empty moved folder: /mnt/cache/sh/g/p/e'
+ same_in_test_mode "topFolder, a folder row whose parent holds a symlink ($tool)" "$want" symlink_beside_row \
+ cleanFolders topFolder movefilesTool "$tool"
+ [ "${AGE_MOVER_DEBUG:-0}" != 2 ] || dlog_has 'TEST MODE: Would fail to delete moved folder (not empty): /mnt/cache/sh/g/p'
+done
+
# the second folder row's folder is gone before its turn, and the first row's walk deleted its parent
folder_rows_one_gone() {
mkdir -p /mnt/cache/sh/p/e /mnt/cache/sh/p/g
From 8c8f4ae327d7e305190780e3cb231d14c3cfe9e2 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Thu, 26 Nov 2026 10:29:40 +0800
Subject: [PATCH 72/94] Say would_rmdir checks ZFS mounts only
---
.../usr/local/emhttp/plugins/ca.mover.tuning/age_mover | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index 6fae2e09..908f5f70 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -2565,7 +2565,7 @@ count_left() {
echo "$n"
}
-# Whether a real run's rmdir would take folder $1: nothing left in it, as count_left sees, and nothing mounted on it
+# Whether a real run's rmdir would take folder $1: nothing left in it, as count_left sees, and no ZFS dataset mounted on it
would_rmdir() { [ "$(count_left "$1" -mindepth 1 -maxdepth 1)" = 0 ] && ! is_zfs_dataset_mountpoint "$1"; }
# In topFolder mode, notes this row's share top folder for the check after the pass; fills processTheMoves' TOP_SEEN
From 5336e0a71305b1fdbb0397cec6d5b14989436438 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Thu, 26 Nov 2026 11:23:40 +0800
Subject: [PATCH 73/94] Let the stop skip a process that ended since it was
listed
killtree signals children first, so a parent often exits before its own
kill, which then printed "No such process" with the stop's output.
---
.../emhttp/plugins/ca.mover.tuning/age_mover | 4 ++--
tests/age_mover/test_stops.sh | 18 ++++++++++++++++++
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index a7bd7e4d..d48292db 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -3701,8 +3701,8 @@ killtree() {
for child in $(pgrep --ns $$ -P $pid); do
killtree $child
done
- # a paused copy acts on the TERM only once it runs again
- [ $pid -ne $$ ] && kill -TERM $pid && kill -CONT "$pid"
+ # a paused copy acts on the TERM only once it runs again; one that ended since pgrep listed it needs none
+ [ $pid -ne $$ ] && kill -TERM $pid 2>/dev/null && kill -CONT "$pid"
}
# Caution: stopping mover like this can lead to partial files on the destination
diff --git a/tests/age_mover/test_stops.sh b/tests/age_mover/test_stops.sh
index dbc84825..065a50ae 100644
--- a/tests/age_mover/test_stops.sh
+++ b/tests/age_mover/test_stops.sh
@@ -196,4 +196,22 @@ for now in 'auto Auto (read/modify/write)' ' Read/modify/write'; do
array_is sh sh/s sh/s/1.txt
done
+# a process pgrep lists can end before its signal; a pid no process can have stands for it, so no real one is signalled
+begin "the plugin's stop, a listed process gone before its signal"
+real_pgrep=$(command -v pgrep)
+# the container's init, not this script, reaps it: a zombie would still answer the stop's kill -0
+(bash -c 'sleep 30; exit 0' & echo $! >"$T/run.pid")
+run=$(cat "$T/run.pid")
+gone=$(($(cat /proc/sys/kernel/pid_max) + 1))
+printf '#!/bin/bash\n%q "$@"\n[ "${*: -1}" != %q ] || echo %q\n' "$real_pgrep" "$run" "$gone" >"$T/bin/pgrep"
+chmod 755 "$T/bin/pgrep"
+hash -r
+echo "$run" >"$T/pid"
+check "the stop said only that it stopped" 'mover: stopped' \
+ "$(PIDFILE=$T/pid MOVER_STATUS=$T/mover.ini PAUSEFILE=$T/pause MOVINGFILE=$T/moving; stop 2>&1)"
+rm -f "$T/bin/pgrep"
+hash -r
+check "the run ended" "" "$(kill -0 "$run" 2>/dev/null && echo running)"
+check "the stop removed the pid file" "" "$(ls "$T/pid" 2>/dev/null)"
+
finish
From 6c39cbba3577848b3bc23f364d9a73d9aa3d6555 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Thu, 26 Nov 2026 11:36:11 +0800
Subject: [PATCH 74/94] Mark the stop case's stand-in quoting and the variables
stop reads for ShellCheck
---
tests/age_mover/test_stops.sh | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tests/age_mover/test_stops.sh b/tests/age_mover/test_stops.sh
index 065a50ae..8df0b8da 100644
--- a/tests/age_mover/test_stops.sh
+++ b/tests/age_mover/test_stops.sh
@@ -203,10 +203,12 @@ real_pgrep=$(command -v pgrep)
(bash -c 'sleep 30; exit 0' & echo $! >"$T/run.pid")
run=$(cat "$T/run.pid")
gone=$(($(cat /proc/sys/kernel/pid_max) + 1))
+# shellcheck disable=SC2016 # the stand-in expands its own $@ and $*
printf '#!/bin/bash\n%q "$@"\n[ "${*: -1}" != %q ] || echo %q\n' "$real_pgrep" "$run" "$gone" >"$T/bin/pgrep"
chmod 755 "$T/bin/pgrep"
hash -r
echo "$run" >"$T/pid"
+# shellcheck disable=SC2034 # stop, from funcs.sh, reads them
check "the stop said only that it stopped" 'mover: stopped' \
"$(PIDFILE=$T/pid MOVER_STATUS=$T/mover.ini PAUSEFILE=$T/pause MOVINGFILE=$T/moving; stop 2>&1)"
rm -f "$T/bin/pgrep"
From c33541d5810244994b71a6eeb7e71c3817df7632 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Thu, 26 Nov 2026 11:54:35 +0800
Subject: [PATCH 75/94] Reap the stop case's run in the test script, as CI's
container has no init to
---
tests/age_mover/test_stops.sh | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/tests/age_mover/test_stops.sh b/tests/age_mover/test_stops.sh
index 8df0b8da..7cfb65db 100644
--- a/tests/age_mover/test_stops.sh
+++ b/tests/age_mover/test_stops.sh
@@ -199,9 +199,9 @@ done
# a process pgrep lists can end before its signal; a pid no process can have stands for it, so no real one is signalled
begin "the plugin's stop, a listed process gone before its signal"
real_pgrep=$(command -v pgrep)
-# the container's init, not this script, reaps it: a zombie would still answer the stop's kill -0
-(bash -c 'sleep 30; exit 0' & echo $! >"$T/run.pid")
-run=$(cat "$T/run.pid")
+# this script waits on the run, so it is reaped as it ends: one nobody reaps would still answer the stop's kill -0
+bash -c 'sleep 30 && exit 3' &
+run=$!
gone=$(($(cat /proc/sys/kernel/pid_max) + 1))
# shellcheck disable=SC2016 # the stand-in expands its own $@ and $*
printf '#!/bin/bash\n%q "$@"\n[ "${*: -1}" != %q ] || echo %q\n' "$real_pgrep" "$run" "$gone" >"$T/bin/pgrep"
@@ -209,11 +209,15 @@ chmod 755 "$T/bin/pgrep"
hash -r
echo "$run" >"$T/pid"
# shellcheck disable=SC2034 # stop, from funcs.sh, reads them
-check "the stop said only that it stopped" 'mover: stopped' \
- "$(PIDFILE=$T/pid MOVER_STATUS=$T/mover.ini PAUSEFILE=$T/pause MOVINGFILE=$T/moving; stop 2>&1)"
+(PIDFILE=$T/pid MOVER_STATUS=$T/mover.ini PAUSEFILE=$T/pause MOVINGFILE=$T/moving; stop) >"$T/stop.out" 2>&1 &
+stopper=$!
+wait "$run"
+check "the stop ended the run" 143 "$?"
+wait "$stopper"
rm -f "$T/bin/pgrep"
hash -r
-check "the run ended" "" "$(kill -0 "$run" 2>/dev/null && echo running)"
+check "the stop said only that it stopped" 'mover: stopped' "$(cat "$T/stop.out")"
check "the stop removed the pid file" "" "$(ls "$T/pid" 2>/dev/null)"
+rm -f "$T/stop.out"
finish
From 0f65becca3446e2314f1209966c5bdb0d8d71aae Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Thu, 26 Nov 2026 12:56:53 +0800
Subject: [PATCH 76/94] Keep the turbo restore armed until mdcmd sets the write
method back
The plugin's stop signals mdcmd before the run, so mdcmd can end before
it sets the write method back; the EXIT trap now stays set and tries
again. A failed force or restore is logged, and the stop's CONT no
longer reports a process that ended after its TERM.
---
.../emhttp/plugins/ca.mover.tuning/age_mover | 14 +++--
tests/age_mover/test_stops.sh | 53 +++++++++++++++++--
2 files changed, 58 insertions(+), 9 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index e9ac26f8..eb538317 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -3438,11 +3438,11 @@ force_turbo() {
# waits for it; a KILL cannot
trap 'trap "" HUP INT TERM; restore_turbo' EXIT
mvlogger "Forcing turbo write on"
- /usr/local/sbin/mdcmd set md_write_method 1
+ /usr/local/sbin/mdcmd set md_write_method 1 || mvlogger "Could not force turbo write on: mdcmd exited $?"
}
# Sets the write method back after force_turbo, where the run ends or from the EXIT trap of a run a signal ends sooner;
-# it clears the trap
+# it clears the trap, in a real run only once mdcmd has set it back
restore_turbo() {
local m name
[ -n "$TURBO_WAS" ] || return 0
@@ -3457,7 +3457,11 @@ restore_turbo() {
mvlogger "TEST MODE: Would restore original turbo write mode $name"
else
mvlogger "Restoring original turbo write mode $name"
- /usr/local/sbin/mdcmd set md_write_method "$m"
+ # the plugin's stop signals mdcmd before the run: one it ends first leaves the EXIT trap to try again
+ /usr/local/sbin/mdcmd set md_write_method "$m" || {
+ mvlogger "Could not restore original turbo write mode $name: mdcmd exited $?"
+ return 1
+ }
fi
TURBO_WAS=""
trap - EXIT
@@ -3747,8 +3751,8 @@ killtree() {
for child in $(pgrep --ns $$ -P $pid); do
killtree $child
done
- # a paused copy acts on the TERM only once it runs again; one that ended since pgrep listed it needs none
- [ $pid -ne $$ ] && kill -TERM $pid 2>/dev/null && kill -CONT "$pid"
+ # a paused copy acts on the TERM only once it runs again; a process can end before either signal reaches it
+ [ $pid -ne $$ ] && kill -TERM $pid 2>/dev/null && kill -CONT "$pid" 2>/dev/null
}
# Caution: stopping mover like this can lead to partial files on the destination
diff --git a/tests/age_mover/test_stops.sh b/tests/age_mover/test_stops.sh
index 7cfb65db..465ee831 100644
--- a/tests/age_mover/test_stops.sh
+++ b/tests/age_mover/test_stops.sh
@@ -154,6 +154,42 @@ put_back_once
array_is sh sh/s sh/s/1.txt
cache_is sh sh/s sh/s/2.txt
+# the plugin's stop signals mdcmd before the run, so mdcmd can end before it sets the write method back (143 here): the
+# run keeps its EXIT trap and tries again as it ends
+begin "turbo write on, mdcmd fails as the run puts the write method back" enableTurbo yes
+mk cache sh/s/1.txt
+row 'move from primary' f sh/s/1.txt | list
+turbo_standin
+touch "$T/fail_once"
+cat >/usr/local/sbin/mdcmd <>$T/mdcmd.calls
+EOF
+run_moves
+check "turbo write forced, then put back as the run ended" "$(printf '%s\n' 'mdcmd set md_write_method 1' \
+ 'mdcmd set md_write_method 0')" "$(cat "$T/mdcmd.calls")"
+log_count 1 'Could not restore original turbo write mode Read/modify/write: mdcmd exited 143'
+log_count 2 'Restoring original turbo write mode Read/modify/write'
+rm -rf /usr/local/sbin/mdcmd /var/local/emhttp "$T/mdcmd.calls"
+array_is sh sh/s sh/s/1.txt
+
+begin "turbo write on, mdcmd fails to force it" enableTurbo yes
+mk cache sh/s/1.txt
+row 'move from primary' f sh/s/1.txt | list
+turbo_standin
+cat >/usr/local/sbin/mdcmd <>$T/mdcmd.calls
+EOF
+run_moves
+check "the write method was set back as it was" 'mdcmd set md_write_method 0' "$(cat "$T/mdcmd.calls")"
+log_count 1 'Could not force turbo write on: mdcmd exited 1'
+log_count 1 'Restoring original turbo write mode Read/modify/write'
+rm -rf /usr/local/sbin/mdcmd /var/local/emhttp "$T/mdcmd.calls"
+array_is sh sh/s sh/s/1.txt
+
begin "turbo write on, var.ini gives no write method" enableTurbo yes
mk cache sh/s/1.txt
row 'move from primary' f sh/s/1.txt | list
@@ -196,8 +232,9 @@ for now in 'auto Auto (read/modify/write)' ' Read/modify/write'; do
array_is sh sh/s sh/s/1.txt
done
-# a process pgrep lists can end before its signal; a pid no process can have stands for it, so no real one is signalled
-begin "the plugin's stop, a listed process gone before its signal"
+# a process pgrep lists can end before its TERM, or between its TERM and CONT: a pid no process can have stands for the
+# first, so no real one is signalled, and a kill that waits after each TERM until its process has gone for the second
+begin "the plugin's stop, listed processes that end before or between its signals"
real_pgrep=$(command -v pgrep)
# this script waits on the run, so it is reaped as it ends: one nobody reaps would still answer the stop's kill -0
bash -c 'sleep 30 && exit 3' &
@@ -208,8 +245,16 @@ printf '#!/bin/bash\n%q "$@"\n[ "${*: -1}" != %q ] || echo %q\n' "$real_pgrep" "
chmod 755 "$T/bin/pgrep"
hash -r
echo "$run" >"$T/pid"
-# shellcheck disable=SC2034 # stop, from funcs.sh, reads them
-(PIDFILE=$T/pid MOVER_STATUS=$T/mover.ini PAUSEFILE=$T/pause MOVINGFILE=$T/moving; stop) >"$T/stop.out" 2>&1 &
+# shellcheck disable=SC2034,SC2329 # stop, from funcs.sh, reads the variables and calls kill
+(
+ kill() {
+ builtin kill "$@" || return
+ [ "$1" = -TERM ] || return 0
+ for _ in $(seq 50); do builtin kill -0 "$2" 2>/dev/null || return 0; sleep 0.1; done
+ }
+ PIDFILE=$T/pid MOVER_STATUS=$T/mover.ini PAUSEFILE=$T/pause MOVINGFILE=$T/moving
+ stop
+) >"$T/stop.out" 2>&1 &
stopper=$!
wait "$run"
check "the stop ended the run" 143 "$?"
From e441cb4ee7d1ca711a95627e5fc4042e10fdb704 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Thu, 26 Nov 2026 13:08:02 +0800
Subject: [PATCH 77/94] Keep share_mover's turbo restore armed until mdcmd sets
it back
The plugin's stop signals mdcmd before share_mover, so mdcmd can end
before it sets the write method back; the EXIT trap now stays set and
tries again. A failed force or restore is logged.
---
.../plugins/ca.mover.tuning/share_mover | 10 ++++--
tests/age_mover/test_share_mover.sh | 33 +++++++++++++++++++
2 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover
index 8e931464..c0f96e07 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover
@@ -174,11 +174,11 @@ force_turbo() {
# stop waits for it; a KILL cannot
trap 'trap "" HUP INT TERM; restore_turbo; pid_cleanup' EXIT
mvlogger "Forcing turbo write on"
- /usr/local/sbin/mdcmd set md_write_method 1
+ /usr/local/sbin/mdcmd set md_write_method 1 || mvlogger "Could not force turbo write on: mdcmd exited $?"
}
# Sets the write method back after force_turbo, where the moves end or from the EXIT trap of a run a signal ends sooner;
-# the EXIT trap goes back to pid_cleanup alone
+# the EXIT trap goes back to pid_cleanup alone, in a real run only once mdcmd has set it back
restore_turbo() {
local m name
[ -n "$TURBO_WAS" ] || return 0
@@ -193,7 +193,11 @@ restore_turbo() {
mvlogger "TEST MODE: Would restore original turbo write mode $name"
else
mvlogger "Restoring original turbo write mode $name"
- /usr/local/sbin/mdcmd set md_write_method "$m"
+ # the plugin's stop signals mdcmd before the run: one it ends first leaves the EXIT trap to try again
+ /usr/local/sbin/mdcmd set md_write_method "$m" || {
+ mvlogger "Could not restore original turbo write mode $name: mdcmd exited $?"
+ return 1
+ }
fi
TURBO_WAS=""
trap pid_cleanup EXIT
diff --git a/tests/age_mover/test_share_mover.sh b/tests/age_mover/test_share_mover.sh
index 81e68f7a..eee1805e 100644
--- a/tests/age_mover/test_share_mover.sh
+++ b/tests/age_mover/test_share_mover.sh
@@ -221,6 +221,39 @@ cat >/usr/local/sbin/mdcmd <>$T/mdcmd.calls
EOF
+# the plugin's stop signals mdcmd before the run, so mdcmd can end before it sets the write method back (143 here): the
+# run keeps its EXIT trap and tries again as it ends
+share 'turbo on, mdcmd fails as the run puts the write method back' yes enableTurbo yes
+mk cache sh/a.txt
+touch "$T/fail_once"
+cat >/usr/local/sbin/mdcmd <>$T/mdcmd.calls
+EOF
+run 0
+mdcmd_calls 'set md_write_method 1' 'set md_write_method auto'
+log_count 1 'Could not restore original turbo write mode Auto (read/modify/write): mdcmd exited 143'
+log_count 2 'Restoring original turbo write mode Auto (read/modify/write)'
+array_is sh sh/a.txt
+
+share 'turbo on, mdcmd fails to force it' yes enableTurbo yes
+mk cache sh/a.txt
+cat >/usr/local/sbin/mdcmd <>$T/mdcmd.calls
+EOF
+run 0
+mdcmd_calls 'set md_write_method auto'
+log_count 1 'Could not force turbo write on: mdcmd exited 1'
+log_count 1 'Restoring original turbo write mode Auto (read/modify/write)'
+array_is sh sh/a.txt
+cat >/usr/local/sbin/mdcmd <>$T/mdcmd.calls
+EOF
+
# a share name with shell in it is a name: the run moves its files and runs nothing
share 'a share name that holds a command' yes
# shellcheck disable=SC2016 # the name holds shell text on purpose
From 6be8f184ea0cfbdd031da6cc820689dcdaf2d6c9 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Thu, 26 Nov 2026 13:33:42 +0800
Subject: [PATCH 78/94] Make the last turbo restore before the run removes its
pid file
A restore that failed left the EXIT trap to try again after the stopped
branch, or start()'s cleanup, had removed the pid file, so it could undo
the turbo write a run started meanwhile had forced. last_restore_turbo
tries before the pid file goes and then clears the trap.
---
.../emhttp/plugins/ca.mover.tuning/age_mover | 10 +++++---
tests/age_mover/test_dataset_stops.sh | 23 +++++++++++++++++++
2 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
index eb538317..a2455cae 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/age_mover
@@ -3377,10 +3377,9 @@ processTheMoves() {
notice_lines=$(finish_on_stop dataset_problems_notice)
[ -z "$notice_lines" ] || printf '%s\n' "$notice_lines"
if [ -n "$stopped" ]; then
- # before the pid file goes, as a run that starts once it has gone may force turbo write again; a second stop must
- # not end the run, or its mdcmd, first
+ # a second stop must not end the run, or its mdcmd, before the pid file goes
trap '' TERM HUP INT
- restore_turbo
+ last_restore_turbo
# the plugin's stop removes these once the run has ended; a stop that signals the run alone leaves them
[ "$(cat "$PIDFILE" 2>/dev/null)" != "$$" ] || rm -f "$PIDFILE" "$MOVER_STATUS" "$PAUSEFILE" "$MOVINGFILE"
exit 0
@@ -3467,6 +3466,10 @@ restore_turbo() {
trap - EXIT
}
+# The last try, before the run removes its pid file: a run that starts after may force turbo write, which a later try
+# would undo
+last_restore_turbo() { restore_turbo || trap - EXIT; }
+
# The settings pages cannot offer this combination, so it only arrives by saving a
# lower moving threshold while the old freeing value is still selected.
warn_freeing_above_moving() {
@@ -3641,6 +3644,7 @@ start() {
mvDebuglogger "Reset run-once settings completed" "run-once settings END"
+ last_restore_turbo
mvlogger "Cleaning lock and stop files"
for file in $PIDFILE $SOFTSTOPFILE $MOVER_STATUS $PAUSEFILE $MOVINGFILE; do
[[ -e "$file" ]] && rm -f "$file"
diff --git a/tests/age_mover/test_dataset_stops.sh b/tests/age_mover/test_dataset_stops.sh
index aeea578c..b7385794 100644
--- a/tests/age_mover/test_dataset_stops.sh
+++ b/tests/age_mover/test_dataset_stops.sh
@@ -74,6 +74,29 @@ cache_is sh sh/bare.txt
no_private
notices "$NOT_MOUNTED"
+# mdcmd fails to put the write method back: no other try once the pid file has gone, as a run started then may force it
+begin "Clean ZFS datasets, a stop of the run alone, mdcmd fails to put the write method back" cleanFolders topFolder \
+ cleanDatasets yes notify errorsOnly enableTurbo yes
+one_share
+mkdir -p /usr/local/sbin /var/local/emhttp
+echo 'md_write_method="0"' >/var/local/emhttp/var.ini
+# shellcheck disable=SC2016 # the stand-in expands its own $*, $w and $3
+printf '#!/bin/bash\n[ ! -e %q ] || w=" (pid file there)"\necho "mdcmd $*$w" >>%q\n[ "$3" != 0 ]\n' "$T/pid" \
+ "$T/mdcmd.calls" >/usr/local/sbin/mdcmd
+chmod 755 /usr/local/sbin/mdcmd
+echo $$ >"$T/pid"
+{ stop_hook run; echo 'echo y >/mnt/cache/sh/bare.txt'; } >"$T/zfs.on_mount.zfs"
+run_moves 'processTheMoves did not return'
+check "turbo write forced, then one try to put it back, before the pid file goes" \
+ "$(printf '%s\n' 'mdcmd set md_write_method 1 (pid file there)' 'mdcmd set md_write_method 0 (pid file there)')" \
+ "$(cat "$T/mdcmd.calls")"
+log_count 1 'Could not restore original turbo write mode Read/modify/write: mdcmd exited 1'
+check "the run removed its pid file" "" "$(ls "$T/pid" 2>/dev/null)"
+rm -rf /usr/local/sbin/mdcmd /var/local/emhttp "$T/mdcmd.calls"
+cache_is sh sh/bare.txt
+no_private
+notices "$NOT_MOUNTED"
+
# a second stop that signals every process, as the plugin's does, reaches the run and the mdcmd that puts the write
# method back: both wait for it
begin "Clean ZFS datasets, a second stop as the stopped run puts the write method back" cleanFolders topFolder \
From 6bdf1e4bb2f31d5bd34e8eec07db40ef57c4d43c Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Thu, 26 Nov 2026 14:35:41 +0800
Subject: [PATCH 79/94] Test a prefer share's folder on disk10, the second disk
pattern
---
tests/age_mover/test_share_mover.sh | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/tests/age_mover/test_share_mover.sh b/tests/age_mover/test_share_mover.sh
index eee1805e..5c6cb205 100644
--- a/tests/age_mover/test_share_mover.sh
+++ b/tests/age_mover/test_share_mover.sh
@@ -108,17 +108,21 @@ rm "$T/bin/move"
log_has "Complete Mover Command: find \"/mnt/cache/sh\" -type f -depth | $T/bin/move -d 1"
array_is sh sh/a.txt
-# /mnt/other is no array disk or pool, as Unassigned Devices' mounts: a folder there that only shares the name stays
+# /mnt/other is no array disk or pool, as Unassigned Devices' mounts: a folder there that only shares the name stays.
+# disk10 is an array disk too
share 'a prefer share' prefer
mk disk1 sh/c.txt
mk disk2 sh/d.txt
+mk disk10 sh/e.txt
mk user0 sh/u.txt
mk other sh/o.txt
run 0
-log_has 'Complete Mover Command: find "/mnt/disk1/sh" "/mnt/disk2/sh" -type f -depth | /usr/libexec/unraid/move -d 1'
-cache_is sh sh/c.txt sh/d.txt
+log_has 'Complete Mover Command: find "/mnt/disk1/sh" "/mnt/disk2/sh" "/mnt/disk10/sh" -type f -depth | /usr/libexec/unraid/move -d 1'
+cache_is sh sh/c.txt sh/d.txt sh/e.txt
holds disk1 sh
holds disk2 sh
+holds disk10 sh
+rm -rf /mnt/disk10
array_is sh sh/u.txt
holds other sh sh/o.txt
From 0830f3f1ef764665fa86b84994d9cbd3adf78d36 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Thu, 26 Nov 2026 15:46:22 +0800
Subject: [PATCH 80/94] share_mover: exit with move's status when the move
fails
A failed or missing move left the run exiting 0. The run now sets the
write method back, logs both statuses and exits with move's, else
find's. Tests pin it, and pin that a stop's EXIT trap tries the restore
once, before the pid file goes.
---
.../plugins/ca.mover.tuning/share_mover | 10 ++++-
tests/age_mover/test_share_mover.sh | 37 +++++++++++++++++++
2 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover
index c0f96e07..d584cabb 100755
--- a/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover
+++ b/source/ca.mover.tuning/usr/local/emhttp/plugins/ca.mover.tuning/share_mover
@@ -147,6 +147,7 @@ if ! mountpoint -q /mnt/user0 && [ ${#POOLCFGS[@]} -lt 2 ]; then
fi
# Remove the pid file only while it still names this run, so overlapping runs cannot delete each other's
+# shellcheck disable=SC2329 # the EXIT traps call it
pid_cleanup() {
[ "$(cat "$PIDFILE" 2>/dev/null)" = "$$" ] && rm -f "$PIDFILE"
}
@@ -170,8 +171,8 @@ force_turbo() {
mvlogger "TEST MODE: Would force turbo write on"
return 0
fi
- # set first: a stop that ends the run from here on puts the write method back before the pid file goes, and a second
- # stop waits for it; a KILL cannot
+ # set first: a stop that ends the run from here on tries once to put the write method back before the pid file goes,
+ # and a second stop waits for that try; a KILL cannot
trap 'trap "" HUP INT TERM; restore_turbo; pid_cleanup' EXIT
mvlogger "Forcing turbo write on"
/usr/local/sbin/mdcmd set md_write_method 1 || mvlogger "Could not force turbo write on: mdcmd exited $?"
@@ -290,7 +291,11 @@ if grep -qs 'shareUseCache="yes\|shareUseCache="prefer"' "$SHARECFG"; then
force_turbo
mvlogger "Complete Mover Command: $FINDSTR | $MOVE -d $LOGLEVEL"
find "${paths[@]}" -type f -depth | "$MOVE" -d "$LOGLEVEL"
+ st=("${PIPESTATUS[@]}")
restore_turbo
+ # move's own failure first: find's SIGPIPE follows from it
+ MOVE_RC=$((st[1] ? st[1] : st[0]))
+ [ "$MOVE_RC" = 0 ] || mvlogger "Move command failed: find exited ${st[0]}, move exited ${st[1]}"
fi
fi
@@ -298,3 +303,4 @@ fi
mvlogger "$(titleLine 'WE ARE DONE !' '*')"
[ "$LOGLEVEL" = 1 ] || echo "Mover tuning plugin done!"
+exit "${MOVE_RC:-0}"
diff --git a/tests/age_mover/test_share_mover.sh b/tests/age_mover/test_share_mover.sh
index 5c6cb205..670d16e1 100644
--- a/tests/age_mover/test_share_mover.sh
+++ b/tests/age_mover/test_share_mover.sh
@@ -108,6 +108,25 @@ rm "$T/bin/move"
log_has "Complete Mover Command: find \"/mnt/cache/sh\" -type f -depth | $T/bin/move -d 1"
array_is sh sh/a.txt
+# a move that fails: the run puts the write method back, then exits with move's status
+share 'turbo on, move fails' yes enableTurbo yes
+mk cache sh/a.txt
+move_hook 'cat >/dev/null; exit 3'
+run 3
+move_unhook
+log_has 'Move command failed: find exited 0, move exited 3'
+mdcmd_calls 'set md_write_method 1' 'set md_write_method auto'
+cache_is sh sh/a.txt
+
+share 'no move anywhere' yes
+mk cache sh/a.txt
+mv /usr/libexec/unraid/move "$T/move.aside"
+# shellcheck disable=SC2016 # the text of share_mover's move line
+run 127 "$SM: line $(grep -nF '"$MOVE" -d' "$SM" | cut -d: -f1): : command not found"
+mv "$T/move.aside" /usr/libexec/unraid/move
+log_has 'move exited 127'
+cache_is sh sh/a.txt
+
# /mnt/other is no array disk or pool, as Unassigned Devices' mounts: a folder there that only shares the name stays.
# disk10 is an array disk too
share 'a prefer share' prefer
@@ -241,6 +260,24 @@ log_count 1 'Could not restore original turbo write mode Auto (read/modify/write
log_count 2 'Restoring original turbo write mode Auto (read/modify/write)'
array_is sh sh/a.txt
+# a stop during the moves, and mdcmd fails to put the write method back: the EXIT trap tries once, before the pid file goes
+share 'turbo on, a stop during the moves, mdcmd fails to put the write method back' yes enableTurbo yes
+mk cache sh/a.txt
+cat >/usr/local/sbin/mdcmd </dev/null)
+echo "mdcmd \$*\${w:+ (pid file there)}" >>$T/mdcmd.calls
+[ "\$3" != auto ]
+EOF
+# shellcheck disable=SC2016 # the hook expands it
+move_hook 'kill -TERM "$(cat /var/run/mover.pid)"'
+run 143
+move_unhook
+mdcmd_calls 'set md_write_method 1 (pid file there)' 'set md_write_method auto (pid file there)'
+log_count 1 'Could not restore original turbo write mode Auto (read/modify/write): mdcmd exited 1'
+check 'the run removed its pid file' '' "$(ls /var/run/mover.pid 2>/dev/null)"
+array_is sh sh/a.txt
+
share 'turbo on, mdcmd fails to force it' yes enableTurbo yes
mk cache sh/a.txt
cat >/usr/local/sbin/mdcmd <
Date: Thu, 26 Nov 2026 15:56:56 +0800
Subject: [PATCH 81/94] Test the run's status when find fails, alone and with
move
A find that fails while move succeeds gives find's status; when both fail, move's.
---
tests/age_mover/test_share_mover.sh | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/tests/age_mover/test_share_mover.sh b/tests/age_mover/test_share_mover.sh
index 670d16e1..330ad300 100644
--- a/tests/age_mover/test_share_mover.sh
+++ b/tests/age_mover/test_share_mover.sh
@@ -127,6 +127,31 @@ mv "$T/move.aside" /usr/libexec/unraid/move
log_has 'move exited 127'
cache_is sh sh/a.txt
+# find fails, as when a folder goes during the walk: the run exits with find's status, or move's when move fails too
+mkdir -p "$T/wrap"
+cat >"$T/wrap/find" <<'EOF'
+#!/bin/bash
+/usr/bin/find "$@"
+exit 1
+EOF
+chmod 755 "$T/wrap/find"
+for movetoo in no yes; do
+ share "find fails$([ "$movetoo" = no ] || echo ', and move too')" yes
+ mk cache sh/a.txt
+ if [ "$movetoo" = no ]; then
+ PATH=$T/wrap:$PATH run 1
+ log_has 'Move command failed: find exited 1, move exited 0'
+ array_is sh sh/a.txt
+ else
+ move_hook 'cat >/dev/null; exit 3'
+ PATH=$T/wrap:$PATH run 3
+ move_unhook
+ log_has 'Move command failed: find exited 1, move exited 3'
+ cache_is sh sh/a.txt
+ fi
+done
+rm -rf "$T/wrap"
+
# /mnt/other is no array disk or pool, as Unassigned Devices' mounts: a folder there that only shares the name stays.
# disk10 is an array disk too
share 'a prefer share' prefer
From 94a1f1e20b882086c5f2f5a11954daca78d7abf9 Mon Sep 17 00:00:00 2001
From: masterwishx <28630321+masterwishx@users.noreply.github.com>
Date: Thu, 26 Nov 2026 08:45:34 +0000
Subject: [PATCH 82/94] chore(beta): release changelog
Release-Synced: d634ea0dede79f6e36c66b0f0c144fae30b5e244
---
CHANGELOG.md | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 77 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 428d0ff2..8144253f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,82 @@
# Changelog
+## Unreleased
+
+- Retire Unraid's old schedule when the saved schedule is cleared (474d41a)
+- Retire Unraid's old schedule at the sync or Apply that replaces it (3814885)
+- Keep Unraid's old schedule until its replacement is written (77393fd)
+- Keep the install's cron path migrations and match dcron's name forms (5632d28)
+- Make the cron files follow the saved settings when Apply is pressed (1b0af16)
+- Escape < and > in notification text before Unraid 7.2 (02ec1ed)
+- Remove the filename check, so names holding $, <, : and the like move (6a2a139)
+- Refuse a mount at /var or /usr in test_share_mover.sh's guard (99a3831)
+- Take the pid from the pid file's first line, so a second line cannot run into it (758ad7b)
+- Read only the pid's digits, as debug_mover does, so spaces or a second line cannot hide a running mover (aab7b68)
+- Test share_mover's fallback to the move in PATH, and refuse a mount at any path the test writes (f426378)
+- Clear share_mover's ShellCheck findings, and stop its rm of an unset SOFTSTOPFILE (386697b)
+- Make the zfs stand-in follow OpenZFS after unmount and destroy, and pin the dataset cases (25f0ac5)
+- Pin what age_mover's folder cleanup does today, through the real processTheMoves (080e0e3)
+- Tell ShellCheck that age_mover's functions read the harness settings (076f946)
+- Make the age_mover harness fail loudly, run debug for real and pin byte counters (e0e241e)
+- Pin what age_mover's moves do today, through the real processTheMoves (84c0f82)
+- age_mover: look up a hardlink group only for a multi-link regular file (2dab2f6)
+- Refuse a mount at /var in test_install.sh's guard (dbfcb7c)
+- Remove validateFilenames and invalidFileChars from saved configs at install (4ce1f9c)
+- Check each share's top folder once, after the pass, instead of after every move row (46cf4a3)
+- Refuse a mount at /usr/libexec/unraid/move or above in lib.sh's guard; note why SC2016 is off for the rsync wrapper (4911cba)
+- Pin what age_mover's soft stop and pause do today, through the real processTheMoves (1500d2e)
+- Treat a busy unmount as a busy destroy; remount only over an empty folder; split dataset tests (9d84d41)
+- Keep the dataset on a busy destroy; note it on folder rows; skip .zfs; log zfs's reason only (b92bd56)
+- Destroy a share's ZFS dataset only when nothing in it would be lost (74d2849)
+- qp goes through qpAll, so the escapes have one owner; pin the backslash escape (6dac7a7)
+- perf: quote message lists without a subshell per item
+- perf: make logging cheap, and free when it is off
+- fix: check files with fuser when the lease helper cannot start
+- fix: keep supporting Unraid before 6.11.0
+- fix: don't break existing leases when checking files
+- perf: use file leases for faster in-use checks
+- update readme (a590559)
+- Ignore a second stop while the stopped run puts the write method back (d057092)
+- Tell the recovery steps to keep both copies of a file the dataset already has (54d7772)
+- Check the mount table after a failed recovery umount, so a detached dataset is mounted back (32ee7be)
+- Give a cut-short remount's notice its steps, and send it under Notify errors only (17e8449)
+- Report a look at the mount back that was cut short (80370d8)
+- Say a cut-short scan can print nothing (4a1b1a9)
+- Keep a dataset whose scan was killed before it finished (7845dc0)
+- Probe the private mount after a failed umount; guard the php stand-in's path (ea10904)
+- Say in the notice why a dataset is out of view and how to mount it back (02b5b01)
+- Look inside the share folder at the remount even when it was gone (08df5c5)
+- Report a write the remount hides, and let stop wait for the run (05441cd)
+- Finish each dataset step on a stop, and tell a busy read-only mount from a failed check (10b8b4c)
+- Check a dataset again at a private read-only mount, and put it back on a stop (1c4786f)
+- Name the dataset notice after its setting and translate it (cf795c7)
+- fix: check a ZFS dataset again once unmounted, before destroying it
+- Count nothing in a folder an earlier row deleted (09aaf89)
+- Count a folder's own subfolders only in the moved-folder walk (6483f79)
+- Recount a folder after a name gone before its turn; keep test mode's countdown (e07de52)
+- Fix the folder cleanup's failed-move, top-folder and count gaps (dfdc405)
+- Say would_rmdir checks ZFS mounts only (8c8f4ae)
+- Let test mode keep a folder rmdir would refuse (893dcec)
+- Say what the missing-name case's recount keeps (8553c5f)
+- Test a missing middle name among four rows in both modes (e7d5b1c)
+- Say in test mode which ZFS dataset a real run would check for deletion (de310e6)
+- Make test mode's folder lines predict a real run's (ec13d05)
+- Make the last turbo restore before the run removes its pid file (6be8f18)
+- Keep the turbo restore armed until mdcmd sets the write method back (0f65bec)
+- Reap the stop case's run in the test script, as CI's container has no init to (c33541d)
+- Mark the stop case's stand-in quoting and the variables stop reads for ShellCheck (6c39cbb)
+- Let the stop skip a process that ended since it was listed (5336e0a)
+- Let the second-stop test's TERM reach mdcmd, as the plugin's stop does (9b62578)
+- Let a second stop wait while the run puts the write method back (8ddc0e5)
+- Force turbo write only when the write method can be set back; mark test mode's turbo lines (d518c2b)
+- Put the write method back when a stop ends the run during the moves (17cdc8e)
+- Test the run's status when find fails, alone and with move (97b55ed)
+- share_mover: exit with move's status when the move fails (0830f3f)
+- Test a prefer share's folder on disk10, the second disk pattern (6bdf1e4)
+- Keep share_mover's turbo restore armed until mdcmd sets it back (e441cb4)
+- share_mover: move a prefer share only from array disks and pools, run no find without a folder, let a second stop wait for the write method (2299eb7)
+- share_mover: run find without eval, force turbo write only when it can be set back, exit 0 after a run (bd920c2)
+
## 2026.11.13
- fix: The Log files list now shows new logs without a page reload. (chodeus)
From 86ede384a4a8cdb6863a1bf09564cf580236e814 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Thu, 26 Nov 2026 16:50:18 +0800
Subject: [PATCH 83/94] chore(beta): write the release notes
One user-facing line per change since 2026.11.13; tests, CI, ShellCheck and fixes to this cycle's own changes left out.
---
CHANGELOG.md | 85 +++++++---------------------------------------------
1 file changed, 11 insertions(+), 74 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8144253f..9e0f3c83 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,80 +2,17 @@
## Unreleased
-- Retire Unraid's old schedule when the saved schedule is cleared (474d41a)
-- Retire Unraid's old schedule at the sync or Apply that replaces it (3814885)
-- Keep Unraid's old schedule until its replacement is written (77393fd)
-- Keep the install's cron path migrations and match dcron's name forms (5632d28)
-- Make the cron files follow the saved settings when Apply is pressed (1b0af16)
-- Escape < and > in notification text before Unraid 7.2 (02ec1ed)
-- Remove the filename check, so names holding $, <, : and the like move (6a2a139)
-- Refuse a mount at /var or /usr in test_share_mover.sh's guard (99a3831)
-- Take the pid from the pid file's first line, so a second line cannot run into it (758ad7b)
-- Read only the pid's digits, as debug_mover does, so spaces or a second line cannot hide a running mover (aab7b68)
-- Test share_mover's fallback to the move in PATH, and refuse a mount at any path the test writes (f426378)
-- Clear share_mover's ShellCheck findings, and stop its rm of an unset SOFTSTOPFILE (386697b)
-- Make the zfs stand-in follow OpenZFS after unmount and destroy, and pin the dataset cases (25f0ac5)
-- Pin what age_mover's folder cleanup does today, through the real processTheMoves (080e0e3)
-- Tell ShellCheck that age_mover's functions read the harness settings (076f946)
-- Make the age_mover harness fail loudly, run debug for real and pin byte counters (e0e241e)
-- Pin what age_mover's moves do today, through the real processTheMoves (84c0f82)
-- age_mover: look up a hardlink group only for a multi-link regular file (2dab2f6)
-- Refuse a mount at /var in test_install.sh's guard (dbfcb7c)
-- Remove validateFilenames and invalidFileChars from saved configs at install (4ce1f9c)
-- Check each share's top folder once, after the pass, instead of after every move row (46cf4a3)
-- Refuse a mount at /usr/libexec/unraid/move or above in lib.sh's guard; note why SC2016 is off for the rsync wrapper (4911cba)
-- Pin what age_mover's soft stop and pause do today, through the real processTheMoves (1500d2e)
-- Treat a busy unmount as a busy destroy; remount only over an empty folder; split dataset tests (9d84d41)
-- Keep the dataset on a busy destroy; note it on folder rows; skip .zfs; log zfs's reason only (b92bd56)
-- Destroy a share's ZFS dataset only when nothing in it would be lost (74d2849)
-- qp goes through qpAll, so the escapes have one owner; pin the backslash escape (6dac7a7)
-- perf: quote message lists without a subshell per item
-- perf: make logging cheap, and free when it is off
-- fix: check files with fuser when the lease helper cannot start
-- fix: keep supporting Unraid before 6.11.0
-- fix: don't break existing leases when checking files
-- perf: use file leases for faster in-use checks
-- update readme (a590559)
-- Ignore a second stop while the stopped run puts the write method back (d057092)
-- Tell the recovery steps to keep both copies of a file the dataset already has (54d7772)
-- Check the mount table after a failed recovery umount, so a detached dataset is mounted back (32ee7be)
-- Give a cut-short remount's notice its steps, and send it under Notify errors only (17e8449)
-- Report a look at the mount back that was cut short (80370d8)
-- Say a cut-short scan can print nothing (4a1b1a9)
-- Keep a dataset whose scan was killed before it finished (7845dc0)
-- Probe the private mount after a failed umount; guard the php stand-in's path (ea10904)
-- Say in the notice why a dataset is out of view and how to mount it back (02b5b01)
-- Look inside the share folder at the remount even when it was gone (08df5c5)
-- Report a write the remount hides, and let stop wait for the run (05441cd)
-- Finish each dataset step on a stop, and tell a busy read-only mount from a failed check (10b8b4c)
-- Check a dataset again at a private read-only mount, and put it back on a stop (1c4786f)
-- Name the dataset notice after its setting and translate it (cf795c7)
-- fix: check a ZFS dataset again once unmounted, before destroying it
-- Count nothing in a folder an earlier row deleted (09aaf89)
-- Count a folder's own subfolders only in the moved-folder walk (6483f79)
-- Recount a folder after a name gone before its turn; keep test mode's countdown (e07de52)
-- Fix the folder cleanup's failed-move, top-folder and count gaps (dfdc405)
-- Say would_rmdir checks ZFS mounts only (8c8f4ae)
-- Let test mode keep a folder rmdir would refuse (893dcec)
-- Say what the missing-name case's recount keeps (8553c5f)
-- Test a missing middle name among four rows in both modes (e7d5b1c)
-- Say in test mode which ZFS dataset a real run would check for deletion (de310e6)
-- Make test mode's folder lines predict a real run's (ec13d05)
-- Make the last turbo restore before the run removes its pid file (6be8f18)
-- Keep the turbo restore armed until mdcmd sets the write method back (0f65bec)
-- Reap the stop case's run in the test script, as CI's container has no init to (c33541d)
-- Mark the stop case's stand-in quoting and the variables stop reads for ShellCheck (6c39cbb)
-- Let the stop skip a process that ended since it was listed (5336e0a)
-- Let the second-stop test's TERM reach mdcmd, as the plugin's stop does (9b62578)
-- Let a second stop wait while the run puts the write method back (8ddc0e5)
-- Force turbo write only when the write method can be set back; mark test mode's turbo lines (d518c2b)
-- Put the write method back when a stop ends the run during the moves (17cdc8e)
-- Test the run's status when find fails, alone and with move (97b55ed)
-- share_mover: exit with move's status when the move fails (0830f3f)
-- Test a prefer share's folder on disk10, the second disk pattern (6bdf1e4)
-- Keep share_mover's turbo restore armed until mdcmd sets it back (e441cb4)
-- share_mover: move a prefer share only from array disks and pools, run no find without a folder, let a second stop wait for the write method (2299eb7)
-- share_mover: run find without eval, force turbo write only when it can be set back, exit 0 after a run (bd920c2)
+- perf: Faster in-use file checks: file leases replace fuser where the system supports them. (coppit)
+- perf: Logging costs much less, and almost nothing when it is off. (coppit)
+- perf: Large moves run faster, with fewer hardlink lookups and top folder checks. (chodeus)
+- fix: Apply now changes the mover schedule to the saved settings. (chodeus)
+- fix: File names holding $, <, : and similar characters now move; the filename check is removed. (chodeus)
+- fix: A file name holding < or > no longer breaks notifications before Unraid 7.2. (chodeus)
+- fix: Clean empty ZFS datasets keeps a dataset until everything in it has moved. (chodeus)
+- fix: Clean empty folders keeps the folder of a failed move, and on Yes the share's top folder. (chodeus)
+- fix: Turbo write is now restored when a move is stopped, Move Now included. (chodeus)
+- fix: Move Now no longer reads Unassigned Devices mounts or runs text from a share name. (chodeus)
+- fix: Test mode's folder cleanup and turbo write lines now match what a real run does. (chodeus)
## 2026.11.13
From 2b20a2354bb9042ffab8dd81d1b0ca1e6abc5d73 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Thu, 26 Nov 2026 16:51:48 +0800
Subject: [PATCH 84/94] chore(beta): credit coppit for the faster large moves
---
CHANGELOG.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9e0f3c83..38e52607 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,7 +4,7 @@
- perf: Faster in-use file checks: file leases replace fuser where the system supports them. (coppit)
- perf: Logging costs much less, and almost nothing when it is off. (coppit)
-- perf: Large moves run faster, with fewer hardlink lookups and top folder checks. (chodeus)
+- perf: Large moves run faster, with fewer hardlink lookups and top folder checks. (chodeus, coppit)
- fix: Apply now changes the mover schedule to the saved settings. (chodeus)
- fix: File names holding $, <, : and similar characters now move; the filename check is removed. (chodeus)
- fix: A file name holding < or > no longer breaks notifications before Unraid 7.2. (chodeus)
From 0a63e677423afc8c224e3cfc3618cdffd364634b Mon Sep 17 00:00:00 2001
From: masterwishx <28630321+masterwishx@users.noreply.github.com>
Date: Thu, 26 Nov 2026 08:52:52 +0000
Subject: [PATCH 85/94] chore(release): 2026.11.26a [skip ci]
---
CHANGELOG.md | 2 +-
plugins/ca.mover.tuning.plg | 17 +++++++++++++++--
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 38e52607..85ff0957 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,6 @@
# Changelog
-## Unreleased
+## 2026.11.26a (beta)
- perf: Faster in-use file checks: file leases replace fuser where the system supports them. (coppit)
- perf: Logging costs much less, and almost nothing when it is off. (coppit)
diff --git a/plugins/ca.mover.tuning.plg b/plugins/ca.mover.tuning.plg
index d1376a7f..cbcab7f0 100644
--- a/plugins/ca.mover.tuning.plg
+++ b/plugins/ca.mover.tuning.plg
@@ -2,8 +2,8 @@
-
-
+
+
@@ -14,6 +14,19 @@
+###2026.11.26a
+- perf: Faster in-use file checks: file leases replace fuser where the system supports them. (coppit)
+- perf: Logging costs much less, and almost nothing when it is off. (coppit)
+- perf: Large moves run faster, with fewer hardlink lookups and top folder checks. (chodeus, coppit)
+- fix: Apply now changes the mover schedule to the saved settings. (chodeus)
+- fix: File names holding $, <, : and similar characters now move; the filename check is removed. (chodeus)
+- fix: A file name holding < or > no longer breaks notifications before Unraid 7.2. (chodeus)
+- fix: Clean empty ZFS datasets keeps a dataset until everything in it has moved. (chodeus)
+- fix: Clean empty folders keeps the folder of a failed move, and on Yes the share's top folder. (chodeus)
+- fix: Turbo write is now restored when a move is stopped, Move Now included. (chodeus)
+- fix: Move Now no longer reads Unassigned Devices mounts or runs text from a share name. (chodeus)
+- fix: Test mode's folder cleanup and turbo write lines now match what a real run does. (chodeus)
+
###2026.11.13
- fix: The Log files list now shows new logs without a page reload. (chodeus)
- fix: The Log files icons now follow the theme's text colour. (chodeus)
From 087068ced9198f4f126e28bfd5d321c76a8b9e6d Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Thu, 26 Nov 2026 18:14:25 +0800
Subject: [PATCH 86/94] ci: look the build comment up again for the note after
the deletes
A publish run can post its first build comment between the sweep's two notes; the cached empty id left that comment pointing at a removed build.
---
.github/workflows/pr-cleanup.yml | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/.github/workflows/pr-cleanup.yml b/.github/workflows/pr-cleanup.yml
index bb69023c..5e492219 100644
--- a/.github/workflows/pr-cleanup.yml
+++ b/.github/workflows/pr-cleanup.yml
@@ -27,18 +27,21 @@ jobs:
run: |
set -euo pipefail
marker=""
- note() { [ -z "$1" ] || gh api "repos/$GITHUB_REPOSITORY/issues/comments/$1" -X PATCH -f body="$marker"$'\n'"The test build for this pull request has been removed." >/dev/null; }
# set -e does not reach into a function called with ||, so every failure returns 1 itself
- clean() { # $1 pull request, $2 its tags, $3 closed or gone (deleted, so no note to update)
- local id="" tag out
- if [ "$3" = closed ]; then
- id=$(gh api --paginate "repos/$GITHUB_REPOSITORY/issues/$1/comments?per_page=100" --jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | startswith(\"$marker\"))) | .id") || return 1
- id=${id%%$'\n'*}
- fi
- [ "$id" != null ] || id=""
+ # looks the comment up each time: a publish run may post its first one between two notes
+ note() { # $1 pull request, $2 closed or gone (deleted, so no note to update)
+ local id
+ [ "$2" = closed ] || return 0
+ id=$(gh api --paginate "repos/$GITHUB_REPOSITORY/issues/$1/comments?per_page=100" --jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | startswith(\"$marker\"))) | .id") || return 1
+ id=${id%%$'\n'*}
+ [ -n "$id" ] || return 0
+ gh api "repos/$GITHUB_REPOSITORY/issues/comments/$id" -X PATCH -f body="$marker"$'\n'"The test build for this pull request has been removed." >/dev/null
+ }
+ clean() { # $1 pull request, $2 its tags, $3 closed or gone
+ local tag out
# the note before the deletes, as this pull request is not visited again once they are done, and after
# them, as a publish run may have written its own note in between
- note "$id" || return 1
+ note "$1" "$3" || return 1
while read -r tag; do
if grep -qxF -- "$tag" <<< "$builds"; then
# a publish run that saw the close may remove it first: "release not found", or a 404 when it does so
@@ -50,7 +53,7 @@ jobs:
fi
echo "removed $tag"
done <<< "$2"
- note "$id" || return 1
+ note "$1" "$3" || return 1
}
# listed first: a failing call inside a process substitution would read as "nothing to remove". Tags before
# releases, so a release published between the two lists is never taken for a tag without one
From 53170ac1813e10d52df460653aae54ff80ea3d73 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Thu, 26 Nov 2026 19:04:06 +0800
Subject: [PATCH 87/94] ci: count a tag a publish run removed first as removed
in the cleanup sweep
A publish run's --cleanup-tag can delete an orphaned tag between the sweep's inventory and its delete; GitHub answers 422 "Reference does not exist" (or 404), which stopped that pull request's cleanup.
---
.github/workflows/pr-cleanup.yml | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/.github/workflows/pr-cleanup.yml b/.github/workflows/pr-cleanup.yml
index 5e492219..b5f4154b 100644
--- a/.github/workflows/pr-cleanup.yml
+++ b/.github/workflows/pr-cleanup.yml
@@ -49,7 +49,9 @@ jobs:
out=$(gh release delete --repo "$GITHUB_REPOSITORY" "$tag" --yes --cleanup-tag 2>&1) \
|| [[ "$out" == *"release not found"* || "$out" == *"HTTP 404"* ]] || { echo "$out" >&2; return 1; }
else
- gh api -X DELETE "repos/$GITHUB_REPOSITORY/git/refs/tags/$tag" >/dev/null || return 1
+ # a publish run's --cleanup-tag may remove it first: GitHub answers that with this 422, or a 404
+ out=$(gh api -X DELETE "repos/$GITHUB_REPOSITORY/git/refs/tags/$tag" 2>&1 >/dev/null) \
+ || [[ "$out" == *"Reference does not exist"* || "$out" == *"HTTP 404"* ]] || { echo "$out" >&2; return 1; }
fi
echo "removed $tag"
done <<< "$2"
From c9b9c461ee238b592b37d12c1c48a054ecb821f3 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Thu, 26 Nov 2026 20:08:30 +0800
Subject: [PATCH 88/94] ci: delete the build tags after the cleanup's note, so
a failed note is retried
The sweep finds a pull request by its pr- tags. Deleting them with the releases, before the final note, meant a note that failed was never written again and the comment kept pointing at a removed build. Releases go first, then one note, then the tags; the note before the deletes is no longer needed.
---
.github/workflows/pr-cleanup.yml | 28 +++++++++++++---------------
.github/workflows/pr-publish.yml | 2 +-
2 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/.github/workflows/pr-cleanup.yml b/.github/workflows/pr-cleanup.yml
index b5f4154b..46c6a407 100644
--- a/.github/workflows/pr-cleanup.yml
+++ b/.github/workflows/pr-cleanup.yml
@@ -28,7 +28,6 @@ jobs:
set -euo pipefail
marker=""
# set -e does not reach into a function called with ||, so every failure returns 1 itself
- # looks the comment up each time: a publish run may post its first one between two notes
note() { # $1 pull request, $2 closed or gone (deleted, so no note to update)
local id
[ "$2" = closed ] || return 0
@@ -39,30 +38,29 @@ jobs:
}
clean() { # $1 pull request, $2 its tags, $3 closed or gone
local tag out
- # the note before the deletes, as this pull request is not visited again once they are done, and after
- # them, as a publish run may have written its own note in between
+ while read -r tag; do
+ grep -qxF -- "$tag" <<< "$builds" || continue
+ # a publish run that saw the close may remove it first: "release not found", or a 404 when it does so
+ # between gh's lookup and its delete, is that outcome
+ out=$(gh release delete --repo "$GITHUB_REPOSITORY" "$tag" --yes 2>&1) \
+ || [[ "$out" == *"release not found"* || "$out" == *"HTTP 404"* ]] || { echo "$out" >&2; return 1; }
+ done <<< "$2"
+ # after the release deletes: a publish run's comment lands before it or finds no release (pr-publish). Before
+ # the tag deletes: a failed note keeps the tags, so the next sweep comes back to this pull request
note "$1" "$3" || return 1
while read -r tag; do
- if grep -qxF -- "$tag" <<< "$builds"; then
- # a publish run that saw the close may remove it first: "release not found", or a 404 when it does so
- # between gh's lookup and its delete, is that outcome
- out=$(gh release delete --repo "$GITHUB_REPOSITORY" "$tag" --yes --cleanup-tag 2>&1) \
- || [[ "$out" == *"release not found"* || "$out" == *"HTTP 404"* ]] || { echo "$out" >&2; return 1; }
- else
- # a publish run's --cleanup-tag may remove it first: GitHub answers that with this 422, or a 404
- out=$(gh api -X DELETE "repos/$GITHUB_REPOSITORY/git/refs/tags/$tag" 2>&1 >/dev/null) \
- || [[ "$out" == *"Reference does not exist"* || "$out" == *"HTTP 404"* ]] || { echo "$out" >&2; return 1; }
- fi
+ # a publish run's --cleanup-tag may remove it first: GitHub answers that with this 422, or a 404
+ out=$(gh api -X DELETE "repos/$GITHUB_REPOSITORY/git/refs/tags/$tag" 2>&1 >/dev/null) \
+ || [[ "$out" == *"Reference does not exist"* || "$out" == *"HTTP 404"* ]] || { echo "$out" >&2; return 1; }
echo "removed $tag"
done <<< "$2"
- note "$1" "$3" || return 1
}
# listed first: a failing call inside a process substitution would read as "nothing to remove". Tags before
# releases, so a release published between the two lists is never taken for a tag without one
refs=$(gh api --paginate "repos/$GITHUB_REPOSITORY/git/matching-refs/tags/pr-" --jq '.[].ref | ltrimstr("refs/tags/") | select(test("^pr-[0-9]+-"))')
listed=$(gh api --paginate "repos/$GITHUB_REPOSITORY/releases" --jq '.[] | select(.tag_name | test("^pr-[0-9]+-")) | "\(.prerelease) \(.tag_name)"')
builds=$(sed -n 's/^true //p' <<< "$listed")
- # a tag no release has: gh deletes the release first, so a failed tag delete leaves the tag behind
+ # a tag no release has: clean deletes tags last, so a failure after the release deletes leaves them behind
orphans=$(grep -vxF -f <(sed 's/^[a-z]* //' <<< "$listed") <<< "$refs") || [ $? = 1 ]
tags=$(printf '%s\n' "$builds" "$orphans" | sed '/^$/d' | sort -u)
[ -n "$tags" ] || { echo "No test builds."; exit 0; }
diff --git a/.github/workflows/pr-publish.yml b/.github/workflows/pr-publish.yml
index 8661bda7..5042665c 100644
--- a/.github/workflows/pr-publish.yml
+++ b/.github/workflows/pr-publish.yml
@@ -221,7 +221,7 @@ jobs:
id=$(gh api "repos/$GITHUB_REPOSITORY/issues/$PR/comments" -X POST -f body="$body" --jq .id)
fi
# checked after the write: PR cleanup may have removed the build since the closed check, and it notes after
- # its deletes, so whichever note lands last says what is there
+ # its release deletes, so whichever note lands last says what is there
[ "$VERIFIED" = true ] && [ "$CLOSED" != true ] || exit 0
out=$(gh release view --repo "$GITHUB_REPOSITORY" "$TAG" 2>&1 >/dev/null) && exit 0
[[ "$out" == *"release not found"* ]] || { echo "$out" >&2; exit 1; }
From 8fc3f1e0d656df46e8414448923d85eadf632812 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Thu, 26 Nov 2026 20:10:05 +0800
Subject: [PATCH 89/94] ci: keep the tag when a publish run removes a closed
pull request's build
Its comment is written in the next step. With the tag gone, a failed write left the comment on a removed build and PR cleanup never came back to it; the tag now leads that sweep to note the comment and remove the tag.
---
.github/workflows/pr-publish.yml | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/.github/workflows/pr-publish.yml b/.github/workflows/pr-publish.yml
index 5042665c..48e16e12 100644
--- a/.github/workflows/pr-publish.yml
+++ b/.github/workflows/pr-publish.yml
@@ -183,10 +183,10 @@ jobs:
set -euo pipefail
# its own line, so set -e stops on an unreadable pull request instead of removing an open one's build
state=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$PR" --jq .state)
- # PR cleanup's hourly sweep may get there first: "release not found", or a 404 when it removes it between
- # gh's lookup and its delete, means it did, and the build is gone either way
+ # PR cleanup's sweep may get there first ("release not found", or a 404 between gh's lookup and its delete).
+ # The tag stays: that sweep finds it, notes the comment and removes it, so a failed note below is redone
if [ "$state" != "open" ]; then
- out=$(gh release delete --repo "$GITHUB_REPOSITORY" "$TAG" --cleanup-tag --yes 2>&1) \
+ out=$(gh release delete --repo "$GITHUB_REPOSITORY" "$TAG" --yes 2>&1) \
|| [[ "$out" == *"release not found"* || "$out" == *"HTTP 404"* ]] || { echo "$out" >&2; exit 1; }
echo "closed=true" >> "$GITHUB_OUTPUT"
echo "Pull request #$PR closed while publishing; the release was removed again."
From 88496d1a9e6fa2217538009dfe86c342ed2b736d Mon Sep 17 00:00:00 2001
From: masterwishx <28630321+masterwishx@users.noreply.github.com>
Date: Thu, 26 Nov 2026 13:20:42 +0000
Subject: [PATCH 90/94] chore(beta): release changelog
Release-Synced: bdb6f15697cca463a8f8b8e6552bb2dff9937605
---
CHANGELOG.md | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 85ff0957..1174c129 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,13 @@
# Changelog
+## Unreleased
+
+- fix: correct feature descriptions and improve clarity in README.md
+- fix: correct typos and improve formatting in README.md
+- fix: update tip for settings page in README.md
+- fix: update Unraid badge color in README.md
+- Update README.md (8957161)
+
## 2026.11.26a (beta)
- perf: Faster in-use file checks: file leases replace fuser where the system supports them. (coppit)
From 6fb66f511ae8d32a75482b673175dd18919f22d0 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Thu, 26 Nov 2026 21:21:19 +0800
Subject: [PATCH 91/94] chore(beta): write the release notes
---
CHANGELOG.md | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1174c129..ce561b20 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,11 +2,7 @@
## Unreleased
-- fix: correct feature descriptions and improve clarity in README.md
-- fix: correct typos and improve formatting in README.md
-- fix: update tip for settings page in README.md
-- fix: update Unraid badge color in README.md
-- Update README.md (8957161)
+- No changes to the plugin since 2026.11.26a: README updates and release workflow fixes only. (masterwishx, chodeus)
## 2026.11.26a (beta)
From 358bbc6276fdced9f43c0a9ea1ad44635173e1b0 Mon Sep 17 00:00:00 2001
From: masterwishx <28630321+masterwishx@users.noreply.github.com>
Date: Thu, 26 Nov 2026 13:25:33 +0000
Subject: [PATCH 92/94] chore(release): 2026.11.26b [skip ci]
---
CHANGELOG.md | 2 +-
plugins/ca.mover.tuning.plg | 7 +++++--
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ce561b20..9314dd6d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,6 @@
# Changelog
-## Unreleased
+## 2026.11.26b (beta)
- No changes to the plugin since 2026.11.26a: README updates and release workflow fixes only. (masterwishx, chodeus)
diff --git a/plugins/ca.mover.tuning.plg b/plugins/ca.mover.tuning.plg
index cbcab7f0..3bc3fac0 100644
--- a/plugins/ca.mover.tuning.plg
+++ b/plugins/ca.mover.tuning.plg
@@ -2,8 +2,8 @@
-
-
+
+
@@ -14,6 +14,9 @@
+###2026.11.26b
+- No changes to the plugin since 2026.11.26a: README updates and release workflow fixes only. (masterwishx, chodeus)
+
###2026.11.26a
- perf: Faster in-use file checks: file leases replace fuser where the system supports them. (coppit)
- perf: Logging costs much less, and almost nothing when it is off. (coppit)
From 33475e6458d047b893d535b17653f65bf15ef8cc Mon Sep 17 00:00:00 2001
From: masterwishx <28630321+masterwishx@users.noreply.github.com>
Date: Thu, 26 Nov 2026 13:25:44 +0000
Subject: [PATCH 93/94] chore(master): release changelog
Release-Synced: 8b9cfed60d82151419714f2ca8e1da0bb669a62f
Release-Synced-Beta: 2026.11.26b
---
CHANGELOG.md | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 27a72173..821a79bc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,20 @@
# Changelog
+## Unreleased
+
+- perf: Faster in-use file checks: file leases replace fuser where the system supports them. (coppit)
+- perf: Logging costs much less, and almost nothing when it is off. (coppit)
+- perf: Large moves run faster, with fewer hardlink lookups and top folder checks. (chodeus, coppit)
+- fix: Apply now changes the mover schedule to the saved settings. (chodeus)
+- fix: File names holding $, <, : and similar characters now move; the filename check is removed. (chodeus)
+- fix: A file name holding < or > no longer breaks notifications before Unraid 7.2. (chodeus)
+- fix: Clean empty ZFS datasets keeps a dataset until everything in it has moved. (chodeus)
+- fix: Clean empty folders keeps the folder of a failed move, and on Yes the share's top folder. (chodeus)
+- fix: Turbo write is now restored when a move is stopped, Move Now included. (chodeus)
+- fix: Move Now no longer reads Unassigned Devices mounts or runs text from a share name. (chodeus)
+- fix: Test mode's folder cleanup and turbo write lines now match what a real run does. (chodeus)
+- No changes to the plugin since 2026.11.26a: README updates and release workflow fixes only. (masterwishx, chodeus)
+
## 2026.11.26b (beta)
- No changes to the plugin since 2026.11.26a: README updates and release workflow fixes only. (masterwishx, chodeus)
From 3a3a5102c23ec718cb8249867b1485c6ad1cbed3 Mon Sep 17 00:00:00 2001
From: chodeus <190988615+chodeus@users.noreply.github.com>
Date: Thu, 26 Nov 2026 21:26:54 +0800
Subject: [PATCH 94/94] chore(master): leave the beta-only note out of the
release notes
---
CHANGELOG.md | 1 -
1 file changed, 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 821a79bc..ff5a721a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,7 +13,6 @@
- fix: Turbo write is now restored when a move is stopped, Move Now included. (chodeus)
- fix: Move Now no longer reads Unassigned Devices mounts or runs text from a share name. (chodeus)
- fix: Test mode's folder cleanup and turbo write lines now match what a real run does. (chodeus)
-- No changes to the plugin since 2026.11.26a: README updates and release workflow fixes only. (masterwishx, chodeus)
## 2026.11.26b (beta)