The same, but for nics.
Signed-off-by: Marcelo Tosatti <[EMAIL PROTECTED]>
Index: kvm-userspace.hotplug/qemu/net.h
===================================================================
--- kvm-userspace.hotplug.orig/qemu/net.h
+++ kvm-userspace.hotplug/qemu/net.h
@@ -46,6 +46,7 @@ struct NICInfo {
const char *model;
VLANState *vlan;
int devfn;
+ int used;
};
extern int nb_nics;
Index: kvm-userspace.hotplug/qemu/vl.c
===================================================================
--- kvm-userspace.hotplug.orig/qemu/vl.c
+++ kvm-userspace.hotplug/qemu/vl.c
@@ -4754,6 +4754,15 @@ static int check_params(char *buf, int b
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)
{
@@ -4786,19 +4795,20 @@ static int net_client_init(const char *s
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) {
@@ -4810,6 +4820,7 @@ static int net_client_init(const char *s
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-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel