Skip to content

Commit 36b71a8

Browse files
committed
dlm: fix deadlock between dlm_send and dlm_controld
A deadlock sometimes occurs between dlm_controld closing a lowcomms connection through configfs and dlm_send looking up the address for a new connection in configfs. dlm_controld does a configfs rmdir which calls dlm_lowcomms_close which waits for dlm_send to cancel work on the workqueues. The dlm_send workqueue thread has called tcp_connect_to_sock which calls dlm_nodeid_to_addr which does a configfs lookup and blocks on a lock held by dlm_controld in the rmdir path. The solution here is to save the node addresses within the lowcomms code so that the lowcomms workqueue does not need to step through configfs to get a node address. dlm_controld: wait_for_completion+0x1d/0x20 __cancel_work_timer+0x1b3/0x1e0 cancel_work_sync+0x10/0x20 dlm_lowcomms_close+0x4c/0xb0 [dlm] drop_comm+0x22/0x60 [dlm] client_drop_item+0x26/0x50 [configfs] configfs_rmdir+0x180/0x230 [configfs] vfs_rmdir+0xbd/0xf0 do_rmdir+0x103/0x120 sys_rmdir+0x16/0x20 dlm_send: mutex_lock+0x2b/0x50 get_comm+0x34/0x140 [dlm] dlm_nodeid_to_addr+0x18/0xd0 [dlm] tcp_connect_to_sock+0xf4/0x2d0 [dlm] process_send_sockets+0x1d2/0x260 [dlm] worker_thread+0x170/0x2a0 Signed-off-by: David Teigland <teigland@redhat.com>
1 parent 42a579a commit 36b71a8

5 files changed

Lines changed: 200 additions & 90 deletions

File tree

‎fs/dlm/config.c‎

Lines changed: 15 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,7 @@ static ssize_t comm_local_write(struct dlm_comm *cm, const char *buf,
750750
static ssize_t comm_addr_write(struct dlm_comm *cm, const char *buf, size_t len)
751751
{
752752
struct sockaddr_storage *addr;
753+
int rv;
753754

754755
if (len != sizeof(struct sockaddr_storage))
755756
return -EINVAL;
@@ -762,6 +763,13 @@ static ssize_t comm_addr_write(struct dlm_comm *cm, const char *buf, size_t len)
762763
return -ENOMEM;
763764

764765
memcpy(addr, buf, len);
766+
767+
rv = dlm_lowcomms_addr(cm->nodeid, addr, len);
768+
if (rv) {
769+
kfree(addr);
770+
return rv;
771+
}
772+
765773
cm->addr[cm->addr_count++] = addr;
766774
return len;
767775
}
@@ -878,34 +886,7 @@ static void put_space(struct dlm_space *sp)
878886
config_item_put(&sp->group.cg_item);
879887
}
880888

881-
static int addr_compare(struct sockaddr_storage *x, struct sockaddr_storage *y)
882-
{
883-
switch (x->ss_family) {
884-
case AF_INET: {
885-
struct sockaddr_in *sinx = (struct sockaddr_in *)x;
886-
struct sockaddr_in *siny = (struct sockaddr_in *)y;
887-
if (sinx->sin_addr.s_addr != siny->sin_addr.s_addr)
888-
return 0;
889-
if (sinx->sin_port != siny->sin_port)
890-
return 0;
891-
break;
892-
}
893-
case AF_INET6: {
894-
struct sockaddr_in6 *sinx = (struct sockaddr_in6 *)x;
895-
struct sockaddr_in6 *siny = (struct sockaddr_in6 *)y;
896-
if (!ipv6_addr_equal(&sinx->sin6_addr, &siny->sin6_addr))
897-
return 0;
898-
if (sinx->sin6_port != siny->sin6_port)
899-
return 0;
900-
break;
901-
}
902-
default:
903-
return 0;
904-
}
905-
return 1;
906-
}
907-
908-
static struct dlm_comm *get_comm(int nodeid, struct sockaddr_storage *addr)
889+
static struct dlm_comm *get_comm(int nodeid)
909890
{
910891
struct config_item *i;
911892
struct dlm_comm *cm = NULL;
@@ -919,19 +900,11 @@ static struct dlm_comm *get_comm(int nodeid, struct sockaddr_storage *addr)
919900
list_for_each_entry(i, &comm_list->cg_children, ci_entry) {
920901
cm = config_item_to_comm(i);
921902

922-
if (nodeid) {
923-
if (cm->nodeid != nodeid)
924-
continue;
925-
found = 1;
926-
config_item_get(i);
927-
break;
928-
} else {
929-
if (!cm->addr_count || !addr_compare(cm->addr[0], addr))
930-
continue;
931-
found = 1;
932-
config_item_get(i);
933-
break;
934-
}
903+
if (cm->nodeid != nodeid)
904+
continue;
905+
found = 1;
906+
config_item_get(i);
907+
break;
935908
}
936909
mutex_unlock(&clusters_root.subsys.su_mutex);
937910

@@ -995,36 +968,14 @@ int dlm_config_nodes(char *lsname, struct dlm_config_node **nodes_out,
995968

996969
int dlm_comm_seq(int nodeid, uint32_t *seq)
997970
{
998-
struct dlm_comm *cm = get_comm(nodeid, NULL);
971+
struct dlm_comm *cm = get_comm(nodeid);
999972
if (!cm)
1000973
return -EEXIST;
1001974
*seq = cm->seq;
1002975
put_comm(cm);
1003976
return 0;
1004977
}
1005978

1006-
int dlm_nodeid_to_addr(int nodeid, struct sockaddr_storage *addr)
1007-
{
1008-
struct dlm_comm *cm = get_comm(nodeid, NULL);
1009-
if (!cm)
1010-
return -EEXIST;
1011-
if (!cm->addr_count)
1012-
return -ENOENT;
1013-
memcpy(addr, cm->addr[0], sizeof(*addr));
1014-
put_comm(cm);
1015-
return 0;
1016-
}
1017-
1018-
int dlm_addr_to_nodeid(struct sockaddr_storage *addr, int *nodeid)
1019-
{
1020-
struct dlm_comm *cm = get_comm(0, addr);
1021-
if (!cm)
1022-
return -EEXIST;
1023-
*nodeid = cm->nodeid;
1024-
put_comm(cm);
1025-
return 0;
1026-
}
1027-
1028979
int dlm_our_nodeid(void)
1029980
{
1030981
return local_comm ? local_comm->nodeid : 0;

‎fs/dlm/config.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ void dlm_config_exit(void);
4646
int dlm_config_nodes(char *lsname, struct dlm_config_node **nodes_out,
4747
int *count_out);
4848
int dlm_comm_seq(int nodeid, uint32_t *seq);
49-
int dlm_nodeid_to_addr(int nodeid, struct sockaddr_storage *addr);
50-
int dlm_addr_to_nodeid(struct sockaddr_storage *addr, int *nodeid);
5149
int dlm_our_nodeid(void);
5250
int dlm_our_addr(struct sockaddr_storage *addr, int num);
5351

0 commit comments

Comments
 (0)