@@ -519,37 +519,33 @@ static void lowcomms_error_report(struct sock *sk)
519519/* Note: sk_callback_lock must be locked before calling this function. */
520520static void save_callbacks (struct connection * con , struct sock * sk )
521521{
522- lock_sock (sk );
523522 con -> orig_data_ready = sk -> sk_data_ready ;
524523 con -> orig_state_change = sk -> sk_state_change ;
525524 con -> orig_write_space = sk -> sk_write_space ;
526525 con -> orig_error_report = sk -> sk_error_report ;
527- release_sock (sk );
528526}
529527
530528static void restore_callbacks (struct connection * con , struct sock * sk )
531529{
532530 write_lock_bh (& sk -> sk_callback_lock );
533- lock_sock (sk );
534531 sk -> sk_user_data = NULL ;
535532 sk -> sk_data_ready = con -> orig_data_ready ;
536533 sk -> sk_state_change = con -> orig_state_change ;
537534 sk -> sk_write_space = con -> orig_write_space ;
538535 sk -> sk_error_report = con -> orig_error_report ;
539- release_sock (sk );
540536 write_unlock_bh (& sk -> sk_callback_lock );
541537}
542538
543539/* Make a socket active */
544- static void add_sock (struct socket * sock , struct connection * con )
540+ static void add_sock (struct socket * sock , struct connection * con , bool save_cb )
545541{
546542 struct sock * sk = sock -> sk ;
547543
548544 write_lock_bh (& sk -> sk_callback_lock );
549545 con -> sock = sock ;
550546
551547 sk -> sk_user_data = con ;
552- if (! test_bit ( CF_IS_OTHERCON , & con -> flags ) )
548+ if (save_cb )
553549 save_callbacks (con , sk );
554550 /* Install a data_ready callback */
555551 sk -> sk_data_ready = lowcomms_data_ready ;
@@ -806,7 +802,7 @@ static int tcp_accept_from_sock(struct connection *con)
806802 newcon -> othercon = othercon ;
807803 othercon -> sock = newsock ;
808804 newsock -> sk -> sk_user_data = othercon ;
809- add_sock (newsock , othercon );
805+ add_sock (newsock , othercon , false );
810806 addcon = othercon ;
811807 }
812808 else {
@@ -819,7 +815,10 @@ static int tcp_accept_from_sock(struct connection *con)
819815 else {
820816 newsock -> sk -> sk_user_data = newcon ;
821817 newcon -> rx_action = receive_from_sock ;
822- add_sock (newsock , newcon );
818+ /* accept copies the sk after we've saved the callbacks, so we
819+ don't want to save them a second time or comm errors will
820+ result in calling sk_error_report recursively. */
821+ add_sock (newsock , newcon , false);
823822 addcon = newcon ;
824823 }
825824
@@ -880,7 +879,8 @@ static int sctp_accept_from_sock(struct connection *con)
880879 }
881880
882881 make_sockaddr (& prim .ssp_addr , 0 , & addr_len );
883- if (addr_to_nodeid (& prim .ssp_addr , & nodeid )) {
882+ ret = addr_to_nodeid (& prim .ssp_addr , & nodeid );
883+ if (ret ) {
884884 unsigned char * b = (unsigned char * )& prim .ssp_addr ;
885885
886886 log_print ("reject connect from unknown addr" );
@@ -919,7 +919,7 @@ static int sctp_accept_from_sock(struct connection *con)
919919 newcon -> othercon = othercon ;
920920 othercon -> sock = newsock ;
921921 newsock -> sk -> sk_user_data = othercon ;
922- add_sock (newsock , othercon );
922+ add_sock (newsock , othercon , false );
923923 addcon = othercon ;
924924 } else {
925925 printk ("Extra connection from node %d attempted\n" , nodeid );
@@ -930,7 +930,7 @@ static int sctp_accept_from_sock(struct connection *con)
930930 } else {
931931 newsock -> sk -> sk_user_data = newcon ;
932932 newcon -> rx_action = receive_from_sock ;
933- add_sock (newsock , newcon );
933+ add_sock (newsock , newcon , false );
934934 addcon = newcon ;
935935 }
936936
@@ -1058,7 +1058,7 @@ static void sctp_connect_to_sock(struct connection *con)
10581058 sock -> sk -> sk_user_data = con ;
10591059 con -> rx_action = receive_from_sock ;
10601060 con -> connect_action = sctp_connect_to_sock ;
1061- add_sock (sock , con );
1061+ add_sock (sock , con , true );
10621062
10631063 /* Bind to all addresses. */
10641064 if (sctp_bind_addrs (con , 0 ))
@@ -1146,7 +1146,7 @@ static void tcp_connect_to_sock(struct connection *con)
11461146 sock -> sk -> sk_user_data = con ;
11471147 con -> rx_action = receive_from_sock ;
11481148 con -> connect_action = tcp_connect_to_sock ;
1149- add_sock (sock , con );
1149+ add_sock (sock , con , true );
11501150
11511151 /* Bind to our cluster-known address connecting to avoid
11521152 routing problems */
@@ -1366,7 +1366,7 @@ static int tcp_listen_for_all(void)
13661366
13671367 sock = tcp_create_listen_sock (con , dlm_local_addr [0 ]);
13681368 if (sock ) {
1369- add_sock (sock , con );
1369+ add_sock (sock , con , true );
13701370 result = 0 ;
13711371 }
13721372 else {
0 commit comments