Skip to content

Commit de23fc4

Browse files
authored
Remove /proc/mounts fallback support. (#754)
Previously if `/proc/1/mountinfo` does not exist, `/proc/mounts` is used to probe mounts as a fallback. As /proc/mounts has lack of information about bind mounts, the fallback support is removed. Signed-off-by: Bala.FA <bala@minio.io>
1 parent 378b953 commit de23fc4

File tree

1 file changed

+2
-80
lines changed

1 file changed

+2
-80
lines changed

pkg/sys/mount_linux.go

+2-80
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"syscall"
2929

3030
"github.com/minio/directpv/pkg/utils"
31-
"golang.org/x/sys/unix"
3231
"k8s.io/klog/v2"
3332
)
3433

@@ -93,91 +92,14 @@ func parseProc1Mountinfo(r io.Reader) (mountPointMap, deviceMap, majorMinorMap,
9392
return
9493
}
9594

96-
func getMajorMinor(device string) (majorMinor string, err error) {
97-
stat := syscall.Stat_t{}
98-
if err = syscall.Stat(device, &stat); err == nil {
99-
majorMinor = fmt.Sprintf("%v:%v", unix.Major(stat.Rdev), unix.Minor(stat.Rdev))
100-
}
101-
return
102-
}
103-
104-
func parseProcMounts(r io.Reader, includeMajorMinorMap bool) (mountPointMap, deviceMap, majorMinorMap, rootMountPointMap map[string]utils.StringSet, err error) {
105-
reader := bufio.NewReader(r)
106-
107-
mountPointMap = make(map[string]utils.StringSet)
108-
deviceMap = make(map[string]utils.StringSet)
109-
for {
110-
s, err := reader.ReadString('\n')
111-
if err != nil {
112-
if errors.Is(err, io.EOF) {
113-
break
114-
}
115-
return nil, nil, nil, nil, err
116-
}
117-
118-
// Refer /proc/mounts section in https://man7.org/linux/man-pages/man5/proc.5.html
119-
// to know about this logic.
120-
tokens := strings.Fields(strings.TrimSpace(s))
121-
if len(tokens) < 2 {
122-
continue
123-
}
124-
125-
mountPoint := tokens[1]
126-
device := tokens[0]
127-
128-
if _, found := mountPointMap[mountPoint]; !found {
129-
mountPointMap[mountPoint] = make(utils.StringSet)
130-
}
131-
mountPointMap[mountPoint].Set(device)
132-
133-
if _, found := deviceMap[device]; !found {
134-
deviceMap[device] = make(utils.StringSet)
135-
}
136-
deviceMap[device].Set(mountPoint)
137-
}
138-
139-
if !includeMajorMinorMap {
140-
return
141-
}
142-
143-
majorMinorMap = make(map[string]utils.StringSet)
144-
for device := range deviceMap {
145-
// Ignore pseudo devices.
146-
if !strings.HasPrefix(device, "/") {
147-
continue
148-
}
149-
150-
majorMinor, err := getMajorMinor(device)
151-
if err != nil {
152-
return nil, nil, nil, nil, err
153-
}
154-
155-
if _, found := majorMinorMap[device]; !found {
156-
majorMinorMap[majorMinor] = make(utils.StringSet)
157-
}
158-
majorMinorMap[majorMinor].Set(device)
159-
}
160-
161-
return
162-
}
163-
164-
func getMounts(includeMajorMinorMap bool) (mountPointMap, deviceMap, majorMinorMap, rootMountPointMap map[string]utils.StringSet, err error) {
95+
func getMounts(_ bool) (mountPointMap, deviceMap, majorMinorMap, rootMountPointMap map[string]utils.StringSet, err error) {
16596
file, err := os.Open("/proc/1/mountinfo")
16697
if err != nil {
167-
if !errors.Is(err, os.ErrNotExist) {
168-
return nil, nil, nil, nil, err
169-
}
170-
} else {
171-
defer file.Close()
172-
return parseProc1Mountinfo(file)
173-
}
174-
175-
if file, err = os.Open("/proc/mounts"); err != nil {
17698
return nil, nil, nil, nil, err
17799
}
178100

179101
defer file.Close()
180-
return parseProcMounts(file, includeMajorMinorMap)
102+
return parseProc1Mountinfo(file)
181103
}
182104

183105
var mountFlagMap = map[string]uintptr{

0 commit comments

Comments
 (0)