Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LXGsr-0003rW-W5 for qemu-devel@nongnu.org; Wed, 11 Feb 2009 10:20:18 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LXGsr-0003qs-0R for qemu-devel@nongnu.org; Wed, 11 Feb 2009 10:20:17 -0500 Received: from [199.232.76.173] (port=52321 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LXGsq-0003qg-HU for qemu-devel@nongnu.org; Wed, 11 Feb 2009 10:20:16 -0500 Received: from savannah.gnu.org ([199.232.41.3]:40267 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LXGsq-00028U-82 for qemu-devel@nongnu.org; Wed, 11 Feb 2009 10:20:16 -0500 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1LXGsl-0004on-3L for qemu-devel@nongnu.org; Wed, 11 Feb 2009 15:20:12 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1LXGsh-0004oI-Gb for qemu-devel@nongnu.org; Wed, 11 Feb 2009 15:20:09 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Wed, 11 Feb 2009 15:20:07 +0000 Subject: [Qemu-devel] [6595] qemu: dynamic nic info index allocation (Marcelo Tosatti) Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 6595 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6595 Author: aliguori Date: 2009-02-11 15:20:03 +0000 (Wed, 11 Feb 2009) Log Message: ----------- qemu: dynamic nic info index allocation (Marcelo Tosatti) Dynamically allocate nic info index, so to reuse indexes when devices are removed. Signed-off-by: Marcelo Tosatti Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/net.c trunk/net.h Modified: trunk/net.c =================================================================== --- trunk/net.c 2009-02-11 15:19:58 UTC (rev 6594) +++ trunk/net.c 2009-02-11 15:20:03 UTC (rev 6595) @@ -1501,6 +1501,16 @@ return vlan; } +static int nic_get_free_idx(void) +{ + int index; + + for (index = 0; index < MAX_NICS; index++) + if (!nd_table[index].used) + return index; + return -1; +} + void qemu_check_nic_model(NICInfo *nd, const char *model) { const char *models[2]; @@ -1557,19 +1567,20 @@ if (!strcmp(device, "nic")) { NICInfo *nd; uint8_t *macaddr; + int idx = nic_get_free_idx(); - if (nb_nics >= MAX_NICS) { + if (idx == -1 || nb_nics >= MAX_NICS) { fprintf(stderr, "Too Many NICs\n"); return -1; } - nd = &nd_table[nb_nics]; + nd = &nd_table[idx]; macaddr = nd->macaddr; macaddr[0] = 0x52; macaddr[1] = 0x54; macaddr[2] = 0x00; macaddr[3] = 0x12; macaddr[4] = 0x34; - macaddr[5] = 0x56 + nb_nics; + macaddr[5] = 0x56 + idx; if (get_param_value(buf, sizeof(buf), "macaddr", p)) { if (parse_macaddr(macaddr, buf) < 0) { @@ -1582,6 +1593,7 @@ } nd->vlan = vlan; nd->name = name; + nd->used = 1; name = NULL; nb_nics++; vlan->nb_guest_devs++; Modified: trunk/net.h =================================================================== --- trunk/net.h 2009-02-11 15:19:58 UTC (rev 6594) +++ trunk/net.h 2009-02-11 15:20:03 UTC (rev 6595) @@ -65,6 +65,7 @@ const char *name; VLANState *vlan; void *private; + int used; }; extern int nb_nics;