Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3b71535f authored by Denis V. Lunev's avatar Denis V. Lunev Committed by David S. Miller
Browse files

[NET]: Make netlink processing routines semi-synchronious (inspired by rtnl) v2



The code in netfilter/nfnetlink.c and in ./net/netlink/genetlink.c looks
like outdated copy/paste from rtnetlink.c. Push them into sync with the
original.

Changes from v1:
- deleted comment in nfnetlink_rcv_msg by request of Patrick McHardy

Signed-off-by: default avatarDenis V. Lunev <den@openvz.org>
Acked-by: default avatarPatrick McHardy <kaber@trash.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1536cc0d
Loading
Loading
Loading
Loading
+5 −20
Original line number Original line Diff line number Diff line
@@ -44,28 +44,16 @@ static struct sock *nfnl = NULL;
static const struct nfnetlink_subsystem *subsys_table[NFNL_SUBSYS_COUNT];
static const struct nfnetlink_subsystem *subsys_table[NFNL_SUBSYS_COUNT];
static DEFINE_MUTEX(nfnl_mutex);
static DEFINE_MUTEX(nfnl_mutex);


static void nfnl_lock(void)
static inline void nfnl_lock(void)
{
{
	mutex_lock(&nfnl_mutex);
	mutex_lock(&nfnl_mutex);
}
}


static int nfnl_trylock(void)
static inline void nfnl_unlock(void)
{
	return !mutex_trylock(&nfnl_mutex);
}

static void __nfnl_unlock(void)
{
{
	mutex_unlock(&nfnl_mutex);
	mutex_unlock(&nfnl_mutex);
}
}


static void nfnl_unlock(void)
{
	mutex_unlock(&nfnl_mutex);
	if (nfnl->sk_receive_queue.qlen)
		nfnl->sk_data_ready(nfnl, 0);
}

int nfnetlink_subsys_register(const struct nfnetlink_subsystem *n)
int nfnetlink_subsys_register(const struct nfnetlink_subsystem *n)
{
{
	nfnl_lock();
	nfnl_lock();
@@ -147,9 +135,7 @@ static int nfnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
	ss = nfnetlink_get_subsys(type);
	ss = nfnetlink_get_subsys(type);
	if (!ss) {
	if (!ss) {
#ifdef CONFIG_KMOD
#ifdef CONFIG_KMOD
		/* don't call nfnl_unlock, since it would reenter
		nfnl_unlock();
		 * with further packet processing */
		__nfnl_unlock();
		request_module("nfnetlink-subsys-%d", NFNL_SUBSYS_ID(type));
		request_module("nfnetlink-subsys-%d", NFNL_SUBSYS_ID(type));
		nfnl_lock();
		nfnl_lock();
		ss = nfnetlink_get_subsys(type);
		ss = nfnetlink_get_subsys(type);
@@ -188,10 +174,9 @@ static void nfnetlink_rcv(struct sock *sk, int len)
	unsigned int qlen = 0;
	unsigned int qlen = 0;


	do {
	do {
		if (nfnl_trylock())
		nfnl_lock();
			return;
		qlen = netlink_run_queue(sk, qlen, nfnetlink_rcv_msg);
		qlen = netlink_run_queue(sk, qlen, nfnetlink_rcv_msg);
		__nfnl_unlock();
		nfnl_unlock();
	} while (qlen);
	} while (qlen);
}
}


+3 −12
Original line number Original line Diff line number Diff line
@@ -22,22 +22,14 @@ struct sock *genl_sock = NULL;


static DEFINE_MUTEX(genl_mutex); /* serialization of message processing */
static DEFINE_MUTEX(genl_mutex); /* serialization of message processing */


static void genl_lock(void)
static inline void genl_lock(void)
{
{
	mutex_lock(&genl_mutex);
	mutex_lock(&genl_mutex);
}
}


static int genl_trylock(void)
static inline void genl_unlock(void)
{
	return !mutex_trylock(&genl_mutex);
}

static void genl_unlock(void)
{
{
	mutex_unlock(&genl_mutex);
	mutex_unlock(&genl_mutex);

	if (genl_sock && genl_sock->sk_receive_queue.qlen)
		genl_sock->sk_data_ready(genl_sock, 0);
}
}


#define GENL_FAM_TAB_SIZE	16
#define GENL_FAM_TAB_SIZE	16
@@ -483,8 +475,7 @@ static void genl_rcv(struct sock *sk, int len)
	unsigned int qlen = 0;
	unsigned int qlen = 0;


	do {
	do {
		if (genl_trylock())
		genl_lock();
			return;
		qlen = netlink_run_queue(sk, qlen, genl_rcv_msg);
		qlen = netlink_run_queue(sk, qlen, genl_rcv_msg);
		genl_unlock();
		genl_unlock();
	} while (qlen && genl_sock && genl_sock->sk_receive_queue.qlen);
	} while (qlen && genl_sock && genl_sock->sk_receive_queue.qlen);