Remove empty cleanup sections

After recent cleanups, there are some pointless cleanup sections.

Clean them up.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Ján Tomko 2021-12-10 16:21:59 +01:00
parent 8a82117ee2
commit 7d825985b4
21 changed files with 106 additions and 209 deletions

View File

@ -141,7 +141,6 @@ bhyveConnectGetCapabilities(virConnectPtr conn)
{ {
struct _bhyveConn *privconn = conn->privateData; struct _bhyveConn *privconn = conn->privateData;
g_autoptr(virCaps) caps = NULL; g_autoptr(virCaps) caps = NULL;
char *xml = NULL;
if (virConnectGetCapabilitiesEnsureACL(conn) < 0) if (virConnectGetCapabilitiesEnsureACL(conn) < 0)
return NULL; return NULL;
@ -149,14 +148,10 @@ bhyveConnectGetCapabilities(virConnectPtr conn)
if (!(caps = bhyveDriverGetCapabilities(privconn))) { if (!(caps = bhyveDriverGetCapabilities(privconn))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Unable to get Capabilities")); _("Unable to get Capabilities"));
goto cleanup; return NULL;
} }
if (!(xml = virCapabilitiesFormatXML(caps))) return virCapabilitiesFormatXML(caps);
goto cleanup;
cleanup:
return xml;
} }
static virDomainObj * static virDomainObj *
@ -1558,7 +1553,6 @@ bhyveConnectDomainXMLFromNative(virConnectPtr conn,
const char *nativeConfig, const char *nativeConfig,
unsigned int flags) unsigned int flags)
{ {
char *xml = NULL;
g_autoptr(virDomainDef) def = NULL; g_autoptr(virDomainDef) def = NULL;
struct _bhyveConn *privconn = conn->privateData; struct _bhyveConn *privconn = conn->privateData;
unsigned bhyveCaps = bhyveDriverGetBhyveCaps(privconn); unsigned bhyveCaps = bhyveDriverGetBhyveCaps(privconn);
@ -1571,18 +1565,15 @@ bhyveConnectDomainXMLFromNative(virConnectPtr conn,
if (STRNEQ(nativeFormat, BHYVE_CONFIG_FORMAT_ARGV)) { if (STRNEQ(nativeFormat, BHYVE_CONFIG_FORMAT_ARGV)) {
virReportError(VIR_ERR_INVALID_ARG, virReportError(VIR_ERR_INVALID_ARG,
_("unsupported config type %s"), nativeFormat); _("unsupported config type %s"), nativeFormat);
goto cleanup; return NULL;
} }
def = bhyveParseCommandLineString(nativeConfig, bhyveCaps, def = bhyveParseCommandLineString(nativeConfig, bhyveCaps,
privconn->xmlopt); privconn->xmlopt);
if (def == NULL) if (def == NULL)
goto cleanup; return NULL;
xml = virDomainDefFormat(def, privconn->xmlopt, 0); return virDomainDefFormat(def, privconn->xmlopt, 0);
cleanup:
return xml;
} }
static char * static char *

View File

@ -57,13 +57,13 @@ virCaps *virCHDriverCapsInit(void)
if ((caps = virCapabilitiesNew(virArchFromHost(), if ((caps = virCapabilitiesNew(virArchFromHost(),
false, false)) == NULL) false, false)) == NULL)
goto cleanup; return NULL;
if (!(caps->host.numa = virCapabilitiesHostNUMANewHost())) if (!(caps->host.numa = virCapabilitiesHostNUMANewHost()))
goto cleanup; return NULL;
if (virCapabilitiesInitCaches(caps) < 0) if (virCapabilitiesInitCaches(caps) < 0)
goto cleanup; return NULL;
guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM,
caps->host.arch, NULL, NULL, 0, NULL); caps->host.arch, NULL, NULL, 0, NULL);
@ -71,9 +71,6 @@ virCaps *virCHDriverCapsInit(void)
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_KVM, virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_KVM,
NULL, NULL, 0, NULL); NULL, NULL, 0, NULL);
return g_steal_pointer(&caps); return g_steal_pointer(&caps);
cleanup:
return NULL;
} }
/** /**

View File

@ -271,7 +271,7 @@ hypervCapsInit(hypervPrivate *priv)
return NULL; return NULL;
if (hypervLookupHostSystemBiosUuid(priv, caps->host.host_uuid) < 0) if (hypervLookupHostSystemBiosUuid(priv, caps->host.host_uuid) < 0)
goto error; return NULL;
/* i686 caps */ /* i686 caps */
guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_I686, guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_I686,
@ -288,9 +288,6 @@ hypervCapsInit(hypervPrivate *priv)
NULL, NULL, 0, NULL); NULL, NULL, 0, NULL);
return g_steal_pointer(&caps); return g_steal_pointer(&caps);
error:
return NULL;
} }

View File

