@@ -607,15 +607,56 @@ static void sctp_init_failed(void)
607607 mutex_unlock (& connections_lock );
608608}
609609
610+ static void retry_failed_sctp_send (struct connection * recv_con ,
611+ struct sctp_send_failed * sn_send_failed ,
612+ char * buf )
613+ {
614+ int len = sn_send_failed -> ssf_length - sizeof (struct sctp_send_failed );
615+ struct dlm_mhandle * mh ;
616+ struct connection * con ;
617+ char * retry_buf ;
618+ int nodeid = sn_send_failed -> ssf_info .sinfo_ppid ;
619+
620+ log_print ("Retry sending %d bytes to node id %d" , len , nodeid );
621+
622+ con = nodeid2con (nodeid , 0 );
623+ if (!con ) {
624+ log_print ("Could not look up con for nodeid %d\n" ,
625+ nodeid );
626+ return ;
627+ }
628+
629+ mh = dlm_lowcomms_get_buffer (nodeid , len , GFP_NOFS , & retry_buf );
630+ if (!mh ) {
631+ log_print ("Could not allocate buf for retry." );
632+ return ;
633+ }
634+ memcpy (retry_buf , buf + sizeof (struct sctp_send_failed ), len );
635+ dlm_lowcomms_commit_buffer (mh );
636+
637+ /*
638+ * If we got a assoc changed event before the send failed event then
639+ * we only need to retry the send.
640+ */
641+ if (con -> sctp_assoc ) {
642+ if (!test_and_set_bit (CF_WRITE_PENDING , & con -> flags ))
643+ queue_work (send_workqueue , & con -> swork );
644+ } else
645+ sctp_init_failed_foreach (con );
646+ }
647+
610648/* Something happened to an association */
611649static void process_sctp_notification (struct connection * con ,
612650 struct msghdr * msg , char * buf )
613651{
614652 union sctp_notification * sn = (union sctp_notification * )buf ;
615653
616- if (sn -> sn_header .sn_type == SCTP_ASSOC_CHANGE ) {
654+ switch (sn -> sn_header .sn_type ) {
655+ case SCTP_SEND_FAILED :
656+ retry_failed_sctp_send (con , & sn -> sn_send_failed , buf );
657+ break ;
658+ case SCTP_ASSOC_CHANGE :
617659 switch (sn -> sn_assoc_change .sac_state ) {
618-
619660 case SCTP_COMM_UP :
620661 case SCTP_RESTART :
621662 {
@@ -713,14 +754,10 @@ static void process_sctp_notification(struct connection *con,
713754 }
714755 break ;
715756
716- /* We don't know which INIT failed, so clear the PENDING flags
717- * on them all. if assoc_id is zero then it will then try
718- * again */
719-
720757 case SCTP_CANT_STR_ASSOC :
721758 {
759+ /* Will retry init when we get the send failed notification */
722760 log_print ("Can't start SCTP association - retrying" );
723- sctp_init_failed ();
724761 }
725762 break ;
726763
@@ -729,6 +766,8 @@ static void process_sctp_notification(struct connection *con,
729766 (int )sn -> sn_assoc_change .sac_assoc_id ,
730767 sn -> sn_assoc_change .sac_state );
731768 }
769+ default :
770+ ; /* fall through */
732771 }
733772}
734773
@@ -988,6 +1027,24 @@ static void free_entry(struct writequeue_entry *e)
9881027 kfree (e );
9891028}
9901029
1030+ /*
1031+ * writequeue_entry_complete - try to delete and free write queue entry
1032+ * @e: write queue entry to try to delete
1033+ * @completed: bytes completed
1034+ *
1035+ * writequeue_lock must be held.
1036+ */
1037+ static void writequeue_entry_complete (struct writequeue_entry * e , int completed )
1038+ {
1039+ e -> offset += completed ;
1040+ e -> len -= completed ;
1041+
1042+ if (e -> len == 0 && e -> users == 0 ) {
1043+ list_del (& e -> list );
1044+ free_entry (e );
1045+ }
1046+ }
1047+
9911048/* Initiate an SCTP association.
9921049 This is a special case of send_to_sock() in that we don't yet have a
9931050 peeled-off socket for this association, so we use the listening socket
@@ -1007,16 +1064,14 @@ static void sctp_init_assoc(struct connection *con)
10071064 int addrlen ;
10081065 struct kvec iov [1 ];
10091066
1067+ mutex_lock (& con -> sock_mutex );
10101068 if (test_and_set_bit (CF_INIT_PENDING , & con -> flags ))
1011- return ;
1012-
1013- if (con -> retries ++ > MAX_CONNECT_RETRIES )
1014- return ;
1069+ goto unlock ;
10151070
10161071 if (nodeid_to_addr (con -> nodeid , NULL , (struct sockaddr * )& rem_addr ,
10171072 con -> try_new_addr )) {
10181073 log_print ("no address for nodeid %d" , con -> nodeid );
1019- return ;
1074+ goto unlock ;
10201075 }
10211076 base_con = nodeid2con (0 , 0 );
10221077 BUG_ON (base_con == NULL );
@@ -1034,17 +1089,17 @@ static void sctp_init_assoc(struct connection *con)
10341089 if (list_empty (& con -> writequeue )) {
10351090 spin_unlock (& con -> writequeue_lock );
10361091 log_print ("writequeue empty for nodeid %d" , con -> nodeid );
1037- return ;
1092+ goto unlock ;
10381093 }
10391094
10401095 e = list_first_entry (& con -> writequeue , struct writequeue_entry , list );
10411096 len = e -> len ;
10421097 offset = e -> offset ;
1043- spin_unlock (& con -> writequeue_lock );
10441098
10451099 /* Send the first block off the write queue */
10461100 iov [0 ].iov_base = page_address (e -> page )+ offset ;
10471101 iov [0 ].iov_len = len ;
1102+ spin_unlock (& con -> writequeue_lock );
10481103
10491104 if (rem_addr .ss_family == AF_INET ) {
10501105 struct sockaddr_in * sin = (struct sockaddr_in * )& rem_addr ;
@@ -1060,7 +1115,7 @@ static void sctp_init_assoc(struct connection *con)
10601115 cmsg -> cmsg_len = CMSG_LEN (sizeof (struct sctp_sndrcvinfo ));
10611116 sinfo = CMSG_DATA (cmsg );
10621117 memset (sinfo , 0x00 , sizeof (struct sctp_sndrcvinfo ));
1063- sinfo -> sinfo_ppid = cpu_to_le32 (dlm_our_nodeid () );
1118+ sinfo -> sinfo_ppid = cpu_to_le32 (con -> nodeid );
10641119 outmessage .msg_controllen = cmsg -> cmsg_len ;
10651120 sinfo -> sinfo_flags |= SCTP_ADDR_OVER ;
10661121
@@ -1075,15 +1130,12 @@ static void sctp_init_assoc(struct connection *con)
10751130 }
10761131 else {
10771132 spin_lock (& con -> writequeue_lock );
1078- e -> offset += ret ;
1079- e -> len -= ret ;
1080-
1081- if (e -> len == 0 && e -> users == 0 ) {
1082- list_del (& e -> list );
1083- free_entry (e );
1084- }
1133+ writequeue_entry_complete (e , ret );
10851134 spin_unlock (& con -> writequeue_lock );
10861135 }
1136+
1137+ unlock :
1138+ mutex_unlock (& con -> sock_mutex );
10871139}
10881140
10891141/* Connect a new socket to its peer */
@@ -1533,13 +1585,7 @@ static void send_to_sock(struct connection *con)
15331585 }
15341586
15351587 spin_lock (& con -> writequeue_lock );
1536- e -> offset += ret ;
1537- e -> len -= ret ;
1538-
1539- if (e -> len == 0 && e -> users == 0 ) {
1540- list_del (& e -> list );
1541- free_entry (e );
1542- }
1588+ writequeue_entry_complete (e , ret );
15431589 }
15441590 spin_unlock (& con -> writequeue_lock );
15451591out :
0 commit comments