Skip to content

Commit 0774dc7

Browse files
Christoph Hellwigdavem330
authored andcommitted
dlm: use the tcp version of accept_from_sock for sctp as well
The only difference between a few missing fixes applied to the SCTP one is that TCP uses ->getpeername to get the remote address, while SCTP uses kernel_getsockopt(.. SCTP_PRIMARY_ADDR). But given that getpeername is defined to return the primary address for sctp, there doesn't seem to be any reason for the different way of quering the peername, or all the code duplication. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 50ce4c0 commit 0774dc7

1 file changed

Lines changed: 3 additions & 120 deletions

File tree

‎fs/dlm/lowcomms.c‎

Lines changed: 3 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ static int receive_from_sock(struct connection *con)
724724
}
725725

726726
/* Listening socket is busy, accept a connection */
727-
static int tcp_accept_from_sock(struct connection *con)
727+
static int accept_from_sock(struct connection *con)
728728
{
729729
int result;
730730
struct sockaddr_storage peeraddr;
@@ -852,123 +852,6 @@ static int tcp_accept_from_sock(struct connection *con)
852852
return result;
853853
}
854854

855-
static int sctp_accept_from_sock(struct connection *con)
856-
{
857-
/* Check that the new node is in the lockspace */
858-
struct sctp_prim prim;
859-
int nodeid;
860-
int prim_len, ret;
861-
int addr_len;
862-
struct connection *newcon;
863-
struct connection *addcon;
864-
struct socket *newsock;
865-
866-
mutex_lock(&connections_lock);
867-
if (!dlm_allow_conn) {
868-
mutex_unlock(&connections_lock);
869-
return -1;
870-
}
871-
mutex_unlock(&connections_lock);
872-
873-
mutex_lock_nested(&con->sock_mutex, 0);
874-
875-
ret = kernel_accept(con->sock, &newsock, O_NONBLOCK);
876-
if (ret < 0)
877-
goto accept_err;
878-
879-
memset(&prim, 0, sizeof(struct sctp_prim));
880-
prim_len = sizeof(struct sctp_prim);
881-
882-
ret = kernel_getsockopt(newsock, IPPROTO_SCTP, SCTP_PRIMARY_ADDR,
883-
(char *)&prim, &prim_len);
884-
if (ret < 0) {
885-
log_print("getsockopt/sctp_primary_addr failed: %d", ret);
886-
goto accept_err;
887-
}
888-
889-
make_sockaddr(&prim.ssp_addr, 0, &addr_len);
890-
ret = addr_to_nodeid(&prim.ssp_addr, &nodeid);
891-
if (ret) {
892-
unsigned char *b = (unsigned char *)&prim.ssp_addr;
893-
894-
log_print("reject connect from unknown addr");
895-
print_hex_dump_bytes("ss: ", DUMP_PREFIX_NONE,
896-
b, sizeof(struct sockaddr_storage));
897-
goto accept_err;
898-
}
899-
900-
newcon = nodeid2con(nodeid, GFP_NOFS);
901-
if (!newcon) {
902-
ret = -ENOMEM;
903-
goto accept_err;
904-
}
905-
906-
mutex_lock_nested(&newcon->sock_mutex, 1);
907-
908-
if (newcon->sock) {
909-
struct connection *othercon = newcon->othercon;
910-
911-
if (!othercon) {
912-
othercon = kmem_cache_zalloc(con_cache, GFP_NOFS);
913-
if (!othercon) {
914-
log_print("failed to allocate incoming socket");
915-
mutex_unlock(&newcon->sock_mutex);
916-
ret = -ENOMEM;
917-
goto accept_err;
918-
}
919-
othercon->nodeid = nodeid;
920-
othercon->rx_action = receive_from_sock;
921-
mutex_init(&othercon->sock_mutex);
922-
INIT_LIST_HEAD(&othercon->writequeue);
923-
spin_lock_init(&othercon->writequeue_lock);
924-
INIT_WORK(&othercon->swork, process_send_sockets);
925-
INIT_WORK(&othercon->rwork, process_recv_sockets);
926-
set_bit(CF_IS_OTHERCON, &othercon->flags);
927-
}
928-
mutex_lock_nested(&othercon->sock_mutex, 2);
929-
if (!othercon->sock) {
930-
newcon->othercon = othercon;
931-
add_sock(newsock, othercon);
932-
addcon = othercon;
933-
mutex_unlock(&othercon->sock_mutex);
934-
} else {
935-
printk("Extra connection from node %d attempted\n", nodeid);
936-
ret = -EAGAIN;
937-
mutex_unlock(&othercon->sock_mutex);
938-
mutex_unlock(&newcon->sock_mutex);
939-
goto accept_err;
940-
}
941-
} else {
942-
newcon->rx_action = receive_from_sock;
943-
add_sock(newsock, newcon);
944-
addcon = newcon;
945-
}
946-
947-
log_print("connected to %d", nodeid);
948-
949-
mutex_unlock(&newcon->sock_mutex);
950-
951-
/*
952-
* Add it to the active queue in case we got data
953-
* between processing the accept adding the socket
954-
* to the read_sockets list
955-
*/
956-
if (!test_and_set_bit(CF_READ_PENDING, &addcon->flags))
957-
queue_work(recv_workqueue, &addcon->rwork);
958-
mutex_unlock(&con->sock_mutex);
959-
960-
return 0;
961-
962-
accept_err:
963-
mutex_unlock(&con->sock_mutex);
964-
if (newsock)
965-
sock_release(newsock);
966-
if (ret != -EAGAIN)
967-
log_print("error accepting connection from node: %d", ret);
968-
969-
return ret;
970-
}
971-
972855
static void free_entry(struct writequeue_entry *e)
973856
{
974857
__free_page(e->page);
@@ -1253,7 +1136,7 @@ static struct socket *tcp_create_listen_sock(struct connection *con,
12531136
write_lock_bh(&sock->sk->sk_callback_lock);
12541137
sock->sk->sk_user_data = con;
12551138
save_listen_callbacks(sock);
1256-
con->rx_action = tcp_accept_from_sock;
1139+
con->rx_action = accept_from_sock;
12571140
con->connect_action = tcp_connect_to_sock;
12581141
write_unlock_bh(&sock->sk->sk_callback_lock);
12591142

@@ -1340,7 +1223,7 @@ static int sctp_listen_for_all(void)
13401223
save_listen_callbacks(sock);
13411224
con->sock = sock;
13421225
con->sock->sk->sk_data_ready = lowcomms_data_ready;
1343-
con->rx_action = sctp_accept_from_sock;
1226+
con->rx_action = accept_from_sock;
13441227
con->connect_action = sctp_connect_to_sock;
13451228

13461229
write_unlock_bh(&sock->sk->sk_callback_lock);

0 commit comments

Comments
 (0)