qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [patch 07/24] QEMU/KVM: dynamic nic info index allocation


From: Marcelo Tosatti
Subject: [Qemu-devel] [patch 07/24] QEMU/KVM: dynamic nic info index allocation
Date: Tue, 11 Mar 2008 17:11:58 -0300
User-agent: quilt/0.46-1

The same, but for nics.

Signed-off-by: Marcelo Tosatti <address@hidden>

Index: kvm-userspace.hotplug2/qemu/net.h
===================================================================
--- kvm-userspace.hotplug2.orig/qemu/net.h
+++ kvm-userspace.hotplug2/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.hotplug2/qemu/vl.c
===================================================================
--- kvm-userspace.hotplug2.orig/qemu/vl.c
+++ kvm-userspace.hotplug2/qemu/vl.c
@@ -4791,6 +4791,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)
 {
@@ -4823,19 +4832,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) {
@@ -4847,6 +4857,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;

-- 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]