[PATCH 6/6] qemu: remove virConnectPtr from some more startup code paths

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

 



There's a few places in startup code paths which pass around a
virConnectPtr which is no longer required. Specifically, the
qemuProcessStart() method now only requires a non-NULL connection if
autodestroy is requested.

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 src/qemu/qemu_driver.c  | 35 +++++++----------------------------
 src/qemu/qemu_process.c | 26 ++++++++------------------
 src/qemu/qemu_process.h |  2 +-
 3 files changed, 16 insertions(+), 47 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index c44b1f8793..c747b4319e 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -181,12 +181,6 @@ static virNWFilterCallbackDriver qemuCallbackDriver = {
 };
 
 
-struct qemuAutostartData {
-    virQEMUDriverPtr driver;
-    virConnectPtr conn;
-};
-
-
 /**
  * qemuDomObjFromDomain:
  * @domain: Domain pointer that has to be looked up
@@ -254,9 +248,9 @@ static int
 qemuAutostartDomain(virDomainObjPtr vm,
                     void *opaque)
 {
-    struct qemuAutostartData *data = opaque;
+    virQEMUDriverPtr driver = opaque;
     int flags = 0;
-    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(data->driver);
+    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
     int ret = -1;
 
     if (cfg->autoStartBypassCache)
@@ -267,7 +261,7 @@ qemuAutostartDomain(virDomainObjPtr vm,
     virResetLastError();
     if (vm->autostart &&
         !virDomainObjIsActive(vm)) {
-        if (qemuProcessBeginJob(data->driver, vm,
+        if (qemuProcessBeginJob(driver, vm,
                                 VIR_DOMAIN_JOB_OPERATION_START) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Failed to start job on VM '%s': %s"),
@@ -275,14 +269,14 @@ qemuAutostartDomain(virDomainObjPtr vm,
             goto cleanup;
         }
 
-        if (qemuDomainObjStart(data->conn, data->driver, vm, flags,
+        if (qemuDomainObjStart(NULL, driver, vm, flags,
                                QEMU_ASYNC_JOB_START) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Failed to autostart VM '%s': %s"),
                            vm->def->name, virGetLastErrorMessage());
         }
 
-        qemuProcessEndJob(data->driver, vm);
+        qemuProcessEndJob(driver, vm);
     }
 
     ret = 0;
@@ -297,18 +291,9 @@ static void
 qemuAutostartDomains(virQEMUDriverPtr driver)
 {
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
-    /* XXX: Figure out a better way todo this. The domain
-     * startup code needs a connection handle in order
-     * to lookup the bridge associated with a virtual
-     * network
-     */
-    virConnectPtr conn = virConnectOpen(cfg->uri);
-    /* Ignoring NULL conn which is mostly harmless here */
-    struct qemuAutostartData data = { driver, conn };
 
-    virDomainObjListForEach(driver->domains, qemuAutostartDomain, &data);
+    virDomainObjListForEach(driver->domains, qemuAutostartDomain, driver);
 
-    virObjectUnref(conn);
     virObjectUnref(cfg);
 }
 
