bridge: Move locking defines into if_bridge.c

The locking defines for if_bridge used to live in if_bridgevar.h, but
they're only ever used by the bridge implementation itself (in
if_bridge.c). Moving them into the .c file.

Reported by:	philip, emaste
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D23808
This commit is contained in:
Kristof Provost 2020-02-26 08:47:18 +00:00
parent 547a1e03c3
commit 33b1fe11a2
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=358325
2 changed files with 41 additions and 38 deletions

View File

@ -184,6 +184,47 @@ extern void nd6_setmtu(struct ifnet *);
*/
#define BRIDGE_IFCAPS_STRIP IFCAP_LRO
/*
* Bridge locking
*/
#define BRIDGE_LOCK_INIT(_sc) do { \
mtx_init(&(_sc)->sc_mtx, "if_bridge", NULL, MTX_DEF); \
cv_init(&(_sc)->sc_cv, "if_bridge_cv"); \
} while (0)
#define BRIDGE_LOCK_DESTROY(_sc) do { \
mtx_destroy(&(_sc)->sc_mtx); \
cv_destroy(&(_sc)->sc_cv); \
} while (0)
#define BRIDGE_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
#define BRIDGE_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx)
#define BRIDGE_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->sc_mtx, MA_OWNED)
#define BRIDGE_UNLOCK_ASSERT(_sc) mtx_assert(&(_sc)->sc_mtx, MA_NOTOWNED)
#define BRIDGE_LOCK2REF(_sc, _err) do { \
mtx_assert(&(_sc)->sc_mtx, MA_OWNED); \
if ((_sc)->sc_iflist_xcnt > 0) \
(_err) = EBUSY; \
else \
(_sc)->sc_iflist_ref++; \
mtx_unlock(&(_sc)->sc_mtx); \
} while (0)
#define BRIDGE_UNREF(_sc) do { \
mtx_lock(&(_sc)->sc_mtx); \
(_sc)->sc_iflist_ref--; \
if (((_sc)->sc_iflist_xcnt > 0) && ((_sc)->sc_iflist_ref == 0)) \
cv_broadcast(&(_sc)->sc_cv); \
mtx_unlock(&(_sc)->sc_mtx); \
} while (0)
#define BRIDGE_XLOCK(_sc) do { \
mtx_assert(&(_sc)->sc_mtx, MA_OWNED); \
(_sc)->sc_iflist_xcnt++; \
while ((_sc)->sc_iflist_ref > 0) \
cv_wait(&(_sc)->sc_cv, &(_sc)->sc_mtx); \
} while (0)
#define BRIDGE_XDROP(_sc) do { \
mtx_assert(&(_sc)->sc_mtx, MA_OWNED); \
(_sc)->sc_iflist_xcnt--; \
} while (0)
/*
* Bridge interface list entry.
*/

View File

@ -271,44 +271,6 @@ struct ifbpstpconf {
#ifdef _KERNEL
#define BRIDGE_LOCK_INIT(_sc) do { \
mtx_init(&(_sc)->sc_mtx, "if_bridge", NULL, MTX_DEF); \
cv_init(&(_sc)->sc_cv, "if_bridge_cv"); \
} while (0)
#define BRIDGE_LOCK_DESTROY(_sc) do { \
mtx_destroy(&(_sc)->sc_mtx); \
cv_destroy(&(_sc)->sc_cv); \
} while (0)
#define BRIDGE_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
#define BRIDGE_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx)
#define BRIDGE_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->sc_mtx, MA_OWNED)
#define BRIDGE_UNLOCK_ASSERT(_sc) mtx_assert(&(_sc)->sc_mtx, MA_NOTOWNED)
#define BRIDGE_LOCK2REF(_sc, _err) do { \
mtx_assert(&(_sc)->sc_mtx, MA_OWNED); \
if ((_sc)->sc_iflist_xcnt > 0) \
(_err) = EBUSY; \
else \
(_sc)->sc_iflist_ref++; \
mtx_unlock(&(_sc)->sc_mtx); \
} while (0)
#define BRIDGE_UNREF(_sc) do { \
mtx_lock(&(_sc)->sc_mtx); \
(_sc)->sc_iflist_ref--; \
if (((_sc)->sc_iflist_xcnt > 0) && ((_sc)->sc_iflist_ref == 0)) \
cv_broadcast(&(_sc)->sc_cv); \
mtx_unlock(&(_sc)->sc_mtx); \
} while (0)
#define BRIDGE_XLOCK(_sc) do { \
mtx_assert(&(_sc)->sc_mtx, MA_OWNED); \
(_sc)->sc_iflist_xcnt++; \
while ((_sc)->sc_iflist_ref > 0) \
cv_wait(&(_sc)->sc_cv, &(_sc)->sc_mtx); \
} while (0)
#define BRIDGE_XDROP(_sc) do { \
mtx_assert(&(_sc)->sc_mtx, MA_OWNED); \
(_sc)->sc_iflist_xcnt--; \
} while (0)
#define BRIDGE_INPUT(_ifp, _m) do { \
KASSERT((_ifp)->if_bridge_input != NULL, \
("%s: if_bridge not loaded!", __func__)); \