Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 90448
b: refs/heads/master
c: 13ff3d6
h: refs/heads/master
v: v3
  • Loading branch information
Pavel Emelyanov authored and David S. Miller committed Mar 28, 2008
1 parent 34b671e commit c651879
Show file tree
Hide file tree
Showing 3 changed files with 36 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: bc578a54f0fd489d0722303f9a52508495ccaf9a
refs/heads/master: 13ff3d6fa4e6d8b6ee7c64245a0078e6a0e6f977
1 change: 1 addition & 0 deletions trunk/include/net/sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ struct proto {

/* Keeping track of sockets in use */
#ifdef CONFIG_PROC_FS
unsigned int inuse_idx;
struct pcounter inuse;
#endif

Expand Down
34 changes: 34 additions & 0 deletions trunk/net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1940,6 +1940,38 @@ EXPORT_SYMBOL(sk_common_release);
static DEFINE_RWLOCK(proto_list_lock);
static LIST_HEAD(proto_list);

#ifdef CONFIG_PROC_FS
#define PROTO_INUSE_NR 64 /* should be enough for the first time */

static DECLARE_BITMAP(proto_inuse_idx, PROTO_INUSE_NR);

static void assign_proto_idx(struct proto *prot)
{
prot->inuse_idx = find_first_zero_bit(proto_inuse_idx, PROTO_INUSE_NR);

if (unlikely(prot->inuse_idx == PROTO_INUSE_NR - 1)) {
printk(KERN_ERR "PROTO_INUSE_NR exhausted\n");
return;
}

set_bit(prot->inuse_idx, proto_inuse_idx);
}

static void release_proto_idx(struct proto *prot)
{
if (prot->inuse_idx != PROTO_INUSE_NR - 1)
clear_bit(prot->inuse_idx, proto_inuse_idx);
}
#else
static inline void assign_proto_idx(struct proto *prot)
{
}

static inline void release_proto_idx(struct proto *prot)
{
}
#endif

int proto_register(struct proto *prot, int alloc_slab)
{
char *request_sock_slab_name = NULL;
Expand Down Expand Up @@ -2000,6 +2032,7 @@ int proto_register(struct proto *prot, int alloc_slab)

write_lock(&proto_list_lock);
list_add(&prot->node, &proto_list);
assign_proto_idx(prot);
write_unlock(&proto_list_lock);
return 0;

Expand All @@ -2026,6 +2059,7 @@ EXPORT_SYMBOL(proto_register);
void proto_unregister(struct proto *prot)
{
write_lock(&proto_list_lock);
release_proto_idx(prot);
list_del(&prot->node);
write_unlock(&proto_list_lock);

Expand Down

0 comments on commit c651879

Please sign in to comment.