@ -645,18 +645,15 @@ libxlMakeCapabilities(libxl_ctx *ctx)
return NULL; return NULL;
if (libxlCapsInitHost(ctx, caps) < 0) if (libxlCapsInitHost(ctx, caps) < 0)
goto error; return NULL;
if (libxlCapsInitNuma(ctx, caps) < 0) if (libxlCapsInitNuma(ctx, caps) < 0)
goto error; return NULL;
if (libxlCapsInitGuests(ctx, caps) < 0) if (libxlCapsInitGuests(ctx, caps) < 0)
goto error; return NULL;
return g_steal_pointer(&caps); return g_steal_pointer(&caps);
error:
return NULL;
} }
/* /*

View File

@ -1891,7 +1891,6 @@ libxlDriverGetDom0MaxmemConf(libxlDriverConfig *cfg,
size_t i; size_t i;
size_t j; size_t j;
libxl_physinfo physinfo; libxl_physinfo physinfo;
int ret = -1;
if (cfg->verInfo->commandline == NULL || if (cfg->verInfo->commandline == NULL ||
!(cmd_tokens = g_strsplit(cfg->verInfo->commandline, " ", 0))) !(cmd_tokens = g_strsplit(cfg->verInfo->commandline, " ", 0)))
@ -1931,8 +1930,7 @@ libxlDriverGetDom0MaxmemConf(libxlDriverConfig *cfg,
} }
} }
*maxmem = *maxmem * multiplier; *maxmem = *maxmem * multiplier;
ret = 0; return 0;
goto cleanup;
} }
} }
} }
@ -1942,14 +1940,11 @@ libxlDriverGetDom0MaxmemConf(libxlDriverConfig *cfg,
libxl_physinfo_init(&physinfo); libxl_physinfo_init(&physinfo);
if (libxl_get_physinfo(cfg->ctx, &physinfo)) { if (libxl_get_physinfo(cfg->ctx, &physinfo)) {
VIR_WARN("libxl_get_physinfo failed"); VIR_WARN("libxl_get_physinfo failed");
goto cleanup; return -1;
} }
*maxmem = (physinfo.total_pages * cfg->verInfo->pagesize) / 1024; *maxmem = (physinfo.total_pages * cfg->verInfo->pagesize) / 1024;
libxl_physinfo_dispose(&physinfo); libxl_physinfo_dispose(&physinfo);
ret = 0; return 0;
cleanup:
return ret;
} }

View File

@ -1575,19 +1575,15 @@ xenMakeIPList(virNetDevIPInfo *guestIP)
{ {
size_t i; size_t i;
g_auto(GStrv) address_array = NULL; g_auto(GStrv) address_array = NULL;
char *ret = NULL;
address_array = g_new0(char *, guestIP->nips + 1); address_array = g_new0(char *, guestIP->nips + 1);
for (i = 0; i < guestIP->nips; i++) { for (i = 0; i < guestIP->nips; i++) {
address_array[i] = virSocketAddrFormat(&guestIP->ips[i]->address); address_array[i] = virSocketAddrFormat(&guestIP->ips[i]->address);
if (!address_array[i]) if (!address_array[i])
goto cleanup; return NULL;
} }
ret = g_strjoinv(" ", address_array); return g_strjoinv(" ", address_array);
cleanup:
return ret;
} }
static int static int

View File

@ -248,7 +248,6 @@ xenParseXLCPUID(virConf *conf, virDomainDef *def)
g_autofree char *cpuid_str = NULL; g_autofree char *cpuid_str = NULL;
g_auto(GStrv) cpuid_pairs = NULL; g_auto(GStrv) cpuid_pairs = NULL;
size_t i; size_t i;
int ret = -1;
int policy; int policy;
if (xenConfigGetString(conf, "cpuid", &cpuid_str, NULL) < 0) if (xenConfigGetString(conf, "cpuid", &cpuid_str, NULL) < 0)
@ -267,29 +266,27 @@ xenParseXLCPUID(virConf *conf, virDomainDef *def)
cpuid_pairs = g_strsplit(cpuid_str, ",", 0); cpuid_pairs = g_strsplit(cpuid_str, ",", 0);
if (!cpuid_pairs) if (!cpuid_pairs)
goto cleanup; return -1;
if (!cpuid_pairs[0]) { if (!cpuid_pairs[0])
ret = 0; return 0;
goto cleanup;
}
if (STRNEQ(cpuid_pairs[0], "host")) { if (STRNEQ(cpuid_pairs[0], "host")) {
virReportError(VIR_ERR_CONF_SYNTAX, virReportError(VIR_ERR_CONF_SYNTAX,
_("cpuid starting with %s is not supported, only libxl format is"), _("cpuid starting with %s is not supported, only libxl format is"),
cpuid_pairs[0]); cpuid_pairs[0]);
goto cleanup; return -1;
} }
for (i = 1; cpuid_pairs[i]; i++) { for (i = 1; cpuid_pairs[i]; i++) {
g_auto(GStrv) name_and_value = g_strsplit(cpuid_pairs[i], "=", 2); g_auto(GStrv) name_and_value = g_strsplit(cpuid_pairs[i], "=", 2);
if (!name_and_value) if (!name_and_value)
goto cleanup; return -1;
if (!name_and_value[0] || !name_and_value[1]) { if (!name_and_value[0] || !name_and_value[1]) {
virReportError(VIR_ERR_CONF_SYNTAX, virReportError(VIR_ERR_CONF_SYNTAX,
_("Invalid libxl cpuid key=value element: %s"), _("Invalid libxl cpuid key=value element: %s"),
cpuid_pairs[i]); cpuid_pairs[i]);
goto cleanup; return -1;
} }
if (STREQ(name_and_value[1], "1")) { if (STREQ(name_and_value[1], "1")) {
policy = VIR_CPU_FEATURE_FORCE; policy = VIR_CPU_FEATURE_FORCE;
@ -305,19 +302,16 @@ xenParseXLCPUID(virConf *conf, virDomainDef *def)
virReportError(VIR_ERR_CONF_SYNTAX, virReportError(VIR_ERR_CONF_SYNTAX,
_("Invalid libxl cpuid value: %s"), _("Invalid libxl cpuid value: %s"),
cpuid_pairs[i]); cpuid_pairs[i]);
goto cleanup; return -1;
} }
if (virCPUDefAddFeature(def->cpu, if (virCPUDefAddFeature(def->cpu,
xenTranslateCPUFeature(name_and_value[0], true), xenTranslateCPUFeature(name_and_value[0], true),
policy) < 0) policy) < 0)
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
return ret;
} }
@ -1292,7 +1286,6 @@ xenFormatXLCPUID(virConf *conf, virDomainDef *def)
g_auto(GStrv) cpuid_pairs = NULL; g_auto(GStrv) cpuid_pairs = NULL;
g_autofree char *cpuid_string = NULL; g_autofree char *cpuid_string = NULL;
size_t i, j; size_t i, j;
int ret = -1;
if (!def->cpu) if (!def->cpu)
return 0; return 0;
@ -1341,13 +1334,10 @@ xenFormatXLCPUID(virConf *conf, virDomainDef *def)
cpuid_string = g_strjoinv(",", cpuid_pairs); cpuid_string = g_strjoinv(",", cpuid_pairs);
if (xenConfigSetString(conf, "cpuid", cpuid_string) < 0) if (xenConfigSetString(conf, "cpuid", cpuid_string) < 0)
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
return ret;
} }
static int static int

View File

@ -65,14 +65,14 @@ virCaps *virLXCDriverCapsInit(virLXCDriver *driver)
if ((caps = virCapabilitiesNew(virArchFromHost(), if ((caps = virCapabilitiesNew(virArchFromHost(),
false, false)) == NULL) false, false)) == NULL)
goto error; return NULL;
/* Some machines have problematic NUMA topology causing /* Some machines have problematic NUMA topology causing
* unexpected failures. We don't want to break the lxc * unexpected failures. We don't want to break the lxc
* driver in this scenario, so log errors & carry on * driver in this scenario, so log errors & carry on
*/ */
if (!(caps->host.numa = virCapabilitiesHostNUMANewHost())) if (!(caps->host.numa = virCapabilitiesHostNUMANewHost()))
goto error; return NULL;
if (virCapabilitiesInitCaches(caps) < 0) if (virCapabilitiesInitCaches(caps) < 0)
VIR_WARN("Failed to get host CPU cache info"); VIR_WARN("Failed to get host CPU cache info");
@ -89,13 +89,13 @@ virCaps *virLXCDriverCapsInit(virLXCDriver *driver)
if (virGetHostUUID(caps->host.host_uuid)) { if (virGetHostUUID(caps->host.host_uuid)) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot get the host uuid")); "%s", _("cannot get the host uuid"));
goto error; return NULL;
} }
if (!(lxc_path = virFileFindResource("libvirt_lxc", if (!(lxc_path = virFileFindResource("libvirt_lxc",
abs_top_builddir "/src", abs_top_builddir "/src",
LIBEXECDIR))) LIBEXECDIR)))
goto error; return NULL;
guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_EXE, guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_EXE,
caps->host.arch, lxc_path, NULL, 0, NULL); caps->host.arch, lxc_path, NULL, 0, NULL);
@ -130,7 +130,7 @@ virCaps *virLXCDriverCapsInit(virLXCDriver *driver)
virCapabilitiesHostSecModelAddBaseLabel(&caps->host.secModels[0], virCapabilitiesHostSecModelAddBaseLabel(&caps->host.secModels[0],
type, type,
label) < 0) label) < 0)
goto error; return NULL;
VIR_DEBUG("Initialized caps for security driver \"%s\" with " VIR_DEBUG("Initialized caps for security driver \"%s\" with "
"DOI \"%s\"", model, doi); "DOI \"%s\"", model, doi);
@ -139,9 +139,6 @@ virCaps *virLXCDriverCapsInit(virLXCDriver *driver)
} }
return g_steal_pointer(&caps); return g_steal_pointer(&caps);
error:
return NULL;
} }

