[libvirt] [PATCH] lxc: convert to typesafe virConf accessors in lxc_native.c

2018-05-04 Thread Prafull
From: Prafullkumar Tale 

Signed-off-by: Prafullkumar Tale 
---
 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 (virStrT

[libvirt] [PATCH] lxc: report error message raised by the failing function

2018-03-22 Thread Prafull
The code that calls VIR_WARN after a function fails, doesn't
report the error message raised by the failing function.
Such error messages are now reported in lxc/lxc_driver.c

Signed-off-by: Prafullkumar T 
---
 src/lxc/lxc_driver.c | 36 ++--
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 4f6b93b..4f600f3 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -3915,8 +3915,8 @@ lxcDomainAttachDeviceDiskLive(virLXCDriverPtr driver,
 major(sb.st_rdev),
 minor(sb.st_rdev),
 perms) < 0)
-VIR_WARN("cannot deny device %s for domain %s",
- src, vm->def->name);
+VIR_WARN("cannot deny device %s for domain %s: %s",
+ src, vm->def->name, virGetLastErrorMessage());
 goto cleanup;
 }
 
@@ -4011,8 +4011,8 @@ lxcDomainAttachDeviceNetLive(virConnectPtr conn,
 goto cleanup;
 } else {
 VIR_WARN("setting bandwidth on interfaces of "
- "type '%s' is not implemented yet",
- virDomainNetTypeToString(actualType));
+ "type '%s' is not implemented yet: %s",
+ virDomainNetTypeToString(actualType), 
virGetLastErrorMessage());
 }
 }
 
@@ -4116,8 +4116,8 @@ lxcDomainAttachDeviceHostdevSubsysUSBLive(virLXCDriverPtr 
driver,
 if (virUSBDeviceFileIterate(usb,
 virLXCTeardownHostUSBDeviceCgroup,
 priv->cgroup) < 0)
-VIR_WARN("cannot deny device %s for domain %s",
- src, vm->def->name);
+VIR_WARN("cannot deny device %s for domain %s: %s",
+ src, vm->def->name, virGetLastErrorMessage());
 goto cleanup;
 }
 
@@ -4190,8 +4190,8 @@ lxcDomainAttachDeviceHostdevStorageLive(virLXCDriverPtr 
driver,
 major(sb.st_rdev),
 minor(sb.st_rdev),
 VIR_CGROUP_DEVICE_RWM) < 0)
-VIR_WARN("cannot deny device %s for domain %s",
- def->source.caps.u.storage.block, vm->def->name);
+VIR_WARN("cannot deny device %s for domain %s: %s",
+ def->source.caps.u.storage.block, vm->def->name, 
virGetLastErrorMessage());
 goto cleanup;
 }
 
@@ -4262,8 +4262,8 @@ lxcDomainAttachDeviceHostdevMiscLive(virLXCDriverPtr 
driver,
 major(sb.st_rdev),
 minor(sb.st_rdev),
 VIR_CGROUP_DEVICE_RWM) < 0)
-VIR_WARN("cannot deny device %s for domain %s",
- def->source.caps.u.storage.block, vm->def->name);
+VIR_WARN("cannot deny device %s for domain %s: %s",
+ def->source.caps.u.storage.block, vm->def->name, 
virGetLastErrorMessage());
 goto cleanup;
 }
 
@@ -4434,8 +4434,8 @@ lxcDomainDetachDeviceDiskLive(virDomainObjPtr vm,
 
 if (virCgroupDenyDevicePath(priv->cgroup, src,
 VIR_CGROUP_DEVICE_RWM, false) != 0)
-VIR_WARN("cannot deny device %s for domain %s",
- src, vm->def->name);
+VIR_WARN("cannot deny device %s for domain %s: %s",
+ src, vm->def->name, virGetLastErrorMessage());
 
 virDomainDiskRemove(vm->def, idx);
 virDomainDiskDefFree(def);
@@ -4567,8 +4567,8 @@ lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr 
driver,
 if (virUSBDeviceFileIterate(usb,
 virLXCTeardownHostUSBDeviceCgroup,
 priv->cgroup) < 0)
-VIR_WARN("cannot deny device %s for domain %s",
- dst, vm->def->name);
+VIR_WARN("cannot deny device %s for domain %s: %s",
+ dst, vm->def->name, virGetLastErrorMessage());
 
 virObjectLock(hostdev_mgr->activeUSBHostdevs);
 virUSBDeviceListDel(hostdev_mgr->activeUSBHostdevs, usb);
@@ -4623,8 +4623,8 @@ lxcDomainDetachDeviceHostdevStorageLive(virDomainObjPtr 
vm,
 
 if (virCgroupDenyDevicePath(priv->cgroup, def->source.caps.u.storage.block,
 VIR_CGROUP_DEVICE_RWM, false) != 0)
-VIR_WARN("cannot deny device %s for domain %s",
- def->source.caps.u.storage.block, vm->def->name);
+VIR_WARN("cannot deny device %s for domain %s: %s",
+ def->source.caps.u.storage.block, vm->def->name, 
virGetLastErrorMessage());
 
 virDomainHostdevRemove(vm->def, idx);
 virDomainHostdevDefFree(def);
@@ -4673,8 +4673,8 @@ lxcDomainDetachDeviceHostdevMiscLive(virDomainObjPtr vm,
 
 if (virCgroupDenyDevicePath(priv->cgroup, def->source.caps.u.misc.chardev,
 VIR_CGROUP_DEVICE_