[PATCH 13/16] LXC from native: add lxc.cgroup.blkio.* mapping

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

 



---
 src/lxc/lxc_native.c                               | 44 ++++++++++++++++++++++
 tests/lxcconf2xmldata/lxcconf2xml-blkiotune.config |  9 +++++
 tests/lxcconf2xmldata/lxcconf2xml-blkiotune.xml    | 44 ++++++++++++++++++++++
 tests/lxcconf2xmltest.c                            |  1 +
 4 files changed, 98 insertions(+)
 create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-blkiotune.config
 create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-blkiotune.xml

diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index 635eb89..75e05a5 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -835,6 +835,46 @@ lxcSetCpusetTune(virDomainDefPtr def, virPropertiesPtr properties)
     return 0;
 }
 
+static int
+lxcSetBlkioTune(virDomainDefPtr def, virPropertiesPtr properties)
+{
+    char *value;
+    char **parts;
+    virBlkioDevicePtr device = NULL;
+
+    if ((value = virPropertiesLookup(properties, "lxc.cgroup.blkio.weight")) &&
+            virStrToLong_ui(value, NULL, 10, &def->blkio.weight) < 0)
+        return -1;
+
+    value = virPropertiesLookup(properties, "lxc.cgroup.blkio.device_weight");
+    while (value) {
+        if (!(parts = lxcStringSplit(value)))
+            return -1;
+
+        if (!parts[0] || !parts[1])
+            goto error;
+
+        if (VIR_EXPAND_N(def->blkio.devices, def->blkio.ndevices, 1) < 0)
+            goto error;
+        device = &def->blkio.devices[def->blkio.ndevices - 1];
+
+        if (virAsprintf(&device->path, "/dev/block/%s", parts[0]) < 0)
+            goto error;
+
+        if (virStrToLong_ui(parts[1], NULL, 10, &device->weight) < 0)
+            goto error;
+
+        virStringFreeList(parts);
+        value = virPropertiesLookup(properties, NULL);
+    }
+
+    return 0;
+
+error:
+    virStringFreeList(parts);
+    return -1;
+}
+
 virDomainDefPtr
 lxcParseConfigString(const char *config,
                      const char *fstab,
@@ -941,6 +981,10 @@ lxcParseConfigString(const char *config,
     if (lxcSetCpusetTune(vmdef, properties) < 0)
         goto error;
 
+    /* lxc.cgroup.blkio.* */
+    if (lxcSetBlkioTune(vmdef, properties) < 0)
+        goto error;
+
     goto cleanup;
 
 error:
diff --git a/tests/lxcconf2xmldata/lxcconf2xml-blkiotune.config b/tests/lxcconf2xmldata/lxcconf2xml-blkiotune.config
new file mode 100644
index 0000000..704c737
--- /dev/null
+++ b/tests/lxcconf2xmldata/lxcconf2xml-blkiotune.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.blkio.weight = 500
+lxc.cgroup.blkio.device_weight = 8:16	1000
+lxc.cgroup.blkio.device_weight = 8:0    300
diff --git a/tests/lxcconf2xmldata/lxcconf2xml-blkiotune.xml b/tests/lxcconf2xmldata/lxcconf2xml-blkiotune.xml
new file mode 100644
index 0000000..51d2881
--- /dev/null
+++ b/tests/lxcconf2xmldata/lxcconf2xml-blkiotune.xml
@@ -0,0 +1,44 @@
+<domain type='lxc'>
+  <name>migrate_test</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>4035770</memory>
+  <currentMemory unit='KiB'>0</currentMemory>
+  <blkiotune>
+    <weight>500</weight>
+    <device>
+      <path>/dev/block/8:16</path>
+      <weight>1000</weight>
+    </device>
+    <device>
+      <path>/dev/block/8:0</path>
+      <weight>300</weight>
+    </device>
+  </blkiotune>
+  <vcpu placement='static' current='0'>1</vcpu>
+  <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 da94db4..60fdb01 100644
--- a/tests/lxcconf2xmltest.c
+++ b/tests/lxcconf2xmltest.c
@@ -114,6 +114,7 @@ mymain(void)
     DO_TEST("memtune");
     DO_TEST("cputune");
     DO_TEST("cpusettune");
+    DO_TEST("blkiotune");
 
     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]