mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-08 22:15:21 +00:00
domain_conf.c: modernize virDomainControllerDefParseXML()
Let's register AUTOPTR_CLEANUP_FUNC for virDomainControllerDefPtr and modernize this function, removing the 'error' label using g_autoptr(). Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
parent
6048610c7e
commit
491bc80d6b
@ -11047,7 +11047,7 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
xmlXPathContextPtr ctxt,
|
||||
unsigned int flags)
|
||||
{
|
||||
virDomainControllerDefPtr def = NULL;
|
||||
g_autoptr(virDomainControllerDef) def = NULL;
|
||||
int type = 0;
|
||||
xmlNodePtr cur = NULL;
|
||||
bool processedModel = false;
|
||||
@ -11080,19 +11080,19 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
if ((type = virDomainControllerTypeFromString(typeStr)) < 0) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("Unknown controller type '%s'"), typeStr);
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(def = virDomainControllerDefNew(type)))
|
||||
goto error;
|
||||
return NULL;
|
||||
|
||||
model = virXMLPropString(node, "model");
|
||||
if (model) {
|
||||
if ((def->model = virDomainControllerModelTypeFromString(def, model)) < 0) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("Unknown model type '%s'"), model);
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -11103,7 +11103,7 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
idxVal > INT_MAX) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Cannot parse controller index %s"), idx);
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
def->idx = idxVal;
|
||||
}
|
||||
@ -11119,13 +11119,13 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
iothread = virXMLPropString(cur, "iothread");
|
||||
|
||||
if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0)
|
||||
goto error;
|
||||
return NULL;
|
||||
} else if (virXMLNodeNameEqual(cur, "model")) {
|
||||
if (processedModel) {
|
||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||
_("Multiple <model> elements in "
|
||||
"controller definition not allowed"));
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
modelName = virXMLPropString(cur, "name");
|
||||
processedModel = true;
|
||||
@ -11134,7 +11134,7 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||
_("Multiple <target> elements in "
|
||||
"controller definition not allowed"));
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
chassisNr = virXMLPropString(cur, "chassisNr");
|
||||
chassis = virXMLPropString(cur, "chassis");
|
||||
@ -11155,39 +11155,39 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
if (rc == -2 || (rc == 0 && numaNode < 0)) {
|
||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||
_("invalid NUMA node in target"));
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (queues && virStrToLong_ui(queues, NULL, 10, &def->queues) < 0) {
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("Malformed 'queues' value '%s'"), queues);
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (cmd_per_lun && virStrToLong_ui(cmd_per_lun, NULL, 10, &def->cmd_per_lun) < 0) {
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("Malformed 'cmd_per_lun' value '%s'"), cmd_per_lun);
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (max_sectors && virStrToLong_ui(max_sectors, NULL, 10, &def->max_sectors) < 0) {
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("Malformed 'max_sectors' value %s"), max_sectors);
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (ioeventfd &&
|
||||
(def->ioeventfd = virTristateSwitchTypeFromString(ioeventfd)) < 0) {
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("Malformed 'ioeventfd' value %s"), ioeventfd);
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (iothread) {
|
||||
if (virStrToLong_uip(iothread, NULL, 10, &def->iothread) < 0) {
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("Invalid 'iothread' value '%s'"), iothread);
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -11196,7 +11196,7 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
VIR_DEBUG("Ignoring device address for none model usb controller");
|
||||
} else if (virDomainDeviceInfoParseXML(xmlopt, node,
|
||||
&def->info, flags) < 0) {
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
portsStr = virXMLPropString(node, "ports");
|
||||
@ -11205,7 +11205,7 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
if (r != 0 || ports < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Invalid ports: %s"), portsStr);
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -11220,7 +11220,7 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
if (r != 0 || def->opts.vioserial.vectors < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Invalid vectors: %s"), vectors);
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -11258,12 +11258,12 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||
_("pci-root and pcie-root controllers should not "
|
||||
"have an address"));
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
if ((rc = virParseScaledValue("./pcihole64", NULL,
|
||||
ctxt, &bytes, 1024,
|
||||
1024ULL * ULONG_MAX, false)) < 0)
|
||||
goto error;
|
||||
return NULL;
|
||||
|
||||
if (rc == 1)
|
||||
def->opts.pciopts.pcihole64 = true;
|
||||
@ -11288,7 +11288,7 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("Unknown PCI controller model name '%s'"),
|
||||
modelName);
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
if (chassisNr) {
|
||||
if (virStrToLong_i(chassisNr, NULL, 0,
|
||||
@ -11296,7 +11296,7 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("Invalid chassisNr '%s' in PCI controller"),
|
||||
chassisNr);
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
if (def->opts.pciopts.chassisNr < 1 ||
|
||||
def->opts.pciopts.chassisNr > 255) {
|
||||
@ -11304,7 +11304,7 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
_("PCI controller chassisNr '%s' out of range "
|
||||
"- must be 1-255"),
|
||||
chassisNr);
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (chassis) {
|
||||
@ -11313,7 +11313,7 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("Invalid chassis '%s' in PCI controller"),
|
||||
chassis);
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
if (def->opts.pciopts.chassis < 0 ||
|
||||
def->opts.pciopts.chassis > 255) {
|
||||
@ -11321,7 +11321,7 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
_("PCI controller chassis '%s' out of range "
|
||||
"- must be 0-255"),
|
||||
chassis);
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (port) {
|
||||
@ -11330,7 +11330,7 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("Invalid port '%s' in PCI controller"),
|
||||
port);
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
if (def->opts.pciopts.port < 0 ||
|
||||
def->opts.pciopts.port > 255) {
|
||||
@ -11338,7 +11338,7 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
_("PCI controller port '%s' out of range "
|
||||
"- must be 0-255"),
|
||||
port);
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (busNr) {
|
||||
@ -11347,7 +11347,7 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("Invalid busNr '%s' in PCI controller"),
|
||||
busNr);
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
if (def->opts.pciopts.busNr < 1 ||
|
||||
def->opts.pciopts.busNr > 254) {
|
||||
@ -11355,7 +11355,7 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
_("PCI controller busNr '%s' out of range "
|
||||
"- must be 1-254"),
|
||||
busNr);
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (targetIndex) {
|
||||
@ -11365,7 +11365,7 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("Invalid target index '%s' in PCI controller"),
|
||||
targetIndex);
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (numaNode >= 0) {
|
||||
@ -11373,7 +11373,7 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||
_("The PCI controller with index=0 can't "
|
||||
"be associated with a NUMA node"));
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
def->opts.pciopts.numaNode = numaNode;
|
||||
}
|
||||
@ -11384,7 +11384,7 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("PCI controller unrecognized hotplug setting '%s'"),
|
||||
hotplug);
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
def->opts.pciopts.hotplug = val;
|
||||
}
|
||||
@ -11399,7 +11399,7 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
if (r != 0 || def->opts.xenbusopts.maxGrantFrames < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Invalid maxGrantFrames: %s"), gntframes);
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (eventchannels) {
|
||||
@ -11408,7 +11408,7 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
if (r != 0 || def->opts.xenbusopts.maxEventChannels < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Invalid maxEventChannels: %s"), eventchannels);
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -11418,11 +11418,7 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
break;
|
||||
}
|
||||
|
||||
return def;
|
||||
|
||||
error:
|
||||
virDomainControllerDefFree(def);
|
||||
return NULL;
|
||||
return g_steal_pointer(&def);
|
||||
}
|
||||
|
||||
|
||||
|
@ -3060,6 +3060,7 @@ virDomainDiskDefPtr virDomainDiskFindByBusAndDst(virDomainDefPtr def,
|
||||
|
||||
virDomainControllerDefPtr virDomainControllerDefNew(virDomainControllerType type);
|
||||
void virDomainControllerDefFree(virDomainControllerDefPtr def);
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainControllerDef, virDomainControllerDefFree);
|
||||
bool virDomainControllerIsPSeriesPHB(const virDomainControllerDef *cont);
|
||||
|
||||
virDomainFSDefPtr virDomainFSDefNew(virDomainXMLOptionPtr xmlopt);
|
||||
|
Loading…
Reference in New Issue
Block a user