lib: Drop needless one line labels

In some cases we have a label that contains nothing but a return
statement. The amount of such labels rises as we use automagic
cleanup. Anyway, such labels are pointless and can be dropped.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
Michal Privoznik 2021-11-04 15:26:07 +01:00
parent 3010a69226
commit 784e9e2b62
27 changed files with 196 additions and 320 deletions

View File

@ -42,7 +42,7 @@ main(int argc, char *argv[])
if (argc < 4) { if (argc < 4) {
usage(argv[0]); usage(argv[0]);
goto out; return EXIT_FAILURE;
} }
src_uri = argv[1]; src_uri = argv[1];
@ -54,7 +54,7 @@ main(int argc, char *argv[])
if (!conn) { if (!conn) {
fprintf(stderr, "No connection to the source hypervisor: %s.\n", fprintf(stderr, "No connection to the source hypervisor: %s.\n",
virGetLastErrorMessage()); virGetLastErrorMessage());
goto out; return EXIT_FAILURE;
} }
printf("Attempting to retrieve domain %s...\n", domname); printf("Attempting to retrieve domain %s...\n", domname);
@ -79,7 +79,5 @@ main(int argc, char *argv[])
if (dom != NULL) if (dom != NULL)
virDomainFree(dom); virDomainFree(dom);
virConnectClose(conn); virConnectClose(conn);
out:
return ret; return ret;
} }

View File

@ -18866,7 +18866,7 @@ virDomainDefParseIDs(virDomainDef *def,
/* Extract domain name */ /* Extract domain name */
if (!(def->name = virXPathString("string(./name[1])", ctxt))) { if (!(def->name = virXPathString("string(./name[1])", ctxt))) {
virReportError(VIR_ERR_NO_NAME, NULL); virReportError(VIR_ERR_NO_NAME, NULL);
goto error; return -1;
} }
/* Extract domain uuid. If both uuid and sysinfo/system/entry/uuid /* Extract domain uuid. If both uuid and sysinfo/system/entry/uuid
@ -18877,50 +18877,47 @@ virDomainDefParseIDs(virDomainDef *def,
if (virUUIDGenerate(def->uuid) < 0) { if (virUUIDGenerate(def->uuid) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Failed to generate UUID")); "%s", _("Failed to generate UUID"));
goto error; return -1;
} }
*uuid_generated = true; *uuid_generated = true;
} else { } else {
if (virUUIDParse(tmp, def->uuid) < 0) { if (virUUIDParse(tmp, def->uuid) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("malformed uuid element")); "%s", _("malformed uuid element"));
goto error; return -1;
} }
VIR_FREE(tmp); VIR_FREE(tmp);
} }
/* Extract domain genid - a genid can either be provided or generated */ /* Extract domain genid - a genid can either be provided or generated */
if ((n = virXPathNodeSet("./genid", ctxt, &nodes)) < 0) if ((n = virXPathNodeSet("./genid", ctxt, &nodes)) < 0)
goto error; return -1;
if (n > 0) { if (n > 0) {
if (n != 1) { if (n != 1) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("element 'genid' can only appear once")); _("element 'genid' can only appear once"));
goto error; return -1;
} }
def->genidRequested = true; def->genidRequested = true;
if (!(tmp = virXPathString("string(./genid)", ctxt))) { if (!(tmp = virXPathString("string(./genid)", ctxt))) {
if (virUUIDGenerate(def->genid) < 0) { if (virUUIDGenerate(def->genid) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Failed to generate genid")); "%s", _("Failed to generate genid"));
goto error; return -1;
} }
def->genidGenerated = true; def->genidGenerated = true;
} else { } else {
if (virUUIDParse(tmp, def->genid) < 0) { if (virUUIDParse(tmp, def->genid) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("malformed genid element")); "%s", _("malformed genid element"));
goto error; return -1;
} }
VIR_FREE(tmp); VIR_FREE(tmp);
} }
} }
VIR_FREE(nodes); VIR_FREE(nodes);
return 0; return 0;
error:
return -1;
} }
@ -19009,20 +19006,20 @@ virDomainDefParseMemory(virDomainDef *def,
/* Extract domain memory */ /* Extract domain memory */
if (virDomainParseMemory("./memory[1]", NULL, ctxt, if (virDomainParseMemory("./memory[1]", NULL, ctxt,
&def->mem.total_memory, false, true) < 0) &def->mem.total_memory, false, true) < 0)
goto error; return -1;
if (virDomainParseMemory("./currentMemory[1]", NULL, ctxt, if (virDomainParseMemory("./currentMemory[1]", NULL, ctxt,
&def->mem.cur_balloon, false, true) < 0) &def->mem.cur_balloon, false, true) < 0)
goto error; return -1;
if (virDomainParseMemory("./maxMemory[1]", NULL, ctxt, if (virDomainParseMemory("./maxMemory[1]", NULL, ctxt,
&def->mem.max_memory, false, false) < 0) &def->mem.max_memory, false, false) < 0)
goto error; return -1;
if (virXPathUInt("string(./maxMemory[1]/@slots)", ctxt, &def->mem.memory_slots) == -2) { if (virXPathUInt("string(./maxMemory[1]/@slots)", ctxt, &def->mem.memory_slots) == -2) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("Failed to parse memory slot count")); _("Failed to parse memory slot count"));
goto error; return -1;
} }
/* and info about it */ /* and info about it */
@ -19030,7 +19027,7 @@ virDomainDefParseMemory(virDomainDef *def,
(def->mem.dump_core = virTristateSwitchTypeFromString(tmp)) <= 0) { (def->mem.dump_core = virTristateSwitchTypeFromString(tmp)) <= 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Invalid memory core dump attribute value '%s'"), tmp); _("Invalid memory core dump attribute value '%s'"), tmp);
goto error; return -1;
} }
VIR_FREE(tmp); VIR_FREE(tmp);
@ -19039,7 +19036,7 @@ virDomainDefParseMemory(virDomainDef *def,
if ((def->mem.source = virDomainMemorySourceTypeFromString(tmp)) <= 0) { if ((def->mem.source = virDomainMemorySourceTypeFromString(tmp)) <= 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown memoryBacking/source/type '%s'"), tmp); _("unknown memoryBacking/source/type '%s'"), tmp);
goto error; return -1;
} }
VIR_FREE(tmp); VIR_FREE(tmp);
} }
@ -19049,7 +19046,7 @@ virDomainDefParseMemory(virDomainDef *def,
if ((def->mem.access = virDomainMemoryAccessTypeFromString(tmp)) <= 0) { if ((def->mem.access = virDomainMemoryAccessTypeFromString(tmp)) <= 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown memoryBacking/access/mode '%s'"), tmp); _("unknown memoryBacking/access/mode '%s'"), tmp);
goto error; return -1;
} }
VIR_FREE(tmp); VIR_FREE(tmp);
} }
@ -19059,7 +19056,7 @@ virDomainDefParseMemory(virDomainDef *def,
if ((def->mem.allocation = virDomainMemoryAllocationTypeFromString(tmp)) <= 0) { if ((def->mem.allocation = virDomainMemoryAllocationTypeFromString(tmp)) <= 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown memoryBacking/allocation/mode '%s'"), tmp); _("unknown memoryBacking/allocation/mode '%s'"), tmp);
goto error; return -1;
} }
VIR_FREE(tmp); VIR_FREE(tmp);
} }
@ -19069,7 +19066,7 @@ virDomainDefParseMemory(virDomainDef *def,
if ((n = virXPathNodeSet("./memoryBacking/hugepages/page", ctxt, &nodes)) < 0) { if ((n = virXPathNodeSet("./memoryBacking/hugepages/page", ctxt, &nodes)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot extract hugepages nodes")); _("cannot extract hugepages nodes"));
goto error; return -1;
} }
if (n) { if (n) {
@ -19078,7 +19075,7 @@ virDomainDefParseMemory(virDomainDef *def,
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if (virDomainHugepagesParseXML(nodes[i], ctxt, if (virDomainHugepagesParseXML(nodes[i], ctxt,
&def->mem.hugepages[i]) < 0) &def->mem.hugepages[i]) < 0)
goto error; return -1;
def->mem.nhugepages++; def->mem.nhugepages++;
} }
@ -19100,9 +19097,6 @@ virDomainDefParseMemory(virDomainDef *def,
def->mem.discard = VIR_TRISTATE_BOOL_YES; def->mem.discard = VIR_TRISTATE_BOOL_YES;
return 0; return 0;
error:
return -1;
} }
@ -19453,43 +19447,40 @@ virDomainDefLifecycleParse(virDomainDef *def,
&def->onReboot, &def->onReboot,
VIR_DOMAIN_LIFECYCLE_ACTION_RESTART, VIR_DOMAIN_LIFECYCLE_ACTION_RESTART,
virDomainLifecycleActionTypeFromString) < 0) virDomainLifecycleActionTypeFromString) < 0)
goto error; return -1;
if (virDomainEventActionParseXML(ctxt, "on_poweroff", if (virDomainEventActionParseXML(ctxt, "on_poweroff",
"string(./on_poweroff[1])", "string(./on_poweroff[1])",
&def->onPoweroff, &def->onPoweroff,
VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY, VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY,
virDomainLifecycleActionTypeFromString) < 0) virDomainLifecycleActionTypeFromString) < 0)
goto error; return -1;
if (virDomainEventActionParseXML(ctxt, "on_crash", if (virDomainEventActionParseXML(ctxt, "on_crash",
"string(./on_crash[1])", "string(./on_crash[1])",
&def->onCrash, &def->onCrash,
VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY, VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY,
virDomainLifecycleActionTypeFromString) < 0) virDomainLifecycleActionTypeFromString) < 0)
goto error; return -1;
if (virDomainEventActionParseXML(ctxt, "on_lockfailure", if (virDomainEventActionParseXML(ctxt, "on_lockfailure",
"string(./on_lockfailure[1])", "string(./on_lockfailure[1])",
&def->onLockFailure, &def->onLockFailure,
VIR_DOMAIN_LOCK_FAILURE_DEFAULT, VIR_DOMAIN_LOCK_FAILURE_DEFAULT,
virDomainLockFailureTypeFromString) < 0) virDomainLockFailureTypeFromString) < 0)
goto error; return -1;
if (virDomainPMStateParseXML(ctxt, if (virDomainPMStateParseXML(ctxt,
"string(./pm/suspend-to-mem/@enabled)", "string(./pm/suspend-to-mem/@enabled)",
&def->pm.s3) < 0) &def->pm.s3) < 0)
goto error; return -1;
if (virDomainPMStateParseXML(ctxt, if (virDomainPMStateParseXML(ctxt,
"string(./pm/suspend-to-disk/@enabled)", "string(./pm/suspend-to-disk/@enabled)",
&def->pm.s4) < 0) &def->pm.s4) < 0)
goto error; return -1;
return 0; return 0;
error:
return -1;
} }
@ -19506,7 +19497,7 @@ virDomainDefClockParse(virDomainDef *def,
(def->clock.offset = virDomainClockOffsetTypeFromString(tmp)) < 0) { (def->clock.offset = virDomainClockOffsetTypeFromString(tmp)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown clock offset '%s'"), tmp); _("unknown clock offset '%s'"), tmp);
goto error; return -1;
} }
VIR_FREE(tmp); VIR_FREE(tmp);
@ -19523,7 +19514,7 @@ virDomainDefClockParse(virDomainDef *def,
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR,
_("unknown clock adjustment '%s'"), _("unknown clock adjustment '%s'"),
tmp); tmp);
goto error; return -1;
} }
switch (def->clock.offset) { switch (def->clock.offset) {
case VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME: case VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME:
@ -19553,7 +19544,7 @@ virDomainDefClockParse(virDomainDef *def,
if ((def->clock.data.variable.basis = virDomainClockBasisTypeFromString(tmp)) < 0) { if ((def->clock.data.variable.basis = virDomainClockBasisTypeFromString(tmp)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown clock basis '%s'"), tmp); _("unknown clock basis '%s'"), tmp);
goto error; return -1;
} }
VIR_FREE(tmp); VIR_FREE(tmp);
} else { } else {
@ -19566,13 +19557,13 @@ virDomainDefClockParse(virDomainDef *def,
if (!def->clock.data.timezone) { if (!def->clock.data.timezone) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing 'timezone' attribute for clock with offset='timezone'")); _("missing 'timezone' attribute for clock with offset='timezone'"));
goto error; return -1;
} }
break; break;
} }
if ((n = virXPathNodeSet("./clock/timer", ctxt, &nodes)) < 0) if ((n = virXPathNodeSet("./clock/timer", ctxt, &nodes)) < 0)
goto error; return -1;
if (n) if (n)
def->clock.timers = g_new0(virDomainTimerDef *, n); def->clock.timers = g_new0(virDomainTimerDef *, n);
@ -19581,16 +19572,13 @@ virDomainDefClockParse(virDomainDef *def,
virDomainTimerDef *timer = virDomainTimerDefParseXML(nodes[i], ctxt); virDomainTimerDef *timer = virDomainTimerDefParseXML(nodes[i], ctxt);
if (!timer) if (!timer)
goto error; return -1;
def->clock.timers[def->clock.ntimers++] = timer; def->clock.timers[def->clock.ntimers++] = timer;
} }
VIR_FREE(nodes); VIR_FREE(nodes);
return 0; return 0;
error:
return -1;
} }
static int static int

