[PATCH 15/40] qemu: Convert 'priv->dbusVMStateIds' to a GSList

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

 



The conversion removes the use of virStringListAdd/virStringListRemove
which try to add dynamic properties to a string list which is really
inefficient.

Storing the dbus VMState ids in a GSList is pretty straightforward and
the slightly increased complexity of the code will be paid back by
removing the string list helpers later.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_command.c      |  2 +-
 src/qemu/qemu_dbus.c         | 19 ++++++++++++++++---
 src/qemu/qemu_dbus.h         |  2 +-
 src/qemu/qemu_domain.c       |  4 ++--
 src/qemu/qemu_domain.h       |  2 +-
 src/qemu/qemu_migration.c    | 10 ++++------
 src/qemu/qemu_monitor.c      | 19 +++++++++++++------
 src/qemu/qemu_monitor.h      |  2 +-
 src/qemu/qemu_monitor_json.c |  5 ++---
 src/qemu/qemu_monitor_json.h |  2 +-
 src/qemu/qemu_slirp.c        |  7 ++-----
 11 files changed, 44 insertions(+), 30 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 92036d26c0..ac6bec3389 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -9605,7 +9605,7 @@ qemuBuildDBusVMStateCommandLine(virCommandPtr cmd,
     g_autoptr(virJSONValue) props = NULL;
     qemuDomainObjPrivatePtr priv = QEMU_DOMAIN_PRIVATE(vm);

-    if (virStringListLength((const char **)priv->dbusVMStateIds) == 0)
+    if (!priv->dbusVMStateIds)
         return 0;

     if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DBUS_VMSTATE)) {
diff --git a/src/qemu/qemu_dbus.c b/src/qemu/qemu_dbus.c
index ffcf83e5da..31ede2646f 100644
--- a/src/qemu/qemu_dbus.c
+++ b/src/qemu/qemu_dbus.c
@@ -287,15 +287,28 @@ qemuDBusStart(virQEMUDriverPtr driver,
 }


-int
+void
 qemuDBusVMStateAdd(virDomainObjPtr vm, const char *id)
 {
-    return virStringListAdd(&QEMU_DOMAIN_PRIVATE(vm)->dbusVMStateIds, id);
+    qemuDomainObjPrivatePtr priv = vm->privateData;
+
+    priv->dbusVMStateIds = g_slist_append(priv->dbusVMStateIds, g_strdup(id));
 }


 void
 qemuDBusVMStateRemove(virDomainObjPtr vm, const char *id)
 {
-    virStringListRemove(&QEMU_DOMAIN_PRIVATE(vm)->dbusVMStateIds, id);
+    qemuDomainObjPrivatePtr priv = vm->privateData;
+    GSList *next;
+
+    for (next = priv->dbusVMStateIds; next; next = next->next) {
+        const char *elem = next->data;
+
+        if (STREQ(id, elem)) {
+            priv->dbusVMStateIds = g_slist_remove_link(priv->dbusVMStateIds, next);
+            g_slist_free_full(next, g_free);
+            break;
+        }
+    }
 }
diff --git a/src/qemu/qemu_dbus.h b/src/qemu/qemu_dbus.h
index e3ce1330fd..5900b99144 100644
--- a/src/qemu/qemu_dbus.h
+++ b/src/qemu/qemu_dbus.h
@@ -30,7 +30,7 @@ int qemuDBusStart(virQEMUDriverPtr driver,
 void qemuDBusStop(virQEMUDriverPtr driver,
                   virDomainObjPtr vm);

-int qemuDBusVMStateAdd(virDomainObjPtr vm, const char *id);
+void qemuDBusVMStateAdd(virDomainObjPtr vm, const char *id);

 void qemuDBusVMStateRemove(virDomainObjPtr vm, const char *id);

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 0f09e321fb..31b1110887 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1785,8 +1785,8 @@ qemuDomainObjPrivateDataClear(qemuDomainObjPrivatePtr priv)

     priv->dbusDaemonRunning = false;

-    g_strfreev(priv->dbusVMStateIds);
-    priv->dbusVMStateIds = NULL;
+    if (priv->dbusVMStateIds)
+        g_slist_free_full(g_steal_pointer(&priv->dbusVMStateIds), g_free);

     priv->dbusVMState = false;

diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 7453881a31..29a5dd97d8 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -260,7 +260,7 @@ struct _qemuDomainObjPrivate {
     bool dbusDaemonRunning;

     /* list of Ids to migrate */
-    char **dbusVMStateIds;
+    GSList *dbusVMStateIds;
     /* true if -object dbus-vmstate was added */
     bool dbusVMState;

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index f44d31c971..1bb4a9608e 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1408,7 +1408,7 @@ qemuMigrationSrcIsAllowed(virQEMUDriverPtr driver,
             }
         }

-        if (virStringListLength((const char **)priv->dbusVMStateIds) > 0 &&
+        if (priv->dbusVMStateIds &&
             !virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DBUS_VMSTATE)) {
             virReportError(VIR_ERR_OPERATION_INVALID, "%s",
                            _("cannot migrate this domain without dbus-vmstate support"));
@@ -2091,8 +2091,7 @@ qemuMigrationDstRun(virQEMUDriverPtr driver,
     if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
         return -1;

-    rv = qemuMonitorSetDBusVMStateIdList(priv->mon,
-                                         (const char **)priv->dbusVMStateIds);
+    rv = qemuMonitorSetDBusVMStateIdList(priv->mon, priv->dbusVMStateIds);
     if (rv < 0)
         goto exit_monitor;

@@ -3602,7 +3601,7 @@ qemuMigrationSetDBusVMState(virQEMUDriverPtr driver,
 {
     qemuDomainObjPrivatePtr priv = vm->privateData;

-    if (virStringListLength((const char **)priv->dbusVMStateIds) > 0) {
+    if (priv->dbusVMStateIds) {
         int rv;

         if (qemuHotplugAttachDBusVMState(driver, vm, QEMU_ASYNC_JOB_NONE) < 0)
@@ -3611,8 +3610,7 @@ qemuMigrationSetDBusVMState(virQEMUDriverPtr driver,
         if (qemuDomainObjEnterMonitorAsync(driver, vm, QEMU_ASYNC_JOB_NONE) < 0)
             return -1;

-        rv = qemuMonitorSetDBusVMStateIdList(priv->mon,
-                                             (const char **)priv->dbusVMStateIds);
+        rv = qemuMonitorSetDBusVMStateIdList(priv->mon, priv->dbusVMStateIds);

         if (qemuDomainObjExitMonitor(driver, vm) < 0)
             rv = -1;
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 14966d4096..0476d606f5 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -2385,21 +2385,28 @@ qemuMonitorSavePhysicalMemory(qemuMonitorPtr mon,

 int
 qemuMonitorSetDBusVMStateIdList(qemuMonitorPtr mon,
-                                const char **list)
+                                GSList *list)
 {
     g_autofree char *path = NULL;
+    g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
+    GSList *next;

     VIR_DEBUG("list=%p", list);

-    if (virStringListLength(list) == 0)
+    QEMU_CHECK_MONITOR(mon);
+
+    if (!list)
         return 0;

-    path = g_strdup_printf("/objects/%s",
-                           qemuDomainGetDBusVMStateAlias());
+    for (next = list; next; next = next->next)
+        virBufferAsprintf(&buf, "%s,", (const char *) next->data);

-    QEMU_CHECK_MONITOR(mon);
+    virBufferTrim(&buf, ",");
+
+    path = g_strdup_printf("/objects/%s", qemuDomainGetDBusVMStateAlias());

-    return qemuMonitorJSONSetDBusVMStateIdList(mon, path, list);
+    return qemuMonitorJSONSetDBusVMStateIdList(mon, path,
+                                               virBufferCurrentContent(&buf));
 }


diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index b0068f2a82..32dc96ee82 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -777,7 +777,7 @@ int qemuMonitorSavePhysicalMemory(qemuMonitorPtr mon,
                                   const char *path);

 int qemuMonitorSetDBusVMStateIdList(qemuMonitorPtr mon,
-                                    const char **list);
+                                    GSList *list);

 int qemuMonitorSetMigrationSpeed(qemuMonitorPtr mon,
                                  unsigned long bandwidth);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index d3b2a2c7a5..72b60daecc 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -2359,12 +2359,11 @@ qemuMonitorJSONSetMemoryStatsPeriod(qemuMonitorPtr mon,
 int
 qemuMonitorJSONSetDBusVMStateIdList(qemuMonitorPtr mon,
                                     const char *vmstatepath,
-                                    const char **list)
+                                    const char *idstr)
 {
-    g_autofree char *str = virStringListJoin(list, ",");
     qemuMonitorJSONObjectProperty prop = {
         .type = QEMU_MONITOR_OBJECT_PROPERTY_STRING,
-        .val.str = str,
+        .val.str = idstr,
     };

     return qemuMonitorJSONSetObjectProperty(mon, vmstatepath, "id-list", &prop);
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 64af758885..a550dac33c 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -699,7 +699,7 @@ qemuMonitorJSONTransactionBackup(virJSONValuePtr actions,

 int qemuMonitorJSONSetDBusVMStateIdList(qemuMonitorPtr mon,
                                         const char *vmstatepath,
-                                        const char **list)
+                                        const char *idstr)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);

 int
diff --git a/src/qemu/qemu_slirp.c b/src/qemu/qemu_slirp.c
index 62a6665679..7f6156fbc1 100644
--- a/src/qemu/qemu_slirp.c
+++ b/src/qemu/qemu_slirp.c
@@ -320,11 +320,8 @@ qemuSlirpStart(qemuSlirpPtr slirp,
         virCommandAddArgFormat(cmd, "--dbus-address=%s", dbus_addr);

         if (qemuSlirpHasFeature(slirp, QEMU_SLIRP_FEATURE_MIGRATE)) {
-            if (qemuDBusVMStateAdd(vm, id) < 0) {
-                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                               _("Failed to register slirp migration"));
-                goto error;
-            }
+            qemuDBusVMStateAdd(vm, id);
+
             if (incoming)
                 virCommandAddArg(cmd, "--dbus-incoming");
         }
-- 
2.29.2




[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