From ad729e721aca43c17ab297e022edd9c7250d43ee Mon Sep 17 00:00:00 2001 Message-Id: From: Pavel Hrdina Date: Tue, 25 Nov 2014 10:52:59 +0100 Subject: [PATCH] video: cleanup usage of vram attribute and update documentation The vram attribute was introduced to set the video memory but it is usable only for few hypervisors excluding QEMU/KVM and the old XEN driver. Only in case of QEMU the vram was used for QXL. This patch updates the documentation to reflect current code in libvirt and also changes the cases when we will set the default vram attribute. It also fixes existing strange default value for VGA devices 9MB to 16MB because the video ram should be rounded to power of two. The change of default value could affect migrations but I found out that QEMU always round the video ram to power of two internally so it's safe to change the default value to the next closest power of two and also silently correct every domain XML definition. And it's also safe because we don't pass the value to QEMU. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1076098 Signed-off-by: Pavel Hrdina (cherry picked from commit 81ba2298b27aa3257e7b5136f5dd5055076d7d9c) Conflicts: src/xen/xen_driver.c - missing context 9320c3ff Signed-off-by: Pavel Hrdina Signed-off-by: Jiri Denemark --- docs/formatdomain.html.in | 66 ++++++++++++++-------- src/conf/domain_conf.c | 15 +++-- src/conf/domain_conf.h | 3 +- src/qemu/qemu_command.c | 16 ++++-- ...qemuhotplug-console-compat-2+console-virtio.xml | 2 +- .../qemuxml2argv-console-compat-2.xml | 2 +- .../qemuxml2argv-controller-order.xml | 2 +- .../qemuxml2argv-graphics-listen-network.xml | 2 +- .../qemuxml2argv-graphics-listen-network2.xml | 2 +- .../qemuxml2argv-graphics-sdl-fullscreen.xml | 2 +- .../qemuxml2argvdata/qemuxml2argv-graphics-sdl.xml | 2 +- .../qemuxml2argv-graphics-spice-agentmouse.xml | 2 +- .../qemuxml2argv-graphics-spice-compression.args | 2 +- .../qemuxml2argv-graphics-spice-compression.xml | 2 +- .../qemuxml2argv-graphics-spice-sasl.args | 2 +- .../qemuxml2argv-graphics-spice-sasl.xml | 2 +- .../qemuxml2argv-graphics-spice-timeout.xml | 2 +- .../qemuxml2argv-graphics-spice.args | 2 +- .../qemuxml2argv-graphics-spice.xml | 2 +- .../qemuxml2argv-graphics-vnc-policy.xml | 2 +- .../qemuxml2argv-graphics-vnc-sasl.xml | 2 +- .../qemuxml2argv-graphics-vnc-socket.xml | 2 +- .../qemuxml2argv-graphics-vnc-tls.xml | 2 +- .../qemuxml2argv-graphics-vnc-websocket.xml | 2 +- .../qemuxml2argvdata/qemuxml2argv-graphics-vnc.xml | 2 +- .../qemuxml2argv-net-bandwidth.xml | 2 +- .../qemuxml2argv-pci-autoadd-addr.xml | 2 +- .../qemuxml2argv-pci-autoadd-idx.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-pci-bridge.xml | 2 +- .../qemuxml2argv-pcihole64-q35.args | 2 +- .../qemuxml2argv-pcihole64-q35.xml | 2 +- .../qemuxml2argvdata/qemuxml2argv-pseries-disk.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-q35.args | 2 +- tests/qemuxml2argvdata/qemuxml2argv-q35.xml | 2 +- .../qemuxml2argv-serial-spiceport.args | 2 +- .../qemuxml2argv-serial-spiceport.xml | 2 +- .../qemuxml2xmlout-graphics-listen-network2.xml | 2 +- .../qemuxml2xmlout-graphics-spice-timeout.xml | 2 +- .../qemuxml2xmlout-pci-autoadd-addr.xml | 2 +- .../qemuxml2xmlout-pci-autoadd-idx.xml | 2 +- tests/qemuxml2xmloutdata/qemuxml2xmlout-q35.xml | 2 +- tests/virt-aa-helper-test | 2 +- 42 files changed, 102 insertions(+), 74 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index f8d5b31..4755e01 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -4636,7 +4636,7 @@ qemu-kvm -net nic,model=? /dev/null ... <devices> <video> - <model type='vga' vram='8192' heads='1'> + <model type='vga' vram='16384' heads='1'> <acceleration accel3d='yes' accel2d='yes'/> </model> </video> @@ -4646,33 +4646,51 @@ qemu-kvm -net nic,model=? /dev/null
video
- The video element is the container for describing - video devices. For backwards compatibility, if no video - is set but there is a graphics in domain xml, then libvirt - will add a default video according to the guest type. - For a guest of type "kvm", the default video for it is: - type with value "cirrus", vram with value - "9216", and heads with value "1". By default, the first - video device in domain xml is the primary one, but the optional - attribute primary (since 1.0.2) - with value 'yes' can be used to mark the primary in cases of multiple - video device. The non-primary must be type of "qxl". The optional - attribute ram (since - 1.0.2) is allowed for "qxl" type only and specifies - the size of the primary bar, while vram specifies the - secondary bar size. If "ram" or "vram" are not supplied a default - value is used. +

+ The video element is the container for describing + video devices. For backwards compatibility, if no video + is set but there is a graphics in domain xml, then + libvirt will add a default video according to the guest + type. +

+