View File

@ -45,14 +45,14 @@ virNetDevVPortProfileParse(xmlNodePtr node, unsigned int flags)
(virtPort->virtPortType = virNetDevVPortTypeFromString(virtPortType)) <= 0) { (virtPort->virtPortType = virNetDevVPortTypeFromString(virtPortType)) <= 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown virtualport type %s"), virtPortType); _("unknown virtualport type %s"), virtPortType);
goto error; return NULL;
} }
if ((virtPort->virtPortType == VIR_NETDEV_VPORT_PROFILE_NONE) && if ((virtPort->virtPortType == VIR_NETDEV_VPORT_PROFILE_NONE) &&
(flags & VIR_VPORT_XML_REQUIRE_TYPE)) { (flags & VIR_VPORT_XML_REQUIRE_TYPE)) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing required virtualport type")); _("missing required virtualport type"));
goto error; return NULL;
} }
while (cur != NULL) { while (cur != NULL) {
@ -74,12 +74,12 @@ virNetDevVPortProfileParse(xmlNodePtr node, unsigned int flags)
if (virStrToLong_ui(virtPortManagerID, NULL, 0, &val)) { if (virStrToLong_ui(virtPortManagerID, NULL, 0, &val)) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("cannot parse value of managerid parameter")); _("cannot parse value of managerid parameter"));
goto error; return NULL;
} }
if (val > 0xff) { if (val > 0xff) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("value of managerid out of range")); _("value of managerid out of range"));
goto error; return NULL;
} }
virtPort->managerID = (uint8_t)val; virtPort->managerID = (uint8_t)val;
virtPort->managerID_specified = true; virtPort->managerID_specified = true;
@ -91,12 +91,12 @@ virNetDevVPortProfileParse(xmlNodePtr node, unsigned int flags)
if (virStrToLong_ui(virtPortTypeID, NULL, 0, &val)) { if (virStrToLong_ui(virtPortTypeID, NULL, 0, &val)) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("cannot parse value of typeid parameter")); _("cannot parse value of typeid parameter"));
goto error; return NULL;
} }
if (val > 0xffffff) { if (val > 0xffffff) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("value for typeid out of range")); _("value for typeid out of range"));
goto error; return NULL;
} }
virtPort->typeID = (uint32_t)val; virtPort->typeID = (uint32_t)val;
virtPort->typeID_specified = true; virtPort->typeID_specified = true;
@ -108,12 +108,12 @@ virNetDevVPortProfileParse(xmlNodePtr node, unsigned int flags)
if (virStrToLong_ui(virtPortTypeIDVersion, NULL, 0, &val)) { if (virStrToLong_ui(virtPortTypeIDVersion, NULL, 0, &val)) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("cannot parse value of typeidversion parameter")); _("cannot parse value of typeidversion parameter"));
goto error; return NULL;
} }
if (val > 0xff) { if (val > 0xff) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("value of typeidversion out of range")); _("value of typeidversion out of range"));
goto error; return NULL;
} }
virtPort->typeIDVersion = (uint8_t)val; virtPort->typeIDVersion = (uint8_t)val;
virtPort->typeIDVersion_specified = true; virtPort->typeIDVersion_specified = true;
@ -123,7 +123,7 @@ virNetDevVPortProfileParse(xmlNodePtr node, unsigned int flags)
if (virUUIDParse(virtPortInstanceID, virtPort->instanceID) < 0) { if (virUUIDParse(virtPortInstanceID, virtPort->instanceID) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("cannot parse instanceid parameter as a uuid")); _("cannot parse instanceid parameter as a uuid"));
goto error; return NULL;
} }
virtPort->instanceID_specified = true; virtPort->instanceID_specified = true;
} }
@ -132,14 +132,14 @@ virNetDevVPortProfileParse(xmlNodePtr node, unsigned int flags)
virStrcpyStatic(virtPort->profileID, virtPortProfileID) < 0) { virStrcpyStatic(virtPort->profileID, virtPortProfileID) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("profileid parameter too long")); _("profileid parameter too long"));
goto error; return NULL;
} }
if (virtPortInterfaceID) { if (virtPortInterfaceID) {
if (virUUIDParse(virtPortInterfaceID, virtPort->interfaceID) < 0) { if (virUUIDParse(virtPortInterfaceID, virtPort->interfaceID) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("cannot parse interfaceid parameter as a uuid")); _("cannot parse interfaceid parameter as a uuid"));
goto error; return NULL;
} }
virtPort->interfaceID_specified = true; virtPort->interfaceID_specified = true;
} }
@ -152,7 +152,7 @@ virNetDevVPortProfileParse(xmlNodePtr node, unsigned int flags)
if (virUUIDGenerate(virtPort->instanceID) < 0) { if (virUUIDGenerate(virtPort->instanceID) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot generate a random uuid for instanceid")); _("cannot generate a random uuid for instanceid"));
goto error; return NULL;
} }
virtPort->instanceID_specified = true; virtPort->instanceID_specified = true;
} }
@ -162,7 +162,7 @@ virNetDevVPortProfileParse(xmlNodePtr node, unsigned int flags)
if (virUUIDGenerate(virtPort->interfaceID) < 0) { if (virUUIDGenerate(virtPort->interfaceID) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot generate a random uuid for interfaceid")); _("cannot generate a random uuid for interfaceid"));
goto error; return NULL;
} }
virtPort->interfaceID_specified = true; virtPort->interfaceID_specified = true;
} }
@ -172,16 +172,13 @@ virNetDevVPortProfileParse(xmlNodePtr node, unsigned int flags)
if ((flags & VIR_VPORT_XML_REQUIRE_ALL_ATTRIBUTES) && if ((flags & VIR_VPORT_XML_REQUIRE_ALL_ATTRIBUTES) &&
(virNetDevVPortProfileCheckComplete(virtPort, false) < 0)) { (virNetDevVPortProfileCheckComplete(virtPort, false) < 0)) {
goto error; return NULL;
} }
if (virNetDevVPortProfileCheckNoExtras(virtPort) < 0) if (virNetDevVPortProfileCheckNoExtras(virtPort) < 0)
goto error; return NULL;
return g_steal_pointer(&virtPort); return g_steal_pointer(&virtPort);
error:
return NULL;
} }

View File

