On a Monday in 2024, Jim Fehlig via Devel wrote:
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(a)suse.com>
---
src/libxl/libxl_driver.c | 4 ++--
src/libxl/xen_common.c | 25 +++++++++++++++----------
src/libxl/xen_common.h | 1 -
src/libxl/xen_xl.c | 4 ++--
src/libxl/xen_xl.h | 2 +-
src/libxl/xen_xm.c | 5 ++---
src/libxl/xen_xm.h | 2 +-
tests/xlconfigtest.c | 7 +------
tests/xmconfigtest.c | 7 +------
9 files changed, 25 insertions(+), 32 deletions(-)
diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c
index 79eb593432..0b2346d8b5 100644
--- a/src/libxl/xen_common.c
+++ b/src/libxl/xen_common.c
@@ -24,6 +24,7 @@
#include <config.h>
+#include "driver.h"
#include "internal.h"
#include "virerror.h"
#include "virconf.h"
@@ -1586,8 +1587,7 @@ xenMakeIPList(virNetDevIPInfo *guestIP)
}
static int
-xenFormatNet(virConnectPtr conn,
- virConfValue *list,
+xenFormatNet(virConfValue *list,
virDomainNetDef *net,
int hvm,
const char *vif_typename)
@@ -1649,13 +1649,21 @@ xenFormatNet(virConnectPtr conn,
case VIR_DOMAIN_NET_TYPE_NETWORK:
{
- virNetworkPtr network = virNetworkLookupByName(conn, net->data.network.name);
+ virConnectPtr conn = NULL;
You can use:
g_autoptr(virConnect) conn = NULL;
to avoid adding the unref on both branches.
Regardless of that:
Reviewed-by: Ján Tomko <jtomko(a)redhat.com>
Jano
+ 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);
+ virObjectUnref(conn);
return -1;
}
+ virObjectUnref(conn);
+
bridge = virNetworkGetBridgeName(network);
virObjectUnref(network);
if (!bridge) {