[PATCH] qemu_monitor: search memballoon QOM device path using alias

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

 



Commit 4a585a88 introduced searching QOM device path by alias, let's use it for
memballoon too.  This may speedup the search because in most cases we will find
the correct QOM device path directly by using alias without the need for the
recursion code.

Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 src/qemu/qemu_driver.c  |  5 +++--
 src/qemu/qemu_monitor.c | 29 ++++++++++++++++++-----------
 src/qemu/qemu_monitor.h |  2 ++
 src/qemu/qemu_process.c | 10 ++++------
 4 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d5ba3b8..0501003 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -2455,7 +2455,7 @@ static int qemuDomainSetMemoryStatsPeriod(virDomainPtr dom, int period,
         }
 
         qemuDomainObjEnterMonitor(driver, vm);
-        r = qemuMonitorSetMemoryStatsPeriod(priv->mon, period);
+        r = qemuMonitorSetMemoryStatsPeriod(priv->mon, def->memballoon, period);
         if (qemuDomainObjExitMonitor(driver, vm) < 0)
             goto endjob;
         if (r < 0) {
@@ -11003,7 +11003,8 @@ qemuDomainMemoryStats(virDomainPtr dom,
     if (vm->def->memballoon &&
         vm->def->memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO) {
         qemuDomainObjEnterMonitor(driver, vm);
-        ret = qemuMonitorGetMemoryStats(qemuDomainGetMonitor(vm), stats, nr_stats);
+        ret = qemuMonitorGetMemoryStats(qemuDomainGetMonitor(vm),
+                                        vm->def->memballoon, stats, nr_stats);
         if (qemuDomainObjExitMonitor(driver, vm) < 0)
             ret = -1;
 
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 1fac4de..58c04d5 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -1068,11 +1068,12 @@ qemuMonitorSetOptions(qemuMonitorPtr mon, virJSONValuePtr options)
  * This feature was added to QEMU 1.5.
  */
 static void
-qemuMonitorInitBalloonObjectPath(qemuMonitorPtr mon)
+qemuMonitorInitBalloonObjectPath(qemuMonitorPtr mon,
+                                 virDomainMemballoonDefPtr balloon)
 {
     ssize_t i, nprops = 0;
-    int flp_ret = 0;
     char *path = NULL;
+    const char *name;
     qemuMonitorJSONListPathPtr *bprops = NULL;
 
     if (mon->balloonpath) {
@@ -1084,16 +1085,20 @@ qemuMonitorInitBalloonObjectPath(qemuMonitorPtr mon)
     }
     mon->ballooninit = true;
 
-    flp_ret = qemuMonitorJSONFindLinkPath(mon, "virtio-balloon-pci", NULL, &path);
-    if (flp_ret == -2) {
-        /* pci object was not found retry search for ccw object */
-        if (qemuMonitorJSONFindLinkPath(mon, "virtio-balloon-ccw",
-                                        NULL, &path) < 0)
-            return;
-    } else if (flp_ret < 0) {
+    switch (balloon->info.type) {
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
+        name = "virtio-balloon-pci";
+        break;
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW:
+        name = "virtio-balloon-ccw";
+        break;
+    default:
         return;
     }
 
+    if (qemuMonitorJSONFindLinkPath(mon, name, balloon->info.alias, &path) < 0)
+        return;
+
     nprops = qemuMonitorJSONGetObjectListPaths(mon, path, &bprops);
     if (nprops < 0)
         goto cleanup;
@@ -1718,6 +1723,7 @@ qemuMonitorGetBalloonInfo(qemuMonitorPtr mon,
 
 int
 qemuMonitorGetMemoryStats(qemuMonitorPtr mon,
+                          virDomainMemballoonDefPtr balloon,
                           virDomainMemoryStatPtr stats,
                           unsigned int nr_stats)
 {
@@ -1726,7 +1732,7 @@ qemuMonitorGetMemoryStats(qemuMonitorPtr mon,
     QEMU_CHECK_MONITOR(mon);
 
     if (mon->json) {
-        qemuMonitorInitBalloonObjectPath(mon);
+        qemuMonitorInitBalloonObjectPath(mon, balloon);
         return qemuMonitorJSONGetMemoryStats(mon, mon->balloonpath,
                                              stats, nr_stats);
     } else {
@@ -1744,6 +1750,7 @@ qemuMonitorGetMemoryStats(qemuMonitorPtr mon,
  */
 int
 qemuMonitorSetMemoryStatsPeriod(qemuMonitorPtr mon,
+                                virDomainMemballoonDefPtr balloon,
                                 int period)
 {
     int ret = -1;
@@ -1758,7 +1765,7 @@ qemuMonitorSetMemoryStatsPeriod(qemuMonitorPtr mon,
     if (period < 0)
         return -1;
 
-    qemuMonitorInitBalloonObjectPath(mon);
+    qemuMonitorInitBalloonObjectPath(mon, balloon);
     if (mon->balloonpath) {
         ret = qemuMonitorJSONSetMemoryStatsPeriod(mon, mon->balloonpath,
                                                   period);
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index cb4cca8..ae0954d 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -397,9 +397,11 @@ int qemuMonitorGetVirtType(qemuMonitorPtr mon,
 int qemuMonitorGetBalloonInfo(qemuMonitorPtr mon,
                               unsigned long long *currmem);
 int qemuMonitorGetMemoryStats(qemuMonitorPtr mon,
+                              virDomainMemballoonDefPtr balloon,
                               virDomainMemoryStatPtr stats,
                               unsigned int nr_stats);
 int qemuMonitorSetMemoryStatsPeriod(qemuMonitorPtr mon,
+                                    virDomainMemballoonDefPtr balloon,
                                     int period);
 
 int qemuMonitorBlockIOStatusToError(const char *status);
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 4adb14e..c7639c1 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4268,19 +4268,17 @@ qemuProcessSetupBalloon(virQEMUDriverPtr driver,
 {
     unsigned long long balloon = vm->def->mem.cur_balloon;
     qemuDomainObjPrivatePtr priv = vm->privateData;
-    int period;
     int ret = -1;
 
     if (!virDomainDefHasMemballoon(vm->def))
         return 0;
 
-    period = vm->def->memballoon->period;
-
     if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
         goto cleanup;
 
-    if (period)
-        qemuMonitorSetMemoryStatsPeriod(priv->mon, period);
+    if (vm->def->memballoon->period)
+        qemuMonitorSetMemoryStatsPeriod(priv->mon, vm->def->memballoon,
+                                        vm->def->memballoon->period);
     if (qemuMonitorSetBalloon(priv->mon, balloon) < 0)
         goto cleanup;
 
@@ -6022,7 +6020,7 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED,
             vm->def->memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO &&
             vm->def->memballoon->period) {
             qemuDomainObjEnterMonitor(driver, vm);
-            qemuMonitorSetMemoryStatsPeriod(priv->mon,
+            qemuMonitorSetMemoryStatsPeriod(priv->mon, vm->def->memballoon,
                                             vm->def->memballoon->period);
             if (qemuDomainObjExitMonitor(driver, vm) < 0)
                 goto error;
-- 
2.9.2

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