summaryrefslogtreecommitdiff
path: root/libpod/pod.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-05-16 12:45:09 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-05-17 23:10:12 +0000
commit7e1ea9d26dff92c346bb11640fdab523d513e867 (patch)
tree28fca87c36fa1ddf5c357c61e2677626ed27835a /libpod/pod.go
parent018d2c6b1d23acf7fe67e809498bc354eaf6becf (diff)
downloadpodman-7e1ea9d26dff92c346bb11640fdab523d513e867.tar.gz
podman-7e1ea9d26dff92c346bb11640fdab523d513e867.tar.bz2
podman-7e1ea9d26dff92c346bb11640fdab523d513e867.zip
Add per-pod CGroups
Pods can now create their own (cgroupfs) cgroups which containers in them can (optionally) use. This presently only works with CGroupFS, systemd cgroups are still WIP Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #784 Approved by: rhatdan
Diffstat (limited to 'libpod/pod.go')
-rw-r--r--libpod/pod.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/libpod/pod.go b/libpod/pod.go
index e082ef807..19347dde7 100644
--- a/libpod/pod.go
+++ b/libpod/pod.go
@@ -31,6 +31,11 @@ type PodConfig struct {
Labels map[string]string `json:"labels"`
// CgroupParent contains the pod's CGroup parent
CgroupParent string `json:"cgroupParent"`
+ // UsePodCgroup indicates whether the pod will create its own CGroup and
+ // join containers to it.
+ // If true, all containers joined to the pod will use the pod cgroup as
+ // their cgroup parent, and cannot set a different cgroup parent
+ UsePodCgroup bool
}
// podState represents a pod's state
@@ -64,6 +69,23 @@ func (p *Pod) CgroupParent() string {
return p.config.CgroupParent
}
+// UsePodCgroup returns whether containers in the pod will default to this pod's
+// cgroup instead of the default libpod parent
+func (p *Pod) UsePodCgroup() bool {
+ return p.config.UsePodCgroup
+}
+
+// CgroupPath returns the path to the pod's CGroup
+func (p *Pod) CgroupPath() (string, error) {
+ p.lock.Lock()
+ p.lock.Unlock()
+ if err := p.updatePod(); err != nil {
+ return "", err
+ }
+
+ return p.state.CgroupPath, nil
+}
+
// Creates a new, empty pod
func newPod(lockDir string, runtime *Runtime) (*Pod, error) {
pod := new(Pod)
@@ -85,6 +107,52 @@ func newPod(lockDir string, runtime *Runtime) (*Pod, error) {
return pod, nil
}
+// Update pod state from database
+func (p *Pod) updatePod() error {
+ if err := p.runtime.state.UpdatePod(p); err != nil {
+ return err
+ }
+
+ return nil
+}
+
+// Save pod state to database
+func (p *Pod) save() error {
+ if err := p.runtime.state.SavePod(p); err != nil {
+ return errors.Wrapf(err, "error saving pod %s state")
+ }
+
+ return nil
+}
+
+// Refresh a pod's state after restart
+func (p *Pod) refresh() error {
+ p.lock.Lock()
+ defer p.lock.Unlock()
+
+ if !p.valid {
+ return ErrPodRemoved
+ }
+
+ // We need to recreate the pod's cgroup
+ if p.config.UsePodCgroup {
+ switch p.runtime.config.CgroupManager {
+ case SystemdCgroupsManager:
+ // NOOP for now, until proper systemd cgroup management
+ // is implemented
+ case CgroupfsCgroupsManager:
+ p.state.CgroupPath = filepath.Join(p.config.CgroupParent, p.ID())
+
+ logrus.Debugf("setting pod cgroup to %s", p.state.CgroupPath)
+ default:
+ return errors.Wrapf(ErrInvalidArg, "unknown cgroups manager %s specified", p.runtime.config.CgroupManager)
+ }
+ }
+
+ // Save changes
+ return p.save()
+}
+
// Start starts all containers within a pod
// It combines the effects of Init() and Start() on a container
// If a container has already been initialized it will be started,