Skip to content

Commit

Permalink
dpif: Fix cleanup of netdev_ports map
Browse files Browse the repository at this point in the history
Executing dpctl commands from userspace also calls to
dpif_open()/dpif_close() but not really creating another dpif
but using a clone.
As for netdev_ports map is global we avoid adding duplicate entries
but also need to make sure we are not removing needed entries.
With this commit we make sure only the last dpif close should clean
the netdev_ports map.

Fixes: 6595cb9 ("dpif: Clean up netdev_ports map on dpif_close().")
Signed-off-by: Roi Dayan <[email protected]>
Reviewed-by: Paul Blakey <[email protected]>
Signed-off-by: Joe Stringer <[email protected]>
  • Loading branch information
roidayan authored and joestringer committed Aug 18, 2017
1 parent 42253e5 commit 71d90be
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/dpif.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,22 +428,30 @@ dpif_create_and_open(const char *name, const char *type, struct dpif **dpifp)
return error;
}

static void
dpif_remove_netdev_ports(struct dpif *dpif) {
struct dpif_port_dump port_dump;
struct dpif_port dpif_port;

DPIF_PORT_FOR_EACH (&dpif_port, &port_dump, dpif) {
if (!dpif_is_internal_port(dpif_port.type)) {
netdev_ports_remove(dpif_port.port_no, dpif->dpif_class);
}
}
}

/* Closes and frees the connection to 'dpif'. Does not destroy the datapath
* itself; call dpif_delete() first, instead, if that is desirable. */
void
dpif_close(struct dpif *dpif)
{
if (dpif) {
struct registered_dpif_class *rc;
struct dpif_port_dump port_dump;
struct dpif_port dpif_port;

rc = shash_find_data(&dpif_classes, dpif->dpif_class->type);

DPIF_PORT_FOR_EACH (&dpif_port, &port_dump, dpif) {
if (!dpif_is_internal_port(dpif_port.type)) {
netdev_ports_remove(dpif_port.port_no, dpif->dpif_class);
}
if (rc->refcount == 1) {
dpif_remove_netdev_ports(dpif);
}
dpif_uninit(dpif, true);
dp_class_unref(rc);
Expand Down

0 comments on commit 71d90be

Please sign in to comment.