From patchwork Thu Oct 8 18:58:23 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 35507 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 ozlabs.org (Postfix) with ESMTPS id 2EDB1B6F2B for ; Fri, 9 Oct 2009 06:10:15 +1100 (EST) Received: from localhost ([127.0.0.1]:52800 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvyNQ-0002rc-6Y for incoming@patchwork.ozlabs.org; Thu, 08 Oct 2009 15:10:12 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MvyDv-00068E-Va for qemu-devel@nongnu.org; Thu, 08 Oct 2009 15:00:24 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MvyDs-00066e-1H for qemu-devel@nongnu.org; Thu, 08 Oct 2009 15:00:23 -0400 Received: from [199.232.76.173] (port=52326 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvyDr-00066K-HN for qemu-devel@nongnu.org; Thu, 08 Oct 2009 15:00:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:63510) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MvyDq-0006x8-M9 for qemu-devel@nongnu.org; Thu, 08 Oct 2009 15:00:19 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n98J0Dx0030877 for ; Thu, 8 Oct 2009 15:00:18 -0400 Received: from blaa.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n98J0CSw013075; Thu, 8 Oct 2009 15:00:13 -0400 Received: by blaa.localdomain (Postfix, from userid 500) id 48A4A4F579; Thu, 8 Oct 2009 19:58:33 +0100 (IST) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Thu, 8 Oct 2009 19:58:23 +0100 Message-Id: <1255028312-28180-8-git-send-email-markmc@redhat.com> In-Reply-To: <1255028312-28180-1-git-send-email-markmc@redhat.com> References: <1255028312-28180-1-git-send-email-markmc@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Mark McLoughlin Subject: [Qemu-devel] [PATCH 07/16] net: use qtailq for vlan and client lists 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: Mark McLoughlin --- net.c | 116 +++++++++++++++++++++++++++++++------------------------------- net.h | 6 ++-- savevm.c | 2 +- 3 files changed, 62 insertions(+), 62 deletions(-) diff --git a/net.c b/net.c index 87dcf06..35547a5 100644 --- a/net.c +++ b/net.c @@ -113,10 +113,8 @@ #include "qemu-config.h" #include "slirp/libslirp.h" -#include "qemu-queue.h" - -static VLANState *first_vlan; +static QTAILQ_HEAD(, VLANState) vlans; /***********************************************************/ /* network device redirectors */ @@ -287,12 +285,14 @@ static char *assign_name(VLANClientState *vc1, const char *model) char buf[256]; int id = 0; - for (vlan = first_vlan; vlan; vlan = vlan->next) { + QTAILQ_FOREACH(vlan, &vlans, next) { VLANClientState *vc; - for (vc = vlan->first_client; vc; vc = vc->next) - if (vc != vc1 && strcmp(vc->model, model) == 0) + QTAILQ_FOREACH(vc, &vlan->clients, next) { + if (vc != vc1 && strcmp(vc->model, model) == 0) { id++; + } + } } snprintf(buf, sizeof(buf), "%s.%d", model, id); @@ -309,8 +309,10 @@ VLANClientState *qemu_new_vlan_client(VLANState *vlan, NetCleanup *cleanup, void *opaque) { - VLANClientState *vc, **pvc; + VLANClientState *vc; + vc = qemu_mallocz(sizeof(VLANClientState)); + vc->model = qemu_strdup(model); if (name) vc->name = qemu_strdup(name); @@ -321,43 +323,35 @@ VLANClientState *qemu_new_vlan_client(VLANState *vlan, vc->receive_iov = receive_iov; vc->cleanup = cleanup; vc->opaque = opaque; + vc->vlan = vlan; + QTAILQ_INSERT_TAIL(&vc->vlan->clients, vc, next); - vc->next = NULL; - pvc = &vlan->first_client; - while (*pvc != NULL) - pvc = &(*pvc)->next; - *pvc = vc; return vc; } void qemu_del_vlan_client(VLANClientState *vc) { - VLANClientState **pvc = &vc->vlan->first_client; + QTAILQ_REMOVE(&vc->vlan->clients, vc, next); - while (*pvc != NULL) - if (*pvc == vc) { - *pvc = vc->next; - if (vc->cleanup) { - vc->cleanup(vc); - } - qemu_free(vc->name); - qemu_free(vc->model); - qemu_free(vc); - break; - } else - pvc = &(*pvc)->next; + if (vc->cleanup) { + vc->cleanup(vc); + } + + qemu_free(vc->name); + qemu_free(vc->model); + qemu_free(vc); } VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque) { - VLANClientState **pvc = &vlan->first_client; + VLANClientState *vc; - while (*pvc != NULL) - if ((*pvc)->opaque == opaque) - return *pvc; - else - pvc = &(*pvc)->next; + QTAILQ_FOREACH(vc, &vlan->clients, next) { + if (vc->opaque == opaque) { + return vc; + } + } return NULL; } @@ -375,7 +369,7 @@ qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id, return NULL; } - for (vc = vlan->first_client; vc != NULL; vc = vc->next) { + QTAILQ_FOREACH(vc, &vlan->clients, next) { if (!strcmp(vc->name, client_str)) { break; } @@ -393,7 +387,7 @@ int qemu_can_send_packet(VLANClientState *sender) VLANState *vlan = sender->vlan; VLANClientState *vc; - for (vc = vlan->first_client; vc != NULL; vc = vc->next) { + QTAILQ_FOREACH(vc, &vlan->clients, next) { if (vc == sender) { continue; } @@ -414,7 +408,7 @@ qemu_deliver_packet(VLANClientState *sender, const uint8_t *buf, int size) sender->vlan->delivering = 1; - for (vc = sender->vlan->first_client; vc != NULL; vc = vc->next) { + QTAILQ_FOREACH(vc, &sender->vlan->clients, next) { ssize_t len; if (vc == sender) { @@ -557,7 +551,7 @@ static int qemu_deliver_packet_iov(VLANClientState *sender, sender->vlan->delivering = 1; - for (vc = sender->vlan->first_client; vc != NULL; vc = vc->next) { + QTAILQ_FOREACH(vc, &sender->vlan->clients, next) { ssize_t len; if (vc == sender) { @@ -2305,22 +2299,25 @@ static int net_dump_init(VLANState *vlan, const char *device, /* find or alloc a new VLAN */ VLANState *qemu_find_vlan(int id, int allocate) { - VLANState **pvlan, *vlan; - for(vlan = first_vlan; vlan != NULL; vlan = vlan->next) { - if (vlan->id == id) + VLANState *vlan; + + QTAILQ_FOREACH(vlan, &vlans, next) { + if (vlan->id == id) { return vlan; + } } + if (!allocate) { return NULL; } + vlan = qemu_mallocz(sizeof(VLANState)); vlan->id = id; + QTAILQ_INIT(&vlan->clients); QTAILQ_INIT(&vlan->send_queue); - vlan->next = NULL; - pvlan = &first_vlan; - while (*pvlan != NULL) - pvlan = &(*pvlan)->next; - *pvlan = vlan; + + QTAILQ_INSERT_TAIL(&vlans, vlan, next); + return vlan; } @@ -3118,12 +3115,15 @@ void net_set_boot_mask(int net_boot_mask) void do_info_network(Monitor *mon) { VLANState *vlan; - VLANClientState *vc; - for(vlan = first_vlan; vlan != NULL; vlan = vlan->next) { + QTAILQ_FOREACH(vlan, &vlans, next) { + VLANClientState *vc; + monitor_printf(mon, "VLAN %d devices:\n", vlan->id); - for(vc = vlan->first_client; vc != NULL; vc = vc->next) + + QTAILQ_FOREACH(vc, &vlan->clients, next) { monitor_printf(mon, " %s: %s\n", vc->name, vc->info_str); + } } } @@ -3134,10 +3134,13 @@ void do_set_link(Monitor *mon, const QDict *qdict) const char *name = qdict_get_str(qdict, "name"); const char *up_or_down = qdict_get_str(qdict, "up_or_down"); - for (vlan = first_vlan; vlan != NULL; vlan = vlan->next) - for (vc = vlan->first_client; vc != NULL; vc = vc->next) - if (strcmp(vc->name, name) == 0) + QTAILQ_FOREACH(vlan, &vlans, next) { + QTAILQ_FOREACH(vc, &vlan->clients, next) { + if (strcmp(vc->name, name) == 0) { goto done; + } + } + } done: if (!vc) { @@ -3161,16 +3164,11 @@ void net_cleanup(void) { VLANState *vlan; - /* close network clients */ - for(vlan = first_vlan; vlan != NULL; vlan = vlan->next) { - VLANClientState *vc = vlan->first_client; - - while (vc) { - VLANClientState *next = vc->next; + QTAILQ_FOREACH(vlan, &vlans, next) { + VLANClientState *vc, *next_vc; + QTAILQ_FOREACH_SAFE(vc, &vlan->clients, next, next_vc) { qemu_del_vlan_client(vc); - - vc = next; } } } @@ -3179,7 +3177,7 @@ static void net_check_clients(void) { VLANState *vlan; - for(vlan = first_vlan; vlan != NULL; vlan = vlan->next) { + QTAILQ_FOREACH(vlan, &vlans, next) { if (vlan->nb_guest_devs == 0 && vlan->nb_host_devs == 0) continue; if (vlan->nb_guest_devs == 0) @@ -3206,6 +3204,8 @@ int net_init_clients(void) #endif } + QTAILQ_INIT(&vlans); + if (qemu_opts_foreach(&qemu_net_opts, net_init_client, NULL, 1) == -1) { return -1; } diff --git a/net.h b/net.h index 164ea3d..79e9b47 100644 --- a/net.h +++ b/net.h @@ -26,7 +26,7 @@ struct VLANClientState { LinkStatusChanged *link_status_changed; int link_down; void *opaque; - struct VLANClientState *next; + QTAILQ_ENTRY(VLANClientState) next; struct VLANState *vlan; char *model; char *name; @@ -47,8 +47,8 @@ struct VLANPacket { struct VLANState { int id; - VLANClientState *first_client; - struct VLANState *next; + QTAILQ_HEAD(, VLANClientState) clients; + QTAILQ_ENTRY(VLANState) next; unsigned int nb_guest_devs, nb_host_devs; QTAILQ_HEAD(send_queue, VLANPacket) send_queue; int delivering; diff --git a/savevm.c b/savevm.c index 7a363b6..27a7686 100644 --- a/savevm.c +++ b/savevm.c @@ -131,7 +131,7 @@ static void qemu_announce_self_once(void *opaque) continue; len = announce_self_create(buf, nd_table[i].macaddr); vlan = nd_table[i].vlan; - for(vc = vlan->first_client; vc != NULL; vc = vc->next) { + QTAILQ_FOREACH(vc, &vlan->clients, next) { vc->receive(vc, buf, len); } }