]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - net/core/sock.c
sched: speed up and simplify vslice calculations
[linux-2.6-omap-h63xx.git] / net / core / sock.c
index 190de61cd648db8400ec852e40a652a6897a9e7d..d45ecdccc6a153ec1ffccb1430e6085a3dd42f7d 100644 (file)
 #include <linux/netdevice.h>
 #include <net/protocol.h>
 #include <linux/skbuff.h>
+#include <net/net_namespace.h>
 #include <net/request_sock.h>
 #include <net/sock.h>
 #include <net/xfrm.h>
@@ -366,6 +367,7 @@ static int sock_bindtodevice(struct sock *sk, char __user *optval, int optlen)
 {
        int ret = -ENOPROTOOPT;
 #ifdef CONFIG_NETDEVICES
+       struct net *net = sk->sk_net;
        char devname[IFNAMSIZ];
        int index;
 
@@ -394,7 +396,7 @@ static int sock_bindtodevice(struct sock *sk, char __user *optval, int optlen)
        if (devname[0] == '\0') {
                index = 0;
        } else {
-               struct net_device *dev = dev_get_by_name(devname);
+               struct net_device *dev = dev_get_by_name(net, devname);
 
                ret = -ENODEV;
                if (!dev)
@@ -867,12 +869,13 @@ static inline void sock_lock_init(struct sock *sk)
 
 /**
  *     sk_alloc - All socket objects are allocated here
+ *     @net: the applicable net namespace
  *     @family: protocol family
  *     @priority: for allocation (%GFP_KERNEL, %GFP_ATOMIC, etc)
  *     @prot: struct proto associated with this new sock instance
  *     @zero_it: if we should zero the newly allocated sock
  */
-struct sock *sk_alloc(int family, gfp_t priority,
+struct sock *sk_alloc(struct net *net, int family, gfp_t priority,
                      struct proto *prot, int zero_it)
 {
        struct sock *sk = NULL;
@@ -893,6 +896,7 @@ struct sock *sk_alloc(int family, gfp_t priority,
                         */
                        sk->sk_prot = sk->sk_prot_creator = prot;
                        sock_lock_init(sk);
+                       sk->sk_net = get_net(net);
                }
 
                if (security_sk_alloc(sk, family, priority))
@@ -932,6 +936,7 @@ void sk_free(struct sock *sk)
                       __FUNCTION__, atomic_read(&sk->sk_omem_alloc));
 
        security_sk_free(sk);
+       put_net(sk->sk_net);
        if (sk->sk_prot_creator->slab != NULL)
                kmem_cache_free(sk->sk_prot_creator->slab, sk);
        else
@@ -941,7 +946,7 @@ void sk_free(struct sock *sk)
 
 struct sock *sk_clone(const struct sock *sk, const gfp_t priority)
 {
-       struct sock *newsk = sk_alloc(sk->sk_family, priority, sk->sk_prot, 0);
+       struct sock *newsk = sk_alloc(sk->sk_net, sk->sk_family, priority, sk->sk_prot, 0);
 
        if (newsk != NULL) {
                struct sk_filter *filter;
@@ -1585,9 +1590,9 @@ void fastcall lock_sock_nested(struct sock *sk, int subclass)
 {
        might_sleep();
        spin_lock_bh(&sk->sk_lock.slock);
-       if (sk->sk_lock.owner)
+       if (sk->sk_lock.owned)
                __lock_sock(sk);
-       sk->sk_lock.owner = (void *)1;
+       sk->sk_lock.owned = 1;
        spin_unlock(&sk->sk_lock.slock);
        /*
         * The sk_lock has mutex_lock() semantics here:
@@ -1608,7 +1613,7 @@ void fastcall release_sock(struct sock *sk)
        spin_lock_bh(&sk->sk_lock.slock);
        if (sk->sk_backlog.tail)
                __release_sock(sk);
-       sk->sk_lock.owner = NULL;
+       sk->sk_lock.owned = 0;
        if (waitqueue_active(&sk->sk_lock.wq))
                wake_up(&sk->sk_lock.wq);
        spin_unlock_bh(&sk->sk_lock.slock);
@@ -1973,7 +1978,7 @@ static const struct file_operations proto_seq_fops = {
 static int __init proto_init(void)
 {
        /* register /proc/net/protocols */
-       return proc_net_fops_create("protocols", S_IRUGO, &proto_seq_fops) == NULL ? -ENOBUFS : 0;
+       return proc_net_fops_create(&init_net, "protocols", S_IRUGO, &proto_seq_fops) == NULL ? -ENOBUFS : 0;
 }
 
 subsys_initcall(proto_init);