Commit 9b73534d authored by Patrick McHardy's avatar Patrick McHardy Committed by David S. Miller

[NETFILTER]: nf_log: switch logger registration/unregistration to mutex

The spinlock is only used in process context (register/unregister),
switch to a mutex.
Signed-off-by: default avatarPatrick McHardy <kaber@trash.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 9dc6aa5f
...@@ -15,27 +15,31 @@ ...@@ -15,27 +15,31 @@
#define NF_LOG_PREFIXLEN 128 #define NF_LOG_PREFIXLEN 128
static struct nf_logger *nf_logging[NPROTO]; /* = NULL */ static struct nf_logger *nf_logging[NPROTO]; /* = NULL */
static DEFINE_SPINLOCK(nf_log_lock); static DEFINE_MUTEX(nf_log_mutex);
/* return EBUSY if somebody else is registered, EEXIST if the same logger /* return EBUSY if somebody else is registered, EEXIST if the same logger
* is registred, 0 on success. */ * is registred, 0 on success. */
int nf_log_register(int pf, struct nf_logger *logger) int nf_log_register(int pf, struct nf_logger *logger)
{ {
int ret = -EBUSY; int ret;
if (pf >= NPROTO) if (pf >= NPROTO)
return -EINVAL; return -EINVAL;
/* Any setup of logging members must be done before /* Any setup of logging members must be done before
* substituting pointer. */ * substituting pointer. */
spin_lock(&nf_log_lock); ret = mutex_lock_interruptible(&nf_log_mutex);
if (!nf_logging[pf]) { if (ret < 0)
return ret;
if (!nf_logging[pf])
rcu_assign_pointer(nf_logging[pf], logger); rcu_assign_pointer(nf_logging[pf], logger);
ret = 0; else if (nf_logging[pf] == logger)
} else if (nf_logging[pf] == logger)
ret = -EEXIST; ret = -EEXIST;
else
ret = -EBUSY;
spin_unlock(&nf_log_lock); mutex_unlock(&nf_log_mutex);
return ret; return ret;
} }
EXPORT_SYMBOL(nf_log_register); EXPORT_SYMBOL(nf_log_register);
...@@ -44,9 +48,9 @@ void nf_log_unregister_pf(int pf) ...@@ -44,9 +48,9 @@ void nf_log_unregister_pf(int pf)
{ {
if (pf >= NPROTO) if (pf >= NPROTO)
return; return;
spin_lock(&nf_log_lock); mutex_lock(&nf_log_mutex);
rcu_assign_pointer(nf_logging[pf], NULL); rcu_assign_pointer(nf_logging[pf], NULL);
spin_unlock(&nf_log_lock); mutex_unlock(&nf_log_mutex);
/* Give time to concurrent readers. */ /* Give time to concurrent readers. */
synchronize_rcu(); synchronize_rcu();
...@@ -57,12 +61,12 @@ void nf_log_unregister_logger(struct nf_logger *logger) ...@@ -57,12 +61,12 @@ void nf_log_unregister_logger(struct nf_logger *logger)
{ {
int i; int i;
spin_lock(&nf_log_lock); mutex_lock(&nf_log_mutex);
for (i = 0; i < NPROTO; i++) { for (i = 0; i < NPROTO; i++) {
if (nf_logging[i] == logger) if (nf_logging[i] == logger)
rcu_assign_pointer(nf_logging[i], NULL); rcu_assign_pointer(nf_logging[i], NULL);
} }
spin_unlock(&nf_log_lock); mutex_unlock(&nf_log_mutex);
synchronize_rcu(); synchronize_rcu();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment