From nobody Tue Feb 10 03:40:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1580164889432867.4386484082106; Mon, 27 Jan 2020 14:41:29 -0800 (PST) Received: from localhost ([::1]:51858 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iwD4S-0004UD-AC for importer@patchew.org; Mon, 27 Jan 2020 17:41:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47549) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iwCxk-00014E-AF for qemu-devel@nongnu.org; Mon, 27 Jan 2020 17:34:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iwCxj-0003ny-5B for qemu-devel@nongnu.org; Mon, 27 Jan 2020 17:34:32 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:33075 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iwCxj-0003nf-1I for qemu-devel@nongnu.org; Mon, 27 Jan 2020 17:34:31 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-157-19zYFD4vOS6LhNVWhMRZXg-1; Mon, 27 Jan 2020 17:34:26 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ED38F800D48 for ; Mon, 27 Jan 2020 22:34:25 +0000 (UTC) Received: from secure.mitica (ovpn-116-64.ams2.redhat.com [10.36.116.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0D0E7165D3; Mon, 27 Jan 2020 22:34:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580164470; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gJIadrTNkzEmMqCAUdGwvBZO5d00l8VMeCgOqcs5A8I=; b=ciaLdxNGjOJ/s/+peIJV+tZhBX6hKnnvxkIgLa70EsiLd6CGlzAlyPZl0J419wO1ybaLds 5DtOq7BOchgWZsq9zsvrgHCjVhdGcw2aRY+wvXxowW75LhpF7F9rcKaRax8I7fb+VZDkOY aGj2ngK8L7paR2SMz46S1tSxGrCQOss= From: Juan Quintela To: qemu-devel@nongnu.org Subject: [PULL 18/19] migration: Simplify get_qlist Date: Mon, 27 Jan 2020 23:33:20 +0100 Message-Id: <20200127223321.2742-19-quintela@redhat.com> In-Reply-To: <20200127223321.2742-1-quintela@redhat.com> References: <20200127223321.2742-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: 19zYFD4vOS6LhNVWhMRZXg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Juan Quintela , Markus Armbruster , "Dr. David Alan Gilbert" , Eric Auger , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Eric Auger Instead of inserting read elements at the head and then reversing the list, it is simpler to add each element after the previous one. Introduce QLIST_RAW_INSERT_AFTER helper and use it in get_qlist(). Signed-off-by: Eric Auger Suggested-by: Juan Quintela Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- include/qemu/queue.h | 19 ++++++------------- migration/vmstate-types.c | 10 +++++++--- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/include/qemu/queue.h b/include/qemu/queue.h index 4d4554a7ce..19425f973f 100644 --- a/include/qemu/queue.h +++ b/include/qemu/queue.h @@ -515,6 +515,12 @@ union { = \ (elm); = \ (elm) =3D *QLIST_RAW_NEXT(elm, entry)) =20 +#define QLIST_RAW_INSERT_AFTER(head, prev, elem, entry) do { = \ + *QLIST_RAW_NEXT(prev, entry) =3D elem; = \ + *QLIST_RAW_PREVIOUS(elem, entry) =3D QLIST_RAW_NEXT(prev, entry); = \ + *QLIST_RAW_NEXT(elem, entry) =3D NULL; = \ +} while (0) + #define QLIST_RAW_INSERT_HEAD(head, elm, entry) do { = \ void *first =3D *QLIST_RAW_FIRST(head); = \ *QLIST_RAW_FIRST(head) =3D elm; = \ @@ -527,17 +533,4 @@ union { = \ } = \ } while (0) =20 -#define QLIST_RAW_REVERSE(head, elm, entry) do { = \ - void *iter =3D *QLIST_RAW_FIRST(head), *prev =3D NULL, *next; = \ - while (iter) { = \ - next =3D *QLIST_RAW_NEXT(iter, entry); = \ - *QLIST_RAW_PREVIOUS(iter, entry) =3D QLIST_RAW_NEXT(next, entr= y); \ - *QLIST_RAW_NEXT(iter, entry) =3D prev; = \ - prev =3D iter; = \ - iter =3D next; = \ - } = \ - *QLIST_RAW_FIRST(head) =3D prev; = \ - *QLIST_RAW_PREVIOUS(prev, entry) =3D QLIST_RAW_FIRST(head); = \ -} while (0) - #endif /* QEMU_SYS_QUEUE_H */ diff --git a/migration/vmstate-types.c b/migration/vmstate-types.c index 1eee36773a..35e784c9d9 100644 --- a/migration/vmstate-types.c +++ b/migration/vmstate-types.c @@ -879,7 +879,7 @@ static int get_qlist(QEMUFile *f, void *pv, size_t unus= ed_size, /* offset of the QLIST entry in a QLIST element */ size_t entry_offset =3D field->start; int version_id =3D field->version_id; - void *elm; + void *elm, *prev =3D NULL; =20 trace_get_qlist(field->name, vmsd->name, vmsd->version_id); if (version_id > vmsd->version_id) { @@ -900,9 +900,13 @@ static int get_qlist(QEMUFile *f, void *pv, size_t unu= sed_size, g_free(elm); return ret; } - QLIST_RAW_INSERT_HEAD(pv, elm, entry_offset); + if (!prev) { + QLIST_RAW_INSERT_HEAD(pv, elm, entry_offset); + } else { + QLIST_RAW_INSERT_AFTER(pv, prev, elm, entry_offset); + } + prev =3D elm; } - QLIST_RAW_REVERSE(pv, elm, entry_offset); trace_get_qlist_end(field->name, vmsd->name); =20 return ret; --=20 2.24.1