LXC from native: map lxc.cgroup.cpu.*

This commit is contained in:
Cédric Bosdonnat 2014-02-05 15:10:10 +01:00 committed by Daniel P. Berrange
parent 13b9946eb5
commit 4f3f7aea6c
4 changed files with 71 additions and 0 deletions

View File

@ -643,6 +643,36 @@ lxcSetMemTune(virDomainDefPtr def, virConfPtr properties)
return 0; 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 virDomainDefPtr
lxcParseConfigString(const char *config) lxcParseConfigString(const char *config)
{ {
@ -719,6 +749,10 @@ lxcParseConfigString(const char *config)
if (lxcSetMemTune(vmdef, properties) < 0) if (lxcSetMemTune(vmdef, properties) < 0)
goto error; goto error;
/* lxc.cgroup.cpu.* */
if (lxcSetCpuTune(vmdef, properties) < 0)
goto error;
goto cleanup; goto cleanup;
error: error:

View File

@ -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

View File

@ -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>

View File

@ -110,6 +110,7 @@ mymain(void)
DO_TEST("macvlannetwork", false); DO_TEST("macvlannetwork", false);
DO_TEST("idmap", false); DO_TEST("idmap", false);
DO_TEST("memtune", false); DO_TEST("memtune", false);
DO_TEST("cputune", false);
return ret; return ret;
} }