if (argc < 4) {
usage(argv[0]);
- goto out;
+ return EXIT_FAILURE;
}
src_uri = argv[1];
if (!conn) {
fprintf(stderr, "No connection to the source hypervisor: %s.\n",
virGetLastErrorMessage());
- goto out;
+ return EXIT_FAILURE;
}
printf("Attempting to retrieve domain %s...\n", domname);
if (dom != NULL)
virDomainFree(dom);
virConnectClose(conn);
-
- out:
return ret;
}
/* Extract domain name */
if (!(def->name = virXPathString("string(./name[1])", ctxt))) {
virReportError(VIR_ERR_NO_NAME, NULL);
- goto error;
+ return -1;
}
/* Extract domain uuid. If both uuid and sysinfo/system/entry/uuid
if (virUUIDGenerate(def->uuid) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Failed to generate UUID"));
- goto error;
+ return -1;
}
*uuid_generated = true;
} else {
if (virUUIDParse(tmp, def->uuid) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("malformed uuid element"));
- goto error;
+ return -1;
}
VIR_FREE(tmp);
}
/* Extract domain genid - a genid can either be provided or generated */
if ((n = virXPathNodeSet("./genid", ctxt, &nodes)) < 0)
- goto error;
+ return -1;
if (n > 0) {
if (n != 1) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("element 'genid' can only appear once"));
- goto error;
+ return -1;
}
def->genidRequested = true;
if (!(tmp = virXPathString("string(./genid)", ctxt))) {
if (virUUIDGenerate(def->genid) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Failed to generate genid"));
- goto error;
+ return -1;
}
def->genidGenerated = true;
} else {
if (virUUIDParse(tmp, def->genid) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("malformed genid element"));
- goto error;
+ return -1;
}
VIR_FREE(tmp);
}
}
VIR_FREE(nodes);
return 0;
-
- error:
- return -1;
}
/* Extract domain memory */
if (virDomainParseMemory("./memory[1]", NULL, ctxt,
&def->mem.total_memory, false, true) < 0)
- goto error;
+ return -1;
if (virDomainParseMemory("./currentMemory[1]", NULL, ctxt,
&def->mem.cur_balloon, false, true) < 0)
- goto error;
+ return -1;
if (virDomainParseMemory("./maxMemory[1]", NULL, ctxt,
&def->mem.max_memory, false, false) < 0)
- goto error;
+ return -1;
if (virXPathUInt("string(./maxMemory[1]/@slots)", ctxt, &def->mem.memory_slots) == -2) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("Failed to parse memory slot count"));
- goto error;
+ return -1;
}
/* and info about it */
(def->mem.dump_core = virTristateSwitchTypeFromString(tmp)) <= 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Invalid memory core dump attribute value '%s'"), tmp);
- goto error;
+ return -1;
}
VIR_FREE(tmp);
if ((def->mem.source = virDomainMemorySourceTypeFromString(tmp)) <= 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown memoryBacking/source/type '%s'"), tmp);
- goto error;
+ return -1;
}
VIR_FREE(tmp);
}
if ((def->mem.access = virDomainMemoryAccessTypeFromString(tmp)) <= 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown memoryBacking/access/mode '%s'"), tmp);
- goto error;
+ return -1;
}
VIR_FREE(tmp);
}
if ((def->mem.allocation = virDomainMemoryAllocationTypeFromString(tmp)) <= 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown memoryBacking/allocation/mode '%s'"), tmp);
- goto error;
+ return -1;
}
VIR_FREE(tmp);
}
if ((n = virXPathNodeSet("./memoryBacking/hugepages/page", ctxt, &nodes)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot extract hugepages nodes"));
- goto error;
+ return -1;
}
if (n) {
for (i = 0; i < n; i++) {
if (virDomainHugepagesParseXML(nodes[i], ctxt,
&def->mem.hugepages[i]) < 0)
- goto error;
+ return -1;
def->mem.nhugepages++;
}
def->mem.discard = VIR_TRISTATE_BOOL_YES;
return 0;
-
- error:
- return -1;
}
&def->onReboot,
VIR_DOMAIN_LIFECYCLE_ACTION_RESTART,
virDomainLifecycleActionTypeFromString) < 0)
- goto error;
+ return -1;
if (virDomainEventActionParseXML(ctxt, "on_poweroff",
"string(./on_poweroff[1])",
&def->onPoweroff,
VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY,
virDomainLifecycleActionTypeFromString) < 0)
- goto error;
+ return -1;
if (virDomainEventActionParseXML(ctxt, "on_crash",
"string(./on_crash[1])",
&def->onCrash,
VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY,
virDomainLifecycleActionTypeFromString) < 0)
- goto error;
+ return -1;
if (virDomainEventActionParseXML(ctxt, "on_lockfailure",
"string(./on_lockfailure[1])",
&def->onLockFailure,
VIR_DOMAIN_LOCK_FAILURE_DEFAULT,
virDomainLockFailureTypeFromString) < 0)
- goto error;
+ return -1;
if (virDomainPMStateParseXML(ctxt,
"string(./pm/suspend-to-mem/@enabled)",
&def->pm.s3) < 0)
- goto error;
+ return -1;
if (virDomainPMStateParseXML(ctxt,
"string(./pm/suspend-to-disk/@enabled)",
&def->pm.s4) < 0)
- goto error;
+ return -1;
return 0;
-
- error:
- return -1;
}
(def->clock.offset = virDomainClockOffsetTypeFromString(tmp)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown clock offset '%s'"), tmp);
- goto error;
+ return -1;
}
VIR_FREE(tmp);
virReportError(VIR_ERR_XML_ERROR,
_("unknown clock adjustment '%s'"),
tmp);
- goto error;
+ return -1;
}
switch (def->clock.offset) {
case VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME:
if ((def->clock.data.variable.basis = virDomainClockBasisTypeFromString(tmp)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown clock basis '%s'"), tmp);
- goto error;
+ return -1;
}
VIR_FREE(tmp);
} else {
if (!def->clock.data.timezone) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing 'timezone' attribute for clock with offset='timezone'"));
- goto error;
+ return -1;
}
break;
}
if ((n = virXPathNodeSet("./clock/timer", ctxt, &nodes)) < 0)
- goto error;
+ return -1;
if (n)
def->clock.timers = g_new0(virDomainTimerDef *, n);
virDomainTimerDef *timer = virDomainTimerDefParseXML(nodes[i], ctxt);
if (!timer)
- goto error;
+ return -1;
def->clock.timers[def->clock.ntimers++] = timer;
}
VIR_FREE(nodes);
return 0;
-
- error:
- return -1;
}
static int
(virtPort->virtPortType = virNetDevVPortTypeFromString(virtPortType)) <= 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown virtualport type %s"), virtPortType);
- goto error;
+ return NULL;
}
if ((virtPort->virtPortType == VIR_NETDEV_VPORT_PROFILE_NONE) &&
(flags & VIR_VPORT_XML_REQUIRE_TYPE)) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing required virtualport type"));
- goto error;
+ return NULL;
}
while (cur != NULL) {
if (virStrToLong_ui(virtPortManagerID, NULL, 0, &val)) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("cannot parse value of managerid parameter"));
- goto error;
+ return NULL;
}
if (val > 0xff) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("value of managerid out of range"));
- goto error;
+ return NULL;
}
virtPort->managerID = (uint8_t)val;
virtPort->managerID_specified = true;
if (virStrToLong_ui(virtPortTypeID, NULL, 0, &val)) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("cannot parse value of typeid parameter"));
- goto error;
+ return NULL;
}
if (val > 0xffffff) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("value for typeid out of range"));
- goto error;
+ return NULL;
}
virtPort->typeID = (uint32_t)val;
virtPort->typeID_specified = true;
if (virStrToLong_ui(virtPortTypeIDVersion, NULL, 0, &val)) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("cannot parse value of typeidversion parameter"));
- goto error;
+ return NULL;
}
if (val > 0xff) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("value of typeidversion out of range"));
- goto error;
+ return NULL;
}
virtPort->typeIDVersion = (uint8_t)val;
virtPort->typeIDVersion_specified = true;
if (virUUIDParse(virtPortInstanceID, virtPort->instanceID) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("cannot parse instanceid parameter as a uuid"));
- goto error;
+ return NULL;
}
virtPort->instanceID_specified = true;
}
virStrcpyStatic(virtPort->profileID, virtPortProfileID) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("profileid parameter too long"));
- goto error;
+ return NULL;
}
if (virtPortInterfaceID) {
if (virUUIDParse(virtPortInterfaceID, virtPort->interfaceID) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("cannot parse interfaceid parameter as a uuid"));
- goto error;
+ return NULL;
}
virtPort->interfaceID_specified = true;
}
if (virUUIDGenerate(virtPort->instanceID) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot generate a random uuid for instanceid"));
- goto error;
+ return NULL;
}
virtPort->instanceID_specified = true;
}
if (virUUIDGenerate(virtPort->interfaceID) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot generate a random uuid for interfaceid"));
- goto error;
+ return NULL;
}
virtPort->interfaceID_specified = true;
}
if ((flags & VIR_VPORT_XML_REQUIRE_ALL_ATTRIBUTES) &&
(virNetDevVPortProfileCheckComplete(virtPort, false) < 0)) {
- goto error;
+ return NULL;
}
if (virNetDevVPortProfileCheckNoExtras(virtPort) < 0)
- goto error;
+ return NULL;
return g_steal_pointer(&virtPort);
-
- error:
- return NULL;
}
const char *permxpath)
{
long long val;
- int ret = -1;
VIR_XPATH_NODE_AUTORESTORE(ctxt)
xmlNodePtr node;
g_autofree char *mode = NULL;
if (virStrToLong_i(mode, NULL, 8, &tmp) < 0 || (tmp & ~0777)) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("malformed octal mode"));
- goto error;
+ return -1;
}
perms->mode = tmp;
} else {
val != -1)) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("malformed owner element"));
- goto error;
+ return -1;
}
perms->uid = val;
val != -1)) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("malformed group element"));
- goto error;
+ return -1;
}
perms->gid = val;
}
/* NB, we're ignoring missing labels here - they'll simply inherit */
perms->label = virXPathString("string(./label)", ctxt);
-
- ret = 0;
- error:
- return ret;
+ return 0;
}
xmlXPathContextPtr ctxt)
{
VIR_XPATH_NODE_AUTORESTORE(ctxt)
- virStorageAuthDef *ret = NULL;
xmlNodePtr secretnode = NULL;
g_autoptr(virStorageAuthDef) authdef = NULL;
g_autofree char *authtype = NULL;
if (!(authdef->username = virXPathString("string(./@username)", ctxt))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing username for auth"));
- goto cleanup;
+ return NULL;
}
authdef->authType = VIR_STORAGE_AUTH_TYPE_NONE;
if ((authdef->authType = virStorageAuthTypeFromString(authtype)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown auth type '%s'"), authtype);
- goto cleanup;
+ return NULL;
}
}
if (!(secretnode = virXPathNode("./secret ", ctxt))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("Missing <secret> element in auth"));
- goto cleanup;
+ return NULL;
}
/* Used by the domain disk xml parsing in order to ensure the
authdef->secrettype = virXMLPropString(secretnode, "type");
if (virSecretLookupParseSecret(secretnode, &authdef->seclookupdef) < 0)
- goto cleanup;
-
- ret = g_steal_pointer(&authdef);
-
- cleanup:
+ return NULL;
- return ret;
+ return g_steal_pointer(&authdef);
}
*obj = NULL;
- if (!(ctxt->node = virXPathNode("./cookie", ctxt))) {
+ if (!(ctxt->node = virXPathNode("./cookie", ctxt)))
return 0;
- }
return virSaveCookieParseNode(ctxt, obj, saveCookie);
}
if (helperData->usesVFIO &&
STREQ_NULLABLE(actual_drvname, helperData->driverName) &&
STREQ_NULLABLE(actual_domname, helperData->domainName))
- goto iommu_owner;
+ return 0;
if (actual_drvname && actual_domname)
virReportError(VIR_ERR_OPERATION_INVALID,
virPCIDeviceGetName(actual));
return -1;
}
- iommu_owner:
+
return 0;
}
tc->dataFD[0] = -1;
tc->dataFD[1] = -1;
if (virPipe(tc->dataFD) < 0)
- goto out;
+ return -1;
arg = &tc->tmThread;
/* Read from pipe */
name, false, arg) < 0) {
virReportError(errno, "%s",
_("Unable to create tunnel migration thread"));
- goto out;
+ return -1;
}
virObjectUnlock(vm);
ret = libxlDoMigrateSrcSend(driver, vm, flags, tc->dataFD[1]);
virObjectLock(vm);
- out:
/* libxlMigrationSrcStopTunnel will be called in libxlDoMigrateSrcP2P
* to free all resources for us.
*/
int format = virDomainDiskGetFormat(disk);
const char *driver = virDomainDiskGetDriver(disk);
g_autofree char *target = NULL;
- int ret = -1;
/* format */
virBufferAddLit(&buf, "format=");
if (disk->transient) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("transient disks not supported yet"));
- goto cleanup;
+ return -1;
}
/* backendtype */
* it must come last.
*/
if (xenFormatXLDiskSrc(disk->src, &target) < 0)
- goto cleanup;
+ return -1;
if (target)
virBufferAsprintf(&buf, ",target=%s", target);
tmp->next = val;
else
list->list = val;
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
if (openvzDomainSetNetwork(conn, def->name, def->nets[i], &buf) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not configure network"));
- goto exit;
+ return -1;
}
}
}
return 0;
-
- exit:
- return -1;
}
priv->kernelVersion = g_strdup_printf("%s %s", uts.release, uts.version);
priv->cpuData = virCPUDataGetHost();
-
- cleanup:
return cache;
error:
virObjectUnref(cache);
- cache = NULL;
- goto cleanup;
+ return NULL;
}
}
if (!balloonpath)
- goto cleanup;
+ return got;
if (!(cmd = qemuMonitorJSONMakeCommand("qom-get",
"s:path", balloonpath,
"s:property", "guest-stats",
NULL)))
- goto cleanup;
+ return got;
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
- goto cleanup;
+ return got;
if ((data = virJSONValueObjectGetObject(reply, "error"))) {
const char *klass = virJSONValueObjectGetString(data, "class");
STREQ_NULLABLE(desc, "guest hasn't updated any stats yet")) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("the guest hasn't updated any stats yet"));
- goto cleanup;
+ return got;
}
}
if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
- goto cleanup;
+ return got;
data = virJSONValueObjectGetObject(reply, "return");
if (!(statsdata = virJSONValueObjectGet(data, "stats"))) {
VIR_DEBUG("data does not include 'stats'");
- goto cleanup;
+ return got;
}
GET_BALLOON_STATS(statsdata, "stat-swap-in",
GET_BALLOON_STATS(statsdata, "stat-htlb-pgfail",
VIR_DOMAIN_MEMORY_STAT_HUGETLB_PGFAIL, 1);
- ret = got;
- cleanup:
- return ret;
+ return got;
}
#undef GET_BALLOON_STATS
parse_flags |= VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE;
if (qemuDomainSupportsCheckpointsBlockjobs(vm) < 0)
- goto cleanup;
+ return NULL;
if (!vm->persistent && (flags & VIR_DOMAIN_SNAPSHOT_CREATE_HALT)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("cannot halt after transient domain snapshot"));
- goto cleanup;
+ return NULL;
}
if ((flags & VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY) ||
!virDomainObjIsActive(vm))
if (!(def = virDomainSnapshotDefParseString(xmlDesc, driver->xmlopt,
priv->qemuCaps, NULL, parse_flags)))
- goto cleanup;
+ return NULL;
/* reject snapshot names containing slashes or starting with dot as
* snapshot definitions are saved in files named by the snapshot name */
_("invalid snapshot name '%s': "
"name can't contain '/'"),
def->parent.name);
- goto cleanup;
+ return NULL;
}
if (def->parent.name[0] == '.') {
_("invalid snapshot name '%s': "
"name can't start with '.'"),
def->parent.name);
- goto cleanup;
+ return NULL;
}
}
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("live snapshot creation is supported only "
"during full system snapshots"));
- goto cleanup;
+ return NULL;
}
/* allow snapshots only in certain states */
if (!redefine) {
virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid domain state %s"),
virDomainSnapshotStateTypeToString(state));
- goto cleanup;
+ return NULL;
}
break;
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("qemu doesn't support taking snapshots of "
"PMSUSPENDED guests"));
- goto cleanup;
+ return NULL;
/* invalid states */
case VIR_DOMAIN_SNAPSHOT_NOSTATE:
case VIR_DOMAIN_SNAPSHOT_LAST:
virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid domain state %s"),
virDomainSnapshotStateTypeToString(state));
- goto cleanup;
+ return NULL;
}
/* We are going to modify the domain below. Internal snapshots would use
* job mask appropriately. */
if (qemuDomainObjBeginAsyncJob(driver, vm, QEMU_ASYNC_JOB_SNAPSHOT,
VIR_DOMAIN_JOB_OPERATION_SNAPSHOT, flags) < 0)
- goto cleanup;
+ return NULL;
qemuDomainObjSetAsyncJobMask(vm, QEMU_JOB_NONE);
qemuDomainObjEndAsyncJob(driver, vm);
- cleanup:
return snapshot;
}
pid_t pid = (pid_t) -1;
VIR_AUTOCLOSE fd = -1;
VIR_AUTOCLOSE logfd = -1;
- int ret = -1;
int rc;
if (!virFileExists(fs->src->path)) {
}
if (!(pidfile = qemuVirtioFSCreatePidFilename(vm, fs->info.alias)))
- goto cleanup;
+ goto error;
socket_path = qemuDomainGetVHostUserFSSocketPath(vm->privateData, fs);
if ((fd = qemuVirtioFSOpenChardev(driver, vm, socket_path)) < 0)
- goto cleanup;
+ goto error;
logpath = qemuVirtioFSCreateLogFilename(cfg, vm->def, fs->info.alias);
g_autoptr(virLogManager) logManager = virLogManagerNew(driver->privileged);
if (!logManager)
- goto cleanup;
+ goto error;
if ((logfd = virLogManagerDomainOpenLogFile(logManager,
"qemu",
logpath,
0,
NULL, NULL)) < 0)
- goto cleanup;
+ goto error;
} else {
if ((logfd = open(logpath, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR)) < 0) {
virReportSystemError(errno, _("failed to create logfile %s"),
logpath);
- goto cleanup;
+ goto error;
}
if (virSetCloseExec(logfd) < 0) {
virReportSystemError(errno, _("failed to set close-on-exec flag on %s"),
}
if (!(cmd = qemuVirtioFSBuildCommandLine(cfg, fs, &fd)))
- goto cleanup;
+ goto error;
/* so far only running as root is supported */
virCommandSetUID(cmd, 0);
virCommandDaemonize(cmd);
if (qemuExtDeviceLogCommand(driver, vm, cmd, "virtiofsd") < 0)
- goto cleanup;
+ goto error;
rc = virCommandRun(cmd, NULL);
goto error;
}
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
error:
if (pid != -1)
unlink(pidfile);
if (socket_path)
unlink(socket_path);
- goto cleanup;
+ return -1;
}
virNetLibsshAuthMethod *priv,
ssh_key *ret_key)
{
- int err;
int ret;
ssh_key key;
virReportError(VIR_ERR_AUTH_FAILED,
_("error while reading private key '%s'"),
priv->filename);
- err = SSH_AUTH_ERROR;
- goto error;
+ return SSH_AUTH_ERROR;
} else if (ret == SSH_ERROR) {
if (virGetLastErrorCode() == VIR_ERR_OK) {
virReportError(VIR_ERR_AUTH_FAILED,
"passphrase?"),
priv->filename);
}
- err = SSH_AUTH_ERROR;
- goto error;
+ return SSH_AUTH_ERROR;
}
*ret_key = key;
return SSH_AUTH_SUCCESS;
-
- error:
- return err;
}
virStorageBackendISCSIGetHostNumber(const char *sysfs_path,
uint32_t *host)
{
- int ret = -1;
g_autoptr(DIR) sysdir = NULL;
struct dirent *dirent = NULL;
int direrr;
virWaitForDevices();
if (virDirOpen(&sysdir, sysfs_path) < 0)
- goto cleanup;
+ return -1;
while ((direrr = virDirRead(sysdir, &dirent, sysfs_path)) > 0) {
if (STRPREFIX(dirent->d_name, "target")) {
if (sscanf(dirent->d_name, "target%u:", host) == 1) {
- ret = 0;
- goto cleanup;
+ return 0;
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to parse target '%s'"), dirent->d_name);
- goto cleanup;
+ return -1;
}
}
}
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to get host number for iSCSI session "
"with path '%s'"), sysfs_path);
- goto cleanup;
+ return -1;
}
- cleanup:
- return ret;
+ return -1;
}
static int
absFile = testBuildFilename(file, relFile);
if (!(doc = virXMLParse(absFile, NULL, type, NULL, false)))
- goto error;
+ return NULL;
ret = xmlCopyNode(xmlDocGetRootElement(doc), 1);
if (!ret) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Failed to copy XML node"));
- goto error;
+ return NULL;
}
xmlReplaceNode(node, ret);
xmlFreeNode(node);
ret = node;
}
- error:
return ret;
}
if (rc == 0) {
VIR_DEBUG("Path %s does not exist, assuming done", keypath);
- killedAny = false;
- goto done;
+ return 0;
}
while ((direrr = virDirRead(dp, &ent, keypath)) > 0) {
if (direrr < 0)
return -1;
- done:
return killedAny ? 1 : 0;
}
gid_t gid,
int controllers)
{
- int ret = -1;
size_t i;
int direrr;
cgroup->legacy[i].placement);
if (virDirOpen(&dh, base) < 0)
- goto cleanup;
+ return -1;
while ((direrr = virDirRead(dh, &de, base)) > 0) {
g_autofree char *entry = NULL;
virReportSystemError(errno,
_("cannot chown '%s' to (%u, %u)"),
entry, uid, gid);
- goto cleanup;
+ return -1;
}
}
if (direrr < 0)
- goto cleanup;
+ return -1;
if (chown(base, uid, gid) < 0) {
virReportSystemError(errno,
_("cannot chown '%s' to (%u, %u)"),
base, uid, gid);
- goto cleanup;
+ return -1;
}
}
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
}
unsigned long long *inactiveFile,
unsigned long long *unevictable)
{
- int ret = -1;
g_autofree char *stat = NULL;
char *line = NULL;
unsigned long long cacheVal = 0;
if (!valueStr) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Cannot parse 'memory.stat' cgroup file."));
- goto cleanup;
+ return -1;
}
*valueStr = '\0';
if (virStrToLong_ull(valueStr + 1, NULL, 10, &value) < 0)
- goto cleanup;
+ return -1;
if (STREQ(line, "cache"))
cacheVal = value >> 10;
*inactiveFile = inactiveFileVal;
*unevictable = unevictableVal;
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
}
if (!(f = fopen(tmp, "w"))) {
istmp = false;
- if (!(f = fopen(path, "w"))) {
- rc = -errno;
- goto cleanup;
- }
+ if (!(f = fopen(path, "w")))
+ return -errno;
}
for (i = 0; i < nhosts; i++) {
if (istmp)
unlink(tmp);
- goto cleanup;
+ return rc;
}
for (j = 0; j < hosts[i].nhostnames; j++) {
if (istmp)
unlink(tmp);
- goto cleanup;
+ return rc;
}
}
if (istmp)
unlink(tmp);
- goto cleanup;
+ return rc;
}
}
- if (VIR_FCLOSE(f) == EOF) {
- rc = -errno;
- goto cleanup;
- }
+ if (VIR_FCLOSE(f) == EOF)
+ return -errno;
if (istmp && rename(tmp, path) < 0) {
rc = -errno;
unlink(tmp);
- goto cleanup;
+ return rc;
}
- cleanup:
- return rc;
+ return 0;
}
static int
if (!(f = fopen(tmp, "w"))) {
istmp = false;
- if (!(f = fopen(path, "w"))) {
- rc = -errno;
- goto cleanup;
- }
+ if (!(f = fopen(path, "w")))
+ return -errno;
}
for (i = 0; i < nhosts; i++) {
if (istmp)
unlink(tmp);
- goto cleanup;
+ return rc;
}
}
- if (VIR_FCLOSE(f) == EOF) {
- rc = -errno;
- goto cleanup;
- }
+ if (VIR_FCLOSE(f) == EOF)
+ return -errno;
if (istmp && rename(tmp, path) < 0) {
rc = -errno;
unlink(tmp);
- goto cleanup;
+ return rc;
}
- cleanup:
- return rc;
+ return 0;
}
static int
g_autofree long *cpu_times = NULL;
struct clockinfo clkinfo;
size_t i, j, cpu_times_size, clkinfo_size;
- int cpu_times_num, offset, hz, stathz, ret = -1;
+ int cpu_times_num, offset, hz, stathz;
struct field_cpu_map {
const char *field;
int idx[CPUSTATES];
virReportSystemError(errno,
_("sysctl failed for '%s'"),
sysctl_name);
- goto cleanup;
+ return -1;
}
for (i = 0; cpu_map[i].field != NULL; i++) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Field '%s' too long for destination"),
cpu_map[i].field);
- goto cleanup;
+ return -1;
}
param->value = 0;
param->value += cpu_times[offset + cpu_map[i].idx[j]] * TICK_TO_NSEC;
}
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
}
#endif /* __FreeBSD__ */
int ret = 0;
if ((caps = virTestGenericCapsInit()) == NULL)
- goto cleanup;
+ return EXIT_FAILURE;
if (!(xmlopt = virTestGenericDomainXMLConfInit()))
- goto cleanup;
+ return EXIT_FAILURE;
#define DO_TEST_GET_FS(fspath, expect) \
do { \
virObjectUnref(caps);
virObjectUnref(xmlopt);
- cleanup:
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
return NULL;
}
- if (!strchr(name, '+'))
- goto fallback;
-
if (!(volinfo = g_strsplit(name, "+", 2)))
return NULL;
- if (!volinfo[1])
- goto fallback;
+ if (!volinfo[1]) {
+ return virGetStorageVol(pool->conn, pool->name, name, "block", NULL, NULL);
+ }
return virGetStorageVol(pool->conn, pool->name, volinfo[1], volinfo[0],
NULL, NULL);
-
- fallback:
- return virGetStorageVol(pool->conn, pool->name, name, "block", NULL, NULL);
}
static int
return false;
if (vshCommandOptStringReq(ctl, cmd, "file", &to) < 0)
- goto cleanup;
+ return false;
if (vshCommandOptBool(cmd, "verbose"))
verbose = true;
true,
doSave,
&data) < 0)
- goto cleanup;
+ return false;
virshWatchJob(ctl, dom, verbose, eventLoop,
&data.ret, 0, NULL, NULL, _("Save"));
if (!data.ret)
vshPrintExtra(ctl, _("\nDomain '%s' saved to %s\n"), name, to);
- cleanup:
return !data.ret;
}
true,
doManagedsave,
&data) < 0)
- goto cleanup;
+ return false;
virshWatchJob(ctl, dom, verbose, eventLoop,
&data.ret, 0, NULL, NULL, _("Managedsave"));
if (!data.ret)
vshPrintExtra(ctl, _("\nDomain '%s' state saved by libvirt\n"), name);
- cleanup:
return !data.ret;
}
int n;
if (virFileReadAll(xmlFile, VSH_MAX_XML_FILE, &buffer) < 0)
- goto error;
+ return NULL;
/* Strip possible XML declaration */
if (STRPREFIX(buffer, "<?xml") && (doc = strstr(buffer, "?>")))
xmlStr = g_strdup_printf("<container>%s</container>", doc);
if (!(xml = virXMLParseStringCtxt(xmlStr, xmlFile, &ctxt)))
- goto error;
+ return NULL;
n = virXPathNodeSet("/container/cpu|"
"/container/domain/cpu|"
"mode[@name='host-model' and @supported='yes']",
ctxt, &nodes);
if (n < 0)
- goto error;
+ return NULL;
if (n == 0) {
vshError(ctl, _("File '%s' does not contain any <cpu> element or "
"valid domain XML, host capabilities XML, or "
"domain capabilities XML"), xmlFile);
- goto error;
+ return NULL;
}
cpus = g_new0(char *, n + 1);
vshError(ctl,
_("Cannot extract CPU definition from domain "
"capabilities XML"));
- goto error;
+ return NULL;
}
}
}
if (!(cpus[i] = virXMLNodeToString(xml, nodes[i]))) {
vshSaveLibvirtError();
- goto error;
+ return NULL;
}
}
- cleanup:
return g_steal_pointer(&cpus);
-
- error:
- goto cleanup;
}
cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshNodeDevice) dev = NULL;
- bool ret = false;
const char *device_value = NULL;
if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0)
dev = vshFindNodeDevice(ctl, device_value);
if (!dev)
- goto cleanup;
+ return false;
if (virNodeDeviceDestroy(dev) == 0) {
vshPrintExtra(ctl, _("Destroyed node device '%s'\n"), device_value);
} else {
vshError(ctl, _("Failed to destroy node device '%s'"), device_value);
- goto cleanup;
+ return false;
}
- ret = true;
- cleanup:
- return ret;
+ return true;
}
struct virshNodeList {
g_autoptr(virshNodeDevice) device = NULL;
g_autofree char *xml = NULL;
const char *device_value = NULL;
- bool ret = false;
if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0)
return false;
device = vshFindNodeDevice(ctl, device_value);
if (!device)
- goto cleanup;
+ return false;
if (!(xml = virNodeDeviceGetXMLDesc(device, 0)))
- goto cleanup;
+ return false;
vshPrint(ctl, "%s\n", xml);
-
- ret = true;
- cleanup:
- return ret;
+ return true;
}
/*
cmdNodeDeviceUndefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
{
g_autoptr(virshNodeDevice) dev = NULL;
- bool ret = false;
const char *device_value = NULL;
if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0)
dev = vshFindNodeDevice(ctl, device_value);
if (!dev)
- goto cleanup;
+ return false;
if (virNodeDeviceUndefine(dev, 0) < 0) {
vshError(ctl, _("Failed to undefine node device '%s'"), device_value);
- goto cleanup;
+ return false;
}
vshPrintExtra(ctl, _("Undefined node device '%s'\n"), device_value);
- ret = true;
- cleanup:
- return ret;
+ return true;
}
cmdNodeDeviceAutostart(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshNodeDevice) dev = NULL;
- bool ret = false;
const char *name = NULL;
int autostart;
dev = vshFindNodeDevice(ctl, name);
- if (!dev) goto cleanup;
+ if (!dev)
+ return false;
autostart = !vshCommandOptBool(cmd, "disable");
vshError(ctl, _("failed to mark device %s as autostarted"), name);
else
vshError(ctl, _("failed to unmark device %s as autostarted"), name);
- goto cleanup;
+ return false;
}
if (autostart)
else
vshPrintExtra(ctl, _("Device %s unmarked as autostarted\n"), name);
- ret = true;
- cleanup:
- return ret;
+ return true;
}
{
g_autoptr(virshNodeDevice) device = NULL;
const char *device_value = NULL;
- bool ret = false;
int autostart;
const char *parent = NULL;
device = vshFindNodeDevice(ctl, device_value);
if (!device)
- goto cleanup;
+ return false;
parent = virNodeDeviceGetParent(device);
vshPrint(ctl, "%-15s %s\n", _("Name:"), virNodeDeviceGetName(device));
else
vshPrint(ctl, "%-15s %s\n", _("Autostart:"), autostart ? _("yes") : _("no"));
- ret = true;
- cleanup:
- return ret;
+ return true;
}
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
unsigned long flags = 0;
virshControl *priv = ctl->privData;
- bool ret = false;
if (vshCommandOptBool(cmd, "prealloc-metadata"))
flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA;
return false;
if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0)
- goto cleanup;
+ return false;
if (vshCommandOptStringReq(ctl, cmd, "capacity", &capacityStr) < 0)
- goto cleanup;
+ return false;
if (virshVolSize(capacityStr, &capacity) < 0) {
vshError(ctl, _("Malformed size %s"), capacityStr);
- goto cleanup;
+ return false;
}
if (vshCommandOptStringQuiet(ctl, cmd, "allocation", &allocationStr) > 0 &&
virshVolSize(allocationStr, &allocation) < 0) {
vshError(ctl, _("Malformed size %s"), allocationStr);
- goto cleanup;
+ return false;
}
if (vshCommandOptStringReq(ctl, cmd, "format", &format) < 0 ||
vshCommandOptStringReq(ctl, cmd, "backing-vol", &snapshotStrVol) < 0 ||
vshCommandOptStringReq(ctl, cmd, "backing-vol-format",
&snapshotStrFormat) < 0)
- goto cleanup;
+ return false;
virBufferAddLit(&buf, "<volume>\n");
virBufferAdjustIndent(&buf, 2);
}
if (snapVol == NULL) {
vshError(ctl, _("failed to get vol '%s'"), snapshotStrVol);
- goto cleanup;
+ return false;
}
if ((snapshotStrVolPath = virStorageVolGetPath(snapVol)) == NULL) {
- goto cleanup;
+ return false;
}
/* Create XML for the backing store */
} else {
if (!(vol = virStorageVolCreateXML(pool, xml, flags))) {
vshError(ctl, _("Failed to create vol %s"), name);
- goto cleanup;
+ return false;
}
vshPrintExtra(ctl, _("Vol %s created\n"), name);
}
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
/*
g_autoptr(virshStoragePool) pool = NULL;
g_autoptr(virshStorageVol) vol = NULL;
const char *from = NULL;
- bool ret = false;
unsigned int flags = 0;
g_autofree char *buffer = NULL;
return false;
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
- goto cleanup;
+ return false;
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
vshSaveLibvirtError();
- goto cleanup;
+ return false;
}
if (!(vol = virStorageVolCreateXML(pool, buffer, flags))) {
vshError(ctl, _("Failed to create vol from %s"), from);
- goto cleanup;
+ return false;
}
vshPrintExtra(ctl, _("Vol %s created from %s\n"),
virStorageVolGetName(vol), from);
- ret = true;
- cleanup:
- return ret;
+ return true;
}
/*
g_autoptr(virshStorageVol) newvol = NULL;
g_autoptr(virshStorageVol) inputvol = NULL;
const char *from = NULL;
- bool ret = false;
g_autofree char *buffer = NULL;
unsigned int flags = 0;
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", NULL)))
- goto cleanup;
+ return false;
if (vshCommandOptBool(cmd, "prealloc-metadata"))
flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA;
flags |= VIR_STORAGE_VOL_CREATE_REFLINK;
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
- goto cleanup;
+ return false;
if (!(inputvol = virshCommandOptVol(ctl, cmd, "vol", "inputpool", NULL)))
- goto cleanup;
+ return false;
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
vshReportError(ctl);
- goto cleanup;
+ return false;
}
newvol = virStorageVolCreateXMLFrom(pool, buffer, inputvol, flags);
if (!newvol) {
vshError(ctl, _("Failed to create vol from %s"), from);
- goto cleanup;
+ return false;
}
vshPrintExtra(ctl, _("Vol %s created from input vol %s\n"),
virStorageVolGetName(newvol), virStorageVolGetName(inputvol));
- ret = true;
- cleanup:
- return ret;
+ return true;
}
static xmlChar *
{
const char *file = NULL;
g_autoptr(virshStorageVol) vol = NULL;
- bool ret = false;
VIR_AUTOCLOSE fd = -1;
g_autoptr(virshStream) st = NULL;
const char *name = NULL;
return false;
if (vshCommandOptStringReq(ctl, cmd, "file", &file) < 0)
- goto cleanup;
+ return false;
if ((fd = open(file, O_RDONLY)) < 0) {
vshError(ctl, _("cannot read %s"), file);
- goto cleanup;
+ return false;
}
if (fstat(fd, &sb) < 0) {
vshError(ctl, _("unable to stat %s"), file);
- goto cleanup;
+ return false;
}
cbData.ctl = ctl;
if (!(st = virStreamNew(priv->conn, 0))) {
vshError(ctl, _("cannot create a new stream"));
- goto cleanup;
+ return false;
}
if (virStorageVolUpload(vol, st, offset, length, flags) < 0) {
vshError(ctl, _("cannot upload to volume %s"), name);
- goto cleanup;
+ return false;
}
if (flags & VIR_STORAGE_VOL_UPLOAD_SPARSE_STREAM) {
virshStreamInData,
virshStreamSourceSkip, &cbData) < 0) {
vshError(ctl, _("cannot send data to volume %s"), name);
- goto cleanup;
+ return false;
}
} else {
if (virStreamSendAll(st, virshStreamSource, &cbData) < 0) {
vshError(ctl, _("cannot send data to volume %s"), name);
- goto cleanup;
+ return false;
}
}
if (VIR_CLOSE(fd) < 0) {
vshError(ctl, _("cannot close file %s"), file);
virStreamAbort(st);
- goto cleanup;
+ return false;
}
if (virStreamFinish(st) < 0) {
vshError(ctl, _("cannot close volume %s"), name);
- goto cleanup;
+ return false;
}
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
/*
cmdVolWipe(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshStorageVol) vol = NULL;
- bool ret = false;
const char *name;
const char *algorithm_str = NULL;
int algorithm = VIR_STORAGE_VOL_WIPE_ALG_ZERO;
return false;
if (vshCommandOptStringReq(ctl, cmd, "algorithm", &algorithm_str) < 0)
- goto out;
+ return false;
if (algorithm_str &&
(algorithm = virshStorageVolWipeAlgorithmTypeFromString(algorithm_str)) < 0) {
vshError(ctl, _("Unsupported algorithm '%s'"), algorithm_str);
- goto out;
+ return false;
}
if ((funcRet = virStorageVolWipePattern(vol, algorithm, 0)) < 0) {
if (funcRet < 0) {
vshError(ctl, _("Failed to wipe vol %s"), name);
- goto out;
+ return false;
}
vshPrintExtra(ctl, _("Vol %s wiped\n"), name);
- ret = true;
- out:
- return ret;
+ return true;
}
const char *capacityStr = NULL;
unsigned long long capacity = 0;
unsigned int flags = 0;
- bool ret = false;
bool delta = vshCommandOptBool(cmd, "delta");
if (vshCommandOptBool(cmd, "allocate"))
return false;
if (vshCommandOptStringReq(ctl, cmd, "capacity", &capacityStr) < 0)
- goto cleanup;
+ return false;
virSkipSpaces(&capacityStr);
if (*capacityStr == '-') {
/* The API always requires a positive value; but we allow a
} else {
vshError(ctl, "%s",
_("negative size requires --shrink"));
- goto cleanup;
+ return false;
}
}
if (virshVolSize(capacityStr, &capacity) < 0) {
vshError(ctl, _("Malformed size %s"), capacityStr);
- goto cleanup;
+ return false;
}
if (virStorageVolResize(vol, capacity, flags) < 0) {
delta ? _("Failed to change size of volume '%s' by %s")
: _("Failed to change size of volume '%s' to %s"),
virStorageVolGetName(vol), capacityStr);
- goto cleanup;
+ return false;
}
vshPrintExtra(ctl,
delta ? _("Size of volume '%s' successfully changed by %s\n")
: _("Size of volume '%s' successfully changed to %s\n"),
virStorageVolGetName(vol), capacityStr);
- ret = true;
- cleanup:
- return ret;
+ return true;
}
/*