mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-21 21:25:25 +00:00
libxl: Fix domxml-to-native conversion
Similar to commit 57d084febe
, another case of the libxl driver not
adapting to modular daemons. When converting configuration that
contains a type='network' interface, the converter calls
virNetworkLookupByName, passing the hypervisor connection object
instead of a connection to virtnetworkd. E.g.
> cat dom.xml
...
<interface type='network'>
<source network='default'/>
</interface>
...
> virsh net-info default
Name: default
UUID: 25a5b089-1e71-4956-99aa-df2213bbb407
Active: yes
Persistent: no
Autostart: no
Bridge: virbr0
> virsh domxml-to-native xen-xl dom.xml
error: Network not found: default
Acquire a connection to virtnetworkd and use it when calling
virNetwork* APIs.
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
fa54595178
commit
3146305fd3
@ -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 {
|
||||
|
||||
|
@ -24,6 +24,8 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#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,
|
||||
|
@ -61,7 +61,6 @@ int xenParseConfigCommon(virConf *conf,
|
||||
|
||||
int xenFormatConfigCommon(virConf *conf,
|
||||
virDomainDef *def,
|
||||
virConnectPtr conn,
|
||||
const char *nativeFormat);
|
||||
|
||||
char *xenMakeIPList(virNetDevIPInfo *guestIP);
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user