Skip to content

Commit 98e1b60

Browse files
Mike Christieteigland
authored andcommitted
dlm: try other IPs when sctp init assoc fails
Currently, if we cannot create a association to the first IP addr that is added to DLM, the SCTP init assoc code will just retry the same IP. This patch adds a simple failover schemes where we will try one of the addresses that was passed into DLM. Signed-off-by: Mike Christie <michaelc@cs.wisc.edu> Signed-off-by: David Teigland <teigland@redhat.com>
1 parent b390ca3 commit 98e1b60

1 file changed

Lines changed: 50 additions & 11 deletions

File tree

‎fs/dlm/lowcomms.c‎

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ struct connection {
126126
struct connection *othercon;
127127
struct work_struct rwork; /* Receive workqueue */
128128
struct work_struct swork; /* Send workqueue */
129+
bool try_new_addr;
129130
};
130131
#define sock2con(x) ((struct connection *)(x)->sk_user_data)
131132

@@ -144,6 +145,7 @@ struct dlm_node_addr {
144145
struct list_head list;
145146
int nodeid;
146147
int addr_count;
148+
int curr_addr_index;
147149
struct sockaddr_storage *addr[DLM_MAX_ADDR_COUNT];
148150
};
149151

@@ -310,7 +312,7 @@ static int addr_compare(struct sockaddr_storage *x, struct sockaddr_storage *y)
310312
}
311313

312314
static int nodeid_to_addr(int nodeid, struct sockaddr_storage *sas_out,
313-
struct sockaddr *sa_out)
315+
struct sockaddr *sa_out, bool try_new_addr)
314316
{
315317
struct sockaddr_storage sas;
316318
struct dlm_node_addr *na;
@@ -320,8 +322,16 @@ static int nodeid_to_addr(int nodeid, struct sockaddr_storage *sas_out,
320322

321323
spin_lock(&dlm_node_addrs_spin);
322324
na = find_node_addr(nodeid);
323-
if (na && na->addr_count)
324-
memcpy(&sas, na->addr[0], sizeof(struct sockaddr_storage));
325+
if (na && na->addr_count) {
326+
if (try_new_addr) {
327+
na->curr_addr_index++;
328+
if (na->curr_addr_index == na->addr_count)
329+
na->curr_addr_index = 0;
330+
}
331+
332+
memcpy(&sas, na->addr[na->curr_addr_index ],
333+
sizeof(struct sockaddr_storage));
334+
}
325335
spin_unlock(&dlm_node_addrs_spin);
326336

327337
if (!na)
@@ -353,19 +363,22 @@ static int addr_to_nodeid(struct sockaddr_storage *addr, int *nodeid)
353363
{
354364
struct dlm_node_addr *na;
355365
int rv = -EEXIST;
366+
int addr_i;
356367

357368
spin_lock(&dlm_node_addrs_spin);
358369
list_for_each_entry(na, &dlm_node_addrs, list) {
359370
if (!na->addr_count)
360371
continue;
361372

362-
if (!addr_compare(na->addr[0], addr))
363-
continue;
364-
365-
*nodeid = na->nodeid;
366-
rv = 0;
367-
break;
373+
for (addr_i = 0; addr_i < na->addr_count; addr_i++) {
374+
if (addr_compare(na->addr[addr_i], addr)) {
375+
*nodeid = na->nodeid;
376+
rv = 0;
377+
goto unlock;
378+
}
379+
}
368380
}
381+
unlock:
369382
spin_unlock(&dlm_node_addrs_spin);
370383
return rv;
371384
}
@@ -561,6 +574,21 @@ static void sctp_send_shutdown(sctp_assoc_t associd)
561574

562575
static void sctp_init_failed_foreach(struct connection *con)
563576
{
577+
578+
/*
579+
* Don't try to recover base con and handle race where the
580+
* other node's assoc init creates a assoc and we get that
581+
* notification, then we get a notification that our attempt
582+
* failed due. This happens when we are still trying the primary
583+
* address, but the other node has already tried secondary addrs
584+
* and found one that worked.
585+
*/
586+
if (!con->nodeid || con->sctp_assoc)
587+
return;
588+
589+
log_print("Retrying SCTP association init for node %d\n", con->nodeid);
590+
591+
con->try_new_addr = true;
564592
con->sctp_assoc = 0;
565593
if (test_and_clear_bit(CF_INIT_PENDING, &con->flags)) {
566594
if (!test_and_set_bit(CF_WRITE_PENDING, &con->flags))
@@ -663,6 +691,7 @@ static void process_sctp_notification(struct connection *con,
663691
nodeid, (int)sn->sn_assoc_change.sac_assoc_id);
664692

665693
new_con->sctp_assoc = sn->sn_assoc_change.sac_assoc_id;
694+
new_con->try_new_addr = false;
666695
/* Send any pending writes */
667696
clear_bit(CF_CONNECT_PENDING, &new_con->flags);
668697
clear_bit(CF_INIT_PENDING, &new_con->flags);
@@ -984,7 +1013,8 @@ static void sctp_init_assoc(struct connection *con)
9841013
if (con->retries++ > MAX_CONNECT_RETRIES)
9851014
return;
9861015

987-
if (nodeid_to_addr(con->nodeid, NULL, (struct sockaddr *)&rem_addr)) {
1016+
if (nodeid_to_addr(con->nodeid, NULL, (struct sockaddr *)&rem_addr,
1017+
con->try_new_addr)) {
9881018
log_print("no address for nodeid %d", con->nodeid);
9891019
return;
9901020
}
@@ -1016,6 +1046,14 @@ static void sctp_init_assoc(struct connection *con)
10161046
iov[0].iov_base = page_address(e->page)+offset;
10171047
iov[0].iov_len = len;
10181048

1049+
if (rem_addr.ss_family == AF_INET) {
1050+
struct sockaddr_in *sin = (struct sockaddr_in *)&rem_addr;
1051+
log_print("Trying to connect to %pI4", &sin->sin_addr.s_addr);
1052+
} else {
1053+
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&rem_addr;
1054+
log_print("Trying to connect to %pI6", &sin6->sin6_addr);
1055+
}
1056+
10191057
cmsg = CMSG_FIRSTHDR(&outmessage);
10201058
cmsg->cmsg_level = IPPROTO_SCTP;
10211059
cmsg->cmsg_type = SCTP_SNDRCV;
@@ -1024,6 +1062,7 @@ static void sctp_init_assoc(struct connection *con)
10241062
memset(sinfo, 0x00, sizeof(struct sctp_sndrcvinfo));
10251063
sinfo->sinfo_ppid = cpu_to_le32(dlm_our_nodeid());
10261064
outmessage.msg_controllen = cmsg->cmsg_len;
1065+
sinfo->sinfo_flags |= SCTP_ADDR_OVER;
10271066

10281067
ret = kernel_sendmsg(base_con->sock, &outmessage, iov, 1, len);
10291068
if (ret < 0) {
@@ -1076,7 +1115,7 @@ static void tcp_connect_to_sock(struct connection *con)
10761115
goto out_err;
10771116

10781117
memset(&saddr, 0, sizeof(saddr));
1079-
result = nodeid_to_addr(con->nodeid, &saddr, NULL);
1118+
result = nodeid_to_addr(con->nodeid, &saddr, NULL, false);
10801119
if (result < 0) {
10811120
log_print("no address for nodeid %d", con->nodeid);
10821121
goto out_err;

0 commit comments

Comments
 (0)