[PATCH 5/9] libxl: Don't use dom->conn to lookup virNetwork

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When using the monolithic daemon, then dom->conn has all driver
tables filled in properly and thus it's safe to call an API other
than virDomain*(). However, when using split daemons then
dom->conn has only hypervisor driver table set
(dom->conn->driver) and the rest is NULL. Therefore, if we want
to call a non-domain API (virNetworkLookupByName() in this case),
we have obtain the cached connection object accessible via
virGetConnectNetwork().

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/libxl/libxl_driver.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 44a74e8779..ccef4f3955 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -6235,10 +6235,10 @@ static int libxlNodeGetSecurityModel(virConnectPtr conn,
 }
 
 static int
-libxlGetDHCPInterfaces(virDomainPtr dom,
-                       virDomainObjPtr vm,
+libxlGetDHCPInterfaces(virDomainObjPtr vm,
                        virDomainInterfacePtr **ifaces)
 {
+    g_autoptr(virConnect) conn = NULL;
     int rv = -1;
     int n_leases = 0;
     size_t i, j;
@@ -6249,12 +6249,8 @@ libxlGetDHCPInterfaces(virDomainPtr dom,
     virNetworkDHCPLeasePtr *leases = NULL;
     virDomainInterfacePtr *ifaces_ret = NULL;
 
-    if (!dom->conn->networkDriver ||
-        !dom->conn->networkDriver->networkGetDHCPLeases) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("Network driver does not support DHCP lease query"));
+    if (!(conn = virGetConnectNetwork()))
         return -1;
-    }
 
     for (i = 0; i < vm->def->nnets; i++) {
         if (vm->def->nets[i]->type != VIR_DOMAIN_NET_TYPE_NETWORK)
@@ -6262,8 +6258,10 @@ libxlGetDHCPInterfaces(virDomainPtr dom,
 
         virMacAddrFormat(&(vm->def->nets[i]->mac), macaddr);
         virObjectUnref(network);
-        network = virNetworkLookupByName(dom->conn,
+        network = virNetworkLookupByName(conn,
                                          vm->def->nets[i]->data.network.name);
+        if (!network)
+            goto error;
 
         if ((n_leases = virNetworkGetDHCPLeases(network, macaddr,
                                                 &leases, 0)) < 0)
@@ -6351,7 +6349,7 @@ libxlDomainInterfaceAddresses(virDomainPtr dom,
 
     switch (source) {
     case VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE:
-        ret = libxlGetDHCPInterfaces(dom, vm, ifaces);
+        ret = libxlGetDHCPInterfaces(vm, ifaces);
         break;
 
     default:
-- 
2.23.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux