Skip to content

Commit

Permalink
[NET]: Relax the reference counting of init_net_ns
Browse files Browse the repository at this point in the history
When the CONFIG_NET_NS is n there's no need in refcounting
the initial net namespace. So relax this code by making a
stupid stubs for the "n" case.

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Pavel Emelyanov authored and David S. Miller committed Nov 1, 2007
1 parent 1dba323 commit d465579
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions include/net/net_namespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,12 @@ static inline struct net *copy_net_ns(unsigned long flags, struct net *net_ns)
}
#endif

#ifdef CONFIG_NET_NS
extern void __put_net(struct net *net);

static inline struct net *get_net(struct net *net)
{
#ifdef CONFIG_NET
atomic_inc(&net->count);
#endif
return net;
}

Expand All @@ -75,26 +74,44 @@ static inline struct net *maybe_get_net(struct net *net)

static inline void put_net(struct net *net)
{
#ifdef CONFIG_NET
if (atomic_dec_and_test(&net->count))
__put_net(net);
#endif
}

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

static inline void release_net(struct net *net)
{
#ifdef CONFIG_NET
atomic_dec(&net->use_count);
#endif
}
#else
static inline struct net *get_net(struct net *net)
{
return net;
}

static inline void put_net(struct net *net)
{
}

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

static inline void release_net(struct net *net)
{
}

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

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

0 comments on commit d465579

Please sign in to comment.