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>
{
struct _bhyveConn *privconn = conn->privateData;
g_autoptr(virCaps) caps = NULL;
- char *xml = NULL;
if (virConnectGetCapabilitiesEnsureACL(conn) < 0)
return NULL;
if (!(caps = bhyveDriverGetCapabilities(privconn))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Unable to get Capabilities"));
- goto cleanup;
+ return NULL;
}
- if (!(xml = virCapabilitiesFormatXML(caps)))
- goto cleanup;
-
- cleanup:
- return xml;
+ return virCapabilitiesFormatXML(caps);
}
static virDomainObj *
const char *nativeConfig,
unsigned int flags)
{
- char *xml = NULL;
g_autoptr(virDomainDef) def = NULL;
struct _bhyveConn *privconn = conn->privateData;
unsigned bhyveCaps = bhyveDriverGetBhyveCaps(privconn);
if (STRNEQ(nativeFormat, BHYVE_CONFIG_FORMAT_ARGV)) {
virReportError(VIR_ERR_INVALID_ARG,
_("unsupported config type %s"), nativeFormat);
- goto cleanup;
+ return NULL;
}
def = bhyveParseCommandLineString(nativeConfig, bhyveCaps,
privconn->xmlopt);
if (def == NULL)
- goto cleanup;
-
- xml = virDomainDefFormat(def, privconn->xmlopt, 0);
+ return NULL;
- cleanup:
- return xml;
+ return virDomainDefFormat(def, privconn->xmlopt, 0);
}
static char *
if ((caps = virCapabilitiesNew(virArchFromHost(),
false, false)) == NULL)
- goto cleanup;
+ return NULL;
if (!(caps->host.numa = virCapabilitiesHostNUMANewHost()))
- goto cleanup;
+ return NULL;
if (virCapabilitiesInitCaches(caps) < 0)
- goto cleanup;
+ return NULL;
guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM,
caps->host.arch, NULL, NULL, 0, NULL);
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_KVM,
NULL, NULL, 0, NULL);
return g_steal_pointer(&caps);
-
- cleanup:
- return NULL;
}
/**
return NULL;
if (hypervLookupHostSystemBiosUuid(priv, caps->host.host_uuid) < 0)
- goto error;
+ return NULL;
/* i686 caps */
guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_I686,
NULL, NULL, 0, NULL);
return g_steal_pointer(&caps);
-
- error:
- return NULL;
}
return NULL;
if (libxlCapsInitHost(ctx, caps) < 0)
- goto error;
+ return NULL;
if (libxlCapsInitNuma(ctx, caps) < 0)
- goto error;
+ return NULL;
if (libxlCapsInitGuests(ctx, caps) < 0)
- goto error;
+ return NULL;
return g_steal_pointer(&caps);
-
- error:
- return NULL;
}
/*
size_t i;
size_t j;
libxl_physinfo physinfo;
- int ret = -1;
if (cfg->verInfo->commandline == NULL ||
!(cmd_tokens = g_strsplit(cfg->verInfo->commandline, " ", 0)))
}
}
*maxmem = *maxmem * multiplier;
- ret = 0;
- goto cleanup;
+ return 0;
}
}
}
libxl_physinfo_init(&physinfo);
if (libxl_get_physinfo(cfg->ctx, &physinfo)) {
VIR_WARN("libxl_get_physinfo failed");
- goto cleanup;
+ return -1;
}
*maxmem = (physinfo.total_pages * cfg->verInfo->pagesize) / 1024;
libxl_physinfo_dispose(&physinfo);
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
}
{
size_t i;
g_auto(GStrv) address_array = NULL;
- char *ret = NULL;
address_array = g_new0(char *, guestIP->nips + 1);
for (i = 0; i < guestIP->nips; i++) {
address_array[i] = virSocketAddrFormat(&guestIP->ips[i]->address);
if (!address_array[i])
- goto cleanup;
+ return NULL;
}
- ret = g_strjoinv(" ", address_array);
-
- cleanup:
- return ret;
+ return g_strjoinv(" ", address_array);
}
static int
g_autofree char *cpuid_str = NULL;
g_auto(GStrv) cpuid_pairs = NULL;
size_t i;
- int ret = -1;
int policy;
if (xenConfigGetString(conf, "cpuid", &cpuid_str, NULL) < 0)
cpuid_pairs = g_strsplit(cpuid_str, ",", 0);
if (!cpuid_pairs)
- goto cleanup;
+ return -1;
- if (!cpuid_pairs[0]) {
- ret = 0;
- goto cleanup;
- }
+ if (!cpuid_pairs[0])
+ return 0;
if (STRNEQ(cpuid_pairs[0], "host")) {
virReportError(VIR_ERR_CONF_SYNTAX,
_("cpuid starting with %s is not supported, only libxl format is"),
cpuid_pairs[0]);
- goto cleanup;
+ return -1;
}
for (i = 1; cpuid_pairs[i]; i++) {
g_auto(GStrv) name_and_value = g_strsplit(cpuid_pairs[i], "=", 2);
if (!name_and_value)
- goto cleanup;
+ return -1;
if (!name_and_value[0] || !name_and_value[1]) {
virReportError(VIR_ERR_CONF_SYNTAX,
_("Invalid libxl cpuid key=value element: %s"),
cpuid_pairs[i]);
- goto cleanup;
+ return -1;
}
if (STREQ(name_and_value[1], "1")) {
policy = VIR_CPU_FEATURE_FORCE;
virReportError(VIR_ERR_CONF_SYNTAX,
_("Invalid libxl cpuid value: %s"),
cpuid_pairs[i]);
- goto cleanup;
+ return -1;
}
if (virCPUDefAddFeature(def->cpu,
xenTranslateCPUFeature(name_and_value[0], true),
policy) < 0)
- goto cleanup;
+ return -1;
}
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
}
g_auto(GStrv) cpuid_pairs = NULL;
g_autofree char *cpuid_string = NULL;
size_t i, j;
- int ret = -1;
if (!def->cpu)
return 0;
cpuid_string = g_strjoinv(",", cpuid_pairs);
if (xenConfigSetString(conf, "cpuid", cpuid_string) < 0)
- goto cleanup;
+ return -1;
}
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
}
static int
if ((caps = virCapabilitiesNew(virArchFromHost(),
false, false)) == NULL)
- goto error;
+ return NULL;
/* Some machines have problematic NUMA topology causing
* unexpected failures. We don't want to break the lxc
* driver in this scenario, so log errors & carry on
*/
if (!(caps->host.numa = virCapabilitiesHostNUMANewHost()))
- goto error;
+ return NULL;
if (virCapabilitiesInitCaches(caps) < 0)
VIR_WARN("Failed to get host CPU cache info");
if (virGetHostUUID(caps->host.host_uuid)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot get the host uuid"));
- goto error;
+ return NULL;
}
if (!(lxc_path = virFileFindResource("libvirt_lxc",
abs_top_builddir "/src",
LIBEXECDIR)))
- goto error;
+ return NULL;
guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_EXE,
caps->host.arch, lxc_path, NULL, 0, NULL);
virCapabilitiesHostSecModelAddBaseLabel(&caps->host.secModels[0],
type,
label) < 0)
- goto error;
+ return NULL;
VIR_DEBUG("Initialized caps for security driver \"%s\" with "
"DOI \"%s\"", model, doi);
}
return g_steal_pointer(&caps);
-
- error:
- return NULL;
}
size_t i;
int saveErrno;
const char *failedUmount = NULL;
- int ret = -1;
VIR_DEBUG("Unmount subtree from %s", prefix);
if (virFileGetMountReverseSubtree("/proc/mounts", prefix,
&mounts, &nmounts) < 0)
- goto cleanup;
+ return -1;
for (i = 0; i < nmounts; i++) {
VIR_DEBUG("Umount %s", mounts[i]);
if (umount(mounts[i]) < 0) {
virReportSystemError(saveErrno,
_("Failed to unmount '%s' and could not detach subtree '%s'"),
failedUmount, mounts[nmounts-1]);
- goto cleanup;
+ return -1;
}
/* This unmounts the tmpfs on which the old root filesystem was hosted */
if (isOldRootFS &&
virReportSystemError(saveErrno,
_("Failed to unmount '%s' and could not unmount old root '%s'"),
failedUmount, mounts[nmounts-1]);
- goto cleanup;
+ return -1;
}
}
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
}
static int lxcContainerResolveSymlinks(virDomainFSDef *fs, bool gentle)
const char *nativeConfig,
unsigned int flags)
{
- char *xml = NULL;
g_autoptr(virDomainDef) def = NULL;
virLXCDriver *driver = conn->privateData;
g_autoptr(virCaps) caps = virLXCDriverGetCapabilities(driver, false);
virCheckFlags(0, NULL);
if (virConnectDomainXMLFromNativeEnsureACL(conn) < 0)
- goto cleanup;
+ return NULL;
if (STRNEQ(nativeFormat, LXC_CONFIG_FORMAT)) {
virReportError(VIR_ERR_INVALID_ARG,
_("unsupported config type %s"), nativeFormat);
- goto cleanup;
+ return NULL;
}
if (!(def = lxcParseConfigString(nativeConfig, caps, driver->xmlopt)))
- goto cleanup;
-
- xml = virDomainDefFormat(def, driver->xmlopt, 0);
+ return NULL;
- cleanup:
- return xml;
+ return virDomainDefFormat(def, driver->xmlopt, 0);
}
/**
}
if (!(parts = g_strsplit(tmp, " ", 0)))
- goto error;
+ return NULL;
/* Append NULL element */
VIR_EXPAND_N(result, ntokens, 1);
}
return g_steal_pointer(&result);
-
- error:
- return NULL;
}
static lxcFstab *
bool readonly;
int type = VIR_DOMAIN_FS_TYPE_MOUNT;
unsigned long long usage = 0;
- int ret = -1;
if (!options)
return -1;
}
/* Check that we don't add basic mounts */
- if (lxcIsBasicMountLocation(dst)) {
- ret = 0;
- goto cleanup;
- }
+ if (lxcIsBasicMountLocation(dst))
+ return 0;
if (STREQ(fstab->type, "tmpfs")) {
char *sizeStr = NULL;
for (i = 0; options[i]; i++) {
if ((sizeStr = STRSKIP(options[i], "size="))) {
if (lxcConvertSize(sizeStr, &usage) < 0)
- goto cleanup;
+ return -1;
break;
}
}
if (!sizeStr) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing tmpfs size, set the size option"));
- goto cleanup;
+ return -1;
}
} else {
src = fstab->src;
readonly = g_strv_contains((const char **)options, "ro");
if (lxcAddFSDef(def, type, src, dst, readonly, usage) < 0)
- goto cleanup;
-
- ret = 1;
+ return -1;
- cleanup:
- return ret;
+ return 1;
}
static int
virDomainDef *def = data;
size_t i = 0;
g_autofree char *path = NULL;
- int ret = -1;
if (!STRPREFIX(name, "lxc.cgroup.blkio.") ||
STREQ(name, "lxc.cgroup.blkio.weight")|| !value->str)
virReportError(VIR_ERR_INTERNAL_ERROR,
_("invalid %s value: '%s'"),
name, value->str);
- goto cleanup;
+ return -1;
}
path = g_strdup_printf("/dev/block/%s", parts[0]);
if (virStrToLong_ui(parts[1], NULL, 10, &device->weight) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to parse device weight: '%s'"), parts[1]);
- goto cleanup;
+ return -1;
}
} else if (STREQ(name, "lxc.cgroup.blkio.throttle.read_bps_device")) {
if (virStrToLong_ull(parts[1], NULL, 10, &device->rbps) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to parse read_bps_device: '%s'"),
parts[1]);
- goto cleanup;
+ return -1;
}
} else if (STREQ(name, "lxc.cgroup.blkio.throttle.write_bps_device")) {
if (virStrToLong_ull(parts[1], NULL, 10, &device->wbps) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to parse write_bps_device: '%s'"),
parts[1]);
- goto cleanup;
+ return -1;
}
} else if (STREQ(name, "lxc.cgroup.blkio.throttle.read_iops_device")) {
if (virStrToLong_ui(parts[1], NULL, 10, &device->riops) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to parse read_iops_device: '%s'"),
parts[1]);
- goto cleanup;
+ return -1;
}
} else if (STREQ(name, "lxc.cgroup.blkio.throttle.write_iops_device")) {
if (virStrToLong_ui(parts[1], NULL, 10, &device->wiops) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to parse write_iops_device: '%s'"),
parts[1]);
- goto cleanup;
+ return -1;
}
} else {
VIR_WARN("Unhandled blkio tune config: %s", name);
}
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
}
static int
virDomainDef *def,
virDomainNetDef *net)
{
- char *ret = NULL;
char *res_ifname = NULL;
const virNetDevBandwidth *bw;
const virNetDevVPortProfile *prof;
cfg->stateDir,
NULL, 0,
macvlan_create_flags) < 0)
- goto cleanup;
-
- ret = res_ifname;
+ return NULL;
- cleanup:
- return ret;
+ return res_ifname;
}
static const char *nsInfoLocal[VIR_LXC_DOMAIN_NAMESPACE_LAST] = {
g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
if (virSecurityManagerSetSocketLabel(driver->securityManager, vm->def) < 0)
- goto cleanup;
+ return NULL;
/* Hold an extra reference because we can't allow 'vm' to be
* deleted while the monitor is active. This will be unreffed
virObjectUnref(vm);
if (virSecurityManagerClearSocketLabel(driver->securityManager, vm->def) < 0) {
- if (monitor) {
+ if (monitor)
virObjectUnref(monitor);
- monitor = NULL;
- }
- goto cleanup;
+ return NULL;
}
- cleanup:
return monitor;
}
virCommandRequireHandshake(cmd);
cleanup:
- return cmd;
+ return cmd;
error:
virCommandFree(cmd);
cmd = NULL;
size_t i, j;
if ((caps = virCapabilitiesNew(VIR_ARCH_I686, false, false)) == NULL)
- goto error;
+ return NULL;
if (virCapabilitiesAddHostFeature(caps, "pae") < 0)
- goto error;
+ return NULL;
if (virCapabilitiesAddHostFeature(caps, "nonpae") < 0)
- goto error;
+ return NULL;
virCapabilitiesHostInitIOMMU(caps);
caps->host.secModels[0].doi = g_strdup("");
return g_steal_pointer(&caps);
-
- error:
- return NULL;
}
{
g_auto(GStrv) tokens = NULL;
size_t i;
- int ret = -1;
if (!(tokens = g_strsplit(path, "/", 0)))
- return ret;
+ return -1;
for (i = 0; tokens[i] != NULL; i++) {
/* Special case the 3 top level fixed dirs
}
if (virCgroupPartitionEscape(&(tokens[i])) < 0)
- goto cleanup;
+ return -1;
}
if (!(*res = g_strjoinv("/", tokens)))
- goto cleanup;
-
- ret = 0;
+ return -1;
- cleanup:
- return ret;
+ return 0;
}
int
virFirmwareParse(const char *str, virFirmware *firmware)
{
- int ret = -1;
g_auto(GStrv) token = NULL;
if (!(token = g_strsplit(str, ":", 0)))
- goto cleanup;
+ return -1;
if (token[0]) {
virSkipSpaces((const char **) &token[0]);
virReportError(VIR_ERR_CONF_SYNTAX,
_("Invalid nvram format: '%s'"),
str);
- goto cleanup;
+ return -1;
}
firmware->name = g_strdup(token[0]);
firmware->nvram = g_strdup(token[1]);
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
virFirmware ***firmwares,
size_t *nfirmwares)
{
- int ret = -1;
g_auto(GStrv) token = NULL;
size_t i, j;
if (!(token = g_strsplit(list, ":", 0)))
- goto cleanup;
+ return -1;
for (i = 0; token[i]; i += 2) {
if (!token[i] || !token[i + 1] ||
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid --with-loader-nvram list: %s"),
list);
- goto cleanup;
+ return -1;
}
}
}
}
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
return NULL;
if (!(caps->host.numa = virCapabilitiesHostNUMANewHost()))
- goto error;
+ return NULL;
if (virCapabilitiesInitCaches(caps) < 0)
- goto error;
+ return NULL;
for (i = 0; i < G_N_ELEMENTS(ostypes); i++)
for (j = 0; j < G_N_ELEMENTS(archs); j++)
for (k = 0; k < G_N_ELEMENTS(emulators); k++)
if (vzCapsAddGuestDomain(caps, ostypes[i], archs[j],
emulators[k], virt_types[k]) < 0)
- goto error;
+ return NULL;
if (virCapabilitiesGetNodeInfo(&nodeinfo))
- goto error;
+ return NULL;
if (!(caps->host.cpu = virCPUGetHost(caps->host.arch, VIR_CPU_TYPE_HOST,
&nodeinfo, NULL)))
- goto error;
+ return NULL;
if (virCapabilitiesAddHostMigrateTransport(caps, "vzmigr") < 0)
- goto error;
+ return NULL;
return g_steal_pointer(&caps);
-
- error:
- return NULL;
}
static void vzDriverDispose(void * obj)
if ((qemuCaps = testQemuGetCaps(capsData)) == NULL) {
fprintf(stderr, "failed to parse qemu capabilities flags");
- goto error;
+ return NULL;
}
if ((caps = virCapabilitiesNew(arch, false, false)) == NULL) {
fprintf(stderr, "failed to create the fake capabilities");
- goto error;
+ return NULL;
}
if (virQEMUCapsInitGuestFromBinary(caps,
qemuCaps,
arch) < 0) {
fprintf(stderr, "failed to create the capabilities from qemu");
- goto error;
+ return NULL;
}
return g_steal_pointer(&caps);
-
- error:
- return NULL;
}
static int
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
g_auto(GStrv) xmlLines = NULL;
char **xmlLine;
- char *ret = NULL;
if (!(xmlLines = g_strsplit(xml, "\n", 0))) {
VIR_FREE(xml);
- goto cleanup;
+ return NULL;
}
VIR_FREE(xml);
virBufferStrcat(&buf, *xmlLine, "\n", NULL);
}
- ret = virBufferContentAndReset(&buf);
-
- cleanup:
- return ret;
+ return virBufferContentAndReset(&buf);
}
static int
"string_list = [\"foo\", \"bar\"]\n" \
"string = \"foo\"\n";
- int ret = -1;
g_autoptr(virConf) conf = virConfReadString(srcdata, 0);
g_auto(GStrv) str = NULL;
if (virConfGetValueType(conf, "string_list") !=
VIR_CONF_LIST) {
fprintf(stderr, "expected a list for 'string_list'\n");
- goto cleanup;
+ return -1;
}
if (virConfGetValueStringList(conf, "string_list", false, &str) < 0)
- goto cleanup;
+ return -1;
if (!str || g_strv_length(str) != 2) {
fprintf(stderr, "expected a 2 element list\n");
- goto cleanup;
+ return -1;
}
if (STRNEQ_NULLABLE(str[0], "foo")) {
fprintf(stderr, "Expected 'foo' got '%s'\n", str[0]);
- goto cleanup;
+ return -1;
}
if (STRNEQ_NULLABLE(str[1], "bar")) {
fprintf(stderr, "Expected 'bar' got '%s'\n", str[1]);
- goto cleanup;
+ return -1;
}
if (virConfGetValueStringList(conf, "string", false, &str) != -1) {
fprintf(stderr, "Expected error for 'string'\n");
- goto cleanup;
+ return -1;
}
if (virConfGetValueStringList(conf, "string", true, &str) < 0)
- goto cleanup;
+ return -1;
if (!str || g_strv_length(str) != 1) {
fprintf(stderr, "expected a 1 element list\n");
- goto cleanup;
+ return -1;
}
if (STRNEQ_NULLABLE(str[0], "foo")) {
fprintf(stderr, "Expected 'foo' got '%s'\n", str[0]);
- goto cleanup;
+ return -1;
}
-
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
static int testFileGetMountSubtree(const void *opaque)
{
- int ret = -1;
g_auto(GStrv) gotmounts = NULL;
size_t gotnmounts = 0;
const struct testFileGetMountSubtreeData *data = opaque;
data->prefix,
&gotmounts,
&gotnmounts) < 0)
- goto cleanup;
+ return -1;
} else {
if (virFileGetMountSubtree(data->path,
data->prefix,
&gotmounts,
&gotnmounts) < 0)
- goto cleanup;
+ return -1;
}
- ret = testFileCheckMounts(data->prefix,
- gotmounts, gotnmounts,
- data->mounts, data->nmounts);
-
- cleanup:
- return ret;
+ return testFileCheckMounts(data->prefix,
+ gotmounts, gotnmounts,
+ data->mounts, data->nmounts);
}
#endif /* ! defined WITH_MNTENT_H && defined WITH_GETMNTENT_R */
const struct stringSearchData *data = opaque;
g_auto(GStrv) matches = NULL;
ssize_t nmatches;
- int ret = -1;
nmatches = virStringSearch(data->str, data->regexp,
data->maxMatches, &matches);
if (nmatches != -1) {
fprintf(stderr, "expected error on %s but got %zd matches\n",
data->str, nmatches);
- goto cleanup;
+ return -1;
}
} else {
size_t i;
if (nmatches < 0) {
fprintf(stderr, "expected %zu matches on %s but got error\n",
data->expectNMatches, data->str);
- goto cleanup;
+ return -1;
}
if (nmatches != data->expectNMatches) {
fprintf(stderr, "expected %zu matches on %s but got %zd\n",
data->expectNMatches, data->str, nmatches);
- goto cleanup;
+ return -1;
}
if (g_strv_length(matches) != nmatches) {
fprintf(stderr, "expected %zu matches on %s but got %u matches\n",
data->expectNMatches, data->str,
g_strv_length(matches));
- goto cleanup;
+ return -1;
}
for (i = 0; i < nmatches; i++) {
if (STRNEQ(matches[i], data->expectMatches[i])) {
fprintf(stderr, "match %zu expected '%s' but got '%s'\n",
i, data->expectMatches[i], matches[i]);
- goto cleanup;
+ return -1;
}
}
}
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
}