Skip to content

fix(ssd_trim): trim each filesystem once - #2797

Open
Joly0 wants to merge 1 commit into
unraid:masterfrom
Joly0:fix/ssd-trim-once
Open

Joly0 wants to merge 1 commit into
unraid:masterfrom
Joly0:fix/ssd-trim-once

Conversation

@Joly0

@Joly0 Joly0 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2796.

xfs_btrfs_trim() ran fstrim on every btrfs/xfs mount with a /dev/ source, bind mounts included (their source is /dev/xxx[/subdir]). fstrim trims the whole filesystem whatever mount point it gets, so a pool with bind mounts (for example /var/lib/docker on a Docker directory) was trimmed once per mount.

The mount list now also selects MAJ:MIN and FSROOT, keeps one entry per MAJ:MIN (one per filesystem; the same for every mount of it, including btrfs subvolumes), and prefers the mount of the filesystem root, so the trim result still names the usual mount point. The rest of the function is unchanged.

Tested on 7.4.0-rc.1 with a btrfs cache pool that has three bind mounts and six array disks: the list went from 10 entries to 7 (/mnt/disk1 to /mnt/disk6 and /mnt/cache), php -l passes. The output format (target, tab, source) is unchanged, so the handling of mount points with spaces from #2042 is untouched.

Summary by CodeRabbit

  • Bug Fixes
    • SSD trimming now considers one mount per device instead of processing every matching mount. When a device has multiple mounts, the root mount is prioritized. This provides more consistent handling of devices mounted in multiple locations while preserving the existing trim feature.

fstrim always trims the whole filesystem, but every bind mount of a pool (for example /var/lib/docker) was trimmed again. Keep one mount per MAJ:MIN, preferring the mount of the filesystem root.
@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 32d4d006-81dc-4a57-9e31-f8e8d0f3c7d2
📥 Commits

Reviewing files that changed from the base of the PR and between 26eb1b5 and 67d1a6b.

📒 Files selected for processing: 1
  • emhttp/plugins/dynamix/scripts/ssd_trim

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

Walkthrough

xfs_btrfs_trim now uses mount metadata to prefer filesystem-root mounts and process one mount per major/minor device.

Changes

SSD trim mount selection

Layer / File(s) Summary
Select one mount per filesystem
emhttp/plugins/dynamix/scripts/ssd_trim
xfs_btrfs_trim now selects mount targets, sources, major/minor numbers, and filesystem roots. It filters to /dev/ sources, orders root mounts first, and keeps one mount per major/minor device.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 67d1a

The change makes scheduled SSD trim run once per filesystem and prefer the root mount, which addresses the repeated-trim problem. No merge-blocking risk remains.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: trimming each filesystem once instead of once per mount.
Linked Issues check Passed Issue #2796 requires one trim per filesystem, preferably through the filesystem-root mount. In emhttp/plugins/dynamix/scripts/ssd_trim, xfs_btrfs_trim() now reads MAJ:MIN and FSROOT, orders ro…
Out of Scope Changes check Passed The pull request changes only emhttp/plugins/dynamix/scripts/ssd_trim. The change is limited to selecting filesystem identity and root information, deduplicating mounts, and retaining the existing t…
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Full details: Linked Issues check

Explanation

Issue #2796 requires one trim per filesystem, preferably through the filesystem-root mount. In emhttp/plugins/dynamix/scripts/ssd_trim, xfs_btrfs_trim() now reads MAJ:MIN and FSROOT, orders root mounts first, and applies unique_by(."maj:min") before producing the unchanged target/source output. This prevents repeated fstrim calls for bind mounts while preserving the existing source filter and output handling. No separate automated regression-test requirement appears in the linked issue.

Full details: Out of Scope Changes check

Explanation

The pull request changes only emhttp/plugins/dynamix/scripts/ssd_trim. The change is limited to selecting filesystem identity and root information, deduplicating mounts, and retaining the existing trim output. These changes directly implement issue #2796 and introduce no unrelated behavior.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks the mount list twice,
Root-first paths make trimming precise.
One device, one pass along the way,
No bind-mount repeats to slow the day.
Then hops away beneath the moon.

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

🔧 PR Test Plugin Available

A test plugin has been generated for this PR that includes the modified files.

Version: 2026.10.22.0927
Build: View Workflow Run

📥 Installation Instructions:

Install via Unraid Web UI:

  1. Go to Plugins → Install Plugin
  2. Copy and paste this URL:
https://preview.dl.unraid.net/pr-plugins/pr-2797/webgui-pr-2797.plg
  1. Click Install

Alternative: Direct Download

⚠️ Important Notes:

  • Testing only: This plugin is for testing PR changes
  • Backup included: Original files are automatically backed up
  • Easy removal: Files are restored when plugin is removed
  • Conflicts: Remove this plugin before installing production updates
  • Post-merge behavior: This preview stays available after merge until preview storage expires or it is manually cleaned up

📝 Modified Files:

Click to expand file list
emhttp/plugins/dynamix/scripts/ssd_trim

🔄 To Remove:

Navigate to Plugins → Installed Plugins and remove webgui-pr-2797, or run:

plugin remove webgui-pr-2797

🤖 This comment is automatically generated and will be updated with each new push to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ssd_trim trims the same filesystem once per bind mount

1 participant