1
0
mirror of https://github.com/kata-containers/kata-containers.git synced 2025-04-30 04:34:27 +00:00

qemu: allow to set migration incoming

It is useful when we want to specify migration incoming source.
Supported source are fd and exec right now.

Signed-off-by: Peng Tao <bergwolf@gmail.com>
This commit is contained in:
Peng Tao 2018-05-07 17:50:19 +08:00
parent 723bc5f3c6
commit 0ace4176b4
2 changed files with 61 additions and 0 deletions

View File

@ -1194,6 +1194,24 @@ type IOThread struct {
ID string
}
const (
// MigrationFD is the migration incoming type based on open file descriptor.
// Skip default 0 so that it must be set on purpose.
MigrationFD = 1
// MigrationExec is the migration incoming type based on commands.
MigrationExec = 2
)
// Incoming controls migration source preparation
type Incoming struct {
// Possible values are MigrationFD, MigrationExec
MigrationType int
// Only valid if MigrationType == MigrationFD
FD *os.File
// Only valid if MigrationType == MigrationExec
Exec string
}
// Config is the qemu configuration structure.
// It allows for passing custom settings and parameters to the qemu API.
type Config struct {
@ -1245,6 +1263,9 @@ type Config struct {
// Bios is the -bios parameter
Bios string
// Incoming controls migration source preparation
Incoming Incoming
// fds is a list of open file descriptors to be passed to the spawned qemu process
fds []*os.File
@ -1546,6 +1567,20 @@ func (config *Config) appendIOThreads() {
}
}
func (config *Config) appendIncoming() {
var uri string
switch config.Incoming.MigrationType {
case MigrationExec:
uri = fmt.Sprintf("exec:%s", config.Incoming.Exec)
case MigrationFD:
chFDs := config.appendFDs([]*os.File{config.Incoming.FD})
uri = fmt.Sprintf("fd:%d", chFDs[0])
default:
return
}
config.qemuParams = append(config.qemuParams, "-S", "-incoming", uri)
}
// LaunchQemu can be used to launch a new qemu instance.
//
// The Config parameter contains a set of qemu parameters and settings.
@ -1570,6 +1605,7 @@ func LaunchQemu(config Config, logger QMPLog) (string, error) {
config.appendKernel()
config.appendBios()
config.appendIOThreads()
config.appendIncoming()
if err := config.appendCPUs(); err != nil {
return "", err

View File

@ -71,6 +71,9 @@ func testAppend(structure interface{}, expected string, t *testing.T) {
case IOThread:
config.IOThreads = []IOThread{s}
config.appendIOThreads()
case Incoming:
config.Incoming = s
config.appendIncoming()
}
result := strings.Join(config.qemuParams, " ")
@ -563,3 +566,25 @@ func TestAppendIOThread(t *testing.T) {
testAppend(ioThread, ioThreadString, t)
}
var incomingStringFD = "-S -incoming fd:3"
func TestAppendIncomingFD(t *testing.T) {
source := Incoming{
MigrationType: MigrationFD,
FD: os.Stdout,
}
testAppend(source, incomingStringFD, t)
}
var incomingStringExec = "-S -incoming exec:test migration cmd"
func TestAppendIncomingExec(t *testing.T) {
source := Incoming{
MigrationType: MigrationExec,
Exec: "test migration cmd",
}
testAppend(source, incomingStringExec, t)
}