net: Rename net_sem to pernet_ops_rwsem
authorKirill Tkhai <ktkhai@virtuozzo.com>
Tue, 27 Mar 2018 15:02:23 +0000 (18:02 +0300)
committerDavid S. Miller <davem@davemloft.net>
Tue, 27 Mar 2018 17:18:09 +0000 (13:18 -0400)
net_sem is some undefined area name, so it will be better
to make the area more defined.

Rename it to pernet_ops_rwsem for better readability and
better intelligibility.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/rtnetlink.h
include/net/net_namespace.h
net/core/net_namespace.c
net/core/rtnetlink.c

index 562a175..c7d1e46 100644 (file)
@@ -36,7 +36,7 @@ extern int rtnl_is_locked(void);
 extern int rtnl_lock_killable(void);
 
 extern wait_queue_head_t netdev_unregistering_wq;
-extern struct rw_semaphore net_sem;
+extern struct rw_semaphore pernet_ops_rwsem;
 
 #ifdef CONFIG_PROVE_LOCKING
 extern bool lockdep_rtnl_is_held(void);
index 37bcf83..922e8b6 100644 (file)
@@ -60,9 +60,10 @@ struct net {
 
        struct list_head        list;           /* list of network namespaces */
        struct list_head        exit_list;      /* To linked to call pernet exit
-                                                * methods on dead net (net_sem
-                                                * read locked), or to unregister
-                                                * pernet ops (net_sem wr locked).
+                                                * methods on dead net (
+                                                * pernet_ops_rwsem read locked),
+                                                * or to unregister pernet ops
+                                                * (pernet_ops_rwsem write locked).
                                                 */
        struct llist_node       cleanup_list;   /* namespaces on death row */
 
@@ -95,8 +96,9 @@ struct net {
        /* core fib_rules */
        struct list_head        rules_ops;
 
-       struct list_head        fib_notifier_ops;  /* protected by net_sem */
-
+       struct list_head        fib_notifier_ops;  /* Populated by
+                                                   * register_pernet_subsys()
+                                                   */
        struct net_device       *loopback_dev;          /* The loopback */
        struct netns_core       core;
        struct netns_mib        mib;
index eef17ad..9e8ee46 100644 (file)
@@ -41,10 +41,10 @@ EXPORT_SYMBOL(init_net);
 
 static bool init_net_initialized;
 /*
- * net_sem: protects: pernet_list, net_generic_ids,
+ * pernet_ops_rwsem: protects: pernet_list, net_generic_ids,
  * init_net_initialized and first_device pointer.
  */
-DECLARE_RWSEM(net_sem);
+DECLARE_RWSEM(pernet_ops_rwsem);
 
 #define MIN_PERNET_OPS_ID      \
        ((sizeof(struct net_generic) + sizeof(void *) - 1) / sizeof(void *))
@@ -72,7 +72,7 @@ static int net_assign_generic(struct net *net, unsigned int id, void *data)
        BUG_ON(id < MIN_PERNET_OPS_ID);
 
        old_ng = rcu_dereference_protected(net->gen,
-                                          lockdep_is_held(&net_sem));
+                                          lockdep_is_held(&pernet_ops_rwsem));
        if (old_ng->s.len > id) {
                old_ng->ptr[id] = data;
                return 0;
@@ -289,7 +289,7 @@ struct net *get_net_ns_by_id(struct net *net, int id)
  */
 static __net_init int setup_net(struct net *net, struct user_namespace *user_ns)
 {
-       /* Must be called with net_sem held */
+       /* Must be called with pernet_ops_rwsem held */
        const struct pernet_operations *ops, *saved_ops;
        int error = 0;
        LIST_HEAD(net_exit_list);
@@ -422,13 +422,13 @@ struct net *copy_net_ns(unsigned long flags,
        net->ucounts = ucounts;
        get_user_ns(user_ns);
 
-       rv = down_read_killable(&net_sem);
+       rv = down_read_killable(&pernet_ops_rwsem);
        if (rv < 0)
                goto put_userns;
 
        rv = setup_net(net, user_ns);
 
-       up_read(&net_sem);
+       up_read(&pernet_ops_rwsem);
 
        if (rv < 0) {
 put_userns:
@@ -480,7 +480,7 @@ static void cleanup_net(struct work_struct *work)
        /* Atomically snapshot the list of namespaces to cleanup */
        net_kill_list = llist_del_all(&cleanup_list);
 
-       down_read(&net_sem);
+       down_read(&pernet_ops_rwsem);
 
        /* Don't let anyone else find us. */
        rtnl_lock();
@@ -519,7 +519,7 @@ static void cleanup_net(struct work_struct *work)
        list_for_each_entry_reverse(ops, &pernet_list, list)
                ops_free_list(ops, &net_exit_list);
 
-       up_read(&net_sem);
+       up_read(&pernet_ops_rwsem);
 
        /* Ensure there are no outstanding rcu callbacks using this
         * network namespace.
@@ -546,8 +546,8 @@ static void cleanup_net(struct work_struct *work)
  */
 void net_ns_barrier(void)
 {
-       down_write(&net_sem);
-       up_write(&net_sem);
+       down_write(&pernet_ops_rwsem);
+       up_write(&pernet_ops_rwsem);
 }
 EXPORT_SYMBOL(net_ns_barrier);
 
@@ -869,12 +869,12 @@ static int __init net_ns_init(void)
 
        rcu_assign_pointer(init_net.gen, ng);
 
-       down_write(&net_sem);
+       down_write(&pernet_ops_rwsem);
        if (setup_net(&init_net, &init_user_ns))
                panic("Could not setup the initial network namespace");
 
        init_net_initialized = true;
-       up_write(&net_sem);
+       up_write(&pernet_ops_rwsem);
 
        register_pernet_subsys(&net_ns_ops);
 
@@ -1013,9 +1013,9 @@ static void unregister_pernet_operations(struct pernet_operations *ops)
 int register_pernet_subsys(struct pernet_operations *ops)
 {
        int error;
-       down_write(&net_sem);
+       down_write(&pernet_ops_rwsem);
        error =  register_pernet_operations(first_device, ops);
-       up_write(&net_sem);
+       up_write(&pernet_ops_rwsem);
        return error;
 }
 EXPORT_SYMBOL_GPL(register_pernet_subsys);
@@ -1031,9 +1031,9 @@ EXPORT_SYMBOL_GPL(register_pernet_subsys);
  */
 void unregister_pernet_subsys(struct pernet_operations *ops)
 {
-       down_write(&net_sem);
+       down_write(&pernet_ops_rwsem);
        unregister_pernet_operations(ops);
-       up_write(&net_sem);
+       up_write(&pernet_ops_rwsem);
 }
 EXPORT_SYMBOL_GPL(unregister_pernet_subsys);
 
@@ -1059,11 +1059,11 @@ EXPORT_SYMBOL_GPL(unregister_pernet_subsys);
 int register_pernet_device(struct pernet_operations *ops)
 {
        int error;
-       down_write(&net_sem);
+       down_write(&pernet_ops_rwsem);
        error = register_pernet_operations(&pernet_list, ops);
        if (!error && (first_device == &pernet_list))
                first_device = &ops->list;
-       up_write(&net_sem);
+       up_write(&pernet_ops_rwsem);
        return error;
 }
 EXPORT_SYMBOL_GPL(register_pernet_device);
@@ -1079,11 +1079,11 @@ EXPORT_SYMBOL_GPL(register_pernet_device);
  */
 void unregister_pernet_device(struct pernet_operations *ops)
 {
-       down_write(&net_sem);
+       down_write(&pernet_ops_rwsem);
        if (&ops->list == first_device)
                first_device = first_device->next;
        unregister_pernet_operations(ops);
-       up_write(&net_sem);
+       up_write(&pernet_ops_rwsem);
 }
 EXPORT_SYMBOL_GPL(unregister_pernet_device);
 
index 31438b6..73011a6 100644 (file)
@@ -460,11 +460,11 @@ static void rtnl_lock_unregistering_all(void)
 void rtnl_link_unregister(struct rtnl_link_ops *ops)
 {
        /* Close the race with cleanup_net() */
-       down_write(&net_sem);
+       down_write(&pernet_ops_rwsem);
        rtnl_lock_unregistering_all();
        __rtnl_link_unregister(ops);
        rtnl_unlock();
-       up_write(&net_sem);
+       up_write(&pernet_ops_rwsem);
 }
 EXPORT_SYMBOL_GPL(rtnl_link_unregister);