diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-02-21 23:11:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-21 23:11:24 +0100 |
commit | eb6243226a08254f15657c3728bb4dd8949ee6cd (patch) | |
tree | 25fea4777a578895b9ac0f5f6c2e19860fc2e4bd /libpod/runtime_renumber.go | |
parent | b4c10790d514538277a937a443219e4310cb057f (diff) | |
parent | 19eb72f4206192b22856eef24ce3815eac3d7bda (diff) | |
download | podman-eb6243226a08254f15657c3728bb4dd8949ee6cd.tar.gz podman-eb6243226a08254f15657c3728bb4dd8949ee6cd.tar.bz2 podman-eb6243226a08254f15657c3728bb4dd8949ee6cd.zip |
Merge pull request #2350 from mheon/lock_renumber
Add lock renumbering
Diffstat (limited to 'libpod/runtime_renumber.go')
-rw-r--r-- | libpod/runtime_renumber.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/libpod/runtime_renumber.go b/libpod/runtime_renumber.go new file mode 100644 index 000000000..125cf0825 --- /dev/null +++ b/libpod/runtime_renumber.go @@ -0,0 +1,57 @@ +package libpod + +import ( + "github.com/pkg/errors" +) + +// renumberLocks reassigns lock numbers for all containers and pods in the +// state. +// TODO: It would be desirable to make it impossible to call this until all +// other libpod sessions are dead. +// Possibly use a read-write file lock, with all non-renumber podmans owning the +// lock as read, renumber attempting to take a write lock? +// The alternative is some sort of session tracking, and I don't know how +// reliable that can be. +func (r *Runtime) renumberLocks() error { + // 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 + } + } + allPods, err := r.state.AllPods() + if err != nil { + return err + } + for _, pod := range allPods { + lock, err := r.lockManager.AllocateLock() + if err != nil { + return errors.Wrapf(err, "error allocating lock for pod %s", pod.ID()) + } + + pod.config.LockID = lock.ID() + + // Write the new lock ID + if err := r.state.RewritePodConfig(pod, pod.config); err != nil { + return err + } + } + + return nil +} |