2929#include <linux/in.h>
3030#include <net/sock.h>
3131#include <net/tcp.h>
32+ #include <net/smc.h>
3233
3334#include "smc.h"
3435#include "smc_clc.h"
@@ -59,13 +60,48 @@ static void smc_set_keepalive(struct sock *sk, int val)
5960 smc -> clcsock -> sk -> sk_prot -> keepalive (smc -> clcsock -> sk , val );
6061}
6162
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 = {
6395 .name = "SMC" ,
6496 .owner = THIS_MODULE ,
6597 .keepalive = smc_set_keepalive ,
98+ .hash = smc_hash_sk ,
99+ .unhash = smc_unhash_sk ,
66100 .obj_size = sizeof (struct smc_sock ),
101+ .h .smc_hash = & smc_v4_hashinfo ,
67102 .slab_flags = SLAB_DESTROY_BY_RCU ,
68103};
104+ EXPORT_SYMBOL_GPL (smc_proto );
69105
70106static int smc_release (struct socket * sock )
71107{
@@ -109,6 +145,7 @@ static int smc_release(struct socket *sock)
109145 schedule_delayed_work (& smc -> sock_put_work ,
110146 SMC_CLOSE_SOCK_PUT_DELAY );
111147 }
148+ sk -> sk_prot -> unhash (sk );
112149 release_sock (sk );
113150
114151 sock_put (sk );
@@ -144,6 +181,7 @@ static struct sock *smc_sock_alloc(struct net *net, struct socket *sock)
144181 INIT_LIST_HEAD (& smc -> accept_q );
145182 spin_lock_init (& smc -> accept_q_lock );
146183 INIT_DELAYED_WORK (& smc -> sock_put_work , smc_close_sock_put_work );
184+ sk -> sk_prot -> hash (sk );
147185 sk_refcnt_debug_inc (sk );
148186
149187 return sk ;
@@ -536,6 +574,7 @@ static int smc_clcsock_accept(struct smc_sock *lsmc, struct smc_sock **new_smc)
536574 lsmc -> sk .sk_err = - rc ;
537575 new_sk -> sk_state = SMC_CLOSED ;
538576 sock_set_flag (new_sk , SOCK_DEAD );
577+ sk -> sk_prot -> unhash (new_sk );
539578 sock_put (new_sk );
540579 * new_smc = NULL ;
541580 goto out ;
@@ -545,6 +584,7 @@ static int smc_clcsock_accept(struct smc_sock *lsmc, struct smc_sock **new_smc)
545584 sock_release (new_clcsock );
546585 new_sk -> sk_state = SMC_CLOSED ;
547586 sock_set_flag (new_sk , SOCK_DEAD );
587+ sk -> sk_prot -> unhash (new_sk );
548588 sock_put (new_sk );
549589 * new_smc = NULL ;
550590 goto out ;
@@ -1320,6 +1360,7 @@ static int __init smc_init(void)
13201360 pr_err ("%s: sock_register fails with %d\n" , __func__ , rc );
13211361 goto out_proto ;
13221362 }
1363+ INIT_HLIST_HEAD (& smc_v4_hashinfo .ht );
13231364
13241365 rc = smc_ib_register_client ();
13251366 if (rc ) {
0 commit comments