Skip to content

inputs/diskio: honour HOST_MOUNT_PREFIX / HOST_DEV#18732

Closed
SAY-5 wants to merge 1 commit intoinfluxdata:masterfrom
SAY-5:fix-diskio-host-mount-prefix-18671
Closed

inputs/diskio: honour HOST_MOUNT_PREFIX / HOST_DEV#18732
SAY-5 wants to merge 1 commit intoinfluxdata:masterfrom
SAY-5:fix-diskio-host-mount-prefix-18671

Conversation

@SAY-5
Copy link
Copy Markdown
Contributor

@SAY-5 SAY-5 commented Apr 17, 2026

Fixes #18671.

Problem

When telegraf runs inside a container with HOST_MOUNT_PREFIX=/hostfs (and friends), the [[inputs.diskio]] plugin still hard-codes /dev/, /sys/, and /run/udev/:

W! [inputs.diskio] Unable to gather disk name for "mmcblk0p1":
    error reading /dev/mmcblk0p1: no such file or directory

The paths that needed updating are:

  • /dev/<name> (unix.Stat check)
  • /run/udev/data/b<major>:<minor> (udev data)
  • /dev/.udev/db/block:<name> (non-systemd fallback)
  • /sys/class/block/<name> (sys block entry)
  • /dev/<name> (EvalSymlinks in resolveName)
  • /sys/block/<name>/wwid (wwid reader)

Fix

Two changes:

  1. internal/env.go: add GetDevPath() and GetRunPath() helpers that mirror the existing GetProcPath() / GetSysPath() pattern. Each prefers its explicit env var (HOST_DEV, HOST_RUN), falls back to HOST_MOUNT_PREFIX/<subdir> so a single HOST_MOUNT_PREFIX=/hostfs covers /proc, /sys, /dev, /run, and falls back to the real paths on bare metal. GetSysPath() also gets the HOST_MOUNT_PREFIX fallback so it matches the others.

  2. plugins/inputs/diskio/diskio_linux.go: switch every filesystem-access path to build via filepath.Join(internal.GetDevPath(), ...) / internal.GetSysPath() / internal.GetRunPath(). The two places that construct tag strings destined for metrics (DEVLINKS, DEVNAME) keep their "/dev/..." format because those are identifiers, not filesystem paths.

No configuration changes required; existing containers that already set HOST_MOUNT_PREFIX simply start working.

Signed off per DCO.

Reported as influxdata#18671. When telegraf runs inside a
container and the host devices are mounted under /hostfs, diskio
still hard-codes /dev, /sys, and /run/udev when it reads:

    /dev/<name>                              (Stat)
    /run/udev/data/bMAJOR:MINOR              (os.Stat)
    /dev/.udev/db/block:<name>               (os.Stat)
    /sys/class/block/<name>                  (os.Open uevent)
    /dev/<name>                              (EvalSymlinks in resolveName)
    /sys/block/<name>/wwid                   (os.ReadFile)

so every device shows up in logs as "no such file or directory",
even though telegraf is otherwise configured with HOST_PROC,
HOST_SYS, HOST_ETC, HOST_RUN, HOST_DEV and HOST_MOUNT_PREFIX like
every other input plugin documents.

Add GetDevPath() and GetRunPath() helpers in internal/env.go that
mirror the existing GetProcPath() / GetSysPath() pattern: prefer
HOST_DEV / HOST_RUN, fall back to HOST_MOUNT_PREFIX/<subdir>, fall
back to the real paths on bare metal. GetSysPath() gets the same
HOST_MOUNT_PREFIX fallback. Switch diskio_linux.go to build every
filesystem-access path via filepath.Join through these helpers. The
two places that construct tag strings destined for metrics
(DEVLINKS, DEVNAME) keep their "/dev/..." format, since those values
are identifiers, not filesystem paths.

No configuration changes required; plugins that already set
HOST_MOUNT_PREFIX just start working.

Fixes influxdata#18671

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@srebhan
Copy link
Copy Markdown
Member

srebhan commented Apr 17, 2026

@SAY-5 please restore the PR description template as we cannot review your PR otherwise! The template is there for a reason!

Furthermore, this PR seems like a one-to-one copy of PR #18682, so what is the additional benefit of this PR?

@srebhan srebhan added the waiting for response waiting for response from contributor label Apr 17, 2026
@srebhan srebhan self-assigned this Apr 17, 2026
@telegraf-tiger
Copy link
Copy Markdown
Contributor

@SAY-5
Copy link
Copy Markdown
Contributor Author

SAY-5 commented Apr 17, 2026

Closing as duplicate of #18682 (didn't see the existing open PR against #18671). Apologies for the noise, will search more carefully.

@SAY-5 SAY-5 closed this Apr 17, 2026
@telegraf-tiger telegraf-tiger Bot removed the waiting for response waiting for response from contributor label Apr 17, 2026
@srebhan
Copy link
Copy Markdown
Member

srebhan commented Apr 17, 2026

Sorry if I sounded rude! Thanks for caring about this project!

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.

[[inputs.diskio]] not honoring HOST_MOUNT_PREFIX / Missing HOST_DEV environment variable

2 participants