mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
virNodeDeviceDefParseXML: Use g_auto*
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
parent
8f390ae310
commit
f16305b36f
@ -2059,21 +2059,20 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt,
|
|||||||
int create,
|
int create,
|
||||||
const char *virt_type)
|
const char *virt_type)
|
||||||
{
|
{
|
||||||
virNodeDeviceDef *def;
|
g_autoptr(virNodeDeviceDef) def = g_new0(virNodeDeviceDef, 1);
|
||||||
virNodeDevCapsDef **next_cap;
|
virNodeDevCapsDef **next_cap;
|
||||||
xmlNodePtr *nodes = NULL;
|
g_autofree xmlNodePtr *devnode = NULL;
|
||||||
|
g_autofree xmlNodePtr *capability = NULL;
|
||||||
int n, m;
|
int n, m;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
def = g_new0(virNodeDeviceDef, 1);
|
|
||||||
|
|
||||||
/* Extract device name */
|
/* Extract device name */
|
||||||
if (create == EXISTING_DEVICE) {
|
if (create == EXISTING_DEVICE) {
|
||||||
def->name = virXPathString("string(./name[1])", ctxt);
|
def->name = virXPathString("string(./name[1])", ctxt);
|
||||||
|
|
||||||
if (!def->name) {
|
if (!def->name) {
|
||||||
virReportError(VIR_ERR_NO_NAME, NULL);
|
virReportError(VIR_ERR_NO_NAME, NULL);
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
def->name = g_strdup("new device");
|
def->name = g_strdup("new device");
|
||||||
@ -2082,27 +2081,27 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt,
|
|||||||
def->sysfs_path = virXPathString("string(./path[1])", ctxt);
|
def->sysfs_path = virXPathString("string(./path[1])", ctxt);
|
||||||
|
|
||||||
/* Parse devnodes */
|
/* Parse devnodes */
|
||||||
if ((n = virXPathNodeSet("./devnode", ctxt, &nodes)) < 0)
|
if ((n = virXPathNodeSet("./devnode", ctxt, &devnode)) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
|
|
||||||
def->devlinks = g_new0(char *, n + 1);
|
def->devlinks = g_new0(char *, n + 1);
|
||||||
|
|
||||||
for (i = 0, m = 0; i < n; i++) {
|
for (i = 0, m = 0; i < n; i++) {
|
||||||
xmlNodePtr node = nodes[i];
|
xmlNodePtr node = devnode[i];
|
||||||
virNodeDevDevnodeType val;
|
virNodeDevDevnodeType val;
|
||||||
|
|
||||||
if (virXMLPropEnum(node, "type", virNodeDevDevnodeTypeFromString,
|
if (virXMLPropEnum(node, "type", virNodeDevDevnodeTypeFromString,
|
||||||
VIR_XML_PROP_REQUIRED, &val) < 0)
|
VIR_XML_PROP_REQUIRED, &val) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
|
|
||||||
switch (val) {
|
switch (val) {
|
||||||
case VIR_NODE_DEV_DEVNODE_DEV:
|
case VIR_NODE_DEV_DEVNODE_DEV:
|
||||||
if (!(def->devnode = virXMLNodeContentString(node)))
|
if (!(def->devnode = virXMLNodeContentString(node)))
|
||||||
goto error;
|
return NULL;
|
||||||
break;
|
break;
|
||||||
case VIR_NODE_DEV_DEVNODE_LINK:
|
case VIR_NODE_DEV_DEVNODE_LINK:
|
||||||
if (!(def->devlinks[m++] = virXMLNodeContentString(node)))
|
if (!(def->devlinks[m++] = virXMLNodeContentString(node)))
|
||||||
goto error;
|
return NULL;
|
||||||
break;
|
break;
|
||||||
case VIR_NODE_DEV_DEVNODE_LAST:
|
case VIR_NODE_DEV_DEVNODE_LAST:
|
||||||
break;
|
break;
|
||||||
@ -2118,7 +2117,7 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt,
|
|||||||
_("when providing parent wwnn='%s', the "
|
_("when providing parent wwnn='%s', the "
|
||||||
"wwpn must also be provided"),
|
"wwpn must also be provided"),
|
||||||
def->parent_wwnn);
|
def->parent_wwnn);
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!def->parent_wwnn && def->parent_wwpn) {
|
if (!def->parent_wwnn && def->parent_wwpn) {
|
||||||
@ -2126,42 +2125,35 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt,
|
|||||||
_("when providing parent wwpn='%s', the "
|
_("when providing parent wwpn='%s', the "
|
||||||
"wwnn must also be provided"),
|
"wwnn must also be provided"),
|
||||||
def->parent_wwpn);
|
def->parent_wwpn);
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
def->parent_fabric_wwn = virXPathString("string(./parent[1]/@fabric_wwn)",
|
def->parent_fabric_wwn = virXPathString("string(./parent[1]/@fabric_wwn)",
|
||||||
ctxt);
|
ctxt);
|
||||||
|
|
||||||
/* Parse device capabilities */
|
/* Parse device capabilities */
|
||||||
VIR_FREE(nodes);
|
if ((n = virXPathNodeSet("./capability", ctxt, &capability)) < 0)
|
||||||
if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) < 0)
|
return NULL;
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("no device capabilities for '%s'"),
|
_("no device capabilities for '%s'"),
|
||||||
def->name);
|
def->name);
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
next_cap = &def->caps;
|
next_cap = &def->caps;
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
*next_cap = virNodeDevCapsDefParseXML(ctxt, def,
|
*next_cap = virNodeDevCapsDefParseXML(ctxt, def,
|
||||||
nodes[i],
|
capability[i],
|
||||||
create,
|
create,
|
||||||
virt_type);
|
virt_type);
|
||||||
if (!*next_cap)
|
if (!*next_cap)
|
||||||
goto error;
|
return NULL;
|
||||||
|
|
||||||
next_cap = &(*next_cap)->next;
|
next_cap = &(*next_cap)->next;
|
||||||
}
|
}
|
||||||
VIR_FREE(nodes);
|
|
||||||
|
|
||||||
return def;
|
return g_steal_pointer(&def);
|
||||||
|
|
||||||
error:
|
|
||||||
virNodeDeviceDefFree(def);
|
|
||||||
VIR_FREE(nodes);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user