mirror of
https://github.com/containers/podman.git
synced 2025-06-29 06:57:13 +08:00
podman machine start/stop do not write config unlocked
Move the writes into the shim level to make sure they happen while we hold the machine lock to prevent any race conditions reading/writing the file. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
@ -12,7 +12,6 @@ import (
|
|||||||
"github.com/containers/podman/v5/pkg/machine/env"
|
"github.com/containers/podman/v5/pkg/machine/env"
|
||||||
"github.com/containers/podman/v5/pkg/machine/shim"
|
"github.com/containers/podman/v5/pkg/machine/shim"
|
||||||
"github.com/containers/podman/v5/pkg/machine/vmconfigs"
|
"github.com/containers/podman/v5/pkg/machine/vmconfigs"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -82,19 +81,6 @@ func start(_ *cobra.Command, args []string) error {
|
|||||||
fmt.Printf("Starting machine %q\n", vmName)
|
fmt.Printf("Starting machine %q\n", vmName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set starting to true
|
|
||||||
mc.Starting = true
|
|
||||||
if err := mc.Write(); err != nil {
|
|
||||||
logrus.Error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set starting to false on exit
|
|
||||||
defer func() {
|
|
||||||
mc.Starting = false
|
|
||||||
if err := mc.Write(); err != nil {
|
|
||||||
logrus.Error(err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
if err := shim.Start(mc, provider, dirs, startOpts); err != nil {
|
if err := shim.Start(mc, provider, dirs, startOpts); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -4,14 +4,12 @@ package machine
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/containers/podman/v5/cmd/podman/registry"
|
"github.com/containers/podman/v5/cmd/podman/registry"
|
||||||
"github.com/containers/podman/v5/libpod/events"
|
"github.com/containers/podman/v5/libpod/events"
|
||||||
"github.com/containers/podman/v5/pkg/machine/env"
|
"github.com/containers/podman/v5/pkg/machine/env"
|
||||||
"github.com/containers/podman/v5/pkg/machine/shim"
|
"github.com/containers/podman/v5/pkg/machine/shim"
|
||||||
"github.com/containers/podman/v5/pkg/machine/vmconfigs"
|
"github.com/containers/podman/v5/pkg/machine/vmconfigs"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -59,12 +57,6 @@ func stop(cmd *cobra.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update last time up
|
|
||||||
mc.LastUp = time.Now()
|
|
||||||
if err := mc.Write(); err != nil {
|
|
||||||
logrus.Errorf("unable to write configuration file: %q", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("Machine %q stopped successfully\n", vmName)
|
fmt.Printf("Machine %q stopped successfully\n", vmName)
|
||||||
newMachineEvent(events.Stop, events.Event{Name: vmName})
|
newMachineEvent(events.Stop, events.Event{Name: vmName})
|
||||||
return nil
|
return nil
|
||||||
|
@ -366,7 +366,9 @@ func stopLocked(mc *vmconfigs.MachineConfig, mp vmconfigs.VMProvider, dirs *mach
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
// Update last time up
|
||||||
|
mc.LastUp = time.Now()
|
||||||
|
return mc.Write()
|
||||||
}
|
}
|
||||||
|
|
||||||
func Start(mc *vmconfigs.MachineConfig, mp vmconfigs.VMProvider, dirs *machineDefine.MachineDirs, opts machine.StartOptions) error {
|
func Start(mc *vmconfigs.MachineConfig, mp vmconfigs.VMProvider, dirs *machineDefine.MachineDirs, opts machine.StartOptions) error {
|
||||||
@ -376,6 +378,19 @@ func Start(mc *vmconfigs.MachineConfig, mp vmconfigs.VMProvider, dirs *machineDe
|
|||||||
mc.Lock()
|
mc.Lock()
|
||||||
defer mc.Unlock()
|
defer mc.Unlock()
|
||||||
|
|
||||||
|
// Set starting to true
|
||||||
|
mc.Starting = true
|
||||||
|
if err := mc.Write(); err != nil {
|
||||||
|
logrus.Error(err)
|
||||||
|
}
|
||||||
|
// Set starting to false on exit
|
||||||
|
defer func() {
|
||||||
|
mc.Starting = false
|
||||||
|
if err := mc.Write(); err != nil {
|
||||||
|
logrus.Error(err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
gvproxyPidFile, err := dirs.RuntimeDir.AppendToNewVMFile("gvproxy.pid", nil)
|
gvproxyPidFile, err := dirs.RuntimeDir.AppendToNewVMFile("gvproxy.pid", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Reference in New Issue
Block a user