From 981c01d419782af2e38f71f42a21091aeb0754b7 Mon Sep 17 00:00:00 2001 From: Dmitry Andreev Date: Fri, 8 Jan 2016 13:45:07 +0300 Subject: [PATCH] qemu: add support of optional 'autodeflate' attribute Autodeflate can be enabled/disabled for memballon device of model 'virtio'. xml: qemu: qemu -device virtio-balloon-pci,...,deflate-on-oom=on Autodeflate cannot be enabled/disabled for running domain. --- src/qemu/qemu_command.c | 11 +++++++ .../qemuxml2argv-balloon-ccw-deflate.args | 20 +++++++++++++ .../qemuxml2argv-balloon-ccw-deflate.xml | 21 +++++++++++++ ...muxml2argv-balloon-device-deflate-off.args | 23 ++++++++++++++ ...emuxml2argv-balloon-device-deflate-off.xml | 25 ++++++++++++++++ .../qemuxml2argv-balloon-device-deflate.args | 23 ++++++++++++++ .../qemuxml2argv-balloon-device-deflate.xml | 25 ++++++++++++++++ .../qemuxml2argv-balloon-mmio-deflate.args | 25 ++++++++++++++++ .../qemuxml2argv-balloon-mmio-deflate.xml | 30 +++++++++++++++++++ tests/qemuxml2argvtest.c | 9 ++++++ 10 files changed, 212 insertions(+) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-balloon-ccw-deflate.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-balloon-ccw-deflate.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate-off.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate-off.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-balloon-mmio-deflate.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-balloon-mmio-deflate.xml diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 3c9caea49d..5d3ab3a4ea 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5758,6 +5758,17 @@ qemuBuildMemballoonDevStr(virDomainDefPtr def, if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0) goto error; + if (dev->autodeflate != VIR_TRISTATE_SWITCH_ABSENT) { + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_BALLOON_AUTODEFLATE)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("deflate-on-oom is not supported by this QEMU binary")); + goto error; + } + + virBufferAsprintf(&buf, ",deflate-on-oom=%s", + virTristateSwitchTypeToString(dev->autodeflate)); + } + if (virBufferCheckError(&buf) < 0) goto error; diff --git a/tests/qemuxml2argvdata/qemuxml2argv-balloon-ccw-deflate.args b/tests/qemuxml2argvdata/qemuxml2argv-balloon-ccw-deflate.args new file mode 100644 index 0000000000..8dfced6b69 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-balloon-ccw-deflate.args @@ -0,0 +1,20 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/home/test \ +USER=test \ +LOGNAME=test \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu \ +-name QEMUGuest1 \ +-S \ +-M s390-ccw \ +-m 214 \ +-smp 1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-nographic \ +-nodefconfig \ +-nodefaults \ +-monitor unix:/tmp/test-monitor,server,nowait \ +-no-acpi \ +-boot c \ +-device virtio-balloon-ccw,id=balloon0,devno=fe.0.000a,deflate-on-oom=on diff --git a/tests/qemuxml2argvdata/qemuxml2argv-balloon-ccw-deflate.xml b/tests/qemuxml2argvdata/qemuxml2argv-balloon-ccw-deflate.xml new file mode 100644 index 0000000000..248b609c5d --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-balloon-ccw-deflate.xml @@ -0,0 +1,21 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + +
+ + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate-off.args b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate-off.args new file mode 100644 index 0000000000..86f6336393 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate-off.args @@ -0,0 +1,23 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/home/test \ +USER=test \ +LOGNAME=test \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu \ +-name QEMUGuest1 \ +-S \ +-M pc \ +-m 214 \ +-smp 1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-nographic \ +-nodefconfig \ +-nodefaults \ +-monitor unix:/tmp/test-monitor,server,nowait \ +-no-acpi \ +-boot c \ +-usb \ +-drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \ +-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x12,deflate-on-oom=off diff --git a/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate-off.xml b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate-off.xml new file mode 100644 index 0000000000..bc7c6f3675 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate-off.xml @@ -0,0 +1,25 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + + +
+ + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate.args b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate.args new file mode 100644 index 0000000000..9a0332f734 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate.args @@ -0,0 +1,23 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/home/test \ +USER=test \ +LOGNAME=test \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu \ +-name QEMUGuest1 \ +-S \ +-M pc \ +-m 214 \ +-smp 1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-nographic \ +-nodefconfig \ +-nodefaults \ +-monitor unix:/tmp/test-monitor,server,nowait \ +-no-acpi \ +-boot c \ +-usb \ +-drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \ +-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x12,deflate-on-oom=on diff --git a/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate.xml b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate.xml new file mode 100644 index 0000000000..3c25ad58bc --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate.xml @@ -0,0 +1,25 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + + +
+ + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-balloon-mmio-deflate.args b/tests/qemuxml2argvdata/qemuxml2argv-balloon-mmio-deflate.args new file mode 100644 index 0000000000..bb70bf8506 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-balloon-mmio-deflate.args @@ -0,0 +1,25 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/home/test \ +USER=test \ +LOGNAME=test \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu-system-aarch64 \ +-name aarch64test \ +-S \ +-M virt \ +-cpu cortex-a53 \ +-m 1024 \ +-smp 1 \ +-uuid 496d7ea8-9739-544b-4ebd-ef08be936e8b \ +-nographic \ +-nodefconfig \ +-nodefaults \ +-monitor unix:/tmp/test-monitor,server,nowait \ +-boot c \ +-kernel /aarch64.kernel \ +-initrd /aarch64.initrd \ +-append 'earlyprintk console=ttyAMA0,115200n8 rw root=/dev/vda rootwait' \ +-dtb /aarch64.dtb \ +-usb \ +-device virtio-balloon-device,id=balloon0,deflate-on-oom=on diff --git a/tests/qemuxml2argvdata/qemuxml2argv-balloon-mmio-deflate.xml b/tests/qemuxml2argvdata/qemuxml2argv-balloon-mmio-deflate.xml new file mode 100644 index 0000000000..1b5b48c429 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-balloon-mmio-deflate.xml @@ -0,0 +1,30 @@ + + aarch64test + 496d7ea8-9739-544b-4ebd-ef08be936e8b + 1048576 + 1048576 + 1 + + hvm + /aarch64.kernel + /aarch64.initrd + /aarch64.dtb + earlyprintk console=ttyAMA0,115200n8 rw root=/dev/vda rootwait + + + + + + + + cortex-a53 + + + destroy + restart + restart + + /usr/bin/qemu-system-aarch64 + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 20998324a6..7cd8c8e18f 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1210,6 +1210,15 @@ mymain(void) QEMU_CAPS_DEVICE, QEMU_CAPS_CHARDEV, QEMU_CAPS_NODEFCONFIG, QEMU_CAPS_BOOTINDEX, QEMU_CAPS_VIRTIO_S390); DO_TEST("balloon-device", QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG); + DO_TEST("balloon-device-deflate", QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG, + QEMU_CAPS_VIRTIO_BALLOON_AUTODEFLATE); + DO_TEST("balloon-ccw-deflate", QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG, + QEMU_CAPS_VIRTIO_BALLOON_AUTODEFLATE); + DO_TEST("balloon-mmio-deflate", QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG, + QEMU_CAPS_DTB, QEMU_CAPS_DEVICE_VIRTIO_MMIO, + QEMU_CAPS_VIRTIO_BALLOON_AUTODEFLATE); + DO_TEST("balloon-device-deflate-off", QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG, + QEMU_CAPS_VIRTIO_BALLOON_AUTODEFLATE); DO_TEST("balloon-device-auto", QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG); DO_TEST("balloon-device-period", QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG);