mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 17:34:18 +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:
parent
ce71b8654d
commit
0677e11125
@ -53,9 +53,9 @@ VIR_ENUM_IMPL(virNetworkForward,
|
||||
VIR_NETWORK_FORWARD_LAST,
|
||||
"none", "nat", "route" )
|
||||
|
||||
#define virNetworkReportError(conn, code, fmt...) \
|
||||
virReportErrorHelper(conn, VIR_FROM_NETWORK, code, __FILE__, \
|
||||
__FUNCTION__, __LINE__, fmt)
|
||||
#define virNetworkReportError(code, fmt...) \
|
||||
virReportErrorHelper(NULL, VIR_FROM_NETWORK, code, __FILE__, \
|
||||
__FUNCTION__, __LINE__, fmt)
|
||||
|
||||
virNetworkObjPtr virNetworkFindByUUID(const virNetworkObjListPtr nets,
|
||||
const unsigned char *uuid)
|
||||
@ -147,8 +147,7 @@ void virNetworkObjListFree(virNetworkObjListPtr nets)
|
||||
nets->count = 0;
|
||||
}
|
||||
|
||||
virNetworkObjPtr virNetworkAssignDef(virConnectPtr conn,
|
||||
virNetworkObjListPtr nets,
|
||||
virNetworkObjPtr virNetworkAssignDef(virNetworkObjListPtr nets,
|
||||
const virNetworkDefPtr def)
|
||||
{
|
||||
virNetworkObjPtr network;
|
||||
@ -171,7 +170,7 @@ virNetworkObjPtr virNetworkAssignDef(virConnectPtr conn,
|
||||
return NULL;
|
||||
}
|
||||
if (virMutexInit(&network->lock) < 0) {
|
||||
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||
virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"%s", _("cannot initialize mutex"));
|
||||
VIR_FREE(network);
|
||||
return NULL;
|
||||
@ -221,8 +220,7 @@ void virNetworkRemoveInactive(virNetworkObjListPtr nets,
|
||||
|
||||
|
||||
static int
|
||||
virNetworkDHCPRangeDefParseXML(virConnectPtr conn,
|
||||
virNetworkDefPtr def,
|
||||
virNetworkDHCPRangeDefParseXML(virNetworkDefPtr def,
|
||||
xmlNodePtr node) {
|
||||
|
||||
xmlNodePtr cur;
|
||||
@ -246,7 +244,7 @@ virNetworkDHCPRangeDefParseXML(virConnectPtr conn,
|
||||
}
|
||||
|
||||
if (virSocketParseAddr(start, &saddr, 0) < 0) {
|
||||
virNetworkReportError(conn, VIR_ERR_XML_ERROR,
|
||||
virNetworkReportError(VIR_ERR_XML_ERROR,
|
||||
_("cannot parse dhcp start address '%s'"),
|
||||
start);
|
||||
xmlFree(start);
|
||||
@ -255,7 +253,7 @@ virNetworkDHCPRangeDefParseXML(virConnectPtr conn,
|
||||
continue;
|
||||
}
|
||||
if (virSocketParseAddr(end, &eaddr, 0) < 0) {
|
||||
virNetworkReportError(conn, VIR_ERR_XML_ERROR,
|
||||
virNetworkReportError(VIR_ERR_XML_ERROR,
|
||||
_("cannot parse dhcp end address '%s'"),
|
||||
end);
|
||||
xmlFree(start);
|
||||
@ -266,7 +264,7 @@ virNetworkDHCPRangeDefParseXML(virConnectPtr conn,
|
||||
|
||||
range = virSocketGetRange(&saddr, &eaddr);
|
||||
if (range < 0) {
|
||||
virNetworkReportError(conn, VIR_ERR_XML_ERROR,
|
||||
virNetworkReportError(VIR_ERR_XML_ERROR,
|
||||
_("dhcp range '%s' to '%s' invalid"),
|
||||
start, end);
|
||||
xmlFree(start);
|
||||
@ -294,14 +292,14 @@ virNetworkDHCPRangeDefParseXML(virConnectPtr conn,
|
||||
mac = xmlGetProp(cur, BAD_CAST "mac");
|
||||
if ((mac != NULL) &&
|
||||
(virParseMacAddr((const char *) mac, &addr[0]) != 0)) {
|
||||
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||
virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("cannot parse MAC address '%s'"),
|
||||
mac);
|
||||
VIR_FREE(mac);
|
||||
}
|
||||
name = xmlGetProp(cur, BAD_CAST "name");
|
||||
if ((name != NULL) && (!c_isalpha(name[0]))) {
|
||||
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||
virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("cannot use name address '%s'"),
|
||||
name);
|
||||
VIR_FREE(name);
|
||||
@ -317,7 +315,7 @@ virNetworkDHCPRangeDefParseXML(virConnectPtr conn,
|
||||
}
|
||||
ip = xmlGetProp(cur, BAD_CAST "ip");
|
||||
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'"),
|
||||
ip);
|
||||
VIR_FREE(ip);
|
||||
@ -358,8 +356,7 @@ virNetworkDHCPRangeDefParseXML(virConnectPtr conn,
|
||||
}
|
||||
|
||||
static int
|
||||
virNetworkIPParseXML(virConnectPtr conn,
|
||||
virNetworkDefPtr def,
|
||||
virNetworkIPParseXML(virNetworkDefPtr def,
|
||||
xmlNodePtr node) {
|
||||
xmlNodePtr cur;
|
||||
|
||||
@ -367,7 +364,7 @@ virNetworkIPParseXML(virConnectPtr conn,
|
||||
while (cur != NULL) {
|
||||
if (cur->type == XML_ELEMENT_NODE &&
|
||||
xmlStrEqual(cur->name, BAD_CAST "dhcp")) {
|
||||
int result = virNetworkDHCPRangeDefParseXML(conn, def, cur);
|
||||
int result = virNetworkDHCPRangeDefParseXML(def, cur);
|
||||
if (result)
|
||||
return result;
|
||||
|
||||
@ -389,8 +386,7 @@ virNetworkIPParseXML(virConnectPtr conn,
|
||||
}
|
||||
|
||||
static virNetworkDefPtr
|
||||
virNetworkDefParseXML(virConnectPtr conn,
|
||||
xmlXPathContextPtr ctxt)
|
||||
virNetworkDefParseXML(xmlXPathContextPtr ctxt)
|
||||
{
|
||||
virNetworkDefPtr def;
|
||||
char *tmp;
|
||||
@ -403,7 +399,7 @@ virNetworkDefParseXML(virConnectPtr conn,
|
||||
/* Extract network name */
|
||||
def->name = virXPathString("string(./name[1])", ctxt);
|
||||
if (!def->name) {
|
||||
virNetworkReportError(conn, VIR_ERR_NO_NAME, NULL);
|
||||
virNetworkReportError(VIR_ERR_NO_NAME, NULL);
|
||||
goto error;
|
||||
}
|
||||
|
||||
@ -411,14 +407,14 @@ virNetworkDefParseXML(virConnectPtr conn,
|
||||
tmp = virXPathString("string(./uuid[1])", ctxt);
|
||||
if (!tmp) {
|
||||
if (virUUIDGenerate(def->uuid)) {
|
||||
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||
virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"%s", _("Failed to generate UUID"));
|
||||
goto error;
|
||||
}
|
||||
} else {
|
||||
if (virUUIDParse(tmp, def->uuid) < 0) {
|
||||
VIR_FREE(tmp);
|
||||
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||
virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"%s", _("malformed uuid element"));
|
||||
goto error;
|
||||
}
|
||||
@ -447,13 +443,13 @@ virNetworkDefParseXML(virConnectPtr conn,
|
||||
xmlNodePtr ip;
|
||||
|
||||
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'"),
|
||||
def->ipAddress);
|
||||
goto error;
|
||||
}
|
||||
if (inet_pton(AF_INET, def->netmask, &innetmask) <= 0) {
|
||||
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||
virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("cannot parse netmask '%s'"),
|
||||
def->netmask);
|
||||
goto error;
|
||||
@ -468,7 +464,7 @@ virNetworkDefParseXML(virConnectPtr conn,
|
||||
}
|
||||
|
||||
if ((ip = virXPathNode("./ip[1]", ctxt)) &&
|
||||
virNetworkIPParseXML(conn, def, ip) < 0)
|
||||
virNetworkIPParseXML(def, ip) < 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
@ -477,7 +473,7 @@ virNetworkDefParseXML(virConnectPtr conn,
|
||||
if (virXPathBoolean("count(./forward) > 0", ctxt)) {
|
||||
if (!def->ipAddress ||
|
||||
!def->netmask) {
|
||||
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||
virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"%s", _("Forwarding requested, but no IPv4 address/netmask provided"));
|
||||
goto error;
|
||||
}
|
||||
@ -485,7 +481,7 @@ virNetworkDefParseXML(virConnectPtr conn,
|
||||
tmp = virXPathString("string(./forward[1]/@mode)", ctxt);
|
||||
if (tmp) {
|
||||
if ((def->forwardType = virNetworkForwardTypeFromString(tmp)) < 0) {
|
||||
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||
virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("unknown forwarding type '%s'"), tmp);
|
||||
VIR_FREE(tmp);
|
||||
goto error;
|
||||
@ -515,22 +511,18 @@ catchXMLError (void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
|
||||
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
|
||||
|
||||
if (ctxt) {
|
||||
virConnectPtr conn = ctxt->_private;
|
||||
|
||||
if (conn &&
|
||||
conn->err.code == VIR_ERR_NONE &&
|
||||
if (virGetLastError() == NULL &&
|
||||
ctxt->lastError.level == XML_ERR_FATAL &&
|
||||
ctxt->lastError.message != NULL) {
|
||||
virNetworkReportError (conn, VIR_ERR_XML_DETAIL,
|
||||
_("at line %d: %s"),
|
||||
ctxt->lastError.line,
|
||||
ctxt->lastError.message);
|
||||
virNetworkReportError(VIR_ERR_XML_DETAIL,
|
||||
_("at line %d: %s"),
|
||||
ctxt->lastError.line,
|
||||
ctxt->lastError.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virNetworkDefPtr virNetworkDefParseString(virConnectPtr conn,
|
||||
const char *xmlStr)
|
||||
virNetworkDefPtr virNetworkDefParseString(const char *xmlStr)
|
||||
{
|
||||
xmlParserCtxtPtr pctxt;
|
||||
xmlDocPtr xml = NULL;
|
||||
@ -542,26 +534,24 @@ virNetworkDefPtr virNetworkDefParseString(virConnectPtr conn,
|
||||
if (!pctxt || !pctxt->sax)
|
||||
goto cleanup;
|
||||
pctxt->sax->error = catchXMLError;
|
||||
pctxt->_private = conn;
|
||||
|
||||
if (conn) virResetError (&conn->err);
|
||||
xml = xmlCtxtReadDoc (pctxt, BAD_CAST xmlStr, "network.xml", NULL,
|
||||
XML_PARSE_NOENT | XML_PARSE_NONET |
|
||||
XML_PARSE_NOWARNING);
|
||||
if (!xml) {
|
||||
if (conn && conn->err.code == VIR_ERR_NONE)
|
||||
virNetworkReportError(conn, VIR_ERR_XML_ERROR,
|
||||
"%s", _("failed to parse xml document"));
|
||||
if (virGetLastError() == NULL)
|
||||
virNetworkReportError(VIR_ERR_XML_ERROR,
|
||||
"%s", _("failed to parse xml document"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((root = xmlDocGetRootElement(xml)) == NULL) {
|
||||
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||
virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"%s", _("missing root element"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
def = virNetworkDefParseNode(conn, xml, root);
|
||||
def = virNetworkDefParseNode(xml, root);
|
||||
|
||||
cleanup:
|
||||
xmlFreeParserCtxt (pctxt);
|
||||
@ -569,8 +559,7 @@ cleanup:
|
||||
return def;
|
||||
}
|
||||
|
||||
virNetworkDefPtr virNetworkDefParseFile(virConnectPtr conn,
|
||||
const char *filename)
|
||||
virNetworkDefPtr virNetworkDefParseFile(const char *filename)
|
||||
{
|
||||
xmlParserCtxtPtr pctxt;
|
||||
xmlDocPtr xml = NULL;
|
||||
@ -582,26 +571,24 @@ virNetworkDefPtr virNetworkDefParseFile(virConnectPtr conn,
|
||||
if (!pctxt || !pctxt->sax)
|
||||
goto cleanup;
|
||||
pctxt->sax->error = catchXMLError;
|
||||
pctxt->_private = conn;
|
||||
|
||||
if (conn) virResetError (&conn->err);
|
||||
xml = xmlCtxtReadFile (pctxt, filename, NULL,
|
||||
XML_PARSE_NOENT | XML_PARSE_NONET |
|
||||
XML_PARSE_NOWARNING);
|
||||
if (!xml) {
|
||||
if (conn && conn->err.code == VIR_ERR_NONE)
|
||||
virNetworkReportError(conn, VIR_ERR_XML_ERROR,
|
||||
"%s", _("failed to parse xml document"));
|
||||
if (virGetLastError() == NULL)
|
||||
virNetworkReportError(VIR_ERR_XML_ERROR,
|
||||
"%s", _("failed to parse xml document"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((root = xmlDocGetRootElement(xml)) == NULL) {
|
||||
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||
virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"%s", _("missing root element"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
def = virNetworkDefParseNode(conn, xml, root);
|
||||
def = virNetworkDefParseNode(xml, root);
|
||||
|
||||
cleanup:
|
||||
xmlFreeParserCtxt (pctxt);
|
||||
@ -610,15 +597,14 @@ cleanup:
|
||||
}
|
||||
|
||||
|
||||
virNetworkDefPtr virNetworkDefParseNode(virConnectPtr conn,
|
||||
xmlDocPtr xml,
|
||||
virNetworkDefPtr virNetworkDefParseNode(xmlDocPtr xml,
|
||||
xmlNodePtr root)
|
||||
{
|
||||
xmlXPathContextPtr ctxt = NULL;
|
||||
virNetworkDefPtr def = NULL;
|
||||
|
||||
if (!xmlStrEqual(root->name, BAD_CAST "network")) {
|
||||
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||
virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"%s", _("incorrect root element"));
|
||||
return NULL;
|
||||
}
|
||||
@ -630,15 +616,14 @@ virNetworkDefPtr virNetworkDefParseNode(virConnectPtr conn,
|
||||
}
|
||||
|
||||
ctxt->node = root;
|
||||
def = virNetworkDefParseXML(conn, ctxt);
|
||||
def = virNetworkDefParseXML(ctxt);
|
||||
|
||||
cleanup:
|
||||
xmlXPathFreeContext(ctxt);
|
||||
return def;
|
||||
}
|
||||
|
||||
char *virNetworkDefFormat(virConnectPtr conn ATTRIBUTE_UNUSED /*TEMPORARY*/,
|
||||
const virNetworkDefPtr def)
|
||||
char *virNetworkDefFormat(const virNetworkDefPtr def)
|
||||
{
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
unsigned char *uuid;
|
||||
@ -734,8 +719,7 @@ char *virNetworkDefFormat(virConnectPtr conn ATTRIBUTE_UNUSED /*TEMPORARY*/,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int virNetworkSaveXML(virConnectPtr conn,
|
||||
const char *configDir,
|
||||
int virNetworkSaveXML(const char *configDir,
|
||||
virNetworkDefPtr def,
|
||||
const char *xml)
|
||||
{
|
||||
@ -744,7 +728,7 @@ int virNetworkSaveXML(virConnectPtr conn,
|
||||
size_t towrite;
|
||||
int err;
|
||||
|
||||
if ((configFile = virNetworkConfigFile(conn, configDir, def->name)) == NULL)
|
||||
if ((configFile = virNetworkConfigFile(configDir, def->name)) == NULL)
|
||||
goto cleanup;
|
||||
|
||||
if ((err = virFileMakePath(configDir))) {
|
||||
@ -789,17 +773,16 @@ int virNetworkSaveXML(virConnectPtr conn,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int virNetworkSaveConfig(virConnectPtr conn,
|
||||
const char *configDir,
|
||||
int virNetworkSaveConfig(const char *configDir,
|
||||
virNetworkDefPtr def)
|
||||
{
|
||||
int ret = -1;
|
||||
char *xml;
|
||||
|
||||
if (!(xml = virNetworkDefFormat(conn, def)))
|
||||
if (!(xml = virNetworkDefFormat(def)))
|
||||
goto cleanup;
|
||||
|
||||
if (virNetworkSaveXML(conn, configDir, def, xml))
|
||||
if (virNetworkSaveXML(configDir, def, xml))
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
@ -809,8 +792,7 @@ cleanup:
|
||||
}
|
||||
|
||||
|
||||
virNetworkObjPtr virNetworkLoadConfig(virConnectPtr conn,
|
||||
virNetworkObjListPtr nets,
|
||||
virNetworkObjPtr virNetworkLoadConfig(virNetworkObjListPtr nets,
|
||||
const char *configDir,
|
||||
const char *autostartDir,
|
||||
const char *name)
|
||||
@ -820,19 +802,19 @@ virNetworkObjPtr virNetworkLoadConfig(virConnectPtr conn,
|
||||
virNetworkObjPtr net;
|
||||
int autostart;
|
||||
|
||||
if ((configFile = virNetworkConfigFile(conn, configDir, name)) == NULL)
|
||||
if ((configFile = virNetworkConfigFile(configDir, name)) == NULL)
|
||||
goto error;
|
||||
if ((autostartLink = virNetworkConfigFile(conn, autostartDir, name)) == NULL)
|
||||
if ((autostartLink = virNetworkConfigFile(autostartDir, name)) == NULL)
|
||||
goto error;
|
||||
|
||||
if ((autostart = virFileLinkPointsTo(autostartLink, configFile)) < 0)
|
||||
goto error;
|
||||
|
||||
if (!(def = virNetworkDefParseFile(conn, configFile)))
|
||||
if (!(def = virNetworkDefParseFile(configFile)))
|
||||
goto error;
|
||||
|
||||
if (!STREQ(name, def->name)) {
|
||||
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||
virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Network config filename '%s'"
|
||||
" does not match network name '%s'"),
|
||||
configFile, def->name);
|
||||
@ -842,10 +824,10 @@ virNetworkObjPtr virNetworkLoadConfig(virConnectPtr conn,
|
||||
/* 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 (virNetworkSetBridgeName(conn, nets, def, 0))
|
||||
if (virNetworkSetBridgeName(nets, def, 0))
|
||||
goto error;
|
||||
|
||||
if (!(net = virNetworkAssignDef(conn, nets, def)))
|
||||
if (!(net = virNetworkAssignDef(nets, def)))
|
||||
goto error;
|
||||
|
||||
net->autostart = autostart;
|
||||
@ -863,8 +845,7 @@ error:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int virNetworkLoadAllConfigs(virConnectPtr conn,
|
||||
virNetworkObjListPtr nets,
|
||||
int virNetworkLoadAllConfigs(virNetworkObjListPtr nets,
|
||||
const char *configDir,
|
||||
const char *autostartDir)
|
||||
{
|
||||
@ -891,8 +872,7 @@ int virNetworkLoadAllConfigs(virConnectPtr conn,
|
||||
|
||||
/* NB: ignoring errors, so one malformed config doesn't
|
||||
kill the whole process */
|
||||
net = virNetworkLoadConfig(conn,
|
||||
nets,
|
||||
net = virNetworkLoadConfig(nets,
|
||||
configDir,
|
||||
autostartDir,
|
||||
entry->d_name);
|
||||
@ -905,8 +885,7 @@ int virNetworkLoadAllConfigs(virConnectPtr conn,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int virNetworkDeleteConfig(virConnectPtr conn,
|
||||
const char *configDir,
|
||||
int virNetworkDeleteConfig(const char *configDir,
|
||||
const char *autostartDir,
|
||||
virNetworkObjPtr net)
|
||||
{
|
||||
@ -914,9 +893,9 @@ int virNetworkDeleteConfig(virConnectPtr conn,
|
||||
char *autostartLink = NULL;
|
||||
int ret = -1;
|
||||
|
||||
if ((configFile = virNetworkConfigFile(conn, configDir, net->def->name)) == NULL)
|
||||
if ((configFile = virNetworkConfigFile(configDir, net->def->name)) == NULL)
|
||||
goto error;
|
||||
if ((autostartLink = virNetworkConfigFile(conn, autostartDir, net->def->name)) == NULL)
|
||||
if ((autostartLink = virNetworkConfigFile(autostartDir, net->def->name)) == NULL)
|
||||
goto error;
|
||||
|
||||
/* Not fatal if this doesn't work */
|
||||
@ -937,8 +916,7 @@ error:
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *virNetworkConfigFile(virConnectPtr conn ATTRIBUTE_UNUSED /*TEMPORARY*/,
|
||||
const char *dir,
|
||||
char *virNetworkConfigFile(const char *dir,
|
||||
const char *name)
|
||||
{
|
||||
char *ret = NULL;
|
||||
@ -970,8 +948,7 @@ int virNetworkBridgeInUse(const virNetworkObjListPtr nets,
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *virNetworkAllocateBridge(virConnectPtr conn,
|
||||
const virNetworkObjListPtr nets,
|
||||
char *virNetworkAllocateBridge(const virNetworkObjListPtr nets,
|
||||
const char *template)
|
||||
{
|
||||
|
||||
@ -997,14 +974,13 @@ char *virNetworkAllocateBridge(virConnectPtr conn,
|
||||
id++;
|
||||
} while (id <= MAX_BRIDGE_ID);
|
||||
|
||||
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||
virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Bridge generation exceeded max id %d"),
|
||||
MAX_BRIDGE_ID);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int virNetworkSetBridgeName(virConnectPtr conn,
|
||||
const virNetworkObjListPtr nets,
|
||||
int virNetworkSetBridgeName(const virNetworkObjListPtr nets,
|
||||
virNetworkDefPtr def,
|
||||
int check_collision) {
|
||||
|
||||
@ -1016,14 +992,14 @@ int virNetworkSetBridgeName(virConnectPtr conn,
|
||||
* defined. */
|
||||
if (check_collision &&
|
||||
virNetworkBridgeInUse(nets, def->bridge, def->name)) {
|
||||
networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||
_("bridge name '%s' already in use."),
|
||||
def->bridge);
|
||||
virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("bridge name '%s' already in use."),
|
||||
def->bridge);
|
||||
goto error;
|
||||
}
|
||||
} else {
|
||||
/* Allocate a bridge name */
|
||||
if (!(def->bridge = virNetworkAllocateBridge(conn, nets, def->bridge)))
|
||||
if (!(def->bridge = virNetworkAllocateBridge(nets, def->bridge)))
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
@ -112,11 +112,6 @@ virNetworkObjIsActive(const virNetworkObjPtr net)
|
||||
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,
|
||||
const unsigned char *uuid);
|
||||
virNetworkObjPtr virNetworkFindByName(const virNetworkObjListPtr nets,
|
||||
@ -127,63 +122,50 @@ void virNetworkDefFree(virNetworkDefPtr def);
|
||||
void virNetworkObjFree(virNetworkObjPtr net);
|
||||
void virNetworkObjListFree(virNetworkObjListPtr vms);
|
||||
|
||||
virNetworkObjPtr virNetworkAssignDef(virConnectPtr conn,
|
||||
virNetworkObjListPtr nets,
|
||||
virNetworkObjPtr virNetworkAssignDef(virNetworkObjListPtr nets,
|
||||
const virNetworkDefPtr def);
|
||||
void virNetworkRemoveInactive(virNetworkObjListPtr nets,
|
||||
const virNetworkObjPtr net);
|
||||
|
||||
virNetworkDefPtr virNetworkDefParseString(virConnectPtr conn,
|
||||
const char *xmlStr);
|
||||
virNetworkDefPtr virNetworkDefParseFile(virConnectPtr conn,
|
||||
const char *filename);
|
||||
virNetworkDefPtr virNetworkDefParseNode(virConnectPtr conn,
|
||||
xmlDocPtr xml,
|
||||
virNetworkDefPtr virNetworkDefParseString(const char *xmlStr);
|
||||
virNetworkDefPtr virNetworkDefParseFile(const char *filename);
|
||||
virNetworkDefPtr virNetworkDefParseNode(xmlDocPtr xml,
|
||||
xmlNodePtr root);
|
||||
|
||||
char *virNetworkDefFormat(virConnectPtr conn,
|
||||
const virNetworkDefPtr def);
|
||||
char *virNetworkDefFormat(const virNetworkDefPtr def);
|
||||
|
||||
|
||||
int virNetworkSaveXML(virConnectPtr conn,
|
||||
const char *configDir,
|
||||
int virNetworkSaveXML(const char *configDir,
|
||||
virNetworkDefPtr def,
|
||||
const char *xml);
|
||||
|
||||
int virNetworkSaveConfig(virConnectPtr conn,
|
||||
const char *configDir,
|
||||
int virNetworkSaveConfig(const char *configDir,
|
||||
virNetworkDefPtr def);
|
||||
|
||||
virNetworkObjPtr virNetworkLoadConfig(virConnectPtr conn,
|
||||
virNetworkObjListPtr nets,
|
||||
virNetworkObjPtr virNetworkLoadConfig(virNetworkObjListPtr nets,
|
||||
const char *configDir,
|
||||
const char *autostartDir,
|
||||
const char *file);
|
||||
|
||||
int virNetworkLoadAllConfigs(virConnectPtr conn,
|
||||
virNetworkObjListPtr nets,
|
||||
int virNetworkLoadAllConfigs(virNetworkObjListPtr nets,
|
||||
const char *configDir,
|
||||
const char *autostartDir);
|
||||
|
||||
int virNetworkDeleteConfig(virConnectPtr conn,
|
||||
const char *configDir,
|
||||
int virNetworkDeleteConfig(const char *configDir,
|
||||
const char *autostartDir,
|
||||
virNetworkObjPtr net);
|
||||
|
||||
char *virNetworkConfigFile(virConnectPtr conn,
|
||||
const char *dir,
|
||||
char *virNetworkConfigFile(const char *dir,
|
||||
const char *name);
|
||||
|
||||
int virNetworkBridgeInUse(const virNetworkObjListPtr nets,
|
||||
const char *bridge,
|
||||
const char *skipname);
|
||||
|
||||
char *virNetworkAllocateBridge(virConnectPtr conn,
|
||||
const virNetworkObjListPtr nets,
|
||||
char *virNetworkAllocateBridge(const virNetworkObjListPtr nets,
|
||||
const char *template);
|
||||
|
||||
int virNetworkSetBridgeName(virConnectPtr conn,
|
||||
const virNetworkObjListPtr nets,
|
||||
int virNetworkSetBridgeName(const virNetworkObjListPtr nets,
|
||||
virNetworkDefPtr def,
|
||||
int check_collision);
|
||||
|
||||
|
@ -63,6 +63,10 @@
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_NETWORK
|
||||
|
||||
#define networkReportError(code, fmt...) \
|
||||
virReportErrorHelper(NULL, VIR_FROM_NETWORK, code, __FILE__, \
|
||||
__FUNCTION__, __LINE__, fmt)
|
||||
|
||||
/* Main driver state */
|
||||
struct network_driver {
|
||||
virMutex lock;
|
||||
@ -88,13 +92,11 @@ static void networkDriverUnlock(struct network_driver *driver)
|
||||
|
||||
static int networkShutdown(void);
|
||||
|
||||
static int networkStartNetworkDaemon(virConnectPtr conn,
|
||||
struct network_driver *driver,
|
||||
virNetworkObjPtr network);
|
||||
static int networkStartNetworkDaemon(struct network_driver *driver,
|
||||
virNetworkObjPtr network);
|
||||
|
||||
static int networkShutdownNetworkDaemon(virConnectPtr conn,
|
||||
struct network_driver *driver,
|
||||
virNetworkObjPtr network);
|
||||
static int networkShutdownNetworkDaemon(struct network_driver *driver,
|
||||
virNetworkObjPtr network);
|
||||
|
||||
static void networkReloadIptablesRules(struct network_driver *driver);
|
||||
|
||||
@ -112,8 +114,7 @@ networkFindActiveConfigs(struct network_driver *driver) {
|
||||
|
||||
virNetworkObjLock(obj);
|
||||
|
||||
if ((config = virNetworkConfigFile(NULL,
|
||||
NETWORK_STATE_DIR,
|
||||
if ((config = virNetworkConfigFile(NETWORK_STATE_DIR,
|
||||
obj->def->name)) == NULL) {
|
||||
virNetworkObjUnlock(obj);
|
||||
continue;
|
||||
@ -126,7 +127,7 @@ networkFindActiveConfigs(struct network_driver *driver) {
|
||||
}
|
||||
|
||||
/* Try and load the live config */
|
||||
tmp = virNetworkDefParseFile(NULL, config);
|
||||
tmp = virNetworkDefParseFile(config);
|
||||
VIR_FREE(config);
|
||||
if (tmp) {
|
||||
obj->newDef = obj->def;
|
||||
@ -176,7 +177,7 @@ networkAutostartConfigs(struct network_driver *driver) {
|
||||
virNetworkObjLock(driver->networks.objs[i]);
|
||||
if (driver->networks.objs[i]->autostart &&
|
||||
!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 */
|
||||
}
|
||||
virNetworkObjUnlock(driver->networks.objs[i]);
|
||||
@ -252,8 +253,7 @@ networkStartup(int privileged) {
|
||||
}
|
||||
|
||||
|
||||
if (virNetworkLoadAllConfigs(NULL,
|
||||
&driverState->networks,
|
||||
if (virNetworkLoadAllConfigs(&driverState->networks,
|
||||
driverState->networkConfigDir,
|
||||
driverState->networkAutostartDir) < 0)
|
||||
goto error;
|
||||
@ -290,8 +290,7 @@ networkReload(void) {
|
||||
return 0;
|
||||
|
||||
networkDriverLock(driverState);
|
||||
virNetworkLoadAllConfigs(NULL,
|
||||
&driverState->networks,
|
||||
virNetworkLoadAllConfigs(&driverState->networks,
|
||||
driverState->networkConfigDir,
|
||||
driverState->networkAutostartDir);
|
||||
networkReloadIptablesRules(driverState);
|
||||
@ -523,8 +522,7 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
|
||||
|
||||
|
||||
static int
|
||||
dhcpStartDhcpDaemon(virConnectPtr conn,
|
||||
virNetworkObjPtr network)
|
||||
dhcpStartDhcpDaemon(virNetworkObjPtr network)
|
||||
{
|
||||
const char **argv;
|
||||
char *pidfile;
|
||||
@ -533,8 +531,8 @@ dhcpStartDhcpDaemon(virConnectPtr conn,
|
||||
network->dnsmasqPid = -1;
|
||||
|
||||
if (network->def->ipAddress == NULL) {
|
||||
networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||
"%s", _("cannot start dhcp daemon without IP address for server"));
|
||||
networkReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"%s", _("cannot start dhcp daemon without IP address for server"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -885,14 +883,14 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int networkStartNetworkDaemon(virConnectPtr conn,
|
||||
struct network_driver *driver,
|
||||
virNetworkObjPtr network) {
|
||||
static int networkStartNetworkDaemon(struct network_driver *driver,
|
||||
virNetworkObjPtr network)
|
||||
{
|
||||
int err;
|
||||
|
||||
if (virNetworkObjIsActive(network)) {
|
||||
networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||
"%s", _("network is already active"));
|
||||
networkReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"%s", _("network is already active"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -947,12 +945,12 @@ static int networkStartNetworkDaemon(virConnectPtr conn,
|
||||
|
||||
if ((network->def->ipAddress ||
|
||||
network->def->nranges) &&
|
||||
dhcpStartDhcpDaemon(conn, network) < 0)
|
||||
dhcpStartDhcpDaemon(network) < 0)
|
||||
goto err_delbr2;
|
||||
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
@ -987,9 +985,9 @@ static int networkStartNetworkDaemon(virConnectPtr conn,
|
||||
}
|
||||
|
||||
|
||||
static int networkShutdownNetworkDaemon(virConnectPtr conn,
|
||||
struct network_driver *driver,
|
||||
virNetworkObjPtr network) {
|
||||
static int networkShutdownNetworkDaemon(struct network_driver *driver,
|
||||
virNetworkObjPtr network)
|
||||
{
|
||||
int err;
|
||||
char *stateFile;
|
||||
|
||||
@ -998,7 +996,7 @@ static int networkShutdownNetworkDaemon(virConnectPtr conn,
|
||||
if (!virNetworkObjIsActive(network))
|
||||
return 0;
|
||||
|
||||
stateFile = virNetworkConfigFile(conn, NETWORK_STATE_DIR, network->def->name);
|
||||
stateFile = virNetworkConfigFile(NETWORK_STATE_DIR, network->def->name);
|
||||
if (!stateFile)
|
||||
return -1;
|
||||
|
||||
@ -1049,8 +1047,8 @@ static virNetworkPtr networkLookupByUUID(virConnectPtr conn,
|
||||
network = virNetworkFindByUUID(&driver->networks, uuid);
|
||||
networkDriverUnlock(driver);
|
||||
if (!network) {
|
||||
networkReportError(conn, NULL, NULL, VIR_ERR_NO_NETWORK,
|
||||
"%s", _("no network with matching uuid"));
|
||||
networkReportError(VIR_ERR_NO_NETWORK,
|
||||
"%s", _("no network with matching uuid"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@ -1072,8 +1070,8 @@ static virNetworkPtr networkLookupByName(virConnectPtr conn,
|
||||
network = virNetworkFindByName(&driver->networks, name);
|
||||
networkDriverUnlock(driver);
|
||||
if (!network) {
|
||||
networkReportError(conn, NULL, NULL, VIR_ERR_NO_NETWORK,
|
||||
_("no network with matching name '%s'"), name);
|
||||
networkReportError(VIR_ERR_NO_NETWORK,
|
||||
_("no network with matching name '%s'"), name);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@ -1198,7 +1196,7 @@ static int networkIsActive(virNetworkPtr net)
|
||||
obj = virNetworkFindByUUID(&driver->networks, net->uuid);
|
||||
networkDriverUnlock(driver);
|
||||
if (!obj) {
|
||||
networkReportError(net->conn, NULL, NULL, VIR_ERR_NO_NETWORK, NULL);
|
||||
networkReportError(VIR_ERR_NO_NETWORK, NULL);
|
||||
goto cleanup;
|
||||
}
|
||||
ret = virNetworkObjIsActive(obj);
|
||||
@ -1219,7 +1217,7 @@ static int networkIsPersistent(virNetworkPtr net)
|
||||
obj = virNetworkFindByUUID(&driver->networks, net->uuid);
|
||||
networkDriverUnlock(driver);
|
||||
if (!obj) {
|
||||
networkReportError(net->conn, NULL, NULL, VIR_ERR_NO_NETWORK, NULL);
|
||||
networkReportError(VIR_ERR_NO_NETWORK, NULL);
|
||||
goto cleanup;
|
||||
}
|
||||
ret = obj->persistent;
|
||||
@ -1239,19 +1237,18 @@ static virNetworkPtr networkCreate(virConnectPtr conn, const char *xml) {
|
||||
|
||||
networkDriverLock(driver);
|
||||
|
||||
if (!(def = virNetworkDefParseString(conn, xml)))
|
||||
if (!(def = virNetworkDefParseString(xml)))
|
||||
goto cleanup;
|
||||
|
||||
if (virNetworkSetBridgeName(conn, &driver->networks, def, 1))
|
||||
if (virNetworkSetBridgeName(&driver->networks, def, 1))
|
||||
goto cleanup;
|
||||
|
||||
if (!(network = virNetworkAssignDef(conn,
|
||||
&driver->networks,
|
||||
if (!(network = virNetworkAssignDef(&driver->networks,
|
||||
def)))
|
||||
goto cleanup;
|
||||
def = NULL;
|
||||
|
||||
if (networkStartNetworkDaemon(conn, driver, network) < 0) {
|
||||
if (networkStartNetworkDaemon(driver, network) < 0) {
|
||||
virNetworkRemoveInactive(&driver->networks,
|
||||
network);
|
||||
network = NULL;
|
||||
@ -1276,22 +1273,20 @@ static virNetworkPtr networkDefine(virConnectPtr conn, const char *xml) {
|
||||
|
||||
networkDriverLock(driver);
|
||||
|
||||
if (!(def = virNetworkDefParseString(conn, xml)))
|
||||
if (!(def = virNetworkDefParseString(xml)))
|
||||
goto cleanup;
|
||||
|
||||
if (virNetworkSetBridgeName(conn, &driver->networks, def, 1))
|
||||
if (virNetworkSetBridgeName(&driver->networks, def, 1))
|
||||
goto cleanup;
|
||||
|
||||
if (!(network = virNetworkAssignDef(conn,
|
||||
&driver->networks,
|
||||
if (!(network = virNetworkAssignDef(&driver->networks,
|
||||
def)))
|
||||
goto cleanup;
|
||||
def = NULL;
|
||||
|
||||
network->persistent = 1;
|
||||
|
||||
if (virNetworkSaveConfig(conn,
|
||||
driver->networkConfigDir,
|
||||
if (virNetworkSaveConfig(driver->networkConfigDir,
|
||||
network->newDef ? network->newDef : network->def) < 0) {
|
||||
virNetworkRemoveInactive(&driver->networks,
|
||||
network);
|
||||
@ -1318,19 +1313,18 @@ static int networkUndefine(virNetworkPtr net) {
|
||||
|
||||
network = virNetworkFindByUUID(&driver->networks, net->uuid);
|
||||
if (!network) {
|
||||
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK,
|
||||
networkReportError(VIR_ERR_INVALID_NETWORK,
|
||||
"%s", _("no network with matching uuid"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virNetworkObjIsActive(network)) {
|
||||
networkReportError(net->conn, NULL, net, VIR_ERR_INTERNAL_ERROR,
|
||||
networkReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"%s", _("network is still active"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virNetworkDeleteConfig(net->conn,
|
||||
driver->networkConfigDir,
|
||||
if (virNetworkDeleteConfig(driver->networkConfigDir,
|
||||
driver->networkAutostartDir,
|
||||
network) < 0)
|
||||
goto cleanup;
|
||||
@ -1356,12 +1350,12 @@ static int networkStart(virNetworkPtr net) {
|
||||
network = virNetworkFindByUUID(&driver->networks, net->uuid);
|
||||
|
||||
if (!network) {
|
||||
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK,
|
||||
networkReportError(VIR_ERR_INVALID_NETWORK,
|
||||
"%s", _("no network with matching uuid"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = networkStartNetworkDaemon(net->conn, driver, network);
|
||||
ret = networkStartNetworkDaemon(driver, network);
|
||||
|
||||
cleanup:
|
||||
if (network)
|
||||
@ -1379,18 +1373,18 @@ static int networkDestroy(virNetworkPtr net) {
|
||||
network = virNetworkFindByUUID(&driver->networks, net->uuid);
|
||||
|
||||
if (!network) {
|
||||
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK,
|
||||
networkReportError(VIR_ERR_INVALID_NETWORK,
|
||||
"%s", _("no network with matching uuid"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!virNetworkObjIsActive(network)) {
|
||||
networkReportError(net->conn, NULL, net, VIR_ERR_INTERNAL_ERROR,
|
||||
networkReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"%s", _("network is not active"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = networkShutdownNetworkDaemon(net->conn, driver, network);
|
||||
ret = networkShutdownNetworkDaemon(driver, network);
|
||||
if (!network->persistent) {
|
||||
virNetworkRemoveInactive(&driver->networks,
|
||||
network);
|
||||
@ -1414,12 +1408,12 @@ static char *networkDumpXML(virNetworkPtr net, int flags ATTRIBUTE_UNUSED) {
|
||||
networkDriverUnlock(driver);
|
||||
|
||||
if (!network) {
|
||||
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK,
|
||||
networkReportError(VIR_ERR_INVALID_NETWORK,
|
||||
"%s", _("no network with matching uuid"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = virNetworkDefFormat(net->conn, network->def);
|
||||
ret = virNetworkDefFormat(network->def);
|
||||
|
||||
cleanup:
|
||||
if (network)
|
||||
@ -1437,13 +1431,13 @@ static char *networkGetBridgeName(virNetworkPtr net) {
|
||||
networkDriverUnlock(driver);
|
||||
|
||||
if (!network) {
|
||||
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK,
|
||||
networkReportError(VIR_ERR_INVALID_NETWORK,
|
||||
"%s", _("no network with matching id"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
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->def->name);
|
||||
goto cleanup;
|
||||
@ -1469,8 +1463,8 @@ static int networkGetAutostart(virNetworkPtr net,
|
||||
network = virNetworkFindByUUID(&driver->networks, net->uuid);
|
||||
networkDriverUnlock(driver);
|
||||
if (!network) {
|
||||
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK,
|
||||
"%s", _("no network with matching uuid"));
|
||||
networkReportError(VIR_ERR_INVALID_NETWORK,
|
||||
"%s", _("no network with matching uuid"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@ -1494,23 +1488,23 @@ static int networkSetAutostart(virNetworkPtr net,
|
||||
network = virNetworkFindByUUID(&driver->networks, net->uuid);
|
||||
|
||||
if (!network) {
|
||||
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK,
|
||||
"%s", _("no network with matching uuid"));
|
||||
networkReportError(VIR_ERR_INVALID_NETWORK,
|
||||
"%s", _("no network with matching uuid"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!network->persistent) {
|
||||
networkReportError(net->conn, NULL, net, VIR_ERR_INTERNAL_ERROR,
|
||||
"%s", _("cannot set autostart for transient network"));
|
||||
networkReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"%s", _("cannot set autostart for transient network"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
autostart = (autostart != 0);
|
||||
|
||||
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;
|
||||
if ((autostartLink = virNetworkConfigFile(net->conn, driver->networkAutostartDir, network->def->name)) == NULL)
|
||||
if ((autostartLink = virNetworkConfigFile(driver->networkAutostartDir, network->def->name)) == NULL)
|
||||
goto cleanup;
|
||||
|
||||
if (autostart) {
|
||||
|
@ -558,9 +558,9 @@ static int testOpenDefault(virConnectPtr conn) {
|
||||
domobj->persistent = 1;
|
||||
virDomainObjUnlock(domobj);
|
||||
|
||||
if (!(netdef = virNetworkDefParseString(conn, defaultNetworkXML)))
|
||||
if (!(netdef = virNetworkDefParseString(defaultNetworkXML)))
|
||||
goto error;
|
||||
if (!(netobj = virNetworkAssignDef(conn, &privconn->networks, netdef))) {
|
||||
if (!(netobj = virNetworkAssignDef(&privconn->networks, netdef))) {
|
||||
virNetworkDefFree(netdef);
|
||||
goto error;
|
||||
}
|
||||
@ -934,15 +934,15 @@ static int testOpenFromFile(virConnectPtr conn,
|
||||
goto error;
|
||||
}
|
||||
|
||||
def = virNetworkDefParseFile(conn, absFile);
|
||||
def = virNetworkDefParseFile(absFile);
|
||||
VIR_FREE(absFile);
|
||||
if (!def)
|
||||
goto error;
|
||||
} else {
|
||||
if ((def = virNetworkDefParseNode(conn, xml, networks[i])) == NULL)
|
||||
if ((def = virNetworkDefParseNode(xml, networks[i])) == NULL)
|
||||
goto error;
|
||||
}
|
||||
if (!(net = virNetworkAssignDef(conn, &privconn->networks,
|
||||
if (!(net = virNetworkAssignDef(&privconn->networks,
|
||||
def))) {
|
||||
virNetworkDefFree(def);
|
||||
goto error;
|
||||
@ -2881,10 +2881,10 @@ static virNetworkPtr testNetworkCreate(virConnectPtr conn, const char *xml) {
|
||||
virNetworkPtr ret = NULL;
|
||||
|
||||
testDriverLock(privconn);
|
||||
if ((def = virNetworkDefParseString(conn, xml)) == NULL)
|
||||
if ((def = virNetworkDefParseString(xml)) == NULL)
|
||||
goto cleanup;
|
||||
|
||||
if ((net = virNetworkAssignDef(conn, &privconn->networks, def)) == NULL)
|
||||
if ((net = virNetworkAssignDef(&privconn->networks, def)) == NULL)
|
||||
goto cleanup;
|
||||
def = NULL;
|
||||
net->active = 1;
|
||||
@ -2906,10 +2906,10 @@ static virNetworkPtr testNetworkDefine(virConnectPtr conn, const char *xml) {
|
||||
virNetworkPtr ret = NULL;
|
||||
|
||||
testDriverLock(privconn);
|
||||
if ((def = virNetworkDefParseString(conn, xml)) == NULL)
|
||||
if ((def = virNetworkDefParseString(xml)) == NULL)
|
||||
goto cleanup;
|
||||
|
||||
if ((net = virNetworkAssignDef(conn, &privconn->networks, def)) == NULL)
|
||||
if ((net = virNetworkAssignDef(&privconn->networks, def)) == NULL)
|
||||
goto cleanup;
|
||||
def = NULL;
|
||||
net->persistent = 1;
|
||||
@ -3030,7 +3030,7 @@ static char *testNetworkDumpXML(virNetworkPtr network, int flags ATTRIBUTE_UNUSE
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = virNetworkDefFormat(network->conn, privnet->def);
|
||||
ret = virNetworkDefFormat(privnet->def);
|
||||
|
||||
cleanup:
|
||||
if (privnet)
|
||||
|
@ -5722,7 +5722,7 @@ static virNetworkPtr vboxNetworkDefineCreateXML(virConnectPtr conn, const char *
|
||||
char *networkInterfaceNameUtf8 = NULL;
|
||||
IHostNetworkInterface *networkInterface = NULL;
|
||||
|
||||
virNetworkDefPtr def = virNetworkDefParseString(conn, xml);
|
||||
virNetworkDefPtr def = virNetworkDefParseString(xml);
|
||||
|
||||
if ( (!def)
|
||||
|| (def->forwardType != VIR_NETWORK_FORWARD_NONE))
|
||||
@ -6180,7 +6180,7 @@ static char *vboxNetworkDumpXML(virNetworkPtr network, int flags ATTRIBUTE_UNUSE
|
||||
VBOX_UTF16_FREE(networkInterfaceNameUtf16);
|
||||
VBOX_RELEASE(host);
|
||||
|
||||
ret = virNetworkDefFormat(network->conn, def);
|
||||
ret = virNetworkDefFormat(def);
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(networkNameUtf8);
|
||||
|
@ -33,10 +33,10 @@ static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) {
|
||||
if (virtTestLoadFile(outxml, &outXmlPtr, MAX_FILE) < 0)
|
||||
goto fail;
|
||||
|
||||
if (!(dev = virNetworkDefParseString(NULL, inXmlData)))
|
||||
if (!(dev = virNetworkDefParseString(inXmlData)))
|
||||
goto fail;
|
||||
|
||||
if (!(actual = virNetworkDefFormat(NULL, dev)))
|
||||
if (!(actual = virNetworkDefFormat(dev)))
|
||||
goto fail;
|
||||
|
||||
if (STRNEQ(outXmlData, actual)) {
|
||||
|
Loading…
Reference in New Issue
Block a user