Skip to content

Commit 8848aad

Browse files
authored
Merge pull request #15781 from spowelljr/windows
Implement basic QEMU on Windows code
2 parents 6a2fc9a + 62b5c51 commit 8848aad

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

Diff for: pkg/drivers/qemu/qemu.go

+34-19
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"bytes"
2222
"encoding/json"
2323
"fmt"
24+
"io"
2425
"math/rand"
2526
"net"
2627
"os"
@@ -170,21 +171,23 @@ func checkPid(pid int) error {
170171
}
171172

172173
func (d *Driver) GetState() (state.State, error) {
173-
if _, err := os.Stat(d.pidfilePath()); err != nil {
174-
return state.Stopped, nil
175-
}
176-
p, err := os.ReadFile(d.pidfilePath())
177-
if err != nil {
178-
return state.Error, err
179-
}
180-
pid, err := strconv.Atoi(strings.TrimSpace(string(p)))
181-
if err != nil {
182-
return state.Error, err
183-
}
184-
if err := checkPid(pid); err != nil {
185-
// No pid, remove pidfile
186-
os.Remove(d.pidfilePath())
187-
return state.Stopped, nil
174+
if runtime.GOOS != "windows" {
175+
if _, err := os.Stat(d.pidfilePath()); err != nil {
176+
return state.Stopped, nil
177+
}
178+
p, err := os.ReadFile(d.pidfilePath())
179+
if err != nil {
180+
return state.Error, err
181+
}
182+
pid, err := strconv.Atoi(strings.TrimSpace(string(p)))
183+
if err != nil {
184+
return state.Error, err
185+
}
186+
if err := checkPid(pid); err != nil {
187+
// No pid, remove pidfile
188+
os.Remove(d.pidfilePath())
189+
return state.Stopped, nil
190+
}
188191
}
189192
ret, err := d.RunQMPCommand("query-status")
190193
if err != nil {
@@ -425,8 +428,10 @@ func (d *Driver) Start() error {
425428
return fmt.Errorf("unknown network: %s", d.Network)
426429
}
427430

428-
startCmd = append(startCmd,
429-
"-daemonize")
431+
if runtime.GOOS != "windows" {
432+
startCmd = append(startCmd,
433+
"-daemonize")
434+
}
430435

431436
if d.CloudConfigRoot != "" {
432437
startCmd = append(startCmd,
@@ -453,7 +458,11 @@ func (d *Driver) Start() error {
453458
startCmd = append([]string{d.SocketVMNetPath, d.Program}, startCmd...)
454459
}
455460

456-
if stdout, stderr, err := cmdOutErr(startProgram, startCmd...); err != nil {
461+
startFunc := cmdOutErr
462+
if runtime.GOOS == "windows" {
463+
startFunc = cmdStart
464+
}
465+
if stdout, stderr, err := startFunc(startProgram, startCmd...); err != nil {
457466
fmt.Printf("OUTPUT: %s\n", stdout)
458467
fmt.Printf("ERROR: %s\n", stderr)
459468
return err
@@ -522,6 +531,12 @@ func cmdOutErr(cmdStr string, args ...string) (string, string, error) {
522531
return stdoutStr, stderrStr, err
523532
}
524533

534+
func cmdStart(cmdStr string, args ...string) (string, string, error) {
535+
cmd := exec.Command(cmdStr, args...)
536+
log.Debugf("executing: %s %s", cmdStr, strings.Join(args, " "))
537+
return "", "", cmd.Start()
538+
}
539+
525540
func (d *Driver) Stop() error {
526541
if _, err := d.RunQMPCommand("system_powerdown"); err != nil {
527542
return err
@@ -794,7 +809,7 @@ func WaitForTCPWithDelay(addr string, duration time.Duration) error {
794809
continue
795810
}
796811
defer conn.Close()
797-
if _, err := conn.Read(make([]byte, 1)); err != nil {
812+
if _, err := conn.Read(make([]byte, 1)); err != nil && err != io.EOF {
798813
time.Sleep(duration)
799814
continue
800815
}

Diff for: pkg/minikube/registry/drvs/qemu2/qemu2.go

+3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ func qemuFirmwarePath(customPath string) (string, error) {
7070
if customPath != "" {
7171
return customPath, nil
7272
}
73+
if runtime.GOOS == "windows" {
74+
return "C:\\Program Files\\qemu\\share\\edk2-x86_64-code.fd", nil
75+
}
7376
arch := runtime.GOARCH
7477
// For macOS, find the correct brew installation path for qemu firmware
7578
if runtime.GOOS == "darwin" {

0 commit comments

Comments
 (0)