net: multiqueue support

This patch adds basic multiqueue support for qemu. The idea is simple, an array
of NetClientStates were introduced in NICState, parse_netdev() were extended to
find and match all NetClientStates belongs to the backend and place their
pointers in NICConf. Then qemu_new_nic can setup a N:N mapping between NICStates
that belongs to a nic and NICStates belongs to the netdev. And a queue_index
were introduced in NetClientState to track its index. After this, each peers of
a NICState were abstracted as a queue.

After this change, all NetClientState that belongs to the same backend/nic has
the same id. When use want to change the link status, all NetClientStates that
belongs to the same backend/nic will be also changed. When user want to delete
a device or netdev, all NetClientStates that belongs to the same backend/nic
will be deleted also. Changing or deleting an specific queue is not allowed.

Signed-off-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Jason Wang
2013-01-30 19:12:28 +08:00
committed by Anthony Liguori
parent f7860455fd
commit 1ceef9f273
6 changed files with 139 additions and 48 deletions

View File

@ -173,16 +173,47 @@ PropertyInfo qdev_prop_chr = {
static int parse_netdev(DeviceState *dev, const char *str, void **ptr)
{
NetClientState *netdev = qemu_find_netdev(str);
NICPeers *peers_ptr = (NICPeers *)ptr;
NICConf *conf = container_of(peers_ptr, NICConf, peers);
NetClientState **ncs = peers_ptr->ncs;
NetClientState *peers[MAX_QUEUE_NUM];
int queues, i = 0;
int ret;
if (netdev == NULL) {
return -ENOENT;
queues = qemu_find_net_clients_except(str, peers,
NET_CLIENT_OPTIONS_KIND_NIC,
MAX_QUEUE_NUM);
if (queues == 0) {
ret = -ENOENT;
goto err;
}
if (netdev->peer) {
return -EEXIST;
if (queues > MAX_QUEUE_NUM) {
ret = -E2BIG;
goto err;
}
*ptr = netdev;
for (i = 0; i < queues; i++) {
if (peers[i] == NULL) {
ret = -ENOENT;
goto err;
}
if (peers[i]->peer) {
ret = -EEXIST;
goto err;
}
ncs[i] = peers[i];
ncs[i]->queue_index = i;
}
conf->queues = queues;
return 0;
err:
return ret;
}
static const char *print_netdev(void *ptr)
@ -249,7 +280,8 @@ static void set_vlan(Object *obj, Visitor *v, void *opaque,
{
DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
NetClientState **ptr = qdev_get_prop_ptr(dev, prop);
NICPeers *peers_ptr = qdev_get_prop_ptr(dev, prop);
NetClientState **ptr = &peers_ptr->ncs[0];
Error *local_err = NULL;
int32_t id;
NetClientState *hubport;