summaryrefslogtreecommitdiff
path: root/pkg/machine/qemu/machine.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/machine/qemu/machine.go')
-rw-r--r--pkg/machine/qemu/machine.go49
1 files changed, 33 insertions, 16 deletions
diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go
index a92892957..855a39c56 100644
--- a/pkg/machine/qemu/machine.go
+++ b/pkg/machine/qemu/machine.go
@@ -1,4 +1,4 @@
-// +build amd64,linux arm64,linux amd64,darwin arm64,darwin
+// +build amd64,!windows arm64,!windows
package qemu
@@ -138,29 +138,29 @@ func (v *MachineVM) Init(opts machine.InitOptions) error {
jsonFile := filepath.Join(vmConfigDir, v.Name) + ".json"
v.IdentityPath = filepath.Join(sshDir, v.Name)
- // The user has provided an alternate image which can be a file path
- // or URL.
- if len(opts.ImagePath) > 0 {
- g, err := machine.NewGenericDownloader(vmtype, v.Name, opts.ImagePath)
+ switch opts.ImagePath {
+ case "testing", "stable", "":
+ // Get image as usual
+ dd, err := machine.NewFcosDownloader(vmtype, v.Name, opts.ImagePath)
if err != nil {
return err
}
- v.ImagePath = g.Get().LocalUncompressedFile
- if err := g.DownloadImage(); err != nil {
+ v.ImagePath = dd.Get().LocalUncompressedFile
+ if err := dd.DownloadImage(); err != nil {
return err
}
- } else {
- // Get the image as usual
- dd, err := machine.NewFcosDownloader(vmtype, v.Name)
+ default:
+ // The user has provided an alternate image which can be a file path
+ // or URL.
+ g, err := machine.NewGenericDownloader(vmtype, v.Name, opts.ImagePath)
if err != nil {
return err
}
- v.ImagePath = dd.Get().LocalUncompressedFile
- if err := dd.DownloadImage(); err != nil {
+ v.ImagePath = g.Get().LocalUncompressedFile
+ if err := g.DownloadImage(); err != nil {
return err
}
}
-
// Add arch specific options including image location
v.CmdLine = append(v.CmdLine, v.addArchOptions()...)
@@ -244,6 +244,7 @@ func (v *MachineVM) Start(name string, _ machine.StartOptions) error {
qemuSocketConn net.Conn
wait time.Duration = time.Millisecond * 500
)
+
if err := v.startHostNetworking(); err != nil {
return errors.Errorf("unable to start host networking: %q", err)
}
@@ -264,7 +265,11 @@ func (v *MachineVM) Start(name string, _ machine.StartOptions) error {
if err != nil {
return err
}
-
+ // If the qemusocketpath exists and the vm is off/down, we should rm
+ // it before the dial as to avoid a segv
+ if err := os.Remove(qemuSocketPath); err != nil && !errors.Is(err, os.ErrNotExist) {
+ logrus.Warn(err)
+ }
for i := 0; i < 6; i++ {
qemuSocketConn, err = net.Dial("unix", qemuSocketPath)
if err == nil {
@@ -273,6 +278,9 @@ func (v *MachineVM) Start(name string, _ machine.StartOptions) error {
time.Sleep(wait)
wait++
}
+ if err != nil {
+ return err
+ }
fd, err := qemuSocketConn.(*net.UnixConn).File()
if err != nil {
@@ -352,7 +360,7 @@ func (v *MachineVM) Stop(name string, _ machine.StopOptions) error {
if _, err = qmpMonitor.Run(input); err != nil {
return err
}
- _, pidFile, err := v.getSocketandPid()
+ qemuSocketFile, pidFile, err := v.getSocketandPid()
if err != nil {
return err
}
@@ -373,7 +381,16 @@ func (v *MachineVM) Stop(name string, _ machine.StopOptions) error {
if p == nil && err != nil {
return err
}
- return p.Kill()
+ // Kill the process
+ if err := p.Kill(); err != nil {
+ return err
+ }
+ // Remove the pidfile
+ if err := os.Remove(pidFile); err != nil && !errors.Is(err, os.ErrNotExist) {
+ logrus.Warn(err)
+ }
+ // Remove socket
+ return os.Remove(qemuSocketFile)
}
// NewQMPMonitor creates the monitor subsection of our vm