Files
podman/libpod/runtime_renumber.go
Matthew Heon d2b77f8b33 Do not make renumber shut down the runtime
The original intent behind the requirement was to ensure that, if
two SHM lock structs were open at the same time, we should not
make such a runtime available to the user, and should clean it up
instead.

It turns out that we don't even need to open a second SHM lock
struct - if we get an error mapping the first one due to a lock
count mismatch, we can just delete it, and it cleans itself up
when it errors. So there's no reason not to return a valid
runtime.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-02-21 10:51:42 -05:00

58 lines
1.4 KiB
Go

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
}