Add remove method to subsystems

Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
Michael Crosby 2014-04-18 22:17:31 -07:00
parent bb89b83c68
commit 810cf722cc
9 changed files with 45 additions and 18 deletions

View file

@ -25,6 +25,7 @@ var (
type subsystem interface { type subsystem interface {
Set(*data) error Set(*data) error
Remove(*data) error
} }
type data struct { type data struct {
@ -94,24 +95,8 @@ func (raw *data) join(subsystem string) (string, error) {
} }
func (raw *data) Cleanup() error { func (raw *data) Cleanup() error {
get := func(subsystem string) string { for _, sys := range subsystems {
path, _ := raw.path(subsystem) sys.Remove(raw)
return path
}
for _, path := range []string{
get("memory"),
get("devices"),
get("cpu"),
get("cpuset"),
get("cpuacct"),
get("blkio"),
get("perf_event"),
get("freezer"),
} {
if path != "" {
os.RemoveAll(path)
}
} }
return nil return nil
} }
@ -119,3 +104,13 @@ func (raw *data) Cleanup() error {
func writeFile(dir, file, data string) error { func writeFile(dir, file, data string) error {
return ioutil.WriteFile(filepath.Join(dir, file), []byte(data), 0700) return ioutil.WriteFile(filepath.Join(dir, file), []byte(data), 0700)
} }
func removePath(p string, err error) error {
if err != nil {
return err
}
if p != "" {
return os.RemoveAll(p)
}
return nil
}

View file

@ -14,3 +14,7 @@ func (s *blkioGroup) Set(d *data) error {
} }
return nil return nil
} }
func (s *blkioGroup) Remove(d *data) error {
return removePath(d.path("blkio"))
}

View file

@ -21,3 +21,7 @@ func (s *cpuGroup) Set(d *data) error {
} }
return nil return nil
} }
func (s *cpuGroup) Remove(d *data) error {
return removePath(d.path("cpu"))
}

View file

@ -14,3 +14,7 @@ func (s *cpuacctGroup) Set(d *data) error {
} }
return nil return nil
} }
func (s *cpuacctGroup) Remove(d *data) error {
return removePath(d.path("cpuacct"))
}

View file

@ -26,3 +26,7 @@ func (s *cpusetGroup) Set(d *data) error {
} }
return nil return nil
} }
func (s *cpusetGroup) Remove(d *data) error {
return removePath(d.path("cpuset"))
}

View file

@ -59,3 +59,7 @@ func (s *devicesGroup) Set(d *data) error {
} }
return nil return nil
} }
func (s *devicesGroup) Remove(d *data) error {
return removePath(d.path("devices"))
}

View file

@ -14,3 +14,7 @@ func (s *freezerGroup) Set(d *data) error {
} }
return nil return nil
} }
func (s *freezerGroup) Remove(d *data) error {
return removePath(d.path("freezer"))
}

View file

@ -39,3 +39,7 @@ func (s *memoryGroup) Set(d *data) error {
} }
return nil return nil
} }
func (s *memoryGroup) Remove(d *data) error {
return removePath(d.path("memory"))
}

View file

@ -14,3 +14,7 @@ func (s *perfEventGroup) Set(d *data) error {
} }
return nil return nil
} }
func (s *perfEventGroup) Remove(d *data) error {
return removePath(d.path("perf_event"))
}