Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use /proc/mounts instead of statfs(2) for ro state #1002

Merged
merged 1 commit into from
Jul 16, 2018

Conversation

bgilmore
Copy link
Contributor

Fixes #591 with the approach discussed by @SuperQ and @discordianfish

I verified that this exports correctly on a very troubled test machine.

@@ -59,8 +59,15 @@ func (c *filesystemCollector) GetStats() ([]filesystemStats, error) {
}

var ro float64
if (buf.Flags & readOnly) != 0 {
ro = 1
OPTIONS:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of label jumps. Is there a better way to do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dislike them too, but I thought the equivalent conditional was sort of ugly.

		var ro float64
		for _, option := range strings.Split(labels.options, ",") {
			if option == "ro" {
				ro = 1
				break
			}
			if option == "rw" {
				break
			}
		}

A switch statement seems more idiomatic but I'm happy to change styles for sake of dropping labels.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, a switch would be better.

Is there really a need to break? The efficiency gain is probably minimal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason to break is a minimal efficiency gain ;-)

Dropped the branching since, to your point, we're only scanning tens of bytes.

Cheers.

While the statfs(2) approach is reliable for normally mounted filesystems, the
flags returned can be inconsistent when filesystem has been remounted read-only
after encountering an error. The returned flags do accurately represent the
internal state of the filesystem, but they do not reflect whether the VFS layer
will accept writes. Instead, it makes sense to parse the current VFS mount
state from the options field in /proc/mounts since it takes precedence.

Signed-off-by: Brandon Gilmore <bgilmore@valvesoftware.com>
@bgilmore
Copy link
Contributor Author

Sorry for squashing your code review @SuperQ. I didn't realize the comments would be lost like tears in the rain.

I'd be happy to resolve the build failure if it's a side effect of my change, but I'm unable to see the details.

@SuperQ
Copy link
Member

SuperQ commented Jul 13, 2018

Yea, buildkite is somewhat annoying that way. The failures are due to openbsd test VMs running out of disk space. 😭 I'll see about fixing those.

Copy link
Member

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@SuperQ
Copy link
Member

SuperQ commented Jul 16, 2018

The buildkite error is unrelated (OpenBSD build server problems), so I'm going to merge this.

@SuperQ SuperQ merged commit 76bbd8d into prometheus:master Jul 16, 2018
@bgilmore bgilmore deleted the issue-591 branch July 16, 2018 15:20
SuperQ pushed a commit that referenced this pull request Nov 30, 2018
The pull request #1002 changed the logic used on Linux servers to determine if a filesystem is
read-only. As a result of this change, the variable `readOnly` is now unused and can be removed.

Signed-off-by: Jerome Froelich <jeromefroelich@hotmail.com>
oblitorum pushed a commit to shatteredsilicon/node_exporter that referenced this pull request Apr 9, 2024
While the statfs(2) approach is reliable for normally mounted filesystems, the
flags returned can be inconsistent when filesystem has been remounted read-only
after encountering an error. The returned flags do accurately represent the
internal state of the filesystem, but they do not reflect whether the VFS layer
will accept writes. Instead, it makes sense to parse the current VFS mount
state from the options field in /proc/mounts since it takes precedence.

Signed-off-by: Brandon Gilmore <bgilmore@valvesoftware.com>
oblitorum pushed a commit to shatteredsilicon/node_exporter that referenced this pull request Apr 9, 2024
…#1173)

The pull request prometheus#1002 changed the logic used on Linux servers to determine if a filesystem is
read-only. As a result of this change, the variable `readOnly` is now unused and can be removed.

Signed-off-by: Jerome Froelich <jeromefroelich@hotmail.com>
oblitorum pushed a commit to shatteredsilicon/node_exporter that referenced this pull request Apr 9, 2024
…#1173)

The pull request prometheus#1002 changed the logic used on Linux servers to determine if a filesystem is
read-only. As a result of this change, the variable `readOnly` is now unused and can be removed.

Signed-off-by: Jerome Froelich <jeromefroelich@hotmail.com>
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.

2 participants