From 10065f5d357a156cecd14003c9c125e4291081dd Mon Sep 17 00:00:00 2001 From: Xujun Ma Date: Fri, 20 Dec 2024 15:14:04 +0800 Subject: [PATCH] Add device address parameter for s390x Signed-off-by: Xujun Ma --- virttest/qemu_devices/qcontainer.py | 6 +-- virttest/qemu_devices/qdevices.py | 82 +++++++++++++++++++---------- 2 files changed, 57 insertions(+), 31 deletions(-) diff --git a/virttest/qemu_devices/qcontainer.py b/virttest/qemu_devices/qcontainer.py index 841d125caf..8602d5b703 100644 --- a/virttest/qemu_devices/qcontainer.py +++ b/virttest/qemu_devices/qcontainer.py @@ -1699,9 +1699,7 @@ def machine_s390_virtio(machine_params): # can't be used. LOG.warning("Support for s390x is highly experimental!") bus = ( - qdevices.QNoAddrCustomBus( - "bus", - [["addr"], [32]], + qdevices.QCSSBus( "virtual-css", "virtual-css", "virtual-css", @@ -2475,7 +2473,7 @@ def define_hbas( if scsi_hba == "virtio-scsi-device": pci_bus = {"type": "virtio-bus"} elif scsi_hba == "virtio-scsi-ccw": - pci_bus = None + pci_bus = {"type": "virtual-css"} elif scsi_hba == "spapr-vscsi": addr_spec = [64, 32] pci_bus = None diff --git a/virttest/qemu_devices/qdevices.py b/virttest/qemu_devices/qdevices.py index 1df7b963fa..3b6bb3a7ca 100644 --- a/virttest/qemu_devices/qdevices.py +++ b/virttest/qemu_devices/qdevices.py @@ -6,6 +6,7 @@ :copyright: 2012-2013 Red Hat Inc. """ + import json import logging import os @@ -63,7 +64,6 @@ def _build_cmd(cmd, args=None, q_id=None): # Device objects # class QBaseDevice(object): - """Base class of qemu objects""" def __init__( @@ -378,7 +378,6 @@ def is_pcie_device(self): class QStringDevice(QBaseDevice): - """ General device which allows to specify methods by fixed or parametrizable strings in this format: @@ -444,7 +443,6 @@ def cmdline_nd(self): class QCustomDevice(QBaseDevice): - """ Representation of the '-$option $param1=$value1,$param2...' qemu object. This representation handles only cmdline. @@ -515,7 +513,6 @@ def cmdline_nd(self): class QDrive(QCustomDevice): - """ Representation of the '-drive' qemu object without hotplug support. """ @@ -545,7 +542,6 @@ def set_param(self, option, value, option_type=None): class QOldDrive(QDrive): - """ This is a variant for -drive without 'addr' support """ @@ -566,7 +562,6 @@ def set_param(self, option, value, option_type=None): class QHPDrive(QDrive): - """ Representation of the '-drive' qemu object with hotplug support. """ @@ -640,7 +635,6 @@ def unplug_hmp(self): class QRHDrive(QDrive): - """ Representation of the '-drive' qemu object with RedHat hotplug support. """ @@ -1118,7 +1112,6 @@ class QBlockdevProtocolFTPS(QBlockdevProtocol): class QDevice(QCustomDevice): - """ Representation of the '-device' qemu object. It supports all methods. :note: Use driver format in full form - 'driver' = '...' (usb-ehci, ide-hd) @@ -1309,7 +1302,6 @@ def _cmdline_json(self): class QGlobal(QBaseDevice): - """ Representation of qemu global setting (-global driver.property=value) """ @@ -1334,7 +1326,6 @@ def cmdline(self): class QFloppy(QGlobal): - """ Imitation of qemu floppy disk defined by -global isa-fdc.drive?=$drive """ @@ -1368,7 +1359,6 @@ def set_param(self, option, value, option_type=None): class QObject(QCustomDevice): - """ Representation of the '-object backend' qemu object. """ @@ -1616,7 +1606,6 @@ def verify_unplug(self, out, monitor): class Memory(QObject): - """ QOM memory object, support for pinning memory on host NUMA nodes. The existing options in __attributes__ are subsumed by the QOM objects @@ -2660,7 +2649,6 @@ def verify_hotplug(self, out, monitor): # virtio-serial-bus # class QSparseBus(object): - """ Universal bus representation object. @@ -3062,7 +3050,6 @@ def match_bus(self, bus_spec, type_test=True): class QStrictCustomBus(QSparseBus): - """ Similar to QSparseBus. The address starts with 1 and addr is always set """ @@ -3089,7 +3076,6 @@ def _update_device_props(self, device, addr): class QNoAddrCustomBus(QSparseBus): - """ This is the opposite of QStrictCustomBus. Even when addr is set it's not updated in the device's params. @@ -3103,7 +3089,6 @@ def _update_device_props(self, device, addr): class QUSBBus(QSparseBus): - """ USB bus representation including usb-hub handling. """ @@ -3179,7 +3164,6 @@ def _update_device_props(self, device, addr): class QDriveBus(QSparseBus): - """ QDrive bus representation (single slot, drive=...) """ @@ -3212,7 +3196,6 @@ def _update_device_props(self, device, addr): class QDenseBus(QSparseBus): - """ Dense bus representation. The only difference from SparseBus is the output string format. DenseBus iterates over all addresses and show free slots @@ -3252,7 +3235,6 @@ def _str_devices(self): class QPCIBus(QSparseBus): - """ PCI Bus representation (bus&addr, uses hex digits) """ @@ -3514,7 +3496,6 @@ def prepare_hotplug(self, device): class QPCISwitchBus(QPCIBus): - """ PCI Switch bus representation (creates downstream device while inserting a device). @@ -3569,7 +3550,6 @@ def _set_device_props(self, device, addr): class QSCSIBus(QSparseBus): - """ SCSI bus representation (bus + 2 leves, don't iterate over lun by default) """ @@ -3598,7 +3578,6 @@ def _increment_addr(self, addr, last_addr=None): class QBusUnitBus(QDenseBus): - """Implementation of bus-unit/nr bus (ahci, ide, virtio-serial)""" def __init__( @@ -3663,7 +3642,6 @@ def _dev2addr(self, device): class QSerialBus(QBusUnitBus): - """Serial bus representation""" def __init__(self, busid, bus_type, aobject=None, max_ports=32): @@ -3681,7 +3659,6 @@ def __init__(self, busid, bus_type, aobject=None, max_ports=32): class QAHCIBus(QBusUnitBus): - """AHCI bus (ich9-ahci, ahci)""" def __init__(self, busid, aobject=None): @@ -3690,7 +3667,6 @@ def __init__(self, busid, aobject=None): class QIDEBus(QBusUnitBus): - """IDE bus (piix3-ide)""" def __init__(self, busid, aobject=None): @@ -3699,7 +3675,6 @@ def __init__(self, busid, aobject=None): class QFloppyBus(QDenseBus): - """ Floppy bus (-global isa-fdc.drive?=$drive) """ @@ -3735,7 +3710,6 @@ def _set_device_props(self, device, addr): class QOldFloppyBus(QDenseBus): - """ Floppy bus (-drive index=n) """ @@ -3983,3 +3957,57 @@ def _cmdline_raw(self): # -machine allows empty line return "" return super()._cmdline_raw() + + +class QCSSBus(QSparseBus): + """ + CSS Bus representation (bus&ssid&devno, uses hex digits) + """ + + def __init__(self, busid, bus_type, aobject): + """bus&ssid&devno, 4 ssid and 65536 device numbers""" + super(QCSSBus, self).__init__( + "bus", [["ssid", "devno"], [4, 65536]], busid, bus_type, aobject + ) + + @staticmethod + def _addr2stor(addr): + """ + Converts internal addr to storable/hashable address + :param addr: internal address [addr1, addr2, ...] + :return: storable address "addr1-addr2-..." + """ + out = "" + for value in addr: + if value is None: + out += "*-" + else: + out += "%s-" % value + if out: + return out[:-1] + else: + return "*" + + def _dev2addr(self, device): + """Read the values in base of 16 (hex)""" + addr = device.get_param("addr") + if isinstance(addr, int): # only addr + return [0, addr] + elif not addr: # not defined + return [0, None] + elif isinstance(addr, six.string_types): # ssid.addr + addr = [int(_, 16) for _ in addr.split(".", 1)] + if len(addr) < 2: # only addr + addr.insert(0, 0) + return addr + + def _set_device_props(self, device, addr): + """Convert addr to the format used by qtree""" + if device.get_param("addr"): + del device.params["addr"] + device.set_param("devno", "fe.%s.%s" % ( + hex(addr[0])[2:], f"{addr[1]:04x}")) + + def _update_device_props(self, device, addr): + """Always set properties""" + self._set_device_props(device, addr)