dpif-netdev: Fix improper use of CMAP_FOR_EACH.
authorDaniele Di Proietto <diproiettod@vmware.com>
Wed, 27 Jan 2016 02:53:52 +0000 (18:53 -0800)
committerDaniele Di Proietto <diproiettod@vmware.com>
Wed, 3 Feb 2016 02:50:12 +0000 (18:50 -0800)
commitd916785ce98ccdaab4f4f0676d564852fb7c9451
treedc37a7ce773e16d6703ceed7a7a3c6d2ea82263a
parenta90ed02611446fc7fcfc6fbf237c5c2fbe06eee3
dpif-netdev: Fix improper use of CMAP_FOR_EACH.

It is ok to iterate a cmap with CMAP_FOR_EACH and remove elements with
cmap_remove(), but having quiescent states inside the loop might create
problems, since some of the postponed cleanup done inside the cmap might
be executed, freeing the memory that the iterator is using.

We had several of these errors in dpif-netdev, because when we rearrange
ports or threads we often need to wait on a condition variable (which
implies a quiescent state).

This problem caused iterations to skip elements or to list them twice,
resulting in the main thread waiting on a condition without anyone else
to signal.

Fix these cases by moving the possible quiescent states outside
CMAP_FOR_EACH loops.

Signed-off-by: Daniele Di Proietto <diproiettod@vmware.com>
Tested-by: Ilya Maximets <i.maximets@samsung.com>
Acked-by: Ilya Maximets <i.maximets@samsung.com>
Acked-by: Jarno Rajahalme <jarno@ovn.org>
lib/dpif-netdev.c