1 Star 0 Fork 0

Derek Ray/podman

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
runtime_renumber.go 1.42 KB
一键复制 编辑 原始数据 按行查看 历史
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
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/derekhjray/podman.git
git@gitee.com:derekhjray/podman.git
derekhjray
podman
podman
v1.2.0

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385