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