Skip to content

fix(agent): keep every EXTRA_FILESYSTEMS mount when device keys collide#1932

Open
BootstrapperSBL wants to merge 1 commit intohenrygd:mainfrom
BootstrapperSBL:fix/extra-filesystems-autofs-collision
Open

fix(agent): keep every EXTRA_FILESYSTEMS mount when device keys collide#1932
BootstrapperSBL wants to merge 1 commit intohenrygd:mainfrom
BootstrapperSBL:fix/extra-filesystems-autofs-collision

Conversation

@BootstrapperSBL
Copy link
Copy Markdown
Contributor

What

EXTRA_FILESYSTEMS now correctly registers every listed mount when multiple entries sit behind systemd-automount (or any other pseudo-device that reuses a single device identifier across mounts).

Fixes #1931.

Why

agent/disk.go's registerFilesystemStats dedupes by device-derived key. For most real devices that's correct — /dev/sda1 can only be mounted in one place at a time. But x-systemd.automount reports every mount with the literal device systemd-1, so the fsStats key collides on the first entry and every subsequent mount is silently dropped (no log line, no error).

Reporter's config, which should register two disks, only surfaces one:

EXTRA_FILESYSTEMS=/media/video__Video,/media/backup__Backup
INFO Detected disk name=Video device=systemd-1 mount=/media/video io=systemd-1 root=false
DEBUG Extra FS data=map[Video:0x...]

Only Video ever makes it into fsStats; Backup is silently discarded because fsStats["systemd-1"] was already set.

How

registerFilesystemStats now distinguishes two "existing key" cases:

  1. Same mountpoint already registered — real duplicate. Still rejected with ok=false (the old behaviour).
  2. Different mountpoint under the same key — pseudo-device collision. Fall back to a unique key derived from the mountpoint basename (/media/backupbackup), with a -N suffix if that basename also collides.

A small uniqueFsStatsKey helper encapsulates the basename/suffix logic.

Before / After

For EXTRA_FILESYSTEMS=/media/video__Video,/media/backup__Backup:

v0.18.7 After
fsStats keys {"systemd-1": Video} {"systemd-1": Video, "backup": Backup}
Mounts visible in UI Video only Video and Backup

No change for any setup where the device key uniquely identifies the mount (i.e. every real block device). The new path only triggers on key collisions, so existing user-visible names stay stable.

Test plan

systemd-automount (x-systemd.automount in fstab) reports the same device
name — "systemd-1" — for every automount target. `registerFilesystemStats`
dedupes by key, so only the first mount survived and every additional
mount in `EXTRA_FILESYSTEMS` was silently dropped with no log line.

Before, the agent log showed only Video for:
  EXTRA_FILESYSTEMS=/media/video__Video,/media/backup__Backup
because both were registered under key "systemd-1" and the second call
hit the "already exists" short-circuit.

The dedupe check now distinguishes two cases:
 * same mountpoint under an existing key → still rejected (genuine
   double-registration)
 * different mountpoint under an existing key → fall back to a unique
   key derived from the mountpoint basename (with a -N suffix if that
   collides too)

The original "skips existing key" test is updated to describe the real
case (same mount re-registered) and two new tests cover the pseudo-device
collision and the suffix-disambiguation paths.

Fixes henrygd#1931
@BootstrapperSBL
Copy link
Copy Markdown
Contributor Author

Hey, just checking if you've had a chance to look at this — happy to adjust anything if needed.

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.

[Bug]: Binary agent only detects one EXTRA_FILESYSTEMS mount when multiple systemd automount filesystems are configured

1 participant