From 4f3f7aea6c3df907c562ac2e7829b015693164a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= Date: Wed, 5 Feb 2014 15:10:10 +0100 Subject: [PATCH] LXC from native: map lxc.cgroup.cpu.* --- src/lxc/lxc_native.c | 34 +++++++++++++++++++ .../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 ecc63ded2d..c5245c0191 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 0000000000..9797dec6ef --- /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 0000000000..a511dcfee4 --- /dev/null +++ b/tests/lxcconf2xmldata/lxcconf2xml-cputune.xml @@ -0,0 +1,29 @@ + + migrate_test + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 65536 + 0 + 1 + + 1024 + 500000 + -1 + + + exe + /sbin/init + + + + + + destroy + restart + destroy + + + + + + + diff --git a/tests/lxcconf2xmltest.c b/tests/lxcconf2xmltest.c index 3dd0a0bcf9..1148cd30c5 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; }