1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-10 05:17:59 +03:00

virsh: domain: remove 'ret' variable and use direct return when possible

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Kristina Hanicova 2021-09-24 17:17:46 +02:00 committed by Michal Privoznik
parent a1fe822801
commit 9a5db04fe6

View File

@ -2702,7 +2702,6 @@ virshBlockJobAbort(virDomainPtr dom,
static bool static bool
cmdBlockjob(vshControl *ctl, const vshCmd *cmd) cmdBlockjob(vshControl *ctl, const vshCmd *cmd)
{ {
bool ret = false;
bool raw = vshCommandOptBool(cmd, "raw"); bool raw = vshCommandOptBool(cmd, "raw");
bool bytes = vshCommandOptBool(cmd, "bytes"); bool bytes = vshCommandOptBool(cmd, "bytes");
bool abortMode = vshCommandOptBool(cmd, "abort"); bool abortMode = vshCommandOptBool(cmd, "abort");
@ -2735,13 +2734,10 @@ cmdBlockjob(vshControl *ctl, const vshCmd *cmd)
return false; return false;
if (bandwidth) if (bandwidth)
ret = virshBlockJobSetSpeed(ctl, cmd, dom, path, bytes); return virshBlockJobSetSpeed(ctl, cmd, dom, path, bytes);
else if (abortMode || pivot || async) if (abortMode || pivot || async)
ret = virshBlockJobAbort(dom, path, pivot, async); return virshBlockJobAbort(dom, path, pivot, async);
else return virshBlockJobInfo(ctl, dom, path, raw, bytes);
ret = virshBlockJobInfo(ctl, dom, path, raw, bytes);
return ret;
} }
/* /*
@ -5063,7 +5059,6 @@ cmdSchedInfoUpdateOne(vshControl *ctl,
const char *field, const char *value) const char *field, const char *value)
{ {
virTypedParameterPtr param; virTypedParameterPtr param;
int ret = -1;
size_t i; size_t i;
for (i = 0; i < nsrc_params; i++) { for (i = 0; i < nsrc_params; i++) {
@ -5078,14 +5073,11 @@ cmdSchedInfoUpdateOne(vshControl *ctl,
vshSaveLibvirtError(); vshSaveLibvirtError();
return -1; return -1;
} }
ret = 0; return 0;
break;
} }
if (ret < 0) vshError(ctl, _("invalid scheduler option: %s"), field);
vshError(ctl, _("invalid scheduler option: %s"), field); return -1;
return ret;
} }
static int static int
@ -5529,7 +5521,6 @@ virshGenFileName(vshControl *ctl, virDomainPtr dom, const char *mime)
g_autoptr(GDateTime) now = g_date_time_new_now_local(); g_autoptr(GDateTime) now = g_date_time_new_now_local();
g_autofree char *nowstr = NULL; g_autofree char *nowstr = NULL;
const char *ext = NULL; const char *ext = NULL;
char *ret = NULL;
if (!dom) { if (!dom) {
vshError(ctl, "%s", _("Invalid domain supplied")); vshError(ctl, "%s", _("Invalid domain supplied"));
@ -5544,10 +5535,8 @@ virshGenFileName(vshControl *ctl, virDomainPtr dom, const char *mime)
nowstr = g_date_time_format(now, "%Y-%m-%d-%H:%M:%S"); nowstr = g_date_time_format(now, "%Y-%m-%d-%H:%M:%S");
ret = g_strdup_printf("%s-%s%s", virDomainGetName(dom), return g_strdup_printf("%s-%s%s", virDomainGetName(dom),
nowstr, NULLSTR_EMPTY(ext)); nowstr, NULLSTR_EMPTY(ext));
return ret;
} }
static bool static bool
@ -5686,7 +5675,6 @@ static bool
cmdSetLifecycleAction(vshControl *ctl, const vshCmd *cmd) cmdSetLifecycleAction(vshControl *ctl, const vshCmd *cmd)
{ {
g_autoptr(virshDomain) dom = NULL; g_autoptr(virshDomain) dom = NULL;
bool ret = true;
bool config = vshCommandOptBool(cmd, "config"); bool config = vshCommandOptBool(cmd, "config");
bool live = vshCommandOptBool(cmd, "live"); bool live = vshCommandOptBool(cmd, "live");
bool current = vshCommandOptBool(cmd, "current"); bool current = vshCommandOptBool(cmd, "current");
@ -5727,10 +5715,9 @@ cmdSetLifecycleAction(vshControl *ctl, const vshCmd *cmd)
if (virDomainSetLifecycleAction(dom, type, action, flags) < 0) { if (virDomainSetLifecycleAction(dom, type, action, flags) < 0) {
vshError(ctl, "%s", _("Unable to change lifecycle action.")); vshError(ctl, "%s", _("Unable to change lifecycle action."));
ret = false; return false;
} }
return true;
return ret;
} }
/* /*
@ -6469,15 +6456,14 @@ static bool
cmdDomjobabort(vshControl *ctl, const vshCmd *cmd) cmdDomjobabort(vshControl *ctl, const vshCmd *cmd)
{ {
g_autoptr(virshDomain) dom = NULL; g_autoptr(virshDomain) dom = NULL;
bool ret = true;
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
return false; return false;
if (virDomainAbortJob(dom) < 0) if (virDomainAbortJob(dom) < 0)
ret = false; return false;
return ret; return true;
} }
/* /*
@ -11920,12 +11906,12 @@ virshDomainDetachInterface(char *doc,
xmlNodePtr cur = NULL, matchNode = NULL; xmlNodePtr cur = NULL, matchNode = NULL;
g_autofree char *detach_xml = NULL; g_autofree char *detach_xml = NULL;
char buf[64]; char buf[64];
int diff_mac, ret = -1; int diff_mac = -1;
size_t i; size_t i;
if (!(xml = virXMLParseStringCtxt(doc, _("(domain_definition)"), &ctxt))) { if (!(xml = virXMLParseStringCtxt(doc, _("(domain_definition)"), &ctxt))) {
vshError(ctl, "%s", _("Failed to get interface information")); vshError(ctl, "%s", _("Failed to get interface information"));
goto cleanup; return false;
} }
g_snprintf(buf, sizeof(buf), "/domain/devices/interface[@type='%s']", type); g_snprintf(buf, sizeof(buf), "/domain/devices/interface[@type='%s']", type);
@ -11933,13 +11919,13 @@ virshDomainDetachInterface(char *doc,
if (obj == NULL || obj->type != XPATH_NODESET || if (obj == NULL || obj->type != XPATH_NODESET ||
obj->nodesetval == NULL || obj->nodesetval->nodeNr == 0) { obj->nodesetval == NULL || obj->nodesetval->nodeNr == 0) {
vshError(ctl, _("No interface found whose type is %s"), type); vshError(ctl, _("No interface found whose type is %s"), type);
goto cleanup; return false;
} }
if (!mac && obj->nodesetval->nodeNr > 1) { if (!mac && obj->nodesetval->nodeNr > 1) {
vshError(ctl, _("Domain has %d interfaces. Please specify which one " vshError(ctl, _("Domain has %d interfaces. Please specify which one "
"to detach using --mac"), obj->nodesetval->nodeNr); "to detach using --mac"), obj->nodesetval->nodeNr);
goto cleanup; return false;
} }
if (!mac) { if (!mac) {
@ -11962,7 +11948,7 @@ virshDomainDetachInterface(char *doc,
"MAC address %s. You must use detach-device and " "MAC address %s. You must use detach-device and "
"specify the device pci address to remove it."), "specify the device pci address to remove it."),
mac); mac);
goto cleanup; return false;
} }
matchNode = obj->nodesetval->nodeTab[i]; matchNode = obj->nodesetval->nodeTab[i];
} }
@ -11972,22 +11958,18 @@ virshDomainDetachInterface(char *doc,
} }
if (!matchNode) { if (!matchNode) {
vshError(ctl, _("No interface with MAC address %s was found"), mac); vshError(ctl, _("No interface with MAC address %s was found"), mac);
goto cleanup; return false;
} }
hit: hit:
if (!(detach_xml = virXMLNodeToString(xml, matchNode))) { if (!(detach_xml = virXMLNodeToString(xml, matchNode))) {
vshSaveLibvirtError(); vshSaveLibvirtError();
goto cleanup; return false;
} }
if (flags != 0 || current) if (flags != 0 || current)
ret = virDomainDetachDeviceFlags(dom, detach_xml, flags); return virDomainDetachDeviceFlags(dom, detach_xml, flags) == 0;
else return virDomainDetachDevice(dom, detach_xml) == 0;
ret = virDomainDetachDevice(dom, detach_xml);
cleanup:
return ret == 0;
} }