parseMountStats parses a /proc/[pid]/mountstats file and returns a slice of Mount structures containing detailed information about each mount. If available, statistics for each mount are parsed as well.
(r io.Reader)
| 272 | // of Mount structures containing detailed information about each mount. |
| 273 | // If available, statistics for each mount are parsed as well. |
| 274 | func parseMountStats(r io.Reader) ([]*Mount, error) { |
| 275 | const ( |
| 276 | device = "device" |
| 277 | statVersionPrefix = "statvers=" |
| 278 | |
| 279 | nfs3Type = "nfs" |
| 280 | nfs4Type = "nfs4" |
| 281 | ) |
| 282 | |
| 283 | var mounts []*Mount |
| 284 | |
| 285 | s := bufio.NewScanner(r) |
| 286 | for s.Scan() { |
| 287 | // Only look for device entries in this function |
| 288 | ss := strings.Fields(string(s.Bytes())) |
| 289 | if len(ss) == 0 || ss[0] != device { |
| 290 | continue |
| 291 | } |
| 292 | |
| 293 | m, err := parseMount(ss) |
| 294 | if err != nil { |
| 295 | return nil, err |
| 296 | } |
| 297 | |
| 298 | // Does this mount also possess statistics information? |
| 299 | if len(ss) > deviceEntryLen { |
| 300 | // Only NFSv3 and v4 are supported for parsing statistics |
| 301 | if m.Type != nfs3Type && m.Type != nfs4Type { |
| 302 | return nil, fmt.Errorf("%w: Cannot parse MountStats for %q", ErrFileParse, m.Type) |
| 303 | } |
| 304 | |
| 305 | statVersion := strings.TrimPrefix(ss[8], statVersionPrefix) |
| 306 | |
| 307 | stats, err := parseMountStatsNFS(s, statVersion) |
| 308 | if err != nil { |
| 309 | return nil, err |
| 310 | } |
| 311 | |
| 312 | m.Stats = stats |
| 313 | } |
| 314 | |
| 315 | mounts = append(mounts, m) |
| 316 | } |
| 317 | |
| 318 | return mounts, s.Err() |
| 319 | } |
| 320 | |
| 321 | // parseMount parses an entry in /proc/[pid]/mountstats in the format: |
| 322 | // |
searching dependent graphs…