[PATCH] qemu: domain: Extract common clearing of VM private data

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

 



VM private data is cleared when the VM is turned off and also when the
VM object is being freed. Some of the clearing code was duplicated.
Extract it to a separate function.

This also removes the now unnecessary function
qemuDomainClearPrivatePaths.
---
 src/qemu/qemu_domain.c  | 76 +++++++++++++++++++++++++++++++++----------------
 src/qemu/qemu_domain.h  |  4 +--
 src/qemu/qemu_process.c | 36 ++---------------------
 3 files changed, 55 insertions(+), 61 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index cb371f1e8..7cb2bfce1 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1684,16 +1684,6 @@ qemuDomainSetPrivatePaths(virQEMUDriverPtr driver,
 }


-void
-qemuDomainClearPrivatePaths(virDomainObjPtr vm)
-{
-    qemuDomainObjPrivatePtr priv = vm->privateData;
-
-    VIR_FREE(priv->libDir);
-    VIR_FREE(priv->channelTargetDir);
-}
-
-
 static void *
 qemuDomainObjPrivateAlloc(void *opaque)
 {
@@ -1721,24 +1711,69 @@ qemuDomainObjPrivateAlloc(void *opaque)
     return NULL;
 }

-static void
-qemuDomainObjPrivateFree(void *data)
+/**
+ * qemuDomainObjPrivateDataClear:
+ * @priv: domain private data
+ *
+ * Clears private data entries, which are not necessary or stale if the VM is
+ * not running.
+ */
+void
+qemuDomainObjPrivateDataClear(qemuDomainObjPrivatePtr priv)
 {
-    qemuDomainObjPrivatePtr priv = data;
+    virStringListFree(priv->qemuDevices);
+    priv->qemuDevices = NULL;
+
+    virCgroupFree(&priv->cgroup);
+
+    virPerfFree(priv->perf);
+    priv->perf = NULL;
+
+    VIR_FREE(priv->machineName);

     virObjectUnref(priv->qemuCaps);
+    priv->qemuCaps = NULL;

-    virBitmapFree(priv->namespaces);
+    VIR_FREE(priv->pidfile);

-    virCgroupFree(&priv->cgroup);
+    VIR_FREE(priv->libDir);
+    VIR_FREE(priv->channelTargetDir);
+
+    /* remove automatic pinning data */
+    virBitmapFree(priv->autoNodeset);
+    priv->autoNodeset = NULL;
+    virBitmapFree(priv->autoCpuset);
+    priv->autoCpuset = NULL;
+
+    /* remove address data */
     virDomainPCIAddressSetFree(priv->pciaddrs);
+    priv->pciaddrs = NULL;
     virDomainUSBAddressSetFree(priv->usbaddrs);
+    priv->usbaddrs = NULL;
+
+    /* clean up migration data */
+    VIR_FREE(priv->migTLSAlias);
+    virCPUDefFree(priv->origCPU);
+    priv->origCPU = NULL;
+
+    /* clear previously used namespaces */
+    virBitmapFree(priv->namespaces);
+    priv->namespaces = NULL;
+}
+
+
+static void
+qemuDomainObjPrivateFree(void *data)
+{
+    qemuDomainObjPrivatePtr priv = data;
+
+    qemuDomainObjPrivateDataClear(priv);
+
     virDomainChrSourceDefFree(priv->monConfig);
     qemuDomainObjFreeJob(priv);
     VIR_FREE(priv->lockState);
     VIR_FREE(priv->origname);

-    virStringListFree(priv->qemuDevices);
     virChrdevFree(priv->devs);

     /* This should never be non-NULL if we get here, but just in case... */
@@ -1751,19 +1786,10 @@ qemuDomainObjPrivateFree(void *data)
         qemuAgentClose(priv->agent);
     }
     VIR_FREE(priv->cleanupCallbacks);
-    virBitmapFree(priv->autoNodeset);
-    virBitmapFree(priv->autoCpuset);
-
-    VIR_FREE(priv->machineName);
-    VIR_FREE(priv->libDir);
-    VIR_FREE(priv->channelTargetDir);

     qemuDomainSecretInfoFree(&priv->migSecinfo);
-    VIR_FREE(priv->migTLSAlias);
     qemuDomainMasterKeyFree(priv);

-    virCPUDefFree(priv->origCPU);
-
     VIR_FREE(priv);
 }

diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 09201b1a4..cdf94b2f6 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -676,6 +676,8 @@ void qemuDomainCleanupRemove(virDomainObjPtr vm,
 void qemuDomainCleanupRun(virQEMUDriverPtr driver,
                           virDomainObjPtr vm);

+void qemuDomainObjPrivateDataClear(qemuDomainObjPrivatePtr priv);
+
 extern virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks;
 extern virDomainXMLNamespace virQEMUDriverDomainXMLNamespace;
 extern virDomainDefParserConfig virQEMUDriverDomainDefParserConfig;
@@ -783,8 +785,6 @@ int qemuDomainNetVLAN(virDomainNetDefPtr def);
 int qemuDomainSetPrivatePaths(virQEMUDriverPtr driver,
                               virDomainObjPtr vm);

-void qemuDomainClearPrivatePaths(virDomainObjPtr vm);
-
 virDomainDiskDefPtr qemuDomainDiskByName(virDomainDefPtr def, const char *name);

 char *qemuDomainGetMasterKeyFilePath(const char *libDir);
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index c104985aa..0a2493770 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -6196,8 +6196,6 @@ void qemuProcessStop(virQEMUDriverPtr driver,
     virFileDeleteTree(priv->libDir);
     virFileDeleteTree(priv->channelTargetDir);

-    qemuDomainClearPrivatePaths(vm);
-
     ignore_value(virDomainChrDefForeach(vm->def,
                                         false,
                                         qemuProcessCleanupChardevDevice,
@@ -6248,9 +6246,6 @@ void qemuProcessStop(virQEMUDriverPtr driver,
         VIR_FREE(vm->def->seclabels[i]->imagelabel);
     }

-    virStringListFree(priv->qemuDevices);
-    priv->qemuDevices = NULL;
-
     qemuHostdevReAttachDomainDevices(driver, vm->def);

     def = vm->def;
@@ -6319,10 +6314,6 @@ void qemuProcessStop(virQEMUDriverPtr driver,
         VIR_WARN("Failed to remove cgroup for %s",
                  vm->def->name);
     }
-    virCgroupFree(&priv->cgroup);
-
-    virPerfFree(priv->perf);
-    priv->perf = NULL;

     qemuProcessRemoveDomainStatus(driver, vm);

@@ -6376,37 +6367,14 @@ void qemuProcessStop(virQEMUDriverPtr driver,
         }
     }

-    VIR_FREE(priv->machineName);
-
     vm->taint = 0;
     vm->pid = -1;
     virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, reason);
     for (i = 0; i < vm->def->niothreadids; i++)
         vm->def->iothreadids[i]->thread_id = 0;
-    virObjectUnref(priv->qemuCaps);
-    priv->qemuCaps = NULL;
-    VIR_FREE(priv->pidfile);

-    /* remove automatic pinning data */
-    virBitmapFree(priv->autoNodeset);
-    priv->autoNodeset = NULL;
-    virBitmapFree(priv->autoCpuset);
-    priv->autoCpuset = NULL;
-
-    /* remove address data */
-    virDomainPCIAddressSetFree(priv->pciaddrs);
-    priv->pciaddrs = NULL;
-    virDomainUSBAddressSetFree(priv->usbaddrs);
-    priv->usbaddrs = NULL;
-
-    /* clean up migration data */
-    VIR_FREE(priv->migTLSAlias);
-    virCPUDefFree(priv->origCPU);
-    priv->origCPU = NULL;
-
-    /* clear previously used namespaces */
-    virBitmapFree(priv->namespaces);
-    priv->namespaces = NULL;
+    /* clear all private data entries which are no longer needed */
+    qemuDomainObjPrivateDataClear(priv);

     /* The "release" hook cleans up additional resources */
     if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) {
-- 
2.14.1

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