Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MJRvQ-0007cX-9z for qemu-devel@nongnu.org; Wed, 24 Jun 2009 08:50:04 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MJRvL-0007ZS-AA for qemu-devel@nongnu.org; Wed, 24 Jun 2009 08:50:03 -0400 Received: from [199.232.76.173] (port=53310 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MJRvK-0007Yu-IQ for qemu-devel@nongnu.org; Wed, 24 Jun 2009 08:49:58 -0400 Received: from lizzard.sbs.de ([194.138.37.39]:19622) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MJRvJ-0005ev-CS for qemu-devel@nongnu.org; Wed, 24 Jun 2009 08:49:57 -0400 Resent-To: Anthony Liguori Resent-Message-Id: <4A4220F3.8020307@siemens.com> From: Jan Kiszka Date: Wed, 24 Jun 2009 14:42:31 +0200 Message-ID: <20090624124231.29402.20859.stgit@mchn012c.ww002.siemens.net> In-Reply-To: <20090624124227.29402.750.stgit@mchn012c.ww002.siemens.net> References: <20090624124227.29402.750.stgit@mchn012c.ww002.siemens.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH 39/41] net: Provide VLAN client lookup helper List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Mark McLoughlin , qemu-devel@nongnu.org Introduce qemu_find_vlan_client_by_name for VLANClientState lookup based on VLAN ID and client name. This is useful for monitor commands. Signed-off-by: Jan Kiszka --- hw/xen_nic.c | 2 +- net.c | 44 ++++++++++++++++++++++++++++++++------------ net.h | 2 +- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/hw/xen_nic.c b/hw/xen_nic.c index e4f71f7..4377ed1 100644 --- a/hw/xen_nic.c +++ b/hw/xen_nic.c @@ -301,7 +301,7 @@ static int net_init(struct XenDevice *xendev) if (netdev->mac == NULL) return -1; - vlan = qemu_find_vlan(netdev->xendev.dev); + vlan = qemu_find_vlan(netdev->xendev.dev, 1); netdev->vs = qemu_new_vlan_client(vlan, "xen", NULL, net_rx_ok, net_rx_packet, NULL, NULL, netdev); diff --git a/net.c b/net.c index 917f72f..030c29b 100644 --- a/net.c +++ b/net.c @@ -389,6 +389,32 @@ VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque) return NULL; } +static VLANClientState * +qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id, + const char *client_str) +{ + VLANState *vlan; + VLANClientState *vc; + + vlan = qemu_find_vlan(vlan_id, 0); + if (!vlan) { + monitor_printf(mon, "unknown VLAN %d\n", vlan_id); + return NULL; + } + + for (vc = vlan->first_client; vc != NULL; vc = vc->next) { + if (!strcmp(vc->name, client_str)) { + break; + } + } + if (!vc) { + monitor_printf(mon, "can't find device %s on VLAN %d\n", + client_str, vlan_id); + } + + return vc; +} + int qemu_can_send_packet(VLANClientState *sender) { VLANState *vlan = sender->vlan; @@ -2255,13 +2281,16 @@ static int net_dump_init(Monitor *mon, VLANState *vlan, const char *device, } /* find or alloc a new VLAN */ -VLANState *qemu_find_vlan(int id) +VLANState *qemu_find_vlan(int id, int allocate) { VLANState **pvlan, *vlan; for(vlan = first_vlan; vlan != NULL; vlan = vlan->next) { if (vlan->id == id) return vlan; } + if (!allocate) { + return NULL; + } vlan = qemu_mallocz(sizeof(VLANState)); vlan->id = id; vlan->next = NULL; @@ -2327,7 +2356,7 @@ int net_client_init(Monitor *mon, const char *device, const char *p) if (get_param_value(buf, sizeof(buf), "vlan", p)) { vlan_id = strtol(buf, NULL, 0); } - vlan = qemu_find_vlan(vlan_id); + vlan = qemu_find_vlan(vlan_id, 1); if (get_param_value(buf, sizeof(buf), "name", p)) { name = qemu_strdup(buf); @@ -2724,19 +2753,10 @@ void net_host_device_add(Monitor *mon, const char *device, const char *opts) void net_host_device_remove(Monitor *mon, int vlan_id, const char *device) { - VLANState *vlan; VLANClientState *vc; - vlan = qemu_find_vlan(vlan_id); - - for (vc = vlan->first_client; vc != NULL; vc = vc->next) { - if (!strcmp(vc->name, device)) { - break; - } - } - + vc = qemu_find_vlan_client_by_name(mon, vlan_id, device); if (!vc) { - monitor_printf(mon, "can't find device %s\n", device); return; } if (!net_host_check_device(vc->model)) { diff --git a/net.h b/net.h index 7fcb49d..9fba4c6 100644 --- a/net.h +++ b/net.h @@ -51,7 +51,7 @@ struct VLANState { int delivering; }; -VLANState *qemu_find_vlan(int id); +VLANState *qemu_find_vlan(int id, int allocate); VLANClientState *qemu_new_vlan_client(VLANState *vlan, const char *model, const char *name,