diff options
Diffstat (limited to 'net')
-rw-r--r-- | net/l2tpv3.c | 9 | ||||
-rw-r--r-- | net/queue.c | 2 | ||||
-rw-r--r-- | net/slirp.c | 2 | ||||
-rw-r--r-- | net/tap.c | 12 |
4 files changed, 18 insertions, 7 deletions
diff --git a/net/l2tpv3.c b/net/l2tpv3.c index 3b805a7a4c..8c598b09bc 100644 --- a/net/l2tpv3.c +++ b/net/l2tpv3.c @@ -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); diff --git a/net/queue.c b/net/queue.c index f948318718..ebbe2bb93b 100644 --- a/net/queue.c +++ b/net/queue.c @@ -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; diff --git a/net/slirp.c b/net/slirp.c index 377d7ef8c0..0cbca3cc83 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -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); @@ -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; + } } } |