virt-manager/virtinst/devices/memory.py
Lin Ma febddd4b01 cli: Add --memdev target.address_base for virtio-mem and virtio-pmem
Libvirt(since 9.4.0) allows to control this attribute for virtio-{mem,pmem}.
Now add it into virt-install.

Example:
virt-install \
--name test \
--os-variant opensusetumbleweed \
--cdrom /isos/openSUSE-Tumbleweed-DVD-x86_64-Current.iso \
--disk /vms/tw/disk0.qcow2 \
--vcpu 2 \
--cpu cell0.cpus=0,cell0.memory=4194304,\
cell1.cpus=1,cell1.memory=4194304 \
--memory maxMemory=65536,maxMemory.slots=8 \
--memdev model=virtio-mem,\
target.node=0,\
target.block=2048,\
target.size=8192,\
target.requested=2097152,\
target.address_base=0x280000000 \
--memdev model=virtio-pmem,\
source.path=/tmp/virtio_pmem,\
target.size=4096,\
target.address_base=0x480000000

It results in the following domain XML snippet:
    <memory model='virtio-mem'>
      <target>
        <size unit='KiB'>8388608</size>
        <node>0</node>
        <block unit='KiB'>2048</block>
        <requested unit='KiB'>2097152</requested>
        <current unit='KiB'>0</current>
        <address base='0x280000000'/>
      </target>
      <alias name='virtiomem0'/>
      <address type='pci' domain='0x0000' bus='0x07' slot='0x00' function='0x0'/>
    </memory>
    <memory model='virtio-pmem' access='shared'>
      <source>
        <path>/tmp/virtio_pmem</path>
      </source>
      <target>
        <size unit='KiB'>2097152</size>
        <address base='0x480000000'/>
      </target>
      <alias name='virtiopmem0'/>
      <address type='pci' domain='0x0000' bus='0x08' slot='0x00' function='0x0'/>
    </memory>

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Lin Ma <lma@suse.de>
2024-09-08 11:25:32 -04:00

53 lines
1.5 KiB
Python

#
# Copyright 2017 Red Hat, Inc.
#
# This work is licensed under the GNU GPLv2 or later.
# See the COPYING file in the top-level directory.
from .device import Device
from ..xmlbuilder import XMLBuilder, XMLChildProperty, XMLProperty
class _DeviceMemoryTarget(XMLBuilder):
XML_NAME = "target"
size = XMLProperty("./size", is_int=True)
node = XMLProperty("./node", is_int=True)
label_size = XMLProperty("./label/size", is_int=True)
readonly = XMLProperty("./readonly", is_bool=True)
block = XMLProperty("./block", is_int=True)
requested = XMLProperty("./requested", is_int=True)
current = XMLProperty("./current", is_int=True)
address_base = XMLProperty("./address/@base")
class _DeviceMemorySource(XMLBuilder):
XML_NAME = "source"
pagesize = XMLProperty("./pagesize", is_int=True)
nodemask = XMLProperty("./nodemask")
path = XMLProperty("./path")
alignsize = XMLProperty("./alignsize", is_int=True)
pmem = XMLProperty("./pmem", is_bool=True)
class DeviceMemory(Device):
XML_NAME = "memory"
MODEL_DIMM = "dimm"
MODEL_NVDIMM = "nvdimm"
models = [MODEL_DIMM, MODEL_NVDIMM]
ACCESS_SHARED = "shared"
ACCESS_PRIVATE = "private"
accesses = [ACCESS_SHARED, ACCESS_PRIVATE]
model = XMLProperty("./@model")
access = XMLProperty("./@access")
discard = XMLProperty("./@discard", is_yesno=True)
uuid = XMLProperty("./uuid")
source = XMLChildProperty(_DeviceMemorySource, is_single=True)
target = XMLChildProperty(_DeviceMemoryTarget, is_single=True)