Skip to content

Commit 65ae9b1

Browse files
authored
Merge pull request lxc#1531 from bensmrs/main
incusd/instance/qemu: Fix QMP arguments typing
2 parents 83b5c05 + 3ed3a4a commit 65ae9b1

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

internal/server/instance/drivers/driver_qemu.go

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2393,7 +2393,7 @@ func (d *qemu) deviceAttachPath(deviceName string, configCopy map[string]string,
23932393

23942394
d.logger.Debug("Using PCI bus device to hotplug virtiofs into", logger.Ctx{"device": deviceName, "port": pciDeviceName})
23952395

2396-
qemuDev := map[string]string{
2396+
qemuDev := map[string]any{
23972397
"driver": "vhost-user-fs-pci",
23982398
"bus": pciDeviceName,
23992399
"addr": "00.0",
@@ -2535,7 +2535,7 @@ func (d *qemu) deviceAttachNIC(deviceName string, configCopy map[string]string,
25352535
return err
25362536
}
25372537

2538-
qemuDev := make(map[string]string)
2538+
qemuDev := make(map[string]any)
25392539

25402540
// PCIe and PCI require a port device name to hotplug the NIC into.
25412541
if slices.Contains([]string{"pcie", "pci"}, qemuBus) {
@@ -2633,7 +2633,7 @@ func (d *qemu) deviceAttachPCI(deviceName string, configCopy map[string]string,
26332633
return err
26342634
}
26352635

2636-
qemuDev := make(map[string]string)
2636+
qemuDev := make(map[string]any)
26372637
escapedDeviceName := linux.PathNameEncode(devName)
26382638

26392639
d.logger.Debug("Using PCI bus device to hotplug NIC into", logger.Ctx{"device": deviceName, "port": pciDeviceName})
@@ -3589,7 +3589,7 @@ func (d *qemu) generateQemuConfigFile(cpuInfo *cpuTopology, mountInfo *storagePo
35893589
break
35903590
}
35913591

3592-
qemuDev := make(map[string]string)
3592+
qemuDev := make(map[string]any)
35933593
if slices.Contains([]string{"nvme", "virtio-blk"}, busName) {
35943594
// Allocate a PCI(e) port and write it to the config file so QMP can "hotplug" the
35953595
// drive into it later.
@@ -3600,7 +3600,7 @@ func (d *qemu) generateQemuConfigFile(cpuInfo *cpuTopology, mountInfo *storagePo
36003600
qemuDev["addr"] = devAddr
36013601

36023602
if multi {
3603-
qemuDev["multifunction"] = "on"
3603+
qemuDev["multifunction"] = true
36043604
}
36053605
}
36063606

@@ -3624,7 +3624,7 @@ func (d *qemu) generateQemuConfigFile(cpuInfo *cpuTopology, mountInfo *storagePo
36243624

36253625
// Add network device.
36263626
if len(runConf.NetworkInterface) > 0 {
3627-
qemuDev := make(map[string]string)
3627+
qemuDev := make(map[string]any)
36283628
if slices.Contains([]string{"pcie", "pci"}, bus.name) {
36293629
// Allocate a PCI(e) port and write it to the config file so QMP can "hotplug" the
36303630
// NIC into it later.
@@ -3635,7 +3635,7 @@ func (d *qemu) generateQemuConfigFile(cpuInfo *cpuTopology, mountInfo *storagePo
36353635
qemuDev["addr"] = devAddr
36363636

36373637
if multi {
3638-
qemuDev["multifunction"] = "on"
3638+
qemuDev["multifunction"] = true
36393639
}
36403640
}
36413641

@@ -3860,7 +3860,7 @@ func (d *qemu) addFileDescriptor(fdFiles *[]*os.File, file *os.File) int {
38603860
}
38613861

38623862
// addRootDriveConfig adds the qemu config required for adding the root drive.
3863-
func (d *qemu) addRootDriveConfig(qemuDev map[string]string, mountInfo *storagePools.MountInfo, bootIndexes map[string]int, rootDriveConf deviceConfig.MountEntryItem) (monitorHook, error) {
3863+
func (d *qemu) addRootDriveConfig(qemuDev map[string]any, mountInfo *storagePools.MountInfo, bootIndexes map[string]int, rootDriveConf deviceConfig.MountEntryItem) (monitorHook, error) {
38643864
if rootDriveConf.TargetPath != "/" {
38653865
return nil, fmt.Errorf("Non-root drive config supplied")
38663866
}
@@ -3992,7 +3992,7 @@ func (d *qemu) addDriveDirConfig(cfg *[]cfgSection, bus *qemuBus, fdFiles *[]*os
39923992
}
39933993

39943994
// addDriveConfig adds the qemu config required for adding a supplementary drive.
3995-
func (d *qemu) addDriveConfig(qemuDev map[string]string, bootIndexes map[string]int, driveConf deviceConfig.MountEntryItem) (monitorHook, error) {
3995+
func (d *qemu) addDriveConfig(qemuDev map[string]any, bootIndexes map[string]int, driveConf deviceConfig.MountEntryItem) (monitorHook, error) {
39963996
aioMode := "native" // Use native kernel async IO and O_DIRECT by default.
39973997
cacheMode := "none" // Bypass host cache, use O_DIRECT semantics by default.
39983998
media := "disk"
@@ -4248,16 +4248,16 @@ func (d *qemu) addDriveConfig(qemuDev map[string]string, bootIndexes map[string]
42484248
}
42494249

42504250
if qemuDev == nil {
4251-
qemuDev = map[string]string{}
4251+
qemuDev = map[string]any{}
42524252
}
42534253

42544254
qemuDev["id"] = fmt.Sprintf("%s%s", qemuDeviceIDPrefix, escapedDeviceName)
42554255
qemuDev["drive"] = blockDev["node-name"].(string)
42564256
qemuDev["serial"] = fmt.Sprintf("%s%s", qemuBlockDevIDPrefix, escapedDeviceName)
42574257

42584258
if bus == "virtio-scsi" {
4259-
qemuDev["channel"] = "0"
4260-
qemuDev["lun"] = "1"
4259+
qemuDev["channel"] = 0
4260+
qemuDev["lun"] = 1
42614261
qemuDev["bus"] = "qemu_scsi.0"
42624262

42634263
if media == "disk" {
@@ -4282,7 +4282,7 @@ func (d *qemu) addDriveConfig(qemuDev map[string]string, bootIndexes map[string]
42824282
}
42834283

42844284
if bootIndexes != nil {
4285-
qemuDev["bootindex"] = strconv.Itoa(bootIndexes[driveConf.DevName])
4285+
qemuDev["bootindex"] = bootIndexes[driveConf.DevName]
42864286
}
42874287

42884288
monHook := func(m *qmp.Monitor) error {
@@ -4336,7 +4336,7 @@ func (d *qemu) addDriveConfig(qemuDev map[string]string, bootIndexes map[string]
43364336
}
43374337

43384338
if driveConf.Limits != nil {
4339-
err = m.SetBlockThrottle(qemuDev["id"], int(driveConf.Limits.ReadBytes), int(driveConf.Limits.WriteBytes), int(driveConf.Limits.ReadIOps), int(driveConf.Limits.WriteIOps))
4339+
err = m.SetBlockThrottle(qemuDev["id"].(string), int(driveConf.Limits.ReadBytes), int(driveConf.Limits.WriteBytes), int(driveConf.Limits.ReadIOps), int(driveConf.Limits.WriteIOps))
43404340
if err != nil {
43414341
return fmt.Errorf("Failed applying limits for disk device %q: %w", driveConf.DevName, err)
43424342
}
@@ -4351,7 +4351,7 @@ func (d *qemu) addDriveConfig(qemuDev map[string]string, bootIndexes map[string]
43514351

43524352
// addNetDevConfig adds the qemu config required for adding a network device.
43534353
// The qemuDev map is expected to be preconfigured with the settings for an existing port to use for the device.
4354-
func (d *qemu) addNetDevConfig(busName string, qemuDev map[string]string, bootIndexes map[string]int, nicConfig []deviceConfig.RunConfigItem) (monitorHook, error) {
4354+
func (d *qemu) addNetDevConfig(busName string, qemuDev map[string]any, bootIndexes map[string]int, nicConfig []deviceConfig.RunConfigItem) (monitorHook, error) {
43554355
reverter := revert.New()
43564356
defer reverter.Fail()
43574357

@@ -4382,7 +4382,7 @@ func (d *qemu) addNetDevConfig(busName string, qemuDev map[string]string, bootIn
43824382
if len(bootIndexes) > 0 {
43834383
bootIndex, found := bootIndexes[devName]
43844384
if found {
4385-
qemuDev["bootindex"] = strconv.Itoa(bootIndex)
4385+
qemuDev["bootindex"] = bootIndex
43864386
}
43874387
}
43884388

@@ -4400,9 +4400,9 @@ func (d *qemu) addNetDevConfig(busName string, qemuDev map[string]string, bootIn
44004400
// Number of vectors is number of vCPUs * 2 (RX/TX) + 2 (config/control MSI-X).
44014401
vectors := 2*queueCount + 2
44024402
if vectors > 0 {
4403-
qemuDev["mq"] = "on"
4403+
qemuDev["mq"] = true
44044404
if slices.Contains([]string{"pcie", "pci"}, busName) {
4405-
qemuDev["vectors"] = strconv.Itoa(vectors)
4405+
qemuDev["vectors"] = vectors
44064406
}
44074407
}
44084408

@@ -4591,9 +4591,9 @@ func (d *qemu) addNetDevConfig(busName string, qemuDev map[string]string, bootIn
45914591
}
45924592

45934593
qemuDev["netdev"] = qemuNetDev["id"].(string)
4594-
qemuDev["page-per-vq"] = "on"
4595-
qemuDev["iommu_platform"] = "on"
4596-
qemuDev["disable-legacy"] = "on"
4594+
qemuDev["page-per-vq"] = true
4595+
qemuDev["iommu_platform"] = true
4596+
qemuDev["disable-legacy"] = true
45974597

45984598
err = m.AddNIC(qemuNetDev, qemuDev)
45994599
if err != nil {
@@ -4819,7 +4819,7 @@ func (d *qemu) addGPUDevConfig(cfg *[]cfgSection, bus *qemuBus, gpuConfig []devi
48194819
}
48204820

48214821
func (d *qemu) addUSBDeviceConfig(usbDev deviceConfig.USBDeviceItem) (monitorHook, error) {
4822-
device := map[string]string{
4822+
qemuDev := map[string]any{
48234823
"id": fmt.Sprintf("%s%s", qemuDeviceIDPrefix, usbDev.DeviceName),
48244824
"driver": "usb-host",
48254825
"bus": "qemu_usb.0",
@@ -4836,18 +4836,18 @@ func (d *qemu) addUSBDeviceConfig(usbDev deviceConfig.USBDeviceItem) (monitorHoo
48364836

48374837
defer func() { _ = f.Close() }()
48384838

4839-
info, err := m.SendFileWithFDSet(device["id"], f, false)
4839+
info, err := m.SendFileWithFDSet(qemuDev["id"].(string), f, false)
48404840
if err != nil {
48414841
return fmt.Errorf("Failed to send file descriptor: %w", err)
48424842
}
48434843

48444844
revert.Add(func() {
4845-
_ = m.RemoveFDFromFDSet(device["id"])
4845+
_ = m.RemoveFDFromFDSet(qemuDev["id"].(string))
48464846
})
48474847

4848-
device["hostdevice"] = fmt.Sprintf("/dev/fdset/%d", info.ID)
4848+
qemuDev["hostdevice"] = fmt.Sprintf("/dev/fdset/%d", info.ID)
48494849

4850-
err = m.AddDevice(device)
4850+
err = m.AddDevice(qemuDev)
48514851
if err != nil {
48524852
return fmt.Errorf("Failed to add device: %w", err)
48534853
}
@@ -9188,19 +9188,19 @@ func (d *qemu) setCPUs(monitor *qmp.Monitor, count int) error {
91889188

91899189
devID := fmt.Sprintf("cpu%d%d%d", cpu.Props.SocketID, cpu.Props.CoreID, cpu.Props.ThreadID)
91909190

9191-
dev := map[string]string{
9191+
qemuDev := map[string]any{
91929192
"id": devID,
91939193
"driver": cpu.Type,
9194-
"core-id": fmt.Sprintf("%d", cpu.Props.CoreID),
9194+
"core-id": cpu.Props.CoreID,
91959195
}
91969196

91979197
// No such thing as sockets and threads on s390x.
91989198
if d.architecture != osarch.ARCH_64BIT_S390_BIG_ENDIAN {
9199-
dev["socket-id"] = fmt.Sprintf("%d", cpu.Props.SocketID)
9200-
dev["thread-id"] = fmt.Sprintf("%d", cpu.Props.ThreadID)
9199+
qemuDev["socket-id"] = cpu.Props.SocketID
9200+
qemuDev["thread-id"] = cpu.Props.ThreadID
92019201
}
92029202

9203-
err := monitor.AddDevice(dev)
9203+
err := monitor.AddDevice(qemuDev)
92049204
if err != nil {
92059205
return fmt.Errorf("Failed to add device: %w", err)
92069206
}
@@ -9229,12 +9229,12 @@ func (d *qemu) setCPUs(monitor *qmp.Monitor, count int) error {
92299229
}
92309230

92319231
revert.Add(func() {
9232-
err := monitor.AddDevice(map[string]string{
9232+
err := monitor.AddDevice(map[string]any{
92339233
"id": devID,
92349234
"driver": cpu.Type,
9235-
"socket-id": fmt.Sprintf("%d", cpu.Props.SocketID),
9236-
"core-id": fmt.Sprintf("%d", cpu.Props.CoreID),
9237-
"thread-id": fmt.Sprintf("%d", cpu.Props.ThreadID),
9235+
"socket-id": cpu.Props.SocketID,
9236+
"core-id": cpu.Props.CoreID,
9237+
"thread-id": cpu.Props.ThreadID,
92389238
})
92399239
d.logger.Warn("Failed to add CPU device", logger.Ctx{"err": err})
92409240
})

internal/server/instance/drivers/qmp/commands.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ func (m *Monitor) SetMemoryBalloonSizeBytes(sizeBytes int64) error {
538538
}
539539

540540
// AddBlockDevice adds a block device.
541-
func (m *Monitor) AddBlockDevice(blockDev map[string]any, device map[string]string) error {
541+
func (m *Monitor) AddBlockDevice(blockDev map[string]any, device map[string]any) error {
542542
revert := revert.New()
543543
defer revert.Fail()
544544

@@ -624,7 +624,7 @@ func (m *Monitor) RemoveCharDevice(deviceID string) error {
624624
}
625625

626626
// AddDevice adds a new device.
627-
func (m *Monitor) AddDevice(device map[string]string) error {
627+
func (m *Monitor) AddDevice(device map[string]any) error {
628628
if device != nil {
629629
err := m.Run("device_add", device, nil)
630630
if err != nil {
@@ -656,7 +656,7 @@ func (m *Monitor) RemoveDevice(deviceID string) error {
656656
}
657657

658658
// AddNIC adds a NIC device.
659-
func (m *Monitor) AddNIC(netDev map[string]any, device map[string]string) error {
659+
func (m *Monitor) AddNIC(netDev map[string]any, device map[string]any) error {
660660
revert := revert.New()
661661
defer revert.Fail()
662662

0 commit comments

Comments
 (0)