[NET]: Convert RTNL to mutex.
authorStephen Hemminger <shemminger@osdl.org>
Tue, 21 Mar 2006 06:23:58 +0000 (22:23 -0800)
committerDavid S. Miller <davem@davemloft.net>
Tue, 21 Mar 2006 06:23:58 +0000 (22:23 -0800)
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>
drivers/net/8139too.c
include/linux/rtnetlink.h
net/core/dev.c
net/core/link_watch.c
net/core/netpoll.c
net/core/rtnetlink.c
net/ipv4/igmp.c
net/ipv4/ipconfig.c

index e58d4c50c2e1dde2712e0d3b160bbb5bd1dc12b3..f5ee064ab6b27c0b1fa4fcbe9c69d6a7530b0b6a 100644 (file)
@@ -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 {
index edccefb451882a628214c8b6e6e700504368b4a1..d263853a8f1c7e987678d4cc922d9ada22c37c85 100644 (file)
@@ -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)
@@ -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(); \
index 8763c99fcb84738a6035163db103f308fa969d20..be1d896cc5b94b96bbd10cd464564f12fcdc790e 100644 (file)
@@ -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)
@@ -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,
@@ -2894,7 +2894,7 @@ static void netdev_wait_allrefs(struct net_device *dev)
                                linkwatch_run_queue();
                        }
 
-                       rtnl_shunlock();
+                       __rtnl_unlock();
 
                        rebroadcast_time = jiffies;
                }
index e82a451d330b88d59cc8c0eeff3d0edde77dcef8..341de44c7ed1e884f1d036ff74c94d884f6714ea 100644 (file)
@@ -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();
 }
 
 
index ea51f8d02eb8654d0533afd7bc5eb38a0e08c7fd..e8e05cebd95adaeee351c84144d6c51250b503e9 100644 (file)
@@ -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;
index 1c15a907066ff26f1e960771d39d70ea6ab7c6c8..ae10d3740faa79fa1b4e72ddd56c38d814379d83 100644 (file)
@@ -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>
 #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);
@@ -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);
@@ -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);
index 64ce52bf0485a368f016e1de23103e19db004d64..3ec502f19da0e347a621b0ad848e33c20a419901 100644 (file)
@@ -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);
 
@@ -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;
 }
 
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
 }
 
@@ -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;
 
@@ -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;
@@ -2146,7 +2146,7 @@ int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf,
        }
        return 0;
 done:
-       rtnl_shunlock();
+       rtnl_unlock();
        return err;
 }
 
index bb3613ec448c59438158fbf72c95116810fbd659..cb8a92f18ef6e4be2ec561f1a91af9ddcf0b5281 100644 (file)
@@ -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)
@@ -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;
@@ -232,7 +232,7 @@ static int __init ic_open_devs(void)
                                dev->name, able, d->xid));
                }
        }
-       rtnl_shunlock();
+       rtnl_unlock();
 
        *last = NULL;
 
@@ -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;
@@ -262,7 +262,7 @@ static void __init ic_close_devs(void)
                }
                kfree(d);
        }
-       rtnl_shunlock();
+       rtnl_unlock();
 }
 
 /*