cgroups: only return path when subsystem really mounted
If cgroup patch doesn't exist, there is no point we do the Set. Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
This commit is contained in:
parent
83663f82e3
commit
606d9064b0
|
@ -229,6 +229,12 @@ func (raw *data) parent(subsystem string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (raw *data) path(subsystem string) (string, error) {
|
func (raw *data) path(subsystem string) (string, error) {
|
||||||
|
_, err := cgroups.FindCgroupMountpoint(subsystem)
|
||||||
|
// If we didn't mount the subsystem, there is no point we make the path.
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
// If the cgroup name/path is absolute do not look relative to the cgroup of the init process.
|
// If the cgroup name/path is absolute do not look relative to the cgroup of the init process.
|
||||||
if filepath.IsAbs(raw.cgroup) {
|
if filepath.IsAbs(raw.cgroup) {
|
||||||
path := filepath.Join(raw.root, subsystem, raw.cgroup)
|
path := filepath.Join(raw.root, subsystem, raw.cgroup)
|
||||||
|
|
|
@ -17,8 +17,12 @@ type BlkioGroup struct {
|
||||||
|
|
||||||
func (s *BlkioGroup) Apply(d *data) error {
|
func (s *BlkioGroup) Apply(d *data) error {
|
||||||
dir, err := d.join("blkio")
|
dir, err := d.join("blkio")
|
||||||
if err != nil && !cgroups.IsNotFound(err) {
|
if err != nil {
|
||||||
return err
|
if cgroups.IsNotFound(err) {
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := s.Set(dir, d.c); err != nil {
|
if err := s.Set(dir, d.c); err != nil {
|
||||||
|
|
|
@ -18,7 +18,11 @@ func (s *CpuGroup) Apply(d *data) error {
|
||||||
// on a container basis
|
// on a container basis
|
||||||
dir, err := d.join("cpu")
|
dir, err := d.join("cpu")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
if cgroups.IsNotFound(err) {
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := s.Set(dir, d.c); err != nil {
|
if err := s.Set(dir, d.c); err != nil {
|
||||||
|
|
|
@ -17,7 +17,11 @@ type CpusetGroup struct {
|
||||||
func (s *CpusetGroup) Apply(d *data) error {
|
func (s *CpusetGroup) Apply(d *data) error {
|
||||||
dir, err := d.path("cpuset")
|
dir, err := d.path("cpuset")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
if cgroups.IsNotFound(err) {
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return s.ApplyDir(dir, d.c, d.pid)
|
return s.ApplyDir(dir, d.c, d.pid)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,11 @@ type DevicesGroup struct {
|
||||||
func (s *DevicesGroup) Apply(d *data) error {
|
func (s *DevicesGroup) Apply(d *data) error {
|
||||||
dir, err := d.join("devices")
|
dir, err := d.join("devices")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
if cgroups.IsNotFound(err) {
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := s.Set(dir, d.c); err != nil {
|
if err := s.Set(dir, d.c); err != nil {
|
||||||
|
|
|
@ -13,8 +13,12 @@ type FreezerGroup struct {
|
||||||
|
|
||||||
func (s *FreezerGroup) Apply(d *data) error {
|
func (s *FreezerGroup) Apply(d *data) error {
|
||||||
dir, err := d.join("freezer")
|
dir, err := d.join("freezer")
|
||||||
if err != nil && !cgroups.IsNotFound(err) {
|
if err != nil {
|
||||||
return err
|
if cgroups.IsNotFound(err) {
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := s.Set(dir, d.c); err != nil {
|
if err := s.Set(dir, d.c); err != nil {
|
||||||
|
|
|
@ -16,9 +16,12 @@ type MemoryGroup struct {
|
||||||
|
|
||||||
func (s *MemoryGroup) Apply(d *data) error {
|
func (s *MemoryGroup) Apply(d *data) error {
|
||||||
dir, err := d.join("memory")
|
dir, err := d.join("memory")
|
||||||
// only return an error for memory if it was specified
|
if err != nil {
|
||||||
if err != nil && (d.c.Memory != 0 || d.c.MemoryReservation != 0 || d.c.MemorySwap != 0) {
|
if cgroups.IsNotFound(err) {
|
||||||
return err
|
return nil
|
||||||
|
} else {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue