virsh: cmdChangeMedia: Refactor cleanup

Use automatic pointer freeing for the 'disk_node' variable and remove
the 'cleanup' label and 'ret' variable.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2022-12-02 10:14:09 +01:00
parent be9560070b
commit 3dd4971e29

View File

@ -13089,9 +13089,8 @@ cmdChangeMedia(vshControl *ctl, const vshCmd *cmd)
const char *source = NULL; const char *source = NULL;
const char *path = NULL; const char *path = NULL;
g_autofree char *doc = NULL; g_autofree char *doc = NULL;
xmlNodePtr disk_node = NULL; g_autoptr(xmlNode) disk_node = NULL;
g_autofree char *disk_xml = NULL; g_autofree char *disk_xml = NULL;
bool ret = false;
virshUpdateDiskXMLType update_type; virshUpdateDiskXMLType update_type;
const char *action = NULL; const char *action = NULL;
const char *success_msg = NULL; const char *success_msg = NULL;
@ -13152,38 +13151,34 @@ cmdChangeMedia(vshControl *ctl, const vshCmd *cmd)
return false; return false;
if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0) if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0)
goto cleanup; return false;
if (flags & VIR_DOMAIN_AFFECT_CONFIG) if (flags & VIR_DOMAIN_AFFECT_CONFIG)
doc = virDomainGetXMLDesc(dom, VIR_DOMAIN_XML_INACTIVE); doc = virDomainGetXMLDesc(dom, VIR_DOMAIN_XML_INACTIVE);
else else
doc = virDomainGetXMLDesc(dom, 0); doc = virDomainGetXMLDesc(dom, 0);
if (!doc) if (!doc)
goto cleanup; return false;
if (!(disk_node = virshFindDisk(doc, path, VIRSH_FIND_DISK_CHANGEABLE))) if (!(disk_node = virshFindDisk(doc, path, VIRSH_FIND_DISK_CHANGEABLE)))
goto cleanup; return false;
if (!(disk_xml = virshUpdateDiskXML(disk_node, source, block, path, if (!(disk_xml = virshUpdateDiskXML(disk_node, source, block, path,
update_type))) update_type)))
goto cleanup; return false;
if (vshCommandOptBool(cmd, "print-xml")) { if (vshCommandOptBool(cmd, "print-xml")) {
vshPrint(ctl, "%s", disk_xml); vshPrint(ctl, "%s", disk_xml);
} else { return true;
}
if (virDomainUpdateDeviceFlags(dom, disk_xml, flags) != 0) { if (virDomainUpdateDeviceFlags(dom, disk_xml, flags) != 0) {
vshError(ctl, _("Failed to complete action %s on media"), action); vshError(ctl, _("Failed to complete action %s on media"), action);
goto cleanup; return false;
} }
vshPrint(ctl, "%s", success_msg); vshPrint(ctl, "%s", success_msg);
} return true;
ret = true;
cleanup:
xmlFreeNode(disk_node);
return ret;
} }
static const vshCmdInfo info_domfstrim[] = { static const vshCmdInfo info_domfstrim[] = {