fs: dlm: fix lowcomms_start error case
Alexander Aring
maintainerPATCH 1/6 fs: dlm: fix lowcomms_start error case
This patch fixes the error path handling in lowcomms_start(). We need to cleanup some static allocated data structure and cleanup possible workqueue if these have started.
--- fs/dlm/lowcomms.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
fs/dlm/lowcomms.c +12 -3
@@ -1803,10 +1803,15 @@ static void process_send_sockets(struct work_struct *work)static void work_stop (void ) { -if (recv_workqueue) +if (recv_workqueue) {destroy_workqueue (recv_workqueue); -if (send_workqueue) + recv_workqueue =NULL ; + } + +if (send_workqueue) {destroy_workqueue (send_workqueue); + send_workqueue =NULL ; + } }static int work_start (void )
@@ -1823,6 +1828,7 @@ static int work_start(void)if (!send_workqueue) {log_print ("can't start dlm_send" );destroy_workqueue (recv_workqueue); + recv_workqueue =NULL ;return -ENOMEM ; }
@@ -1960,7 +1966,7 @@ int dlm_lowcomms_start(void) error =work_start ();if (error) - goto fail; + goto fail_local; dlm_allow_conn =1 ;
@@ -1977,6 +1983,9 @@ int dlm_lowcomms_start(void) fail_unlisten: dlm_allow_conn =0 ;dlm_close_sock (&listen_con.sock); +work_stop (); +fail_local: +deinit_local (); fail:return error; }
Signature · 1 line
2.26.3
Alexander Aring
maintainerPATCH 2/6 fs: dlm: fix memory leak when fenced
I got some kmemleak report when a node was fenced. The user space tool dlm_controld will therefore run some rmdir() in dlm configfs which was triggering some memleaks. This patch stores the sps and cms attributes which stores some handling for subdirectories of the configfs cluster entry and free them if they get released as the parent directory gets freed.
unreferenced object 0xffff88810d9e3e00 (size 192):
comm "dlm_controld", pid 342, jiffies 4294698126 (age 55438.801s) hex dump (first 32 bytes):
00 00 00 00 00 00 00 00 73 70 61 63 65 73 00 00 ........spaces..
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace:
[<00000000db8b640b>] make_cluster+0x5d/0x360
[<000000006a571db4>] configfs_mkdir+0x274/0x730
[<00000000b094501c>] vfs_mkdir+0x27e/0x340
[<0000000058b0adaf>] do_mkdirat+0xff/0x1b0
[<00000000d1ffd156>] do_syscall_64+0x40/0x80
[<00000000ab1408c8>] entry_SYSCALL_64_after_hwframe+0x44/0xae
unreferenced object 0xffff88810d9e3a00 (size 192):
comm "dlm_controld", pid 342, jiffies 4294698126 (age 55438.801s)
hex dump (first 32 bytes):
00 00 00 00 00 00 00 00 63 6f 6d 6d 73 00 00 00 ........comms...
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace:
[<00000000a7ef6ad2>] make_cluster+0x82/0x360
[<000000006a571db4>] configfs_mkdir+0x274/0x730
[<00000000b094501c>] vfs_mkdir+0x27e/0x340
[<0000000058b0adaf>] do_mkdirat+0xff/0x1b0
[<00000000d1ffd156>] do_syscall_64+0x40/0x80
[<00000000ab1408c8>] entry_SYSCALL_64_after_hwframe+0x44/0xae--- fs/dlm/config.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fs/dlm/config.c +9 -0
@@ -80,6 +80,9 @@ struct dlm_cluster {unsigned int cl_new_rsb_count;unsigned int cl_recover_callbacks;char cl_cluster_name[DLM_LOCKSPACE_LEN ]; + +struct dlm_spaces *sps; +struct dlm_comms *cms; };static struct dlm_cluster *config_item_to_cluster (struct config_item *i)
@@ -410,6 +413,9 @@ static struct config_group *make_cluster(struct config_group *g,if (!cl || !sps || !cms) goto fail; + cl->sps = sps; + cl->cms = cms; +config_group_init_type_name (&cl->group, name, &cluster_type);config_group_init_type_name (&sps->ss_group,"spaces" , &spaces_type);config_group_init_type_name (&cms->cs_group,"comms" , &comms_type);
@@ -459,6 +465,9 @@ static void drop_cluster(struct config_group *g, struct config_item *i)static void release_cluster (struct config_item *i) {struct dlm_cluster *cl =config_item_to_cluster (i); + +kfree (cl->sps); +kfree (cl->cms);kfree (cl); }
Signature · 1 line
2.26.3
Alexander Aring
maintainerPATCH 3/6 fs: dlm: use alloc_ordered_workqueue
In reply to Alexander AringThe proper way to allocate ordered workqueues is to use alloc_ordered_workqueue() function. The current way implies an ordered workqueue which is also required by dlm.
--- fs/dlm/lowcomms.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
fs/dlm/lowcomms.c +2 -4
@@ -1816,15 +1816,13 @@ static void work_stop(void)static int work_start (void ) { - recv_workqueue =alloc_workqueue ("dlm_recv" , -WQ_UNBOUND |WQ_MEM_RECLAIM ,1 ); + recv_workqueue =alloc_ordered_workqueue ("dlm_recv" ,WQ_MEM_RECLAIM );if (!recv_workqueue) {log_print ("can't start dlm_recv" );return -ENOMEM ; } - send_workqueue =alloc_workqueue ("dlm_send" , -WQ_UNBOUND |WQ_MEM_RECLAIM ,1 ); + send_workqueue =alloc_ordered_workqueue ("dlm_send" ,WQ_MEM_RECLAIM );if (!send_workqueue) {log_print ("can't start dlm_send" );destroy_workqueue (recv_workqueue);
Signature · 1 line
2.26.3
Alexander Aring
maintainerPATCH 4/6 fs: dlm: move dlm allow conn
In reply to Alexander AringThis patch checks if possible allowing new connections is allowed before queueing the listen socket to accept new connections.
--- fs/dlm/lowcomms.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
fs/dlm/lowcomms.c +3 -4
@@ -471,6 +471,9 @@ static void lowcomms_data_ready(struct sock *sk)static void lowcomms_listen_data_ready (struct sock *sk) { +if (!dlm_allow_conn) +return ; +queue_work (recv_workqueue, &listen_con.rwork); }
@@ -969,10 +972,6 @@ static int accept_from_sock(struct listen_connection *con)struct connection *addcon;unsigned int mark; -if (!dlm_allow_conn) { -return -1 ; - } -if (!con->sock)return -ENOTCONN ;
Signature · 1 line
2.26.3
Alexander Aring
maintainerPATCH 5/6 fs: dlm: introduce proto values
In reply to Alexander AringCurrently the dlm protocol values are that TCP is 0 and everything else is SCTP. This makes it difficult to introduce possible other transport layers. The only one user space tool dlm_controld, which I am aware of, handles the protocol value 1 for SCTP. We change it now to handle SCTP as 1, this will break user space API but it will fix it so we can add possible other transport layers.
--- fs/dlm/config.c | 2 +- fs/dlm/config.h | 3 +++ fs/dlm/lowcomms.c | 23 +++++++++++++++++++---- 3 files changed, 23 insertions(+), 5 deletions(-)
fs/dlm/config.c +1 -1
@@ -952,7 +952,7 @@ int dlm_our_addr(struct sockaddr_storage *addr, int num)#define DEFAULT_SCAN_SECS 5#define DEFAULT_LOG_DEBUG 0#define DEFAULT_LOG_INFO 1 -#define DEFAULT_PROTOCOL 0 +#define DEFAULT_PROTOCOL DLM_PROTO_TCP#define DEFAULT_MARK 0#define DEFAULT_TIMEWARN_CS 500/* 5 sec = 500 centiseconds */ #define DEFAULT_WAITWARN_US 0
fs/dlm/config.h +3 -0
@@ -23,6 +23,9 @@ struct dlm_config_node {#define DLM_MAX_ADDR_COUNT 3 +#define DLM_PROTO_TCP 0 +#define DLM_PROTO_SCTP 1 +struct dlm_config_info {int ci_tcp_port;int ci_buffer_size;
fs/dlm/lowcomms.c +19 -4
@@ -208,12 +208,18 @@ static int dlm_con_init(struct connection *con, int nodeid)INIT_WORK (&con->rwork, process_recv_sockets);init_waitqueue_head (&con->shutdown_wait); -if (dlm_config.ci_protocol ==0 ) { +switch (dlm_config.ci_protocol) { +case DLM_PROTO_TCP : con->connect_action = tcp_connect_to_sock; con->shutdown_action = dlm_tcp_shutdown; con->eof_condition = tcp_eof_condition; - }else { +break ; +case DLM_PROTO_SCTP : con->connect_action = sctp_connect_to_sock; +break ; +default : +kfree (con->rx_buf); +return -EINVAL ; }return 0 ;
@@ -1968,10 +1974,19 @@ int dlm_lowcomms_start(void) dlm_allow_conn =1 ;/* Start listening */ -if (dlm_config.ci_protocol ==0 ) +switch (dlm_config.ci_protocol) { +case DLM_PROTO_TCP : error =tcp_listen_for_all (); -else +break ; +case DLM_PROTO_SCTP : error =sctp_listen_for_all (&listen_con); +break ; +default : +log_print ("Invalid protocol identifier %d set" , + dlm_config.ci_protocol); + error = -EINVAL ; +break ; + }if (error) goto fail_unlisten;
Signature · 1 line
2.26.3
Alexander Aring
maintainerPATCH 6/6 fs: dlm: rename socket and app buffer defines
In reply to Alexander AringThis patch renames DEFAULT_BUFFER_SIZE to DLM_MAX_SOCKET_BUFSIZE and LOWCOMMS_MAX_TX_BUFFER_LEN to DLM_MAX_APP_BUFSIZE as they are proper names to define what's behind those values. The DLM_MAX_SOCKET_BUFSIZE defines the maximum size of buffer which can be handled on socket layer, the DLM_MAX_APP_BUFSIZE defines the maximum size of buffer which can be handled by the DLM application layer.
--- fs/dlm/config.c | 4 ++-- fs/dlm/config.h | 2 +- fs/dlm/lockspace.c | 2 +- fs/dlm/lowcomms.c | 4 ++-- fs/dlm/lowcomms.h | 2 +- fs/dlm/member.c | 2 +- fs/dlm/midcomms.c | 4 ++-- fs/dlm/rcom.c | 6 +++--- 8 files changed, 13 insertions(+), 13 deletions(-)
fs/dlm/config.c +2 -2
@@ -208,7 +208,7 @@ static int dlm_check_zero(unsigned int x)static int dlm_check_buffer_size (unsigned int x) { -if (x <DEFAULT_BUFFER_SIZE ) +if (x <DLM_MAX_SOCKET_BUFSIZE )return -EINVAL ;return 0 ;
@@ -962,7 +962,7 @@ int dlm_our_addr(struct sockaddr_storage *addr, int num)struct dlm_config_info dlm_config = { .ci_tcp_port =DEFAULT_TCP_PORT , - .ci_buffer_size =DEFAULT_BUFFER_SIZE , + .ci_buffer_size =DLM_MAX_SOCKET_BUFSIZE , .ci_rsbtbl_size =DEFAULT_RSBTBL_SIZE , .ci_recover_timer =DEFAULT_RECOVER_TIMER , .ci_toss_secs =DEFAULT_TOSS_SECS ,
fs/dlm/config.h +1 -1
@@ -12,7 +12,7 @@ #ifndef __CONFIG_DOT_H__ #define __CONFIG_DOT_H__ -#define DEFAULT_BUFFER_SIZE 4096 +#define DLM_MAX_SOCKET_BUFSIZE 4096 struct dlm_config_node { int nodeid;
fs/dlm/lockspace.c +1 -1
@@ -572,7 +572,7 @@ static int new_lockspace(const char *name, const char *cluster,* not having out of bounds issues. However on sending side 3.2 * might send less. */ - ls->ls_recover_buf =kmalloc (DEFAULT_BUFFER_SIZE ,GFP_NOFS ); + ls->ls_recover_buf =kmalloc (DLM_MAX_SOCKET_BUFSIZE ,GFP_NOFS );if (!ls->ls_recover_buf) goto out_lkbidr;
fs/dlm/lowcomms.c +2 -2
@@ -1556,9 +1556,9 @@ struct dlm_msg *dlm_lowcomms_new_msg(int nodeid, int len, gfp_t allocation,struct dlm_msg *msg;int idx; -if (len >DEFAULT_BUFFER_SIZE || +if (len >DLM_MAX_SOCKET_BUFSIZE || len <sizeof (struct dlm_header )) { -BUILD_BUG_ON (PAGE_SIZE <DEFAULT_BUFFER_SIZE ); +BUILD_BUG_ON (PAGE_SIZE <DLM_MAX_SOCKET_BUFSIZE );log_print ("failed to allocate a buffer of size %d" , len);WARN_ON (1 );return NULL ;
fs/dlm/lowcomms.h +1 -1
@@ -15,7 +15,7 @@#include "dlm_internal.h" #define DLM_MIDCOMMS_OPT_LEN sizeof(struct dlm_opts) -#define LOWCOMMS_MAX_TX_BUFFER_LEN (DEFAULT_BUFFER_SIZE - \ +#define DLM_MAX_APP_BUFSIZE (DLM_MAX_SOCKET_BUFSIZE - \ DLM_MIDCOMMS_OPT_LEN)#define CONN_HASH_SIZE 32
fs/dlm/member.c +1 -1
@@ -271,7 +271,7 @@ int dlm_slots_assign(struct dlm_ls *ls, int *num_slots, int *slots_size,log_slots (ls, gen, num,NULL , array, array_size); - max_slots = (LOWCOMMS_MAX_TX_BUFFER_LEN -sizeof (struct dlm_rcom ) - + max_slots = (DLM_MAX_APP_BUFSIZE -sizeof (struct dlm_rcom ) -sizeof (struct rcom_config )) /sizeof (struct rcom_slot );if (num > max_slots) {
fs/dlm/midcomms.c +2 -2
@@ -865,7 +865,7 @@ int dlm_process_incoming_buffer(int nodeid, unsigned char *buf, int len)while (len >=sizeof (struct dlm_header )) { hd = (struct dlm_header *)ptr; -/* no message should be more than DEFAULT_BUFFER_SIZE or +/* no message should be more than DLM_MAX_SOCKET_BUFSIZE or * less than dlm_header size. * * Some messages does not have a 8 byte length boundary yet
@@ -877,7 +877,7 @@ int dlm_process_incoming_buffer(int nodeid, unsigned char *buf, int len)* the next major version bump. */ msglen =le16_to_cpu (hd->h_length); -if (msglen >DEFAULT_BUFFER_SIZE || +if (msglen >DLM_MAX_SOCKET_BUFSIZE || msglen <sizeof (struct dlm_header )) {log_print ("received invalid length header: %u from node %d, will abort message parsing" , msglen, nodeid);
fs/dlm/rcom.c +3 -3
@@ -202,7 +202,7 @@ int dlm_rcom_status(struct dlm_ls *ls, int nodeid, uint32_t status_flags)set_rcom_status (ls, (struct rcom_status *)rc->rc_buf, status_flags);allow_sync_reply (ls, &rc->rc_id); -memset (ls->ls_recover_buf,0 ,DEFAULT_BUFFER_SIZE ); +memset (ls->ls_recover_buf,0 ,DLM_MAX_SOCKET_BUFSIZE );send_rcom_stateless (ls, msg, rc);
@@ -325,7 +325,7 @@ int dlm_rcom_names(struct dlm_ls *ls, int nodeid, char *last_name, int last_len)memcpy (rc->rc_buf, last_name, last_len);allow_sync_reply (ls, &rc->rc_id); -memset (ls->ls_recover_buf,0 ,DEFAULT_BUFFER_SIZE ); +memset (ls->ls_recover_buf,0 ,DLM_MAX_SOCKET_BUFSIZE );send_rcom_stateless (ls, msg, rc);
@@ -345,7 +345,7 @@ static void receive_rcom_names(struct dlm_ls *ls, struct dlm_rcom *rc_in) nodeid = rc_in->rc_header.h_nodeid; inlen = rc_in->rc_header.h_length -sizeof (struct dlm_rcom ); - outlen =LOWCOMMS_MAX_TX_BUFFER_LEN -sizeof (struct dlm_rcom ); + outlen =DLM_MAX_APP_BUFSIZE -sizeof (struct dlm_rcom ); error =create_rcom_stateless (ls, nodeid,DLM_RCOM_NAMES_REPLY , outlen, &rc, &msg);
Signature · 1 line
2.26.3