Commit 7697079b73360cef3d8f1cd014a87bd923464b26
1 parent
7d5aca9e
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 <mtosatti@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6595 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
2 changed files
with
16 additions
and
3 deletions
net.c
... | ... | @@ -1501,6 +1501,16 @@ VLANState *qemu_find_vlan(int id) |
1501 | 1501 | return vlan; |
1502 | 1502 | } |
1503 | 1503 | |
1504 | +static int nic_get_free_idx(void) | |
1505 | +{ | |
1506 | + int index; | |
1507 | + | |
1508 | + for (index = 0; index < MAX_NICS; index++) | |
1509 | + if (!nd_table[index].used) | |
1510 | + return index; | |
1511 | + return -1; | |
1512 | +} | |
1513 | + | |
1504 | 1514 | void qemu_check_nic_model(NICInfo *nd, const char *model) |
1505 | 1515 | { |
1506 | 1516 | const char *models[2]; |
... | ... | @@ -1557,19 +1567,20 @@ int net_client_init(const char *device, const char *p) |
1557 | 1567 | if (!strcmp(device, "nic")) { |
1558 | 1568 | NICInfo *nd; |
1559 | 1569 | uint8_t *macaddr; |
1570 | + int idx = nic_get_free_idx(); | |
1560 | 1571 | |
1561 | - if (nb_nics >= MAX_NICS) { | |
1572 | + if (idx == -1 || nb_nics >= MAX_NICS) { | |
1562 | 1573 | fprintf(stderr, "Too Many NICs\n"); |
1563 | 1574 | return -1; |
1564 | 1575 | } |
1565 | - nd = &nd_table[nb_nics]; | |
1576 | + nd = &nd_table[idx]; | |
1566 | 1577 | macaddr = nd->macaddr; |
1567 | 1578 | macaddr[0] = 0x52; |
1568 | 1579 | macaddr[1] = 0x54; |
1569 | 1580 | macaddr[2] = 0x00; |
1570 | 1581 | macaddr[3] = 0x12; |
1571 | 1582 | macaddr[4] = 0x34; |
1572 | - macaddr[5] = 0x56 + nb_nics; | |
1583 | + macaddr[5] = 0x56 + idx; | |
1573 | 1584 | |
1574 | 1585 | if (get_param_value(buf, sizeof(buf), "macaddr", p)) { |
1575 | 1586 | if (parse_macaddr(macaddr, buf) < 0) { |
... | ... | @@ -1582,6 +1593,7 @@ int net_client_init(const char *device, const char *p) |
1582 | 1593 | } |
1583 | 1594 | nd->vlan = vlan; |
1584 | 1595 | nd->name = name; |
1596 | + nd->used = 1; | |
1585 | 1597 | name = NULL; |
1586 | 1598 | nb_nics++; |
1587 | 1599 | vlan->nb_guest_devs++; | ... | ... |