Skip to content

Commit

Permalink
[NET]: Convert RTNL to mutex.
Browse files Browse the repository at this point in the history
This patch turns the RTNL from a semaphore to a new 2.6.16 mutex and
gets rid of some of the leftover legacy.

Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Stephen Hemminger authored and David S. Miller committed Mar 21, 2006
1 parent 253aa11 commit 6756ae4
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion drivers/net/8139too.c
Original file line number Diff line number Diff line change
Expand Up @@ -1605,7 +1605,7 @@ static void rtl8139_thread (void *_data)
if (tp->watchdog_fired) {
tp->watchdog_fired = 0;
rtl8139_tx_timeout_task(_data);
} else if (rtnl_shlock_nowait() == 0) {
} else if (rtnl_trylock()) {
rtl8139_thread_iter (dev, tp, tp->mmio_addr);
rtnl_unlock ();
} else {
Expand Down
20 changes: 7 additions & 13 deletions include/linux/rtnetlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ struct tcamsg
#ifdef __KERNEL__

#include <linux/config.h>
#include <linux/mutex.h>

extern size_t rtattr_strlcpy(char *dest, const struct rtattr *rta, size_t size);
static __inline__ int rtattr_strcmp(const struct rtattr *rta, const char *str)
Expand Down Expand Up @@ -1038,24 +1039,17 @@ __rta_reserve(struct sk_buff *skb, int attrtype, int attrlen)

extern void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change);

extern struct semaphore rtnl_sem;

#define rtnl_shlock() down(&rtnl_sem)
#define rtnl_shlock_nowait() down_trylock(&rtnl_sem)

#define rtnl_shunlock() do { up(&rtnl_sem); \
if (rtnl && rtnl->sk_receive_queue.qlen) \
rtnl->sk_data_ready(rtnl, 0); \
} while(0)

/* RTNL is used as a global lock for all changes to network configuration */
extern void rtnl_lock(void);
extern int rtnl_lock_interruptible(void);
extern void rtnl_unlock(void);
extern int rtnl_trylock(void);

extern void rtnetlink_init(void);
extern void __rtnl_unlock(void);

