Commit b664e3673c6c2ca228ce025292e32b34f73df5f5
Committed by
Anthony Liguori
1 parent
b9adce2c
net: add tap_read_poll() helper
Add a helper to enable/disable the read polling on tapfd. We need this, because we want to start write polling on the tapfd too and enable/disable both types of polling independently. Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing
1 changed file
with
23 additions
and
7 deletions
net.c
| ... | ... | @@ -1043,10 +1043,29 @@ typedef struct TAPState { |
| 1043 | 1043 | char down_script[1024]; |
| 1044 | 1044 | char down_script_arg[128]; |
| 1045 | 1045 | uint8_t buf[4096]; |
| 1046 | + unsigned int read_poll : 1; | |
| 1046 | 1047 | } TAPState; |
| 1047 | 1048 | |
| 1048 | 1049 | static int launch_script(const char *setup_script, const char *ifname, int fd); |
| 1049 | 1050 | |
| 1051 | +static int tap_can_send(void *opaque); | |
| 1052 | +static void tap_send(void *opaque); | |
| 1053 | + | |
| 1054 | +static void tap_update_fd_handler(TAPState *s) | |
| 1055 | +{ | |
| 1056 | + qemu_set_fd_handler2(s->fd, | |
| 1057 | + s->read_poll ? tap_can_send : NULL, | |
| 1058 | + s->read_poll ? tap_send : NULL, | |
| 1059 | + NULL, | |
| 1060 | + s); | |
| 1061 | +} | |
| 1062 | + | |
| 1063 | +static void tap_read_poll(TAPState *s, int enable) | |
| 1064 | +{ | |
| 1065 | + s->read_poll = !!enable; | |
| 1066 | + tap_update_fd_handler(s); | |
| 1067 | +} | |
| 1068 | + | |
| 1050 | 1069 | static ssize_t tap_receive_iov(VLANClientState *vc, const struct iovec *iov, |
| 1051 | 1070 | int iovcnt) |
| 1052 | 1071 | { |
| ... | ... | @@ -1097,13 +1116,10 @@ static ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen) |
| 1097 | 1116 | } |
| 1098 | 1117 | #endif |
| 1099 | 1118 | |
| 1100 | -static void tap_send(void *opaque); | |
| 1101 | - | |
| 1102 | 1119 | static void tap_send_completed(VLANClientState *vc) |
| 1103 | 1120 | { |
| 1104 | 1121 | TAPState *s = vc->opaque; |
| 1105 | - | |
| 1106 | - qemu_set_fd_handler2(s->fd, tap_can_send, tap_send, NULL, s); | |
| 1122 | + tap_read_poll(s, 1); | |
| 1107 | 1123 | } |
| 1108 | 1124 | |
| 1109 | 1125 | static void tap_send(void *opaque) |
| ... | ... | @@ -1119,7 +1135,7 @@ static void tap_send(void *opaque) |
| 1119 | 1135 | |
| 1120 | 1136 | size = qemu_send_packet_async(s->vc, s->buf, size, tap_send_completed); |
| 1121 | 1137 | if (size == 0) { |
| 1122 | - qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL); | |
| 1138 | + tap_read_poll(s, 0); | |
| 1123 | 1139 | } |
| 1124 | 1140 | } while (size > 0); |
| 1125 | 1141 | } |
| ... | ... | @@ -1133,7 +1149,7 @@ static void tap_cleanup(VLANClientState *vc) |
| 1133 | 1149 | if (s->down_script[0]) |
| 1134 | 1150 | launch_script(s->down_script, s->down_script_arg, s->fd); |
| 1135 | 1151 | |
| 1136 | - qemu_set_fd_handler(s->fd, NULL, NULL, NULL); | |
| 1152 | + tap_read_poll(s, 0); | |
| 1137 | 1153 | close(s->fd); |
| 1138 | 1154 | qemu_free(s); |
| 1139 | 1155 | } |
| ... | ... | @@ -1151,7 +1167,7 @@ static TAPState *net_tap_fd_init(VLANState *vlan, |
| 1151 | 1167 | s->fd = fd; |
| 1152 | 1168 | s->vc = qemu_new_vlan_client(vlan, model, name, NULL, tap_receive, |
| 1153 | 1169 | tap_receive_iov, tap_cleanup, s); |
| 1154 | - qemu_set_fd_handler2(s->fd, tap_can_send, tap_send, NULL, s); | |
| 1170 | + tap_read_poll(s, 1); | |
| 1155 | 1171 | snprintf(s->vc->info_str, sizeof(s->vc->info_str), "fd=%d", fd); |
| 1156 | 1172 | return s; |
| 1157 | 1173 | } | ... | ... |