fix(disk/aix): use statfs for UsageWithContext on AIX - #2136
Conversation
The AIX UsageWithContext implementations (cgo and nocgo) enumerated mountpoints via perfstat or `df -v` and matched the requested path exactly, so disk.Usage failed with "mountpoint %s not found" for any path that wasn't a mountpoint (e.g. a subdirectory). Add aix to the build tag of disk_unix.go so AIX reuses the existing statfs(2)-based UsageWithContext, which works on arbitrary paths. AIX's Statfs_t has all the block/inode fields needed. Move the FSType map and getFsType helper to the shared disk_aix.go so disk_unix.go can resolve getFsType on AIX. Only AIX changes; other OSes are unaffected.
ebe8271 to
e4a282c
Compare
shirou
left a comment
There was a problem hiding this comment.
Merging this — thank you so much! Nice cleanup, and it's also a return to what we had: until May 2024 disk_unix.go was tagged ... || (aix && !cgo) and AIX nocgo used this same statfs path; #1651 swapped in the df -v parser with no stated reason.
One thing I'd like on the record here, if you don't mind answering after the fact: AIX's statfs has both f_bsize and f_fsize, and the shared code scales the block counts by Bsize. On JFS2 the two are identical, but classic JFS has fragments — does Blocks * Bsize still give the right total there? I couldn't reach IBM's docs to check either way. "JFS2 is what matters in practice" is a perfectly good answer — I just want it written down, so whoever hits a wrong Total on AIX later has a place to start. Whichever build and filesystem types you checked against would be useful in the same breath.
Two things I'll take care of separately, nothing for you to do:
- The removed cgo
UsageWithContextfell back to"unknown"for unmapped vfstypes andPartitionsWithContextstill does, so a cgo build now reports"unknown"fromPartitions()and""fromUsage().""matches the other platforms, so I'll leavegetFsTypeas is and alignPartitions()on its own. - On nocgo the values shift slightly: the old parser read
%Used/%IusedwithParseInt(always whole numbers) and tookFreefrom df's column rather thanBavail. The new ones are better —Used/(Used+Free)is the project-wide convention from #562 — I'll note the change in the release notes.
No tests needed; we have no AIX runner. For context, our lint matrix also only builds AIX with CGO_ENABLED=0 (the cgo row is commented out with a # FIXME), so CI doesn't cover the side this PR actually changes. That's our gap, not yours.
… in /e2e-go in the go-modules group [skip ci] Bumps the go-modules group in /e2e-go with 1 update: [github.com/shirou/gopsutil/v4](https://github.com/shirou/gopsutil). Updates `github.com/shirou/gopsutil/v4` from 4.26.7 to 4.26.8 Release notes *Sourced from [github.com/shirou/gopsutil/v4's releases](https://github.com/shirou/gopsutil/releases).* > v4.26.8 > ------- > > What's Changed > -------------- > > ### cpu > > * Fix CI Lint and pin version by [`@shirou`](https://github.com/shirou) in [shirou/gopsutil#2138](https://redirect.github.com/shirou/gopsutil/pull/2138) > > ### disk > > * fix(disk/aix): use statfs for UsageWithContext on AIX by [`@pgimalac`](https://github.com/pgimalac) in [shirou/gopsutil#2136](https://redirect.github.com/shirou/gopsutil/pull/2136) > > ### net > > * fix(net): handle short Darwin netstat output by [`@alexfalkowski`](https://github.com/alexfalkowski) in [shirou/gopsutil#2116](https://redirect.github.com/shirou/gopsutil/pull/2116) > > ### process > > * Closes [#2126](https://redirect.github.com/shirou/gopsutil/issues/2126) Implement NtQueryInformationProcess to get commandline Windows 8.1+ by [`@Ahm3dRN`](https://github.com/Ahm3dRN) in [shirou/gopsutil#2127](https://redirect.github.com/shirou/gopsutil/pull/2127) > > ### Other Changes > > * [ci]: run the test suite on FreeBSD by [`@neilpang`](https://github.com/neilpang) in [shirou/gopsutil#2129](https://redirect.github.com/shirou/gopsutil/pull/2129) > > New Contributors > ---------------- > > * [`@alexfalkowski`](https://github.com/alexfalkowski) made their first contribution in [shirou/gopsutil#2116](https://redirect.github.com/shirou/gopsutil/pull/2116) > * [`@neilpang`](https://github.com/neilpang) made their first contribution in [shirou/gopsutil#2129](https://redirect.github.com/shirou/gopsutil/pull/2129) > * [`@Ahm3dRN`](https://github.com/Ahm3dRN) made their first contribution in [shirou/gopsutil#2127](https://redirect.github.com/shirou/gopsutil/pull/2127) > > **Full Changelog**: <shirou/gopsutil@v4.26.7...v4.26.8> Commits * [`7d254a0`](shirou/gopsutil@7d254a0) Merge pull request [#2127](https://redirect.github.com/shirou/gopsutil/issues/2127) from Ahm3dRN/windows-commandline-information * [`4dab2b9`](shirou/gopsutil@4dab2b9) Merge pull request [#2136](https://redirect.github.com/shirou/gopsutil/issues/2136) from pgimalac/aix-disk-usage-statfs * [`1ddce22`](shirou/gopsutil@1ddce22) Merge pull request [#2141](https://redirect.github.com/shirou/gopsutil/issues/2141) from shirou/dependabot/github\_actions/vmactions/free... * [`ec8a313`](shirou/gopsutil@ec8a313) chore(deps): bump vmactions/freebsd-vm from 1.5.4 to 1.5.5 * [`26ae363`](shirou/gopsutil@26ae363) Merge pull request [#2140](https://redirect.github.com/shirou/gopsutil/issues/2140) from shirou/dependabot/github\_actions/vmactions/free... * [`21afc16`](shirou/gopsutil@21afc16) chore(deps): bump vmactions/freebsd-vm from 1.5.2 to 1.5.4 * [`fbf8dd1`](shirou/gopsutil@fbf8dd1) fixed getProcessCommandLine error path to match master and refined the tests ... * [`97835bd`](shirou/gopsutil@97835bd) Windows CMDLine native fallback feedback fixes * [`3e8ab43`](shirou/gopsutil@3e8ab43) fixed gofumpt * [`4631d96`](shirou/gopsutil@4631d96) Implement NtQueryInformationProcess to get commandline Windows 8.1+ * Additional commits viewable in [compare view](shirou/gopsutil@v4.26.7...v4.26.8) [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- Dependabot commands and options You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself) - `@dependabot ignore minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself) - `@dependabot ignore ` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself) - `@dependabot unignore ` will remove all of the ignore conditions of the specified dependency - `@dependabot unignore ` will remove the ignore condition of the specified dependency and ignore conditions
Update
UsageWithContexton AIX to use the same implementation as other Unix OSes, based on thestatfssyscall.CGO_ENABLED=0caseUsageWithContextwork with arbitrary paths. The old implementations (both CGO and no-CGO) only work whenpathis exactly a mountpoint (fails withmountpoint ... not foundotherwise), whilestatfsworks properly no matter whatI confirmed getting the exact same output for real mountpoints, and it now works for non-mountpoints.