Skip to content

Allow using named pipes for qemu communication #981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,8 @@ require (
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/djherbis/times.v1 v1.2.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
)

replace github.com/digitalocean/go-qemu => github.com/afbjorklund/go-qemu v0.0.0-20220622184141-601d8abbe440
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDe
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM=
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
github.com/afbjorklund/go-qemu v0.0.0-20220622184141-601d8abbe440 h1:G+1Tru1X+VT5jzA6WLOCVusAYTzeHqukV0Tw6REqzpI=
github.com/afbjorklund/go-qemu v0.0.0-20220622184141-601d8abbe440/go.mod h1:bt9w5ZPDWgP/9ySrH8KA7zmJ1Thc0XeCwwTM1WsFQnM=
github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0=
github.com/alessio/shellescape v1.4.1/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
Expand Down Expand Up @@ -332,6 +334,8 @@ gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/djherbis/times.v1 v1.2.0 h1:UCvDKl1L/fmBygl2Y7hubXCnY7t4Yj46ZrBFNUipFbM=
gopkg.in/djherbis/times.v1 v1.2.0/go.mod h1:AQlg6unIsrsCEdQYhTzERy542dz6SFdQFZFv6mUY0P8=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7GC73Ei8pv4MzjDUNPHgQWJdtMAaDU=
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce/go.mod h1:5AcXVHNjg+BDxry382+8OKon8SEWiKktQR07RKPsv1c=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
33 changes: 33 additions & 0 deletions pkg/qemu/pipe_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//go:build !windows
// +build !windows

package qemu

import (
"syscall"
)

func createFifo(path string) error {
var stat syscall.Stat_t
err := syscall.Stat(path, &stat)
if err != nil {
if err.(syscall.Errno) != syscall.ENOENT {
return err
}
} else {
if stat.Mode&syscall.S_IFMT == syscall.S_IFIFO {
return nil
}
}
return syscall.Mkfifo(path, 0600)
}

func PipeMakeFifo(path string) error {
if err := createFifo(path + ".in"); err != nil {
return err
}
if err := createFifo(path + ".out"); err != nil {
return err
}
return nil
}
6 changes: 6 additions & 0 deletions pkg/qemu/pipe_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package qemu

func PipeMakeFifo(path string) error {
// created automatically
return nil
}
56 changes: 48 additions & 8 deletions pkg/qemu/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ func Cmdline(cfg Config) (string, []string, error) {
return "", nil, err
}

unix := runtime.GOOS != "windows"

features, err := inspectFeatures(exe)
if err != nil {
return "", nil, err
Expand Down Expand Up @@ -530,16 +532,35 @@ func Cmdline(cfg Config) (string, []string, error) {
args = append(args, "-parallel", "none")

// Serial
serialSock := filepath.Join(cfg.InstanceDir, filenames.SerialSock)
if err := os.RemoveAll(serialSock); err != nil {
return "", nil, err
var serialSock string
if unix {
serialSock := filepath.Join(cfg.InstanceDir, filenames.SerialSock)
if err := os.RemoveAll(serialSock); err != nil {
return "", nil, err
}
} else {
if runtime.GOOS != "windows" {
// path.in,path.out
serialSock = filepath.Join(cfg.InstanceDir, "serial")
if err := PipeMakeFifo(serialSock); err != nil {
return "", nil, err
}
} else {
// `\\.pipe\path`
serialSock = "lima" + "-" + cfg.Name + "." + filenames.SerialPipe
}
}
serialLog := filepath.Join(cfg.InstanceDir, filenames.SerialLog)
if err := os.RemoveAll(serialLog); err != nil {
return "", nil, err
}
const serialChardev = "char-serial"
args = append(args, "-chardev", fmt.Sprintf("socket,id=%s,path=%s,server=on,wait=off,logfile=%s", serialChardev, serialSock, serialLog))
if unix {
args = append(args, "-chardev", fmt.Sprintf("socket,id=%s,path=%s,server=on,wait=off,logfile=%s", serialChardev, serialSock, serialLog))
} else {
//args = append(args, "-chardev", fmt.Sprintf("pipe,id=%s,path=%s,server=on,wait=off,logfile=%s", serialChardev, serialSock, serialLog))
args = append(args, "-chardev", fmt.Sprintf("null,id=%s,path=%s,server=on,wait=off,logfile=%s", serialChardev, serialSock, serialLog))
}
args = append(args, "-serial", "chardev:"+serialChardev)

// We also want to enable vsock here, but QEMU does not support vsock for macOS hosts
Expand All @@ -566,12 +587,31 @@ func Cmdline(cfg Config) (string, []string, error) {
}

// QMP
qmpSock := filepath.Join(cfg.InstanceDir, filenames.QMPSock)
if err := os.RemoveAll(qmpSock); err != nil {
return "", nil, err
var qmpSock string
if unix {
qmpSock = filepath.Join(cfg.InstanceDir, filenames.QMPSock)
if err := os.RemoveAll(qmpSock); err != nil {
return "", nil, err
}
} else {
if runtime.GOOS != "windows" {
// path.in,path.out
qmpSock = filepath.Join(cfg.InstanceDir, filenames.QMPPipe)
if err := PipeMakeFifo(qmpSock); err != nil {
return "", nil, err
}
} else {
// `\\.pipe\path`
qmpSock = "lima" + "-" + cfg.Name + "." + filenames.QMPPipe
}
}
const qmpChardev = "char-qmp"
args = append(args, "-chardev", fmt.Sprintf("socket,id=%s,path=%s,server=on,wait=off", qmpChardev, qmpSock))
if unix {
args = append(args, "-chardev", fmt.Sprintf("socket,id=%s,path=%s,server=on,wait=off", qmpChardev, qmpSock))
} else {
//args = append(args, "-chardev", fmt.Sprintf("pipe,id=%s,path=%s,server=on,wait=off", qmpChardev, qmpSock))
args = append(args, "-chardev", fmt.Sprintf("null,id=%s,path=%s,server=on,wait=off", qmpChardev, qmpSock))
}
args = append(args, "-qmp", "chardev:"+qmpChardev)

// QEMU process
Expand Down
2 changes: 2 additions & 0 deletions pkg/store/filenames/filenames.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ const (
Initrd = "initrd"
QemuPID = "qemu.pid"
QMPSock = "qmp.sock"
QMPPipe = "qmp"
SerialLog = "serial.log"
SerialSock = "serial.sock"
SerialPipe = "serial"
SSHSock = "ssh.sock"
GuestAgentSock = "ga.sock"
HostAgentPID = "ha.pid"
Expand Down