Skip to content

Commit d970dbf

Browse files
author
Vlad Yasevich
committed
SCTP: Convert custom hash lists to use hlist.
Convert the custom hash list traversals to use hlist functions. Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
1 parent 123ed97 commit d970dbf

7 files changed

Lines changed: 32 additions & 53 deletions

File tree

‎include/net/sctp/sctp.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,9 @@ static inline int sctp_vtag_hashfn(__u16 lport, __u16 rport, __u32 vtag)
665665
return (h & (sctp_assoc_hashsize-1));
666666
}
667667

668+
#define sctp_for_each_hentry(epb, node, head) \
669+
hlist_for_each_entry(epb, node, head, node)
670+
668671
/* Is a socket of this style? */
669672
#define sctp_style(sk, style) __sctp_style((sk), (SCTP_SOCKET_##style))
670673
static inline int __sctp_style(const struct sock *sk, sctp_socket_type_t style)

‎include/net/sctp/structs.h‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,19 @@ struct crypto_hash;
100100
struct sctp_bind_bucket {
101101
unsigned short port;
102102
unsigned short fastreuse;
103-
struct sctp_bind_bucket *next;
104-
struct sctp_bind_bucket **pprev;
103+
struct hlist_node node;
105104
struct hlist_head owner;
106105
};
107106

108107
struct sctp_bind_hashbucket {
109108
spinlock_t lock;
110-
struct sctp_bind_bucket *chain;
109+
struct hlist_head chain;
111110
};
112111

113112
/* Used for hashing all associations. */
114113
struct sctp_hashbucket {
115114
rwlock_t lock;
116-
struct sctp_ep_common *chain;
115+
struct hlist_head chain;
117116
} __attribute__((__aligned__(8)));
118117

119118

