mirror of
https://github.com/containers/podman
synced 2024-10-21 01:34:37 +00:00
8489dc4345
With the advent of Podman 2.0.0 we crossed the magical barrier of go modules. While we were able to continue importing all packages inside of the project, the project could not be vendored anymore from the outside. Move the go module to new major version and change all imports to `github.com/containers/libpod/v2`. The renaming of the imports was done via `gomove` [1]. [1] https://github.com/KSubedi/gomove Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
78 lines
1.9 KiB
Go
78 lines
1.9 KiB
Go
package libpod
|
|
|
|
import (
|
|
"github.com/containers/libpod/v2/libpod/events"
|
|
"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
|
|
}
|
|
}
|
|
allVols, err := r.state.AllVolumes()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, vol := range allVols {
|
|
lock, err := r.lockManager.AllocateLock()
|
|
if err != nil {
|
|
return errors.Wrapf(err, "error allocating lock for volume %s", vol.Name())
|
|
}
|
|
|
|
vol.config.LockID = lock.ID()
|
|
|
|
// Write the new lock ID
|
|
if err := r.state.RewriteVolumeConfig(vol, vol.config); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
r.newSystemEvent(events.Renumber)
|
|
|
|
return nil
|
|
}
|