提交 0df0ff6d 编写于 作者: M Mark McLoughlin 提交者: Anthony Liguori

net: add '-net tap,sndbuf=nbytes'

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: NMark McLoughlin <markmc@redhat.com>
Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
上级 4a77b25e
...@@ -1162,6 +1162,18 @@ static void tap_send(void *opaque) ...@@ -1162,6 +1162,18 @@ static void tap_send(void *opaque)
} while (size > 0); } 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) static void tap_cleanup(VLANClientState *vc)
{ {
TAPState *s = vc->opaque; TAPState *s = vc->opaque;
...@@ -2141,9 +2153,6 @@ void qemu_check_nic_model_list(NICInfo *nd, const char * const *models, ...@@ -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) 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]; char buf[1024];
int vlan_id, ret; int vlan_id, ret;
VLANState *vlan; VLANState *vlan;
...@@ -2298,6 +2307,9 @@ int net_client_init(Monitor *mon, const char *device, const char *p) ...@@ -2298,6 +2307,9 @@ int net_client_init(Monitor *mon, const char *device, const char *p)
int fd; int fd;
vlan->nb_host_devs++; vlan->nb_host_devs++;
if (get_param_value(buf, sizeof(buf), "fd", p) > 0) { 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) { if (check_params(chkbuf, sizeof(chkbuf), fd_params, p) < 0) {
config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p); config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p);
ret = -1; ret = -1;
...@@ -2308,7 +2320,7 @@ int net_client_init(Monitor *mon, const char *device, const char *p) ...@@ -2308,7 +2320,7 @@ int net_client_init(Monitor *mon, const char *device, const char *p)
s = net_tap_fd_init(vlan, device, name, fd); s = net_tap_fd_init(vlan, device, name, fd);
} else { } else {
static const char * const tap_params[] = { 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) { if (check_params(chkbuf, sizeof(chkbuf), tap_params, p) < 0) {
config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p); config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p);
...@@ -2327,6 +2339,9 @@ int net_client_init(Monitor *mon, const char *device, const char *p) ...@@ -2327,6 +2339,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); s = net_tap_init(vlan, device, name, ifname, setup_script, down_script);
} }
if (s != NULL) { if (s != NULL) {
if (get_param_value(buf, sizeof(buf), "sndbuf", p)) {
tap_set_sndbuf(s, atoi(buf), mon);
}
ret = 0; ret = 0;
} else { } else {
ret = -1; ret = -1;
...@@ -2336,6 +2351,9 @@ int net_client_init(Monitor *mon, const char *device, const char *p) ...@@ -2336,6 +2351,9 @@ int net_client_init(Monitor *mon, const char *device, const char *p)
if (!strcmp(device, "socket")) { if (!strcmp(device, "socket")) {
char chkbuf[64]; char chkbuf[64];
if (get_param_value(buf, sizeof(buf), "fd", p) > 0) { if (get_param_value(buf, sizeof(buf), "fd", p) > 0) {
static const char * const fd_params[] = {
"vlan", "name", "fd", NULL
};
int fd; int fd;
if (check_params(chkbuf, sizeof(chkbuf), fd_params, p) < 0) { if (check_params(chkbuf, sizeof(chkbuf), fd_params, p) < 0) {
config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p); config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p);
......
...@@ -747,12 +747,19 @@ DEF("net", HAS_ARG, QEMU_OPTION_net, ...@@ -747,12 +747,19 @@ DEF("net", HAS_ARG, QEMU_OPTION_net,
"-net tap[,vlan=n][,name=str],ifname=name\n" "-net tap[,vlan=n][,name=str],ifname=name\n"
" connect the host TAP network interface to VLAN 'n'\n" " connect the host TAP network interface to VLAN 'n'\n"
#else #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" " connect the host TAP network interface to VLAN 'n' and use the\n"
" network scripts 'file' (default=%s)\n" " network scripts 'file' (default=%s)\n"
" and 'dfile' (default=%s);\n" " and 'dfile' (default=%s);\n"
" use '[down]script=no' to disable script execution;\n" " use '[down]script=no' to disable script execution;\n"
" use 'fd=h' to connect to an already opened TAP interface\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 #endif
"-net socket[,vlan=n][,name=str][,fd=h][,listen=[host]:port][,connect=host:port]\n" "-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" " connect the vlan 'n' to another VLAN using a socket connection\n"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册