@ -692,7 +692,6 @@ virStorageDefParsePerms(xmlXPathContextPtr ctxt,
const char *permxpath) const char *permxpath)
{ {
long long val; long long val;
int ret = -1;
VIR_XPATH_NODE_AUTORESTORE(ctxt) VIR_XPATH_NODE_AUTORESTORE(ctxt)
xmlNodePtr node; xmlNodePtr node;
g_autofree char *mode = NULL; g_autofree char *mode = NULL;
@ -715,7 +714,7 @@ virStorageDefParsePerms(xmlXPathContextPtr ctxt,
if (virStrToLong_i(mode, NULL, 8, &tmp) < 0 || (tmp & ~0777)) { if (virStrToLong_i(mode, NULL, 8, &tmp) < 0 || (tmp & ~0777)) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("malformed octal mode")); _("malformed octal mode"));
goto error; return -1;
} }
perms->mode = tmp; perms->mode = tmp;
} else { } else {
@ -731,7 +730,7 @@ virStorageDefParsePerms(xmlXPathContextPtr ctxt,
val != -1)) { val != -1)) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("malformed owner element")); _("malformed owner element"));
goto error; return -1;
} }
perms->uid = val; perms->uid = val;
@ -746,17 +745,14 @@ virStorageDefParsePerms(xmlXPathContextPtr ctxt,
val != -1)) { val != -1)) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("malformed group element")); _("malformed group element"));
goto error; return -1;
} }
perms->gid = val; perms->gid = val;
} }
/* NB, we're ignoring missing labels here - they'll simply inherit */ /* NB, we're ignoring missing labels here - they'll simply inherit */
perms->label = virXPathString("string(./label)", ctxt); perms->label = virXPathString("string(./label)", ctxt);
return 0;
ret = 0;
error:
return ret;
} }

View File

@ -235,7 +235,6 @@ virStorageAuthDefParse(xmlNodePtr node,
xmlXPathContextPtr ctxt) xmlXPathContextPtr ctxt)
{ {
VIR_XPATH_NODE_AUTORESTORE(ctxt) VIR_XPATH_NODE_AUTORESTORE(ctxt)
virStorageAuthDef *ret = NULL;
xmlNodePtr secretnode = NULL; xmlNodePtr secretnode = NULL;
g_autoptr(virStorageAuthDef) authdef = NULL; g_autoptr(virStorageAuthDef) authdef = NULL;
g_autofree char *authtype = NULL; g_autofree char *authtype = NULL;
@ -247,7 +246,7 @@ virStorageAuthDefParse(xmlNodePtr node,
if (!(authdef->username = virXPathString("string(./@username)", ctxt))) { if (!(authdef->username = virXPathString("string(./@username)", ctxt))) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing username for auth")); _("missing username for auth"));
goto cleanup; return NULL;
} }
authdef->authType = VIR_STORAGE_AUTH_TYPE_NONE; authdef->authType = VIR_STORAGE_AUTH_TYPE_NONE;
@ -259,14 +258,14 @@ virStorageAuthDefParse(xmlNodePtr node,
if ((authdef->authType = virStorageAuthTypeFromString(authtype)) < 0) { if ((authdef->authType = virStorageAuthTypeFromString(authtype)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown auth type '%s'"), authtype); _("unknown auth type '%s'"), authtype);
goto cleanup; return NULL;
} }
} }
if (!(secretnode = virXPathNode("./secret ", ctxt))) { if (!(secretnode = virXPathNode("./secret ", ctxt))) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("Missing <secret> element in auth")); _("Missing <secret> element in auth"));
goto cleanup; return NULL;
} }
/* Used by the domain disk xml parsing in order to ensure the /* Used by the domain disk xml parsing in order to ensure the
@ -279,13 +278,9 @@ virStorageAuthDefParse(xmlNodePtr node,
authdef->secrettype = virXMLPropString(secretnode, "type"); authdef->secrettype = virXMLPropString(secretnode, "type");
if (virSecretLookupParseSecret(secretnode, &authdef->seclookupdef) < 0) if (virSecretLookupParseSecret(secretnode, &authdef->seclookupdef) < 0)
goto cleanup; return NULL;
ret = g_steal_pointer(&authdef); return g_steal_pointer(&authdef);
cleanup:
return ret;
} }

View File

@ -61,9 +61,8 @@ virSaveCookieParse(xmlXPathContextPtr ctxt,
*obj = NULL; *obj = NULL;
if (!(ctxt->node = virXPathNode("./cookie", ctxt))) { if (!(ctxt->node = virXPathNode("./cookie", ctxt)))
return 0; return 0;
}
return virSaveCookieParseNode(ctxt, obj, saveCookie); return virSaveCookieParseNode(ctxt, obj, saveCookie);
} }

View File

@ -92,7 +92,7 @@ static int virHostdevIsPCINodeDeviceUsed(virPCIDeviceAddress *devAddr, void *opa
if (helperData->usesVFIO && if (helperData->usesVFIO &&
STREQ_NULLABLE(actual_drvname, helperData->driverName) && STREQ_NULLABLE(actual_drvname, helperData->driverName) &&
STREQ_NULLABLE(actual_domname, helperData->domainName)) STREQ_NULLABLE(actual_domname, helperData->domainName))
goto iommu_owner; return 0;
if (actual_drvname && actual_domname) if (actual_drvname && actual_domname)
virReportError(VIR_ERR_OPERATION_INVALID, virReportError(VIR_ERR_OPERATION_INVALID,
@ -106,7 +106,7 @@ static int virHostdevIsPCINodeDeviceUsed(virPCIDeviceAddress *devAddr, void *opa
virPCIDeviceGetName(actual)); virPCIDeviceGetName(actual));
return -1; return -1;
} }
iommu_owner:
return 0; return 0;
} }

View File

@ -902,7 +902,7 @@ libxlMigrationSrcStartTunnel(libxlDriverPrivate *driver,
tc->dataFD[0] = -1; tc->dataFD[0] = -1;
tc->dataFD[1] = -1; tc->dataFD[1] = -1;
if (virPipe(tc->dataFD) < 0) if (virPipe(tc->dataFD) < 0)
goto out; return -1;
arg = &tc->tmThread; arg = &tc->tmThread;
/* Read from pipe */ /* Read from pipe */
@ -915,7 +915,7 @@ libxlMigrationSrcStartTunnel(libxlDriverPrivate *driver,
name, false, arg) < 0) { name, false, arg) < 0) {
virReportError(errno, "%s", virReportError(errno, "%s",
_("Unable to create tunnel migration thread")); _("Unable to create tunnel migration thread"));
goto out; return -1;
} }
virObjectUnlock(vm); virObjectUnlock(vm);
@ -923,7 +923,6 @@ libxlMigrationSrcStartTunnel(libxlDriverPrivate *driver,
ret = libxlDoMigrateSrcSend(driver, vm, flags, tc->dataFD[1]); ret = libxlDoMigrateSrcSend(driver, vm, flags, tc->dataFD[1]);
virObjectLock(vm); virObjectLock(vm);
out:
/* libxlMigrationSrcStopTunnel will be called in libxlDoMigrateSrcP2P /* libxlMigrationSrcStopTunnel will be called in libxlDoMigrateSrcP2P
* to free all resources for us. * to free all resources for us.
*/ */

View File

@ -1607,7 +1607,6 @@ xenFormatXLDisk(virConfValue *list, virDomainDiskDef *disk)
int format = virDomainDiskGetFormat(disk); int format = virDomainDiskGetFormat(disk);
const char *driver = virDomainDiskGetDriver(disk); const char *driver = virDomainDiskGetDriver(disk);
g_autofree char *target = NULL; g_autofree char *target = NULL;
int ret = -1;
/* format */ /* format */
virBufferAddLit(&buf, "format="); virBufferAddLit(&buf, "format=");
@ -1646,7 +1645,7 @@ xenFormatXLDisk(virConfValue *list, virDomainDiskDef *disk)
if (disk->transient) { if (disk->transient) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("transient disks not supported yet")); _("transient disks not supported yet"));
goto cleanup; return -1;
} }
/* backendtype */ /* backendtype */
@ -1673,7 +1672,7 @@ xenFormatXLDisk(virConfValue *list, virDomainDiskDef *disk)
* it must come last. * it must come last.
*/ */
if (xenFormatXLDiskSrc(disk->src, &target) < 0) if (xenFormatXLDiskSrc(disk->src, &target) < 0)
goto cleanup; return -1;
if (target) if (target)
virBufferAsprintf(&buf, ",target=%s", target); virBufferAsprintf(&buf, ",target=%s", target);
@ -1689,10 +1688,8 @@ xenFormatXLDisk(virConfValue *list, virDomainDiskDef *disk)
tmp->next = val; tmp->next = val;
else else
list->list = val; list->list = val;
ret = 0;
cleanup: return 0;
return ret;
} }

View File

@ -799,7 +799,7 @@ openvzDomainSetNetworkConfig(virConnectPtr conn,
if (openvzDomainSetNetwork(conn, def->name, def->nets[i], &buf) < 0) { if (openvzDomainSetNetwork(conn, def->name, def->nets[i], &buf) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not configure network")); _("Could not configure network"));
goto exit; return -1;
} }
} }
@ -817,9 +817,6 @@ openvzDomainSetNetworkConfig(virConnectPtr conn,
} }
return 0; return 0;
exit:
return -1;
} }

View File

@ -5618,14 +5618,11 @@ virQEMUCapsCacheNew(const char *libDir,
priv->kernelVersion = g_strdup_printf("%s %s", uts.release, uts.version); priv->kernelVersion = g_strdup_printf("%s %s", uts.release, uts.version);
priv->cpuData = virCPUDataGetHost(); priv->cpuData = virCPUDataGetHost();
cleanup:
return cache; return cache;
error: error:
virObjectUnref(cache); virObjectUnref(cache);
cache = NULL; return NULL;
goto cleanup;
} }

View File

