[PATCH 2/9] qemu: 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/qemu/qemu_driver.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 1b9d6d16a1..e5be74c461 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -21549,10 +21549,10 @@ qemuDomainGetFSInfo(virDomainPtr dom,
 
 
 static int
-qemuGetDHCPInterfaces(virDomainPtr dom,
-                      virDomainObjPtr vm,
+qemuGetDHCPInterfaces(virDomainObjPtr vm,
                       virDomainInterfacePtr **ifaces)
 {
+    g_autoptr(virConnect) conn = NULL;
     int rv = -1;
     int n_leases = 0;
     size_t i, j;
@@ -21563,21 +21563,20 @@ qemuGetDHCPInterfaces(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)
             continue;
 
         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)
@@ -21723,7 +21722,7 @@ qemuDomainInterfaceAddresses(virDomainPtr dom,
 
     switch (source) {
     case VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE:
-        ret = qemuGetDHCPInterfaces(dom, vm, ifaces);
+        ret = qemuGetDHCPInterfaces(vm, ifaces);
         break;
 
     case VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT:
-- 
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