From: Marcelo Tosatti <[EMAIL PROTECTED]> Dynamically allocate nic info index, so to reuse indexes when devices are removed.
Signed-off-by: Marcelo Tosatti <[EMAIL PROTECTED]> Signed-off-by: Avi Kivity <[EMAIL PROTECTED]> diff --git a/qemu/net.h b/qemu/net.h index 5bb2afb..d45fc9d 100644 --- a/qemu/net.h +++ b/qemu/net.h @@ -46,6 +46,7 @@ struct NICInfo { const char *model; VLANState *vlan; int devfn; + int used; }; extern int nb_nics; diff --git a/qemu/vl.c b/qemu/vl.c index 1b33aec..834d4f7 100644 --- a/qemu/vl.c +++ b/qemu/vl.c @@ -4791,6 +4791,15 @@ static int check_params(char *buf, int buf_size, return 0; } +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; +} static int net_client_init(const char *str) { @@ -4823,19 +4832,20 @@ static int net_client_init(const char *str) 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) { @@ -4847,6 +4857,7 @@ static int net_client_init(const char *str) nd->model = strdup(buf); } nd->vlan = vlan; + nd->used = 1; nb_nics++; vlan->nb_guest_devs++; ret = 0; ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ kvm-commits mailing list kvm-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-commits