mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 02:51:16 +00:00
Fix virtual networking XML -> XM config file conversion & a mem leak
This commit is contained in:
parent
aa826860bc
commit
bf70fe4883
@ -1,3 +1,10 @@
|
|||||||
|
Wed Oct 10 13:13:53 EST 2007 Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
|
* src/xm_internal.c: Fix XML -> XM config file conversion to
|
||||||
|
include bridge name for virtual networks
|
||||||
|
* src/xml.c: Fix memory leak handling XML -> SEXPR conversion
|
||||||
|
of virtual network bridge devices
|
||||||
|
|
||||||
Mon Oct 8 17:01:53 CEST 2007 Daniel Veillard <veillard@redhat.com>
|
Mon Oct 8 17:01:53 CEST 2007 Daniel Veillard <veillard@redhat.com>
|
||||||
|
|
||||||
* src/xend_internal.c: applied patch from Beth Kon to fix
|
* src/xend_internal.c: applied patch from Beth Kon to fix
|
||||||
|
@ -1635,7 +1635,7 @@ static int xenXMParseXMLDisk(xmlNodePtr node, int hvm, int xendConfigVersion, ch
|
|||||||
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
static char *xenXMParseXMLVif(xmlNodePtr node, int hvm) {
|
static char *xenXMParseXMLVif(virConnectPtr conn, xmlNodePtr node, int hvm) {
|
||||||
xmlNodePtr cur;
|
xmlNodePtr cur;
|
||||||
xmlChar *type = NULL;
|
xmlChar *type = NULL;
|
||||||
xmlChar *source = NULL;
|
xmlChar *source = NULL;
|
||||||
@ -1645,6 +1645,7 @@ static char *xenXMParseXMLVif(xmlNodePtr node, int hvm) {
|
|||||||
int typ = 0;
|
int typ = 0;
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
int buflen = 0;
|
int buflen = 0;
|
||||||
|
char *bridge = NULL;
|
||||||
|
|
||||||
type = xmlGetProp(node, BAD_CAST "type");
|
type = xmlGetProp(node, BAD_CAST "type");
|
||||||
if (type != NULL) {
|
if (type != NULL) {
|
||||||
@ -1652,6 +1653,8 @@ static char *xenXMParseXMLVif(xmlNodePtr node, int hvm) {
|
|||||||
typ = 0;
|
typ = 0;
|
||||||
else if (xmlStrEqual(type, BAD_CAST "ethernet"))
|
else if (xmlStrEqual(type, BAD_CAST "ethernet"))
|
||||||
typ = 1;
|
typ = 1;
|
||||||
|
else if (xmlStrEqual(type, BAD_CAST "network"))
|
||||||
|
typ = 2;
|
||||||
xmlFree(type);
|
xmlFree(type);
|
||||||
}
|
}
|
||||||
cur = node->children;
|
cur = node->children;
|
||||||
@ -1662,8 +1665,10 @@ static char *xenXMParseXMLVif(xmlNodePtr node, int hvm) {
|
|||||||
|
|
||||||
if (typ == 0)
|
if (typ == 0)
|
||||||
source = xmlGetProp(cur, BAD_CAST "bridge");
|
source = xmlGetProp(cur, BAD_CAST "bridge");
|
||||||
else
|
else if (typ == 1)
|
||||||
source = xmlGetProp(cur, BAD_CAST "dev");
|
source = xmlGetProp(cur, BAD_CAST "dev");
|
||||||
|
else
|
||||||
|
source = xmlGetProp(cur, BAD_CAST "network");
|
||||||
} else if ((mac == NULL) &&
|
} else if ((mac == NULL) &&
|
||||||
(xmlStrEqual(cur->name, BAD_CAST "mac"))) {
|
(xmlStrEqual(cur->name, BAD_CAST "mac"))) {
|
||||||
mac = xmlGetProp(cur, BAD_CAST "address");
|
mac = xmlGetProp(cur, BAD_CAST "address");
|
||||||
@ -1685,8 +1690,17 @@ static char *xenXMParseXMLVif(xmlNodePtr node, int hvm) {
|
|||||||
if (source) {
|
if (source) {
|
||||||
if (typ == 0) {
|
if (typ == 0) {
|
||||||
buflen += 8 + strlen((const char *)source);
|
buflen += 8 + strlen((const char *)source);
|
||||||
} else {
|
} else if (typ == 1) {
|
||||||
buflen += 5 + strlen((const char *)source);
|
buflen += 5 + strlen((const char *)source);
|
||||||
|
} else {
|
||||||
|
virNetworkPtr network = virNetworkLookupByName(conn, (const char *) source);
|
||||||
|
if (!network || !(bridge = virNetworkGetBridgeName(network))) {
|
||||||
|
if (network)
|
||||||
|
virNetworkFree(network);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
virNetworkFree(network);
|
||||||
|
buflen += 8 + strlen(bridge);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hvm)
|
if (hvm)
|
||||||
@ -1705,9 +1719,12 @@ static char *xenXMParseXMLVif(xmlNodePtr node, int hvm) {
|
|||||||
if (typ == 0) {
|
if (typ == 0) {
|
||||||
strcat(buf, ",bridge=");
|
strcat(buf, ",bridge=");
|
||||||
strcat(buf, (const char*)source);
|
strcat(buf, (const char*)source);
|
||||||
} else {
|
} else if (typ == 1) {
|
||||||
strcat(buf, ",mac=");
|
strcat(buf, ",dev=");
|
||||||
strcat(buf, (const char*)source);
|
strcat(buf, (const char*)source);
|
||||||
|
} else {
|
||||||
|
strcat(buf, ",bridge=");
|
||||||
|
strcat(buf, bridge);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hvm) {
|
if (hvm) {
|
||||||
@ -1723,6 +1740,8 @@ static char *xenXMParseXMLVif(xmlNodePtr node, int hvm) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
if (bridge != NULL)
|
||||||
|
free(bridge);
|
||||||
if (mac != NULL)
|
if (mac != NULL)
|
||||||
xmlFree(mac);
|
xmlFree(mac);
|
||||||
if (source != NULL)
|
if (source != NULL)
|
||||||
@ -2058,7 +2077,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
|
|||||||
vifs->list = NULL;
|
vifs->list = NULL;
|
||||||
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
|
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
|
||||||
virConfValuePtr thisVif;
|
virConfValuePtr thisVif;
|
||||||
char *vif = xenXMParseXMLVif(obj->nodesetval->nodeTab[i], hvm);
|
char *vif = xenXMParseXMLVif(conn, obj->nodesetval->nodeTab[i], hvm);
|
||||||
if (!vif)
|
if (!vif)
|
||||||
goto error;
|
goto error;
|
||||||
if (!(thisVif = malloc(sizeof(virConfValue)))) {
|
if (!(thisVif = malloc(sizeof(virConfValue)))) {
|
||||||
|
@ -1023,9 +1023,12 @@ virDomainParseXMLIfDesc(virConnectPtr conn ATTRIBUTE_UNUSED, xmlNodePtr node, vi
|
|||||||
virNetworkPtr network = virNetworkLookupByName(conn, (const char *) source);
|
virNetworkPtr network = virNetworkLookupByName(conn, (const char *) source);
|
||||||
char *bridge;
|
char *bridge;
|
||||||
if (!network || !(bridge = virNetworkGetBridgeName(network))) {
|
if (!network || !(bridge = virNetworkGetBridgeName(network))) {
|
||||||
|
if (network)
|
||||||
|
virNetworkFree(network);
|
||||||
virXMLError(conn, VIR_ERR_NO_SOURCE, (const char *) source, 0);
|
virXMLError(conn, VIR_ERR_NO_SOURCE, (const char *) source, 0);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
virNetworkFree(network);
|
||||||
virBufferVSprintf(buf, "(bridge '%s')", bridge);
|
virBufferVSprintf(buf, "(bridge '%s')", bridge);
|
||||||
free(bridge);
|
free(bridge);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user