[libvirt] [PATCH 04/13] conf: store iothreads in order by iothread_id

Pavel Hrdina phrdina at redhat.com
Fri Feb 17 14:49:08 UTC 2017


Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
---
 src/conf/domain_conf.c                             | 46 ++++++++++++++++++++--
 .../qemuxml2argv-iothreads-ids-partial.args        |  4 +-
 2 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index b303c3f46c..69db692217 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2558,6 +2558,28 @@ virDomainIOThreadIDDefArrayFree(virDomainIOThreadIDDefPtr *def,
 
 
 static int
+virDomainIOThreadInsertGetPos(virDomainDefPtr def,
+                              virDomainIOThreadIDDefPtr iothread)
+{
+    int idx;
+    int pos = -1;
+
+    if (def->niothreadids == 0)
+        return pos;
+
+    for (idx = def->niothreadids - 1; idx >= 0; idx--) {
+        if (def->iothreadids[idx]->iothread_id < iothread->iothread_id)
+            break;
+
+        if (def->iothreadids[idx]->iothread_id > iothread->iothread_id)
+            pos = idx;
+    }
+
+    return pos;
+}
+
+
+static int
 virDomainIOThreadIDDefArrayInit(virDomainDefPtr def,
                                 unsigned int iothreads)
 {
@@ -2586,11 +2608,13 @@ virDomainIOThreadIDDefArrayInit(virDomainDefPtr def,
                                        def->iothreadids[i]->iothread_id));
 
     /* resize array */
-    if (VIR_REALLOC_N(def->iothreadids, iothreads) < 0)
+    if (VIR_EXPAND_N(def->iothreadids, i, iothreads - def->niothreadids) < 0)
         goto error;
 
     /* Populate iothreadids[] using the set bit number from thrmap */
     while (def->niothreadids < iothreads) {
+        int pos;
+
         if ((nxt = virBitmapNextSetBit(thrmap, nxt)) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("failed to populate iothreadids"));
@@ -2600,7 +2624,12 @@ virDomainIOThreadIDDefArrayInit(virDomainDefPtr def,
             goto error;
         iothrid->iothread_id = nxt;
         iothrid->autofill = true;
-        def->iothreadids[def->niothreadids++] = iothrid;
+
+        pos = virDomainIOThreadInsertGetPos(def, iothrid);
+
+        /* VIR_INSERT_ELEMENT_INPLACE will never return an error here. */
+        ignore_value(VIR_INSERT_ELEMENT_INPLACE(def->iothreadids, pos,
+                                                def->niothreadids, iothrid));
     }
 
     retval = 0;
@@ -15584,6 +15613,7 @@ virDomainDefParseIOThreads(virDomainDefPtr def,
         goto error;
 
     for (i = 0; i < n; i++) {
+        int pos;
         virDomainIOThreadIDDefPtr iothrid = NULL;
         if (!(iothrid = virDomainIOThreadIDDefParseXML(nodes[i], ctxt)))
             goto error;
@@ -15595,7 +15625,12 @@ virDomainDefParseIOThreads(virDomainDefPtr def,
             virDomainIOThreadIDDefFree(iothrid);
             goto error;
         }
-        def->iothreadids[def->niothreadids++] = iothrid;
+
+        pos = virDomainIOThreadInsertGetPos(def, iothrid);
+
+        /* VIR_INSERT_ELEMENT_INPLACE will never return an error here. */
+        ignore_value(VIR_INSERT_ELEMENT_INPLACE(def->iothreadids, pos,
+                                                def->niothreadids, iothrid));
     }
     VIR_FREE(nodes);
 
@@ -20149,6 +20184,7 @@ virDomainIOThreadIDAdd(virDomainDefPtr def,
                        unsigned int iothread_id)
 {
     virDomainIOThreadIDDefPtr iothrid = NULL;
+    int pos;
 
     if (virDomainIOThreadIDFind(def, iothread_id)) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -20162,7 +20198,9 @@ virDomainIOThreadIDAdd(virDomainDefPtr def,
 
     iothrid->iothread_id = iothread_id;
 
-    if (VIR_APPEND_ELEMENT_COPY(def->iothreadids, def->niothreadids,
+    pos = virDomainIOThreadInsertGetPos(def, iothrid);
+
+    if (VIR_INSERT_ELEMENT_COPY(def->iothreadids, pos, def->niothreadids,
                                 iothrid) < 0)
         goto error;
 
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-iothreads-ids-partial.args b/tests/qemuxml2argvdata/qemuxml2argv-iothreads-ids-partial.args
index c44162074a..38e4c01aa6 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-iothreads-ids-partial.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-iothreads-ids-partial.args
@@ -10,10 +10,10 @@ QEMU_AUDIO_DRV=none \
 -M pc \
 -m 214 \
 -smp 2,sockets=2,cores=1,threads=1 \
--object iothread,id=iothread5 \
--object iothread,id=iothread6 \
 -object iothread,id=iothread1 \
 -object iothread,id=iothread2 \
+-object iothread,id=iothread5 \
+-object iothread,id=iothread6 \
 -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
 -nographic \
 -nodefaults \
-- 
2.11.1




More information about the libvir-list mailing list