@ -2077,16 +2077,16 @@ qemuMonitorJSONGetMemoryStats(qemuMonitor *mon,
} }
if (!balloonpath) if (!balloonpath)
goto cleanup; return got;
if (!(cmd = qemuMonitorJSONMakeCommand("qom-get", if (!(cmd = qemuMonitorJSONMakeCommand("qom-get",
"s:path", balloonpath, "s:path", balloonpath,
"s:property", "guest-stats", "s:property", "guest-stats",
NULL))) NULL)))
goto cleanup; return got;
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup; return got;
if ((data = virJSONValueObjectGetObject(reply, "error"))) { if ((data = virJSONValueObjectGetObject(reply, "error"))) {
const char *klass = virJSONValueObjectGetString(data, "class"); const char *klass = virJSONValueObjectGetString(data, "class");
@ -2096,18 +2096,18 @@ qemuMonitorJSONGetMemoryStats(qemuMonitor *mon,
STREQ_NULLABLE(desc, "guest hasn't updated any stats yet")) { STREQ_NULLABLE(desc, "guest hasn't updated any stats yet")) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s", virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("the guest hasn't updated any stats yet")); _("the guest hasn't updated any stats yet"));
goto cleanup; return got;
} }
} }
if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
goto cleanup; return got;
data = virJSONValueObjectGetObject(reply, "return"); data = virJSONValueObjectGetObject(reply, "return");
if (!(statsdata = virJSONValueObjectGet(data, "stats"))) { if (!(statsdata = virJSONValueObjectGet(data, "stats"))) {
VIR_DEBUG("data does not include 'stats'"); VIR_DEBUG("data does not include 'stats'");
goto cleanup; return got;
} }
GET_BALLOON_STATS(statsdata, "stat-swap-in", GET_BALLOON_STATS(statsdata, "stat-swap-in",
@ -2133,9 +2133,7 @@ qemuMonitorJSONGetMemoryStats(qemuMonitor *mon,
GET_BALLOON_STATS(statsdata, "stat-htlb-pgfail", GET_BALLOON_STATS(statsdata, "stat-htlb-pgfail",
VIR_DOMAIN_MEMORY_STAT_HUGETLB_PGFAIL, 1); VIR_DOMAIN_MEMORY_STAT_HUGETLB_PGFAIL, 1);
ret = got; return got;
cleanup:
return ret;
} }
#undef GET_BALLOON_STATS #undef GET_BALLOON_STATS

View File

@ -1577,12 +1577,12 @@ qemuSnapshotCreateXML(virDomainPtr domain,
parse_flags |= VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE; parse_flags |= VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE;
if (qemuDomainSupportsCheckpointsBlockjobs(vm) < 0) if (qemuDomainSupportsCheckpointsBlockjobs(vm) < 0)
goto cleanup; return NULL;
if (!vm->persistent && (flags & VIR_DOMAIN_SNAPSHOT_CREATE_HALT)) { if (!vm->persistent && (flags & VIR_DOMAIN_SNAPSHOT_CREATE_HALT)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s", virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("cannot halt after transient domain snapshot")); _("cannot halt after transient domain snapshot"));
goto cleanup; return NULL;
} }
if ((flags & VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY) || if ((flags & VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY) ||
!virDomainObjIsActive(vm)) !virDomainObjIsActive(vm))
@ -1593,7 +1593,7 @@ qemuSnapshotCreateXML(virDomainPtr domain,
if (!(def = virDomainSnapshotDefParseString(xmlDesc, driver->xmlopt, if (!(def = virDomainSnapshotDefParseString(xmlDesc, driver->xmlopt,
priv->qemuCaps, NULL, parse_flags))) priv->qemuCaps, NULL, parse_flags)))
goto cleanup; return NULL;
/* reject snapshot names containing slashes or starting with dot as /* reject snapshot names containing slashes or starting with dot as
* snapshot definitions are saved in files named by the snapshot name */ * snapshot definitions are saved in files named by the snapshot name */
@ -1603,7 +1603,7 @@ qemuSnapshotCreateXML(virDomainPtr domain,
_("invalid snapshot name '%s': " _("invalid snapshot name '%s': "
"name can't contain '/'"), "name can't contain '/'"),
def->parent.name); def->parent.name);
goto cleanup; return NULL;
} }
if (def->parent.name[0] == '.') { if (def->parent.name[0] == '.') {
@ -1611,7 +1611,7 @@ qemuSnapshotCreateXML(virDomainPtr domain,
_("invalid snapshot name '%s': " _("invalid snapshot name '%s': "
"name can't start with '.'"), "name can't start with '.'"),
def->parent.name); def->parent.name);
goto cleanup; return NULL;
} }
} }
@ -1622,7 +1622,7 @@ qemuSnapshotCreateXML(virDomainPtr domain,
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("live snapshot creation is supported only " _("live snapshot creation is supported only "
"during full system snapshots")); "during full system snapshots"));
goto cleanup; return NULL;
} }
/* allow snapshots only in certain states */ /* allow snapshots only in certain states */
@ -1640,7 +1640,7 @@ qemuSnapshotCreateXML(virDomainPtr domain,
if (!redefine) { if (!redefine) {
virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid domain state %s"), virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid domain state %s"),
virDomainSnapshotStateTypeToString(state)); virDomainSnapshotStateTypeToString(state));
goto cleanup; return NULL;
} }
break; break;
@ -1648,7 +1648,7 @@ qemuSnapshotCreateXML(virDomainPtr domain,
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("qemu doesn't support taking snapshots of " _("qemu doesn't support taking snapshots of "
"PMSUSPENDED guests")); "PMSUSPENDED guests"));
goto cleanup; return NULL;
/* invalid states */ /* invalid states */
case VIR_DOMAIN_SNAPSHOT_NOSTATE: case VIR_DOMAIN_SNAPSHOT_NOSTATE:
@ -1656,7 +1656,7 @@ qemuSnapshotCreateXML(virDomainPtr domain,
case VIR_DOMAIN_SNAPSHOT_LAST: case VIR_DOMAIN_SNAPSHOT_LAST:
virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid domain state %s"), virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid domain state %s"),
virDomainSnapshotStateTypeToString(state)); virDomainSnapshotStateTypeToString(state));
goto cleanup; return NULL;
} }
/* We are going to modify the domain below. Internal snapshots would use /* We are going to modify the domain below. Internal snapshots would use
@ -1665,7 +1665,7 @@ qemuSnapshotCreateXML(virDomainPtr domain,
* job mask appropriately. */ * job mask appropriately. */
if (qemuDomainObjBeginAsyncJob(driver, vm, QEMU_ASYNC_JOB_SNAPSHOT, if (qemuDomainObjBeginAsyncJob(driver, vm, QEMU_ASYNC_JOB_SNAPSHOT,
VIR_DOMAIN_JOB_OPERATION_SNAPSHOT, flags) < 0) VIR_DOMAIN_JOB_OPERATION_SNAPSHOT, flags) < 0)
goto cleanup; return NULL;
qemuDomainObjSetAsyncJobMask(vm, QEMU_JOB_NONE); qemuDomainObjSetAsyncJobMask(vm, QEMU_JOB_NONE);
@ -1801,7 +1801,6 @@ qemuSnapshotCreateXML(virDomainPtr domain,
qemuDomainObjEndAsyncJob(driver, vm); qemuDomainObjEndAsyncJob(driver, vm);
cleanup:
return snapshot; return snapshot;
} }

View File