@@ -623,7 +608,6 @@ qemuStateInitialize(bool privileged,
                     void *opaque)
 {
     char *driverConf = NULL;
-    virConnectPtr conn = NULL;
     virQEMUDriverConfigPtr cfg;
     uid_t run_uid = -1;
     gid_t run_gid = -1;
@@ -933,8 +917,6 @@ qemuStateInitialize(bool privileged,
                             qemuDomainNetsRestart,
                             NULL);
 
-    conn = virConnectOpen(cfg->uri);
-
     /* Then inactive persistent configs */
     if (virDomainObjListLoadAllConfigs(qemu_driver->domains,
                                        cfg->configDir,
@@ -952,19 +934,16 @@ qemuStateInitialize(bool privileged,
                             qemuDomainManagedSaveLoad,
                             qemu_driver);
 
-    qemuProcessReconnectAll(conn, qemu_driver);
+    qemuProcessReconnectAll(qemu_driver);
 
     qemu_driver->workerPool = virThreadPoolNew(0, 1, 0, qemuProcessEventHandler, qemu_driver);
     if (!qemu_driver->workerPool)
         goto error;
 
-    virObjectUnref(conn);
-
     virNWFilterRegisterCallbackDriver(&qemuCallbackDriver);
     return 0;
 
  error:
-    virObjectUnref(conn);
     VIR_FREE(driverConf);
     VIR_FREE(hugepagePath);
     VIR_FREE(memoryBackingPath);
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 703d62d3e9..77c93bedab 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -2749,7 +2749,6 @@ qemuProcessUpdateVideoRamSize(virQEMUDriverPtr driver,
 
 
 struct qemuProcessHookData {
-    virConnectPtr conn;
     virDomainObjPtr vm;
     virQEMUDriverPtr driver;
     virQEMUDriverConfigPtr cfg;
@@ -5937,7 +5936,12 @@ qemuProcessLaunch(virConnectPtr conn,
 
     cfg = virQEMUDriverGetConfig(driver);
 
-    hookData.conn = conn;
+    if ((flags & VIR_QEMU_PROCESS_START_AUTODESTROY) && !conn) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("Domain autodestroy requirs a connection handle"));
+        return -1;
+    }
+
     hookData.vm = vm;
     hookData.driver = driver;
     /* We don't increase cfg's reference counter here. */
@@ -7246,7 +7250,6 @@ qemuProcessRefreshCPU(virQEMUDriverPtr driver,
 
 
 struct qemuProcessReconnectData {
-    virConnectPtr conn;
     virQEMUDriverPtr driver;
     virDomainObjPtr obj;
 };
@@ -7254,10 +7257,6 @@ struct qemuProcessReconnectData {
  * Open an existing VM's monitor, re-detect VCPU threads
  * and re-reserve the security labels in use
  *
- * We own the virConnectPtr we are passed here - whoever started
- * this thread function has increased the reference counter to it
- * so that we now have to close it.
- *
  * This function also inherits a locked and ref'd domain object.
  *
  * This function needs to:
@@ -7279,7 +7278,6 @@ qemuProcessReconnect(void *opaque)
     virQEMUDriverPtr driver = data->driver;
     virDomainObjPtr obj = data->obj;
     qemuDomainObjPrivatePtr priv;
-    virConnectPtr conn = data->conn;
     struct qemuDomainJobObj oldjob;
     int state;
     int reason;
@@ -7501,7 +7499,6 @@ qemuProcessReconnect(void *opaque)
             qemuDomainRemoveInactiveJob(driver, obj);
     }
     virDomainObjEndAPI(&obj);
-    virObjectUnref(conn);
     virObjectUnref(cfg);
     virObjectUnref(caps);
     virNWFilterUnlockFilterUpdates();
@@ -7557,12 +7554,6 @@ qemuProcessReconnectHelper(virDomainObjPtr obj,
     virObjectLock(obj);
     virObjectRef(obj);
 
-    /* Since we close the connection later on, we have to make sure that the
-     * threads we start see a valid connection throughout their lifetime. We
-     * simply increase the reference counter here.
-     */
-    virObjectRef(data->conn);
-
     if (virThreadCreate(&thread, false, qemuProcessReconnect, data) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Could not create thread. QEMU initialization "
@@ -7578,7 +7569,6 @@ qemuProcessReconnectHelper(virDomainObjPtr obj,
 
         virDomainObjEndAPI(&obj);
         virNWFilterUnlockFilterUpdates();
-        virObjectUnref(data->conn);
         VIR_FREE(data);
         return -1;
     }
@@ -7593,8 +7583,8 @@ qemuProcessReconnectHelper(virDomainObjPtr obj,
  * about.
  */
 void
-qemuProcessReconnectAll(virConnectPtr conn, virQEMUDriverPtr driver)
+qemuProcessReconnectAll(virQEMUDriverPtr driver)
 {
-    struct qemuProcessReconnectData data = {.conn = conn, .driver = driver};
+    struct qemuProcessReconnectData data = {.driver = driver};
     virDomainObjListForEach(driver->domains, qemuProcessReconnectHelper, &data);
 }
diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h
index 1bc1203c18..2741115673 100644
--- a/src/qemu/qemu_process.h
+++ b/src/qemu/qemu_process.h
@@ -47,7 +47,7 @@ int qemuProcessDestroyMemoryBackingPath(virQEMUDriverPtr driver,
                                         virDomainMemoryDefPtr mem);
 
 void qemuProcessAutostartAll(virQEMUDriverPtr driver);
-void qemuProcessReconnectAll(virConnectPtr conn, virQEMUDriverPtr driver);
+void qemuProcessReconnectAll(virQEMUDriverPtr driver);
 
 typedef struct _qemuProcessIncomingDef qemuProcessIncomingDef;
 typedef qemuProcessIncomingDef *qemuProcessIncomingDefPtr;
-- 
2.14.3

--
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