29
29
#include <linux/in.h>
30
30
#include <net/sock.h>
31
31
#include <net/tcp.h>
32
+ #include <net/smc.h>
32
33
33
34
#include "smc.h"
34
35
#include "smc_clc.h"
@@ -59,13 +60,48 @@ static void smc_set_keepalive(struct sock *sk, int val)
59
60
smc -> clcsock -> sk -> sk_prot -> keepalive (smc -> clcsock -> sk , val );
60
61
}
61
62
62
- static struct proto smc_proto = {
63
+ static struct smc_hashinfo smc_v4_hashinfo = {
64
+ .lock = __RW_LOCK_UNLOCKED (smc_v4_hashinfo .lock ),
65
+ };
66
+
67
+ int smc_hash_sk (struct sock * sk )
68
+ {
69
+ struct smc_hashinfo * h = sk -> sk_prot -> h .smc_hash ;
70
+ struct hlist_head * head ;
71
+
72
+ head = & h -> ht ;
73
+
74
+ write_lock_bh (& h -> lock );
75
+ sk_add_node (sk , head );
76
+ sock_prot_inuse_add (sock_net (sk ), sk -> sk_prot , 1 );
77
+ write_unlock_bh (& h -> lock );
78
+
79
+ return 0 ;
80
+ }
81
+ EXPORT_SYMBOL_GPL (smc_hash_sk );
82
+
83
+ void smc_unhash_sk (struct sock * sk )
84
+ {
85
+ struct smc_hashinfo * h = sk -> sk_prot -> h .smc_hash ;
86
+
87
+ write_lock_bh (& h -> lock );
88
+ if (sk_del_node_init (sk ))
89
+ sock_prot_inuse_add (sock_net (sk ), sk -> sk_prot , -1 );
90
+ write_unlock_bh (& h -> lock );
91
+ }
92
+ EXPORT_SYMBOL_GPL (smc_unhash_sk );
93
+
94
+ struct proto smc_proto = {
63
95
.name = "SMC" ,
64
96
.owner = THIS_MODULE ,
65
97
.keepalive = smc_set_keepalive ,
98
+ .hash = smc_hash_sk ,
99
+ .unhash = smc_unhash_sk ,
66
100
.obj_size = sizeof (struct smc_sock ),
101
+ .h .smc_hash = & smc_v4_hashinfo ,
67
102
.slab_flags = SLAB_DESTROY_BY_RCU ,
68
103
};
104
+ EXPORT_SYMBOL_GPL (smc_proto );
69
105
70
106
static int smc_release (struct socket * sock )
71
107
{
@@ -109,6 +145,7 @@ static int smc_release(struct socket *sock)
109
145
schedule_delayed_work (& smc -> sock_put_work ,
110
146
SMC_CLOSE_SOCK_PUT_DELAY );
111
147
}
148
+ sk -> sk_prot -> unhash (sk );
112
149
release_sock (sk );
113
150
114
151
sock_put (sk );
@@ -144,6 +181,7 @@ static struct sock *smc_sock_alloc(struct net *net, struct socket *sock)
144
181
INIT_LIST_HEAD (& smc -> accept_q );
145
182
spin_lock_init (& smc -> accept_q_lock );
146
183
INIT_DELAYED_WORK (& smc -> sock_put_work , smc_close_sock_put_work );
184
+ sk -> sk_prot -> hash (sk );
147
185
sk_refcnt_debug_inc (sk );
148
186
149
187
return sk ;
@@ -536,6 +574,7 @@ static int smc_clcsock_accept(struct smc_sock *lsmc, struct smc_sock **new_smc)
536
574
lsmc -> sk .sk_err = - rc ;
537
575
new_sk -> sk_state = SMC_CLOSED ;
538
576
sock_set_flag (new_sk , SOCK_DEAD );
577
+ sk -> sk_prot -> unhash (new_sk );
539
578
sock_put (new_sk );
540
579
* new_smc = NULL ;
541
580
goto out ;
@@ -545,6 +584,7 @@ static int smc_clcsock_accept(struct smc_sock *lsmc, struct smc_sock **new_smc)
545
584
sock_release (new_clcsock );
546
585
new_sk -> sk_state = SMC_CLOSED ;
547
586
sock_set_flag (new_sk , SOCK_DEAD );
587
+ sk -> sk_prot -> unhash (new_sk );
548
588
sock_put (new_sk );
549
589
* new_smc = NULL ;
550
590
goto out ;
@@ -1320,6 +1360,7 @@ static int __init smc_init(void)
1320
1360
pr_err ("%s: sock_register fails with %d\n" , __func__ , rc );
1321
1361
goto out_proto ;
1322
1362
}
1363
+ INIT_HLIST_HEAD (& smc_v4_hashinfo .ht );
1323
1364
1324
1365
rc = smc_ib_register_client ();
1325
1366
if (rc ) {
0 commit comments