@ -182,7 +182,6 @@ qemuVirtioFSStart(virQEMUDriver *driver,
pid_t pid = (pid_t) -1; pid_t pid = (pid_t) -1;
VIR_AUTOCLOSE fd = -1; VIR_AUTOCLOSE fd = -1;
VIR_AUTOCLOSE logfd = -1; VIR_AUTOCLOSE logfd = -1;
int ret = -1;
int rc; int rc;
if (!virFileExists(fs->src->path)) { if (!virFileExists(fs->src->path)) {
@ -193,12 +192,12 @@ qemuVirtioFSStart(virQEMUDriver *driver,
} }
if (!(pidfile = qemuVirtioFSCreatePidFilename(vm, fs->info.alias))) if (!(pidfile = qemuVirtioFSCreatePidFilename(vm, fs->info.alias)))
goto cleanup; goto error;
socket_path = qemuDomainGetVHostUserFSSocketPath(vm->privateData, fs); socket_path = qemuDomainGetVHostUserFSSocketPath(vm->privateData, fs);
if ((fd = qemuVirtioFSOpenChardev(driver, vm, socket_path)) < 0) if ((fd = qemuVirtioFSOpenChardev(driver, vm, socket_path)) < 0)
goto cleanup; goto error;
logpath = qemuVirtioFSCreateLogFilename(cfg, vm->def, fs->info.alias); logpath = qemuVirtioFSCreateLogFilename(cfg, vm->def, fs->info.alias);
@ -206,7 +205,7 @@ qemuVirtioFSStart(virQEMUDriver *driver,
g_autoptr(virLogManager) logManager = virLogManagerNew(driver->privileged); g_autoptr(virLogManager) logManager = virLogManagerNew(driver->privileged);
if (!logManager) if (!logManager)
goto cleanup; goto error;
if ((logfd = virLogManagerDomainOpenLogFile(logManager, if ((logfd = virLogManagerDomainOpenLogFile(logManager,
"qemu", "qemu",
@ -215,12 +214,12 @@ qemuVirtioFSStart(virQEMUDriver *driver,
logpath, logpath,
0, 0,
NULL, NULL)) < 0) NULL, NULL)) < 0)
goto cleanup; goto error;
} else { } else {
if ((logfd = open(logpath, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR)) < 0) { if ((logfd = open(logpath, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR)) < 0) {
virReportSystemError(errno, _("failed to create logfile %s"), virReportSystemError(errno, _("failed to create logfile %s"),
logpath); logpath);
goto cleanup; goto error;
} }
if (virSetCloseExec(logfd) < 0) { if (virSetCloseExec(logfd) < 0) {
virReportSystemError(errno, _("failed to set close-on-exec flag on %s"), virReportSystemError(errno, _("failed to set close-on-exec flag on %s"),
@ -230,7 +229,7 @@ qemuVirtioFSStart(virQEMUDriver *driver,
} }
if (!(cmd = qemuVirtioFSBuildCommandLine(cfg, fs, &fd))) if (!(cmd = qemuVirtioFSBuildCommandLine(cfg, fs, &fd)))
goto cleanup; goto error;
/* so far only running as root is supported */ /* so far only running as root is supported */
virCommandSetUID(cmd, 0); virCommandSetUID(cmd, 0);
@ -243,7 +242,7 @@ qemuVirtioFSStart(virQEMUDriver *driver,
virCommandDaemonize(cmd); virCommandDaemonize(cmd);
if (qemuExtDeviceLogCommand(driver, vm, cmd, "virtiofsd") < 0) if (qemuExtDeviceLogCommand(driver, vm, cmd, "virtiofsd") < 0)
goto cleanup; goto error;
rc = virCommandRun(cmd, NULL); rc = virCommandRun(cmd, NULL);
@ -267,10 +266,7 @@ qemuVirtioFSStart(virQEMUDriver *driver,
goto error; goto error;
} }
ret = 0; return 0;
cleanup:
return ret;
error: error:
if (pid != -1) if (pid != -1)
@ -279,7 +275,7 @@ qemuVirtioFSStart(virQEMUDriver *driver,
unlink(pidfile); unlink(pidfile);
if (socket_path) if (socket_path)
unlink(socket_path); unlink(socket_path);
goto cleanup; return -1;
} }

View File

@ -453,7 +453,6 @@ virNetLibsshImportPrivkey(virNetLibsshSession *sess,
virNetLibsshAuthMethod *priv, virNetLibsshAuthMethod *priv,
ssh_key *ret_key) ssh_key *ret_key)
{ {
int err;
int ret; int ret;
ssh_key key; ssh_key key;
@ -470,8 +469,7 @@ virNetLibsshImportPrivkey(virNetLibsshSession *sess,
virReportError(VIR_ERR_AUTH_FAILED, virReportError(VIR_ERR_AUTH_FAILED,
_("error while reading private key '%s'"), _("error while reading private key '%s'"),
priv->filename); priv->filename);
err = SSH_AUTH_ERROR; return SSH_AUTH_ERROR;
goto error;
} else if (ret == SSH_ERROR) { } else if (ret == SSH_ERROR) {
if (virGetLastErrorCode() == VIR_ERR_OK) { if (virGetLastErrorCode() == VIR_ERR_OK) {
virReportError(VIR_ERR_AUTH_FAILED, virReportError(VIR_ERR_AUTH_FAILED,
@ -479,15 +477,11 @@ virNetLibsshImportPrivkey(virNetLibsshSession *sess,
"passphrase?"), "passphrase?"),
priv->filename); priv->filename);
} }
err = SSH_AUTH_ERROR; return SSH_AUTH_ERROR;
goto error;
} }
*ret_key = key; *ret_key = key;
return SSH_AUTH_SUCCESS; return SSH_AUTH_SUCCESS;
error:
return err;
} }

View File

@ -91,7 +91,6 @@ static int
virStorageBackendISCSIGetHostNumber(const char *sysfs_path, virStorageBackendISCSIGetHostNumber(const char *sysfs_path,
uint32_t *host) uint32_t *host)
{ {
int ret = -1;
g_autoptr(DIR) sysdir = NULL; g_autoptr(DIR) sysdir = NULL;
struct dirent *dirent = NULL; struct dirent *dirent = NULL;
int direrr; int direrr;
@ -101,17 +100,16 @@ virStorageBackendISCSIGetHostNumber(const char *sysfs_path,
virWaitForDevices(); virWaitForDevices();
if (virDirOpen(&sysdir, sysfs_path) < 0) if (virDirOpen(&sysdir, sysfs_path) < 0)
goto cleanup; return -1;
while ((direrr = virDirRead(sysdir, &dirent, sysfs_path)) > 0) { while ((direrr = virDirRead(sysdir, &dirent, sysfs_path)) > 0) {
if (STRPREFIX(dirent->d_name, "target")) { if (STRPREFIX(dirent->d_name, "target")) {
if (sscanf(dirent->d_name, "target%u:", host) == 1) { if (sscanf(dirent->d_name, "target%u:", host) == 1) {
ret = 0; return 0;
goto cleanup;
} else { } else {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to parse target '%s'"), dirent->d_name); _("Failed to parse target '%s'"), dirent->d_name);
goto cleanup; return -1;
} }
} }
} }
@ -120,11 +118,10 @@ virStorageBackendISCSIGetHostNumber(const char *sysfs_path,
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to get host number for iSCSI session " _("Failed to get host number for iSCSI session "
"with path '%s'"), sysfs_path); "with path '%s'"), sysfs_path);
goto cleanup; return -1;
} }
cleanup: return -1;
return ret;
} }
static int static int

View File

@ -858,13 +858,13 @@ testParseXMLDocFromFile(xmlNodePtr node, const char *file, const char *type)
absFile = testBuildFilename(file, relFile); absFile = testBuildFilename(file, relFile);
if (!(doc = virXMLParse(absFile, NULL, type, NULL, false))) if (!(doc = virXMLParse(absFile, NULL, type, NULL, false)))
goto error; return NULL;
ret = xmlCopyNode(xmlDocGetRootElement(doc), 1); ret = xmlCopyNode(xmlDocGetRootElement(doc), 1);
if (!ret) { if (!ret) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Failed to copy XML node")); _("Failed to copy XML node"));
goto error; return NULL;
} }
xmlReplaceNode(node, ret); xmlReplaceNode(node, ret);
xmlFreeNode(node); xmlFreeNode(node);
@ -872,7 +872,6 @@ testParseXMLDocFromFile(xmlNodePtr node, const char *file, const char *type)
ret = node; ret = node;
} }
error:
return ret; return ret;
} }

View File

@ -2764,8 +2764,7 @@ virCgroupKillRecursiveInternal(virCgroup *group,
if (rc == 0) { if (rc == 0) {
VIR_DEBUG("Path %s does not exist, assuming done", keypath); VIR_DEBUG("Path %s does not exist, assuming done", keypath);
killedAny = false; return 0;
goto done;
} }
while ((direrr = virDirRead(dp, &ent, keypath)) > 0) { while ((direrr = virDirRead(dp, &ent, keypath)) > 0) {
@ -2791,7 +2790,6 @@ virCgroupKillRecursiveInternal(virCgroup *group,
if (direrr < 0) if (direrr < 0)
return -1; return -1;
done:
return killedAny ? 1 : 0; return killedAny ? 1 : 0;
} }

View File

@ -926,7 +926,6 @@ virCgroupV1SetOwner(virCgroup *cgroup,
gid_t gid, gid_t gid,
int controllers) int controllers)
{ {
int ret = -1;
size_t i; size_t i;
int direrr; int direrr;
@ -945,7 +944,7 @@ virCgroupV1SetOwner(virCgroup *cgroup,
cgroup->legacy[i].placement); cgroup->legacy[i].placement);
if (virDirOpen(&dh, base) < 0) if (virDirOpen(&dh, base) < 0)
goto cleanup; return -1;
while ((direrr = virDirRead(dh, &de, base)) > 0) { while ((direrr = virDirRead(dh, &de, base)) > 0) {
g_autofree char *entry = NULL; g_autofree char *entry = NULL;
@ -956,24 +955,21 @@ virCgroupV1SetOwner(virCgroup *cgroup,
virReportSystemError(errno, virReportSystemError(errno,
_("cannot chown '%s' to (%u, %u)"), _("cannot chown '%s' to (%u, %u)"),
entry, uid, gid); entry, uid, gid);
goto cleanup; return -1;
} }
} }
if (direrr < 0) if (direrr < 0)
goto cleanup; return -1;
if (chown(base, uid, gid) < 0) { if (chown(base, uid, gid) < 0) {
virReportSystemError(errno, virReportSystemError(errno,
_("cannot chown '%s' to (%u, %u)"), _("cannot chown '%s' to (%u, %u)"),
base, uid, gid); base, uid, gid);
goto cleanup; return -1;
} }
} }
ret = 0; return 0;
cleanup:
return ret;
} }
@ -1599,7 +1595,6 @@ virCgroupV1GetMemoryStat(virCgroup *group,
unsigned long long *inactiveFile, unsigned long long *inactiveFile,
unsigned long long *unevictable) unsigned long long *unevictable)
{ {
int ret = -1;
g_autofree char *stat = NULL; g_autofree char *stat = NULL;
char *line = NULL; char *line = NULL;
unsigned long long cacheVal = 0; unsigned long long cacheVal = 0;
@ -1629,12 +1624,12 @@ virCgroupV1GetMemoryStat(virCgroup *group,
if (!valueStr) { if (!valueStr) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Cannot parse 'memory.stat' cgroup file.")); _("Cannot parse 'memory.stat' cgroup file."));
goto cleanup; return -1;
} }
*valueStr = '\0'; *valueStr = '\0';
if (virStrToLong_ull(valueStr + 1, NULL, 10, &value) < 0) if (virStrToLong_ull(valueStr + 1, NULL, 10, &value) < 0)
goto cleanup; return -1;
if (STREQ(line, "cache")) if (STREQ(line, "cache"))
cacheVal = value >> 10; cacheVal = value >> 10;
@ -1662,10 +1657,7 @@ virCgroupV1GetMemoryStat(virCgroup *group,
*inactiveFile = inactiveFileVal; *inactiveFile = inactiveFileVal;
*unevictable = unevictableVal; *unevictable = unevictableVal;
ret = 0; return 0;
cleanup:
return ret;
} }

View File

@ -172,10 +172,8 @@ addnhostsWrite(const char *path,
if (!(f = fopen(tmp, "w"))) { if (!(f = fopen(tmp, "w"))) {
istmp = false; istmp = false;
if (!(f = fopen(path, "w"))) { if (!(f = fopen(path, "w")))
rc = -errno; return -errno;
goto cleanup;
}
} }
for (i = 0; i < nhosts; i++) { for (i = 0; i < nhosts; i++) {
@ -186,7 +184,7 @@ addnhostsWrite(const char *path,
if (istmp) if (istmp)
unlink(tmp); unlink(tmp);
goto cleanup; return rc;
} }
for (j = 0; j < hosts[i].nhostnames; j++) { for (j = 0; j < hosts[i].nhostnames; j++) {
@ -197,7 +195,7 @@ addnhostsWrite(const char *path,
if (istmp) if (istmp)
unlink(tmp); unlink(tmp);
goto cleanup; return rc;
} }
} }
@ -208,23 +206,20 @@ addnhostsWrite(const char *path,
if (istmp) if (istmp)
unlink(tmp); unlink(tmp);
goto cleanup; return rc;
} }
} }
if (VIR_FCLOSE(f) == EOF) { if (VIR_FCLOSE(f) == EOF)
rc = -errno; return -errno;
goto cleanup;
}
if (istmp && rename(tmp, path) < 0) { if (istmp && rename(tmp, path) < 0) {
rc = -errno; rc = -errno;
unlink(tmp); unlink(tmp);
goto cleanup; return rc;
} }
cleanup: return 0;
return rc;
} }
static int static int
@ -369,10 +364,8 @@ hostsfileWrite(const char *path,
if (!(f = fopen(tmp, "w"))) { if (!(f = fopen(tmp, "w"))) {
istmp = false; istmp = false;
if (!(f = fopen(path, "w"))) { if (!(f = fopen(path, "w")))
rc = -errno; return -errno;
goto cleanup;
}
} }
for (i = 0; i < nhosts; i++) { for (i = 0; i < nhosts; i++) {
@ -383,23 +376,20 @@ hostsfileWrite(const char *path,
if (istmp) if (istmp)
unlink(tmp); unlink(tmp);
goto cleanup; return rc;
} }
} }
if (VIR_FCLOSE(f) == EOF) { if (VIR_FCLOSE(f) == EOF)
rc = -errno; return -errno;
goto cleanup;
}
if (istmp && rename(tmp, path) < 0) { if (istmp && rename(tmp, path) < 0) {
rc = -errno; rc = -errno;
unlink(tmp); unlink(tmp);
goto cleanup; return rc;
} }
cleanup: return 0;
return rc;
} }
static int static int

