From patchwork Sat Jan 25 17:24:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 1229256 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=hVfBKVWg; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 484jcs0pN7z9sNF for ; Sun, 26 Jan 2020 04:27:25 +1100 (AEDT) Received: from localhost ([::1]:55884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ivPDP-0007oU-3l for incoming@patchwork.ozlabs.org; Sat, 25 Jan 2020 12:27:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39375) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ivPBC-000640-CR for qemu-devel@nongnu.org; Sat, 25 Jan 2020 12:25:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ivPBA-00086d-G3 for qemu-devel@nongnu.org; Sat, 25 Jan 2020 12:25:05 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:49769 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 1ivPBA-0007xT-Au for qemu-devel@nongnu.org; Sat, 25 Jan 2020 12:25:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579973102; 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; bh=CYRkzMGr0qa4lzTOn1tCfqrIUWVP++89tVcGXamSgg0=; b=hVfBKVWgMcPh5CIeuoEfru2gSSbgUgQgQ8J4umFzyHMr7sBNrL1TnwzWC+Uq4l+zfH/2lU WNaJ5j8YRkS0Bb7aBEwACy3dANW6YhXzdCS+jADlyhbdZdad6Bmn33xKuHDRwEKDqtvJxz xvWgUduJ6TQbx/n8blFE4l4jIObW3Vg= 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-270-1r9HeJ-YNZGI1g2H6C76tw-1; Sat, 25 Jan 2020 12:25:00 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E528B18543A4; Sat, 25 Jan 2020 17:24:59 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-37.ams2.redhat.com [10.36.116.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6AB2E8E5E2; Sat, 25 Jan 2020 17:24:53 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, dgilbert@redhat.com, quintela@redhat.com Subject: [PATCH] migration: Simplify get_qlist Date: Sat, 25 Jan 2020 18:24:49 +0100 Message-Id: <20200125172449.13175-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: 1r9HeJ-YNZGI1g2H6C76tw-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.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: peterx@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- --- 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) = *QLIST_RAW_NEXT(elm, entry)) +#define QLIST_RAW_INSERT_AFTER(head, prev, elem, entry) do { \ + *QLIST_RAW_NEXT(prev, entry) = elem; \ + *QLIST_RAW_PREVIOUS(elem, entry) = QLIST_RAW_NEXT(prev, entry); \ + *QLIST_RAW_NEXT(elem, entry) = NULL; \ +} while (0) + #define QLIST_RAW_INSERT_HEAD(head, elm, entry) do { \ void *first = *QLIST_RAW_FIRST(head); \ *QLIST_RAW_FIRST(head) = elm; \ @@ -527,17 +533,4 @@ union { \ } \ } while (0) -#define QLIST_RAW_REVERSE(head, elm, entry) do { \ - void *iter = *QLIST_RAW_FIRST(head), *prev = NULL, *next; \ - while (iter) { \ - next = *QLIST_RAW_NEXT(iter, entry); \ - *QLIST_RAW_PREVIOUS(iter, entry) = QLIST_RAW_NEXT(next, entry); \ - *QLIST_RAW_NEXT(iter, entry) = prev; \ - prev = iter; \ - iter = next; \ - } \ - *QLIST_RAW_FIRST(head) = prev; \ - *QLIST_RAW_PREVIOUS(prev, entry) = 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 unused_size, /* offset of the QLIST entry in a QLIST element */ size_t entry_offset = field->start; int version_id = field->version_id; - void *elm; + void *elm, *prev = NULL; 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 unused_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 = elm; } - QLIST_RAW_REVERSE(pv, elm, entry_offset); trace_get_qlist_end(field->name, vmsd->name); return ret;