From patchwork Tue Sep 1 00:12:33 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 32698 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id CC61EB7B92 for ; Tue, 1 Sep 2009 10:20:35 +1000 (EST) Received: from localhost ([127.0.0.1]:39981 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MiH6u-0004Ho-Kd for incoming@patchwork.ozlabs.org; Mon, 31 Aug 2009 20:20:32 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MiH1l-00030I-CQ for qemu-devel@nongnu.org; Mon, 31 Aug 2009 20:15:13 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MiH1g-0002yf-EZ for qemu-devel@nongnu.org; Mon, 31 Aug 2009 20:15:12 -0400 Received: from [199.232.76.173] (port=52343 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MiH1g-0002yc-7B for qemu-devel@nongnu.org; Mon, 31 Aug 2009 20:15:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:3483) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MiH1f-0005iu-MW for qemu-devel@nongnu.org; Mon, 31 Aug 2009 20:15:07 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n810F6MF029838; Mon, 31 Aug 2009 20:15:07 -0400 Received: from localhost.localdomain (vpn2-9-5.ams2.redhat.com [10.36.9.5]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n810F156016691; Mon, 31 Aug 2009 20:15:05 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Tue, 1 Sep 2009 02:12:33 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: aliguori@us.ibm.com Subject: [Qemu-devel] [PATCH 3/3] savevm: Convert loadvm handlers list to LIST X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Juan Quintela --- savevm.c | 21 ++++++++++++--------- 1 files changed, 12 insertions(+), 9 deletions(-) diff --git a/savevm.c b/savevm.c index baef277..6adf46c 100644 --- a/savevm.c +++ b/savevm.c @@ -1260,10 +1260,10 @@ static SaveStateEntry *find_se(const char *idstr, int instance_id) } typedef struct LoadStateEntry { + LIST_ENTRY(LoadStateEntry) entry; SaveStateEntry *se; int section_id; int version_id; - struct LoadStateEntry *next; } LoadStateEntry; static int qemu_loadvm_state_v2(QEMUFile *f) @@ -1309,7 +1309,9 @@ static int qemu_loadvm_state_v2(QEMUFile *f) int qemu_loadvm_state(QEMUFile *f) { - LoadStateEntry *first_le = NULL; + LIST_HEAD(, LoadStateEntry) loadvm_handlers = + LIST_HEAD_INITIALIZER(loadvm_handlers); + LoadStateEntry *le, *new_le; uint8_t section_type; unsigned int v; int ret; @@ -1326,7 +1328,6 @@ int qemu_loadvm_state(QEMUFile *f) while ((section_type = qemu_get_byte(f)) != QEMU_VM_EOF) { uint32_t instance_id, version_id, section_id; - LoadStateEntry *le; SaveStateEntry *se; char idstr[257]; int len; @@ -1364,8 +1365,7 @@ int qemu_loadvm_state(QEMUFile *f) le->se = se; le->section_id = section_id; le->version_id = version_id; - le->next = first_le; - first_le = le; + LIST_INSERT_HEAD(&loadvm_handlers, le, entry); ret = vmstate_load(f, le->se, le->version_id); if (ret < 0) { @@ -1378,7 +1378,11 @@ int qemu_loadvm_state(QEMUFile *f) case QEMU_VM_SECTION_END: section_id = qemu_get_be32(f); - for (le = first_le; le && le->section_id != section_id; le = le->next); + LIST_FOREACH(le, &loadvm_handlers, entry) { + if (le->section_id == section_id) { + break; + } + } if (le == NULL) { fprintf(stderr, "Unknown savevm section %d\n", section_id); ret = -EINVAL; @@ -1402,9 +1406,8 @@ int qemu_loadvm_state(QEMUFile *f) ret = 0; out: - while (first_le) { - LoadStateEntry *le = first_le; - first_le = first_le->next; + LIST_FOREACH_SAFE(le, &loadvm_handlers, entry, new_le) { + LIST_REMOVE(le, entry); qemu_free(le); }