View File

@ -90,7 +90,7 @@ virHostCPUGetStatsFreeBSD(int cpuNum,
g_autofree long *cpu_times = NULL; g_autofree long *cpu_times = NULL;
struct clockinfo clkinfo; struct clockinfo clkinfo;
size_t i, j, cpu_times_size, clkinfo_size; 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 { struct field_cpu_map {
const char *field; const char *field;
int idx[CPUSTATES]; int idx[CPUSTATES];
@ -151,7 +151,7 @@ virHostCPUGetStatsFreeBSD(int cpuNum,
virReportSystemError(errno, virReportSystemError(errno,
_("sysctl failed for '%s'"), _("sysctl failed for '%s'"),
sysctl_name); sysctl_name);
goto cleanup; return -1;
} }
for (i = 0; cpu_map[i].field != NULL; i++) { for (i = 0; cpu_map[i].field != NULL; i++) {
@ -161,7 +161,7 @@ virHostCPUGetStatsFreeBSD(int cpuNum,
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Field '%s' too long for destination"), _("Field '%s' too long for destination"),
cpu_map[i].field); cpu_map[i].field);
goto cleanup; return -1;
} }
param->value = 0; param->value = 0;
@ -169,10 +169,7 @@ virHostCPUGetStatsFreeBSD(int cpuNum,
param->value += cpu_times[offset + cpu_map[i].idx[j]] * TICK_TO_NSEC; param->value += cpu_times[offset + cpu_map[i].idx[j]] * TICK_TO_NSEC;
} }
ret = 0; return 0;
cleanup:
return ret;
} }
#endif /* __FreeBSD__ */ #endif /* __FreeBSD__ */

View File

@ -76,10 +76,10 @@ mymain(void)
int ret = 0; int ret = 0;
if ((caps = virTestGenericCapsInit()) == NULL) if ((caps = virTestGenericCapsInit()) == NULL)
goto cleanup; return EXIT_FAILURE;
if (!(xmlopt = virTestGenericDomainXMLConfInit())) if (!(xmlopt = virTestGenericDomainXMLConfInit()))
goto cleanup; return EXIT_FAILURE;
#define DO_TEST_GET_FS(fspath, expect) \ #define DO_TEST_GET_FS(fspath, expect) \
do { \ do { \
@ -100,7 +100,6 @@ mymain(void)
virObjectUnref(caps); virObjectUnref(caps);
virObjectUnref(xmlopt); virObjectUnref(xmlopt);
cleanup:
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
} }

View File

@ -141,20 +141,15 @@ fakeStorageVolLookupByName(virStoragePoolPtr pool,
return NULL; return NULL;
} }
if (!strchr(name, '+'))
goto fallback;
if (!(volinfo = g_strsplit(name, "+", 2))) if (!(volinfo = g_strsplit(name, "+", 2)))
return NULL; return NULL;
if (!volinfo[1]) if (!volinfo[1]) {
goto fallback; return virGetStorageVol(pool->conn, pool->name, name, "block", NULL, NULL);
}
return virGetStorageVol(pool->conn, pool->name, volinfo[1], volinfo[0], return virGetStorageVol(pool->conn, pool->name, volinfo[1], volinfo[0],
NULL, NULL); NULL, NULL);
fallback:
return virGetStorageVol(pool->conn, pool->name, name, "block", NULL, NULL);
} }
static int static int

View File

@ -4453,7 +4453,7 @@ cmdSave(vshControl *ctl, const vshCmd *cmd)
return false; return false;
if (vshCommandOptStringReq(ctl, cmd, "file", &to) < 0) if (vshCommandOptStringReq(ctl, cmd, "file", &to) < 0)
goto cleanup; return false;
if (vshCommandOptBool(cmd, "verbose")) if (vshCommandOptBool(cmd, "verbose"))
verbose = true; verbose = true;
@ -4462,7 +4462,7 @@ cmdSave(vshControl *ctl, const vshCmd *cmd)
true, true,
doSave, doSave,
&data) < 0) &data) < 0)
goto cleanup; return false;
virshWatchJob(ctl, dom, verbose, eventLoop, virshWatchJob(ctl, dom, verbose, eventLoop,
&data.ret, 0, NULL, NULL, _("Save")); &data.ret, 0, NULL, NULL, _("Save"));
@ -4472,7 +4472,6 @@ cmdSave(vshControl *ctl, const vshCmd *cmd)
if (!data.ret) if (!data.ret)
vshPrintExtra(ctl, _("\nDomain '%s' saved to %s\n"), name, to); vshPrintExtra(ctl, _("\nDomain '%s' saved to %s\n"), name, to);
cleanup:
return !data.ret; return !data.ret;
} }
@ -4770,7 +4769,7 @@ cmdManagedSave(vshControl *ctl, const vshCmd *cmd)
true, true,
doManagedsave, doManagedsave,
&data) < 0) &data) < 0)
goto cleanup; return false;
virshWatchJob(ctl, dom, verbose, eventLoop, virshWatchJob(ctl, dom, verbose, eventLoop,
&data.ret, 0, NULL, NULL, _("Managedsave")); &data.ret, 0, NULL, NULL, _("Managedsave"));
@ -4780,7 +4779,6 @@ cmdManagedSave(vshControl *ctl, const vshCmd *cmd)
if (!data.ret) if (!data.ret)
vshPrintExtra(ctl, _("\nDomain '%s' state saved by libvirt\n"), name); vshPrintExtra(ctl, _("\nDomain '%s' state saved by libvirt\n"), name);
cleanup:
return !data.ret; return !data.ret;
} }

View File

@ -1070,7 +1070,7 @@ vshExtractCPUDefXMLs(vshControl *ctl,
int n; int n;
if (virFileReadAll(xmlFile, VSH_MAX_XML_FILE, &buffer) < 0) if (virFileReadAll(xmlFile, VSH_MAX_XML_FILE, &buffer) < 0)
goto error; return NULL;
/* Strip possible XML declaration */ /* Strip possible XML declaration */
if (STRPREFIX(buffer, "<?xml") && (doc = strstr(buffer, "?>"))) if (STRPREFIX(buffer, "<?xml") && (doc = strstr(buffer, "?>")))
@ -1081,7 +1081,7 @@ vshExtractCPUDefXMLs(vshControl *ctl,
xmlStr = g_strdup_printf("<container>%s</container>", doc); xmlStr = g_strdup_printf("<container>%s</container>", doc);
if (!(xml = virXMLParseStringCtxt(xmlStr, xmlFile, &ctxt))) if (!(xml = virXMLParseStringCtxt(xmlStr, xmlFile, &ctxt)))
goto error; return NULL;
n = virXPathNodeSet("/container/cpu|" n = virXPathNodeSet("/container/cpu|"
"/container/domain/cpu|" "/container/domain/cpu|"
@ -1090,13 +1090,13 @@ vshExtractCPUDefXMLs(vshControl *ctl,
"mode[@name='host-model' and @supported='yes']", "mode[@name='host-model' and @supported='yes']",
ctxt, &nodes); ctxt, &nodes);
if (n < 0) if (n < 0)
goto error; return NULL;
if (n == 0) { if (n == 0) {
vshError(ctl, _("File '%s' does not contain any <cpu> element or " vshError(ctl, _("File '%s' does not contain any <cpu> element or "
"valid domain XML, host capabilities XML, or " "valid domain XML, host capabilities XML, or "
"domain capabilities XML"), xmlFile); "domain capabilities XML"), xmlFile);
goto error; return NULL;
} }
cpus = g_new0(char *, n + 1); cpus = g_new0(char *, n + 1);
@ -1111,22 +1111,18 @@ vshExtractCPUDefXMLs(vshControl *ctl,
vshError(ctl, vshError(ctl,
_("Cannot extract CPU definition from domain " _("Cannot extract CPU definition from domain "
"capabilities XML")); "capabilities XML"));
goto error; return NULL;
} }
} }
} }
if (!(cpus[i] = virXMLNodeToString(xml, nodes[i]))) { if (!(cpus[i] = virXMLNodeToString(xml, nodes[i]))) {
vshSaveLibvirtError(); vshSaveLibvirtError();
goto error; return NULL;
} }
} }
cleanup:
return g_steal_pointer(&cpus); return g_steal_pointer(&cpus);
error:
goto cleanup;
} }

View File

