mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-05-01 21:24:36 +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:
parent
723bc5f3c6
commit
0ace4176b4
36
qemu/qemu.go
36
qemu/qemu.go
@ -1194,6 +1194,24 @@ type IOThread struct {
|
|||||||
ID string
|
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.
|
// Config is the qemu configuration structure.
|
||||||
// It allows for passing custom settings and parameters to the qemu API.
|
// It allows for passing custom settings and parameters to the qemu API.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
@ -1245,6 +1263,9 @@ type Config struct {
|
|||||||
// Bios is the -bios parameter
|
// Bios is the -bios parameter
|
||||||
Bios string
|
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 is a list of open file descriptors to be passed to the spawned qemu process
|
||||||
fds []*os.File
|
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.
|
// LaunchQemu can be used to launch a new qemu instance.
|
||||||
//
|
//
|
||||||
// The Config parameter contains a set of qemu parameters and settings.
|
// 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.appendKernel()
|
||||||
config.appendBios()
|
config.appendBios()
|
||||||
config.appendIOThreads()
|
config.appendIOThreads()
|
||||||
|
config.appendIncoming()
|
||||||
|
|
||||||
if err := config.appendCPUs(); err != nil {
|
if err := config.appendCPUs(); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -71,6 +71,9 @@ func testAppend(structure interface{}, expected string, t *testing.T) {
|
|||||||
case IOThread:
|
case IOThread:
|
||||||
config.IOThreads = []IOThread{s}
|
config.IOThreads = []IOThread{s}
|
||||||
config.appendIOThreads()
|
config.appendIOThreads()
|
||||||
|
case Incoming:
|
||||||
|
config.Incoming = s
|
||||||
|
config.appendIncoming()
|
||||||
}
|
}
|
||||||
|
|
||||||
result := strings.Join(config.qemuParams, " ")
|
result := strings.Join(config.qemuParams, " ")
|
||||||
@ -563,3 +566,25 @@ func TestAppendIOThread(t *testing.T) {
|
|||||||
|
|
||||||
testAppend(ioThread, ioThreadString, 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)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user