Skip to content

Commit 00b3ef8

Browse files
author
Liu Hua
committed
libct/cg: skip hidden ones when parsing cgroup mounts
According to [1], "If a new mount is stacked on top of a previous existing mount, at pathname P, then the parent of the new mount is the previous mount at that location" Use this strategy to skip hidden cgroup mount. 1. https://man7.org/linux/man-pages/man5/proc.5.html Signed-off-by: Liu Hua <[email protected]>
1 parent ba58ee9 commit 00b3ef8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

libcontainer/cgroups/v1_utils.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8+
"sort"
89
"strings"
910
"sync"
1011
"syscall"
@@ -165,7 +166,22 @@ func (m Mount) GetOwnCgroup(cgroups map[string]string) (string, error) {
165166
func getCgroupMountsHelper(ss map[string]bool, mounts []*mountinfo.Info, all bool) ([]Mount, error) {
166167
res := make([]Mount, 0, len(ss))
167168
numFound := 0
169+
parentIDs := make([]int, 0, len(mounts))
168170
for _, mi := range mounts {
171+
parentIDs = append(parentIDs, mi.Parent)
172+
}
173+
174+
sort.Slice(parentIDs, func(i, j int) bool {
175+
return parentIDs[i] < parentIDs[j]
176+
})
177+
178+
for _, mi := range mounts {
179+
// This mount is hidden by other mount
180+
// at the same mountpoint, so skip it.
181+
if sort.SearchInts(parentIDs, mi.ID) < len(parentIDs) {
182+
continue
183+
}
184+
169185
m := Mount{
170186
Mountpoint: mi.Mountpoint,
171187
Root: mi.Root,

0 commit comments

Comments
 (0)