@ -141,7 +141,6 @@ static bool
cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd) cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd)
{ {
g_autoptr(virshNodeDevice) dev = NULL; g_autoptr(virshNodeDevice) dev = NULL;
bool ret = false;
const char *device_value = NULL; const char *device_value = NULL;
if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0) if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0)
@ -149,18 +148,16 @@ cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd)
dev = vshFindNodeDevice(ctl, device_value); dev = vshFindNodeDevice(ctl, device_value);
if (!dev) if (!dev)
goto cleanup; return false;
if (virNodeDeviceDestroy(dev) == 0) { if (virNodeDeviceDestroy(dev) == 0) {
vshPrintExtra(ctl, _("Destroyed node device '%s'\n"), device_value); vshPrintExtra(ctl, _("Destroyed node device '%s'\n"), device_value);
} else { } else {
vshError(ctl, _("Failed to destroy node device '%s'"), device_value); vshError(ctl, _("Failed to destroy node device '%s'"), device_value);
goto cleanup; return false;
} }
ret = true; return true;
cleanup:
return ret;
} }
struct virshNodeList { struct virshNodeList {
@ -578,7 +575,6 @@ cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cmd)
g_autoptr(virshNodeDevice) device = NULL; g_autoptr(virshNodeDevice) device = NULL;
g_autofree char *xml = NULL; g_autofree char *xml = NULL;
const char *device_value = NULL; const char *device_value = NULL;
bool ret = false;
if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0) if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0)
return false; return false;
@ -586,16 +582,13 @@ cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cmd)
device = vshFindNodeDevice(ctl, device_value); device = vshFindNodeDevice(ctl, device_value);
if (!device) if (!device)
goto cleanup; return false;
if (!(xml = virNodeDeviceGetXMLDesc(device, 0))) if (!(xml = virNodeDeviceGetXMLDesc(device, 0)))
goto cleanup; return false;
vshPrint(ctl, "%s\n", xml); vshPrint(ctl, "%s\n", xml);
return true;
ret = true;
cleanup:
return ret;
} }
/* /*
@ -1013,7 +1006,6 @@ static bool
cmdNodeDeviceUndefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) cmdNodeDeviceUndefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
{ {
g_autoptr(virshNodeDevice) dev = NULL; g_autoptr(virshNodeDevice) dev = NULL;
bool ret = false;
const char *device_value = NULL; const char *device_value = NULL;
if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0) if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0)
@ -1022,17 +1014,15 @@ cmdNodeDeviceUndefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
dev = vshFindNodeDevice(ctl, device_value); dev = vshFindNodeDevice(ctl, device_value);
if (!dev) if (!dev)
goto cleanup; return false;
if (virNodeDeviceUndefine(dev, 0) < 0) { if (virNodeDeviceUndefine(dev, 0) < 0) {
vshError(ctl, _("Failed to undefine node device '%s'"), device_value); vshError(ctl, _("Failed to undefine node device '%s'"), device_value);
goto cleanup; return false;
} }
vshPrintExtra(ctl, _("Undefined node device '%s'\n"), device_value); vshPrintExtra(ctl, _("Undefined node device '%s'\n"), device_value);
ret = true; return true;
cleanup:
return ret;
} }
@ -1163,7 +1153,6 @@ static bool
cmdNodeDeviceAutostart(vshControl *ctl, const vshCmd *cmd) cmdNodeDeviceAutostart(vshControl *ctl, const vshCmd *cmd)
{ {
g_autoptr(virshNodeDevice) dev = NULL; g_autoptr(virshNodeDevice) dev = NULL;
bool ret = false;
const char *name = NULL; const char *name = NULL;
int autostart; int autostart;
@ -1172,7 +1161,8 @@ cmdNodeDeviceAutostart(vshControl *ctl, const vshCmd *cmd)
dev = vshFindNodeDevice(ctl, name); dev = vshFindNodeDevice(ctl, name);
if (!dev) goto cleanup; if (!dev)
return false;
autostart = !vshCommandOptBool(cmd, "disable"); autostart = !vshCommandOptBool(cmd, "disable");
@ -1181,7 +1171,7 @@ cmdNodeDeviceAutostart(vshControl *ctl, const vshCmd *cmd)
vshError(ctl, _("failed to mark device %s as autostarted"), name); vshError(ctl, _("failed to mark device %s as autostarted"), name);
else else
vshError(ctl, _("failed to unmark device %s as autostarted"), name); vshError(ctl, _("failed to unmark device %s as autostarted"), name);
goto cleanup; return false;
} }
if (autostart) if (autostart)
@ -1189,9 +1179,7 @@ cmdNodeDeviceAutostart(vshControl *ctl, const vshCmd *cmd)
else else
vshPrintExtra(ctl, _("Device %s unmarked as autostarted\n"), name); vshPrintExtra(ctl, _("Device %s unmarked as autostarted\n"), name);
ret = true; return true;
cleanup:
return ret;
} }
@ -1224,7 +1212,6 @@ cmdNodeDeviceInfo(vshControl *ctl, const vshCmd *cmd)
{ {
g_autoptr(virshNodeDevice) device = NULL; g_autoptr(virshNodeDevice) device = NULL;
const char *device_value = NULL; const char *device_value = NULL;
bool ret = false;
int autostart; int autostart;
const char *parent = NULL; const char *parent = NULL;
@ -1234,7 +1221,7 @@ cmdNodeDeviceInfo(vshControl *ctl, const vshCmd *cmd)
device = vshFindNodeDevice(ctl, device_value); device = vshFindNodeDevice(ctl, device_value);
if (!device) if (!device)
goto cleanup; return false;
parent = virNodeDeviceGetParent(device); parent = virNodeDeviceGetParent(device);
vshPrint(ctl, "%-15s %s\n", _("Name:"), virNodeDeviceGetName(device)); vshPrint(ctl, "%-15s %s\n", _("Name:"), virNodeDeviceGetName(device));
@ -1248,9 +1235,7 @@ cmdNodeDeviceInfo(vshControl *ctl, const vshCmd *cmd)
else else
vshPrint(ctl, "%-15s %s\n", _("Autostart:"), autostart ? _("yes") : _("no")); vshPrint(ctl, "%-15s %s\n", _("Autostart:"), autostart ? _("yes") : _("no"));
ret = true; return true;
cleanup:
return ret;
} }

View File

@ -238,7 +238,6 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
unsigned long flags = 0; unsigned long flags = 0;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
bool ret = false;
if (vshCommandOptBool(cmd, "prealloc-metadata")) if (vshCommandOptBool(cmd, "prealloc-metadata"))
flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA; flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA;
@ -247,27 +246,27 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
return false; return false;
if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0) if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0)
goto cleanup; return false;
if (vshCommandOptStringReq(ctl, cmd, "capacity", &capacityStr) < 0) if (vshCommandOptStringReq(ctl, cmd, "capacity", &capacityStr) < 0)
goto cleanup; return false;
if (virshVolSize(capacityStr, &capacity) < 0) { if (virshVolSize(capacityStr, &capacity) < 0) {
vshError(ctl, _("Malformed size %s"), capacityStr); vshError(ctl, _("Malformed size %s"), capacityStr);
goto cleanup; return false;
} }
if (vshCommandOptStringQuiet(ctl, cmd, "allocation", &allocationStr) > 0 && if (vshCommandOptStringQuiet(ctl, cmd, "allocation", &allocationStr) > 0 &&
virshVolSize(allocationStr, &allocation) < 0) { virshVolSize(allocationStr, &allocation) < 0) {
vshError(ctl, _("Malformed size %s"), allocationStr); vshError(ctl, _("Malformed size %s"), allocationStr);
goto cleanup; return false;
} }
if (vshCommandOptStringReq(ctl, cmd, "format", &format) < 0 || if (vshCommandOptStringReq(ctl, cmd, "format", &format) < 0 ||
vshCommandOptStringReq(ctl, cmd, "backing-vol", &snapshotStrVol) < 0 || vshCommandOptStringReq(ctl, cmd, "backing-vol", &snapshotStrVol) < 0 ||
vshCommandOptStringReq(ctl, cmd, "backing-vol-format", vshCommandOptStringReq(ctl, cmd, "backing-vol-format",
&snapshotStrFormat) < 0) &snapshotStrFormat) < 0)
goto cleanup; return false;
virBufferAddLit(&buf, "<volume>\n"); virBufferAddLit(&buf, "<volume>\n");
virBufferAdjustIndent(&buf, 2); virBufferAdjustIndent(&buf, 2);
@ -325,11 +324,11 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
} }
if (snapVol == NULL) { if (snapVol == NULL) {
vshError(ctl, _("failed to get vol '%s'"), snapshotStrVol); vshError(ctl, _("failed to get vol '%s'"), snapshotStrVol);
goto cleanup; return false;
} }
if ((snapshotStrVolPath = virStorageVolGetPath(snapVol)) == NULL) { if ((snapshotStrVolPath = virStorageVolGetPath(snapVol)) == NULL) {
goto cleanup; return false;
} }
/* Create XML for the backing store */ /* Create XML for the backing store */
@ -353,15 +352,12 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
} else { } else {
if (!(vol = virStorageVolCreateXML(pool, xml, flags))) { if (!(vol = virStorageVolCreateXML(pool, xml, flags))) {
vshError(ctl, _("Failed to create vol %s"), name); vshError(ctl, _("Failed to create vol %s"), name);
goto cleanup; return false;
} }
vshPrintExtra(ctl, _("Vol %s created\n"), name); vshPrintExtra(ctl, _("Vol %s created\n"), name);
} }
ret = true; return true;
cleanup:
return ret;
} }
/* /*
@ -393,7 +389,6 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd)
g_autoptr(virshStoragePool) pool = NULL; g_autoptr(virshStoragePool) pool = NULL;
g_autoptr(virshStorageVol) vol = NULL; g_autoptr(virshStorageVol) vol = NULL;
const char *from = NULL; const char *from = NULL;
bool ret = false;
unsigned int flags = 0; unsigned int flags = 0;
g_autofree char *buffer = NULL; g_autofree char *buffer = NULL;
@ -404,23 +399,21 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd)
return false; return false;
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
goto cleanup; return false;
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) { if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
vshSaveLibvirtError(); vshSaveLibvirtError();
goto cleanup; return false;
} }
if (!(vol = virStorageVolCreateXML(pool, buffer, flags))) { if (!(vol = virStorageVolCreateXML(pool, buffer, flags))) {
vshError(ctl, _("Failed to create vol from %s"), from); vshError(ctl, _("Failed to create vol from %s"), from);
goto cleanup; return false;
} }
vshPrintExtra(ctl, _("Vol %s created from %s\n"), vshPrintExtra(ctl, _("Vol %s created from %s\n"),
virStorageVolGetName(vol), from); virStorageVolGetName(vol), from);
ret = true; return true;
cleanup:
return ret;
} }
/* /*
@ -463,12 +456,11 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd)
g_autoptr(virshStorageVol) newvol = NULL; g_autoptr(virshStorageVol) newvol = NULL;
g_autoptr(virshStorageVol) inputvol = NULL; g_autoptr(virshStorageVol) inputvol = NULL;
const char *from = NULL; const char *from = NULL;
bool ret = false;
g_autofree char *buffer = NULL; g_autofree char *buffer = NULL;
unsigned int flags = 0; unsigned int flags = 0;
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", NULL))) if (!(pool = virshCommandOptPool(ctl, cmd, "pool", NULL)))
goto cleanup; return false;
if (vshCommandOptBool(cmd, "prealloc-metadata")) if (vshCommandOptBool(cmd, "prealloc-metadata"))
flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA; flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA;
@ -477,28 +469,26 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd)
flags |= VIR_STORAGE_VOL_CREATE_REFLINK; flags |= VIR_STORAGE_VOL_CREATE_REFLINK;
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
goto cleanup; return false;
if (!(inputvol = virshCommandOptVol(ctl, cmd, "vol", "inputpool", NULL))) if (!(inputvol = virshCommandOptVol(ctl, cmd, "vol", "inputpool", NULL)))
goto cleanup; return false;
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) { if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
vshReportError(ctl); vshReportError(ctl);
goto cleanup; return false;
} }
newvol = virStorageVolCreateXMLFrom(pool, buffer, inputvol, flags); newvol = virStorageVolCreateXMLFrom(pool, buffer, inputvol, flags);
if (!newvol) { if (!newvol) {
vshError(ctl, _("Failed to create vol from %s"), from); vshError(ctl, _("Failed to create vol from %s"), from);
goto cleanup; return false;
} }
vshPrintExtra(ctl, _("Vol %s created from input vol %s\n"), vshPrintExtra(ctl, _("Vol %s created from input vol %s\n"),
virStorageVolGetName(newvol), virStorageVolGetName(inputvol)); virStorageVolGetName(newvol), virStorageVolGetName(inputvol));
ret = true; return true;
cleanup:
return ret;
} }
static xmlChar * static xmlChar *
@ -653,7 +643,6 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd)
{ {
const char *file = NULL; const char *file = NULL;
g_autoptr(virshStorageVol) vol = NULL; g_autoptr(virshStorageVol) vol = NULL;
bool ret = false;
VIR_AUTOCLOSE fd = -1; VIR_AUTOCLOSE fd = -1;
g_autoptr(virshStream) st = NULL; g_autoptr(virshStream) st = NULL;
const char *name = NULL; const char *name = NULL;
@ -673,16 +662,16 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd)
return false; return false;
if (vshCommandOptStringReq(ctl, cmd, "file", &file) < 0) if (vshCommandOptStringReq(ctl, cmd, "file", &file) < 0)
goto cleanup; return false;
if ((fd = open(file, O_RDONLY)) < 0) { if ((fd = open(file, O_RDONLY)) < 0) {
vshError(ctl, _("cannot read %s"), file); vshError(ctl, _("cannot read %s"), file);
goto cleanup; return false;
} }
if (fstat(fd, &sb) < 0) { if (fstat(fd, &sb) < 0) {
vshError(ctl, _("unable to stat %s"), file); vshError(ctl, _("unable to stat %s"), file);
goto cleanup; return false;
} }
cbData.ctl = ctl; cbData.ctl = ctl;
@ -694,12 +683,12 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd)
if (!(st = virStreamNew(priv->conn, 0))) { if (!(st = virStreamNew(priv->conn, 0))) {
vshError(ctl, _("cannot create a new stream")); vshError(ctl, _("cannot create a new stream"));
goto cleanup; return false;
} }
if (virStorageVolUpload(vol, st, offset, length, flags) < 0) { if (virStorageVolUpload(vol, st, offset, length, flags) < 0) {
vshError(ctl, _("cannot upload to volume %s"), name); vshError(ctl, _("cannot upload to volume %s"), name);
goto cleanup; return false;
} }
if (flags & VIR_STORAGE_VOL_UPLOAD_SPARSE_STREAM) { if (flags & VIR_STORAGE_VOL_UPLOAD_SPARSE_STREAM) {
@ -707,30 +696,27 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd)
virshStreamInData, virshStreamInData,
virshStreamSourceSkip, &cbData) < 0) { virshStreamSourceSkip, &cbData) < 0) {
vshError(ctl, _("cannot send data to volume %s"), name); vshError(ctl, _("cannot send data to volume %s"), name);
goto cleanup; return false;
} }
} else { } else {
if (virStreamSendAll(st, virshStreamSource, &cbData) < 0) { if (virStreamSendAll(st, virshStreamSource, &cbData) < 0) {
vshError(ctl, _("cannot send data to volume %s"), name); vshError(ctl, _("cannot send data to volume %s"), name);
goto cleanup; return false;
} }
} }
if (VIR_CLOSE(fd) < 0) { if (VIR_CLOSE(fd) < 0) {
vshError(ctl, _("cannot close file %s"), file); vshError(ctl, _("cannot close file %s"), file);
virStreamAbort(st); virStreamAbort(st);
goto cleanup; return false;
} }
if (virStreamFinish(st) < 0) { if (virStreamFinish(st) < 0) {
vshError(ctl, _("cannot close volume %s"), name); vshError(ctl, _("cannot close volume %s"), name);
goto cleanup; return false;
} }
ret = true; return true;
cleanup:
return ret;
} }
/* /*
@ -931,7 +917,6 @@ static bool
cmdVolWipe(vshControl *ctl, const vshCmd *cmd) cmdVolWipe(vshControl *ctl, const vshCmd *cmd)
{ {
g_autoptr(virshStorageVol) vol = NULL; g_autoptr(virshStorageVol) vol = NULL;
bool ret = false;
const char *name; const char *name;
const char *algorithm_str = NULL; const char *algorithm_str = NULL;
int algorithm = VIR_STORAGE_VOL_WIPE_ALG_ZERO; int algorithm = VIR_STORAGE_VOL_WIPE_ALG_ZERO;
@ -941,12 +926,12 @@ cmdVolWipe(vshControl *ctl, const vshCmd *cmd)
return false; return false;
if (vshCommandOptStringReq(ctl, cmd, "algorithm", &algorithm_str) < 0) if (vshCommandOptStringReq(ctl, cmd, "algorithm", &algorithm_str) < 0)
goto out; return false;
if (algorithm_str && if (algorithm_str &&
(algorithm = virshStorageVolWipeAlgorithmTypeFromString(algorithm_str)) < 0) { (algorithm = virshStorageVolWipeAlgorithmTypeFromString(algorithm_str)) < 0) {
vshError(ctl, _("Unsupported algorithm '%s'"), algorithm_str); vshError(ctl, _("Unsupported algorithm '%s'"), algorithm_str);
goto out; return false;
} }
if ((funcRet = virStorageVolWipePattern(vol, algorithm, 0)) < 0) { if ((funcRet = virStorageVolWipePattern(vol, algorithm, 0)) < 0) {
@ -957,13 +942,11 @@ cmdVolWipe(vshControl *ctl, const vshCmd *cmd)
if (funcRet < 0) { if (funcRet < 0) {
vshError(ctl, _("Failed to wipe vol %s"), name); vshError(ctl, _("Failed to wipe vol %s"), name);
goto out; return false;
} }
vshPrintExtra(ctl, _("Vol %s wiped\n"), name); vshPrintExtra(ctl, _("Vol %s wiped\n"), name);
ret = true; return true;
out:
return ret;
} }
@ -1111,7 +1094,6 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd)
const char *capacityStr = NULL; const char *capacityStr = NULL;
unsigned long long capacity = 0; unsigned long long capacity = 0;
unsigned int flags = 0; unsigned int flags = 0;
bool ret = false;
bool delta = vshCommandOptBool(cmd, "delta"); bool delta = vshCommandOptBool(cmd, "delta");
if (vshCommandOptBool(cmd, "allocate")) if (vshCommandOptBool(cmd, "allocate"))
@ -1123,7 +1105,7 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd)
return false; return false;
if (vshCommandOptStringReq(ctl, cmd, "capacity", &capacityStr) < 0) if (vshCommandOptStringReq(ctl, cmd, "capacity", &capacityStr) < 0)
goto cleanup; return false;
virSkipSpaces(&capacityStr); virSkipSpaces(&capacityStr);
if (*capacityStr == '-') { if (*capacityStr == '-') {
/* The API always requires a positive value; but we allow a /* The API always requires a positive value; but we allow a
@ -1134,7 +1116,7 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd)
} else { } else {
vshError(ctl, "%s", vshError(ctl, "%s",
_("negative size requires --shrink")); _("negative size requires --shrink"));
goto cleanup; return false;
} }
} }
@ -1143,7 +1125,7 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd)
if (virshVolSize(capacityStr, &capacity) < 0) { if (virshVolSize(capacityStr, &capacity) < 0) {
vshError(ctl, _("Malformed size %s"), capacityStr); vshError(ctl, _("Malformed size %s"), capacityStr);
goto cleanup; return false;
} }
if (virStorageVolResize(vol, capacity, flags) < 0) { if (virStorageVolResize(vol, capacity, flags) < 0) {
@ -1151,16 +1133,14 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd)
delta ? _("Failed to change size of volume '%s' by %s") delta ? _("Failed to change size of volume '%s' by %s")
: _("Failed to change size of volume '%s' to %s"), : _("Failed to change size of volume '%s' to %s"),
virStorageVolGetName(vol), capacityStr); virStorageVolGetName(vol), capacityStr);
goto cleanup; return false;
} }
vshPrintExtra(ctl, vshPrintExtra(ctl,
delta ? _("Size of volume '%s' successfully changed by %s\n") delta ? _("Size of volume '%s' successfully changed by %s\n")
: _("Size of volume '%s' successfully changed to %s\n"), : _("Size of volume '%s' successfully changed to %s\n"),
virStorageVolGetName(vol), capacityStr); virStorageVolGetName(vol), capacityStr);
ret = true; return true;
cleanup:
return ret;
} }
/* /*