Commit c51c9cd8 authored by Alexander Aring's avatar Alexander Aring Committed by David Teigland

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: default avatarAlexander Aring <aahringo@redhat.com>
Signed-off-by: default avatarDavid Teigland <teigland@redhat.com>
parent c3d88dfd
...@@ -165,7 +165,7 @@ static LIST_HEAD(dlm_node_addrs); ...@@ -165,7 +165,7 @@ static LIST_HEAD(dlm_node_addrs);
static DEFINE_SPINLOCK(dlm_node_addrs_spin); static DEFINE_SPINLOCK(dlm_node_addrs_spin);
static struct listen_connection listen_con; static struct listen_connection listen_con;
static struct sockaddr_storage *dlm_local_addr[DLM_MAX_ADDR_COUNT]; static struct sockaddr_storage dlm_local_addr[DLM_MAX_ADDR_COUNT];
static int dlm_local_count; static int dlm_local_count;
/* Work queues */ /* Work queues */
...@@ -383,7 +383,7 @@ static int nodeid_to_addr(int nodeid, struct sockaddr_storage *sas_out, ...@@ -383,7 +383,7 @@ static int nodeid_to_addr(int nodeid, struct sockaddr_storage *sas_out,
if (!sa_out) if (!sa_out)
return 0; return 0;
if (dlm_local_addr[0]->ss_family == AF_INET) { if (dlm_local_addr[0].ss_family == AF_INET) {
struct sockaddr_in *in4 = (struct sockaddr_in *) &sas; struct sockaddr_in *in4 = (struct sockaddr_in *) &sas;
struct sockaddr_in *ret4 = (struct sockaddr_in *) sa_out; struct sockaddr_in *ret4 = (struct sockaddr_in *) sa_out;
ret4->sin_addr.s_addr = in4->sin_addr.s_addr; ret4->sin_addr.s_addr = in4->sin_addr.s_addr;
...@@ -683,7 +683,7 @@ static void add_sock(struct socket *sock, struct connection *con) ...@@ -683,7 +683,7 @@ static void add_sock(struct socket *sock, struct connection *con)
static void make_sockaddr(struct sockaddr_storage *saddr, uint16_t port, static void make_sockaddr(struct sockaddr_storage *saddr, uint16_t port,
int *addr_len) int *addr_len)
{ {
saddr->ss_family = dlm_local_addr[0]->ss_family; saddr->ss_family = dlm_local_addr[0].ss_family;
if (saddr->ss_family == AF_INET) { if (saddr->ss_family == AF_INET) {
struct sockaddr_in *in4_addr = (struct sockaddr_in *)saddr; struct sockaddr_in *in4_addr = (struct sockaddr_in *)saddr;
in4_addr->sin_port = cpu_to_be16(port); in4_addr->sin_port = cpu_to_be16(port);
...@@ -1065,7 +1065,7 @@ static int sctp_bind_addrs(struct socket *sock, uint16_t port) ...@@ -1065,7 +1065,7 @@ static int sctp_bind_addrs(struct socket *sock, uint16_t port)
int i, addr_len, result = 0; int i, addr_len, result = 0;
for (i = 0; i < dlm_local_count; i++) { for (i = 0; i < dlm_local_count; i++) {
memcpy(&localaddr, dlm_local_addr[i], sizeof(localaddr)); memcpy(&localaddr, &dlm_local_addr[i], sizeof(localaddr));
make_sockaddr(&localaddr, port, &addr_len); make_sockaddr(&localaddr, port, &addr_len);
if (!i) if (!i)
...@@ -1085,7 +1085,7 @@ static int sctp_bind_addrs(struct socket *sock, uint16_t port) ...@@ -1085,7 +1085,7 @@ static int sctp_bind_addrs(struct socket *sock, uint16_t port)
/* Get local addresses */ /* Get local addresses */
static void init_local(void) static void init_local(void)
{ {
struct sockaddr_storage sas, *addr; struct sockaddr_storage sas;
int i; int i;
dlm_local_count = 0; dlm_local_count = 0;
...@@ -1093,21 +1093,10 @@ static void init_local(void) ...@@ -1093,21 +1093,10 @@ static void init_local(void)
if (dlm_our_addr(&sas, i)) if (dlm_our_addr(&sas, i))
break; break;
addr = kmemdup(&sas, sizeof(*addr), GFP_NOFS); memcpy(&dlm_local_addr[dlm_local_count++], &sas, sizeof(sas));
if (!addr)
break;
dlm_local_addr[dlm_local_count++] = addr;
} }
} }
static void deinit_local(void)
{
int i;
for (i = 0; i < dlm_local_count; i++)
kfree(dlm_local_addr[i]);
}
static struct writequeue_entry *new_writequeue_entry(struct connection *con) static struct writequeue_entry *new_writequeue_entry(struct connection *con)
{ {
struct writequeue_entry *entry; struct writequeue_entry *entry;
...@@ -1463,7 +1452,7 @@ static void dlm_connect(struct connection *con) ...@@ -1463,7 +1452,7 @@ static void dlm_connect(struct connection *con)
} }
/* Create a socket to communicate with */ /* Create a socket to communicate with */
result = sock_create_kern(&init_net, dlm_local_addr[0]->ss_family, result = sock_create_kern(&init_net, dlm_local_addr[0].ss_family,
SOCK_STREAM, dlm_proto_ops->proto, &sock); SOCK_STREAM, dlm_proto_ops->proto, &sock);
if (result < 0) if (result < 0)
goto socket_err; goto socket_err;
...@@ -1679,7 +1668,6 @@ void dlm_lowcomms_stop(void) ...@@ -1679,7 +1668,6 @@ void dlm_lowcomms_stop(void)
foreach_conn(free_conn); foreach_conn(free_conn);
srcu_read_unlock(&connections_srcu, idx); srcu_read_unlock(&connections_srcu, idx);
work_stop(); work_stop();
deinit_local();
dlm_proto_ops = NULL; dlm_proto_ops = NULL;
} }
...@@ -1696,7 +1684,7 @@ static int dlm_listen_for_all(void) ...@@ -1696,7 +1684,7 @@ static int dlm_listen_for_all(void)
if (result < 0) if (result < 0)
return result; return result;
result = sock_create_kern(&init_net, dlm_local_addr[0]->ss_family, result = sock_create_kern(&init_net, dlm_local_addr[0].ss_family,
SOCK_STREAM, dlm_proto_ops->proto, &sock); SOCK_STREAM, dlm_proto_ops->proto, &sock);
if (result < 0) { if (result < 0) {
log_print("Can't create comms socket: %d", result); log_print("Can't create comms socket: %d", result);
...@@ -1743,7 +1731,7 @@ static int dlm_tcp_bind(struct socket *sock) ...@@ -1743,7 +1731,7 @@ static int dlm_tcp_bind(struct socket *sock)
/* Bind to our cluster-known address connecting to avoid /* Bind to our cluster-known address connecting to avoid
* routing problems. * routing problems.
*/ */
memcpy(&src_addr, dlm_local_addr[0], sizeof(src_addr)); memcpy(&src_addr, &dlm_local_addr[0], sizeof(src_addr));
make_sockaddr(&src_addr, 0, &addr_len); make_sockaddr(&src_addr, 0, &addr_len);
result = sock->ops->bind(sock, (struct sockaddr *)&src_addr, result = sock->ops->bind(sock, (struct sockaddr *)&src_addr,
...@@ -1800,8 +1788,8 @@ static int dlm_tcp_listen_bind(struct socket *sock) ...@@ -1800,8 +1788,8 @@ static int dlm_tcp_listen_bind(struct socket *sock)
int addr_len; int addr_len;
/* Bind to our port */ /* Bind to our port */
make_sockaddr(dlm_local_addr[0], dlm_config.ci_tcp_port, &addr_len); make_sockaddr(&dlm_local_addr[0], dlm_config.ci_tcp_port, &addr_len);
return sock->ops->bind(sock, (struct sockaddr *)dlm_local_addr[0], return sock->ops->bind(sock, (struct sockaddr *)&dlm_local_addr[0],
addr_len); addr_len);
} }
...@@ -1891,7 +1879,7 @@ int dlm_lowcomms_start(void) ...@@ -1891,7 +1879,7 @@ int dlm_lowcomms_start(void)
error = work_start(); error = work_start();
if (error) if (error)
goto fail_local; goto fail;
/* Start listening */ /* Start listening */
switch (dlm_config.ci_protocol) { switch (dlm_config.ci_protocol) {
...@@ -1918,8 +1906,6 @@ int dlm_lowcomms_start(void) ...@@ -1918,8 +1906,6 @@ int dlm_lowcomms_start(void)
dlm_proto_ops = NULL; dlm_proto_ops = NULL;
fail_proto_ops: fail_proto_ops:
work_stop(); work_stop();
fail_local:
deinit_local();
fail: fail:
return error; return error;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment