net: Kill hold_net release_net
authorEric W. Biederman <ebiederm@xmission.com>
Thu, 12 Mar 2015 04:04:08 +0000 (23:04 -0500)
committerDavid S. Miller <davem@davemloft.net>
Thu, 12 Mar 2015 18:39:40 +0000 (14:39 -0400)
hold_net and release_net were an idea that turned out to be useless.
The code has been disabled since 2008.  Kill the code it is long past due.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Acked-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
15 files changed:
include/linux/netdevice.h
include/net/fib_rules.h
include/net/net_namespace.h
include/net/sock.h
net/core/dev.c
net/core/fib_rules.c
net/core/neighbour.c
net/core/net_namespace.c
net/core/sock.c
net/ipv4/fib_semantics.c
net/ipv4/inet_hashtables.c
net/ipv4/inet_timewait_sock.c
net/ipv6/addrlabel.c
net/ipv6/ip6_flowlabel.c
net/openvswitch/datapath.c

index 1354ae83efc83e8e6a1805edc639f7dcd84000c4..cede40d9cac97c295bbf2198f36b20499421cc2b 100644 (file)
@@ -1864,8 +1864,7 @@ static inline
 void dev_net_set(struct net_device *dev, struct net *net)
 {
 #ifdef CONFIG_NET_NS
-       release_net(dev->nd_net);
-       dev->nd_net = hold_net(net);
+       dev->nd_net = net;
 #endif
 }
 
index 88d2ae526961dd6cf7064deb3ef0476a67f8b139..6d67383a5114bd1010908bc7c8328a41d52e0a3b 100644 (file)
@@ -95,17 +95,10 @@ static inline void fib_rule_get(struct fib_rule *rule)
        atomic_inc(&rule->refcnt);
 }
 
-static inline void fib_rule_put_rcu(struct rcu_head *head)
-{
-       struct fib_rule *rule = container_of(head, struct fib_rule, rcu);
-       release_net(rule->fr_net);
-       kfree(rule);
-}
-
 static inline void fib_rule_put(struct fib_rule *rule)
 {
        if (atomic_dec_and_test(&rule->refcnt))
-               call_rcu(&rule->rcu, fib_rule_put_rcu);
+               kfree_rcu(rule, rcu);
 }
 
 static inline u32 frh_get_table(struct fib_rule_hdr *frh, struct nlattr **nla)
index e086f4030dd20e416ad4ece3e639abf247b3d1a6..fab51ceeabf3c3132ce7808a8a845585a2d9515f 100644 (file)
@@ -49,11 +49,6 @@ struct net {
        atomic_t                count;          /* To decided when the network
                                                 *  namespace should be shut down.
                                                 */
-#ifdef NETNS_REFCNT_DEBUG
-       atomic_t                use_count;      /* To track references we
-                                                * destroy on demand
-                                                */
-#endif
        spinlock_t              rules_mod_lock;
 
        atomic64_t              cookie_gen;
@@ -236,30 +231,6 @@ int net_eq(const struct net *net1, const struct net *net2)
 #endif
 
 
-#ifdef NETNS_REFCNT_DEBUG
-static inline struct net *hold_net(struct net *net)
-{
-       if (net)
-               atomic_inc(&net->use_count);
-       return net;
-}
-
-static inline void release_net(struct net *net)
-{
-       if (net)
-               atomic_dec(&net->use_count);
-}
-#else
-static inline struct net *hold_net(struct net *net)
-{
-       return net;
-}
-
-static inline void release_net(struct net *net)
-{
-}
-#endif
-
 #ifdef CONFIG_NET_NS
 
 static inline void write_pnet(struct net **pnet, struct net *net)
index d996c633bec2e9d5eba4ebebced513211c29672b..95b2c1c220f990b6ee116feb40a585344788a418 100644 (file)
@@ -2204,7 +2204,7 @@ static inline void sk_change_net(struct sock *sk, struct net *net)
 
        if (!net_eq(current_net, net)) {
                put_net(current_net);
-               sock_net_set(sk, hold_net(net));
+               sock_net_set(sk, net);
        }
 }
 
index 962ee9d719641291853715f366717bf1626e115c..39fe369b46ad5b86e6f949e0d110eb060f7eb074 100644 (file)
@@ -6841,8 +6841,6 @@ void free_netdev(struct net_device *dev)
 {
        struct napi_struct *p, *n;
 
-       release_net(dev_net(dev));
-
        netif_free_tx_queues(dev);
 #ifdef CONFIG_SYSFS
        kvfree(dev->_rx);
index b55677fed1c851fc628b3b70076d221022b93806..68ea6950cad1f646906cf45ba78819447a8618eb 100644 (file)
@@ -31,7 +31,7 @@ int fib_default_rule_add(struct fib_rules_ops *ops,
        r->pref = pref;
        r->table = table;
        r->flags = flags;
-       r->fr_net = hold_net(ops->fro_net);
+       r->fr_net = ops->fro_net;
 
        r->suppress_prefixlen = -1;
        r->suppress_ifgroup = -1;
@@ -116,7 +116,6 @@ static int __fib_rules_register(struct fib_rules_ops *ops)
                if (ops->family == o->family)
                        goto errout;
 
-       hold_net(net);
        list_add_tail_rcu(&ops->list, &net->rules_ops);
        err = 0;
 errout:
@@ -160,15 +159,6 @@ static void fib_rules_cleanup_ops(struct fib_rules_ops *ops)
        }
 }
 
-static void fib_rules_put_rcu(struct rcu_head *head)
-{
-       struct fib_rules_ops *ops = container_of(head, struct fib_rules_ops, rcu);
-       struct net *net = ops->fro_net;
-
-       release_net(net);
-       kfree(ops);
-}
-
 void fib_rules_unregister(struct fib_rules_ops *ops)
 {
        struct net *net = ops->fro_net;
@@ -178,7 +168,7 @@ void fib_rules_unregister(struct fib_rules_ops *ops)
        fib_rules_cleanup_ops(ops);
        spin_unlock(&net->rules_mod_lock);
 
-       call_rcu(&ops->rcu, fib_rules_put_rcu);
+       kfree_rcu(ops, rcu);
 }
 EXPORT_SYMBOL_GPL(fib_rules_unregister);
 
@@ -303,7 +293,7 @@ static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh)
                err = -ENOMEM;
                goto errout;
        }
-       rule->fr_net = hold_net(net);
+       rule->fr_net = net;
 
        if (tb[FRA_PRIORITY])
                rule->pref = nla_get_u32(tb[FRA_PRIORITY]);
@@ -423,7 +413,6 @@ static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh)
        return 0;
 
 errout_free:
-       release_net(rule->fr_net);
        kfree(rule);
 errout:
        rules_ops_put(ops);
index ad07990e943da544dd292e29bf132adb6f2cc0c8..0e8b32efc0316c85e56c4b7a95c4c903fde63ecf 100644 (file)
@@ -591,7 +591,7 @@ struct pneigh_entry * pneigh_lookup(struct neigh_table *tbl,
        if (!n)
                goto out;
 
-       write_pnet(&n->net, hold_net(net));
+       write_pnet(&n->net, net);
        memcpy(n->key, pkey, key_len);
        n->dev = dev;
        if (dev)
@@ -600,7 +600,6 @@ struct pneigh_entry * pneigh_lookup(struct neigh_table *tbl,
        if (tbl->pconstructor && tbl->pconstructor(n)) {
                if (dev)
                        dev_put(dev);
-               release_net(net);
                kfree(n);
                n = NULL;
                goto out;
@@ -634,7 +633,6 @@ int pneigh_delete(struct neigh_table *tbl, struct net *net, const void *pkey,
                                tbl->pdestructor(n);
                        if (n->dev)
                                dev_put(n->dev);
-                       release_net(pneigh_net(n));
                        kfree(n);
                        return 0;
                }
@@ -657,7 +655,6 @@ static int pneigh_ifdown(struct neigh_table *tbl, struct net_device *dev)
                                        tbl->pdestructor(n);
                                if (n->dev)
                                        dev_put(n->dev);
-                               release_net(pneigh_net(n));
                                kfree(n);
                                continue;
                        }
@@ -1428,11 +1425,10 @@ struct neigh_parms *neigh_parms_alloc(struct net_device *dev,
                                neigh_rand_reach_time(NEIGH_VAR(p, BASE_REACHABLE_TIME));
                dev_hold(dev);
                p->dev = dev;
-               write_pnet(&p->net, hold_net(net));
+               write_pnet(&p->net, net);
                p->sysctl_table = NULL;
 
                if (ops->ndo_neigh_setup && ops->ndo_neigh_setup(dev, p)) {
-                       release_net(net);
                        dev_put(dev);
                        kfree(p);
                        return NULL;
@@ -1472,7 +1468,6 @@ EXPORT_SYMBOL(neigh_parms_release);
 
 static void neigh_parms_destroy(struct neigh_parms *parms)
 {
-       release_net(neigh_parms_net(parms));
        kfree(parms);
 }
 
index cb5290b8c428c5c348b25d842ab9cf3797b70eba..e5e96b0f6717456c7f40322d4899eba0e5d54010 100644 (file)
@@ -236,10 +236,6 @@ static __net_init int setup_net(struct net *net, struct user_namespace *user_ns)
        net->user_ns = user_ns;
        idr_init(&net->netns_ids);
 
-#ifdef NETNS_REFCNT_DEBUG
-       atomic_set(&net->use_count, 0);
-#endif
-
        list_for_each_entry(ops, &pernet_list, list) {
                error = ops_init(ops, net);
                if (error < 0)
@@ -294,13 +290,6 @@ out_free:
 
 static void net_free(struct net *net)
 {
-#ifdef NETNS_REFCNT_DEBUG
-       if (unlikely(atomic_read(&net->use_count) != 0)) {
-               pr_emerg("network namespace not free! Usage: %d\n",
-                        atomic_read(&net->use_count));
-               return;
-       }
-#endif
        kfree(rcu_access_pointer(net->gen));
        kmem_cache_free(net_cachep, net);
 }
index a9a9c2ff9260945a7beb398507db24fd7a076481..c8842f279f7a422fb1b7d979125db4b054a7e3c1 100644 (file)
@@ -1455,7 +1455,6 @@ void sk_release_kernel(struct sock *sk)
 
        sock_hold(sk);
        sock_release(sk->sk_socket);
-       release_net(sock_net(sk));
        sock_net_set(sk, get_net(&init_net));
        sock_put(sk);
 }
index c6d267442dac93cde1593adfd7dd991f115fcea9..66c1e4fbf8841b9dcbd71ce0333170430cb88f72 100644 (file)
@@ -213,7 +213,6 @@ static void free_fib_info_rcu(struct rcu_head *head)
                rt_fibinfo_free(&nexthop_nh->nh_rth_input);
        } endfor_nexthops(fi);
 
-       release_net(fi->fib_net);
        if (fi->fib_metrics != (u32 *) dst_default_metrics)
                kfree(fi->fib_metrics);
        kfree(fi);
@@ -814,7 +813,7 @@ struct fib_info *fib_create_info(struct fib_config *cfg)
        } else
                fi->fib_metrics = (u32 *) dst_default_metrics;
 
-       fi->fib_net = hold_net(net);
+       fi->fib_net = net;
        fi->fib_protocol = cfg->fc_protocol;
        fi->fib_scope = cfg->fc_scope;
        fi->fib_flags = cfg->fc_flags;
index 9111a4e221557173df0ce08e95632ee059d00b61..f6a12b97d12ba41d6b6bc933e4cb3320d27274f4 100644 (file)
@@ -61,7 +61,7 @@ struct inet_bind_bucket *inet_bind_bucket_create(struct kmem_cache *cachep,
        struct inet_bind_bucket *tb = kmem_cache_alloc(cachep, GFP_ATOMIC);
 
        if (tb != NULL) {
-               write_pnet(&tb->ib_net, hold_net(net));
+               write_pnet(&tb->ib_net, net);
                tb->port      = snum;
                tb->fastreuse = 0;
                tb->fastreuseport = 0;
@@ -79,7 +79,6 @@ void inet_bind_bucket_destroy(struct kmem_cache *cachep, struct inet_bind_bucket
 {
        if (hlist_empty(&tb->owners)) {
                __hlist_del(&tb->node);
-               release_net(ib_net(tb));
                kmem_cache_free(cachep, tb);
        }
 }
index 2bd9805266312b98db32d699b055984a17852fb9..86ebf020925bd0944e05b912f31e6d694d4c0219 100644 (file)
@@ -98,7 +98,6 @@ void inet_twsk_free(struct inet_timewait_sock *tw)
 #ifdef SOCK_REFCNT_DEBUG
        pr_debug("%s timewait_sock %p released\n", tw->tw_prot->name, tw);
 #endif
-       release_net(twsk_net(tw));
        kmem_cache_free(tw->tw_prot->twsk_prot->twsk_slab, tw);
        module_put(owner);
 }
@@ -196,7 +195,7 @@ struct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk, const int stat
                tw->tw_transparent  = inet->transparent;
                tw->tw_prot         = sk->sk_prot_creator;
                atomic64_set(&tw->tw_cookie, atomic64_read(&sk->sk_cookie));
-               twsk_net_set(tw, hold_net(sock_net(sk)));
+               twsk_net_set(tw, sock_net(sk));
                /*
                 * Because we use RCU lookups, we should not set tw_refcnt
                 * to a non null value before everything is setup for this
index e43e79d0a6124caa06cd2e2c09203ad2cd032c9e..59c793040498fd16d432e69e3fdf8d3170f290f9 100644 (file)
@@ -129,9 +129,6 @@ static const __net_initconst struct ip6addrlbl_init_table
 /* Object management */
 static inline void ip6addrlbl_free(struct ip6addrlbl_entry *p)
 {
-#ifdef CONFIG_NET_NS
-       release_net(p->lbl_net);
-#endif
        kfree(p);
 }
 
@@ -241,7 +238,7 @@ static struct ip6addrlbl_entry *ip6addrlbl_alloc(struct net *net,
        newp->label = label;
        INIT_HLIST_NODE(&newp->list);
 #ifdef CONFIG_NET_NS
-       newp->lbl_net = hold_net(net);
+       newp->lbl_net = net;
 #endif
        atomic_set(&newp->refcnt, 1);
        return newp;
index f45d6db50a454727367d2fc2450fd6f0b1dfb923..457303886fd492e3942d02b1a0567a3029fc005c 100644 (file)
@@ -100,7 +100,6 @@ static void fl_free(struct ip6_flowlabel *fl)
        if (fl) {
                if (fl->share == IPV6_FL_S_PROCESS)
                        put_pid(fl->owner.pid);
-               release_net(fl->fl_net);
                kfree(fl->opt);
                kfree_rcu(fl, rcu);
        }
@@ -403,7 +402,7 @@ fl_create(struct net *net, struct sock *sk, struct in6_flowlabel_req *freq,
                }
        }
 
-       fl->fl_net = hold_net(net);
+       fl->fl_net = net;
        fl->expires = jiffies;
        err = fl6_renew(fl, freq->flr_linger, freq->flr_expires);
        if (err)
index 5bae7243c5777e38df7be95454b8164724c769cf..096c6276e6b92680542ed1204bf396470c08caf5 100644 (file)
@@ -203,7 +203,6 @@ static void destroy_dp_rcu(struct rcu_head *rcu)
 
        ovs_flow_tbl_destroy(&dp->table);
        free_percpu(dp->stats_percpu);
-       release_net(ovs_dp_get_net(dp));
        kfree(dp->ports);
        kfree(dp);
 }
@@ -1501,7 +1500,7 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
        if (dp == NULL)
                goto err_free_reply;
 
-       ovs_dp_set_net(dp, hold_net(sock_net(skb->sk)));
+       ovs_dp_set_net(dp, sock_net(skb->sk));
 
        /* Allocate table. */
        err = ovs_flow_tbl_init(&dp->table);
@@ -1575,7 +1574,6 @@ err_destroy_percpu:
 err_destroy_table:
        ovs_flow_tbl_destroy(&dp->table);
 err_free_dp:
-       release_net(ovs_dp_get_net(dp));
        kfree(dp);
 err_free_reply:
        kfree_skb(reply);