Commit 4420bf21 authored by Kirill Tkhai's avatar Kirill Tkhai Committed by David S. Miller

net: Rename net_sem to pernet_ops_rwsem

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: default avatarKirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 2f635cee
...@@ -36,7 +36,7 @@ extern int rtnl_is_locked(void); ...@@ -36,7 +36,7 @@ extern int rtnl_is_locked(void);
extern int rtnl_lock_killable(void); extern int rtnl_lock_killable(void);
extern wait_queue_head_t netdev_unregistering_wq; 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 #ifdef CONFIG_PROVE_LOCKING
extern bool lockdep_rtnl_is_held(void); extern bool lockdep_rtnl_is_held(void);
......
...@@ -60,9 +60,10 @@ struct net { ...@@ -60,9 +60,10 @@ struct net {
struct list_head list; /* list of network namespaces */ struct list_head list; /* list of network namespaces */
struct list_head exit_list; /* To linked to call pernet exit struct list_head exit_list; /* To linked to call pernet exit
* methods on dead net (net_sem * methods on dead net (
* read locked), or to unregister * pernet_ops_rwsem read locked),
* pernet ops (net_sem wr locked). * or to unregister pernet ops
* (pernet_ops_rwsem write locked).
*/ */
struct llist_node cleanup_list; /* namespaces on death row */ struct llist_node cleanup_list; /* namespaces on death row */
...@@ -95,8 +96,9 @@ struct net { ...@@ -95,8 +96,9 @@ struct net {
/* core fib_rules */ /* core fib_rules */
struct list_head rules_ops; 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 net_device *loopback_dev; /* The loopback */
struct netns_core core; struct netns_core core;
struct netns_mib mib; struct netns_mib mib;
......
...@@ -41,10 +41,10 @@ EXPORT_SYMBOL(init_net); ...@@ -41,10 +41,10 @@ EXPORT_SYMBOL(init_net);
static bool init_net_initialized; 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. * init_net_initialized and first_device pointer.
*/ */
DECLARE_RWSEM(net_sem); DECLARE_RWSEM(pernet_ops_rwsem);
#define MIN_PERNET_OPS_ID \ #define MIN_PERNET_OPS_ID \
((sizeof(struct net_generic) + sizeof(void *) - 1) / sizeof(void *)) ((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) ...@@ -72,7 +72,7 @@ static int net_assign_generic(struct net *net, unsigned int id, void *data)
BUG_ON(id < MIN_PERNET_OPS_ID); BUG_ON(id < MIN_PERNET_OPS_ID);
old_ng = rcu_dereference_protected(net->gen, old_ng = rcu_dereference_protected(net->gen,
lockdep_is_held(&net_sem)); lockdep_is_held(&pernet_ops_rwsem));
if (old_ng->s.len > id) { if (old_ng->s.len > id) {
old_ng->ptr[id] = data; old_ng->ptr[id] = data;
return 0; return 0;
...@@ -289,7 +289,7 @@ struct net *get_net_ns_by_id(struct net *net, int id) ...@@ -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) 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; const struct pernet_operations *ops, *saved_ops;
int error = 0; int error = 0;
LIST_HEAD(net_exit_list); LIST_HEAD(net_exit_list);
...@@ -422,13 +422,13 @@ struct net *copy_net_ns(unsigned long flags, ...@@ -422,13 +422,13 @@ struct net *copy_net_ns(unsigned long flags,
net->ucounts = ucounts; net->ucounts = ucounts;
get_user_ns(user_ns); get_user_ns(user_ns);
rv = down_read_killable(&net_sem); rv = down_read_killable(&pernet_ops_rwsem);
if (rv < 0) if (rv < 0)
goto put_userns; goto put_userns;
rv = setup_net(net, user_ns); rv = setup_net(net, user_ns);
up_read(&net_sem); up_read(&pernet_ops_rwsem);
if (rv < 0) { if (rv < 0) {
put_userns: put_userns:
...@@ -480,7 +480,7 @@ static void cleanup_net(struct work_struct *work) ...@@ -480,7 +480,7 @@ static void cleanup_net(struct work_struct *work)
/* Atomically snapshot the list of namespaces to cleanup */ /* Atomically snapshot the list of namespaces to cleanup */
net_kill_list = llist_del_all(&cleanup_list); net_kill_list = llist_del_all(&cleanup_list);
down_read(&net_sem); down_read(&pernet_ops_rwsem);
/* Don't let anyone else find us. */ /* Don't let anyone else find us. */
rtnl_lock(); rtnl_lock();
...@@ -519,7 +519,7 @@ static void cleanup_net(struct work_struct *work) ...@@ -519,7 +519,7 @@ static void cleanup_net(struct work_struct *work)
list_for_each_entry_reverse(ops, &pernet_list, list) list_for_each_entry_reverse(ops, &pernet_list, list)
ops_free_list(ops, &net_exit_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 /* Ensure there are no outstanding rcu callbacks using this
* network namespace. * network namespace.
...@@ -546,8 +546,8 @@ static void cleanup_net(struct work_struct *work) ...@@ -546,8 +546,8 @@ static void cleanup_net(struct work_struct *work)
*/ */
void net_ns_barrier(void) void net_ns_barrier(void)
{ {
down_write(&net_sem); down_write(&pernet_ops_rwsem);
up_write(&net_sem); up_write(&pernet_ops_rwsem);
} }
EXPORT_SYMBOL(net_ns_barrier); EXPORT_SYMBOL(net_ns_barrier);
...@@ -869,12 +869,12 @@ static int __init net_ns_init(void) ...@@ -869,12 +869,12 @@ static int __init net_ns_init(void)
rcu_assign_pointer(init_net.gen, ng); rcu_assign_pointer(init_net.gen, ng);
down_write(&net_sem); down_write(&pernet_ops_rwsem);
if (setup_net(&init_net, &init_user_ns)) if (setup_net(&init_net, &init_user_ns))
panic("Could not setup the initial network namespace"); panic("Could not setup the initial network namespace");
init_net_initialized = true; init_net_initialized = true;
up_write(&net_sem); up_write(&pernet_ops_rwsem);
register_pernet_subsys(&net_ns_ops); register_pernet_subsys(&net_ns_ops);
...@@ -1013,9 +1013,9 @@ static void unregister_pernet_operations(struct pernet_operations *ops) ...@@ -1013,9 +1013,9 @@ static void unregister_pernet_operations(struct pernet_operations *ops)
int register_pernet_subsys(struct pernet_operations *ops) int register_pernet_subsys(struct pernet_operations *ops)
{ {
int error; int error;
down_write(&net_sem); down_write(&pernet_ops_rwsem);
error = register_pernet_operations(first_device, ops); error = register_pernet_operations(first_device, ops);
up_write(&net_sem); up_write(&pernet_ops_rwsem);
return error; return error;
} }
EXPORT_SYMBOL_GPL(register_pernet_subsys); EXPORT_SYMBOL_GPL(register_pernet_subsys);
...@@ -1031,9 +1031,9 @@ EXPORT_SYMBOL_GPL(register_pernet_subsys); ...@@ -1031,9 +1031,9 @@ EXPORT_SYMBOL_GPL(register_pernet_subsys);
*/ */
void unregister_pernet_subsys(struct pernet_operations *ops) void unregister_pernet_subsys(struct pernet_operations *ops)
{ {
down_write(&net_sem); down_write(&pernet_ops_rwsem);
unregister_pernet_operations(ops); unregister_pernet_operations(ops);
up_write(&net_sem); up_write(&pernet_ops_rwsem);
} }
EXPORT_SYMBOL_GPL(unregister_pernet_subsys); EXPORT_SYMBOL_GPL(unregister_pernet_subsys);
...@@ -1059,11 +1059,11 @@ 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 register_pernet_device(struct pernet_operations *ops)
{ {
int error; int error;
down_write(&net_sem); down_write(&pernet_ops_rwsem);
error = register_pernet_operations(&pernet_list, ops); error = register_pernet_operations(&pernet_list, ops);
if (!error && (first_device == &pernet_list)) if (!error && (first_device == &pernet_list))
first_device = &ops->list; first_device = &ops->list;
up_write(&net_sem); up_write(&pernet_ops_rwsem);
return error; return error;
} }
EXPORT_SYMBOL_GPL(register_pernet_device); EXPORT_SYMBOL_GPL(register_pernet_device);
...@@ -1079,11 +1079,11 @@ EXPORT_SYMBOL_GPL(register_pernet_device); ...@@ -1079,11 +1079,11 @@ EXPORT_SYMBOL_GPL(register_pernet_device);
*/ */
void unregister_pernet_device(struct pernet_operations *ops) void unregister_pernet_device(struct pernet_operations *ops)
{ {
down_write(&net_sem); down_write(&pernet_ops_rwsem);
if (&ops->list == first_device) if (&ops->list == first_device)
first_device = first_device->next; first_device = first_device->next;
unregister_pernet_operations(ops); unregister_pernet_operations(ops);
up_write(&net_sem); up_write(&pernet_ops_rwsem);
} }
EXPORT_SYMBOL_GPL(unregister_pernet_device); EXPORT_SYMBOL_GPL(unregister_pernet_device);
......
...@@ -460,11 +460,11 @@ static void rtnl_lock_unregistering_all(void) ...@@ -460,11 +460,11 @@ static void rtnl_lock_unregistering_all(void)
void rtnl_link_unregister(struct rtnl_link_ops *ops) void rtnl_link_unregister(struct rtnl_link_ops *ops)
{ {
/* Close the race with cleanup_net() */ /* Close the race with cleanup_net() */
down_write(&net_sem); down_write(&pernet_ops_rwsem);
rtnl_lock_unregistering_all(); rtnl_lock_unregistering_all();
__rtnl_link_unregister(ops); __rtnl_link_unregister(ops);
rtnl_unlock(); rtnl_unlock();
up_write(&net_sem); up_write(&pernet_ops_rwsem);
} }
EXPORT_SYMBOL_GPL(rtnl_link_unregister); EXPORT_SYMBOL_GPL(rtnl_link_unregister);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment