[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [patch 04/18] qemu: dynamic nic info index allocation
From: |
Marcelo Tosatti |
Subject: |
[Qemu-devel] [patch 04/18] qemu: dynamic nic info index allocation |
Date: |
Wed, 04 Feb 2009 11:33:07 -0200 |
User-agent: |
quilt/0.46-1 |
Dynamically allocate nic info index, so to reuse indexes when devices are
removed.
Signed-off-by: Marcelo Tosatti <address@hidden>
Index: trunk/net.c
===================================================================
--- trunk.orig/net.c
+++ trunk/net.c
@@ -1515,6 +1515,16 @@ VLANState *qemu_find_vlan(int id)
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];
@@ -1571,19 +1581,20 @@ int net_client_init(const char *device,
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) {
@@ -1596,6 +1607,7 @@ int net_client_init(const char *device,
}
nd->vlan = vlan;
nd->name = name;
+ nd->used = 1;
name = NULL;
nb_nics++;
vlan->nb_guest_devs++;
Index: trunk/net.h
===================================================================
--- trunk.orig/net.h
+++ trunk/net.h
@@ -65,6 +65,7 @@ struct NICInfo {
const char *name;
VLANState *vlan;
void *private;
+ int used;
};
extern int nb_nics;
--
- [Qemu-devel] [patch 00/18] acpi pci hotplug support, Marcelo Tosatti, 2009/02/04
- [Qemu-devel] [patch 02/18] qemu: return PCIDevice on net device init and record devfn, Marcelo Tosatti, 2009/02/04
- [Qemu-devel] [patch 03/18] qemu: dynamic drive/drive_opt index allocation, Marcelo Tosatti, 2009/02/04
- [Qemu-devel] [patch 04/18] qemu: dynamic nic info index allocation,
Marcelo Tosatti <=
- [Qemu-devel] [patch 05/18] qemu: drive removal support, Marcelo Tosatti, 2009/02/04
- [Qemu-devel] [patch 06/18] qemu: record devfn on block driver instance, Marcelo Tosatti, 2009/02/04
- [Qemu-devel] [patch 07/18] qemu: move drives_opt for external use, Marcelo Tosatti, 2009/02/04
- [Qemu-devel] [patch 09/18] qemu: add net_client_uninit / qemu_find_vlan_client, Marcelo Tosatti, 2009/02/04
- [Qemu-devel] [patch 08/18] qemu: net/drive add/remove tweaks, Marcelo Tosatti, 2009/02/04
- [Qemu-devel] [patch 10/18] qemu: add cpu_unregister_io_memory and make io mem table index dynamic, Marcelo Tosatti, 2009/02/04
- [Qemu-devel] [patch 11/18] qemu: add qemu_free_irqs, Marcelo Tosatti, 2009/02/04
- [Qemu-devel] [patch 12/18] qemu: add pci_unregister_device, Marcelo Tosatti, 2009/02/04
- [Qemu-devel] [patch 13/18] qemu: warn if PCI region is not power of two, Marcelo Tosatti, 2009/02/04