aboutsummaryrefslogtreecommitdiff
path: root/libpod/runtime_renumber.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@pm.me>2019-02-14 17:25:58 -0500
committerMatthew Heon <matthew.heon@pm.me>2019-02-21 10:51:42 -0500
commit7fdd20ae5a1ced1faceab9cb0a6e553343911a0b (patch)
tree21bc568928dfaa8f12e3b616e0e72fda3f1f5a63 /libpod/runtime_renumber.go
parent84feff2e06e9c3dd504be918f8dcf0b0a434a941 (diff)
downloadpodman-7fdd20ae5a1ced1faceab9cb0a6e553343911a0b.tar.gz
podman-7fdd20ae5a1ced1faceab9cb0a6e553343911a0b.tar.bz2
podman-7fdd20ae5a1ced1faceab9cb0a6e553343911a0b.zip
Add initial version of renumber backend
Renumber is a way of renumbering container locks after the number of locks available has changed. For now, renumber only works with containers. Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'libpod/runtime_renumber.go')
-rw-r--r--libpod/runtime_renumber.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/libpod/runtime_renumber.go b/libpod/runtime_renumber.go
new file mode 100644
index 000000000..bc291156e
--- /dev/null
+++ b/libpod/runtime_renumber.go
@@ -0,0 +1,60 @@
+package libpod
+
+import (
+ "path/filepath"
+
+ "github.com/containers/storage"
+ "github.com/pkg/errors"
+)
+
+// RenumberLocks reassigns lock numbers for all containers, pods, and volumes in
+// the state.
+// It renders the runtime it is called on, and all container/pod/volume structs
+// from that runtime, unusable, and requires that a new runtime be initialized
+// after it is called.
+func (r *Runtime) RenumberLocks() error {
+ r.lock.Lock()
+ locked := true
+ defer func() {
+ if locked {
+ r.lock.Unlock()
+ }
+ }()
+
+ runtimeAliveLock := filepath.Join(r.config.TmpDir, "alive.lck")
+ aliveLock, err := storage.GetLockfile(runtimeAliveLock)
+ if err != nil {
+ return errors.Wrapf(err, "error acquiring runtime init lock")
+ }
+ aliveLock.Lock()
+ // It's OK to defer until Shutdown() has run, so no need to check locked
+ defer aliveLock.Unlock()
+
+ // Start off by deallocating all locks
+ if err := r.lockManager.FreeAllLocks(); err != nil {
+ return err
+ }
+
+ allCtrs, err := r.state.AllContainers()
+ if err != nil {
+ return err
+ }
+ for _, ctr := range allCtrs {
+ lock, err := r.lockManager.AllocateLock()
+ if err != nil {
+ return errors.Wrapf(err, "error allocating lock for container %s", ctr.ID())
+ }
+
+ ctr.config.LockID = lock.ID()
+
+ // Write the new lock ID
+ if err := r.state.RewriteContainerConfig(ctr, ctr.config); err != nil {
+ return err
+ }
+ }
+
+ r.lock.Unlock()
+ locked = false
+
+ return r.Shutdown(false)
+}