c401cc
From fb2a8ad55d2d01c3450ae43640fd3baa41667871 Mon Sep 17 00:00:00 2001
c401cc
Message-Id: <fb2a8ad55d2d01c3450ae43640fd3baa41667871.1386932211.git.jdenemar@redhat.com>
c401cc
From: Martin Kletzander <mkletzan@redhat.com>
c401cc
Date: Tue, 10 Dec 2013 10:03:58 +0100
c401cc
Subject: [PATCH] conf: don't format memtune with unlimited values
c401cc
c401cc
https://bugzilla.redhat.com/show_bug.cgi?id=1024272
c401cc
c401cc
When changing memtune limits to unlimited with AFFECT_CONFIG, the
c401cc
values in virDomainDef are set to PARAM_UNLIMITED, which causes the
c401cc
whole <memtune> to be formatted.  This can be changed in all drivers,
c401cc
but it also makes sense to use the default (0) as another value for
c401cc
"unlimited", since zero memory limit makes no sense.
c401cc
c401cc
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
c401cc
(cherry picked from commit ea130e3bf666397a05a674ffcf15b9ab170b2255)
c401cc
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c401cc
---
c401cc
 src/conf/domain_conf.c                             | 44 ++++++++++++----------
c401cc
 .../qemuxml2argv-memtune-unlimited.args            |  6 +++
c401cc
 .../qemuxml2argv-memtune-unlimited.xml             | 29 ++++++++++++++
c401cc
 tests/qemuxml2argvtest.c                           |  1 +
c401cc
 .../qemuxml2xmlout-memtune-unlimited.xml           | 27 +++++++++++++
c401cc
 tests/qemuxml2xmltest.c                            |  1 +
c401cc
 6 files changed, 88 insertions(+), 20 deletions(-)
c401cc
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-memtune-unlimited.args
c401cc
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-memtune-unlimited.xml
c401cc
 create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-memtune-unlimited.xml
c401cc
c401cc
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
c401cc
index 6048640..f7c0274 100644
c401cc
--- a/src/conf/domain_conf.c
c401cc
+++ b/src/conf/domain_conf.c
c401cc
@@ -16439,28 +16439,32 @@ virDomainDefFormatInternal(virDomainDefPtr def,
c401cc
     }
c401cc
 
c401cc
     /* add memtune only if there are any */
c401cc
-    if (def->mem.hard_limit || def->mem.soft_limit || def->mem.min_guarantee ||
c401cc
-        def->mem.swap_hard_limit)
c401cc
+    if ((def->mem.hard_limit &&
c401cc
+         def->mem.hard_limit != VIR_DOMAIN_MEMORY_PARAM_UNLIMITED) ||
c401cc
+        (def->mem.soft_limit &&
c401cc
+         def->mem.hard_limit != VIR_DOMAIN_MEMORY_PARAM_UNLIMITED) ||
c401cc
+        (def->mem.swap_hard_limit &&
c401cc
+         def->mem.hard_limit != VIR_DOMAIN_MEMORY_PARAM_UNLIMITED) ||
c401cc
+        def->mem.min_guarantee) {
c401cc
         virBufferAddLit(buf, "  <memtune>\n");
c401cc
-    if (def->mem.hard_limit) {
c401cc
-        virBufferAsprintf(buf, "    <hard_limit unit='KiB'>"
c401cc
-                          "%llu</hard_limit>\n", def->mem.hard_limit);
c401cc
-    }
c401cc
-    if (def->mem.soft_limit) {
c401cc
-        virBufferAsprintf(buf, "    <soft_limit unit='KiB'>"
c401cc
-                          "%llu</soft_limit>\n", def->mem.soft_limit);
c401cc
-    }
c401cc
-    if (def->mem.min_guarantee) {
c401cc
-        virBufferAsprintf(buf, "    <min_guarantee unit='KiB'>"
c401cc
-                          "%llu</min_guarantee>\n", def->mem.min_guarantee);
c401cc
-    }
c401cc
-    if (def->mem.swap_hard_limit) {
c401cc
-        virBufferAsprintf(buf, "    <swap_hard_limit unit='KiB'>"
c401cc
-                          "%llu</swap_hard_limit>\n", def->mem.swap_hard_limit);
c401cc
-    }
c401cc
-    if (def->mem.hard_limit || def->mem.soft_limit || def->mem.min_guarantee ||
c401cc
-        def->mem.swap_hard_limit)
c401cc
+        if (def->mem.hard_limit) {
c401cc
+            virBufferAsprintf(buf, "    <hard_limit unit='KiB'>"
c401cc
+                              "%llu</hard_limit>\n", def->mem.hard_limit);
c401cc
+        }
c401cc
+        if (def->mem.soft_limit) {
c401cc
+            virBufferAsprintf(buf, "    <soft_limit unit='KiB'>"
c401cc
+                              "%llu</soft_limit>\n", def->mem.soft_limit);
c401cc
+        }
c401cc
+        if (def->mem.min_guarantee) {
c401cc
+            virBufferAsprintf(buf, "    <min_guarantee unit='KiB'>"
c401cc
+                              "%llu</min_guarantee>\n", def->mem.min_guarantee);
c401cc
+        }
c401cc
+        if (def->mem.swap_hard_limit) {
c401cc
+            virBufferAsprintf(buf, "    <swap_hard_limit unit='KiB'>"
c401cc
+                              "%llu</swap_hard_limit>\n", def->mem.swap_hard_limit);
c401cc
+        }
c401cc
         virBufferAddLit(buf, "  </memtune>\n");
c401cc
+    }
c401cc
 
