- dpif_linux_vport_init(&vport_request);
- vport_request.cmd = OVS_VPORT_CMD_SET;
- vport_request.dp_ifindex = dpif->dp_ifindex;
- vport_request.port_no = port.port_no;
- vport_request.upcall_pid = &upcall_pid;
- error = dpif_linux_vport_transact(&vport_request, NULL, NULL);
- if (!error) {
- VLOG_DBG("%s: assigning port %"PRIu32" to netlink pid %"PRIu32,
- dpif_name(&dpif->dpif), vport_request.port_no,
- upcall_pid);
- } else {
- VLOG_WARN_RL(&error_rl, "%s: failed to set upcall pid on port: %s",
- dpif_name(&dpif->dpif), strerror(error));
+ keep_channels_nbits = dpif->uc_array_size;
+ keep_channels = bitmap_allocate(keep_channels_nbits);
+
+ dpif->n_events = dpif->event_offset = 0;
+
+ ofpbuf_use_stub(&buf, reply_stub, sizeof reply_stub);
+ dpif_linux_port_dump_start__(dpif_, &dump);
+ while (!dpif_linux_port_dump_next__(dpif_, &dump, &vport, &buf)) {
+ uint32_t port_no = odp_to_u32(vport.port_no);
+ struct nl_sock *sock = (port_no < dpif->uc_array_size
+ ? dpif->channels[port_no].sock
+ : NULL);
+ bool new_sock = !sock;
+ int error;
+
+ if (new_sock) {
+ error = nl_sock_create(NETLINK_GENERIC, &sock);
+ if (error) {
+ retval = error;
+ goto error;
+ }
+ }
+
+ /* Configure the vport to deliver misses to 'sock'. */
+ if (!vport.upcall_pid || *vport.upcall_pid != nl_sock_pid(sock)) {
+ uint32_t upcall_pid = nl_sock_pid(sock);
+ struct dpif_linux_vport vport_request;
+
+ dpif_linux_vport_init(&vport_request);
+ vport_request.cmd = OVS_VPORT_CMD_SET;
+ vport_request.dp_ifindex = dpif->dp_ifindex;
+ vport_request.port_no = vport.port_no;
+ vport_request.upcall_pid = &upcall_pid;
+ error = dpif_linux_vport_transact(&vport_request, NULL, NULL);
+ if (!error) {
+ VLOG_DBG("%s: assigning port %"PRIu32" to netlink pid %"PRIu32,
+ dpif_name(&dpif->dpif), vport_request.port_no,
+ upcall_pid);
+ } else {
+ VLOG_WARN_RL(&error_rl,
+ "%s: failed to set upcall pid on port: %s",
+ dpif_name(&dpif->dpif), ovs_strerror(error));
+
+ if (error != ENODEV && error != ENOENT) {
+ retval = error;
+ } else {
+ /* The vport isn't really there, even though the dump says
+ * it is. Probably we just hit a race after a port
+ * disappeared. */
+ }
+ goto error;
+ }
+ }
+
+ if (new_sock) {
+ error = add_channel(dpif, vport.port_no, sock);
+ if (error) {
+ VLOG_INFO("%s: could not add channel for port %s",
+ dpif_name(dpif_), vport.name);
+ retval = error;
+ goto error;
+ }
+ }
+
+ if (port_no < keep_channels_nbits) {
+ bitmap_set1(keep_channels, port_no);
+ }
+ continue;
+
+ error:
+ nl_sock_destroy(sock);
+ }
+ nl_dump_done(&dump);
+ ofpbuf_uninit(&buf);
+
+ /* Discard any saved channels that we didn't reuse. */
+ for (i = 0; i < keep_channels_nbits; i++) {
+ if (!bitmap_is_set(keep_channels, i)) {
+ nl_sock_destroy(dpif->channels[i].sock);
+ dpif->channels[i].sock = NULL;