Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 90786
b: refs/heads/master
c: 5d1e446
h: refs/heads/master
v: v3
  • Loading branch information
Denis V. Lunev authored and David S. Miller committed Apr 16, 2008
1 parent b7a258e commit a5c6484
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 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: 554eb27782d4bb79e0a286a08ecafb81f758058c
refs/heads/master: 5d1e4468a7705db7c1415a65fd16f07113afc1b2
40 changes: 24 additions & 16 deletions trunk/include/net/net_namespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ struct net {
atomic_t count; /* To decided when the network
* namespace should be freed.
*/
#ifdef NETNS_REFCNT_DEBUG
atomic_t use_count; /* To track references we
* destroy on demand
*/
#endif
struct list_head list; /* list of network namespaces */
struct work_struct work; /* work struct for freeing */

Expand Down Expand Up @@ -117,17 +119,6 @@ static inline void put_net(struct net *net)
__put_net(net);
}

static inline struct net *hold_net(struct net *net)
{
atomic_inc(&net->use_count);
return net;
}

static inline void release_net(struct net *net)
{
atomic_dec(&net->use_count);
}

static inline
int net_eq(const struct net *net1, const struct net *net2)
{
Expand All @@ -143,27 +134,44 @@ static inline void put_net(struct net *net)
{
}

static inline struct net *maybe_get_net(struct net *net)
{
return net;
}

static inline
int net_eq(const struct net *net1, const struct net *net2)
{
return 1;
}
#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);
}

static inline struct net *maybe_get_net(struct net *net)
#else
static inline struct net *hold_net(struct net *net)
{
return net;
}

static inline
int net_eq(const struct net *net1, const struct net *net2)
static inline void release_net(struct net *net)
{
return 1;
}
#endif


#define for_each_net(VAR) \
list_for_each_entry(VAR, &net_namespace_list, list)

Expand Down
4 changes: 4 additions & 0 deletions trunk/net/core/net_namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ static __net_init int setup_net(struct net *net)
struct net_generic *ng;

atomic_set(&net->count, 1);
#ifdef NETNS_REFCNT_DEBUG
atomic_set(&net->use_count, 0);
#endif

error = -ENOMEM;
ng = kzalloc(sizeof(struct net_generic) +
Expand Down Expand Up @@ -86,11 +88,13 @@ static void net_free(struct net *net)
if (!net)
return;

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

kmem_cache_free(net_cachep, net);
}
Expand Down

0 comments on commit a5c6484

Please sign in to comment.