From c76239b1d40df4aead0dd9f04f8161cc17d8f4cd Mon Sep 17 00:00:00 2001 From: rcourtman Date: Wed, 3 Dec 2025 14:06:15 +0000 Subject: [PATCH] fix: Filter container overlay mounts in non-standard locations Detect container overlay filesystem paths from various container runtimes (Docker, Podman, LXC, EnhanceCP, etc.) that may not be in standard /var/lib/docker or /var/lib/containers locations. Paths containing /containers/ with overlay patterns (/overlay2/, /overlay/, /diff/, /merged) are now filtered from disk usage aggregation. Related to #790 --- pkg/fsfilters/filters.go | 23 +++++++++++++++++++++++ pkg/fsfilters/filters_test.go | 6 ++++++ 2 files changed, 29 insertions(+) diff --git a/pkg/fsfilters/filters.go b/pkg/fsfilters/filters.go index 93f2fc7..8d6b9a4 100644 --- a/pkg/fsfilters/filters.go +++ b/pkg/fsfilters/filters.go @@ -86,9 +86,21 @@ var specialMountPrefixes = []string{ "/sys", "/run", "/var/lib/docker", + "/var/lib/containers", "/snap", } +// containerOverlayPatterns detect container overlay filesystem paths from various +// container runtimes (Docker, Podman, LXC, EnhanceCP, etc.) that may not be in +// standard locations. These paths should be excluded from disk usage as they +// represent container layers, not actual storage usage. +var containerOverlayPatterns = []string{ + "/overlay2/", + "/overlay/", + "/diff/", + "/merged", +} + // ShouldSkipFilesystem determines if a filesystem should be excluded from disk // usage aggregation. It checks for read-only filesystems, virtual/pseudo filesystems, // network mounts, and special system mountpoints. Returns skip=true if the filesystem @@ -132,5 +144,16 @@ func ShouldSkipFilesystem(fsType, mountpoint string, totalBytes, usedBytes uint6 reasons = append(reasons, "special-mountpoint") } + // Check for container overlay paths from various runtimes in non-standard locations + // (e.g., /var/local/enhance/containers/*/overlay/merged). Related to #790. + if strings.Contains(mountpoint, "/containers/") { + for _, pattern := range containerOverlayPatterns { + if strings.Contains(mountpoint, pattern) { + reasons = append(reasons, "container-overlay") + break + } + } + } + return len(reasons) > 0, reasons } diff --git a/pkg/fsfilters/filters_test.go b/pkg/fsfilters/filters_test.go index 7ee28cb..4af2622 100644 --- a/pkg/fsfilters/filters_test.go +++ b/pkg/fsfilters/filters_test.go @@ -173,6 +173,12 @@ func TestShouldSkipFilesystem(t *testing.T) { {"/var/lib/docker", "ext4", "/var/lib/docker/overlay2", 1000000, 500000, true}, {"/snap prefix", "ext4", "/snap/core/12345", 1000000, 500000, true}, {"/boot/efi exact", "vfat", "/boot/efi", 512 * 1024 * 1024, 50 * 1024 * 1024, true}, + {"/var/lib/containers podman", "ext4", "/var/lib/containers/storage/overlay/abc123/merged", 1000000, 500000, true}, + + // Container overlay paths in non-standard locations (issue #790) + {"enhance containers overlay", "ext4", "/var/local/enhance/containers/abc123/overlay/merged", 1000000, 500000, true}, + {"custom containers diff", "ext4", "/opt/containers/myapp/diff/layer", 1000000, 500000, true}, + {"custom containers overlay2", "ext4", "/data/containers/xyz/overlay2/layer1", 1000000, 500000, true}, // Windows paths {"Windows System Reserved", "NTFS", "System Reserved", 500 * 1024 * 1024, 100 * 1024 * 1024, true},