net: use qtailq for vlan and client lists
Patchworks-ID: 35507 Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
dea7b3b95a
commit
5610c3aaf4
104
net.c
104
net.c
|
@ -113,10 +113,8 @@
|
||||||
#include "qemu-config.h"
|
#include "qemu-config.h"
|
||||||
|
|
||||||
#include "slirp/libslirp.h"
|
#include "slirp/libslirp.h"
|
||||||
#include "qemu-queue.h"
|
|
||||||
|
|
||||||
|
static QTAILQ_HEAD(, VLANState) vlans;
|
||||||
static VLANState *first_vlan;
|
|
||||||
|
|
||||||
/***********************************************************/
|
/***********************************************************/
|
||||||
/* network device redirectors */
|
/* network device redirectors */
|
||||||
|
@ -287,13 +285,15 @@ static char *assign_name(VLANClientState *vc1, const char *model)
|
||||||
char buf[256];
|
char buf[256];
|
||||||
int id = 0;
|
int id = 0;
|
||||||
|
|
||||||
for (vlan = first_vlan; vlan; vlan = vlan->next) {
|
QTAILQ_FOREACH(vlan, &vlans, next) {
|
||||||
VLANClientState *vc;
|
VLANClientState *vc;
|
||||||
|
|
||||||
for (vc = vlan->first_client; vc; vc = vc->next)
|
QTAILQ_FOREACH(vc, &vlan->clients, next) {
|
||||||
if (vc != vc1 && strcmp(vc->model, model) == 0)
|
if (vc != vc1 && strcmp(vc->model, model) == 0) {
|
||||||
id++;
|
id++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "%s.%d", model, id);
|
snprintf(buf, sizeof(buf), "%s.%d", model, id);
|
||||||
|
|
||||||
|
@ -309,8 +309,10 @@ VLANClientState *qemu_new_vlan_client(VLANState *vlan,
|
||||||
NetCleanup *cleanup,
|
NetCleanup *cleanup,
|
||||||
void *opaque)
|
void *opaque)
|
||||||
{
|
{
|
||||||
VLANClientState *vc, **pvc;
|
VLANClientState *vc;
|
||||||
|
|
||||||
vc = qemu_mallocz(sizeof(VLANClientState));
|
vc = qemu_mallocz(sizeof(VLANClientState));
|
||||||
|
|
||||||
vc->model = qemu_strdup(model);
|
vc->model = qemu_strdup(model);
|
||||||
if (name)
|
if (name)
|
||||||
vc->name = qemu_strdup(name);
|
vc->name = qemu_strdup(name);
|
||||||
|
@ -321,43 +323,35 @@ VLANClientState *qemu_new_vlan_client(VLANState *vlan,
|
||||||
vc->receive_iov = receive_iov;
|
vc->receive_iov = receive_iov;
|
||||||
vc->cleanup = cleanup;
|
vc->cleanup = cleanup;
|
||||||
vc->opaque = opaque;
|
vc->opaque = opaque;
|
||||||
vc->vlan = vlan;
|
|
||||||
|
|
||||||
vc->next = NULL;
|
vc->vlan = vlan;
|
||||||
pvc = &vlan->first_client;
|
QTAILQ_INSERT_TAIL(&vc->vlan->clients, vc, next);
|
||||||
while (*pvc != NULL)
|
|
||||||
pvc = &(*pvc)->next;
|
|
||||||
*pvc = vc;
|
|
||||||
return vc;
|
return vc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void qemu_del_vlan_client(VLANClientState *vc)
|
void qemu_del_vlan_client(VLANClientState *vc)
|
||||||
{
|
{
|
||||||
VLANClientState **pvc = &vc->vlan->first_client;
|
QTAILQ_REMOVE(&vc->vlan->clients, vc, next);
|
||||||
|
|
||||||
while (*pvc != NULL)
|
|
||||||
if (*pvc == vc) {
|
|
||||||
*pvc = vc->next;
|
|
||||||
if (vc->cleanup) {
|
if (vc->cleanup) {
|
||||||
vc->cleanup(vc);
|
vc->cleanup(vc);
|
||||||
}
|
}
|
||||||
|
|
||||||
qemu_free(vc->name);
|
qemu_free(vc->name);
|
||||||
qemu_free(vc->model);
|
qemu_free(vc->model);
|
||||||
qemu_free(vc);
|
qemu_free(vc);
|
||||||
break;
|
|
||||||
} else
|
|
||||||
pvc = &(*pvc)->next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque)
|
VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque)
|
||||||
{
|
{
|
||||||
VLANClientState **pvc = &vlan->first_client;
|
VLANClientState *vc;
|
||||||
|
|
||||||
while (*pvc != NULL)
|
QTAILQ_FOREACH(vc, &vlan->clients, next) {
|
||||||
if ((*pvc)->opaque == opaque)
|
if (vc->opaque == opaque) {
|
||||||
return *pvc;
|
return vc;
|
||||||
else
|
}
|
||||||
pvc = &(*pvc)->next;
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -375,7 +369,7 @@ qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (vc = vlan->first_client; vc != NULL; vc = vc->next) {
|
QTAILQ_FOREACH(vc, &vlan->clients, next) {
|
||||||
if (!strcmp(vc->name, client_str)) {
|
if (!strcmp(vc->name, client_str)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -393,7 +387,7 @@ int qemu_can_send_packet(VLANClientState *sender)
|
||||||
VLANState *vlan = sender->vlan;
|
VLANState *vlan = sender->vlan;
|
||||||
VLANClientState *vc;
|
VLANClientState *vc;
|
||||||
|
|
||||||
for (vc = vlan->first_client; vc != NULL; vc = vc->next) {
|
QTAILQ_FOREACH(vc, &vlan->clients, next) {
|
||||||
if (vc == sender) {
|
if (vc == sender) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -414,7 +408,7 @@ qemu_deliver_packet(VLANClientState *sender, const uint8_t *buf, int size)
|
||||||
|
|
||||||
sender->vlan->delivering = 1;
|
sender->vlan->delivering = 1;
|
||||||
|
|
||||||
for (vc = sender->vlan->first_client; vc != NULL; vc = vc->next) {
|
QTAILQ_FOREACH(vc, &sender->vlan->clients, next) {
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
|
|
||||||
if (vc == sender) {
|
if (vc == sender) {
|
||||||
|
@ -557,7 +551,7 @@ static int qemu_deliver_packet_iov(VLANClientState *sender,
|
||||||
|
|
||||||
sender->vlan->delivering = 1;
|
sender->vlan->delivering = 1;
|
||||||
|
|
||||||
for (vc = sender->vlan->first_client; vc != NULL; vc = vc->next) {
|
QTAILQ_FOREACH(vc, &sender->vlan->clients, next) {
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
|
|
||||||
if (vc == sender) {
|
if (vc == sender) {
|
||||||
|
@ -2305,22 +2299,25 @@ static int net_dump_init(VLANState *vlan, const char *device,
|
||||||
/* find or alloc a new VLAN */
|
/* find or alloc a new VLAN */
|
||||||
VLANState *qemu_find_vlan(int id, int allocate)
|
VLANState *qemu_find_vlan(int id, int allocate)
|
||||||
{
|
{
|
||||||
VLANState **pvlan, *vlan;
|
VLANState *vlan;
|
||||||
for(vlan = first_vlan; vlan != NULL; vlan = vlan->next) {
|
|
||||||
if (vlan->id == id)
|
QTAILQ_FOREACH(vlan, &vlans, next) {
|
||||||
|
if (vlan->id == id) {
|
||||||
return vlan;
|
return vlan;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!allocate) {
|
if (!allocate) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
vlan = qemu_mallocz(sizeof(VLANState));
|
vlan = qemu_mallocz(sizeof(VLANState));
|
||||||
vlan->id = id;
|
vlan->id = id;
|
||||||
|
QTAILQ_INIT(&vlan->clients);
|
||||||
QTAILQ_INIT(&vlan->send_queue);
|
QTAILQ_INIT(&vlan->send_queue);
|
||||||
vlan->next = NULL;
|
|
||||||
pvlan = &first_vlan;
|
QTAILQ_INSERT_TAIL(&vlans, vlan, next);
|
||||||
while (*pvlan != NULL)
|
|
||||||
pvlan = &(*pvlan)->next;
|
|
||||||
*pvlan = vlan;
|
|
||||||
return vlan;
|
return vlan;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3118,14 +3115,17 @@ void net_set_boot_mask(int net_boot_mask)
|
||||||
void do_info_network(Monitor *mon)
|
void do_info_network(Monitor *mon)
|
||||||
{
|
{
|
||||||
VLANState *vlan;
|
VLANState *vlan;
|
||||||
|
|
||||||
|
QTAILQ_FOREACH(vlan, &vlans, next) {
|
||||||
VLANClientState *vc;
|
VLANClientState *vc;
|
||||||
|
|
||||||
for(vlan = first_vlan; vlan != NULL; vlan = vlan->next) {
|
|
||||||
monitor_printf(mon, "VLAN %d devices:\n", vlan->id);
|
monitor_printf(mon, "VLAN %d devices:\n", vlan->id);
|
||||||
for(vc = vlan->first_client; vc != NULL; vc = vc->next)
|
|
||||||
|
QTAILQ_FOREACH(vc, &vlan->clients, next) {
|
||||||
monitor_printf(mon, " %s: %s\n", vc->name, vc->info_str);
|
monitor_printf(mon, " %s: %s\n", vc->name, vc->info_str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void do_set_link(Monitor *mon, const QDict *qdict)
|
void do_set_link(Monitor *mon, const QDict *qdict)
|
||||||
{
|
{
|
||||||
|
@ -3134,10 +3134,13 @@ void do_set_link(Monitor *mon, const QDict *qdict)
|
||||||
const char *name = qdict_get_str(qdict, "name");
|
const char *name = qdict_get_str(qdict, "name");
|
||||||
const char *up_or_down = qdict_get_str(qdict, "up_or_down");
|
const char *up_or_down = qdict_get_str(qdict, "up_or_down");
|
||||||
|
|
||||||
for (vlan = first_vlan; vlan != NULL; vlan = vlan->next)
|
QTAILQ_FOREACH(vlan, &vlans, next) {
|
||||||
for (vc = vlan->first_client; vc != NULL; vc = vc->next)
|
QTAILQ_FOREACH(vc, &vlan->clients, next) {
|
||||||
if (strcmp(vc->name, name) == 0)
|
if (strcmp(vc->name, name) == 0) {
|
||||||
goto done;
|
goto done;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
done:
|
done:
|
||||||
|
|
||||||
if (!vc) {
|
if (!vc) {
|
||||||
|
@ -3161,16 +3164,11 @@ void net_cleanup(void)
|
||||||
{
|
{
|
||||||
VLANState *vlan;
|
VLANState *vlan;
|
||||||
|
|
||||||
/* close network clients */
|
QTAILQ_FOREACH(vlan, &vlans, next) {
|
||||||
for(vlan = first_vlan; vlan != NULL; vlan = vlan->next) {
|
VLANClientState *vc, *next_vc;
|
||||||
VLANClientState *vc = vlan->first_client;
|
|
||||||
|
|
||||||
while (vc) {
|
|
||||||
VLANClientState *next = vc->next;
|
|
||||||
|
|
||||||
|
QTAILQ_FOREACH_SAFE(vc, &vlan->clients, next, next_vc) {
|
||||||
qemu_del_vlan_client(vc);
|
qemu_del_vlan_client(vc);
|
||||||
|
|
||||||
vc = next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3179,7 +3177,7 @@ static void net_check_clients(void)
|
||||||
{
|
{
|
||||||
VLANState *vlan;
|
VLANState *vlan;
|
||||||
|
|
||||||
for(vlan = first_vlan; vlan != NULL; vlan = vlan->next) {
|
QTAILQ_FOREACH(vlan, &vlans, next) {
|
||||||
if (vlan->nb_guest_devs == 0 && vlan->nb_host_devs == 0)
|
if (vlan->nb_guest_devs == 0 && vlan->nb_host_devs == 0)
|
||||||
continue;
|
continue;
|
||||||
if (vlan->nb_guest_devs == 0)
|
if (vlan->nb_guest_devs == 0)
|
||||||
|
@ -3206,6 +3204,8 @@ int net_init_clients(void)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QTAILQ_INIT(&vlans);
|
||||||
|
|
||||||
if (qemu_opts_foreach(&qemu_net_opts, net_init_client, NULL, 1) == -1) {
|
if (qemu_opts_foreach(&qemu_net_opts, net_init_client, NULL, 1) == -1) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
6
net.h
6
net.h
|
@ -26,7 +26,7 @@ struct VLANClientState {
|
||||||
LinkStatusChanged *link_status_changed;
|
LinkStatusChanged *link_status_changed;
|
||||||
int link_down;
|
int link_down;
|
||||||
void *opaque;
|
void *opaque;
|
||||||
struct VLANClientState *next;
|
QTAILQ_ENTRY(VLANClientState) next;
|
||||||
struct VLANState *vlan;
|
struct VLANState *vlan;
|
||||||
char *model;
|
char *model;
|
||||||
char *name;
|
char *name;
|
||||||
|
@ -47,8 +47,8 @@ struct VLANPacket {
|
||||||
|
|
||||||
struct VLANState {
|
struct VLANState {
|
||||||
int id;
|
int id;
|
||||||
VLANClientState *first_client;
|
QTAILQ_HEAD(, VLANClientState) clients;
|
||||||
struct VLANState *next;
|
QTAILQ_ENTRY(VLANState) next;
|
||||||
unsigned int nb_guest_devs, nb_host_devs;
|
unsigned int nb_guest_devs, nb_host_devs;
|
||||||
QTAILQ_HEAD(send_queue, VLANPacket) send_queue;
|
QTAILQ_HEAD(send_queue, VLANPacket) send_queue;
|
||||||
int delivering;
|
int delivering;
|
||||||
|
|
2
savevm.c
2
savevm.c
|
@ -131,7 +131,7 @@ static void qemu_announce_self_once(void *opaque)
|
||||||
continue;
|
continue;
|
||||||
len = announce_self_create(buf, nd_table[i].macaddr);
|
len = announce_self_create(buf, nd_table[i].macaddr);
|
||||||
vlan = nd_table[i].vlan;
|
vlan = nd_table[i].vlan;
|
||||||
for(vc = vlan->first_client; vc != NULL; vc = vc->next) {
|
QTAILQ_FOREACH(vc, &vlan->clients, next) {
|
||||||
vc->receive(vc, buf, len);
|
vc->receive(vc, buf, len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue