diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index e42a3dc0a9..4d5eb920bf 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -2709,10 +2709,10 @@ libxlConnectDomainXMLToNative(virConnectPtr conn, const char * nativeFormat, goto cleanup; if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XL)) { - if (!(conf = xenFormatXL(def, conn))) + if (!(conf = xenFormatXL(def))) goto cleanup; } else if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XM)) { - if (!(conf = xenFormatXM(conn, def))) + if (!(conf = xenFormatXM(def))) goto cleanup; } else { diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c index 79eb593432..3a64f565f7 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -24,6 +24,8 @@ #include +#include "datatypes.h" +#include "driver.h" #include "internal.h" #include "virerror.h" #include "virconf.h" @@ -1586,8 +1588,7 @@ xenMakeIPList(virNetDevIPInfo *guestIP) } static int -xenFormatNet(virConnectPtr conn, - virConfValue *list, +xenFormatNet(virConfValue *list, virDomainNetDef *net, int hvm, const char *vif_typename) @@ -1649,13 +1650,19 @@ xenFormatNet(virConnectPtr conn, case VIR_DOMAIN_NET_TYPE_NETWORK: { - virNetworkPtr network = virNetworkLookupByName(conn, net->data.network.name); + g_autoptr(virConnect) conn = NULL; + virNetworkPtr network; char *bridge; - if (!network) { + + if (!(conn = virGetConnectNetwork())) + return -1; + + if (!(network = virNetworkLookupByName(conn, net->data.network.name))) { virReportError(VIR_ERR_NO_NETWORK, "%s", net->data.network.name); return -1; } + bridge = virNetworkGetBridgeName(network); virObjectUnref(network); if (!bridge) { @@ -2304,7 +2311,6 @@ xenFormatSound(virConf *conf, virDomainDef *def) static int xenFormatVif(virConf *conf, - virConnectPtr conn, virDomainDef *def, const char *vif_typename) { @@ -2317,8 +2323,7 @@ xenFormatVif(virConf *conf, netVal->list = NULL; for (i = 0; i < def->nnets; i++) { - if (xenFormatNet(conn, netVal, def->nets[i], - hvm, vif_typename) < 0) + if (xenFormatNet(netVal, def->nets[i], hvm, vif_typename) < 0) return -1; } @@ -2336,7 +2341,6 @@ xenFormatVif(virConf *conf, int xenFormatConfigCommon(virConf *conf, virDomainDef *def, - virConnectPtr conn, const char *nativeFormat) { if (xenFormatGeneralMeta(conf, def) < 0) @@ -2364,10 +2368,10 @@ xenFormatConfigCommon(virConf *conf, return -1; if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XL)) { - if (xenFormatVif(conf, conn, def, "vif") < 0) + if (xenFormatVif(conf, def, "vif") < 0) return -1; } else if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XM)) { - if (xenFormatVif(conf, conn, def, "netfront") < 0) + if (xenFormatVif(conf, def, "netfront") < 0) return -1; } else { virReportError(VIR_ERR_INVALID_ARG, diff --git a/src/libxl/xen_common.h b/src/libxl/xen_common.h index b21046e959..95408fa896 100644 --- a/src/libxl/xen_common.h +++ b/src/libxl/xen_common.h @@ -61,7 +61,6 @@ int xenParseConfigCommon(virConf *conf, int xenFormatConfigCommon(virConf *conf, virDomainDef *def, - virConnectPtr conn, const char *nativeFormat); char *xenMakeIPList(virNetDevIPInfo *guestIP); diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c index f175359307..53f6871efc 100644 --- a/src/libxl/xen_xl.c +++ b/src/libxl/xen_xl.c @@ -2041,14 +2041,14 @@ xenFormatXLDomainNamespaceData(virConf *conf, virDomainDef *def) } virConf * -xenFormatXL(virDomainDef *def, virConnectPtr conn) +xenFormatXL(virDomainDef *def) { g_autoptr(virConf) conf = NULL; if (!(conf = virConfNew())) return NULL; - if (xenFormatConfigCommon(conf, def, conn, XEN_CONFIG_FORMAT_XL) < 0) + if (xenFormatConfigCommon(conf, def, XEN_CONFIG_FORMAT_XL) < 0) return NULL; if (xenFormatXLOS(conf, def) < 0) diff --git a/src/libxl/xen_xl.h b/src/libxl/xen_xl.h index f8b1ebfde9..028b359b76 100644 --- a/src/libxl/xen_xl.h +++ b/src/libxl/xen_xl.h @@ -29,6 +29,6 @@ virDomainDef *xenParseXL(virConf *conn, virCaps *caps, virDomainXMLOption *xmlopt); -virConf *xenFormatXL(virDomainDef *def, virConnectPtr); +virConf *xenFormatXL(virDomainDef *def); const char *xenTranslateCPUFeature(const char *feature_name, bool from_libxl); diff --git a/src/libxl/xen_xm.c b/src/libxl/xen_xm.c index 5705a5ec0c..274b35153b 100644 --- a/src/libxl/xen_xm.c +++ b/src/libxl/xen_xm.c @@ -543,15 +543,14 @@ G_STATIC_ASSERT(MAX_VIRT_CPUS <= sizeof(1UL) * CHAR_BIT); * Convert a virDomainDef object into an XM config record. */ virConf * -xenFormatXM(virConnectPtr conn, - virDomainDef *def) +xenFormatXM(virDomainDef *def) { g_autoptr(virConf) conf = NULL; if (!(conf = virConfNew())) return NULL; - if (xenFormatConfigCommon(conf, def, conn, XEN_CONFIG_FORMAT_XM) < 0) + if (xenFormatConfigCommon(conf, def, XEN_CONFIG_FORMAT_XM) < 0) return NULL; if (xenFormatXMOS(conf, def) < 0) diff --git a/src/libxl/xen_xm.h b/src/libxl/xen_xm.h index afb4f51ff7..db2ae52581 100644 --- a/src/libxl/xen_xm.h +++ b/src/libxl/xen_xm.h @@ -26,7 +26,7 @@ #include "virconf.h" #include "domain_conf.h" -virConf *xenFormatXM(virConnectPtr conn, virDomainDef *def); +virConf *xenFormatXM(virDomainDef *def); virDomainDef *xenParseXM(virConf *conf, virCaps *caps, virDomainXMLOption *xmlopt); diff --git a/tests/xlconfigtest.c b/tests/xlconfigtest.c index 962a1f2c4b..00b6a355eb 100644 --- a/tests/xlconfigtest.c +++ b/tests/xlconfigtest.c @@ -65,17 +65,12 @@ testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars) { g_autofree char *gotxlcfgData = NULL; g_autoptr(virConf) conf = NULL; - g_autoptr(virConnect) conn = NULL; int wrote = 4096; g_autoptr(virDomainDef) def = NULL; g_autofree char *replacedXML = NULL; gotxlcfgData = g_new0(char, wrote); - conn = virGetConnect(); - if (!conn) - return -1; - if (replaceVars) { if (!(replacedXML = testReplaceVarsXML(xml))) return -1; @@ -93,7 +88,7 @@ testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars) return -1; } - if (!(conf = xenFormatXL(def, conn))) + if (!(conf = xenFormatXL(def))) return -1; if (virConfWriteMem(gotxlcfgData, &wrote, conf) < 0) diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c index dbf9f7a4c7..30ad49f8b1 100644 --- a/tests/xmconfigtest.c +++ b/tests/xmconfigtest.c @@ -39,16 +39,11 @@ testCompareParseXML(const char *xmcfg, const char *xml) { g_autofree char *gotxmcfgData = NULL; g_autoptr(virConf) conf = NULL; - g_autoptr(virConnect) conn = NULL; int wrote = 4096; g_autoptr(virDomainDef) def = NULL; gotxmcfgData = g_new0(char, wrote); - conn = virGetConnect(); - if (!conn) - return -1; - if (!(def = virDomainDefParseFile(xml, driver->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE))) return -1; @@ -58,7 +53,7 @@ testCompareParseXML(const char *xmcfg, const char *xml) return -1; } - if (!(conf = xenFormatXM(conn, def))) + if (!(conf = xenFormatXM(def))) return -1; if (virConfWriteMem(gotxmcfgData, &wrote, conf) < 0)