From 05b48408fb8bc420908d93d97231bb6727b17e9a Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Sun, 15 Nov 2009 14:27:15 -0800 Subject: [PATCH] Add mutex_enter_nested() as wrapper for mutex_lock_nested(). This symbol can be used by GPL modules which use the SPL to handle cases where a call path takes a two different locks by the same name. This is needed to avoid a false positive in the lock checker. --- include/sys/mutex.h | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/include/sys/mutex.h b/include/sys/mutex.h index 49d17659d..596c15612 100644 --- a/include/sys/mutex.h +++ b/include/sys/mutex.h @@ -52,17 +52,26 @@ mutex_owner(kmutex_t *mp) #define MUTEX_HELD(mp) mutex_owned(mp) #undef mutex_init #define mutex_init(mp, name, type, ibc) \ -({ \ +({ \ static struct lock_class_key __key; \ ASSERT(type == MUTEX_DEFAULT); \ \ __mutex_init((mp), #mp, &__key); \ }) -/* #define mutex_destroy(mp) ((void)0) */ + #define mutex_tryenter(mp) mutex_trylock(mp) #define mutex_enter(mp) mutex_lock(mp) #define mutex_exit(mp) mutex_unlock(mp) +#ifdef HAVE_GPL_ONLY_SYMBOLS +# define mutex_enter_nested(mp, sc) mutex_lock_nested(mp, sc) +#else +# define mutex_enter_nested(mp, sc) mutex_enter(mp) +# ifdef CONFIG_DEBUG_MUTEXES +# define mutex_destroy(mp) ((void)0) +# endif /* CONFIG_DEBUG_MUTEXES */ +#endif /* HAVE_GPL_ONLY_SYMBOLS */ + #else /* HAVE_MUTEX_OWNER */ typedef struct { @@ -193,6 +202,19 @@ mutex_owner(kmutex_t *mp) mutex_unlock(MUTEX(mp)); \ }) +#ifdef HAVE_GPL_ONLY_SYMBOLS +# define mutex_enter_nested(mp, sc) \ +({ \ + mutex_lock_nested(MUTEX(mp, sc)); \ + spl_mutex_set_owner(mp); \ +}) +#else +# define mutex_enter_nested(mp, sc) \ +({ \ + mutex_enter(mp); \ +}) +#endif + #endif /* HAVE_MUTEX_OWNER */ int spl_mutex_init(void);