--- src/lxc/lxc_native.c | 34 ++++++++++++++++++++++++ tests/lxcconf2xmldata/lxcconf2xml-cputune.config | 7 +++++ tests/lxcconf2xmldata/lxcconf2xml-cputune.xml | 29 ++++++++++++++++++++ tests/lxcconf2xmltest.c | 1 + 4 files changed, 71 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 d430abc..65a1d0d 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -643,6 +643,36 @@ lxcSetMemTune(virDomainDefPtr def, virConfPtr properties) return 0; } +static int +lxcSetCpuTune(virDomainDefPtr def, virConfPtr properties) +{ + virConfValuePtr value; + + if ((value = virConfGetValue(properties, "lxc.cgroup.cpu.shares")) && + value->str && virStrToLong_ul(value->str, NULL, 10, + &def->cputune.shares) < 0) + goto error; + + if ((value = virConfGetValue(properties, + "lxc.cgroup.cpu.cfs_quota_us")) && + value->str && virStrToLong_ll(value->str, NULL, 10, + &def->cputune.quota) < 0) + goto error; + + if ((value = virConfGetValue(properties, + "lxc.cgroup.cpu.cfs_period_us")) && + value->str && virStrToLong_ull(value->str, NULL, 10, + &def->cputune.period) < 0) + goto error; + + return 0; + +error: + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to parse integer: '%s'"), value->str); + return -1; +} + virDomainDefPtr lxcParseConfigString(const char *config) { @@ -719,6 +749,10 @@ lxcParseConfigString(const char *config) if (lxcSetMemTune(vmdef, properties) < 0) goto error; + /* 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..9797dec --- /dev/null +++ b/tests/lxcconf2xmldata/lxcconf2xml-cputune.config @@ -0,0 +1,7 @@ +lxc.rootfs = /var/lib/lxc/migrate_test/rootfs +lxc.utsname = migrate_test +lxc.autodev=1 + +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..a511dcf --- /dev/null +++ b/tests/lxcconf2xmldata/lxcconf2xml-cputune.xml @@ -0,0 +1,29 @@ +<domain type='lxc'> + <name>migrate_test</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>65536</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> + </devices> +</domain> diff --git a/tests/lxcconf2xmltest.c b/tests/lxcconf2xmltest.c index 3dd0a0b..1148cd3 100644 --- a/tests/lxcconf2xmltest.c +++ b/tests/lxcconf2xmltest.c @@ -110,6 +110,7 @@ mymain(void) DO_TEST("macvlannetwork", false); DO_TEST("idmap", false); DO_TEST("memtune", false); + DO_TEST("cputune", false); return ret; } -- 1.8.5.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list