qemu: Add function to hotplug CPUs

ExecuteCPUDeviceAdd hot-adds a CPU to a running VM

Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
Julio Montes 2017-12-06 12:50:59 -06:00
parent 24b14059b3
commit 8c428ed722
2 changed files with 37 additions and 0 deletions

15
qmp.go
View File

@ -736,3 +736,18 @@ func (q *QMP) ExecutePCIVFIODeviceAdd(ctx context.Context, devID, bdf, addr, bus
}
return q.executeCommand(ctx, "device_add", args, nil)
}
// ExecuteCPUDeviceAdd adds a CPU to a QEMU instance using the device_add command.
// driver is the CPU model, cpuID must be a unique ID to identify the CPU, socketID is the socket number within
// node/board the CPU belongs to, coreID is the core number within socket the CPU belongs to, threadID is the
// thread number within core the CPU belongs to.
func (q *QMP) ExecuteCPUDeviceAdd(ctx context.Context, driver, cpuID, socketID, coreID, threadID string) error {
args := map[string]interface{}{
"driver": driver,
"id": cpuID,
"socket-id": socketID,
"core-id": coreID,
"thread-id": threadID,
}
return q.executeCommand(ctx, "device_add", args, nil)
}

View File

@ -810,3 +810,25 @@ func TestQMPPCIDeviceAdd(t *testing.T) {
q.Shutdown()
<-disconnectedCh
}
// Checks that CPU are correctly added using device_add
func TestQMPCPUDeviceAdd(t *testing.T) {
connectedCh := make(chan *QMPVersion)
disconnectedCh := make(chan struct{})
buf := newQMPTestCommandBuffer(t)
buf.AddCommand("device_add", nil, "return", nil)
cfg := QMPConfig{Logger: qmpTestLogger{}}
q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh)
checkVersion(t, connectedCh)
driver := "qemu64-x86_64-cpu"
cpuID := "cpu-0"
socketID := "0"
coreID := "1"
threadID := "0"
err := q.ExecuteCPUDeviceAdd(context.Background(), driver, cpuID, socketID, coreID, threadID)
if err != nil {
t.Fatalf("Unexpected error %v", err)
}
q.Shutdown()
<-disconnectedCh
}