On Fri, 2018-05-04 at 18:46 +0530, Prafull wrote:
From: Prafullkumar Tale <talep158(a)gmail.com>
Signed-off-by: Prafullkumar Tale <talep158(a)gmail.com>
---
src/lxc/lxc_native.c | 141 +++++++++++++++++++++++++--------------------------
1 file changed, 70 insertions(+), 71 deletions(-)
diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index 55ea774..35077e1 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -199,19 +199,15 @@ lxcSetRootfs(virDomainDefPtr def,
virConfPtr properties)
{
int type = VIR_DOMAIN_FS_TYPE_MOUNT;
- virConfValuePtr value;
+ char *value = NULL;
- if (!(value = virConfGetValue(properties, "lxc.rootfs")) ||
- !value->str) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("Missing lxc.rootfs configuration"));
+ if (virConfGetValueString(properties, "lxc.rootfs", &value) <= 0)
return -1;
- }
- if (STRPREFIX(value->str, "/dev/"))
+ if (STRPREFIX(value, "/dev/"))
type = VIR_DOMAIN_FS_TYPE_BLOCK;
- if (lxcAddFSDef(def, type, value->str, "/", false, 0) < 0)
+ if (lxcAddFSDef(def, type, value, "/", false, 0) < 0)
return -1;
return 0;
@@ -684,17 +680,17 @@ lxcConvertNetworkSettings(virDomainDefPtr def, virConfPtr
properties)
static int
lxcCreateConsoles(virDomainDefPtr def, virConfPtr properties)
{
- virConfValuePtr value;
+ char *value = NULL;
int nbttys = 0;
virDomainChrDefPtr console;
size_t i;
- if (!(value = virConfGetValue(properties, "lxc.tty")) || !value->str)
+ if (virConfGetValueString(properties, "lxc.tty", &value) <= 0)
return 0;
- if (virStrToLong_i(value->str, NULL, 10, &nbttys) < 0) {
+ if (virStrToLong_i(value, NULL, 10, &nbttys) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, _("failed to parse int:
'%s'"),
- value->str);
+ value);
return -1;
}
@@ -761,89 +757,91 @@ lxcIdmapWalkCallback(const char *name, virConfValuePtr value, void
*data)
static int
lxcSetMemTune(virDomainDefPtr def, virConfPtr properties)
{
- virConfValuePtr value;
+ char *value = NULL;
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;
+ if (virConfGetValueString(properties,
+ "lxc.cgroup.memory.limit_in_bytes",
+ &value) > 0) {
+ if (lxcConvertSize(value, &size) < 0)
+ goto error;
size = size / 1024;
virDomainDefSetMemoryTotal(def, size);
def->mem.hard_limit = virMemoryLimitTruncate(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;
-
+ if (virConfGetValueString(properties,
+ "lxc.cgroup.memory.soft_limit_in_bytes",
+ &value) > 0) {
+ if (lxcConvertSize(value, &size) < 0)
+ goto error;
def->mem.soft_limit = virMemoryLimitTruncate(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;
-
+ if (virConfGetValueString(properties,
+ "lxc.cgroup.memory.memsw.limit_in_bytes",
+ &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)
{
- virConfValuePtr value;
+ char *value = NULL;
- if ((value = virConfGetValue(properties, "lxc.cgroup.cpu.shares"))
&&
- value->str) {
- if (virStrToLong_ull(value->str, NULL, 10, &def->cputune.shares) <
0)
+ if (virConfGetValueString(properties, "lxc.cgroup.cpu.shares",
+ &value) > 0) {
+ if (virStrToLong_ull(value, NULL, 10, &def->cputune.shares) < 0)
goto error;
def->cputune.sharesSpecified = true;
}
- 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 (virConfGetValueString(properties, "lxc.cgroup.cpu.cfs_quota_us",
+ &value) > 0) {
+ if (virStrToLong_ll(value, 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;
+ if (virConfGetValueString(properties, "lxc.cgroup.cpu.cfs_period_us",
+ &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->str);
+ _("failed to parse integer: '%s'"), value);
return -1;
}
static int
lxcSetCpusetTune(virDomainDefPtr def, virConfPtr properties)
{
- virConfValuePtr value;
+ char *value = NULL;
virBitmapPtr nodeset = NULL;
- if ((value = virConfGetValue(properties, "lxc.cgroup.cpuset.cpus"))
&&
- value->str) {
- if (virBitmapParse(value->str, &def->cpumask,
- VIR_DOMAIN_CPUMASK_LEN) < 0)
+ if (virConfGetValueString(properties, "lxc.cgroup.cpuset.cpus",
+ &value) > 0) {
+ if (virBitmapParse(value, &def->cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0)
return -1;
-
def->placement_mode = VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC;
}
- if ((value = virConfGetValue(properties, "lxc.cgroup.cpuset.mems"))
&&
- value->str) {
- if (virBitmapParse(value->str, &nodeset, VIR_DOMAIN_CPUMASK_LEN) < 0)
+ if (virConfGetValueString(properties, "lxc.cgroup.cpuset.mems",
+ &value) > 0) {
+ if (virBitmapParse(value, &nodeset, VIR_DOMAIN_CPUMASK_LEN) < 0)
return -1;
if (virDomainNumatuneSet(def->numa,
def->placement_mode ==
@@ -952,14 +950,15 @@ lxcBlkioDeviceWalkCallback(const char *name, virConfValuePtr value,
void *data)
static int
lxcSetBlkioTune(virDomainDefPtr def, virConfPtr properties)
{
- virConfValuePtr value;
+ char *value = NULL;
- if ((value = virConfGetValue(properties, "lxc.cgroup.blkio.weight"))
&&
- value->str && virStrToLong_ui(value->str, NULL, 10,
- &def->blkio.weight) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("failed to parse integer: '%s'"),
value->str);
- return -1;
+ if (virConfGetValueString(properties, "lxc.cgroup.blkio.weight",
+ &value) > 0) {
+ if (virStrToLong_ui(value, NULL, 10, &def->blkio.weight) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("failed to parse integer: '%s'"),
value);
+ return -1;
+ }
}
if (virConfWalk(properties, lxcBlkioDeviceWalkCallback, def) < 0)
@@ -971,13 +970,13 @@ lxcSetBlkioTune(virDomainDefPtr def, virConfPtr properties)
static void
lxcSetCapDrop(virDomainDefPtr def, virConfPtr properties)
{
- virConfValuePtr value;
+ char *value = NULL;
char **toDrop = NULL;
const char *capString;
size_t i;
- if ((value = virConfGetValue(properties, "lxc.cap.drop")) &&
value->str)
- toDrop = virStringSplit(value->str, " ", 0);
+ if (virConfGetValueString(properties, "lxc.cap.drop", &value) > 0)
+ toDrop = virStringSplit(value, " ", 0);
for (i = 0; i < VIR_DOMAIN_CAPS_FEATURE_LAST; i++) {
capString = virDomainCapsFeatureTypeToString(i);
@@ -998,7 +997,7 @@ lxcParseConfigString(const char *config,
{
virDomainDefPtr vmdef = NULL;
virConfPtr properties = NULL;
- virConfValuePtr value;
+ char *value = NULL;
if (!(properties = virConfReadString(config, VIR_CONF_FLAG_LXC_FORMAT)))
return NULL;
@@ -1031,11 +1030,11 @@ lxcParseConfigString(const char *config,
vmdef->nfss = 0;
vmdef->os.type = VIR_DOMAIN_OSTYPE_EXE;
- if ((value = virConfGetValue(properties, "lxc.arch")) &&
value->str) {
- virArch arch = virArchFromString(value->str);
- if (arch == VIR_ARCH_NONE && STREQ(value->str, "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(value->str,
"amd64"))
+ else if (arch == VIR_ARCH_NONE && STREQ(value, "amd64"))
arch = VIR_ARCH_X86_64;
vmdef->os.arch = arch;
}
@@ -1043,8 +1042,8 @@ lxcParseConfigString(const char *config,
if (VIR_STRDUP(vmdef->os.init, "/sbin/init") < 0)
goto error;
- if (!(value = virConfGetValue(properties, "lxc.utsname")) ||
- !value->str || (VIR_STRDUP(vmdef->name, value->str) < 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;
ACK and pushed
--
Cedric