View File

@ -515,13 +515,12 @@ static int lxcContainerUnmountSubtree(const char *prefix,
size_t i; size_t i;
int saveErrno; int saveErrno;
const char *failedUmount = NULL; const char *failedUmount = NULL;
int ret = -1;
VIR_DEBUG("Unmount subtree from %s", prefix); VIR_DEBUG("Unmount subtree from %s", prefix);
if (virFileGetMountReverseSubtree("/proc/mounts", prefix, if (virFileGetMountReverseSubtree("/proc/mounts", prefix,
&mounts, &nmounts) < 0) &mounts, &nmounts) < 0)
goto cleanup; return -1;
for (i = 0; i < nmounts; i++) { for (i = 0; i < nmounts; i++) {
VIR_DEBUG("Umount %s", mounts[i]); VIR_DEBUG("Umount %s", mounts[i]);
if (umount(mounts[i]) < 0) { if (umount(mounts[i]) < 0) {
@ -540,7 +539,7 @@ static int lxcContainerUnmountSubtree(const char *prefix,
virReportSystemError(saveErrno, virReportSystemError(saveErrno,
_("Failed to unmount '%s' and could not detach subtree '%s'"), _("Failed to unmount '%s' and could not detach subtree '%s'"),
failedUmount, mounts[nmounts-1]); failedUmount, mounts[nmounts-1]);
goto cleanup; return -1;
} }
/* This unmounts the tmpfs on which the old root filesystem was hosted */ /* This unmounts the tmpfs on which the old root filesystem was hosted */
if (isOldRootFS && if (isOldRootFS &&
@ -548,14 +547,11 @@ static int lxcContainerUnmountSubtree(const char *prefix,
virReportSystemError(saveErrno, virReportSystemError(saveErrno,
_("Failed to unmount '%s' and could not unmount old root '%s'"), _("Failed to unmount '%s' and could not unmount old root '%s'"),
failedUmount, mounts[nmounts-1]); failedUmount, mounts[nmounts-1]);
goto cleanup; return -1;
} }
} }
ret = 0; return 0;
cleanup:
return ret;
} }
static int lxcContainerResolveSymlinks(virDomainFSDef *fs, bool gentle) static int lxcContainerResolveSymlinks(virDomainFSDef *fs, bool gentle)

View File

@ -928,7 +928,6 @@ static char *lxcConnectDomainXMLFromNative(virConnectPtr conn,
const char *nativeConfig, const char *nativeConfig,
unsigned int flags) unsigned int flags)
{ {
char *xml = NULL;
g_autoptr(virDomainDef) def = NULL; g_autoptr(virDomainDef) def = NULL;
virLXCDriver *driver = conn->privateData; virLXCDriver *driver = conn->privateData;
g_autoptr(virCaps) caps = virLXCDriverGetCapabilities(driver, false); g_autoptr(virCaps) caps = virLXCDriverGetCapabilities(driver, false);
@ -936,21 +935,18 @@ static char *lxcConnectDomainXMLFromNative(virConnectPtr conn,
virCheckFlags(0, NULL); virCheckFlags(0, NULL);
if (virConnectDomainXMLFromNativeEnsureACL(conn) < 0) if (virConnectDomainXMLFromNativeEnsureACL(conn) < 0)
goto cleanup; return NULL;
if (STRNEQ(nativeFormat, LXC_CONFIG_FORMAT)) { if (STRNEQ(nativeFormat, LXC_CONFIG_FORMAT)) {
virReportError(VIR_ERR_INVALID_ARG, virReportError(VIR_ERR_INVALID_ARG,
_("unsupported config type %s"), nativeFormat); _("unsupported config type %s"), nativeFormat);
goto cleanup; return NULL;
} }
if (!(def = lxcParseConfigString(nativeConfig, caps, driver->xmlopt))) if (!(def = lxcParseConfigString(nativeConfig, caps, driver->xmlopt)))
goto cleanup; return NULL;
xml = virDomainDefFormat(def, driver->xmlopt, 0); return virDomainDefFormat(def, driver->xmlopt, 0);
cleanup:
return xml;
} }
/** /**

View File

@ -119,7 +119,7 @@ static char ** lxcStringSplit(const char *string)
} }
if (!(parts = g_strsplit(tmp, " ", 0))) if (!(parts = g_strsplit(tmp, " ", 0)))
goto error; return NULL;
/* Append NULL element */ /* Append NULL element */
VIR_EXPAND_N(result, ntokens, 1); VIR_EXPAND_N(result, ntokens, 1);
@ -133,9 +133,6 @@ static char ** lxcStringSplit(const char *string)
} }
return g_steal_pointer(&result); return g_steal_pointer(&result);
error:
return NULL;
} }
static lxcFstab * static lxcFstab *
@ -250,7 +247,6 @@ lxcAddFstabLine(virDomainDef *def, lxcFstab *fstab)
bool readonly; bool readonly;
int type = VIR_DOMAIN_FS_TYPE_MOUNT; int type = VIR_DOMAIN_FS_TYPE_MOUNT;
unsigned long long usage = 0; unsigned long long usage = 0;
int ret = -1;
if (!options) if (!options)
return -1; return -1;
@ -262,10 +258,8 @@ lxcAddFstabLine(virDomainDef *def, lxcFstab *fstab)
} }
/* Check that we don't add basic mounts */ /* Check that we don't add basic mounts */
if (lxcIsBasicMountLocation(dst)) { if (lxcIsBasicMountLocation(dst))
ret = 0; return 0;
goto cleanup;
}
if (STREQ(fstab->type, "tmpfs")) { if (STREQ(fstab->type, "tmpfs")) {
char *sizeStr = NULL; char *sizeStr = NULL;
@ -275,14 +269,14 @@ lxcAddFstabLine(virDomainDef *def, lxcFstab *fstab)
for (i = 0; options[i]; i++) { for (i = 0; options[i]; i++) {
if ((sizeStr = STRSKIP(options[i], "size="))) { if ((sizeStr = STRSKIP(options[i], "size="))) {
if (lxcConvertSize(sizeStr, &usage) < 0) if (lxcConvertSize(sizeStr, &usage) < 0)
goto cleanup; return -1;
break; break;
} }
} }
if (!sizeStr) { if (!sizeStr) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing tmpfs size, set the size option")); _("missing tmpfs size, set the size option"));
goto cleanup; return -1;
} }
} else { } else {
src = fstab->src; src = fstab->src;
@ -296,12 +290,9 @@ lxcAddFstabLine(virDomainDef *def, lxcFstab *fstab)
readonly = g_strv_contains((const char **)options, "ro"); readonly = g_strv_contains((const char **)options, "ro");
if (lxcAddFSDef(def, type, src, dst, readonly, usage) < 0) if (lxcAddFSDef(def, type, src, dst, readonly, usage) < 0)
goto cleanup; return -1;
ret = 1; return 1;
cleanup:
return ret;
} }
static int static int
@ -961,7 +952,6 @@ lxcBlkioDeviceWalkCallback(const char *name, virConfValue *value, void *data)
virDomainDef *def = data; virDomainDef *def = data;
size_t i = 0; size_t i = 0;
g_autofree char *path = NULL; g_autofree char *path = NULL;
int ret = -1;
if (!STRPREFIX(name, "lxc.cgroup.blkio.") || if (!STRPREFIX(name, "lxc.cgroup.blkio.") ||
STREQ(name, "lxc.cgroup.blkio.weight")|| !value->str) STREQ(name, "lxc.cgroup.blkio.weight")|| !value->str)
@ -974,7 +964,7 @@ lxcBlkioDeviceWalkCallback(const char *name, virConfValue *value, void *data)
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("invalid %s value: '%s'"), _("invalid %s value: '%s'"),
name, value->str); name, value->str);
goto cleanup; return -1;
} }
path = g_strdup_printf("/dev/block/%s", parts[0]); path = g_strdup_printf("/dev/block/%s", parts[0]);
@ -996,44 +986,41 @@ lxcBlkioDeviceWalkCallback(const char *name, virConfValue *value, void *data)
if (virStrToLong_ui(parts[1], NULL, 10, &device->weight) < 0) { if (virStrToLong_ui(parts[1], NULL, 10, &device->weight) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to parse device weight: '%s'"), parts[1]); _("failed to parse device weight: '%s'"), parts[1]);
goto cleanup; return -1;
} }
} else if (STREQ(name, "lxc.cgroup.blkio.throttle.read_bps_device")) { } else if (STREQ(name, "lxc.cgroup.blkio.throttle.read_bps_device")) {
if (virStrToLong_ull(parts[1], NULL, 10, &device->rbps) < 0) { if (virStrToLong_ull(parts[1], NULL, 10, &device->rbps) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to parse read_bps_device: '%s'"), _("failed to parse read_bps_device: '%s'"),
parts[1]); parts[1]);
goto cleanup; return -1;
} }
} else if (STREQ(name, "lxc.cgroup.blkio.throttle.write_bps_device")) { } else if (STREQ(name, "lxc.cgroup.blkio.throttle.write_bps_device")) {
if (virStrToLong_ull(parts[1], NULL, 10, &device->wbps) < 0) { if (virStrToLong_ull(parts[1], NULL, 10, &device->wbps) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to parse write_bps_device: '%s'"), _("failed to parse write_bps_device: '%s'"),
parts[1]); parts[1]);
goto cleanup; return -1;
} }
} else if (STREQ(name, "lxc.cgroup.blkio.throttle.read_iops_device")) { } else if (STREQ(name, "lxc.cgroup.blkio.throttle.read_iops_device")) {
if (virStrToLong_ui(parts[1], NULL, 10, &device->riops) < 0) { if (virStrToLong_ui(parts[1], NULL, 10, &device->riops) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to parse read_iops_device: '%s'"), _("failed to parse read_iops_device: '%s'"),
parts[1]); parts[1]);
goto cleanup; return -1;
} }
} else if (STREQ(name, "lxc.cgroup.blkio.throttle.write_iops_device")) { } else if (STREQ(name, "lxc.cgroup.blkio.throttle.write_iops_device")) {
if (virStrToLong_ui(parts[1], NULL, 10, &device->wiops) < 0) { if (virStrToLong_ui(parts[1], NULL, 10, &device->wiops) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to parse write_iops_device: '%s'"), _("failed to parse write_iops_device: '%s'"),
parts[1]); parts[1]);
goto cleanup; return -1;
} }
} else { } else {
VIR_WARN("Unhandled blkio tune config: %s", name); VIR_WARN("Unhandled blkio tune config: %s", name);
} }
ret = 0; return 0;
cleanup:
return ret;
} }
static int static int

