diff options
author | Arnaldo Carvalho de Melo <acme@mandriva.com> | 2006-03-20 20:16:17 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2006-03-20 20:16:17 -0500 |
commit | 9b07ef5ddaced1e822b1a1fb1da088eb15c45cb4 (patch) | |
tree | 57a33bb4ed32384a95e2c23d7039e8ed99c5b595 /net | |
parent | fa23e2ecd30a584cdcb9b3de0149dbb5c073c20b (diff) |
[DCCP] ackvec: Introduce dccp_ackvec_slab
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/dccp/ackvec.c | 34 | ||||
-rw-r--r-- | net/dccp/ackvec.h | 12 | ||||
-rw-r--r-- | net/dccp/proto.c | 9 |
3 files changed, 52 insertions, 3 deletions
diff --git a/net/dccp/ackvec.c b/net/dccp/ackvec.c index 348374005db0..64408253b14e 100644 --- a/net/dccp/ackvec.c +++ b/net/dccp/ackvec.c | |||
@@ -13,10 +13,16 @@ | |||
13 | #include "dccp.h" | 13 | #include "dccp.h" |
14 | 14 | ||
15 | #include <linux/dccp.h> | 15 | #include <linux/dccp.h> |
16 | #include <linux/init.h> | ||
17 | #include <linux/errno.h> | ||
18 | #include <linux/kernel.h> | ||
16 | #include <linux/skbuff.h> | 19 | #include <linux/skbuff.h> |
20 | #include <linux/slab.h> | ||
17 | 21 | ||
18 | #include <net/sock.h> | 22 | #include <net/sock.h> |
19 | 23 | ||
24 | static kmem_cache_t *dccp_ackvec_slab; | ||
25 | |||
20 | int dccp_insert_option_ackvec(struct sock *sk, struct sk_buff *skb) | 26 | int dccp_insert_option_ackvec(struct sock *sk, struct sk_buff *skb) |
21 | { | 27 | { |
22 | struct dccp_sock *dp = dccp_sk(sk); | 28 | struct dccp_sock *dp = dccp_sk(sk); |
@@ -96,7 +102,7 @@ int dccp_insert_option_ackvec(struct sock *sk, struct sk_buff *skb) | |||
96 | 102 | ||
97 | struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority) | 103 | struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority) |
98 | { | 104 | { |
99 | struct dccp_ackvec *av = kmalloc(sizeof(*av), priority); | 105 | struct dccp_ackvec *av = kmem_cache_alloc(dccp_ackvec_slab, priority); |
100 | 106 | ||
101 | if (av != NULL) { | 107 | if (av != NULL) { |
102 | av->dccpav_buf_head = | 108 | av->dccpav_buf_head = |
@@ -115,7 +121,7 @@ struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority) | |||
115 | 121 | ||
116 | void dccp_ackvec_free(struct dccp_ackvec *av) | 122 | void dccp_ackvec_free(struct dccp_ackvec *av) |
117 | { | 123 | { |
118 | kfree(av); | 124 | kmem_cache_free(dccp_ackvec_slab, av); |
119 | } | 125 | } |
120 | 126 | ||
121 | static inline u8 dccp_ackvec_state(const struct dccp_ackvec *av, | 127 | static inline u8 dccp_ackvec_state(const struct dccp_ackvec *av, |
@@ -420,3 +426,27 @@ int dccp_ackvec_parse(struct sock *sk, const struct sk_buff *skb, | |||
420 | len, value); | 426 | len, value); |
421 | return 0; | 427 | return 0; |
422 | } | 428 | } |
429 | |||
430 | static char dccp_ackvec_slab_msg[] __initdata = | ||
431 | KERN_CRIT "DCCP: Unable to create ack vectors slab cache\n"; | ||
432 | |||
433 | int __init dccp_ackvec_init(void) | ||
434 | { | ||
435 | dccp_ackvec_slab = kmem_cache_create("dccp_ackvec", | ||
436 | sizeof(struct dccp_ackvec), 0, | ||
437 | SLAB_HWCACHE_ALIGN, NULL, NULL); | ||
438 | if (dccp_ackvec_slab == NULL) { | ||
439 | printk(dccp_ackvec_slab_msg); | ||
440 | return -ENOBUFS; | ||
441 | } | ||
442 | |||
443 | return 0; | ||
444 | } | ||
445 | |||
446 | void dccp_ackvec_exit(void) | ||
447 | { | ||
448 | if (dccp_ackvec_slab != NULL) { | ||
449 | kmem_cache_destroy(dccp_ackvec_slab); | ||
450 | dccp_ackvec_slab = NULL; | ||
451 | } | ||
452 | } | ||
diff --git a/net/dccp/ackvec.h b/net/dccp/ackvec.h index f083daf4200c..470bae8a9d07 100644 --- a/net/dccp/ackvec.h +++ b/net/dccp/ackvec.h | |||
@@ -71,6 +71,9 @@ struct sock; | |||
71 | struct sk_buff; | 71 | struct sk_buff; |
72 | 72 | ||
73 | #ifdef CONFIG_IP_DCCP_ACKVEC | 73 | #ifdef CONFIG_IP_DCCP_ACKVEC |
74 | extern int dccp_ackvec_init(void); | ||
75 | extern void dccp_ackvec_exit(void); | ||
76 | |||
74 | extern struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority); | 77 | extern struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority); |
75 | extern void dccp_ackvec_free(struct dccp_ackvec *av); | 78 | extern void dccp_ackvec_free(struct dccp_ackvec *av); |
76 | 79 | ||
@@ -89,6 +92,15 @@ static inline int dccp_ackvec_pending(const struct dccp_ackvec *av) | |||
89 | return av->dccpav_sent_len != av->dccpav_vec_len; | 92 | return av->dccpav_sent_len != av->dccpav_vec_len; |
90 | } | 93 | } |
91 | #else /* CONFIG_IP_DCCP_ACKVEC */ | 94 | #else /* CONFIG_IP_DCCP_ACKVEC */ |
95 | static inline int dccp_ackvec_init(void) | ||
96 | { | ||
97 | return 0; | ||
98 | } | ||
99 | |||
100 | static inline void dccp_ackvec_exit(void) | ||
101 | { | ||
102 | } | ||
103 | |||
92 | static inline struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority) | 104 | static inline struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority) |
93 | { | 105 | { |
94 | return NULL; | 106 | return NULL; |
diff --git a/net/dccp/proto.c b/net/dccp/proto.c index 568d266ee379..81ad24953710 100644 --- a/net/dccp/proto.c +++ b/net/dccp/proto.c | |||
@@ -877,11 +877,17 @@ static int __init dccp_init(void) | |||
877 | 877 | ||
878 | inet_register_protosw(&dccp_v4_protosw); | 878 | inet_register_protosw(&dccp_v4_protosw); |
879 | 879 | ||
880 | rc = dccp_ctl_sock_init(); | 880 | rc = dccp_ackvec_init(); |
881 | if (rc) | 881 | if (rc) |
882 | goto out_unregister_protosw; | 882 | goto out_unregister_protosw; |
883 | |||
884 | rc = dccp_ctl_sock_init(); | ||
885 | if (rc) | ||
886 | goto out_ackvec_exit; | ||
883 | out: | 887 | out: |
884 | return rc; | 888 | return rc; |
889 | out_ackvec_exit: | ||
890 | dccp_ackvec_exit(); | ||
885 | out_unregister_protosw: | 891 | out_unregister_protosw: |
886 | inet_unregister_protosw(&dccp_v4_protosw); | 892 | inet_unregister_protosw(&dccp_v4_protosw); |
887 | inet_del_protocol(&dccp_protocol, IPPROTO_DCCP); | 893 | inet_del_protocol(&dccp_protocol, IPPROTO_DCCP); |
@@ -923,6 +929,7 @@ static void __exit dccp_fini(void) | |||
923 | sizeof(struct inet_ehash_bucket))); | 929 | sizeof(struct inet_ehash_bucket))); |
924 | kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep); | 930 | kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep); |
925 | proto_unregister(&dccp_prot); | 931 | proto_unregister(&dccp_prot); |
932 | dccp_ackvec_exit(); | ||
926 | } | 933 | } |
927 | 934 | ||
928 | module_init(dccp_init); | 935 | module_init(dccp_init); |