Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 90477
b: refs/heads/master
c: 70ee115
h: refs/heads/master
i:
  90475: 338bd7f
v: v3
  • Loading branch information
Pavel Emelyanov authored and David S. Miller committed Apr 1, 2008
1 parent 08b46b9 commit 7dbddb7
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: c29a0bc4dfc4d833eb702b1929cec96a3eeb9f7a
refs/heads/master: 70ee115942be6ce52ff10e5e813fb4da82cdb25a
3 changes: 3 additions & 0 deletions trunk/include/net/netns/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
#define __NETNS_CORE_H__

struct ctl_table_header;
struct prot_inuse;

struct netns_core {
/* core sysctls */
struct ctl_table_header *sysctl_hdr;

int sysctl_somaxconn;

struct prot_inuse *inuse;
};

#endif
48 changes: 48 additions & 0 deletions trunk/net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1947,6 +1947,53 @@ struct prot_inuse {
};

static DECLARE_BITMAP(proto_inuse_idx, PROTO_INUSE_NR);

#ifdef CONFIG_NET_NS
void sock_prot_inuse_add(struct net *net, struct proto *prot, int val)
{
int cpu = smp_processor_id();
per_cpu_ptr(net->core.inuse, cpu)->val[prot->inuse_idx] += val;
}
EXPORT_SYMBOL_GPL(sock_prot_inuse_add);

int sock_prot_inuse_get(struct net *net, struct proto *prot)
{
int cpu, idx = prot->inuse_idx;
int res = 0;

for_each_possible_cpu(cpu)
res += per_cpu_ptr(net->core.inuse, cpu)->val[idx];

return res >= 0 ? res : 0;
}
EXPORT_SYMBOL_GPL(sock_prot_inuse_get);

static int sock_inuse_init_net(struct net *net)
{
net->core.inuse = alloc_percpu(struct prot_inuse);
return net->core.inuse ? 0 : -ENOMEM;
}

static void sock_inuse_exit_net(struct net *net)
{
free_percpu(net->core.inuse);
}

static struct pernet_operations net_inuse_ops = {
.init = sock_inuse_init_net,
.exit = sock_inuse_exit_net,
};

static __init int net_inuse_init(void)
{
if (register_pernet_subsys(&net_inuse_ops))
panic("Cannot initialize net inuse counters");

return 0;
}

core_initcall(net_inuse_init);
#else
static DEFINE_PER_CPU(struct prot_inuse, prot_inuse);

void sock_prot_inuse_add(struct net *net, struct proto *prot, int val)
Expand All @@ -1966,6 +2013,7 @@ int sock_prot_inuse_get(struct net *net, struct proto *prot)
return res >= 0 ? res : 0;
}
EXPORT_SYMBOL_GPL(sock_prot_inuse_get);
#endif

static void assign_proto_idx(struct proto *prot)
{
Expand Down

0 comments on commit 7dbddb7

Please sign in to comment.