From 7ba02d3153814f419fdf9bcdcb08a0216557544e Mon Sep 17 00:00:00 2001 From: LeandroSaldivarmrf Date: Mon, 18 May 2026 15:31:08 -0300 Subject: [PATCH] fix(filesystem): add comma separator in mountOptionsString mountOptionsString() was concatenating mount options without a separator, so isFilesystemReadOnly()'s strings.Split(opts, ",") could never find "ro" when it appeared alongside other options. As a result node_filesystem_readonly incorrectly reported 0 for any multi-option read-only mount, including ZFS filesystems mounted read-only and ext4 filesystems after a kernel emergency remount-ro triggered by errors=remount-ro. Also preallocate the slice with len(m) capacity, as suggested in review on #3507, to avoid repeated reallocations during append. Fixes: #3484 Fixes: #3576 Co-authored-by: Ray Tien Signed-off-by: LeandroSaldivarmrf --- collector/filesystem_linux.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/collector/filesystem_linux.go b/collector/filesystem_linux.go index 3739f0fee8..a5c53df0a8 100644 --- a/collector/filesystem_linux.go +++ b/collector/filesystem_linux.go @@ -16,7 +16,6 @@ package collector import ( - "bytes" "errors" "fmt" "log/slog" @@ -237,13 +236,13 @@ func isFilesystemReadOnly(labels filesystemLabels) bool { } func mountOptionsString(m map[string]string) string { - b := new(bytes.Buffer) + parts := make([]string, 0, len(m)) for key, value := range m { if value == "" { - fmt.Fprintf(b, "%s", key) + parts = append(parts, key) } else { - fmt.Fprintf(b, "%s=%s", key, value) + parts = append(parts, key+"="+value) } } - return b.String() + return strings.Join(parts, ",") }