mirror of
https://github.com/containers/podman.git
synced 2025-11-01 22:32:50 +08:00
pkg/machine: refresh config after we hold lock
Currently we first read the conf and then lock, this is racy because while we wait for the lock another process might change the state so the only way to have the actual current state is to read the file while holding the lock. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
@ -323,6 +323,9 @@ func Stop(mc *vmconfigs.MachineConfig, mp vmconfigs.VMProvider, dirs *machineDef
|
|||||||
// an error. so putting in one place instead of sprinkling all over.
|
// an error. so putting in one place instead of sprinkling all over.
|
||||||
mc.Lock()
|
mc.Lock()
|
||||||
defer mc.Unlock()
|
defer mc.Unlock()
|
||||||
|
if err := mc.Refresh(); err != nil {
|
||||||
|
return fmt.Errorf("reload config: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
return stopLocked(mc, mp, dirs, hardStop)
|
return stopLocked(mc, mp, dirs, hardStop)
|
||||||
}
|
}
|
||||||
@ -377,6 +380,9 @@ func Start(mc *vmconfigs.MachineConfig, mp vmconfigs.VMProvider, dirs *machineDe
|
|||||||
|
|
||||||
mc.Lock()
|
mc.Lock()
|
||||||
defer mc.Unlock()
|
defer mc.Unlock()
|
||||||
|
if err := mc.Refresh(); err != nil {
|
||||||
|
return fmt.Errorf("reload config: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
// Set starting to true
|
// Set starting to true
|
||||||
mc.Starting = true
|
mc.Starting = true
|
||||||
@ -538,6 +544,9 @@ func Set(mc *vmconfigs.MachineConfig, mp vmconfigs.VMProvider, opts machineDefin
|
|||||||
func Remove(mc *vmconfigs.MachineConfig, mp vmconfigs.VMProvider, dirs *machineDefine.MachineDirs, opts machine.RemoveOptions) error {
|
func Remove(mc *vmconfigs.MachineConfig, mp vmconfigs.VMProvider, dirs *machineDefine.MachineDirs, opts machine.RemoveOptions) error {
|
||||||
mc.Lock()
|
mc.Lock()
|
||||||
defer mc.Unlock()
|
defer mc.Unlock()
|
||||||
|
if err := mc.Refresh(); err != nil {
|
||||||
|
return fmt.Errorf("reload config: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
state, err := mp.State(mc, false)
|
state, err := mp.State(mc, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user