Skip to content

Commit

Permalink
support multi tmpfs in cadvisor
Browse files Browse the repository at this point in the history
Signed-off-by: Zou Nengren <zouyee1989@gmail.com>
  • Loading branch information
zouyee committed Nov 26, 2019
1 parent c9261a8 commit 976f231
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 8 additions & 2 deletions fs/fs.go
Expand Up @@ -176,9 +176,11 @@ func processMounts(mounts []*mount.Info, excludedMountpointPrefixes []string) ma
if !strings.HasPrefix(mount.Fstype, "ext") && !supportedFsType[mount.Fstype] {
continue
}
// Avoid bind mounts.
// Avoid bind mounts, exclude tmpfs.
if _, ok := partitions[mount.Source]; ok {
continue
if mount.Fstype != "tmpfs" {
continue
}
}

hasPrefix := false
Expand All @@ -192,6 +194,10 @@ func processMounts(mounts []*mount.Info, excludedMountpointPrefixes []string) ma
continue
}

// using mountpoint to replace device once fstype it tmpfs
if mount.Fstype == "tmpfs" {
mount.Source = mount.Mountpoint
}
// btrfs fix: following workaround fixes wrong btrfs Major and Minor Ids reported in /proc/self/mountinfo.
// instead of using values from /proc/self/mountinfo we use stat to get Ids from btrfs mount point
if mount.Fstype == "btrfs" && mount.Major == 0 && strings.HasPrefix(mount.Source, "/dev/") {
Expand Down
4 changes: 4 additions & 0 deletions fs/fs_test.go
Expand Up @@ -517,6 +517,8 @@ func TestProcessMounts(t *testing.T) {
{Root: "/", Mountpoint: "/d", Source: "/dev/sdd", Fstype: "xfs", Major: 253, Minor: 3},
{Root: "/", Mountpoint: "/e", Source: "/dev/sde", Fstype: "zfs", Major: 253, Minor: 4},
{Root: "/", Mountpoint: "/f", Source: "overlay", Fstype: "overlay", Major: 253, Minor: 5},
{Root: "/", Mountpoint: "/test1", Source: "tmpfs", Fstype: "tmpfs", Major: 253, Minor: 4},
{Root: "/", Mountpoint: "/test2", Source: "tmpfs", Fstype: "tmpfs", Major: 253, Minor: 4},
},
expected: map[string]partition{
"/dev/sda": {fsType: "ext3", mountpoint: "/a", major: 253, minor: 0},
Expand All @@ -525,6 +527,8 @@ func TestProcessMounts(t *testing.T) {
"/dev/sdd": {fsType: "xfs", mountpoint: "/d", major: 253, minor: 3},
"/dev/sde": {fsType: "zfs", mountpoint: "/e", major: 253, minor: 4},
"overlay_253-5": {fsType: "overlay", mountpoint: "/f", major: 253, minor: 5},
"/test1": {fsType: "tmpfs", mountpoint: "/test1", major: 253, minor: 4},
"/test2": {fsType: "tmpfs", mountpoint: "/test2", major: 253, minor: 4},
},
},
}
Expand Down

0 comments on commit 976f231

Please sign in to comment.