+ For a guest of type "kvm", the default video is: + type with value "cirrus", vram with value + "16384" and heads with value "1". By default, the first + video device in domain xml is the primary one, but the optional + attribute primary (since 1.0.2) + with value 'yes' can be used to mark the primary in cases of multiple + video device. The non-primary must be type of "qxl". +

model
- The model element has a mandatory type - attribute which takes the value "vga", "cirrus", "vmvga", "xen", - "vbox", or "qxl" (since 0.8.6) - depending on the hypervisor features available. - You can also provide the amount of video memory in kibibytes - (blocks of 1024 bytes) using - vram and the number of screen with heads. +

+ The model element has a mandatory type + attribute which takes the value "vga", "cirrus", "vmvga", "xen", + "vbox", or "qxl" (since 0.8.6) depending + on the hypervisor features available. +

+

+ You can provide the amount of video memory in kibibytes (blocks of + 1024 bytes) using vram. This is supported only for guest + type of "libxl", "parallels", "qemu", "vbox", "vmx" and "xen". If no + value is provided the default is used. If the size is not a power of + two it will be rounded to closest one. +

+

+ The number of screen can be set using heads. This is + supported only for guests type of "parallels", "kvm", "vbox" and "vmx". +

+

+ For guest type of kvm the optional attribute ram + (since 1.0.2) is allowed for "qxl" type + only and specifies the size of the primary bar, while the optional + attribute vram specifies the secondary bar size. + If "ram" or "vram" are not supplied a default value is used. The ram + should also be rounded to power of two as vram. +

acceleration
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ef6e9cf..0b0200b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -3186,6 +3186,12 @@ virDomainDeviceDefPostParseInternal(virDomainDeviceDefPtr dev, } } + if (dev->type == VIR_DOMAIN_DEVICE_VIDEO) { + virDomainVideoDefPtr video = dev->data.video; + video->ram = VIR_ROUND_UP_POWER_OF_TWO(video->ram); + video->vram = VIR_ROUND_UP_POWER_OF_TWO(video->vram); + } + return 0; } @@ -9993,12 +9999,11 @@ virSysinfoParseXML(xmlNodePtr node, goto cleanup; } -int +unsigned int virDomainVideoDefaultRAM(const virDomainDef *def, - int type) + const virDomainVideoType type) { switch (type) { - /* Weird, QEMU defaults to 9 MB ??! */ case VIR_DOMAIN_VIDEO_TYPE_VGA: case VIR_DOMAIN_VIDEO_TYPE_CIRRUS: case VIR_DOMAIN_VIDEO_TYPE_VMVGA: @@ -10007,7 +10012,7 @@ virDomainVideoDefaultRAM(const virDomainDef *def, else if (def->virtType == VIR_DOMAIN_VIRT_VMWARE) return 4 * 1024; else - return 9 * 1024; + return 16 * 1024; break; case VIR_DOMAIN_VIDEO_TYPE_XEN: @@ -10168,7 +10173,7 @@ virDomainVideoDefParseXML(xmlNodePtr node, if (vram) { if (virStrToLong_ui(vram, NULL, 10, &def->vram) < 0) { virReportError(VIR_ERR_XML_ERROR, - _("cannot parse video ram '%s'"), vram); + _("cannot parse video vram '%s'"), vram); goto error; } } else { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index f9cccb4..ae46467 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2587,7 +2587,8 @@ int virDomainFSIndexByName(virDomainDefPtr def, const char *name); virDomainFSDefPtr virDomainFSRemove(virDomainDefPtr def, size_t i); int virDomainVideoDefaultType(const virDomainDef *def); -int virDomainVideoDefaultRAM(const virDomainDef *def, int type); +unsigned int virDomainVideoDefaultRAM(const virDomainDef *def, + const virDomainVideoType type); int virDomainObjListNumOfDomains(virDomainObjListPtr doms, bool active, diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 09a22dc..8d73f89 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4844,11 +4844,15 @@ qemuBuildDeviceVideoStr(virDomainDefPtr def, goto error; } - /* QEMU accepts bytes for ram_size. */ - virBufferAsprintf(&buf, ",ram_size=%u", video->ram * 1024); + if (video->ram) { + /* QEMU accepts bytes for ram_size. */ + virBufferAsprintf(&buf, ",ram_size=%u", video->ram * 1024); + } - /* QEMU accepts bytes for vram_size. */ - virBufferAsprintf(&buf, ",vram_size=%u", video->vram * 1024); + if (video->vram) { + /* QEMU accepts bytes for vram_size. */ + virBufferAsprintf(&buf, ",vram_size=%u", video->vram * 1024); + } } if (qemuBuildDeviceAddressStr(&buf, def, &video->info, qemuCaps) < 0) @@ -9108,8 +9112,8 @@ qemuBuildCommandLine(virConnectPtr conn, virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) { const char *dev = (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_QXL_VGA) ? "qxl-vga" : "qxl"); - int ram = def->videos[0]->ram; - int vram = def->videos[0]->vram; + unsigned int ram = def->videos[0]->ram; + unsigned int vram = def->videos[0]->vram; if (vram > (UINT_MAX / 1024)) { virReportError(VIR_ERR_OVERFLOW, diff --git a/tests/qemuhotplugtestdata/qemuhotplug-console-compat-2+console-virtio.xml b/tests/qemuhotplugtestdata/qemuhotplug-console-compat-2+console-virtio.xml index ec1c6e8..d848677 100644 --- a/tests/qemuhotplugtestdata/qemuhotplug-console-compat-2+console-virtio.xml +++ b/tests/qemuhotplugtestdata/qemuhotplug-console-compat-2+console-virtio.xml @@ -91,7 +91,7 @@