MCPcopy Create free account
hub / github.com/prometheus/procfs / DMMultipathDevices

Method DMMultipathDevices

blockdevice/dm_multipath.go:57–114  ·  view source on GitHub ↗

DMMultipathDevices discovers DM-multipath devices by scanning sys/block/dm-* and filtering on dm/uuid prefix "mpath-". It returns a slice of DMMultipathDevice structs. If no multipath devices are found, it returns an empty (non-nil) slice and no error.

()

Source from the content-addressed store, hash-verified

55// It returns a slice of DMMultipathDevice structs. If no multipath devices
56// are found, it returns an empty (non-nil) slice and no error.
57func (fs FS) DMMultipathDevices() ([]DMMultipathDevice, error) {
58 blockDir := fs.sys.Path(sysBlockPath)
59
60 entries, err := os.ReadDir(blockDir)
61 if err != nil {
62 return nil, err
63 }
64
65 devices := make([]DMMultipathDevice, 0)
66 for _, entry := range entries {
67 if !strings.HasPrefix(entry.Name(), "dm-") {
68 continue
69 }
70
71 uuid, err := parsers.SysReadFile(fs.sys.Path(sysBlockPath, entry.Name(), sysBlockDM, "uuid"))
72 if err != nil {
73 // dm/uuid missing means this is not a device-mapper device; skip it.
74 if os.IsNotExist(err) {
75 continue
76 }
77 return nil, fmt.Errorf("failed to read dm/uuid for %s: %w", entry.Name(), err)
78 }
79 if !strings.HasPrefix(uuid, "mpath-") {
80 continue
81 }
82
83 name, err := parsers.SysReadFile(fs.sys.Path(sysBlockPath, entry.Name(), sysBlockDM, "name"))
84 if err != nil {
85 return nil, fmt.Errorf("failed to read dm/name for %s: %w", entry.Name(), err)
86 }
87
88 suspendedVal, err := parsers.ReadUintFromFile(fs.sys.Path(sysBlockPath, entry.Name(), sysBlockDM, "suspended"))
89 if err != nil {
90 return nil, fmt.Errorf("failed to read dm/suspended for %s: %w", entry.Name(), err)
91 }
92
93 sectors, err := parsers.ReadUintFromFile(fs.sys.Path(sysBlockPath, entry.Name(), sysBlockSize))
94 if err != nil {
95 return nil, fmt.Errorf("failed to read size for %s: %w", entry.Name(), err)
96 }
97
98 paths, err := fs.dmMultipathPaths(entry.Name())
99 if err != nil {
100 return nil, err
101 }
102
103 devices = append(devices, DMMultipathDevice{
104 Name: name,
105 SysfsName: entry.Name(),
106 UUID: uuid,
107 Suspended: suspendedVal == 1,
108 SizeBytes: sectors * procfs.SectorSize,
109 Paths: paths,
110 })
111 }
112
113 return devices, nil
114}

Calls 5

dmMultipathPathsMethod · 0.95
SysReadFileFunction · 0.92
ReadUintFromFileFunction · 0.92
NameMethod · 0.80
PathMethod · 0.45

Tested by 2

TestDMMultipathDevicesFunction · 0.76