From: Mark McLoughlin <markmc@redhat.com>
To: qemu-devel@nongnu.org
Cc: Mark McLoughlin <markmc@redhat.com>
Subject: [Qemu-devel] [PATCH 6/8] net: add '-net tap,sndbuf=nbytes'
Date: Thu, 18 Jun 2009 18:21:34 +0100 [thread overview]
Message-ID: <1245345696-20915-7-git-send-email-markmc@redhat.com> (raw)
In-Reply-To: <1245345696-20915-6-git-send-email-markmc@redhat.com>
2.6.30 adds a new TUNSETSNDBUF ioctl() which allows a send buffer limit
for the tap device to be specified. When this limit is reached, a tap
write() will return EAGAIN and poll() will indicate the fd isn't
writable.
This allows people to tune their setups so as to avoid e.g. UDP packet
loss when the sending application in the guest out-runs the NIC in the
host.
There is no obviously sensible default setting - a suitable value
depends mostly on the capabilities of the physical NIC through which the
packets are being sent.
Also, note that when using a bridge with netfilter enabled, we currently
never get EAGAIN because netfilter causes the packet to be immediately
orphaned. Set /proc/sys/net/bridge/bridge nf-call-iptables to zero to
disable this behaviour.
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
net.c | 26 ++++++++++++++++++++++----
qemu-options.hx | 9 ++++++++-
2 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/net.c b/net.c
index 58f3d51..1bf7c6b 100644
--- a/net.c
+++ b/net.c
@@ -1162,6 +1162,18 @@ static void tap_send(void *opaque)
} while (size > 0);
}
+static void tap_set_sndbuf(TAPState *s, int sndbuf, Monitor *mon)
+{
+#ifdef TUNSETSNDBUF
+ if (ioctl(s->fd, TUNSETSNDBUF, &sndbuf) == -1) {
+ config_error(mon, "TUNSETSNDBUF ioctl failed: %s\n",
+ strerror(errno));
+ }
+#else
+ config_error(mon, "No '-net tap,sndbuf=<nbytes>' support available\n");
+#endif
+}
+
static void tap_cleanup(VLANClientState *vc)
{
TAPState *s = vc->opaque;
@@ -2141,9 +2153,6 @@ void qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
int net_client_init(Monitor *mon, const char *device, const char *p)
{
- static const char * const fd_params[] = {
- "vlan", "name", "fd", NULL
- };
char buf[1024];
int vlan_id, ret;
VLANState *vlan;
@@ -2295,6 +2304,9 @@ int net_client_init(Monitor *mon, const char *device, const char *p)
int fd;
vlan->nb_host_devs++;
if (get_param_value(buf, sizeof(buf), "fd", p) > 0) {
+ static const char * const fd_params[] = {
+ "vlan", "name", "fd", "sndbuf", NULL
+ };
if (check_params(chkbuf, sizeof(chkbuf), fd_params, p) < 0) {
config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p);
ret = -1;
@@ -2305,7 +2317,7 @@ int net_client_init(Monitor *mon, const char *device, const char *p)
s = net_tap_fd_init(vlan, device, name, fd);
} else {
static const char * const tap_params[] = {
- "vlan", "name", "ifname", "script", "downscript", NULL
+ "vlan", "name", "ifname", "script", "downscript", "sndbuf", NULL
};
if (check_params(chkbuf, sizeof(chkbuf), tap_params, p) < 0) {
config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p);
@@ -2324,6 +2336,9 @@ int net_client_init(Monitor *mon, const char *device, const char *p)
s = net_tap_init(vlan, device, name, ifname, setup_script, down_script);
}
if (s != NULL) {
+ if (get_param_value(buf, sizeof(buf), "sndbuf", p)) {
+ tap_set_sndbuf(s, atoi(buf), mon);
+ }
ret = 0;
} else {
ret = -1;
@@ -2333,6 +2348,9 @@ int net_client_init(Monitor *mon, const char *device, const char *p)
if (!strcmp(device, "socket")) {
char chkbuf[64];
if (get_param_value(buf, sizeof(buf), "fd", p) > 0) {
+ static const char * const fd_params[] = {
+ "vlan", "name", "fd", NULL
+ };
int fd;
if (check_params(chkbuf, sizeof(chkbuf), fd_params, p) < 0) {
config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p);
diff --git a/qemu-options.hx b/qemu-options.hx
index 9d5e05a..06e2505 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -744,12 +744,19 @@ DEF("net", HAS_ARG, QEMU_OPTION_net,
"-net tap[,vlan=n][,name=str],ifname=name\n"
" connect the host TAP network interface to VLAN 'n'\n"
#else
- "-net tap[,vlan=n][,name=str][,fd=h][,ifname=name][,script=file][,downscript=dfile]\n"
+ "-net tap[,vlan=n][,name=str][,fd=h][,ifname=name][,script=file][,downscript=dfile]"
+#ifdef TUNSETSNDBUF
+ "[,sndbuf=nbytes]"
+#endif
+ "\n"
" connect the host TAP network interface to VLAN 'n' and use the\n"
" network scripts 'file' (default=%s)\n"
" and 'dfile' (default=%s);\n"
" use '[down]script=no' to disable script execution;\n"
" use 'fd=h' to connect to an already opened TAP interface\n"
+#ifdef TUNSETSNDBUF
+ " use 'sndbuf=nbytes' to limit the size of the send buffer\n"
+#endif
#endif
"-net socket[,vlan=n][,name=str][,fd=h][,listen=[host]:port][,connect=host:port]\n"
" connect the vlan 'n' to another VLAN using a socket connection\n"
--
1.6.0.6
next prev parent reply other threads:[~2009-06-18 17:21 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-18 17:21 [Qemu-devel] [PATCH 0/8] TUNSETSNDBUF - pushback to help UDP tx Mark McLoughlin
2009-06-18 17:21 ` [Qemu-devel] [PATCH 1/8] net: add qemu_purge_queued_packets() Mark McLoughlin
2009-06-18 17:21 ` [Qemu-devel] [PATCH 2/8] net: purge queued packets in tap_cleanup() Mark McLoughlin
2009-06-18 17:21 ` [Qemu-devel] [PATCH 3/8] net: add tap_read_poll() helper Mark McLoughlin
2009-06-18 17:21 ` [Qemu-devel] [PATCH 4/8] net: handle EAGAIN from tapfd write() Mark McLoughlin
2009-06-18 17:21 ` [Qemu-devel] [PATCH 5/8] net: return TAPState from net_tap_init() Mark McLoughlin
2009-06-18 17:21 ` Mark McLoughlin [this message]
2009-06-18 17:21 ` [Qemu-devel] [PATCH 7/8] net: add packet length to NetPacketSent callback Mark McLoughlin
2009-06-18 17:21 ` [Qemu-devel] [PATCH 8/8] virtio-net: implement async packet sending Mark McLoughlin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1245345696-20915-7-git-send-email-markmc@redhat.com \
--to=markmc@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).