Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add device address parameter for s390x #4010

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions virttest/qemu_devices/qcontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down
82 changes: 55 additions & 27 deletions virttest/qemu_devices/qdevices.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

:copyright: 2012-2013 Red Hat Inc.
"""

import json
import logging
import os
Expand Down Expand Up @@ -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__(
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -515,7 +513,6 @@ def cmdline_nd(self):


class QDrive(QCustomDevice):

"""
Representation of the '-drive' qemu object without hotplug support.
"""
Expand Down Expand Up @@ -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
"""
Expand All @@ -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.
"""
Expand Down Expand Up @@ -640,7 +635,6 @@ def unplug_hmp(self):


class QRHDrive(QDrive):

"""
Representation of the '-drive' qemu object with RedHat hotplug support.
"""
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1309,7 +1302,6 @@ def _cmdline_json(self):


class QGlobal(QBaseDevice):

"""
Representation of qemu global setting (-global driver.property=value)
"""
Expand All @@ -1334,7 +1326,6 @@ def cmdline(self):


class QFloppy(QGlobal):

"""
Imitation of qemu floppy disk defined by -global isa-fdc.drive?=$drive
"""
Expand Down Expand Up @@ -1368,7 +1359,6 @@ def set_param(self, option, value, option_type=None):


class QObject(QCustomDevice):

"""
Representation of the '-object backend' qemu object.
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2660,7 +2649,6 @@ def verify_hotplug(self, out, monitor):
# virtio-serial-bus
#
class QSparseBus(object):

"""
Universal bus representation object.

Expand Down Expand Up @@ -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
"""
Expand All @@ -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.
Expand All @@ -3103,7 +3089,6 @@ def _update_device_props(self, device, addr):


class QUSBBus(QSparseBus):

"""
USB bus representation including usb-hub handling.
"""
Expand Down Expand Up @@ -3179,7 +3164,6 @@ def _update_device_props(self, device, addr):


class QDriveBus(QSparseBus):

"""
QDrive bus representation (single slot, drive=...)
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -3252,7 +3235,6 @@ def _str_devices(self):


class QPCIBus(QSparseBus):

"""
PCI Bus representation (bus&addr, uses hex digits)
"""
Expand Down Expand Up @@ -3514,7 +3496,6 @@ def prepare_hotplug(self, device):


class QPCISwitchBus(QPCIBus):

"""
PCI Switch bus representation (creates downstream device while inserting
a device).
Expand Down Expand Up @@ -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)
"""
Expand Down Expand Up @@ -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__(
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -3690,7 +3667,6 @@ def __init__(self, busid, aobject=None):


class QIDEBus(QBusUnitBus):

"""IDE bus (piix3-ide)"""

def __init__(self, busid, aobject=None):
Expand All @@ -3699,7 +3675,6 @@ def __init__(self, busid, aobject=None):


class QFloppyBus(QDenseBus):

"""
Floppy bus (-global isa-fdc.drive?=$drive)
"""
Expand Down Expand Up @@ -3735,7 +3710,6 @@ def _set_device_props(self, device, addr):


class QOldFloppyBus(QDenseBus):

"""
Floppy bus (-drive index=n)
"""
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, here only cover ssid and devno, as cssidset fe by default. However, should we cover unusual test scenarios? from the qemu doc

* a virtio-mouse device in a non-standard channel subsystem image::

    -device virtio-mouse-ccw,devno=2.0.2222

  This would not show up in a standard Linux guest.

  The properties for the device would be ``dev_id = "2.0.2222"`` and
  ``subch_id = "2.0.0000"``.

* a virtio-keyboard device in another non-standard channel subsystem image::

    -device virtio-keyboard-ccw,devno=0.0.1234

  This would not show up in a standard Linux guest, either, as ``0`` is not
  the standard channel subsystem image id.

  The properties for the device would be ``dev_id = "0.0.1234"`` and
  ``subch_id = "0.0.0000"``.

we can set cssid value rather than default fe, so how about includes the ssid but set fe by default.

)

@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}"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as we can mark sure the ssid only with length 0-3, so hex(addr[0])[2:] can easy transfer to addr[0]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And for f"{addr[1]:04x}"), of course your can "fe.%s.%4x" and addr[1] to do the same thing. Or just f"fe.{addr[0]}.{addr[1]:4x}"


def _update_device_props(self, device, addr):
"""Always set properties"""
self._set_device_props(device, addr)
Loading