diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 6c5640536b..8c9d736d5c 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -219,7 +219,7 @@ lxcConvertSize(const char *size, unsigned long long *value) /* Split the string into value and unit */ if (virStrToLong_ull(size, &unit, 10, value) < 0) - goto error; + return -1; if (STREQ(unit, "%")) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -228,16 +228,10 @@ lxcConvertSize(const char *size, unsigned long long *value) return -1; } else { if (virScaleInteger(value, unit, 1, ULLONG_MAX) < 0) - goto error; + return -1; } return 0; - - error: - virReportError(VIR_ERR_INTERNAL_ERROR, - _("failed to convert size: '%s'"), - size); - return -1; } static int @@ -275,8 +269,12 @@ lxcAddFstabLine(virDomainDefPtr def, lxcFstabPtr fstab) for (i = 0; options[i]; i++) { if ((sizeStr = STRSKIP(options[i], "size="))) { - if (lxcConvertSize(sizeStr, &usage) < 0) + if (lxcConvertSize(sizeStr, &usage) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to parse integer: '%s'"), + sizeStr); goto cleanup; + } break; } } @@ -756,106 +754,103 @@ lxcIdmapWalkCallback(const char *name, virConfValuePtr value, void *data) static int lxcSetMemTune(virDomainDefPtr def, virConfPtr properties) { - VIR_AUTOFREE(char *) hard_limit = NULL; - VIR_AUTOFREE(char *) soft_limit = NULL; - VIR_AUTOFREE(char *) swap_hard_limit = NULL; unsigned long long size = 0; + VIR_AUTOFREE(char *) value = NULL; if (virConfGetValueString(properties, "lxc.cgroup.memory.limit_in_bytes", - &hard_limit) > 0) { - if (lxcConvertSize(hard_limit, &size) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("failed to parse integer: '%s'"), - hard_limit); - return -1; - } + &value) > 0) { + if (lxcConvertSize(value, &size) < 0) + goto error; + size = size / 1024; virDomainDefSetMemoryTotal(def, size); def->mem.hard_limit = virMemoryLimitTruncate(size); + VIR_FREE(value); } if (virConfGetValueString(properties, "lxc.cgroup.memory.soft_limit_in_bytes", - &soft_limit) > 0) { - if (lxcConvertSize(soft_limit, &size) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("failed to parse integer: '%s'"), - soft_limit); - return -1; - } + &value) > 0) { + if (lxcConvertSize(value, &size) < 0) + goto error; + def->mem.soft_limit = virMemoryLimitTruncate(size / 1024); + VIR_FREE(value); } if (virConfGetValueString(properties, "lxc.cgroup.memory.memsw.limit_in_bytes", - &swap_hard_limit) > 0) { - if (lxcConvertSize(swap_hard_limit, &size) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("failed to parse integer: '%s'"), - swap_hard_limit); - return -1; - } + &value) > 0) { + if (lxcConvertSize(value, &size) < 0) + goto error; + def->mem.swap_hard_limit = virMemoryLimitTruncate(size / 1024); } + return 0; + + error: + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to parse integer: '%s'"), + value); + return 1; } static int lxcSetCpuTune(virDomainDefPtr def, virConfPtr properties) { - VIR_AUTOFREE(char *) shares = NULL; - VIR_AUTOFREE(char *) quota = NULL; - VIR_AUTOFREE(char *) period = NULL; + VIR_AUTOFREE(char *) value = NULL; if (virConfGetValueString(properties, "lxc.cgroup.cpu.shares", - &shares) > 0) { - if (virStrToLong_ull(shares, NULL, 10, &def->cputune.shares) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("failed to parse integer: '%s'"), shares); - return -1; - } + &value) > 0) { + if (virStrToLong_ull(value, NULL, 10, &def->cputune.shares) < 0) + goto error; + def->cputune.sharesSpecified = true; + VIR_FREE(value); } if (virConfGetValueString(properties, "lxc.cgroup.cpu.cfs_quota_us", - "a) > 0) { - if (virStrToLong_ll(quota, NULL, 10, &def->cputune.quota) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("failed to parse integer: '%s'"), quota); - return -1; - } + &value) > 0) { + if (virStrToLong_ll(value, NULL, 10, &def->cputune.quota) < 0) + goto error; + + VIR_FREE(value); } if (virConfGetValueString(properties, "lxc.cgroup.cpu.cfs_period_us", - &period) > 0) { - if (virStrToLong_ull(period, NULL, 10, &def->cputune.period) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("failed to parse integer: '%s'"), period); - return -1; - } + &value) > 0) { + if (virStrToLong_ull(value, NULL, 10, &def->cputune.period) < 0) + goto error; } return 0; + + error: + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to parse integer: '%s'"), value); + return -1; } static int lxcSetCpusetTune(virDomainDefPtr def, virConfPtr properties) { - VIR_AUTOFREE(char *) cpus = NULL; - VIR_AUTOFREE(char *) mems = NULL; virBitmapPtr nodeset = NULL; + VIR_AUTOFREE(char *) value = NULL; if (virConfGetValueString(properties, "lxc.cgroup.cpuset.cpus", - &cpus) > 0) { - if (virBitmapParse(cpus, &def->cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0) + &value) > 0) { + if (virBitmapParse(value, &def->cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0) return -1; + def->placement_mode = VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC; + VIR_FREE(value); } if (virConfGetValueString(properties, "lxc.cgroup.cpuset.mems", - &mems) > 0) { - if (virBitmapParse(mems, &nodeset, VIR_DOMAIN_CPUMASK_LEN) < 0) + &value) > 0) { + if (virBitmapParse(value, &nodeset, VIR_DOMAIN_CPUMASK_LEN) < 0) return -1; if (virDomainNumatuneSet(def->numa, def->placement_mode == @@ -1011,8 +1006,7 @@ lxcParseConfigString(const char *config, { virDomainDefPtr vmdef = NULL; virConfPtr properties = NULL; - VIR_AUTOFREE(char *) lxcarch = NULL; - VIR_AUTOFREE(char *) lxcutsname = NULL; + VIR_AUTOFREE(char *) value = NULL; if (!(properties = virConfReadString(config, VIR_CONF_FLAG_LXC_FORMAT))) return NULL; @@ -1045,20 +1039,21 @@ lxcParseConfigString(const char *config, vmdef->nfss = 0; vmdef->os.type = VIR_DOMAIN_OSTYPE_EXE; - if (virConfGetValueString(properties, "lxc.arch", &lxcarch) > 0) { - virArch arch = virArchFromString(lxcarch); - if (arch == VIR_ARCH_NONE && STREQ(lxcarch, "x86")) + if (virConfGetValueString(properties, "lxc.arch", &value) > 0) { + virArch arch = virArchFromString(value); + if (arch == VIR_ARCH_NONE && STREQ(value, "x86")) arch = VIR_ARCH_I686; - else if (arch == VIR_ARCH_NONE && STREQ(lxcarch, "amd64")) + else if (arch == VIR_ARCH_NONE && STREQ(value, "amd64")) arch = VIR_ARCH_X86_64; vmdef->os.arch = arch; + VIR_FREE(value); } if (VIR_STRDUP(vmdef->os.init, "/sbin/init") < 0) goto error; - if (virConfGetValueString(properties, "lxc.utsname", &lxcutsname) <= 0 || - VIR_STRDUP(vmdef->name, lxcutsname) < 0) + if (virConfGetValueString(properties, "lxc.utsname", &value) <= 0 || + VIR_STRDUP(vmdef->name, value) < 0) goto error; if (!vmdef->name && (VIR_STRDUP(vmdef->name, "unnamed") < 0)) goto error;