diff --git a/container/raw/container_hints.go b/container/raw/container_hints.go index e63d1441..64d72f84 100644 --- a/container/raw/container_hints.go +++ b/container/raw/container_hints.go @@ -38,8 +38,8 @@ type containerHint struct { } type mount struct { - HostDir string `json:"host-dir,omitempty"` - ContainerDir string `json:"container-dir,omitempty"` + HostDir string `json:"host_dir,omitempty"` + ContainerDir string `json:"container_dir,omitempty"` } type networkInterface struct { diff --git a/container/raw/handler.go b/container/raw/handler.go index c8eee8e8..12f00e0b 100644 --- a/container/raw/handler.go +++ b/container/raw/handler.go @@ -190,11 +190,11 @@ func (self *rawContainerHandler) getFsStats(stats *info.ContainerStats) error { for _, fs := range filesystems { stats.Filesystem = append(stats.Filesystem, info.FsStats{fs.Device, fs.Capacity, fs.Capacity - fs.Free}) } - } else if self.mounts != nil { - var mountSet map[string]bool - mountSet = make(map[string]bool) + } else if len(self.mounts) > 0 { + var mountSet map[string]struct{} + mountSet = make(map[string]struct{}) for _, mount := range self.mounts { - mountSet[mount.HostDir] = true + mountSet[mount.HostDir] = struct{}{} } filesystems, err := self.fsInfo.GetFsInfoForPath(mountSet) if err != nil { diff --git a/container/raw/test_resources/container_hints.json b/container/raw/test_resources/container_hints.json index d6d95fb8..d8842e55 100644 --- a/container/raw/test_resources/container_hints.json +++ b/container/raw/test_resources/container_hints.json @@ -9,28 +9,28 @@ }, "mounts": [ { - "host-dir": "/var/run/nm-sdc1", - "container-dir": "/var/run/nm-sdc1", + "host_dir": "/var/run/nm-sdc1", + "container_dir": "/var/run/nm-sdc1", "permission": "rw" }, { - "host-dir": "/var/run/nm-sdb3", - "container-dir": "/var/run/nm-sdb3", + "host_dir": "/var/run/nm-sdb3", + "container_dir": "/var/run/nm-sdb3", "permission": "rw" }, { - "host-dir": "/var/run/nm-sda3", - "container-dir": "/var/run/nm-sda3", + "host_dir": "/var/run/nm-sda3", + "container_dir": "/var/run/nm-sda3", "permission": "rw" }, { - "host-dir": "/var/run/netns/root", - "container-dir": "/var/run/netns/root", + "host_dir": "/var/run/netns/root", + "container_dir": "/var/run/netns/root", "permission": "ro" }, { - "host-dir": "/var/run/openvswitch/db.sock", - "container-dir": "/var/run/openvswitch/db.sock", + "host_dir": "/var/run/openvswitch/db.sock", + "container_dir": "/var/run/openvswitch/db.sock", "permission": "rw" } ], diff --git a/fs/fs.go b/fs/fs.go index b1830ba9..db492ff6 100644 --- a/fs/fs.go +++ b/fs/fs.go @@ -50,16 +50,18 @@ func NewFsInfo() (FsInfo, error) { return &RealFsInfo{partitions}, nil } -func (self *RealFsInfo) GetFsInfoForPath(mountSet map[string]bool) ([]Fs, error) { +func (self *RealFsInfo) GetFsInfoForPath(mountSet map[string]struct{}) ([]Fs, error) { filesystems := make([]Fs, 0) - deviceSet := make(map[string]bool) + deviceSet := make(map[string]struct{}) for device, partition := range self.partitions { - if mountSet == nil || mountSet[partition.mountpoint] == true { + _, hasMount := mountSet[partition.mountpoint] + _, hasDevice := deviceSet[device] + if mountSet == nil || hasMount && !hasDevice { total, free, err := getVfsStats(partition.mountpoint) if err != nil { glog.Errorf("Statvfs failed. Error: %v", err) - } else if deviceSet[device] == false { - deviceSet[device] = true + } else { + deviceSet[device] = struct{}{} deviceInfo := DeviceInfo{ Device: device, Major: uint(partition.major), diff --git a/fs/types.go b/fs/types.go index c27fe99a..3d54ecb6 100644 --- a/fs/types.go +++ b/fs/types.go @@ -17,7 +17,7 @@ type FsInfo interface { GetGlobalFsInfo() ([]Fs, error) // Returns capacity and free space, in bytes, of the set of mounts passed. - GetFsInfoForPath(mountSet map[string]bool) ([]Fs, error) + GetFsInfoForPath(mountSet map[string]struct{}) ([]Fs, error) // Returns number of bytes occupied by 'dir'. GetDirUsage(dir string) (uint64, error)