code review fixes

This commit is contained in:
Abin Shahab 2014-10-16 01:09:24 +00:00
parent b8ed0bd0e3
commit 751de4a0c9
5 changed files with 24 additions and 22 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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"
}
],

View File

@ -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),

View File

@ -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)