From nobody Sun Feb 8 23:06:02 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) client-ip=209.132.183.24; envelope-from=libvir-list-bounces@redhat.com; helo=mx3-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by mx.zohomail.com with SMTPS id 1487343244307405.21707138648753; Fri, 17 Feb 2017 06:54:04 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v1HEnWOE006012; Fri, 17 Feb 2017 09:49:32 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v1HEnMDt003695 for ; Fri, 17 Feb 2017 09:49:22 -0500 Received: from antique-work.brq.redhat.com (dhcp129-175.brq.redhat.com [10.34.129.175]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1HEnIn1022242 for ; Fri, 17 Feb 2017 09:49:22 -0500 From: Pavel Hrdina To: libvir-list@redhat.com Date: Fri, 17 Feb 2017 15:49:08 +0100 Message-Id: <5a1c0cfd1f0341ee176b189b3f6c810b4cae9387.1487341781.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 04/13] conf: store iothreads in order by iothread_id X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- 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(virDomainIOThreadIDD= efPtr *def, =20 =20 static int +virDomainIOThreadInsertGetPos(virDomainDefPtr def, + virDomainIOThreadIDDefPtr iothread) +{ + int idx; + int pos =3D -1; + + if (def->niothreadids =3D=3D 0) + return pos; + + for (idx =3D def->niothreadids - 1; idx >=3D 0; idx--) { + if (def->iothreadids[idx]->iothread_id < iothread->iothread_id) + break; + + if (def->iothreadids[idx]->iothread_id > iothread->iothread_id) + pos =3D idx; + } + + return pos; +} + + +static int virDomainIOThreadIDDefArrayInit(virDomainDefPtr def, unsigned int iothreads) { @@ -2586,11 +2608,13 @@ virDomainIOThreadIDDefArrayInit(virDomainDefPtr def, def->iothreadids[i]->iothread_id)); =20 /* resize array */ - if (VIR_REALLOC_N(def->iothreadids, iothreads) < 0) + if (VIR_EXPAND_N(def->iothreadids, i, iothreads - def->niothreadids) <= 0) goto error; =20 /* Populate iothreadids[] using the set bit number from thrmap */ while (def->niothreadids < iothreads) { + int pos; + if ((nxt =3D 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 =3D nxt; iothrid->autofill =3D true; - def->iothreadids[def->niothreadids++] =3D iothrid; + + pos =3D 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= )); } =20 retval =3D 0; @@ -15584,6 +15613,7 @@ virDomainDefParseIOThreads(virDomainDefPtr def, goto error; =20 for (i =3D 0; i < n; i++) { + int pos; virDomainIOThreadIDDefPtr iothrid =3D NULL; if (!(iothrid =3D virDomainIOThreadIDDefParseXML(nodes[i], ctxt))) goto error; @@ -15595,7 +15625,12 @@ virDomainDefParseIOThreads(virDomainDefPtr def, virDomainIOThreadIDDefFree(iothrid); goto error; } - def->iothreadids[def->niothreadids++] =3D iothrid; + + pos =3D 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); =20 @@ -20149,6 +20184,7 @@ virDomainIOThreadIDAdd(virDomainDefPtr def, unsigned int iothread_id) { virDomainIOThreadIDDefPtr iothrid =3D NULL; + int pos; =20 if (virDomainIOThreadIDFind(def, iothread_id)) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -20162,7 +20198,9 @@ virDomainIOThreadIDAdd(virDomainDefPtr def, =20 iothrid->iothread_id =3D iothread_id; =20 - if (VIR_APPEND_ELEMENT_COPY(def->iothreadids, def->niothreadids, + pos =3D virDomainIOThreadInsertGetPos(def, iothrid); + + if (VIR_INSERT_ELEMENT_COPY(def->iothreadids, pos, def->niothreadids, iothrid) < 0) goto error; =20 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=3Dnone \ -M pc \ -m 214 \ -smp 2,sockets=3D2,cores=3D1,threads=3D1 \ --object iothread,id=3Diothread5 \ --object iothread,id=3Diothread6 \ -object iothread,id=3Diothread1 \ -object iothread,id=3Diothread2 \ +-object iothread,id=3Diothread5 \ +-object iothread,id=3Diothread6 \ -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ -nographic \ -nodefaults \ --=20 2.11.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list