#define ASSERT_RTNL() do { \
if (unlikely(down_trylock(&rtnl_sem) == 0)) { \
up(&rtnl_sem); \
if (unlikely(rtnl_trylock())) { \
rtnl_unlock(); \
printk(KERN_ERR "RTNL: assertion failed at %s (%d)\n", \
__FILE__, __LINE__); \
dump_stack(); \
Expand Down
8 changes: 4 additions & 4 deletions net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -2466,9 +2466,9 @@ int dev_ioctl(unsigned int cmd, void __user *arg)
*/

if (cmd == SIOCGIFCONF) {
rtnl_shlock();
rtnl_lock();
ret = dev_ifconf((char __user *) arg);
rtnl_shunlock();
rtnl_unlock();
return ret;
}
if (cmd == SIOCGIFNAME)
Expand Down Expand Up @@ -2877,7 +2877,7 @@ static void netdev_wait_allrefs(struct net_device *dev)
rebroadcast_time = warning_time = jiffies;
while (atomic_read(&dev->refcnt) != 0) {
if (time_after(jiffies, rebroadcast_time + 1 * HZ)) {
rtnl_shlock();
rtnl_lock();

/* Rebroadcast unregister notification */
notifier_call_chain(&netdev_chain,
Expand All @@ -2894,7 +2894,7 @@ static void netdev_wait_allrefs(struct net_device *dev)
linkwatch_run_queue();
}

rtnl_shunlock();
__rtnl_unlock();

rebroadcast_time = jiffies;
}
Expand Down
4 changes: 2 additions & 2 deletions net/core/link_watch.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ static void linkwatch_event(void *dummy)
linkwatch_nextevent = jiffies + HZ;
clear_bit(LW_RUNNING, &linkwatch_flags);

rtnl_shlock();
rtnl_lock();
linkwatch_run_queue();
rtnl_shunlock();
rtnl_unlock();
}


Expand Down
6 changes: 3 additions & 3 deletions net/core/netpoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -669,14 +669,14 @@ int netpoll_setup(struct netpoll *np)
printk(KERN_INFO "%s: device %s not up yet, forcing it\n",
np->name, np->dev_name);

rtnl_shlock();
rtnl_lock();
if (dev_change_flags(ndev, ndev->flags | IFF_UP) < 0) {
printk(KERN_ERR "%s: failed to open %s\n",
np->name, np->dev_name);
rtnl_shunlock();
rtnl_unlock();
goto release;
}
rtnl_shunlock();
rtnl_unlock();

atleast = jiffies + HZ/10;
atmost = jiffies + 4*HZ;
Expand Down
28 changes: 17 additions & 11 deletions net/core/rtnetlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <linux/skbuff.h>
#include <linux/init.h>
#include <linux/security.h>
#include <linux/mutex.h>

#include <asm/uaccess.h>
#include <asm/system.h>
Expand All @@ -51,25 +52,31 @@
#include <net/pkt_sched.h>
#include <net/netlink.h>

DECLARE_MUTEX(rtnl_sem);
static DEFINE_MUTEX(rtnl_mutex);

void rtnl_lock(void)
{
rtnl_shlock();
mutex_lock(&rtnl_mutex);
}

int rtnl_lock_interruptible(void)
void __rtnl_unlock(void)
{
return down_interruptible(&rtnl_sem);
mutex_unlock(&rtnl_mutex);
}

void rtnl_unlock(void)
{
rtnl_shunlock();

mutex_unlock(&rtnl_mutex);
if (rtnl && rtnl->sk_receive_queue.qlen)
rtnl->sk_data_ready(rtnl, 0);
netdev_run_todo();
}

int rtnl_trylock(void)
{
return mutex_trylock(&rtnl_mutex);
}

int rtattr_parse(struct rtattr *tb[], int maxattr, struct rtattr *rta, int len)
{
memset(tb, 0, sizeof(struct rtattr*)*maxattr);
Expand Down Expand Up @@ -625,9 +632,9 @@ static void rtnetlink_rcv(struct sock *sk, int len)
unsigned int qlen = 0;

do {
rtnl_lock();
mutex_lock(&rtnl_mutex);
netlink_run_queue(sk, &qlen, &rtnetlink_rcv_msg);
up(&rtnl_sem);
mutex_unlock(&rtnl_mutex);

netdev_run_todo();
} while (qlen);
Expand Down Expand Up @@ -704,6 +711,5 @@ EXPORT_SYMBOL(rtnetlink_links);
EXPORT_SYMBOL(rtnetlink_put_metrics);
EXPORT_SYMBOL(rtnl);
EXPORT_SYMBOL(rtnl_lock);
EXPORT_SYMBOL(rtnl_lock_interruptible);
EXPORT_SYMBOL(rtnl_sem);
EXPORT_SYMBOL(rtnl_trylock);
EXPORT_SYMBOL(rtnl_unlock);
24 changes: 12 additions & 12 deletions net/ipv4/igmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1730,7 +1730,7 @@ int ip_mc_join_group(struct sock *sk , struct ip_mreqn *imr)
if (!MULTICAST(addr))
return -EINVAL;

rtnl_shlock();
rtnl_lock();

in_dev = ip_mc_find_dev(imr);

Expand Down Expand Up @@ -1763,7 +1763,7 @@ int ip_mc_join_group(struct sock *sk , struct ip_mreqn *imr)
ip_mc_inc_group(in_dev, addr);
err = 0;
done:
rtnl_shunlock();
rtnl_unlock();
return err;
}

Expand Down Expand Up @@ -1837,7 +1837,7 @@ int ip_mc_source(int add, int omode, struct sock *sk, struct
if (!MULTICAST(addr))
return -EINVAL;

rtnl_shlock();
rtnl_lock();

imr.imr_multiaddr.s_addr = mreqs->imr_multiaddr;
imr.imr_address.s_addr = mreqs->imr_interface;
Expand Down Expand Up @@ -1947,7 +1947,7 @@ int ip_mc_source(int add, int omode, struct sock *sk, struct
ip_mc_add_src(in_dev, &mreqs->imr_multiaddr, omode, 1,
&mreqs->imr_sourceaddr, 1);
done:
rtnl_shunlock();
rtnl_unlock();
if (leavegroup)
return ip_mc_leave_group(sk, &imr);
return err;
Expand All @@ -1970,7 +1970,7 @@ int ip_mc_msfilter(struct sock *sk, struct ip_msfilter *msf, int ifindex)
msf->imsf_fmode != MCAST_EXCLUDE)
return -EINVAL;

rtnl_shlock();
rtnl_lock();

imr.imr_multiaddr.s_addr = msf->imsf_multiaddr;
imr.imr_address.s_addr = msf->imsf_interface;
Expand Down Expand Up @@ -2030,7 +2030,7 @@ int ip_mc_msfilter(struct sock *sk, struct ip_msfilter *msf, int ifindex)
pmc->sfmode = msf->imsf_fmode;
err = 0;
done:
rtnl_shunlock();
rtnl_unlock();
if (leavegroup)
err = ip_mc_leave_group(sk, &imr);
return err;
Expand All @@ -2050,7 +2050,7 @@ int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf,
if (!MULTICAST(addr))
return -EINVAL;

rtnl_shlock();
rtnl_lock();

imr.imr_multiaddr.s_addr = msf->imsf_multiaddr;
imr.imr_address.s_addr = msf->imsf_interface;
Expand All @@ -2072,7 +2072,7 @@ int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf,
goto done;
msf->imsf_fmode = pmc->sfmode;
psl = pmc->sflist;
rtnl_shunlock();
rtnl_unlock();
if (!psl) {
len = 0;
count = 0;
Expand All @@ -2091,7 +2091,7 @@ int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf,
return -EFAULT;
return 0;
done:
rtnl_shunlock();
rtnl_unlock();
return err;
}

Expand All @@ -2112,7 +2112,7 @@ int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf,
if (!MULTICAST(addr))
return -EINVAL;

rtnl_shlock();
rtnl_lock();

err = -EADDRNOTAVAIL;

Expand All @@ -2125,7 +2125,7 @@ int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf,
goto done;
gsf->gf_fmode = pmc->sfmode;
psl = pmc->sflist;
rtnl_shunlock();
rtnl_unlock();
count = psl ? psl->sl_count : 0;
copycount = count < gsf->gf_numsrc ? count : gsf->gf_numsrc;
gsf->gf_numsrc = count;
Expand All @@ -2146,7 +2146,7 @@ int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf,
}
return 0;
done:
rtnl_shunlock();
rtnl_unlock();
return err;
}

Expand Down
10 changes: 5 additions & 5 deletions net/ipv4/ipconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ static int __init ic_open_devs(void)
unsigned short oflags;

last = &ic_first_dev;
rtnl_shlock();
rtnl_lock();

/* bring loopback device up first */
if (dev_change_flags(&loopback_dev, loopback_dev.flags | IFF_UP) < 0)
Expand Down Expand Up @@ -215,7 +215,7 @@ static int __init ic_open_devs(void)
continue;
}
if (!(d = kmalloc(sizeof(struct ic_device), GFP_KERNEL))) {
rtnl_shunlock();
rtnl_unlock();
return -1;
}
d->dev = dev;
Expand All @@ -232,7 +232,7 @@ static int __init ic_open_devs(void)
dev->name, able, d->xid));
}
}
rtnl_shunlock();
rtnl_unlock();

*last = NULL;

Expand All @@ -251,7 +251,7 @@ static void __init ic_close_devs(void)
struct ic_device *d, *next;
struct net_device *dev;

rtnl_shlock();
rtnl_lock();
next = ic_first_dev;
while ((d = next)) {
next = d->next;
Expand All @@ -262,7 +262,7 @@ static void __init ic_close_devs(void)
}
kfree(d);
}
rtnl_shunlock();
rtnl_unlock();
}

/*
Expand Down

0 comments on commit 6756ae4

Please sign in to comment.