[PATCH 11/16] LXC from native: map lxc.cgroup.cpu.*

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 src/lxc/lxc_native.c                             | 26 ++++++++++++++++
 tests/lxcconf2xmldata/lxcconf2xml-cputune.config |  9 ++++++
 tests/lxcconf2xmldata/lxcconf2xml-cputune.xml    | 38 ++++++++++++++++++++++++
 tests/lxcconf2xmltest.c                          |  1 +
 4 files changed, 74 insertions(+)
 create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-cputune.config
 create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-cputune.xml

diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index 582924e..80b7e74 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -790,6 +790,28 @@ lxcSetMemTune(virDomainDefPtr def, virPropertiesPtr properties)
        def->mem.swap_hard_limit = lxcConvertSize(value, 0) / 1024;
 }
 
+static int
+lxcSetCpuTune(virDomainDefPtr def, virPropertiesPtr properties)
+{
+    char *value;
+
+    if ((value = virPropertiesLookup(properties, "lxc.cgroup.cpu.shares")) &&
+            virStrToLong_ul(value, NULL, 10, &def->cputune.shares) < 0)
+        return -1;
+
+    if ((value = virPropertiesLookup(properties,
+                                      "lxc.cgroup.cpu.cfs_quota_us")) &&
+            virStrToLong_ll(value, NULL, 10, &def->cputune.quota) < 0)
+        return -1;
+
+    if ((value = virPropertiesLookup(properties,
+                                      "lxc.cgroup.cpu.cfs_period_us")) &&
+            virStrToLong_ull(value, NULL, 10, &def->cputune.period) < 0)
+        return -1;
+
+    return 0;
+}
+
 virDomainDefPtr
 lxcParseConfigString(const char *config,
                      const char *fstab,
@@ -888,6 +910,10 @@ lxcParseConfigString(const char *config,
     /* lxc.cgroup.memory.* */
     lxcSetMemTune(vmdef, properties);
 
+    /* lxc.cgroup.cpu.* */
+    if (lxcSetCpuTune(vmdef, properties) < 0)
+        goto error;
+
     goto cleanup;
 
 error:
diff --git a/tests/lxcconf2xmldata/lxcconf2xml-cputune.config b/tests/lxcconf2xmldata/lxcconf2xml-cputune.config
new file mode 100644
index 0000000..3c1448e
--- /dev/null
+++ b/tests/lxcconf2xmldata/lxcconf2xml-cputune.config
@@ -0,0 +1,9 @@
+lxc.mount.entry = /etc/resolv.conf etc/resolv.conf none bind,ro 0 0
+lxc.rootfs = /var/lib/lxc/migrate_test/rootfs
+lxc.utsname = migrate_test
+lxc.autodev=1
+lxc.mount = /var/lib/lxc/migrate_test/fstab
+
+lxc.cgroup.cpu.shares = 1024
+lxc.cgroup.cpu.cfs_quota_us = -1
+lxc.cgroup.cpu.cfs_period_us = 500000
diff --git a/tests/lxcconf2xmldata/lxcconf2xml-cputune.xml b/tests/lxcconf2xmldata/lxcconf2xml-cputune.xml
new file mode 100644
index 0000000..b35b3e3
--- /dev/null
+++ b/tests/lxcconf2xmldata/lxcconf2xml-cputune.xml
@@ -0,0 +1,38 @@
+<domain type='lxc'>
+  <name>migrate_test</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>4035770</memory>
+  <currentMemory unit='KiB'>0</currentMemory>
+  <vcpu placement='static' current='0'>1</vcpu>
+  <cputune>
+    <shares>1024</shares>
+    <period>500000</period>
+    <quota>-1</quota>
+  </cputune>
+  <os>
+    <type>exe</type>
+    <init>/sbin/init</init>
+  </os>
+  <features>
+    <privnet/>
+  </features>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <filesystem type='mount' accessmode='passthrough'>
+      <source dir='/var/lib/lxc/migrate_test/rootfs'/>
+      <target dir='/'/>
+    </filesystem>
+    <filesystem type='mount' accessmode='passthrough'>
+      <source dir='/etc/resolv.conf'/>
+      <target dir='/etc/resolv.conf'/>
+      <readonly/>
+    </filesystem>
+    <filesystem type='ram' accessmode='passthrough'>
+      <source usage='2017885' units='KiB'/>
+      <target dir='/run'/>
+    </filesystem>
+  </devices>
+</domain>
diff --git a/tests/lxcconf2xmltest.c b/tests/lxcconf2xmltest.c
index bf5b06e..096a050 100644
--- a/tests/lxcconf2xmltest.c
+++ b/tests/lxcconf2xmltest.c
@@ -112,6 +112,7 @@ mymain(void)
     DO_TEST("macvlannetwork");
     DO_TEST("idmap");
     DO_TEST("memtune");
+    DO_TEST("cputune");
 
     return ret;
 }
-- 
1.8.5.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]