1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-23 21:34:54 +03:00

Remove virConnectPtr from network XML APis

The virConnectPtr is no longer required for error reporting since
that is recorded in a thread local. Remove use of virConnectPtr
from all APIs in network_conf.{h,c} and update all callers to
match
This commit is contained in:
Daniel P. Berrange 2010-02-10 10:22:52 +00:00
parent ce71b8654d
commit 0677e11125
6 changed files with 157 additions and 205 deletions

View File

@ -53,8 +53,8 @@ VIR_ENUM_IMPL(virNetworkForward,
VIR_NETWORK_FORWARD_LAST, VIR_NETWORK_FORWARD_LAST,
"none", "nat", "route" ) "none", "nat", "route" )
#define virNetworkReportError(conn, code, fmt...) \ #define virNetworkReportError(code, fmt...) \
virReportErrorHelper(conn, VIR_FROM_NETWORK, code, __FILE__, \ virReportErrorHelper(NULL, VIR_FROM_NETWORK, code, __FILE__, \
__FUNCTION__, __LINE__, fmt) __FUNCTION__, __LINE__, fmt)
virNetworkObjPtr virNetworkFindByUUID(const virNetworkObjListPtr nets, virNetworkObjPtr virNetworkFindByUUID(const virNetworkObjListPtr nets,
@ -147,8 +147,7 @@ void virNetworkObjListFree(virNetworkObjListPtr nets)
nets->count = 0; nets->count = 0;
} }
virNetworkObjPtr virNetworkAssignDef(virConnectPtr conn, virNetworkObjPtr virNetworkAssignDef(virNetworkObjListPtr nets,
virNetworkObjListPtr nets,
const virNetworkDefPtr def) const virNetworkDefPtr def)
{ {
virNetworkObjPtr network; virNetworkObjPtr network;
@ -171,7 +170,7 @@ virNetworkObjPtr virNetworkAssignDef(virConnectPtr conn,
return NULL; return NULL;
} }
if (virMutexInit(&network->lock) < 0) { if (virMutexInit(&network->lock) < 0) {
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot initialize mutex")); "%s", _("cannot initialize mutex"));
VIR_FREE(network); VIR_FREE(network);
return NULL; return NULL;
@ -221,8 +220,7 @@ void virNetworkRemoveInactive(virNetworkObjListPtr nets,
static int static int
virNetworkDHCPRangeDefParseXML(virConnectPtr conn, virNetworkDHCPRangeDefParseXML(virNetworkDefPtr def,
virNetworkDefPtr def,
xmlNodePtr node) { xmlNodePtr node) {
xmlNodePtr cur; xmlNodePtr cur;
@ -246,7 +244,7 @@ virNetworkDHCPRangeDefParseXML(virConnectPtr conn,
} }
if (virSocketParseAddr(start, &saddr, 0) < 0) { if (virSocketParseAddr(start, &saddr, 0) < 0) {
virNetworkReportError(conn, VIR_ERR_XML_ERROR, virNetworkReportError(VIR_ERR_XML_ERROR,
_("cannot parse dhcp start address '%s'"), _("cannot parse dhcp start address '%s'"),
start); start);
xmlFree(start); xmlFree(start);
@ -255,7 +253,7 @@ virNetworkDHCPRangeDefParseXML(virConnectPtr conn,
continue; continue;
} }
if (virSocketParseAddr(end, &eaddr, 0) < 0) { if (virSocketParseAddr(end, &eaddr, 0) < 0) {
virNetworkReportError(conn, VIR_ERR_XML_ERROR, virNetworkReportError(VIR_ERR_XML_ERROR,
_("cannot parse dhcp end address '%s'"), _("cannot parse dhcp end address '%s'"),
end); end);
xmlFree(start); xmlFree(start);
@ -266,7 +264,7 @@ virNetworkDHCPRangeDefParseXML(virConnectPtr conn,
range = virSocketGetRange(&saddr, &eaddr); range = virSocketGetRange(&saddr, &eaddr);
if (range < 0) { if (range < 0) {
virNetworkReportError(conn, VIR_ERR_XML_ERROR, virNetworkReportError(VIR_ERR_XML_ERROR,
_("dhcp range '%s' to '%s' invalid"), _("dhcp range '%s' to '%s' invalid"),
start, end); start, end);
xmlFree(start); xmlFree(start);
@ -294,14 +292,14 @@ virNetworkDHCPRangeDefParseXML(virConnectPtr conn,
mac = xmlGetProp(cur, BAD_CAST "mac"); mac = xmlGetProp(cur, BAD_CAST "mac");
if ((mac != NULL) && if ((mac != NULL) &&
(virParseMacAddr((const char *) mac, &addr[0]) != 0)) { (virParseMacAddr((const char *) mac, &addr[0]) != 0)) {
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot parse MAC address '%s'"), _("cannot parse MAC address '%s'"),
mac); mac);
VIR_FREE(mac); VIR_FREE(mac);
} }
name = xmlGetProp(cur, BAD_CAST "name"); name = xmlGetProp(cur, BAD_CAST "name");
if ((name != NULL) && (!c_isalpha(name[0]))) { if ((name != NULL) && (!c_isalpha(name[0]))) {
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot use name address '%s'"), _("cannot use name address '%s'"),
name); name);
VIR_FREE(name); VIR_FREE(name);
@ -317,7 +315,7 @@ virNetworkDHCPRangeDefParseXML(virConnectPtr conn,
} }
ip = xmlGetProp(cur, BAD_CAST "ip"); ip = xmlGetProp(cur, BAD_CAST "ip");
if (inet_pton(AF_INET, (const char *) ip, &inaddress) <= 0) { if (inet_pton(AF_INET, (const char *) ip, &inaddress) <= 0) {
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot parse IP address '%s'"), _("cannot parse IP address '%s'"),
ip); ip);
VIR_FREE(ip); VIR_FREE(ip);
@ -358,8 +356,7 @@ virNetworkDHCPRangeDefParseXML(virConnectPtr conn,
} }
static int static int
virNetworkIPParseXML(virConnectPtr conn, virNetworkIPParseXML(virNetworkDefPtr def,
virNetworkDefPtr def,
xmlNodePtr node) { xmlNodePtr node) {
xmlNodePtr cur; xmlNodePtr cur;
@ -367,7 +364,7 @@ virNetworkIPParseXML(virConnectPtr conn,
while (cur != NULL) { while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE && if (cur->type == XML_ELEMENT_NODE &&
xmlStrEqual(cur->name, BAD_CAST "dhcp")) { xmlStrEqual(cur->name, BAD_CAST "dhcp")) {
int result = virNetworkDHCPRangeDefParseXML(conn, def, cur); int result = virNetworkDHCPRangeDefParseXML(def, cur);
if (result) if (result)
return result; return result;
@ -389,8 +386,7 @@ virNetworkIPParseXML(virConnectPtr conn,
} }
static virNetworkDefPtr static virNetworkDefPtr
virNetworkDefParseXML(virConnectPtr conn, virNetworkDefParseXML(xmlXPathContextPtr ctxt)
xmlXPathContextPtr ctxt)
{ {
virNetworkDefPtr def; virNetworkDefPtr def;
char *tmp; char *tmp;
@ -403,7 +399,7 @@ virNetworkDefParseXML(virConnectPtr conn,
/* Extract network name */ /* Extract network name */
def->name = virXPathString("string(./name[1])", ctxt); def->name = virXPathString("string(./name[1])", ctxt);
if (!def->name) { if (!def->name) {
virNetworkReportError(conn, VIR_ERR_NO_NAME, NULL); virNetworkReportError(VIR_ERR_NO_NAME, NULL);
goto error; goto error;
} }
@ -411,14 +407,14 @@ virNetworkDefParseXML(virConnectPtr conn,
tmp = virXPathString("string(./uuid[1])", ctxt); tmp = virXPathString("string(./uuid[1])", ctxt);
if (!tmp) { if (!tmp) {
if (virUUIDGenerate(def->uuid)) { if (virUUIDGenerate(def->uuid)) {
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Failed to generate UUID")); "%s", _("Failed to generate UUID"));
goto error; goto error;
} }
} else { } else {
if (virUUIDParse(tmp, def->uuid) < 0) { if (virUUIDParse(tmp, def->uuid) < 0) {
VIR_FREE(tmp); VIR_FREE(tmp);
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("malformed uuid element")); "%s", _("malformed uuid element"));
goto error; goto error;
} }
@ -447,13 +443,13 @@ virNetworkDefParseXML(virConnectPtr conn,
xmlNodePtr ip; xmlNodePtr ip;
if (inet_pton(AF_INET, def->ipAddress, &inaddress) <= 0) { if (inet_pton(AF_INET, def->ipAddress, &inaddress) <= 0) {
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot parse IP address '%s'"), _("cannot parse IP address '%s'"),
def->ipAddress); def->ipAddress);
goto error; goto error;
} }
if (inet_pton(AF_INET, def->netmask, &innetmask) <= 0) { if (inet_pton(AF_INET, def->netmask, &innetmask) <= 0) {
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot parse netmask '%s'"), _("cannot parse netmask '%s'"),
def->netmask); def->netmask);
goto error; goto error;
@ -468,7 +464,7 @@ virNetworkDefParseXML(virConnectPtr conn,
} }
if ((ip = virXPathNode("./ip[1]", ctxt)) && if ((ip = virXPathNode("./ip[1]", ctxt)) &&
virNetworkIPParseXML(conn, def, ip) < 0) virNetworkIPParseXML(def, ip) < 0)
goto error; goto error;
} }
@ -477,7 +473,7 @@ virNetworkDefParseXML(virConnectPtr conn,
if (virXPathBoolean("count(./forward) > 0", ctxt)) { if (virXPathBoolean("count(./forward) > 0", ctxt)) {
if (!def->ipAddress || if (!def->ipAddress ||
!def->netmask) { !def->netmask) {
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Forwarding requested, but no IPv4 address/netmask provided")); "%s", _("Forwarding requested, but no IPv4 address/netmask provided"));
goto error; goto error;
} }
@ -485,7 +481,7 @@ virNetworkDefParseXML(virConnectPtr conn,
tmp = virXPathString("string(./forward[1]/@mode)", ctxt); tmp = virXPathString("string(./forward[1]/@mode)", ctxt);
if (tmp) { if (tmp) {
if ((def->forwardType = virNetworkForwardTypeFromString(tmp)) < 0) { if ((def->forwardType = virNetworkForwardTypeFromString(tmp)) < 0) {
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
_("unknown forwarding type '%s'"), tmp); _("unknown forwarding type '%s'"), tmp);
VIR_FREE(tmp); VIR_FREE(tmp);
goto error; goto error;
@ -515,13 +511,10 @@ catchXMLError (void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
if (ctxt) { if (ctxt) {
virConnectPtr conn = ctxt->_private; if (virGetLastError() == NULL &&
if (conn &&
conn->err.code == VIR_ERR_NONE &&
ctxt->lastError.level == XML_ERR_FATAL && ctxt->lastError.level == XML_ERR_FATAL &&
ctxt->lastError.message != NULL) { ctxt->lastError.message != NULL) {
virNetworkReportError (conn, VIR_ERR_XML_DETAIL, virNetworkReportError(VIR_ERR_XML_DETAIL,
_("at line %d: %s"), _("at line %d: %s"),
ctxt->lastError.line, ctxt->lastError.line,
ctxt->lastError.message); ctxt->lastError.message);
@ -529,8 +522,7 @@ catchXMLError (void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
} }
} }
virNetworkDefPtr virNetworkDefParseString(virConnectPtr conn, virNetworkDefPtr virNetworkDefParseString(const char *xmlStr)
const char *xmlStr)
{ {
xmlParserCtxtPtr pctxt; xmlParserCtxtPtr pctxt;
xmlDocPtr xml = NULL; xmlDocPtr xml = NULL;
@ -542,26 +534,24 @@ virNetworkDefPtr virNetworkDefParseString(virConnectPtr conn,
if (!pctxt || !pctxt->sax) if (!pctxt || !pctxt->sax)
goto cleanup; goto cleanup;
pctxt->sax->error = catchXMLError; pctxt->sax->error = catchXMLError;
pctxt->_private = conn;
if (conn) virResetError (&conn->err);
xml = xmlCtxtReadDoc (pctxt, BAD_CAST xmlStr, "network.xml", NULL, xml = xmlCtxtReadDoc (pctxt, BAD_CAST xmlStr, "network.xml", NULL,
XML_PARSE_NOENT | XML_PARSE_NONET | XML_PARSE_NOENT | XML_PARSE_NONET |
XML_PARSE_NOWARNING); XML_PARSE_NOWARNING);
if (!xml) { if (!xml) {
if (conn && conn->err.code == VIR_ERR_NONE) if (virGetLastError() == NULL)
virNetworkReportError(conn, VIR_ERR_XML_ERROR, virNetworkReportError(VIR_ERR_XML_ERROR,
"%s", _("failed to parse xml document")); "%s", _("failed to parse xml document"));
goto cleanup; goto cleanup;
} }
if ((root = xmlDocGetRootElement(xml)) == NULL) { if ((root = xmlDocGetRootElement(xml)) == NULL) {
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("missing root element")); "%s", _("missing root element"));
goto cleanup; goto cleanup;
} }
def = virNetworkDefParseNode(conn, xml, root); def = virNetworkDefParseNode(xml, root);
cleanup: cleanup:
xmlFreeParserCtxt (pctxt); xmlFreeParserCtxt (pctxt);
@ -569,8 +559,7 @@ cleanup:
return def; return def;
} }
virNetworkDefPtr virNetworkDefParseFile(virConnectPtr conn, virNetworkDefPtr virNetworkDefParseFile(const char *filename)
const char *filename)
{ {
xmlParserCtxtPtr pctxt; xmlParserCtxtPtr pctxt;
xmlDocPtr xml = NULL; xmlDocPtr xml = NULL;
@ -582,26 +571,24 @@ virNetworkDefPtr virNetworkDefParseFile(virConnectPtr conn,
if (!pctxt || !pctxt->sax) if (!pctxt || !pctxt->sax)
goto cleanup; goto cleanup;
pctxt->sax->error = catchXMLError; pctxt->sax->error = catchXMLError;
pctxt->_private = conn;
if (conn) virResetError (&conn->err);
xml = xmlCtxtReadFile (pctxt, filename, NULL, xml = xmlCtxtReadFile (pctxt, filename, NULL,
XML_PARSE_NOENT | XML_PARSE_NONET | XML_PARSE_NOENT | XML_PARSE_NONET |
XML_PARSE_NOWARNING); XML_PARSE_NOWARNING);
if (!xml) { if (!xml) {
if (conn && conn->err.code == VIR_ERR_NONE) if (virGetLastError() == NULL)
virNetworkReportError(conn, VIR_ERR_XML_ERROR, virNetworkReportError(VIR_ERR_XML_ERROR,
"%s", _("failed to parse xml document")); "%s", _("failed to parse xml document"));
goto cleanup; goto cleanup;
} }
if ((root = xmlDocGetRootElement(xml)) == NULL) { if ((root = xmlDocGetRootElement(xml)) == NULL) {
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("missing root element")); "%s", _("missing root element"));
goto cleanup; goto cleanup;
} }
def = virNetworkDefParseNode(conn, xml, root); def = virNetworkDefParseNode(xml, root);
cleanup: cleanup:
xmlFreeParserCtxt (pctxt); xmlFreeParserCtxt (pctxt);
@ -610,15 +597,14 @@ cleanup:
} }
virNetworkDefPtr virNetworkDefParseNode(virConnectPtr conn, virNetworkDefPtr virNetworkDefParseNode(xmlDocPtr xml,
xmlDocPtr xml,
xmlNodePtr root) xmlNodePtr root)
{ {
xmlXPathContextPtr ctxt = NULL; xmlXPathContextPtr ctxt = NULL;
virNetworkDefPtr def = NULL; virNetworkDefPtr def = NULL;
if (!xmlStrEqual(root->name, BAD_CAST "network")) { if (!xmlStrEqual(root->name, BAD_CAST "network")) {
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("incorrect root element")); "%s", _("incorrect root element"));
return NULL; return NULL;
} }
@ -630,15 +616,14 @@ virNetworkDefPtr virNetworkDefParseNode(virConnectPtr conn,
} }
ctxt->node = root; ctxt->node = root;
def = virNetworkDefParseXML(conn, ctxt); def = virNetworkDefParseXML(ctxt);
cleanup: cleanup:
xmlXPathFreeContext(ctxt); xmlXPathFreeContext(ctxt);
return def; return def;
} }
char *virNetworkDefFormat(virConnectPtr conn ATTRIBUTE_UNUSED /*TEMPORARY*/, char *virNetworkDefFormat(const virNetworkDefPtr def)
const virNetworkDefPtr def)
{ {
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
unsigned char *uuid; unsigned char *uuid;
@ -734,8 +719,7 @@ char *virNetworkDefFormat(virConnectPtr conn ATTRIBUTE_UNUSED /*TEMPORARY*/,
return NULL; return NULL;
} }
int virNetworkSaveXML(virConnectPtr conn, int virNetworkSaveXML(const char *configDir,
const char *configDir,
virNetworkDefPtr def, virNetworkDefPtr def,
const char *xml) const char *xml)
{ {
@ -744,7 +728,7 @@ int virNetworkSaveXML(virConnectPtr conn,
size_t towrite; size_t towrite;
int err; int err;
if ((configFile = virNetworkConfigFile(conn, configDir, def->name)) == NULL) if ((configFile = virNetworkConfigFile(configDir, def->name)) == NULL)
goto cleanup; goto cleanup;
if ((err = virFileMakePath(configDir))) { if ((err = virFileMakePath(configDir))) {
@ -789,17 +773,16 @@ int virNetworkSaveXML(virConnectPtr conn,
return ret; return ret;
} }
int virNetworkSaveConfig(virConnectPtr conn, int virNetworkSaveConfig(const char *configDir,
const char *configDir,
virNetworkDefPtr def) virNetworkDefPtr def)
{ {
int ret = -1; int ret = -1;
char *xml; char *xml;
if (!(xml = virNetworkDefFormat(conn, def))) if (!(xml = virNetworkDefFormat(def)))
goto cleanup; goto cleanup;
if (virNetworkSaveXML(conn, configDir, def, xml)) if (virNetworkSaveXML(configDir, def, xml))
goto cleanup; goto cleanup;
ret = 0; ret = 0;
@ -809,8 +792,7 @@ cleanup:
} }
virNetworkObjPtr virNetworkLoadConfig(virConnectPtr conn, virNetworkObjPtr virNetworkLoadConfig(virNetworkObjListPtr nets,
virNetworkObjListPtr nets,
const char *configDir, const char *configDir,
const char *autostartDir, const char *autostartDir,
const char *name) const char *name)
@ -820,19 +802,19 @@ virNetworkObjPtr virNetworkLoadConfig(virConnectPtr conn,
virNetworkObjPtr net; virNetworkObjPtr net;
int autostart; int autostart;
if ((configFile = virNetworkConfigFile(conn, configDir, name)) == NULL) if ((configFile = virNetworkConfigFile(configDir, name)) == NULL)
goto error; goto error;
if ((autostartLink = virNetworkConfigFile(conn, autostartDir, name)) == NULL) if ((autostartLink = virNetworkConfigFile(autostartDir, name)) == NULL)
goto error; goto error;
if ((autostart = virFileLinkPointsTo(autostartLink, configFile)) < 0) if ((autostart = virFileLinkPointsTo(autostartLink, configFile)) < 0)
goto error; goto error;
if (!(def = virNetworkDefParseFile(conn, configFile))) if (!(def = virNetworkDefParseFile(configFile)))
goto error; goto error;
if (!STREQ(name, def->name)) { if (!STREQ(name, def->name)) {
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
_("Network config filename '%s'" _("Network config filename '%s'"
" does not match network name '%s'"), " does not match network name '%s'"),
configFile, def->name); configFile, def->name);
@ -842,10 +824,10 @@ virNetworkObjPtr virNetworkLoadConfig(virConnectPtr conn,
/* Generate a bridge if none is specified, but don't check for collisions /* Generate a bridge if none is specified, but don't check for collisions
* if a bridge is hardcoded, so the network is at least defined * if a bridge is hardcoded, so the network is at least defined
*/ */
if (virNetworkSetBridgeName(conn, nets, def, 0)) if (virNetworkSetBridgeName(nets, def, 0))
goto error; goto error;
if (!(net = virNetworkAssignDef(conn, nets, def))) if (!(net = virNetworkAssignDef(nets, def)))
goto error; goto error;
net->autostart = autostart; net->autostart = autostart;
@ -863,8 +845,7 @@ error:
return NULL; return NULL;
} }
int virNetworkLoadAllConfigs(virConnectPtr conn, int virNetworkLoadAllConfigs(virNetworkObjListPtr nets,
virNetworkObjListPtr nets,
const char *configDir, const char *configDir,
const char *autostartDir) const char *autostartDir)
{ {
@ -891,8 +872,7 @@ int virNetworkLoadAllConfigs(virConnectPtr conn,
/* NB: ignoring errors, so one malformed config doesn't /* NB: ignoring errors, so one malformed config doesn't
kill the whole process */ kill the whole process */
net = virNetworkLoadConfig(conn, net = virNetworkLoadConfig(nets,
nets,
configDir, configDir,
autostartDir, autostartDir,
entry->d_name); entry->d_name);
@ -905,8 +885,7 @@ int virNetworkLoadAllConfigs(virConnectPtr conn,
return 0; return 0;
} }
int virNetworkDeleteConfig(virConnectPtr conn, int virNetworkDeleteConfig(const char *configDir,
const char *configDir,
const char *autostartDir, const char *autostartDir,
virNetworkObjPtr net) virNetworkObjPtr net)
{ {
@ -914,9 +893,9 @@ int virNetworkDeleteConfig(virConnectPtr conn,
char *autostartLink = NULL; char *autostartLink = NULL;
int ret = -1; int ret = -1;
if ((configFile = virNetworkConfigFile(conn, configDir, net->def->name)) == NULL) if ((configFile = virNetworkConfigFile(configDir, net->def->name)) == NULL)
goto error; goto error;
if ((autostartLink = virNetworkConfigFile(conn, autostartDir, net->def->name)) == NULL) if ((autostartLink = virNetworkConfigFile(autostartDir, net->def->name)) == NULL)
goto error; goto error;
/* Not fatal if this doesn't work */ /* Not fatal if this doesn't work */
@ -937,8 +916,7 @@ error:
return ret; return ret;
} }
char *virNetworkConfigFile(virConnectPtr conn ATTRIBUTE_UNUSED /*TEMPORARY*/, char *virNetworkConfigFile(const char *dir,
const char *dir,
const char *name) const char *name)
{ {
char *ret = NULL; char *ret = NULL;
@ -970,8 +948,7 @@ int virNetworkBridgeInUse(const virNetworkObjListPtr nets,
return ret; return ret;
} }
char *virNetworkAllocateBridge(virConnectPtr conn, char *virNetworkAllocateBridge(const virNetworkObjListPtr nets,
const virNetworkObjListPtr nets,
const char *template) const char *template)
{ {
@ -997,14 +974,13 @@ char *virNetworkAllocateBridge(virConnectPtr conn,
id++; id++;
} while (id <= MAX_BRIDGE_ID); } while (id <= MAX_BRIDGE_ID);
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR, virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
_("Bridge generation exceeded max id %d"), _("Bridge generation exceeded max id %d"),
MAX_BRIDGE_ID); MAX_BRIDGE_ID);
return NULL; return NULL;
} }
int virNetworkSetBridgeName(virConnectPtr conn, int virNetworkSetBridgeName(const virNetworkObjListPtr nets,
const virNetworkObjListPtr nets,
virNetworkDefPtr def, virNetworkDefPtr def,
int check_collision) { int check_collision) {
@ -1016,14 +992,14 @@ int virNetworkSetBridgeName(virConnectPtr conn,
* defined. */ * defined. */
if (check_collision && if (check_collision &&
virNetworkBridgeInUse(nets, def->bridge, def->name)) { virNetworkBridgeInUse(nets, def->bridge, def->name)) {
networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
_("bridge name '%s' already in use."), _("bridge name '%s' already in use."),
def->bridge); def->bridge);
goto error; goto error;
} }
} else { } else {
/* Allocate a bridge name */ /* Allocate a bridge name */
if (!(def->bridge = virNetworkAllocateBridge(conn, nets, def->bridge))) if (!(def->bridge = virNetworkAllocateBridge(nets, def->bridge)))
goto error; goto error;
} }

View File

@ -112,11 +112,6 @@ virNetworkObjIsActive(const virNetworkObjPtr net)
return net->active; return net->active;
} }
#define networkReportError(conn, dom, net, code, fmt...) \
virReportErrorHelper(conn, VIR_FROM_QEMU, code, __FILE__, \
__FUNCTION__, __LINE__, fmt)
virNetworkObjPtr virNetworkFindByUUID(const virNetworkObjListPtr nets, virNetworkObjPtr virNetworkFindByUUID(const virNetworkObjListPtr nets,
const unsigned char *uuid); const unsigned char *uuid);
virNetworkObjPtr virNetworkFindByName(const virNetworkObjListPtr nets, virNetworkObjPtr virNetworkFindByName(const virNetworkObjListPtr nets,
@ -127,63 +122,50 @@ void virNetworkDefFree(virNetworkDefPtr def);
void virNetworkObjFree(virNetworkObjPtr net); void virNetworkObjFree(virNetworkObjPtr net);
void virNetworkObjListFree(virNetworkObjListPtr vms); void virNetworkObjListFree(virNetworkObjListPtr vms);
virNetworkObjPtr virNetworkAssignDef(virConnectPtr conn, virNetworkObjPtr virNetworkAssignDef(virNetworkObjListPtr nets,
virNetworkObjListPtr nets,
const virNetworkDefPtr def); const virNetworkDefPtr def);
void virNetworkRemoveInactive(virNetworkObjListPtr nets, void virNetworkRemoveInactive(virNetworkObjListPtr nets,
const virNetworkObjPtr net); const virNetworkObjPtr net);
virNetworkDefPtr virNetworkDefParseString(virConnectPtr conn, virNetworkDefPtr virNetworkDefParseString(const char *xmlStr);
const char *xmlStr); virNetworkDefPtr virNetworkDefParseFile(const char *filename);
virNetworkDefPtr virNetworkDefParseFile(virConnectPtr conn, virNetworkDefPtr virNetworkDefParseNode(xmlDocPtr xml,
const char *filename);
virNetworkDefPtr virNetworkDefParseNode(virConnectPtr conn,
xmlDocPtr xml,
xmlNodePtr root); xmlNodePtr root);
char *virNetworkDefFormat(virConnectPtr conn, char *virNetworkDefFormat(const virNetworkDefPtr def);
const virNetworkDefPtr def);
int virNetworkSaveXML(virConnectPtr conn, int virNetworkSaveXML(const char *configDir,
const char *configDir,
virNetworkDefPtr def, virNetworkDefPtr def,
const char *xml); const char *xml);
int virNetworkSaveConfig(virConnectPtr conn, int virNetworkSaveConfig(const char *configDir,
const char *configDir,
virNetworkDefPtr def); virNetworkDefPtr def);
virNetworkObjPtr virNetworkLoadConfig(virConnectPtr conn, virNetworkObjPtr virNetworkLoadConfig(virNetworkObjListPtr nets,
virNetworkObjListPtr nets,
const char *configDir, const char *configDir,
const char *autostartDir, const char *autostartDir,
const char *file); const char *file);
int virNetworkLoadAllConfigs(virConnectPtr conn, int virNetworkLoadAllConfigs(virNetworkObjListPtr nets,
virNetworkObjListPtr nets,
const char *configDir, const char *configDir,
const char *autostartDir); const char *autostartDir);
int virNetworkDeleteConfig(virConnectPtr conn, int virNetworkDeleteConfig(const char *configDir,
const char *configDir,
const char *autostartDir, const char *autostartDir,
virNetworkObjPtr net); virNetworkObjPtr net);
char *virNetworkConfigFile(virConnectPtr conn, char *virNetworkConfigFile(const char *dir,
const char *dir,
const char *name); const char *name);
int virNetworkBridgeInUse(const virNetworkObjListPtr nets, int virNetworkBridgeInUse(const virNetworkObjListPtr nets,
const char *bridge, const char *bridge,
const char *skipname); const char *skipname);
char *virNetworkAllocateBridge(virConnectPtr conn, char *virNetworkAllocateBridge(const virNetworkObjListPtr nets,
const virNetworkObjListPtr nets,
const char *template); const char *template);
int virNetworkSetBridgeName(virConnectPtr conn, int virNetworkSetBridgeName(const virNetworkObjListPtr nets,
const virNetworkObjListPtr nets,
virNetworkDefPtr def, virNetworkDefPtr def,
int check_collision); int check_collision);

View File

@ -63,6 +63,10 @@
#define VIR_FROM_THIS VIR_FROM_NETWORK #define VIR_FROM_THIS VIR_FROM_NETWORK
#define networkReportError(code, fmt...) \
virReportErrorHelper(NULL, VIR_FROM_NETWORK, code, __FILE__, \
__FUNCTION__, __LINE__, fmt)
/* Main driver state */ /* Main driver state */
struct network_driver { struct network_driver {
virMutex lock; virMutex lock;
@ -88,12 +92,10 @@ static void networkDriverUnlock(struct network_driver *driver)
static int networkShutdown(void); static int networkShutdown(void);
static int networkStartNetworkDaemon(virConnectPtr conn, static int networkStartNetworkDaemon(struct network_driver *driver,
struct network_driver *driver,
virNetworkObjPtr network); virNetworkObjPtr network);
static int networkShutdownNetworkDaemon(virConnectPtr conn, static int networkShutdownNetworkDaemon(struct network_driver *driver,
struct network_driver *driver,
virNetworkObjPtr network); virNetworkObjPtr network);
static void networkReloadIptablesRules(struct network_driver *driver); static void networkReloadIptablesRules(struct network_driver *driver);
@ -112,8 +114,7 @@ networkFindActiveConfigs(struct network_driver *driver) {
virNetworkObjLock(obj); virNetworkObjLock(obj);
if ((config = virNetworkConfigFile(NULL, if ((config = virNetworkConfigFile(NETWORK_STATE_DIR,
NETWORK_STATE_DIR,
obj->def->name)) == NULL) { obj->def->name)) == NULL) {
virNetworkObjUnlock(obj); virNetworkObjUnlock(obj);
continue; continue;
@ -126,7 +127,7 @@ networkFindActiveConfigs(struct network_driver *driver) {
} }
/* Try and load the live config */ /* Try and load the live config */
tmp = virNetworkDefParseFile(NULL, config); tmp = virNetworkDefParseFile(config);
VIR_FREE(config); VIR_FREE(config);
if (tmp) { if (tmp) {
obj->newDef = obj->def; obj->newDef = obj->def;
@ -176,7 +177,7 @@ networkAutostartConfigs(struct network_driver *driver) {
virNetworkObjLock(driver->networks.objs[i]); virNetworkObjLock(driver->networks.objs[i]);
if (driver->networks.objs[i]->autostart && if (driver->networks.objs[i]->autostart &&
!virNetworkObjIsActive(driver->networks.objs[i]) && !virNetworkObjIsActive(driver->networks.objs[i]) &&
networkStartNetworkDaemon(NULL, driver, driver->networks.objs[i]) < 0) { networkStartNetworkDaemon(driver, driver->networks.objs[i]) < 0) {
/* failed to start but already logged */ /* failed to start but already logged */
} }
virNetworkObjUnlock(driver->networks.objs[i]); virNetworkObjUnlock(driver->networks.objs[i]);
@ -252,8 +253,7 @@ networkStartup(int privileged) {
} }
if (virNetworkLoadAllConfigs(NULL, if (virNetworkLoadAllConfigs(&driverState->networks,
&driverState->networks,
driverState->networkConfigDir, driverState->networkConfigDir,
driverState->networkAutostartDir) < 0) driverState->networkAutostartDir) < 0)
goto error; goto error;
@ -290,8 +290,7 @@ networkReload(void) {
return 0; return 0;
networkDriverLock(driverState); networkDriverLock(driverState);
virNetworkLoadAllConfigs(NULL, virNetworkLoadAllConfigs(&driverState->networks,
&driverState->networks,
driverState->networkConfigDir, driverState->networkConfigDir,
driverState->networkAutostartDir); driverState->networkAutostartDir);
networkReloadIptablesRules(driverState); networkReloadIptablesRules(driverState);
@ -523,8 +522,7 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
static int static int
dhcpStartDhcpDaemon(virConnectPtr conn, dhcpStartDhcpDaemon(virNetworkObjPtr network)
virNetworkObjPtr network)
{ {
const char **argv; const char **argv;
char *pidfile; char *pidfile;
@ -533,7 +531,7 @@ dhcpStartDhcpDaemon(virConnectPtr conn,
network->dnsmasqPid = -1; network->dnsmasqPid = -1;
if (network->def->ipAddress == NULL) { if (network->def->ipAddress == NULL) {
networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, networkReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot start dhcp daemon without IP address for server")); "%s", _("cannot start dhcp daemon without IP address for server"));
return -1; return -1;
} }
@ -885,13 +883,13 @@ cleanup:
return ret; return ret;
} }
static int networkStartNetworkDaemon(virConnectPtr conn, static int networkStartNetworkDaemon(struct network_driver *driver,
struct network_driver *driver, virNetworkObjPtr network)
virNetworkObjPtr network) { {
int err; int err;
if (virNetworkObjIsActive(network)) { if (virNetworkObjIsActive(network)) {
networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, networkReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("network is already active")); "%s", _("network is already active"));
return -1; return -1;
} }
@ -947,12 +945,12 @@ static int networkStartNetworkDaemon(virConnectPtr conn,
if ((network->def->ipAddress || if ((network->def->ipAddress ||
network->def->nranges) && network->def->nranges) &&
dhcpStartDhcpDaemon(conn, network) < 0) dhcpStartDhcpDaemon(network) < 0)
goto err_delbr2; goto err_delbr2;
/* Persist the live configuration now we have bridge info */ /* Persist the live configuration now we have bridge info */
if (virNetworkSaveConfig(conn, NETWORK_STATE_DIR, network->def) < 0) { if (virNetworkSaveConfig(NETWORK_STATE_DIR, network->def) < 0) {
goto err_kill; goto err_kill;
} }
@ -987,9 +985,9 @@ static int networkStartNetworkDaemon(virConnectPtr conn,
} }
static int networkShutdownNetworkDaemon(virConnectPtr conn, static int networkShutdownNetworkDaemon(struct network_driver *driver,
struct network_driver *driver, virNetworkObjPtr network)
virNetworkObjPtr network) { {
int err; int err;
char *stateFile; char *stateFile;
@ -998,7 +996,7 @@ static int networkShutdownNetworkDaemon(virConnectPtr conn,
if (!virNetworkObjIsActive(network)) if (!virNetworkObjIsActive(network))
return 0; return 0;
stateFile = virNetworkConfigFile(conn, NETWORK_STATE_DIR, network->def->name); stateFile = virNetworkConfigFile(NETWORK_STATE_DIR, network->def->name);
if (!stateFile) if (!stateFile)
return -1; return -1;
@ -1049,7 +1047,7 @@ static virNetworkPtr networkLookupByUUID(virConnectPtr conn,
network = virNetworkFindByUUID(&driver->networks, uuid); network = virNetworkFindByUUID(&driver->networks, uuid);
networkDriverUnlock(driver); networkDriverUnlock(driver);
if (!network) { if (!network) {
networkReportError(conn, NULL, NULL, VIR_ERR_NO_NETWORK, networkReportError(VIR_ERR_NO_NETWORK,
"%s", _("no network with matching uuid")); "%s", _("no network with matching uuid"));
goto cleanup; goto cleanup;
} }
@ -1072,7 +1070,7 @@ static virNetworkPtr networkLookupByName(virConnectPtr conn,
network = virNetworkFindByName(&driver->networks, name); network = virNetworkFindByName(&driver->networks, name);
networkDriverUnlock(driver); networkDriverUnlock(driver);
if (!network) { if (!network) {
networkReportError(conn, NULL, NULL, VIR_ERR_NO_NETWORK, networkReportError(VIR_ERR_NO_NETWORK,
_("no network with matching name '%s'"), name); _("no network with matching name '%s'"), name);
goto cleanup; goto cleanup;
} }
@ -1198,7 +1196,7 @@ static int networkIsActive(virNetworkPtr net)
obj = virNetworkFindByUUID(&driver->networks, net->uuid); obj = virNetworkFindByUUID(&driver->networks, net->uuid);
networkDriverUnlock(driver); networkDriverUnlock(driver);
if (!obj) { if (!obj) {
networkReportError(net->conn, NULL, NULL, VIR_ERR_NO_NETWORK, NULL); networkReportError(VIR_ERR_NO_NETWORK, NULL);
goto cleanup; goto cleanup;
} }
ret = virNetworkObjIsActive(obj); ret = virNetworkObjIsActive(obj);
@ -1219,7 +1217,7 @@ static int networkIsPersistent(virNetworkPtr net)
obj = virNetworkFindByUUID(&driver->networks, net->uuid); obj = virNetworkFindByUUID(&driver->networks, net->uuid);
networkDriverUnlock(driver); networkDriverUnlock(driver);
if (!obj) { if (!obj) {
networkReportError(net->conn, NULL, NULL, VIR_ERR_NO_NETWORK, NULL); networkReportError(VIR_ERR_NO_NETWORK, NULL);
goto cleanup; goto cleanup;
} }
ret = obj->persistent; ret = obj->persistent;
@ -1239,19 +1237,18 @@ static virNetworkPtr networkCreate(virConnectPtr conn, const char *xml) {
networkDriverLock(driver); networkDriverLock(driver);
if (!(def = virNetworkDefParseString(conn, xml))) if (!(def = virNetworkDefParseString(xml)))
goto cleanup; goto cleanup;
if (virNetworkSetBridgeName(conn, &driver->networks, def, 1)) if (virNetworkSetBridgeName(&driver->networks, def, 1))
goto cleanup; goto cleanup;
if (!(network = virNetworkAssignDef(conn, if (!(network = virNetworkAssignDef(&driver->networks,
&driver->networks,
def))) def)))
goto cleanup; goto cleanup;
def = NULL; def = NULL;
if (networkStartNetworkDaemon(conn, driver, network) < 0) { if (networkStartNetworkDaemon(driver, network) < 0) {
virNetworkRemoveInactive(&driver->networks, virNetworkRemoveInactive(&driver->networks,
network); network);
network = NULL; network = NULL;
@ -1276,22 +1273,20 @@ static virNetworkPtr networkDefine(virConnectPtr conn, const char *xml) {
networkDriverLock(driver); networkDriverLock(driver);
if (!(def = virNetworkDefParseString(conn, xml))) if (!(def = virNetworkDefParseString(xml)))
goto cleanup; goto cleanup;
if (virNetworkSetBridgeName(conn, &driver->networks, def, 1)) if (virNetworkSetBridgeName(&driver->networks, def, 1))
goto cleanup; goto cleanup;
if (!(network = virNetworkAssignDef(conn, if (!(network = virNetworkAssignDef(&driver->networks,
&driver->networks,
def))) def)))
goto cleanup; goto cleanup;
def = NULL; def = NULL;
network->persistent = 1; network->persistent = 1;
if (virNetworkSaveConfig(conn, if (virNetworkSaveConfig(driver->networkConfigDir,
driver->networkConfigDir,
network->newDef ? network->newDef : network->def) < 0) { network->newDef ? network->newDef : network->def) < 0) {
virNetworkRemoveInactive(&driver->networks, virNetworkRemoveInactive(&driver->networks,
network); network);
@ -1318,19 +1313,18 @@ static int networkUndefine(virNetworkPtr net) {
network = virNetworkFindByUUID(&driver->networks, net->uuid); network = virNetworkFindByUUID(&driver->networks, net->uuid);
if (!network) { if (!network) {
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK, networkReportError(VIR_ERR_INVALID_NETWORK,
"%s", _("no network with matching uuid")); "%s", _("no network with matching uuid"));
goto cleanup; goto cleanup;
} }
if (virNetworkObjIsActive(network)) { if (virNetworkObjIsActive(network)) {
networkReportError(net->conn, NULL, net, VIR_ERR_INTERNAL_ERROR, networkReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("network is still active")); "%s", _("network is still active"));
goto cleanup; goto cleanup;
} }
if (virNetworkDeleteConfig(net->conn, if (virNetworkDeleteConfig(driver->networkConfigDir,
driver->networkConfigDir,
driver->networkAutostartDir, driver->networkAutostartDir,
network) < 0) network) < 0)
goto cleanup; goto cleanup;
@ -1356,12 +1350,12 @@ static int networkStart(virNetworkPtr net) {
network = virNetworkFindByUUID(&driver->networks, net->uuid); network = virNetworkFindByUUID(&driver->networks, net->uuid);
if (!network) { if (!network) {
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK, networkReportError(VIR_ERR_INVALID_NETWORK,
"%s", _("no network with matching uuid")); "%s", _("no network with matching uuid"));
goto cleanup; goto cleanup;
} }
ret = networkStartNetworkDaemon(net->conn, driver, network); ret = networkStartNetworkDaemon(driver, network);
cleanup: cleanup:
if (network) if (network)
@ -1379,18 +1373,18 @@ static int networkDestroy(virNetworkPtr net) {
network = virNetworkFindByUUID(&driver->networks, net->uuid); network = virNetworkFindByUUID(&driver->networks, net->uuid);
if (!network) { if (!network) {
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK, networkReportError(VIR_ERR_INVALID_NETWORK,
"%s", _("no network with matching uuid")); "%s", _("no network with matching uuid"));
goto cleanup; goto cleanup;
} }
if (!virNetworkObjIsActive(network)) { if (!virNetworkObjIsActive(network)) {
networkReportError(net->conn, NULL, net, VIR_ERR_INTERNAL_ERROR, networkReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("network is not active")); "%s", _("network is not active"));
goto cleanup; goto cleanup;
} }
ret = networkShutdownNetworkDaemon(net->conn, driver, network); ret = networkShutdownNetworkDaemon(driver, network);
if (!network->persistent) { if (!network->persistent) {
virNetworkRemoveInactive(&driver->networks, virNetworkRemoveInactive(&driver->networks,
network); network);
@ -1414,12 +1408,12 @@ static char *networkDumpXML(virNetworkPtr net, int flags ATTRIBUTE_UNUSED) {
networkDriverUnlock(driver); networkDriverUnlock(driver);
if (!network) { if (!network) {
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK, networkReportError(VIR_ERR_INVALID_NETWORK,
"%s", _("no network with matching uuid")); "%s", _("no network with matching uuid"));
goto cleanup; goto cleanup;
} }
ret = virNetworkDefFormat(net->conn, network->def); ret = virNetworkDefFormat(network->def);
cleanup: cleanup:
if (network) if (network)
@ -1437,13 +1431,13 @@ static char *networkGetBridgeName(virNetworkPtr net) {
networkDriverUnlock(driver); networkDriverUnlock(driver);
if (!network) { if (!network) {
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK, networkReportError(VIR_ERR_INVALID_NETWORK,
"%s", _("no network with matching id")); "%s", _("no network with matching id"));
goto cleanup; goto cleanup;
} }
if (!(network->def->bridge)) { if (!(network->def->bridge)) {
networkReportError(net->conn, NULL, net, VIR_ERR_INTERNAL_ERROR, networkReportError(VIR_ERR_INTERNAL_ERROR,
_("network '%s' does not have a bridge name."), _("network '%s' does not have a bridge name."),
network->def->name); network->def->name);
goto cleanup; goto cleanup;
@ -1469,7 +1463,7 @@ static int networkGetAutostart(virNetworkPtr net,
network = virNetworkFindByUUID(&driver->networks, net->uuid); network = virNetworkFindByUUID(&driver->networks, net->uuid);
networkDriverUnlock(driver); networkDriverUnlock(driver);
if (!network) { if (!network) {
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK, networkReportError(VIR_ERR_INVALID_NETWORK,
"%s", _("no network with matching uuid")); "%s", _("no network with matching uuid"));
goto cleanup; goto cleanup;
} }
@ -1494,13 +1488,13 @@ static int networkSetAutostart(virNetworkPtr net,
network = virNetworkFindByUUID(&driver->networks, net->uuid); network = virNetworkFindByUUID(&driver->networks, net->uuid);
if (!network) { if (!network) {
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK, networkReportError(VIR_ERR_INVALID_NETWORK,
"%s", _("no network with matching uuid")); "%s", _("no network with matching uuid"));
goto cleanup; goto cleanup;
} }
if (!network->persistent) { if (!network->persistent) {
networkReportError(net->conn, NULL, net, VIR_ERR_INTERNAL_ERROR, networkReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot set autostart for transient network")); "%s", _("cannot set autostart for transient network"));
goto cleanup; goto cleanup;
} }
@ -1508,9 +1502,9 @@ static int networkSetAutostart(virNetworkPtr net,
autostart = (autostart != 0); autostart = (autostart != 0);
if (network->autostart != autostart) { if (network->autostart != autostart) {
if ((configFile = virNetworkConfigFile(net->conn, driver->networkConfigDir, network->def->name)) == NULL) if ((configFile = virNetworkConfigFile(driver->networkConfigDir, network->def->name)) == NULL)
goto cleanup; goto cleanup;
if ((autostartLink = virNetworkConfigFile(net->conn, driver->networkAutostartDir, network->def->name)) == NULL) if ((autostartLink = virNetworkConfigFile(driver->networkAutostartDir, network->def->name)) == NULL)
goto cleanup; goto cleanup;
if (autostart) { if (autostart) {

View File

@ -558,9 +558,9 @@ static int testOpenDefault(virConnectPtr conn) {
domobj->persistent = 1; domobj->persistent = 1;
virDomainObjUnlock(domobj); virDomainObjUnlock(domobj);
if (!(netdef = virNetworkDefParseString(conn, defaultNetworkXML))) if (!(netdef = virNetworkDefParseString(defaultNetworkXML)))
goto error; goto error;
if (!(netobj = virNetworkAssignDef(conn, &privconn->networks, netdef))) { if (!(netobj = virNetworkAssignDef(&privconn->networks, netdef))) {
virNetworkDefFree(netdef); virNetworkDefFree(netdef);
goto error; goto error;
} }
@ -934,15 +934,15 @@ static int testOpenFromFile(virConnectPtr conn,
goto error; goto error;
} }
def = virNetworkDefParseFile(conn, absFile); def = virNetworkDefParseFile(absFile);
VIR_FREE(absFile); VIR_FREE(absFile);
if (!def) if (!def)
goto error; goto error;
} else { } else {
if ((def = virNetworkDefParseNode(conn, xml, networks[i])) == NULL) if ((def = virNetworkDefParseNode(xml, networks[i])) == NULL)
goto error; goto error;
} }
if (!(net = virNetworkAssignDef(conn, &privconn->networks, if (!(net = virNetworkAssignDef(&privconn->networks,
def))) { def))) {
virNetworkDefFree(def); virNetworkDefFree(def);
goto error; goto error;
@ -2881,10 +2881,10 @@ static virNetworkPtr testNetworkCreate(virConnectPtr conn, const char *xml) {
virNetworkPtr ret = NULL; virNetworkPtr ret = NULL;
testDriverLock(privconn); testDriverLock(privconn);
if ((def = virNetworkDefParseString(conn, xml)) == NULL) if ((def = virNetworkDefParseString(xml)) == NULL)
goto cleanup; goto cleanup;
if ((net = virNetworkAssignDef(conn, &privconn->networks, def)) == NULL) if ((net = virNetworkAssignDef(&privconn->networks, def)) == NULL)
goto cleanup; goto cleanup;
def = NULL; def = NULL;
net->active = 1; net->active = 1;
@ -2906,10 +2906,10 @@ static virNetworkPtr testNetworkDefine(virConnectPtr conn, const char *xml) {
virNetworkPtr ret = NULL; virNetworkPtr ret = NULL;
testDriverLock(privconn); testDriverLock(privconn);
if ((def = virNetworkDefParseString(conn, xml)) == NULL) if ((def = virNetworkDefParseString(xml)) == NULL)
goto cleanup; goto cleanup;
if ((net = virNetworkAssignDef(conn, &privconn->networks, def)) == NULL) if ((net = virNetworkAssignDef(&privconn->networks, def)) == NULL)
goto cleanup; goto cleanup;
def = NULL; def = NULL;
net->persistent = 1; net->persistent = 1;
@ -3030,7 +3030,7 @@ static char *testNetworkDumpXML(virNetworkPtr network, int flags ATTRIBUTE_UNUSE
goto cleanup; goto cleanup;
} }
ret = virNetworkDefFormat(network->conn, privnet->def); ret = virNetworkDefFormat(privnet->def);
cleanup: cleanup:
if (privnet) if (privnet)

View File

@ -5722,7 +5722,7 @@ static virNetworkPtr vboxNetworkDefineCreateXML(virConnectPtr conn, const char *
char *networkInterfaceNameUtf8 = NULL; char *networkInterfaceNameUtf8 = NULL;
IHostNetworkInterface *networkInterface = NULL; IHostNetworkInterface *networkInterface = NULL;
virNetworkDefPtr def = virNetworkDefParseString(conn, xml); virNetworkDefPtr def = virNetworkDefParseString(xml);
if ( (!def) if ( (!def)
|| (def->forwardType != VIR_NETWORK_FORWARD_NONE)) || (def->forwardType != VIR_NETWORK_FORWARD_NONE))
@ -6180,7 +6180,7 @@ static char *vboxNetworkDumpXML(virNetworkPtr network, int flags ATTRIBUTE_UNUSE
VBOX_UTF16_FREE(networkInterfaceNameUtf16); VBOX_UTF16_FREE(networkInterfaceNameUtf16);
VBOX_RELEASE(host); VBOX_RELEASE(host);
ret = virNetworkDefFormat(network->conn, def); ret = virNetworkDefFormat(def);
cleanup: cleanup:
VIR_FREE(networkNameUtf8); VIR_FREE(networkNameUtf8);

View File

@ -33,10 +33,10 @@ static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) {
if (virtTestLoadFile(outxml, &outXmlPtr, MAX_FILE) < 0) if (virtTestLoadFile(outxml, &outXmlPtr, MAX_FILE) < 0)
goto fail; goto fail;
if (!(dev = virNetworkDefParseString(NULL, inXmlData))) if (!(dev = virNetworkDefParseString(inXmlData)))
goto fail; goto fail;
if (!(actual = virNetworkDefFormat(NULL, dev))) if (!(actual = virNetworkDefFormat(dev)))
goto fail; goto fail;
if (STRNEQ(outXmlData, actual)) { if (STRNEQ(outXmlData, actual)) {