Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 72981
b: refs/heads/master
c: 6a1a3b9
h: refs/heads/master
i:
  72979: 1e38f55
v: v3
  • Loading branch information
Pavel Emelyanov authored and David S. Miller committed Nov 1, 2007
1 parent 388f9a8 commit ccf8b57
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 64 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: d46557955f2a35e58772518775464cdf354b3245
refs/heads/master: 6a1a3b9f686bb04820a232cc1657ef2c45670709
131 changes: 68 additions & 63 deletions trunk/net/core/net_namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,65 +22,6 @@ static struct kmem_cache *net_cachep;
struct net init_net;
EXPORT_SYMBOL_GPL(init_net);

static struct net *net_alloc(void)
{
return kmem_cache_zalloc(net_cachep, GFP_KERNEL);
}

static void net_free(struct net *net)
{
if (!net)
return;

if (unlikely(atomic_read(&net->use_count) != 0)) {
printk(KERN_EMERG "network namespace not free! Usage: %d\n",
atomic_read(&net->use_count));
return;
}

kmem_cache_free(net_cachep, net);
}

static void cleanup_net(struct work_struct *work)
{
struct pernet_operations *ops;
struct net *net;

net = container_of(work, struct net, work);

mutex_lock(&net_mutex);

/* Don't let anyone else find us. */
rtnl_lock();
list_del(&net->list);
rtnl_unlock();

/* Run all of the network namespace exit methods */
list_for_each_entry_reverse(ops, &pernet_list, list) {
if (ops->exit)
ops->exit(net);
}

mutex_unlock(&net_mutex);

/* Ensure there are no outstanding rcu callbacks using this
* network namespace.
*/
rcu_barrier();

/* Finally it is safe to free my network namespace structure */
net_free(net);
}


void __put_net(struct net *net)
{
/* Cleanup the network namespace in process context */
INIT_WORK(&net->work, cleanup_net);
schedule_work(&net->work);
}
EXPORT_SYMBOL_GPL(__put_net);

/*
* setup_net runs the initializers for the network namespace object.
*/
Expand Down Expand Up @@ -117,6 +58,12 @@ static int setup_net(struct net *net)
goto out;
}

#ifdef CONFIG_NET_NS
static struct net *net_alloc(void)
{
return kmem_cache_zalloc(net_cachep, GFP_KERNEL);
}

struct net *copy_net_ns(unsigned long flags, struct net *old_net)
{
struct net *new_net = NULL;
Expand All @@ -127,10 +74,6 @@ struct net *copy_net_ns(unsigned long flags, struct net *old_net)
if (!(flags & CLONE_NEWNET))
return old_net;

#ifndef CONFIG_NET_NS
return ERR_PTR(-EINVAL);
#endif

err = -ENOMEM;
new_net = net_alloc();
if (!new_net)
Expand All @@ -157,6 +100,68 @@ struct net *copy_net_ns(unsigned long flags, struct net *old_net)
return new_net;
}

static void net_free(struct net *net)
{
if (!net)
return;

if (unlikely(atomic_read(&net->use_count) != 0)) {
printk(KERN_EMERG "network namespace not free! Usage: %d\n",
atomic_read(&net->use_count));
return;
}

kmem_cache_free(net_cachep, net);
}

static void cleanup_net(struct work_struct *work)
{
struct pernet_operations *ops;
struct net *net;

net = container_of(work, struct net, work);

mutex_lock(&net_mutex);

/* Don't let anyone else find us. */
rtnl_lock();
list_del(&net->list);
rtnl_unlock();

/* Run all of the network namespace exit methods */
list_for_each_entry_reverse(ops, &pernet_list, list) {
if (ops->exit)
ops->exit(net);
}

mutex_unlock(&net_mutex);

/* Ensure there are no outstanding rcu callbacks using this
* network namespace.
*/
rcu_barrier();

/* Finally it is safe to free my network namespace structure */
net_free(net);
}

void __put_net(struct net *net)
{
/* Cleanup the network namespace in process context */
INIT_WORK(&net->work, cleanup_net);
schedule_work(&net->work);
}
EXPORT_SYMBOL_GPL(__put_net);

#else
struct net *copy_net_ns(unsigned long flags, struct net *old_net)
{
if (flags & CLONE_NEWNET)
return ERR_PTR(-EINVAL);
return old_net;
}
#endif

static int __init net_ns_init(void)
{
int err;
Expand Down

0 comments on commit ccf8b57

Please sign in to comment.