@@ -1230,8 +1229,7 @@ typedef enum {
12301229

12311230
struct sctp_ep_common {
12321231
/* Fields to help us manage our entries in the hash tables. */
1233-
struct sctp_ep_common *next;
1234-
struct sctp_ep_common **pprev;
1232+
struct hlist_node node;
12351233
int hashent;
12361234

12371235
/* Runtime type information. What kind of endpoint is this? */

‎net/sctp/endpointola.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ static struct sctp_association *__sctp_endpoint_lookup_assoc(
332332
struct sctp_transport *t = NULL;
333333
struct sctp_hashbucket *head;
334334
struct sctp_ep_common *epb;
335+
struct hlist_node *node;
335336
int hash;
336337
int rport;
337338

@@ -341,7 +342,7 @@ static struct sctp_association *__sctp_endpoint_lookup_assoc(
341342
hash = sctp_assoc_hashfn(ep->base.bind_addr.port, rport);
342343
head = &sctp_assoc_hashtable[hash];
343344
read_lock(&head->lock);
344-
for (epb = head->chain; epb; epb = epb->next) {
345+
sctp_for_each_hentry(epb, node, &head->chain) {
345346
asoc = sctp_assoc(epb);
346347
if (asoc->ep != ep || rport != asoc->peer.port)
347348
goto next;

‎net/sctp/input.c‎

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,6 @@ static int sctp_rcv_ootb(struct sk_buff *skb)
656656
/* Insert endpoint into the hash table. */
657657
static void __sctp_hash_endpoint(struct sctp_endpoint *ep)
658658
{
659-
struct sctp_ep_common **epp;
660659
struct sctp_ep_common *epb;
661660
struct sctp_hashbucket *head;
662661

@@ -666,12 +665,7 @@ static void __sctp_hash_endpoint(struct sctp_endpoint *ep)
666665
head = &sctp_ep_hashtable[epb->hashent];
667666

668667
sctp_write_lock(&head->lock);
669-
epp = &head->chain;
670-
epb->next = *epp;
671-
if (epb->next)
672-
(*epp)->pprev = &epb->next;
673-
*epp = epb;
674-
epb->pprev = epp;
668+
hlist_add_head(&epb->node, &head->chain);
675669
sctp_write_unlock(&head->lock);
676670
}
677671

@@ -691,19 +685,15 @@ static void __sctp_unhash_endpoint(struct sctp_endpoint *ep)
691685

692686
epb = &ep->base;
693687

688+
if (hlist_unhashed(&epb->node))
689+
return;
690+
694691
epb->hashent = sctp_ep_hashfn(epb->bind_addr.port);
695692

696693
head = &sctp_ep_hashtable[epb->hashent];
697694

698695
sctp_write_lock(&head->lock);
699-
700-
if (epb->pprev) {
701-
if (epb->next)
702-
epb->next->pprev = epb->pprev;
703-
*epb->pprev = epb->next;
704-
epb->pprev = NULL;
705-
}
706-
696+
__hlist_del(&epb->node);
707697
sctp_write_unlock(&head->lock);
708698
}
709699

@@ -721,12 +711,13 @@ static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(const union sctp_addr *l
721711
struct sctp_hashbucket *head;
722712
struct sctp_ep_common *epb;
723713
struct sctp_endpoint *ep;
714+
struct hlist_node *node;
724715
int hash;
725716

726717
hash = sctp_ep_hashfn(ntohs(laddr->v4.sin_port));
727718
head = &sctp_ep_hashtable[hash];
728719
read_lock(&head->lock);
729-
for (epb = head->chain; epb; epb = epb->next) {
720+
sctp_for_each_hentry(epb, node, &head->chain) {
730721
ep = sctp_ep(epb);
731722
if (sctp_endpoint_is_match(ep, laddr))
732723
goto hit;
@@ -744,7 +735,6 @@ static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(const union sctp_addr *l
744735
/* Insert association into the hash table. */
745736
static void __sctp_hash_established(struct sctp_association *asoc)
746737
{
747-
struct sctp_ep_common **epp;
748738
struct sctp_ep_common *epb;
749739
struct sctp_hashbucket *head;
750740

@@ -756,12 +746,7 @@ static void __sctp_hash_established(struct sctp_association *asoc)
756746
head = &sctp_assoc_hashtable[epb->hashent];
757747

758748
sctp_write_lock(&head->lock);
759-
epp = &head->chain;
760-
epb->next = *epp;
761-
if (epb->next)
762-
(*epp)->pprev = &epb->next;
763-
*epp = epb;
764-
epb->pprev = epp;
749+
hlist_add_head(&epb->node, &head->chain);
765750
sctp_write_unlock(&head->lock);
766751
}
767752

@@ -790,14 +775,7 @@ static void __sctp_unhash_established(struct sctp_association *asoc)
790775
head = &sctp_assoc_hashtable[epb->hashent];
791776

792777
sctp_write_lock(&head->lock);
793-
794-
if (epb->pprev) {
795-
if (epb->next)
796-
epb->next->pprev = epb->pprev;
797-
*epb->pprev = epb->next;
798-
epb->pprev = NULL;
799-
}
800-
778+
__hlist_del(&epb->node);
801779
sctp_write_unlock(&head->lock);
802780
}
803781

@@ -822,6 +800,7 @@ static struct sctp_association *__sctp_lookup_association(
822800
struct sctp_ep_common *epb;
823801
struct sctp_association *asoc;
824802
struct sctp_transport *transport;
803+
struct hlist_node *node;
825804
int hash;
826805

827806
/* Optimize here for direct hit, only listening connections can
@@ -830,7 +809,7 @@ static struct sctp_association *__sctp_lookup_association(
830809
hash = sctp_assoc_hashfn(ntohs(local->v4.sin_port), ntohs(peer->v4.sin_port));
831810
head = &sctp_assoc_hashtable[hash];
832811
read_lock(&head->lock);
833-
for (epb = head->chain; epb; epb = epb->next) {
812+
sctp_for_each_hentry(epb, node, &head->chain) {
834813
asoc = sctp_assoc(epb);
835814
transport = sctp_assoc_is_match(asoc, local, peer);
836815
if (transport)

‎net/sctp/proc.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ static int sctp_eps_seq_show(struct seq_file *seq, void *v)
225225
struct sctp_ep_common *epb;
226226
struct sctp_endpoint *ep;
227227
struct sock *sk;
228+
struct hlist_node *node;
228229
int hash = *(loff_t *)v;
229230

230231
if (hash >= sctp_ep_hashsize)
@@ -233,7 +234,7 @@ static int sctp_eps_seq_show(struct seq_file *seq, void *v)
233234
head = &sctp_ep_hashtable[hash];
234235
sctp_local_bh_disable();
235236
read_lock(&head->lock);
236-
for (epb = head->chain; epb; epb = epb->next) {
237+
sctp_for_each_hentry(epb, node, &head->chain) {
237238
ep = sctp_ep(epb);
238239
sk = epb->sk;
239240
seq_printf(seq, "%8p %8p %-3d %-3d %-4d %-5d %5d %5lu ", ep, sk,
@@ -328,6 +329,7 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
328329
struct sctp_ep_common *epb;
329330
struct sctp_association *assoc;
330331
struct sock *sk;
332+
struct hlist_node *node;
331333
int hash = *(loff_t *)v;
332334

333335
if (hash >= sctp_assoc_hashsize)
@@ -336,7 +338,7 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
336338
head = &sctp_assoc_hashtable[hash];
337339
sctp_local_bh_disable();
338340
read_lock(&head->lock);
339-
for (epb = head->chain; epb; epb = epb->next) {
341+
sctp_for_each_hentry(epb, node, &head->chain) {
340342
assoc = sctp_assoc(epb);
341343
sk = epb->sk;
342344
seq_printf(seq,

‎net/sctp/protocol.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ SCTP_STATIC __init int sctp_init(void)
11371137
}
11381138
for (i = 0; i < sctp_assoc_hashsize; i++) {
11391139
rwlock_init(&sctp_assoc_hashtable[i].lock);
1140-
sctp_assoc_hashtable[i].chain = NULL;
1140+
INIT_HLIST_HEAD(&sctp_assoc_hashtable[i].chain);
11411141
}
11421142

11431143
/* Allocate and initialize the endpoint hash table. */
@@ -1151,7 +1151,7 @@ SCTP_STATIC __init int sctp_init(void)
11511151
}
11521152
for (i = 0; i < sctp_ep_hashsize; i++) {
11531153
rwlock_init(&sctp_ep_hashtable[i].lock);
1154-
sctp_ep_hashtable[i].chain = NULL;
1154+
INIT_HLIST_HEAD(&sctp_ep_hashtable[i].chain);
11551155
}
11561156

11571157
/* Allocate and initialize the SCTP port hash table. */
@@ -1170,7 +1170,7 @@ SCTP_STATIC __init int sctp_init(void)
11701170
}
11711171
for (i = 0; i < sctp_port_hashsize; i++) {
11721172
spin_lock_init(&sctp_port_hashtable[i].lock);
1173-
sctp_port_hashtable[i].chain = NULL;
1173+
INIT_HLIST_HEAD(&sctp_port_hashtable[i].chain);
11741174
}
11751175

11761176
printk(KERN_INFO "SCTP: Hash tables configured "

‎net/sctp/socket.c‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5307,6 +5307,7 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
53075307
{
53085308
struct sctp_bind_hashbucket *head; /* hash list */
53095309
struct sctp_bind_bucket *pp; /* hash list port iterator */
5310+
struct hlist_node *node;
53105311
unsigned short snum;
53115312
int ret;
53125313

@@ -5331,7 +5332,7 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
53315332
index = sctp_phashfn(rover);
53325333
head = &sctp_port_hashtable[index];
53335334
sctp_spin_lock(&head->lock);
5334-
for (pp = head->chain; pp; pp = pp->next)
5335+
sctp_for_each_hentry(pp, node, &head->chain)
53355336
if (pp->port == rover)
53365337
goto next;
53375338
break;
@@ -5358,7 +5359,7 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
53585359
*/
53595360
head = &sctp_port_hashtable[sctp_phashfn(snum)];
53605361
sctp_spin_lock(&head->lock);
5361-
for (pp = head->chain; pp; pp = pp->next) {
5362+
sctp_for_each_hentry(pp, node, &head->chain) {
53625363
if (pp->port == snum)
53635364
goto pp_found;
53645365
}
@@ -5702,10 +5703,7 @@ static struct sctp_bind_bucket *sctp_bucket_create(
57025703
pp->port = snum;
57035704
pp->fastreuse = 0;
57045705
INIT_HLIST_HEAD(&pp->owner);
5705-
if ((pp->next = head->chain) != NULL)
5706-
pp->next->pprev = &pp->next;
5707-
head->chain = pp;
5708-
pp->pprev = &head->chain;
5706+
hlist_add_head(&pp->node, &head->chain);
57095707
}
57105708
return pp;
57115709
}
@@ -5714,9 +5712,7 @@ static struct sctp_bind_bucket *sctp_bucket_create(
57145712
static void sctp_bucket_destroy(struct sctp_bind_bucket *pp)
57155713
{
57165714
if (pp && hlist_empty(&pp->owner)) {
5717-
if (pp->next)
5718-
pp->next->pprev = pp->pprev;
5719-
*(pp->pprev) = pp->next;
5715+
__hlist_del(&pp->node);
57205716
kmem_cache_free(sctp_bucket_cachep, pp);
57215717
SCTP_DBG_OBJCNT_DEC(bind_bucket);
57225718
}

0 commit comments

Comments
 (0)