return 0;
}
+static int
+lxcSetMemTune(virDomainDefPtr def, virConfPtr properties)
+{
+ virConfValuePtr value;
+ unsigned long long size = 0;
+
+ if ((value = virConfGetValue(properties,
+ "lxc.cgroup.memory.limit_in_bytes")) &&
+ value->str && STRNEQ(value->str, "-1")) {
+ if (lxcConvertSize(value->str, &size) < 0)
+ return -1;
+ size = size / 1024;
+ def->mem.max_balloon = size;
+ def->mem.hard_limit = size;
+ }
+
+ if ((value = virConfGetValue(properties,
+ "lxc.cgroup.memory.soft_limit_in_bytes")) &&
+ value->str && STRNEQ(value->str, "-1")) {
+ if (lxcConvertSize(value->str, &size) < 0)
+ return -1;
+
+ def->mem.soft_limit = size / 1024;
+ }
+
+ if ((value = virConfGetValue(properties,
+ "lxc.cgroup.memory.memsw.limit_in_bytes")) &&
+ value->str && STRNEQ(value->str, "-1")) {
+ if (lxcConvertSize(value->str, &size) < 0)
+ return -1;
+
+ def->mem.swap_hard_limit = size / 1024;
+ }
+ return 0;
+}
+
virDomainDefPtr
lxcParseConfigString(const char *config)
{
if (virConfWalk(properties, lxcIdmapWalkCallback, vmdef) < 0)
goto error;
+ /* lxc.cgroup.memory.* */
+ if (lxcSetMemTune(vmdef, properties) < 0)
+ goto error;
+
goto cleanup;
error:
--- /dev/null
+lxc.rootfs = /var/lib/lxc/migrate_test/rootfs
+lxc.utsname = migrate_test
+lxc.autodev=1
+
+# 1GiB
+lxc.cgroup.memory.limit_in_bytes = 1073741824
+# 128MiB
+lxc.cgroup.memory.soft_limit_in_bytes = 134217728
+# 2GiB
+lxc.cgroup.memory.memsw.limit_in_bytes = 2147483648
--- /dev/null
+<domain type='lxc'>
+ <name>migrate_test</name>
+ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+ <memory unit='KiB'>1048576</memory>
+ <currentMemory unit='KiB'>0</currentMemory>
+ <memtune>
+ <hard_limit unit='KiB'>1048576</hard_limit>
+ <soft_limit unit='KiB'>131072</soft_limit>
+ <swap_hard_limit unit='KiB'>2097152</swap_hard_limit>
+ </memtune>
+ <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>
+ </devices>
+</domain>