c401cc
     if (def->mem.hugepage_backed || def->mem.nosharepages || def->mem.locked) {
c401cc
         virBufferAddLit(buf, "  <memoryBacking>\n");
c401cc
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-memtune-unlimited.args b/tests/qemuxml2argvdata/qemuxml2argv-memtune-unlimited.args
c401cc
new file mode 100644
c401cc
index 0000000..5bbde17
c401cc
--- /dev/null
c401cc
+++ b/tests/qemuxml2argvdata/qemuxml2argv-memtune-unlimited.args
c401cc
@@ -0,0 +1,6 @@
c401cc
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test \
c401cc
+/usr/bin/qemu \
c401cc
+-name QEMUGuest1 -S -M pc -m 214 -smp 1 -nographic -monitor \
c401cc
+unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb \
c401cc
+-hda /dev/HostVG/QEMUGuest1 -net none -serial \
c401cc
+none -parallel none
c401cc
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-memtune-unlimited.xml b/tests/qemuxml2argvdata/qemuxml2argv-memtune-unlimited.xml
c401cc
new file mode 100644
c401cc
index 0000000..526129b
c401cc
--- /dev/null
c401cc
+++ b/tests/qemuxml2argvdata/qemuxml2argv-memtune-unlimited.xml
c401cc
@@ -0,0 +1,29 @@
c401cc
+<domain type='qemu'>
c401cc
+  <name>QEMUGuest1</name>
c401cc
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
c401cc
+  <memory unit='MiB'>214</memory>
c401cc
+  <currentMemory unit='KiB'>219136</currentMemory>
c401cc
+  <memtune>
c401cc
+    <hard_limit unit='KiB'>9007199254740991</hard_limit>
c401cc
+  </memtune>
c401cc
+  <vcpu placement='static'>1</vcpu>
c401cc
+  <os>
c401cc
+    <type arch='i686' machine='pc'>hvm</type>
c401cc
+    <boot dev='hd'/>
c401cc
+  </os>
c401cc
+  <clock offset='utc'/>
c401cc
+  <on_poweroff>destroy</on_poweroff>
c401cc
+  <on_reboot>restart</on_reboot>
c401cc
+  <on_crash>destroy</on_crash>
c401cc
+  <devices>
c401cc
+    <emulator>/usr/bin/qemu</emulator>
c401cc
+    <disk type='block' device='disk'>
c401cc
+      <source dev='/dev/HostVG/QEMUGuest1'/>
c401cc
+      <target dev='hda' bus='ide'/>
c401cc
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
c401cc
+    </disk>
c401cc
+    <controller type='usb' index='0'/>
c401cc
+    <controller type='ide' index='0'/>
c401cc
+    <memballoon model='virtio'/>
c401cc
+  </devices>
c401cc
+</domain>
c401cc
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
c401cc
index 3042065..1beb49f 100644
c401cc
--- a/tests/qemuxml2argvtest.c
c401cc
+++ b/tests/qemuxml2argvtest.c
c401cc
@@ -916,6 +916,7 @@ mymain(void)
c401cc
                     QEMU_CAPS_KVM, QEMU_CAPS_CPU_HOST);
c401cc
 
c401cc
     DO_TEST("memtune", QEMU_CAPS_NAME);
c401cc
+    DO_TEST("memtune-unlimited", QEMU_CAPS_NAME);
c401cc
     DO_TEST("blkiotune", QEMU_CAPS_NAME);
c401cc
     DO_TEST("blkiotune-device", QEMU_CAPS_NAME);
c401cc
     DO_TEST("cputune", QEMU_CAPS_NAME);
c401cc
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-memtune-unlimited.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-memtune-unlimited.xml
c401cc
new file mode 100644
c401cc
index 0000000..1d29fa7
c401cc
--- /dev/null
c401cc
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-memtune-unlimited.xml
c401cc
@@ -0,0 +1,27 @@
c401cc
+<domain type='qemu'>
c401cc
+  <name>QEMUGuest1</name>
c401cc
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
c401cc
+  <memory unit='KiB'>219136</memory>
c401cc
+  <currentMemory unit='KiB'>219136</currentMemory>
c401cc
+  <vcpu placement='static'>1</vcpu>
c401cc
+  <os>
c401cc
+    <type arch='i686' machine='pc'>hvm</type>
c401cc
+    <boot dev='hd'/>
c401cc
+  </os>
c401cc
+  <clock offset='utc'/>
c401cc
+  <on_poweroff>destroy</on_poweroff>
c401cc
+  <on_reboot>restart</on_reboot>
c401cc
+  <on_crash>destroy</on_crash>
c401cc
+  <devices>
c401cc
+    <emulator>/usr/bin/qemu</emulator>
c401cc
+    <disk type='block' device='disk'>
c401cc
+      <source dev='/dev/HostVG/QEMUGuest1'/>
c401cc
+      <target dev='hda' bus='ide'/>
c401cc
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
c401cc
+    </disk>
c401cc
+    <controller type='usb' index='0'/>
c401cc
+    <controller type='ide' index='0'/>
c401cc
+    <controller type='pci' index='0' model='pci-root'/>
c401cc
+    <memballoon model='virtio'/>
c401cc
+  </devices>
c401cc
+</domain>
c401cc
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
c401cc
index 6b984ad..4b6b01d 100644
c401cc
--- a/tests/qemuxml2xmltest.c
c401cc
+++ b/tests/qemuxml2xmltest.c
c401cc
@@ -244,6 +244,7 @@ mymain(void)
c401cc
 
c401cc
     DO_TEST("encrypted-disk");
c401cc
     DO_TEST_DIFFERENT("memtune");
c401cc
+    DO_TEST_DIFFERENT("memtune-unlimited");
c401cc
     DO_TEST("blkiotune");
c401cc
     DO_TEST("blkiotune-device");
c401cc
     DO_TEST("cputune");
c401cc
-- 
c401cc
1.8.5.1
c401cc