summaryrefslogtreecommitdiff
path: root/libpod/runtime.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@pm.me>2019-02-15 10:33:59 -0500
committerMatthew Heon <matthew.heon@pm.me>2019-02-21 10:51:42 -0500
commitf9c548219b6543959dd240618f8a922fdbcabc6d (patch)
treef992bfd9c0bf4d0afb98b79b03ead819aa247ae8 /libpod/runtime.go
parenta72025d6fd111bfa2dc4e1d22871966fec614f88 (diff)
downloadpodman-f9c548219b6543959dd240618f8a922fdbcabc6d.tar.gz
podman-f9c548219b6543959dd240618f8a922fdbcabc6d.tar.bz2
podman-f9c548219b6543959dd240618f8a922fdbcabc6d.zip
Recreate SHM locks when renumbering on count mismatch
When we're renumbering locks, we're destroying all existing allocations anyways, so destroying the old lock struct is not a particularly big deal. Existing long-lived libpod instances will continue to use the old locks, but that will be solved in a followon. Also, solve an issue with returning error values in the C code. There were a few places where we return ERRNO where it was not set, so make them return actual error codes). Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'libpod/runtime.go')
-rw-r--r--libpod/runtime.go26
1 files changed, 20 insertions, 6 deletions
diff --git a/libpod/runtime.go b/libpod/runtime.go
index bc7c061c4..850df4fc9 100644
--- a/libpod/runtime.go
+++ b/libpod/runtime.go
@@ -7,6 +7,7 @@ import (
"os/exec"
"path/filepath"
"sync"
+ "syscall"
"github.com/BurntSushi/toml"
is "github.com/containers/image/storage"
@@ -757,12 +758,6 @@ func makeRuntime(runtime *Runtime) (err error) {
aliveLock.Unlock()
}
}()
- // If we're renumbering locks, do it now.
- // It breaks out of normal runtime init, and will not return a valid
- // runtime.
- if runtime.doRenumber {
- return runtime.renumberLocks()
- }
_, err = os.Stat(runtimeAliveFile)
if err != nil {
@@ -789,12 +784,31 @@ func makeRuntime(runtime *Runtime) (err error) {
if err != nil {
return err
}
+ } else if err == syscall.ERANGE && runtime.doRenumber {
+ // ERANGE indicates a lock numbering mismatch.
+ // Since we're renumbering, this is not fatal.
+ // Remove the earlier set of locks and recreate.
+ if err := os.Remove(filepath.Join("/dev/shm", lockPath)); err != nil {
+ return errors.Wrapf(err, "error removing libpod locks file %s", lockPath)
+ }
+
+ manager, err = lock.NewSHMLockManager(lockPath, runtime.config.NumLocks)
+ if err != nil {
+ return err
+ }
} else {
return err
}
}
runtime.lockManager = manager
+ // If we're renumbering locks, do it now.
+ // It breaks out of normal runtime init, and will not return a valid
+ // runtime.
+ if runtime.doRenumber {
+ return runtime.renumberLocks()
+ }
+
// If we need to refresh the state, do it now - things are guaranteed to
// be set up by now.
if doRefresh {