podman/libpod/runtime_renumber.go
Daniel J Walsh 2c63b8439b
Fix stutters
Podman adds an Error: to every error message.  So starting an error
message with "error" ends up being reported to the user as

Error: error ...

This patch removes the stutter.

Also ioutil.ReadFile errors report the Path, so wrapping the err message
with the path causes a stutter.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-09-10 07:52:00 -04:00

79 lines
1.9 KiB
Go

package libpod
import (
"fmt"
"github.com/containers/podman/v4/libpod/events"
)
// 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 fmt.Errorf("allocating lock for container %s: %w", ctr.ID(), err)
}
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 fmt.Errorf("allocating lock for pod %s: %w", pod.ID(), err)
}
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 fmt.Errorf("allocating lock for volume %s: %w", vol.Name(), err)
}
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
}