These functions can't fail really. Drop checking of their retval
then.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/libxl/libxl_conf.c | 34 +++++++++++-----------------------
src/libxl/libxl_domain.c | 35 +++++++++++++----------------------
src/libxl/libxl_domain.h | 2 +-
src/libxl/libxl_driver.c | 19 +++++++------------
src/libxl/libxl_logger.c | 11 ++++-------
src/libxl/libxl_migration.c | 9 +++------
src/libxl/xen_common.c | 11 +++++------
src/libxl/xen_xl.c | 18 ++++++------------
src/libxl/xen_xm.c | 6 ++----
9 files changed, 52 insertions(+), 93 deletions(-)
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 3f08f0f710..a984c9c8aa 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -212,8 +212,7 @@ libxlMakeChrdevStr(virDomainChrDefPtr def, char **buf)
case VIR_DOMAIN_CHR_TYPE_FILE:
case VIR_DOMAIN_CHR_TYPE_PIPE:
- if (virAsprintf(buf, "%s:%s", type, srcdef->data.file.path) < 0)
- return -1;
+ virAsprintf(buf, "%s:%s", type, srcdef->data.file.path);
break;
case VIR_DOMAIN_CHR_TYPE_DEV:
@@ -232,12 +231,8 @@ libxlMakeChrdevStr(virDomainChrDefPtr def, char **buf)
if (bindService == NULL)
bindService = "0";
- if (virAsprintf(buf, "udp:%s:%s@%s:%s",
- connectHost,
- srcdef->data.udp.connectService,
- bindHost,
- bindService) < 0)
- return -1;
+ virAsprintf(buf, "udp:%s:%s@%s:%s", connectHost,
+ srcdef->data.udp.connectService, bindHost, bindService);
break;
}
@@ -249,20 +244,15 @@ libxlMakeChrdevStr(virDomainChrDefPtr def, char **buf)
else
prefix = "tcp";
- if (virAsprintf(buf, "%s:%s:%s%s",
- prefix,
- srcdef->data.tcp.host,
- srcdef->data.tcp.service,
- srcdef->data.tcp.listen ? ",server,nowait" :
"") < 0)
- return -1;
+ virAsprintf(buf, "%s:%s:%s%s", prefix, srcdef->data.tcp.host,
+ srcdef->data.tcp.service,
+ srcdef->data.tcp.listen ? ",server,nowait" :
"");
break;
}
case VIR_DOMAIN_CHR_TYPE_UNIX:
- if (virAsprintf(buf, "unix:%s%s",
- srcdef->data.nix.path,
- srcdef->data.nix.listen ? ",server,nowait" :
"") < 0)
- return -1;
+ virAsprintf(buf, "unix:%s%s", srcdef->data.nix.path,
+ srcdef->data.nix.listen ? ",server,nowait" :
"");
break;
default:
@@ -1937,11 +1927,9 @@ libxlPrepareChannel(virDomainChrDefPtr channel,
if (channel->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_XEN &&
channel->source->type == VIR_DOMAIN_CHR_TYPE_UNIX &&
!channel->source->data.nix.path) {
- if (virAsprintf(&channel->source->data.nix.path,
- "%s/%s-%s", channelDir, domainName,
- channel->target.name ? channel->target.name
- : "unknown.sock") < 0)
- return -1;
+ virAsprintf(&channel->source->data.nix.path, "%s/%s-%s",
channelDir,
+ domainName,
+ channel->target.name ? channel->target.name :
"unknown.sock");
channel->source->data.nix.listen = true;
}
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index d79c3c1ed7..ebb739ae54 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -714,7 +714,7 @@ libxlDomainManagedSavePath(libxlDriverPrivatePtr driver,
virDomainObjPtr vm)
char *ret;
g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
- ignore_value(virAsprintf(&ret, "%s/%s.save", cfg->saveDir,
vm->def->name));
+ virAsprintf(&ret, "%s/%s.save", cfg->saveDir, vm->def->name);
return ret;
}
@@ -905,11 +905,11 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver,
}
}
- if (virAsprintf(&file, "%s/%s.xml", cfg->stateDir,
vm->def->name) > 0) {
- if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR)
- VIR_DEBUG("Failed to remove domain XML for %s",
vm->def->name);
- VIR_FREE(file);
- }
+ virAsprintf(&file, "%s/%s.xml", cfg->stateDir,
vm->def->name);
+
+ if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR)
+ VIR_DEBUG("Failed to remove domain XML for %s", vm->def->name);
+ VIR_FREE(file);
/* The "release" hook cleans up additional resources */
if (virHookPresent(VIR_HOOK_DRIVER_LIBXL)) {
@@ -931,7 +931,7 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver,
*
* virDomainObjPtr must be locked on invocation
*/
-int
+void
libxlDomainAutoCoreDump(libxlDriverPrivatePtr driver,
virDomainObjPtr vm)
{
@@ -940,28 +940,19 @@ libxlDomainAutoCoreDump(libxlDriverPrivatePtr driver,
char timestr[100];
struct tm time_info;
char *dumpfile = NULL;
- int ret = -1;
localtime_r(&curtime, &time_info);
strftime(timestr, sizeof(timestr), "%Y-%m-%d-%H:%M:%S", &time_info);
- if (virAsprintf(&dumpfile, "%s/%s-%s",
- cfg->autoDumpDir,
- vm->def->name,
- timestr) < 0)
- goto cleanup;
+ virAsprintf(&dumpfile, "%s/%s-%s", cfg->autoDumpDir,
vm->def->name,
+ timestr);
/* Unlock virDomainObj while dumping core */
virObjectUnlock(vm);
libxl_domain_core_dump(cfg->ctx, vm->def->id, dumpfile, NULL);
virObjectLock(vm);
- ret = 0;
-
- cleanup:
VIR_FREE(dumpfile);
-
- return ret;
}
int
@@ -1130,7 +1121,7 @@ libxlConsoleCallback(libxl_ctx *ctx, libxl_event *ev, void
*for_callback)
for (i = 0; i < vm->def->nserials; i++) {
chr = vm->def->serials[i];
- ignore_value(virAsprintf(&chr->info.alias, "serial%zd", i));
+ virAsprintf(&chr->info.alias, "serial%zd", i);
if (chr->source->type == VIR_DOMAIN_CHR_TYPE_PTY) {
if (chr->source->data.file.path)
continue;
@@ -1170,9 +1161,9 @@ libxlDomainCreateIfaceNames(virDomainDefPtr def, libxl_domain_config
*d_config)
if (net->ifname)
continue;
- ignore_value(virAsprintf(&net->ifname,
- LIBXL_GENERATED_PREFIX_XEN "%d.%d%s",
- def->id, x_nic->devid, suffix));
+ virAsprintf(&net->ifname,
+ LIBXL_GENERATED_PREFIX_XEN "%d.%d%s",
+ def->id, x_nic->devid, suffix);
}
}
diff --git a/src/libxl/libxl_domain.h b/src/libxl/libxl_domain.h
index 7e28093722..e78a3ce6b2 100644
--- a/src/libxl/libxl_domain.h
+++ b/src/libxl/libxl_domain.h
@@ -131,7 +131,7 @@ void
libxlDomainEventHandler(void *data,
VIR_LIBXL_EVENT_CONST libxl_event *event);
-int
+void
libxlDomainAutoCoreDump(libxlDriverPrivatePtr driver,
virDomainObjPtr vm);
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 5cc6b87b8c..69a949ee26 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -693,8 +693,7 @@ libxlStateInitialize(bool privileged,
if (!(cfg = libxlDriverConfigNew()))
goto error;
- if (virAsprintf(&driverConf, "%s/libxl.conf", cfg->configBaseDir)
< 0)
- goto error;
+ virAsprintf(&driverConf, "%s/libxl.conf", cfg->configBaseDir);
if (libxlDriverConfigLoadFile(cfg, driverConf) < 0)
goto error;
@@ -5391,16 +5390,13 @@ libxlDiskSectorSize(int domid, int devno)
}
path = val = NULL;
- if (virAsprintf(&path, "/local/domain/%d/device/vbd/%d/backend",
- domid, devno) < 0)
- goto cleanup;
+ virAsprintf(&path, "/local/domain/%d/device/vbd/%d/backend", domid,
devno);
if ((val = xs_read(handle, XBT_NULL, path, &len)) == NULL)
goto cleanup;
VIR_FREE(path);
- if (virAsprintf(&path, "%s/physical-sector-size", val) < 0)
- goto cleanup;
+ virAsprintf(&path, "%s/physical-sector-size", val);
VIR_FREE(val);
if ((val = xs_read(handle, XBT_NULL, path, &len)) == NULL)
@@ -5438,9 +5434,8 @@ libxlDomainBlockStatsVBD(virDomainObjPtr vm,
stats->backend = g_strdup("vbd");
- if (virAsprintf(&path,
"/sys/bus/xen-backend/devices/vbd-%d-%d/statistics",
- vm->def->id, devno) < 0)
- return ret;
+ virAsprintf(&path,
"/sys/bus/xen-backend/devices/vbd-%d-%d/statistics",
+ vm->def->id, devno);
if (!virFileExists(path)) {
virReportError(VIR_ERR_OPERATION_FAILED,
@@ -5449,8 +5444,8 @@ libxlDomainBlockStatsVBD(virDomainObjPtr vm,
}
# define LIBXL_SET_VBDSTAT(FIELD, VAR, MUL) \
- if ((virAsprintf(&name, "%s/"FIELD, path) < 0) || \
- (virFileReadAll(name, 256, &val) < 0) || \
+ virAsprintf(&name, "%s/"FIELD, path); \
+ if ((virFileReadAll(name, 256, &val) < 0) || \
(sscanf(val, "%llu", &status) != 1)) { \
virReportError(VIR_ERR_OPERATION_FAILED, \
_("cannot read %s"), name); \
diff --git a/src/libxl/libxl_logger.c b/src/libxl/libxl_logger.c
index 87ad793fb5..4bdca54fcc 100644
--- a/src/libxl/libxl_logger.c
+++ b/src/libxl/libxl_logger.c
@@ -158,8 +158,7 @@ libxlLoggerNew(const char *logDir, virLogPriority minLevel)
if ((logger.files = virHashCreate(3, libxlLoggerFileFree)) == NULL)
return NULL;
- if (virAsprintf(&path, "%s/libxl-driver.log", logDir) < 0)
- goto error;
+ virAsprintf(&path, "%s/libxl-driver.log", logDir);
if ((logger.defaultLogFile = fopen(path, "a")) == NULL)
goto error;
@@ -196,9 +195,8 @@ libxlLoggerOpenFile(libxlLoggerPtr logger,
char *domidstr = NULL;
char ebuf[1024];
- if (virAsprintf(&path, "%s/%s.log", logger->logDir, name) < 0 ||
- virAsprintf(&domidstr, "%d", id) < 0)
- goto cleanup;
+ virAsprintf(&path, "%s/%s.log", logger->logDir, name);
+ virAsprintf(&domidstr, "%d", id);
if (!(logFile = fopen(path, "a"))) {
VIR_WARN("Failed to open log file %s: %s",
@@ -222,8 +220,7 @@ void
libxlLoggerCloseFile(libxlLoggerPtr logger, int id)
{
char *domidstr = NULL;
- if (virAsprintf(&domidstr, "%d", id) < 0)
- return;
+ virAsprintf(&domidstr, "%d", id);
ignore_value(virHashRemoveEntry(logger->files, domidstr));
diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c
index 0a57b6fcb0..09b709e51b 100644
--- a/src/libxl/libxl_migration.c
+++ b/src/libxl/libxl_migration.c
@@ -709,14 +709,12 @@ libxlDomainMigrationDstPrepare(virConnectPtr dconn,
goto endjob;
priv->migrationPort = port;
- if (virAsprintf(uri_out, "tcp://%s:%d", hostname, port) < 0)
- goto endjob;
+ virAsprintf(uri_out, "tcp://%s:%d", hostname, port);
} else {
if (!(STRPREFIX(uri_in, "tcp://"))) {
/* not full URI, add prefix tcp:// */
char *tmp;
- if (virAsprintf(&tmp, "tcp://%s", uri_in) < 0)
- goto endjob;
+ virAsprintf(&tmp, "tcp://%s", uri_in);
uri = virURIParse(tmp);
VIR_FREE(tmp);
} else {
@@ -747,8 +745,7 @@ libxlDomainMigrationDstPrepare(virConnectPtr dconn,
port = uri->port;
}
- if (virAsprintf(uri_out, "tcp://%s:%d", hostname, port) < 0)
- goto endjob;
+ virAsprintf(uri_out, "tcp://%s:%d", hostname, port);
}
snprintf(portstr, sizeof(portstr), "%d", port);
diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c
index cc9039a0cf..826e6699bf 100644
--- a/src/libxl/xen_common.c
+++ b/src/libxl/xen_common.c
@@ -1838,12 +1838,11 @@ xenFormatPCI(virConfPtr conf, virDomainDefPtr def)
virConfValuePtr val, tmp;
char *buf;
- if (virAsprintf(&buf, "%04x:%02x:%02x.%x",
- def->hostdevs[i]->source.subsys.u.pci.addr.domain,
- def->hostdevs[i]->source.subsys.u.pci.addr.bus,
- def->hostdevs[i]->source.subsys.u.pci.addr.slot,
- def->hostdevs[i]->source.subsys.u.pci.addr.function)
< 0)
- goto error;
+ virAsprintf(&buf, "%04x:%02x:%02x.%x",
+ def->hostdevs[i]->source.subsys.u.pci.addr.domain,
+ def->hostdevs[i]->source.subsys.u.pci.addr.bus,
+ def->hostdevs[i]->source.subsys.u.pci.addr.slot,
+ def->hostdevs[i]->source.subsys.u.pci.addr.function);
if (VIR_ALLOC(val) < 0) {
VIR_FREE(buf);
diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c
index 6bdad2a59d..a7c51e3c98 100644
--- a/src/libxl/xen_xl.c
+++ b/src/libxl/xen_xl.c
@@ -83,11 +83,9 @@ static int xenParseCmdline(virConfPtr conf, char **r_cmdline)
VIR_WARN("ignoring root= and extra= in favour of cmdline=");
} else {
if (root && extra) {
- if (virAsprintf(&cmdline, "root=%s %s", root, extra) < 0)
- return -1;
+ virAsprintf(&cmdline, "root=%s %s", root, extra);
} else if (root) {
- if (virAsprintf(&cmdline, "root=%s", root) < 0)
- return -1;
+ virAsprintf(&cmdline, "root=%s", root);
} else if (extra) {
cmdline = g_strdup(extra);
}
@@ -1396,10 +1394,7 @@ xenFormatXLCPUID(virConfPtr conf, virDomainDefPtr def)
policy = "0";
break;
}
- if (virAsprintf(&cpuid_pairs[j++], "%s=%s",
- feature_name,
- policy) < 0)
- goto cleanup;
+ virAsprintf(&cpuid_pairs[j++], "%s=%s", feature_name, policy);
}
cpuid_pairs[j] = NULL;
@@ -2073,10 +2068,9 @@ xenFormatXLUSB(virConfPtr conf,
virConfValuePtr val, tmp;
char *buf;
- if (virAsprintf(&buf, "hostbus=%x,hostaddr=%x",
- def->hostdevs[i]->source.subsys.u.usb.bus,
- def->hostdevs[i]->source.subsys.u.usb.device) < 0)
- goto error;
+ virAsprintf(&buf, "hostbus=%x,hostaddr=%x",
+ def->hostdevs[i]->source.subsys.u.usb.bus,
+ def->hostdevs[i]->source.subsys.u.usb.device);
if (VIR_ALLOC(val) < 0) {
VIR_FREE(buf);
diff --git a/src/libxl/xen_xm.c b/src/libxl/xen_xm.c
index fdf4e1cd29..d962b13cbb 100644
--- a/src/libxl/xen_xm.c
+++ b/src/libxl/xen_xm.c
@@ -90,11 +90,9 @@ xenParseXMOS(virConfPtr conf, virDomainDefPtr def)
return -1;
if (root && extra) {
- if (virAsprintf(&def->os.cmdline, "root=%s %s", root, extra)
< 0)
- return -1;
+ virAsprintf(&def->os.cmdline, "root=%s %s", root, extra);
} else if (root) {
- if (virAsprintf(&def->os.cmdline, "root=%s", root) < 0)
- return -1;
+ virAsprintf(&def->os.cmdline, "root=%s", root);
} else if (extra) {
def->os.cmdline = g_strdup(extra);
}
--
2.21.0