summaryrefslogtreecommitdiff
path: root/libpod/container.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2017-11-24 13:39:29 -0500
committerMatthew Heon <matthew.heon@gmail.com>2017-12-04 13:39:44 -0500
commitabfd18b0db8cb0ea331d90d702eab19e2157b973 (patch)
treefb0c9c3e941d0b647af9fe701e535d5db816c41f /libpod/container.go
parent750fc239b5da8e3f2792ae33f46a671ddf4622e3 (diff)
downloadpodman-abfd18b0db8cb0ea331d90d702eab19e2157b973.tar.gz
podman-abfd18b0db8cb0ea331d90d702eab19e2157b973.tar.bz2
podman-abfd18b0db8cb0ea331d90d702eab19e2157b973.zip
Move containers to file locks from c/storage
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Diffstat (limited to 'libpod/container.go')
-rw-r--r--libpod/container.go28
1 files changed, 20 insertions, 8 deletions
diff --git a/libpod/container.go b/libpod/container.go
index bd7455147..f93b214b9 100644
--- a/libpod/container.go
+++ b/libpod/container.go
@@ -8,7 +8,6 @@ import (
"os"
"path/filepath"
"strconv"
- "sync"
"syscall"
"time"
@@ -61,9 +60,8 @@ type Container struct {
state *containerRuntimeInfo
- // TODO move to storage.Locker from sync.Mutex
valid bool
- lock sync.Mutex
+ lock storage.Locker
runtime *Runtime
}
@@ -340,7 +338,7 @@ func (c *Container) syncContainer() error {
}
// Make a new container
-func newContainer(rspec *spec.Spec) (*Container, error) {
+func newContainer(rspec *spec.Spec, logDir string) (*Container, error) {
if rspec == nil {
return nil, errors.Wrapf(ErrInvalidArg, "must provide a valid runtime spec to create container")
}
@@ -357,6 +355,20 @@ func newContainer(rspec *spec.Spec) (*Container, error) {
ctr.config.CreatedTime = time.Now()
+ // Path our lock file will reside at
+ lockPath := filepath.Join(logDir, ctr.config.ID)
+ // Ensure there is no conflict - file does not exist
+ _, err := os.Stat(lockPath)
+ if err == nil || !os.IsNotExist(err) {
+ return nil, errors.Wrapf(ErrCtrExists, "lockfile for container ID %s already exists", ctr.config.ID)
+ }
+ // Grab a lockfile at the given path
+ lock, err := storage.GetLockfile(lockPath)
+ if err != nil {
+ return nil, errors.Wrapf(err, "error creating lockfile for new container")
+ }
+ ctr.lock = lock
+
return ctr, nil
}
@@ -807,8 +819,8 @@ func (c *Container) mountStorage() (err error) {
}
}()
- if err := c.runtime.state.SaveContainer(c); err != nil {
- return errors.Wrapf(err, "error saving container %s state", c.ID())
+ if err := c.save(); err != nil {
+ return err
}
return nil
@@ -847,8 +859,8 @@ func (c *Container) cleanupStorage() error {
c.state.Mountpoint = ""
c.state.Mounted = false
- if err := c.runtime.state.SaveContainer(c); err != nil {
- return errors.Wrapf(err, "error saving container %s state", c.ID())
+ if err := c.save(); err != nil {
+ return err
}
return nil