View File

@ -361,7 +361,6 @@ virLXCProcessSetupInterfaceDirect(virLXCDriver *driver,
virDomainDef *def, virDomainDef *def,
virDomainNetDef *net) virDomainNetDef *net)
{ {
char *ret = NULL;
char *res_ifname = NULL; char *res_ifname = NULL;
const virNetDevBandwidth *bw; const virNetDevBandwidth *bw;
const virNetDevVPortProfile *prof; const virNetDevVPortProfile *prof;
@ -407,12 +406,9 @@ virLXCProcessSetupInterfaceDirect(virLXCDriver *driver,
cfg->stateDir, cfg->stateDir,
NULL, 0, NULL, 0,
macvlan_create_flags) < 0) macvlan_create_flags) < 0)
goto cleanup; return NULL;
ret = res_ifname; return res_ifname;
cleanup:
return ret;
} }
static const char *nsInfoLocal[VIR_LXC_DOMAIN_NAMESPACE_LAST] = { static const char *nsInfoLocal[VIR_LXC_DOMAIN_NAMESPACE_LAST] = {
@ -834,7 +830,7 @@ static virLXCMonitor *virLXCProcessConnectMonitor(virLXCDriver *driver,
g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver); g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
if (virSecurityManagerSetSocketLabel(driver->securityManager, vm->def) < 0) if (virSecurityManagerSetSocketLabel(driver->securityManager, vm->def) < 0)
goto cleanup; return NULL;
/* Hold an extra reference because we can't allow 'vm' to be /* Hold an extra reference because we can't allow 'vm' to be
* deleted while the monitor is active. This will be unreffed * deleted while the monitor is active. This will be unreffed
@ -847,14 +843,11 @@ static virLXCMonitor *virLXCProcessConnectMonitor(virLXCDriver *driver,
virObjectUnref(vm); virObjectUnref(vm);
if (virSecurityManagerClearSocketLabel(driver->securityManager, vm->def) < 0) { if (virSecurityManagerClearSocketLabel(driver->securityManager, vm->def) < 0) {
if (monitor) { if (monitor)
virObjectUnref(monitor); virObjectUnref(monitor);
monitor = NULL; return NULL;
}
goto cleanup;
} }
cleanup:
return monitor; return monitor;
} }
@ -1015,7 +1008,7 @@ virLXCProcessBuildControllerCmd(virLXCDriver *driver,
virCommandRequireHandshake(cmd); virCommandRequireHandshake(cmd);
cleanup: cleanup:
return cmd; return cmd;
error: error:
virCommandFree(cmd); virCommandFree(cmd);
cmd = NULL; cmd = NULL;

View File

@ -298,12 +298,12 @@ testBuildCapabilities(virConnectPtr conn)
size_t i, j; size_t i, j;
if ((caps = virCapabilitiesNew(VIR_ARCH_I686, false, false)) == NULL) if ((caps = virCapabilitiesNew(VIR_ARCH_I686, false, false)) == NULL)
goto error; return NULL;
if (virCapabilitiesAddHostFeature(caps, "pae") < 0) if (virCapabilitiesAddHostFeature(caps, "pae") < 0)
goto error; return NULL;
if (virCapabilitiesAddHostFeature(caps, "nonpae") < 0) if (virCapabilitiesAddHostFeature(caps, "nonpae") < 0)
goto error; return NULL;
virCapabilitiesHostInitIOMMU(caps); virCapabilitiesHostInitIOMMU(caps);
@ -362,9 +362,6 @@ testBuildCapabilities(virConnectPtr conn)
caps->host.secModels[0].doi = g_strdup(""); caps->host.secModels[0].doi = g_strdup("");
return g_steal_pointer(&caps); return g_steal_pointer(&caps);
error:
return NULL;
} }

View File

@ -853,10 +853,9 @@ virCgroupSetPartitionSuffix(const char *path, char **res)
{ {
g_auto(GStrv) tokens = NULL; g_auto(GStrv) tokens = NULL;
size_t i; size_t i;
int ret = -1;
if (!(tokens = g_strsplit(path, "/", 0))) if (!(tokens = g_strsplit(path, "/", 0)))
return ret; return -1;
for (i = 0; tokens[i] != NULL; i++) { for (i = 0; tokens[i] != NULL; i++) {
/* Special case the 3 top level fixed dirs /* Special case the 3 top level fixed dirs
@ -878,16 +877,13 @@ virCgroupSetPartitionSuffix(const char *path, char **res)
} }
if (virCgroupPartitionEscape(&(tokens[i])) < 0) if (virCgroupPartitionEscape(&(tokens[i])) < 0)
goto cleanup; return -1;
} }
if (!(*res = g_strjoinv("/", tokens))) if (!(*res = g_strjoinv("/", tokens)))
goto cleanup; return -1;
ret = 0; return 0;
cleanup:
return ret;
} }

View File

@ -58,11 +58,10 @@ virFirmwareFreeList(virFirmware **firmwares, size_t nfirmwares)
int int
virFirmwareParse(const char *str, virFirmware *firmware) virFirmwareParse(const char *str, virFirmware *firmware)
{ {
int ret = -1;
g_auto(GStrv) token = NULL; g_auto(GStrv) token = NULL;
if (!(token = g_strsplit(str, ":", 0))) if (!(token = g_strsplit(str, ":", 0)))
goto cleanup; return -1;
if (token[0]) { if (token[0]) {
virSkipSpaces((const char **) &token[0]); virSkipSpaces((const char **) &token[0]);
@ -76,15 +75,13 @@ virFirmwareParse(const char *str, virFirmware *firmware)
virReportError(VIR_ERR_CONF_SYNTAX, virReportError(VIR_ERR_CONF_SYNTAX,
_("Invalid nvram format: '%s'"), _("Invalid nvram format: '%s'"),
str); str);
goto cleanup; return -1;
} }
firmware->name = g_strdup(token[0]); firmware->name = g_strdup(token[0]);
firmware->nvram = g_strdup(token[1]); firmware->nvram = g_strdup(token[1]);
ret = 0; return 0;
cleanup:
return ret;
} }
@ -93,12 +90,11 @@ virFirmwareParseList(const char *list,
virFirmware ***firmwares, virFirmware ***firmwares,
size_t *nfirmwares) size_t *nfirmwares)
{ {
int ret = -1;
g_auto(GStrv) token = NULL; g_auto(GStrv) token = NULL;
size_t i, j; size_t i, j;
if (!(token = g_strsplit(list, ":", 0))) if (!(token = g_strsplit(list, ":", 0)))
goto cleanup; return -1;
for (i = 0; token[i]; i += 2) { for (i = 0; token[i]; i += 2) {
if (!token[i] || !token[i + 1] || if (!token[i] || !token[i + 1] ||
@ -106,7 +102,7 @@ virFirmwareParseList(const char *list,
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid --with-loader-nvram list: %s"), _("Invalid --with-loader-nvram list: %s"),
list); list);
goto cleanup; return -1;
} }
} }
@ -123,7 +119,5 @@ virFirmwareParseList(const char *list,
} }
} }
ret = 0; return 0;
cleanup:
return ret;
} }

View File

@ -115,32 +115,29 @@ vzBuildCapabilities(void)
return NULL; return NULL;
if (!(caps->host.numa = virCapabilitiesHostNUMANewHost())) if (!(caps->host.numa = virCapabilitiesHostNUMANewHost()))
goto error; return NULL;
if (virCapabilitiesInitCaches(caps) < 0) if (virCapabilitiesInitCaches(caps) < 0)
goto error; return NULL;
for (i = 0; i < G_N_ELEMENTS(ostypes); i++) for (i = 0; i < G_N_ELEMENTS(ostypes); i++)
for (j = 0; j < G_N_ELEMENTS(archs); j++) for (j = 0; j < G_N_ELEMENTS(archs); j++)
for (k = 0; k < G_N_ELEMENTS(emulators); k++) for (k = 0; k < G_N_ELEMENTS(emulators); k++)
if (vzCapsAddGuestDomain(caps, ostypes[i], archs[j], if (vzCapsAddGuestDomain(caps, ostypes[i], archs[j],
emulators[k], virt_types[k]) < 0) emulators[k], virt_types[k]) < 0)
goto error; return NULL;
if (virCapabilitiesGetNodeInfo(&nodeinfo)) if (virCapabilitiesGetNodeInfo(&nodeinfo))
goto error; return NULL;
if (!(caps->host.cpu = virCPUGetHost(caps->host.arch, VIR_CPU_TYPE_HOST, if (!(caps->host.cpu = virCPUGetHost(caps->host.arch, VIR_CPU_TYPE_HOST,
&nodeinfo, NULL))) &nodeinfo, NULL)))
goto error; return NULL;
if (virCapabilitiesAddHostMigrateTransport(caps, "vzmigr") < 0) if (virCapabilitiesAddHostMigrateTransport(caps, "vzmigr") < 0)
goto error; return NULL;
return g_steal_pointer(&caps); return g_steal_pointer(&caps);
error:
return NULL;
} }
static void vzDriverDispose(void * obj) static void vzDriverDispose(void * obj)

View File

@ -94,12 +94,12 @@ testGetCaps(char *capsData, const testQemuData *data)
if ((qemuCaps = testQemuGetCaps(capsData)) == NULL) { if ((qemuCaps = testQemuGetCaps(capsData)) == NULL) {
fprintf(stderr, "failed to parse qemu capabilities flags"); fprintf(stderr, "failed to parse qemu capabilities flags");
goto error; return NULL;
} }
if ((caps = virCapabilitiesNew(arch, false, false)) == NULL) { if ((caps = virCapabilitiesNew(arch, false, false)) == NULL) {
fprintf(stderr, "failed to create the fake capabilities"); fprintf(stderr, "failed to create the fake capabilities");
goto error; return NULL;
} }
if (virQEMUCapsInitGuestFromBinary(caps, if (virQEMUCapsInitGuestFromBinary(caps,
@ -107,13 +107,10 @@ testGetCaps(char *capsData, const testQemuData *data)
qemuCaps, qemuCaps,
arch) < 0) { arch) < 0) {
fprintf(stderr, "failed to create the capabilities from qemu"); fprintf(stderr, "failed to create the capabilities from qemu");
goto error; return NULL;
} }
return g_steal_pointer(&caps); return g_steal_pointer(&caps);
error:
return NULL;
} }
static int static int

View File

@ -21,11 +21,10 @@ testFilterXML(char *xml)
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
g_auto(GStrv) xmlLines = NULL; g_auto(GStrv) xmlLines = NULL;
char **xmlLine; char **xmlLine;
char *ret = NULL;
if (!(xmlLines = g_strsplit(xml, "\n", 0))) { if (!(xmlLines = g_strsplit(xml, "\n", 0))) {
VIR_FREE(xml); VIR_FREE(xml);
goto cleanup; return NULL;
} }
VIR_FREE(xml); VIR_FREE(xml);
@ -36,10 +35,7 @@ testFilterXML(char *xml)
virBufferStrcat(&buf, *xmlLine, "\n", NULL); virBufferStrcat(&buf, *xmlLine, "\n", NULL);
} }
ret = virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
cleanup:
return ret;
} }
static int static int

View File

@ -370,7 +370,6 @@ static int testConfParseStringList(const void *opaque G_GNUC_UNUSED)
"string_list = [\"foo\", \"bar\"]\n" \ "string_list = [\"foo\", \"bar\"]\n" \
"string = \"foo\"\n"; "string = \"foo\"\n";
int ret = -1;
g_autoptr(virConf) conf = virConfReadString(srcdata, 0); g_autoptr(virConf) conf = virConfReadString(srcdata, 0);
g_auto(GStrv) str = NULL; g_auto(GStrv) str = NULL;
@ -380,50 +379,47 @@ static int testConfParseStringList(const void *opaque G_GNUC_UNUSED)
if (virConfGetValueType(conf, "string_list") != if (virConfGetValueType(conf, "string_list") !=
VIR_CONF_LIST) { VIR_CONF_LIST) {
fprintf(stderr, "expected a list for 'string_list'\n"); fprintf(stderr, "expected a list for 'string_list'\n");
goto cleanup; return -1;
} }
if (virConfGetValueStringList(conf, "string_list", false, &str) < 0) if (virConfGetValueStringList(conf, "string_list", false, &str) < 0)
goto cleanup; return -1;
if (!str || g_strv_length(str) != 2) { if (!str || g_strv_length(str) != 2) {
fprintf(stderr, "expected a 2 element list\n"); fprintf(stderr, "expected a 2 element list\n");
goto cleanup; return -1;
} }
if (STRNEQ_NULLABLE(str[0], "foo")) { if (STRNEQ_NULLABLE(str[0], "foo")) {
fprintf(stderr, "Expected 'foo' got '%s'\n", str[0]); fprintf(stderr, "Expected 'foo' got '%s'\n", str[0]);
goto cleanup; return -1;
} }
if (STRNEQ_NULLABLE(str[1], "bar")) { if (STRNEQ_NULLABLE(str[1], "bar")) {
fprintf(stderr, "Expected 'bar' got '%s'\n", str[1]); fprintf(stderr, "Expected 'bar' got '%s'\n", str[1]);
goto cleanup; return -1;
} }
if (virConfGetValueStringList(conf, "string", false, &str) != -1) { if (virConfGetValueStringList(conf, "string", false, &str) != -1) {
fprintf(stderr, "Expected error for 'string'\n"); fprintf(stderr, "Expected error for 'string'\n");
goto cleanup; return -1;
} }
if (virConfGetValueStringList(conf, "string", true, &str) < 0) if (virConfGetValueStringList(conf, "string", true, &str) < 0)
goto cleanup; return -1;
if (!str || g_strv_length(str) != 1) { if (!str || g_strv_length(str) != 1) {
fprintf(stderr, "expected a 1 element list\n"); fprintf(stderr, "expected a 1 element list\n");
goto cleanup; return -1;
} }
if (STRNEQ_NULLABLE(str[0], "foo")) { if (STRNEQ_NULLABLE(str[0], "foo")) {
fprintf(stderr, "Expected 'foo' got '%s'\n", str[0]); fprintf(stderr, "Expected 'foo' got '%s'\n", str[0]);
goto cleanup; return -1;
} }
return 0;
ret = 0;
cleanup:
return ret;
} }

View File

@ -64,7 +64,6 @@ struct testFileGetMountSubtreeData {
static int testFileGetMountSubtree(const void *opaque) static int testFileGetMountSubtree(const void *opaque)
{ {
int ret = -1;
g_auto(GStrv) gotmounts = NULL; g_auto(GStrv) gotmounts = NULL;
size_t gotnmounts = 0; size_t gotnmounts = 0;
const struct testFileGetMountSubtreeData *data = opaque; const struct testFileGetMountSubtreeData *data = opaque;
@ -74,21 +73,18 @@ static int testFileGetMountSubtree(const void *opaque)
data->prefix, data->prefix,
&gotmounts, &gotmounts,
&gotnmounts) < 0) &gotnmounts) < 0)
goto cleanup; return -1;
} else { } else {
if (virFileGetMountSubtree(data->path, if (virFileGetMountSubtree(data->path,
data->prefix, data->prefix,
&gotmounts, &gotmounts,
&gotnmounts) < 0) &gotnmounts) < 0)
goto cleanup; return -1;
} }
ret = testFileCheckMounts(data->prefix, return testFileCheckMounts(data->prefix,
gotmounts, gotnmounts, gotmounts, gotnmounts,
data->mounts, data->nmounts); data->mounts, data->nmounts);
cleanup:
return ret;
} }
#endif /* ! defined WITH_MNTENT_H && defined WITH_GETMNTENT_R */ #endif /* ! defined WITH_MNTENT_H && defined WITH_GETMNTENT_R */

View File

@ -129,7 +129,6 @@ testStringSearch(const void *opaque)
const struct stringSearchData *data = opaque; const struct stringSearchData *data = opaque;
g_auto(GStrv) matches = NULL; g_auto(GStrv) matches = NULL;
ssize_t nmatches; ssize_t nmatches;
int ret = -1;
nmatches = virStringSearch(data->str, data->regexp, nmatches = virStringSearch(data->str, data->regexp,
data->maxMatches, &matches); data->maxMatches, &matches);
@ -138,7 +137,7 @@ testStringSearch(const void *opaque)
if (nmatches != -1) { if (nmatches != -1) {
fprintf(stderr, "expected error on %s but got %zd matches\n", fprintf(stderr, "expected error on %s but got %zd matches\n",
data->str, nmatches); data->str, nmatches);
goto cleanup; return -1;
} }
} else { } else {
size_t i; size_t i;
@ -146,35 +145,32 @@ testStringSearch(const void *opaque)
if (nmatches < 0) { if (nmatches < 0) {
fprintf(stderr, "expected %zu matches on %s but got error\n", fprintf(stderr, "expected %zu matches on %s but got error\n",
data->expectNMatches, data->str); data->expectNMatches, data->str);
goto cleanup; return -1;
} }
if (nmatches != data->expectNMatches) { if (nmatches != data->expectNMatches) {
fprintf(stderr, "expected %zu matches on %s but got %zd\n", fprintf(stderr, "expected %zu matches on %s but got %zd\n",
data->expectNMatches, data->str, nmatches); data->expectNMatches, data->str, nmatches);
goto cleanup; return -1;
} }
if (g_strv_length(matches) != nmatches) { if (g_strv_length(matches) != nmatches) {
fprintf(stderr, "expected %zu matches on %s but got %u matches\n", fprintf(stderr, "expected %zu matches on %s but got %u matches\n",
data->expectNMatches, data->str, data->expectNMatches, data->str,
g_strv_length(matches)); g_strv_length(matches));
goto cleanup; return -1;
} }
for (i = 0; i < nmatches; i++) { for (i = 0; i < nmatches; i++) {
if (STRNEQ(matches[i], data->expectMatches[i])) { if (STRNEQ(matches[i], data->expectMatches[i])) {
fprintf(stderr, "match %zu expected '%s' but got '%s'\n", fprintf(stderr, "match %zu expected '%s' but got '%s'\n",
i, data->expectMatches[i], matches[i]); i, data->expectMatches[i], matches[i]);
goto cleanup; return -1;
} }
} }
} }
ret = 0; return 0;
cleanup:
return ret;
} }