Cleanup of libcontainer state generation.
This commit is contained in:
parent
9016655e9a
commit
4e3629101d
@ -59,12 +59,23 @@ type rawContainerHandler struct {
|
|||||||
// (e.g.: "cpu" -> "/sys/fs/cgroup/cpu/test")
|
// (e.g.: "cpu" -> "/sys/fs/cgroup/cpu/test")
|
||||||
cgroupPaths map[string]string
|
cgroupPaths map[string]string
|
||||||
|
|
||||||
fsInfo fs.FsInfo
|
// Equivalent libcontainer state for this container.
|
||||||
networkInterface *networkInterface
|
libcontainerState dockerlibcontainer.State
|
||||||
externalMounts []mount
|
|
||||||
|
// Whether this container has network isolation enabled.
|
||||||
|
hasNetwork bool
|
||||||
|
|
||||||
|
fsInfo fs.FsInfo
|
||||||
|
externalMounts []mount
|
||||||
}
|
}
|
||||||
|
|
||||||
func newRawContainerHandler(name string, cgroupSubsystems *libcontainer.CgroupSubsystems, machineInfoFactory info.MachineInfoFactory) (container.ContainerHandler, error) {
|
func newRawContainerHandler(name string, cgroupSubsystems *libcontainer.CgroupSubsystems, machineInfoFactory info.MachineInfoFactory) (container.ContainerHandler, error) {
|
||||||
|
// Create the cgroup paths.
|
||||||
|
cgroupPaths := make(map[string]string, len(cgroupSubsystems.MountPoints))
|
||||||
|
for key, val := range cgroupSubsystems.MountPoints {
|
||||||
|
cgroupPaths[key] = path.Join(val, name)
|
||||||
|
}
|
||||||
|
|
||||||
fsInfo, err := fs.NewFsInfo()
|
fsInfo, err := fs.NewFsInfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -73,22 +84,26 @@ func newRawContainerHandler(name string, cgroupSubsystems *libcontainer.CgroupSu
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var networkInterface *networkInterface
|
|
||||||
|
// Generate the equivalent libcontainer state for this container.
|
||||||
|
libcontainerState := dockerlibcontainer.State{
|
||||||
|
CgroupPaths: cgroupPaths,
|
||||||
|
}
|
||||||
|
|
||||||
|
hasNetwork := false
|
||||||
var externalMounts []mount
|
var externalMounts []mount
|
||||||
for _, container := range cHints.AllHosts {
|
for _, container := range cHints.AllHosts {
|
||||||
if name == container.FullName {
|
if name == container.FullName {
|
||||||
networkInterface = container.NetworkInterface
|
libcontainerState.NetworkState = network.NetworkState{
|
||||||
|
VethHost: container.NetworkInterface.VethHost,
|
||||||
|
VethChild: container.NetworkInterface.VethChild,
|
||||||
|
}
|
||||||
|
hasNetwork = true
|
||||||
externalMounts = container.Mounts
|
externalMounts = container.Mounts
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the cgroup paths.
|
|
||||||
cgroupPaths := make(map[string]string, len(cgroupSubsystems.MountPoints))
|
|
||||||
for key, val := range cgroupSubsystems.MountPoints {
|
|
||||||
cgroupPaths[key] = path.Join(val, name)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &rawContainerHandler{
|
return &rawContainerHandler{
|
||||||
name: name,
|
name: name,
|
||||||
cgroup: &cgroups.Cgroup{
|
cgroup: &cgroups.Cgroup{
|
||||||
@ -101,8 +116,9 @@ func newRawContainerHandler(name string, cgroupSubsystems *libcontainer.CgroupSu
|
|||||||
watches: make(map[string]struct{}),
|
watches: make(map[string]struct{}),
|
||||||
cgroupWatches: make(map[string]struct{}),
|
cgroupWatches: make(map[string]struct{}),
|
||||||
cgroupPaths: cgroupPaths,
|
cgroupPaths: cgroupPaths,
|
||||||
|
libcontainerState: libcontainerState,
|
||||||
fsInfo: fsInfo,
|
fsInfo: fsInfo,
|
||||||
networkInterface: networkInterface,
|
hasNetwork: hasNetwork,
|
||||||
externalMounts: externalMounts,
|
externalMounts: externalMounts,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@ -207,9 +223,7 @@ func (self *rawContainerHandler) GetSpec() (info.ContainerSpec, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Network
|
//Network
|
||||||
if self.networkInterface != nil {
|
spec.HasNetwork = self.hasNetwork
|
||||||
spec.HasNetwork = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check physical network devices for root container.
|
// Check physical network devices for root container.
|
||||||
nd, err := self.GetRootNetworkDevices()
|
nd, err := self.GetRootNetworkDevices()
|
||||||
@ -282,20 +296,7 @@ func (self *rawContainerHandler) getFsStats(stats *info.ContainerStats) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *rawContainerHandler) GetStats() (*info.ContainerStats, error) {
|
func (self *rawContainerHandler) GetStats() (*info.ContainerStats, error) {
|
||||||
// TODO(vmarmol): Don't re-create this every time.
|
stats, err := libcontainer.GetStats(self.cgroupPaths, &self.libcontainerState)
|
||||||
state := dockerlibcontainer.State{
|
|
||||||
CgroupPaths: self.cgroupPaths,
|
|
||||||
}
|
|
||||||
if self.networkInterface != nil {
|
|
||||||
state = dockerlibcontainer.State{
|
|
||||||
NetworkState: network.NetworkState{
|
|
||||||
VethHost: self.networkInterface.VethHost,
|
|
||||||
VethChild: self.networkInterface.VethChild,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stats, err := libcontainer.GetStats(self.cgroupPaths, &state)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user