code review fixes
This commit is contained in:
parent
b8ed0bd0e3
commit
751de4a0c9
@ -38,8 +38,8 @@ type containerHint struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type mount struct {
|
type mount struct {
|
||||||
HostDir string `json:"host-dir,omitempty"`
|
HostDir string `json:"host_dir,omitempty"`
|
||||||
ContainerDir string `json:"container-dir,omitempty"`
|
ContainerDir string `json:"container_dir,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type networkInterface struct {
|
type networkInterface struct {
|
||||||
|
@ -190,11 +190,11 @@ func (self *rawContainerHandler) getFsStats(stats *info.ContainerStats) error {
|
|||||||
for _, fs := range filesystems {
|
for _, fs := range filesystems {
|
||||||
stats.Filesystem = append(stats.Filesystem, info.FsStats{fs.Device, fs.Capacity, fs.Capacity - fs.Free})
|
stats.Filesystem = append(stats.Filesystem, info.FsStats{fs.Device, fs.Capacity, fs.Capacity - fs.Free})
|
||||||
}
|
}
|
||||||
} else if self.mounts != nil {
|
} else if len(self.mounts) > 0 {
|
||||||
var mountSet map[string]bool
|
var mountSet map[string]struct{}
|
||||||
mountSet = make(map[string]bool)
|
mountSet = make(map[string]struct{})
|
||||||
for _, mount := range self.mounts {
|
for _, mount := range self.mounts {
|
||||||
mountSet[mount.HostDir] = true
|
mountSet[mount.HostDir] = struct{}{}
|
||||||
}
|
}
|
||||||
filesystems, err := self.fsInfo.GetFsInfoForPath(mountSet)
|
filesystems, err := self.fsInfo.GetFsInfoForPath(mountSet)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -9,28 +9,28 @@
|
|||||||
},
|
},
|
||||||
"mounts": [
|
"mounts": [
|
||||||
{
|
{
|
||||||
"host-dir": "/var/run/nm-sdc1",
|
"host_dir": "/var/run/nm-sdc1",
|
||||||
"container-dir": "/var/run/nm-sdc1",
|
"container_dir": "/var/run/nm-sdc1",
|
||||||
"permission": "rw"
|
"permission": "rw"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"host-dir": "/var/run/nm-sdb3",
|
"host_dir": "/var/run/nm-sdb3",
|
||||||
"container-dir": "/var/run/nm-sdb3",
|
"container_dir": "/var/run/nm-sdb3",
|
||||||
"permission": "rw"
|
"permission": "rw"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"host-dir": "/var/run/nm-sda3",
|
"host_dir": "/var/run/nm-sda3",
|
||||||
"container-dir": "/var/run/nm-sda3",
|
"container_dir": "/var/run/nm-sda3",
|
||||||
"permission": "rw"
|
"permission": "rw"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"host-dir": "/var/run/netns/root",
|
"host_dir": "/var/run/netns/root",
|
||||||
"container-dir": "/var/run/netns/root",
|
"container_dir": "/var/run/netns/root",
|
||||||
"permission": "ro"
|
"permission": "ro"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"host-dir": "/var/run/openvswitch/db.sock",
|
"host_dir": "/var/run/openvswitch/db.sock",
|
||||||
"container-dir": "/var/run/openvswitch/db.sock",
|
"container_dir": "/var/run/openvswitch/db.sock",
|
||||||
"permission": "rw"
|
"permission": "rw"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
12
fs/fs.go
12
fs/fs.go
@ -50,16 +50,18 @@ func NewFsInfo() (FsInfo, error) {
|
|||||||
return &RealFsInfo{partitions}, nil
|
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)
|
filesystems := make([]Fs, 0)
|
||||||
deviceSet := make(map[string]bool)
|
deviceSet := make(map[string]struct{})
|
||||||
for device, partition := range self.partitions {
|
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)
|
total, free, err := getVfsStats(partition.mountpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Statvfs failed. Error: %v", err)
|
glog.Errorf("Statvfs failed. Error: %v", err)
|
||||||
} else if deviceSet[device] == false {
|
} else {
|
||||||
deviceSet[device] = true
|
deviceSet[device] = struct{}{}
|
||||||
deviceInfo := DeviceInfo{
|
deviceInfo := DeviceInfo{
|
||||||
Device: device,
|
Device: device,
|
||||||
Major: uint(partition.major),
|
Major: uint(partition.major),
|
||||||
|
@ -17,7 +17,7 @@ type FsInfo interface {
|
|||||||
GetGlobalFsInfo() ([]Fs, error)
|
GetGlobalFsInfo() ([]Fs, error)
|
||||||
|
|
||||||
// Returns capacity and free space, in bytes, of the set of mounts passed.
|
// 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'.
|
// Returns number of bytes occupied by 'dir'.
|
||||||
GetDirUsage(dir string) (uint64, error)
|
GetDirUsage(dir string) (uint64, error)
|
||||||
|
Loading…
Reference in New Issue
Block a user