Skip to content

Commit c51c9cd

Browse files
Alexander Aringteigland
authored andcommitted
fs: dlm: don't put dlm_local_addrs on heap
This patch removes to allocate the dlm_local_addr[] pointers on the heap. Instead we directly store the type of "struct sockaddr_storage". This removes function deinit_local() because it was freeing memory only. Signed-off-by: Alexander Aring <[email protected]> Signed-off-by: David Teigland <[email protected]>
1 parent c3d88df commit c51c9cd

File tree

1 file changed

+12
-26
lines changed

1 file changed

+12
-26
lines changed

fs/dlm/lowcomms.c

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ static LIST_HEAD(dlm_node_addrs);
165165
static DEFINE_SPINLOCK(dlm_node_addrs_spin);
166166

167167
static struct listen_connection listen_con;
168-
static struct sockaddr_storage *dlm_local_addr[DLM_MAX_ADDR_COUNT];
168+
static struct sockaddr_storage dlm_local_addr[DLM_MAX_ADDR_COUNT];
169169
static int dlm_local_count;
170170

171171
/* Work queues */
@@ -383,7 +383,7 @@ static int nodeid_to_addr(int nodeid, struct sockaddr_storage *sas_out,
383383
if (!sa_out)
384384
return 0;
385385

386-
if (dlm_local_addr[0]->ss_family == AF_INET) {
386+
if (dlm_local_addr[0].ss_family == AF_INET) {
387387
struct sockaddr_in *in4 = (struct sockaddr_in *) &sas;
388388
struct sockaddr_in *ret4 = (struct sockaddr_in *) sa_out;
389389
ret4->sin_addr.s_addr = in4->sin_addr.s_addr;
@@ -683,7 +683,7 @@ static void add_sock(struct socket *sock, struct connection *con)
683683
static void make_sockaddr(struct sockaddr_storage *saddr, uint16_t port,
684684
int *addr_len)
685685
{
686-
saddr->ss_family = dlm_local_addr[0]->ss_family;
686+
saddr->ss_family = dlm_local_addr[0].ss_family;
687687
if (saddr->ss_family == AF_INET) {
688688
struct sockaddr_in *in4_addr = (struct sockaddr_in *)saddr;
689689
in4_addr->sin_port = cpu_to_be16(port);
@@ -1065,7 +1065,7 @@ static int sctp_bind_addrs(struct socket *sock, uint16_t port)
10651065
int i, addr_len, result = 0;
10661066

10671067
for (i = 0; i < dlm_local_count; i++) {
1068-
memcpy(&localaddr, dlm_local_addr[i], sizeof(localaddr));
1068+
memcpy(&localaddr, &dlm_local_addr[i], sizeof(localaddr));
10691069
make_sockaddr(&localaddr, port, &addr_len);
10701070

10711071
if (!i)
@@ -1085,29 +1085,18 @@ static int sctp_bind_addrs(struct socket *sock, uint16_t port)
10851085
/* Get local addresses */
10861086
static void init_local(void)
10871087
{
1088-
struct sockaddr_storage sas, *addr;
1088+
struct sockaddr_storage sas;
10891089
int i;
10901090

10911091
dlm_local_count = 0;
10921092
for (i = 0; i < DLM_MAX_ADDR_COUNT; i++) {
10931093
if (dlm_our_addr(&sas, i))
10941094
break;
10951095

1096-
addr = kmemdup(&sas, sizeof(*addr), GFP_NOFS);
1097-
if (!addr)
1098-
break;
1099-
dlm_local_addr[dlm_local_count++] = addr;
1096+
memcpy(&dlm_local_addr[dlm_local_count++], &sas, sizeof(sas));
11001097
}
11011098
}
11021099

1103-
static void deinit_local(void)
1104-
{
1105-
int i;
1106-
1107-
for (i = 0; i < dlm_local_count; i++)
1108-
kfree(dlm_local_addr[i]);
1109-
}
1110-
11111100
static struct writequeue_entry *new_writequeue_entry(struct connection *con)
11121101
{
11131102
struct writequeue_entry *entry;
@@ -1463,7 +1452,7 @@ static void dlm_connect(struct connection *con)
14631452
}
14641453

14651454
/* Create a socket to communicate with */
1466-
result = sock_create_kern(&init_net, dlm_local_addr[0]->ss_family,
1455+
result = sock_create_kern(&init_net, dlm_local_addr[0].ss_family,
14671456
SOCK_STREAM, dlm_proto_ops->proto, &sock);
14681457
if (result < 0)
14691458
goto socket_err;
@@ -1679,7 +1668,6 @@ void dlm_lowcomms_stop(void)
16791668
foreach_conn(free_conn);
16801669
srcu_read_unlock(&connections_srcu, idx);
16811670
work_stop();
1682-
deinit_local();
16831671

16841672
dlm_proto_ops = NULL;
16851673
}
@@ -1696,7 +1684,7 @@ static int dlm_listen_for_all(void)
16961684
if (result < 0)
16971685
return result;
16981686

1699-
result = sock_create_kern(&init_net, dlm_local_addr[0]->ss_family,
1687+
result = sock_create_kern(&init_net, dlm_local_addr[0].ss_family,
17001688
SOCK_STREAM, dlm_proto_ops->proto, &sock);
17011689
if (result < 0) {
17021690
log_print("Can't create comms socket: %d", result);
@@ -1743,7 +1731,7 @@ static int dlm_tcp_bind(struct socket *sock)
17431731
/* Bind to our cluster-known address connecting to avoid
17441732
* routing problems.
17451733
*/
1746-
memcpy(&src_addr, dlm_local_addr[0], sizeof(src_addr));
1734+
memcpy(&src_addr, &dlm_local_addr[0], sizeof(src_addr));
17471735
make_sockaddr(&src_addr, 0, &addr_len);
17481736

17491737
result = sock->ops->bind(sock, (struct sockaddr *)&src_addr,
@@ -1800,8 +1788,8 @@ static int dlm_tcp_listen_bind(struct socket *sock)
18001788
int addr_len;
18011789

18021790
/* Bind to our port */
1803-
make_sockaddr(dlm_local_addr[0], dlm_config.ci_tcp_port, &addr_len);
1804-
return sock->ops->bind(sock, (struct sockaddr *)dlm_local_addr[0],
1791+
make_sockaddr(&dlm_local_addr[0], dlm_config.ci_tcp_port, &addr_len);
1792+
return sock->ops->bind(sock, (struct sockaddr *)&dlm_local_addr[0],
18051793
addr_len);
18061794
}
18071795

@@ -1891,7 +1879,7 @@ int dlm_lowcomms_start(void)
18911879

18921880
error = work_start();
18931881
if (error)
1894-
goto fail_local;
1882+
goto fail;
18951883

18961884
/* Start listening */
18971885
switch (dlm_config.ci_protocol) {
@@ -1918,8 +1906,6 @@ int dlm_lowcomms_start(void)
19181906
dlm_proto_ops = NULL;
19191907
fail_proto_ops:
19201908
work_stop();
1921-
fail_local:
1922-
deinit_local();
19231909
fail:
19241910
return error;
19251911
}

0 commit comments

Comments
 (0)