mirror of https://gitee.com/openkylin/qemu.git
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1 iQEcBAABAgAGBQJUlCWaAAoJEJykq7OBq3PImO0IAMngtyIaBYOeb4qQU1X5+C2f 8HTp3usHj8qdl3W2iak0jo88cUiX2HTdliHnnGbmShKNyjrAOJuk/4OdGKc5W0UC lBabUsyJeOh0RWG9i33/6jru061RbRewJcohXikFeRLP6h5ed5GZtK7OjtcMYcDB j+VyfCPgf1l8upDmJrBAJdduRYjWgvl1jh0Y780rURE0YGHTiYzzki/wcvgBOm5K n5UVkp9qOpQVLd6TdyS3YpJrAPnpkxfQtfqrZ2AIxZX0OL+PPzDX6amTp83cN8zf 2FB4dLy3c/l/Hf7vEoMQlU+XP9B0I87MmzGLFYcMAu79a2EOGyXPtpa+bKlCknw= =qMs3 -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/stefanha/tags/net-pull-request' into staging # gpg: Signature made Fri 19 Dec 2014 13:18:18 GMT using RSA key ID 81AB73C8 # gpg: Good signature from "Stefan Hajnoczi <stefanha@redhat.com>" # gpg: aka "Stefan Hajnoczi <stefanha@gmail.com>" * remotes/stefanha/tags/net-pull-request: e1000: defer packets until BM enabled net: Use g_new() & friends where that makes obvious sense net: Fuse g_malloc(); memset() into g_new0() net: don't use set/get_pointer() in set/get_netdev() tap: fix vcpu long time io blocking on tap Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
328b3b6c44
|
@ -177,42 +177,69 @@ PropertyInfo qdev_prop_chr = {
|
|||
};
|
||||
|
||||
/* --- netdev device --- */
|
||||
|
||||
static int parse_netdev(DeviceState *dev, const char *str, void **ptr)
|
||||
static void get_netdev(Object *obj, Visitor *v, void *opaque,
|
||||
const char *name, Error **errp)
|
||||
{
|
||||
NICPeers *peers_ptr = (NICPeers *)ptr;
|
||||
DeviceState *dev = DEVICE(obj);
|
||||
Property *prop = opaque;
|
||||
NICPeers *peers_ptr = qdev_get_prop_ptr(dev, prop);
|
||||
char *p = g_strdup(peers_ptr->ncs[0] ? peers_ptr->ncs[0]->name : "");
|
||||
|
||||
visit_type_str(v, &p, name, errp);
|
||||
g_free(p);
|
||||
}
|
||||
|
||||
static void set_netdev(Object *obj, Visitor *v, void *opaque,
|
||||
const char *name, Error **errp)
|
||||
{
|
||||
DeviceState *dev = DEVICE(obj);
|
||||
Property *prop = opaque;
|
||||
NICPeers *peers_ptr = qdev_get_prop_ptr(dev, prop);
|
||||
NetClientState **ncs = peers_ptr->ncs;
|
||||
NetClientState *peers[MAX_QUEUE_NUM];
|
||||
int queues, i = 0;
|
||||
int ret;
|
||||
Error *local_err = NULL;
|
||||
int queues, err = 0, i = 0;
|
||||
char *str;
|
||||
|
||||
if (dev->realized) {
|
||||
qdev_prop_set_after_realize(dev, name, errp);
|
||||
return;
|
||||
}
|
||||
|
||||
visit_type_str(v, &str, name, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
return;
|
||||
}
|
||||
|
||||
queues = qemu_find_net_clients_except(str, peers,
|
||||
NET_CLIENT_OPTIONS_KIND_NIC,
|
||||
MAX_QUEUE_NUM);
|
||||
if (queues == 0) {
|
||||
ret = -ENOENT;
|
||||
goto err;
|
||||
err = -ENOENT;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (queues > MAX_QUEUE_NUM) {
|
||||
ret = -E2BIG;
|
||||
goto err;
|
||||
error_setg(errp, "queues of backend '%s'(%d) exceeds QEMU limitation(%d)",
|
||||
str, queues, MAX_QUEUE_NUM);
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (i = 0; i < queues; i++) {
|
||||
if (peers[i] == NULL) {
|
||||
ret = -ENOENT;
|
||||
goto err;
|
||||
err = -ENOENT;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (peers[i]->peer) {
|
||||
ret = -EEXIST;
|
||||
goto err;
|
||||
err = -EEXIST;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (ncs[i]) {
|
||||
ret = -EINVAL;
|
||||
goto err;
|
||||
err = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ncs[i] = peers[i];
|
||||
|
@ -221,30 +248,9 @@ static int parse_netdev(DeviceState *dev, const char *str, void **ptr)
|
|||
|
||||
peers_ptr->queues = queues;
|
||||
|
||||
return 0;
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static char *print_netdev(void *ptr)
|
||||
{
|
||||
NetClientState *netdev = ptr;
|
||||
const char *val = netdev->name ? netdev->name : "";
|
||||
|
||||
return g_strdup(val);
|
||||
}
|
||||
|
||||
static void get_netdev(Object *obj, Visitor *v, void *opaque,
|
||||
const char *name, Error **errp)
|
||||
{
|
||||
get_pointer(obj, v, opaque, print_netdev, name, errp);
|
||||
}
|
||||
|
||||
static void set_netdev(Object *obj, Visitor *v, void *opaque,
|
||||
const char *name, Error **errp)
|
||||
{
|
||||
set_pointer(obj, v, opaque, parse_netdev, name, errp);
|
||||
out:
|
||||
error_set_from_qdev_prop_error(errp, err, dev, prop, str);
|
||||
g_free(str);
|
||||
}
|
||||
|
||||
PropertyInfo qdev_prop_netdev = {
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "sysemu/sysemu.h"
|
||||
#include "sysemu/dma.h"
|
||||
#include "qemu/iov.h"
|
||||
#include "qemu/range.h"
|
||||
|
||||
#include "e1000_regs.h"
|
||||
|
||||
|
@ -923,7 +924,9 @@ e1000_can_receive(NetClientState *nc)
|
|||
E1000State *s = qemu_get_nic_opaque(nc);
|
||||
|
||||
return (s->mac_reg[STATUS] & E1000_STATUS_LU) &&
|
||||
(s->mac_reg[RCTL] & E1000_RCTL_EN) && e1000_has_rxbufs(s, 1);
|
||||
(s->mac_reg[RCTL] & E1000_RCTL_EN) &&
|
||||
(s->parent_obj.config[PCI_COMMAND] & PCI_COMMAND_MASTER) &&
|
||||
e1000_has_rxbufs(s, 1);
|
||||
}
|
||||
|
||||
static uint64_t rx_desc_base(E1000State *s)
|
||||
|
@ -1529,6 +1532,20 @@ static NetClientInfo net_e1000_info = {
|
|||
.link_status_changed = e1000_set_link_status,
|
||||
};
|
||||
|
||||
static void e1000_write_config(PCIDevice *pci_dev, uint32_t address,
|
||||
uint32_t val, int len)
|
||||
{
|
||||
E1000State *s = E1000(pci_dev);
|
||||
|
||||
pci_default_write_config(pci_dev, address, val, len);
|
||||
|
||||
if (range_covers_byte(address, len, PCI_COMMAND) &&
|
||||
(pci_dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
|
||||
qemu_flush_queued_packets(qemu_get_queue(s->nic));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int pci_e1000_init(PCIDevice *pci_dev)
|
||||
{
|
||||
DeviceState *dev = DEVICE(pci_dev);
|
||||
|
@ -1539,6 +1556,8 @@ static int pci_e1000_init(PCIDevice *pci_dev)
|
|||
int i;
|
||||
uint8_t *macaddr;
|
||||
|
||||
pci_dev->config_write = e1000_write_config;
|
||||
|
||||
pci_conf = pci_dev->config;
|
||||
|
||||
/* TODO: RST# value should be 0, PCI spec 6.2.4 */
|
||||
|
|
|
@ -489,12 +489,12 @@ static struct mmsghdr *build_l2tpv3_vector(NetL2TPV3State *s, int count)
|
|||
struct iovec *iov;
|
||||
struct mmsghdr *msgvec, *result;
|
||||
|
||||
msgvec = g_malloc(sizeof(struct mmsghdr) * count);
|
||||
msgvec = g_new(struct mmsghdr, count);
|
||||
result = msgvec;
|
||||
for (i = 0; i < count ; i++) {
|
||||
msgvec->msg_hdr.msg_name = NULL;
|
||||
msgvec->msg_hdr.msg_namelen = 0;
|
||||
iov = g_malloc(sizeof(struct iovec) * IOVSIZE);
|
||||
iov = g_new(struct iovec, IOVSIZE);
|
||||
msgvec->msg_hdr.msg_iov = iov;
|
||||
iov->iov_base = g_malloc(s->header_size);
|
||||
iov->iov_len = s->header_size;
|
||||
|
@ -695,8 +695,7 @@ int net_init_l2tpv3(const NetClientOptions *opts,
|
|||
goto outerr;
|
||||
}
|
||||
|
||||
s->dgram_dst = g_malloc(sizeof(struct sockaddr_storage));
|
||||
memset(s->dgram_dst, '\0' , sizeof(struct sockaddr_storage));
|
||||
s->dgram_dst = g_new0(struct sockaddr_storage, 1);
|
||||
memcpy(s->dgram_dst, result->ai_addr, result->ai_addrlen);
|
||||
s->dst_size = result->ai_addrlen;
|
||||
|
||||
|
@ -730,7 +729,7 @@ int net_init_l2tpv3(const NetClientOptions *opts,
|
|||
}
|
||||
|
||||
s->msgvec = build_l2tpv3_vector(s, MAX_L2TPV3_MSGCNT);
|
||||
s->vec = g_malloc(sizeof(struct iovec) * MAX_L2TPV3_IOVCNT);
|
||||
s->vec = g_new(struct iovec, MAX_L2TPV3_IOVCNT);
|
||||
s->header_buf = g_malloc(s->header_size);
|
||||
|
||||
qemu_set_nonblock(fd);
|
||||
|
|
|
@ -62,7 +62,7 @@ NetQueue *qemu_new_net_queue(void *opaque)
|
|||
{
|
||||
NetQueue *queue;
|
||||
|
||||
queue = g_malloc0(sizeof(NetQueue));
|
||||
queue = g_new0(NetQueue, 1);
|
||||
|
||||
queue->opaque = opaque;
|
||||
queue->nq_maxlen = 10000;
|
||||
|
|
|
@ -652,7 +652,7 @@ static int slirp_guestfwd(SlirpState *s, const char *config_str,
|
|||
return -1;
|
||||
}
|
||||
} else {
|
||||
fwd = g_malloc(sizeof(struct GuestFwd));
|
||||
fwd = g_new(struct GuestFwd, 1);
|
||||
fwd->hd = qemu_chr_new(buf, p, NULL);
|
||||
if (!fwd->hd) {
|
||||
error_report("could not open guest forwarding device '%s'", buf);
|
||||
|
|
12
net/tap.c
12
net/tap.c
|
@ -189,6 +189,7 @@ static void tap_send(void *opaque)
|
|||
{
|
||||
TAPState *s = opaque;
|
||||
int size;
|
||||
int packets = 0;
|
||||
|
||||
while (qemu_can_send_packet(&s->nc)) {
|
||||
uint8_t *buf = s->buf;
|
||||
|
@ -210,6 +211,17 @@ static void tap_send(void *opaque)
|
|||
} else if (size < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* When the host keeps receiving more packets while tap_send() is
|
||||
* running we can hog the QEMU global mutex. Limit the number of
|
||||
* packets that are processed per tap_send() callback to prevent
|
||||
* stalling the guest.
|
||||
*/
|
||||
packets++;
|
||||
if (packets >= 50) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue