Skip to content

Commit

Permalink
qemu: add support for pidfile option
Browse files Browse the repository at this point in the history
Add input for -pidfile option of qemu, so that we can get pid of
qemu main process, and apply resource limitations to it.

Fixes #62

Signed-off-by: l00397676 <lujingxiao@huawei.com>
  • Loading branch information
jingxiaolu committed Nov 21, 2018
1 parent e82e849 commit 10c36a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 11 additions & 0 deletions qemu/qemu.go
Expand Up @@ -1516,6 +1516,9 @@ type Config struct {

IOThreads []IOThread

// PidFile is the -pidfile parameter
PidFile string

qemuParams []string
}

Expand Down Expand Up @@ -1830,6 +1833,13 @@ func (config *Config) appendIncoming() {
config.qemuParams = append(config.qemuParams, "-S", "-incoming", uri)
}

func (config *Config) appendPidFile() {
if config.PidFile != "" {
config.qemuParams = append(config.qemuParams, "-pidfile")
config.qemuParams = append(config.qemuParams, config.PidFile)
}
}

// LaunchQemu can be used to launch a new qemu instance.
//
// The Config parameter contains a set of qemu parameters and settings.
Expand All @@ -1855,6 +1865,7 @@ func LaunchQemu(config Config, logger QMPLog) (string, error) {
config.appendBios()
config.appendIOThreads()
config.appendIncoming()
config.appendPidFile()

if err := config.appendCPUs(); err != nil {
return "", err
Expand Down
5 changes: 4 additions & 1 deletion qemu/qemu_test.go
Expand Up @@ -738,19 +738,22 @@ func TestAppendQMPSocketServer(t *testing.T) {
testAppend(qmp, qmpSocketServerString, t)
}

var qemuString = "-name cc-qemu -cpu host -uuid " + agentUUID
var pidfile = "/run/vc/vm/iamsandboxid/pidfile"
var qemuString = "-name cc-qemu -cpu host -uuid " + agentUUID + " -pidfile " + pidfile

func TestAppendStrings(t *testing.T) {
config := Config{
Path: "qemu",
Name: "cc-qemu",
UUID: agentUUID,
CPUModel: "host",
PidFile: pidfile,
}

config.appendName()
config.appendCPUModel()
config.appendUUID()
config.appendPidFile()

result := strings.Join(config.qemuParams, " ")
if result != qemuString {
Expand Down

0 comments on commit 10c36a1

Please sign in to comment.