fs: dlm: introduce dlm re-transmission layer
Alexander Aring
maintainerv5 cover fs: dlm: introduce dlm re-transmission layer
Hi,
this is the final patch-series to make dlm reliable when re-connection occurs. You can easily generate a couple of re-connections by running:
tcpkill -9 -i $IFACE port 21064
on your own to test these patches. At some time dlm will detect message drops and will re-transmit messages if necessary. It introduces a new dlm protocol behaviour and increases the dlm protocol version. I tested it with SCTP as well and tried to be backwards compatible with dlm protocol version 3.1. However I don't recommend at all to mix these versions in a setup since dlm version 3.2 fixes long-term issues.
- Alex
changes since v5:
- huge change about how we handle the FIN handling, it does not now block at cluster membership removal. I think I got more information regarding to this issue. It's about ls->ls_nodes attribute and the function dlm_is_member(ls). So far the member is still in this list the DLM subsystem will send msgs to it. In a passive shutdown case we need to wait until this happens and close the connection after such event otherwise it could happen something like (note printout doesn't match to recent implementation):
[ 3341.497741] receive fin from passive shutdown from node 3, send_queue_cnt 0, flags 4 [ 3341.498667] send fin from passive shutdown case 1 to node 3 [ 3341.503333] ------------[ cut here ]------------ [ 3341.503971] WARNING: CPU: 1 PID: 455 at fs/dlm/midcomms.c:878 dlm_midcomms_get_mhandle+0x24b/0x260 ... [ 3341.523797] Call Trace: [ 3341.524110] _request_lock+0x305/0x500 [ 3341.524509] ? do_request+0xc0/0xc0 [ 3341.524922] ? create_lkb+0x1fa/0x2b0 [ 3341.525319] ? lock_downgrade+0x3d0/0x3d0 [ 3341.525679] request_lock.part.0+0x137/0x190 ... [ 3341.537588] gfs2_atomic_open+0x59/0x110
DLM will send requests message, so there is only one question that we cannot receive anything anymore but the requestqueue will handle this and change the handling of the messages in such cases so far I understood? In the above warning the fin message was sent before membership removal of ls->ls_nodes. This patch will take care that there are two cases for a send_fin event either if we receive fin and removal was already happened or delay the send_fin event when the removal happens (half-closed socket case) to still send out messages to the other peer. I think there is now a more higher risk to fail, because we wait for the cluster manager event of membership removal but it should happened.
Otherwise a lot of new state functionality copied from RFC 793 was added for the termination case. See midcomms comment for a nice state diagramm.
Good news is, I don't have any issues anymore with FIN handling and think this is the right approach.
- add debugfs
- add resend state
- fix that we was resend messages which wasn't committed
- add fix srcu patch
- add flush lowcomms workqueue
- add fix of tcp half-socket closing with workqueue handling
- ratelimit some print messages
- use dlm_mhandle and dlm_msg instead of void * as recommended by Guillaume
- remove #if 0 #endif handling to parse possible options
- add reconnect on error report patch, there is still a weird handling with the othercon paradigm but I cannot remove it without breaking backwards compatiblility.
changes since v4:
- remove fast retransmit and the timer, introduce logic to retransmit all unacknowledged message when doing reconnect. The receiver side will deliver the next fit sequence number then.
There might be still problems with that we don't trigger a reconnection again if we don't transmit anything (but still have something unacknowledged in midcomms). This is still an issue in lowcomms implementation which I want to fix in due courses.
- Change comments/commit msg how it works regarding to the new behaviour.
- Let the send_queue now have messages in order according to the seq this is necessary for the new behaviour that the receiver side can resolve drops by receiving unacknowledged messages in their order of delivery. If sequence .e.g. 1 3 2 is received then the receiver will not be able to resolve the drop because 3 will be dropped and not retransmitted again.
- change the dlm fin waiting mechanism to split the wait into fin ack received and fin message received. Also change the timeout handling a little bit there.
- add a missing flush send_queue in midcomms_close
- update patch 04 to not be irqsafe anymore
- fix use-after-free for dlm version 3.1 and recent nodes_srcu changes
I thought about to update patch 08 to drop all pending messages inside the write queue, because we retransmit all unacknowledged messages at reconnect anyway. However that makes a very bad behaviour on reconnects with DLM version 3.1 so I only drop half-transmitted page buffers to don't start the bytestream inside the middle of an DLM message which is terrible as well. It might send more duplicate messages at reconnect, but the receive should solve these duplicates.
I still have some problems with synchronization of membership with DLM_FIN. However I think my testcase is overkill and I have zero problems with any synchronization when not running tcpkill. It gets a lot of more worse when I don't have any synchronization and the "midcomms membership" and sequence numbers are out of sync with the "cluster manager membership". I think such synchronization need to be there but there might be more additional handling. (I hope non protocol changes needed).
changes since v3:
- add comment about why queues are unbound
- move rcu usage to version receive handler
changes since v2:
- make timer handling pending only if messages are on air, the sync isn't quite correct there but doesn't need to be precise
- use before() from tcp to check if seq is before other seq with respect of overflows
- change srcu handling to hold srcu in all places where nodes are referencing - we should not get a disadvantage of holding that lock. We should update also lowcomms regarding to that.
- add some WARN_ON() to check that nothing in send/recv is going anymore otherwise it's likely an issue.
- add more future work regarding to fencing of nodes if over cluster manager timeout/bad seq happens
- add note about missing length size check of tail payload (resource name length) regarding to the receive buffer
- remove some include which isn't necessary in recoverd.c
Thanks to Paolo Abeni and Guillaume Nault for their reviews and recommendations.
Alexander Aring (15):
fs: dlm: add dlm macros for ratelimit log
fs: dlm: fix srcu read lock usage
fs: dlm: set is othercon flag
fs: dlm: reconnect if socket error report occurs
fs: dlm: fix connection tcp EOF handling
fs: dlm: public header in out utility
fs: dlm: add more midcomms hooks
fs: dlm: make buffer handling per msg
fs: dlm: add functionality to re-transmit a message
fs: dlm: move out some hash functionality
fs: dlm: add union in dlm header for lockspace id
fs: dlm: add force flush of writequeue function
fs: dlm: add reliable connection if reconnect
fs: dlm: add midcomms debugfs functionality
fs: dlm: don't allow half transmitted messages
fs/dlm/config.c | 3 +- fs/dlm/debug_fs.c | 54 ++ fs/dlm/dlm_internal.h | 42 +- fs/dlm/lock.c | 16 +- fs/dlm/lockspace.c | 14 +- fs/dlm/lowcomms.c | 381 ++++++++++-- fs/dlm/lowcomms.h | 26 +- fs/dlm/member.c | 3 + fs/dlm/midcomms.c | 1340 ++++++++++++++++++++++++++++++++++++++++- fs/dlm/midcomms.h | 15 + fs/dlm/rcom.c | 113 ++-- fs/dlm/util.c | 10 +- fs/dlm/util.h | 2 + 13 files changed, 1867 insertions(+), 152 deletions(-)
Signature · 1 line
2.26.3
Alexander Aring
maintainerPATCH v5 1/15 fs: dlm: add dlm macros for ratelimit log
This patch add ratelimit macro to dlm subsystem and will set the connecting log message to ratelimit. In non blocking connecting cases it will print out this message a lot.
--- fs/dlm/dlm_internal.h | 2 ++ fs/dlm/lowcomms.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-)
fs/dlm/dlm_internal.h +2 -0
@@ -60,6 +60,8 @@ struct dlm_mhandle; #define log_print(fmt, args...) \ printk(KERN_ERR "dlm: "fmt"\n" , ##args) +#define log_print_ratelimited(fmt, args...) \ + printk_ratelimited(KERN_ERR "dlm: "fmt"\n", ##args) #define log_error(ls, fmt, args...) \ printk(KERN_ERR "dlm: %s: " fmt "\n", (ls)->ls_name , ##args)
fs/dlm/lowcomms.c +2 -2
@@ -1075,7 +1075,7 @@ static void sctp_connect_to_sock(struct connection *con)make_sockaddr (&daddr, dlm_config.ci_tcp_port, &addr_len); -log_print ("connecting to %d" , con->nodeid); +log_print_ratelimited ("connecting to %d" , con->nodeid);/* Turn off Nagle's algorithm */ sctp_sock_set_nodelay (sock->sk);
@@ -1171,7 +1171,7 @@ static void tcp_connect_to_sock(struct connection *con)make_sockaddr (&saddr, dlm_config.ci_tcp_port, &addr_len); -log_print ("connecting to %d" , con->nodeid); +log_print_ratelimited ("connecting to %d" , con->nodeid);/* Turn off Nagle's algorithm */ tcp_sock_set_nodelay (sock->sk);
Signature · 1 line
2.26.3
Alexander Aring
maintainerPATCH v5 2/15 fs: dlm: fix srcu read lock usage
In reply to Alexander AringThis patch holds the srcu connection read lock in cases where we lookup the connections and accessing it. We don't hold the srcu lock in workers function where the scheduled worker is part of the connection itself. The connection should not be freed if any worker is scheduled or pending.
--- fs/dlm/lowcomms.c | 75 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 23 deletions(-)
fs/dlm/lowcomms.c +52 -23
@@ -113,6 +113,7 @@ struct writequeue_entry {int len;int end;int users; +int idx;/* get()/commit() idx exchange */ struct connection *con; };
@@ -163,21 +164,14 @@ static inline int nodeid_hash(int nodeid)return nodeid & (CONN_HASH_SIZE -1 ); } -static struct connection *__find_con (int nodeid) +static struct connection *__find_con (int nodeid,int r) { -int r, idx;struct connection *con; - r =nodeid_hash (nodeid); - - idx =srcu_read_lock (&connections_srcu);hlist_for_each_entry_rcu (con, &connection_hash[r], list) { -if (con->nodeid == nodeid) { -srcu_read_unlock (&connections_srcu, idx); +if (con->nodeid == nodeid)return con; - } } -srcu_read_unlock (&connections_srcu, idx);return NULL ; }
@@ -216,7 +210,8 @@ static struct connection *nodeid2con(int nodeid, gfp_t alloc)struct connection *con, *tmp;int r, ret; - con =__find_con (nodeid); + r =nodeid_hash (nodeid); + con =__find_con (nodeid, r);if (con || !alloc)return con;
@@ -230,8 +225,6 @@ static struct connection *nodeid2con(int nodeid, gfp_t alloc)return NULL ; } - r =nodeid_hash (nodeid); -spin_lock (&connections_lock);/* Because multiple workqueues/threads calls this function it can * race on multiple cpu's. Instead of locking hot path __find_con()
@@ -239,7 +232,7 @@ static struct connection *nodeid2con(int nodeid, gfp_t alloc)* under protection of connections_lock. If this is the case we * abort our connection creation and return the existing connection. */ - tmp =__find_con (nodeid); + tmp =__find_con (nodeid, r);if (tmp) {spin_unlock (&connections_lock);kfree (con->rx_buf);
@@ -256,15 +249,13 @@ static struct connection *nodeid2con(int nodeid, gfp_t alloc)/* Loop round all connections */ static void foreach_conn (void (*conn_func)(struct connection *c)) { -int i, idx; +int i;struct connection *con; - idx =srcu_read_lock (&connections_srcu);for (i =0 ; i <CONN_HASH_SIZE ; i++) {hlist_for_each_entry_rcu (con, &connection_hash[i], list)conn_func (con); } -srcu_read_unlock (&connections_srcu, idx); }static struct dlm_node_addr *find_node_addr (int nodeid)
@@ -518,14 +509,21 @@ static void lowcomms_state_change(struct sock *sk)int dlm_lowcomms_connect_node (int nodeid) {struct connection *con; +int idx;if (nodeid ==dlm_our_nodeid ())return 0 ; + idx =srcu_read_lock (&connections_srcu); con =nodeid2con (nodeid,GFP_NOFS ); -if (!con) +if (!con) { +srcu_read_unlock (&connections_srcu, idx);return -ENOMEM ; + } +lowcomms_connect_sock (con); +srcu_read_unlock (&connections_srcu, idx); +return 0 ; }
@@ -864,7 +862,7 @@ static int accept_from_sock(struct listen_connection *con)int result;struct sockaddr_storage peeraddr;struct socket *newsock; -int len; +int len, idx;int nodeid;struct connection *newcon;struct connection *addcon;
@@ -907,8 +905,10 @@ static int accept_from_sock(struct listen_connection *con)* the same time and the connections cross on the wire. * In this case we store the incoming one in "othercon" */ + idx =srcu_read_lock (&connections_srcu); newcon =nodeid2con (nodeid,GFP_NOFS );if (!newcon) { +srcu_read_unlock (&connections_srcu, idx); result = -ENOMEM ; goto accept_err; }
@@ -924,6 +924,7 @@ static int accept_from_sock(struct listen_connection *con)if (!othercon) {log_print ("failed to allocate incoming socket" );mutex_unlock (&newcon->sock_mutex); +srcu_read_unlock (&connections_srcu, idx); result = -ENOMEM ; goto accept_err; }
@@ -932,6 +933,7 @@ static int accept_from_sock(struct listen_connection *con)if (result <0 ) {kfree (othercon);mutex_unlock (&newcon->sock_mutex); +srcu_read_unlock (&connections_srcu, idx); goto accept_err; }
@@ -966,6 +968,8 @@ static int accept_from_sock(struct listen_connection *con)if (!test_and_set_bit (CF_READ_PENDING , &addcon->flags))queue_work (recv_workqueue, &addcon->rwork); +srcu_read_unlock (&connections_srcu, idx); +return 0 ; accept_err:
@@ -1403,7 +1407,9 @@ static struct writequeue_entry *new_wq_entry(struct connection *con, int len,void *dlm_lowcomms_get_buffer (int nodeid,int len,gfp_t allocation,char **ppc) { +struct writequeue_entry *e;struct connection *con; +int idx;if (len >DEFAULT_BUFFER_SIZE || len <sizeof (struct dlm_header )) {
@@ -1413,11 +1419,23 @@ void *dlm_lowcomms_get_buffer(int nodeid, int len, gfp_t allocation, char **ppc)return NULL ; } + idx =srcu_read_lock (&connections_srcu); con =nodeid2con (nodeid, allocation); -if (!con) +if (!con) { +srcu_read_unlock (&connections_srcu, idx);return NULL ; + } + + e =new_wq_entry (con, len, allocation, ppc); +if (!e) { +srcu_read_unlock (&connections_srcu, idx); +return NULL ; + } + +/* we assume if successful commit must called */ + e->idx = idx; -return new_wq_entry (con, len, allocation, ppc); +return e; }void dlm_lowcomms_commit_buffer (void *mh)
@@ -1435,10 +1453,12 @@ void dlm_lowcomms_commit_buffer(void *mh)spin_unlock (&con->writequeue_lock);queue_work (send_workqueue, &con->swork); +srcu_read_unlock (&connections_srcu, e->idx);return ; out:spin_unlock (&con->writequeue_lock); +srcu_read_unlock (&connections_srcu, e->idx);return ; }
@@ -1532,8 +1552,10 @@ int dlm_lowcomms_close(int nodeid) {struct connection *con;struct dlm_node_addr *na; +int idx;log_print ("closing connection to node %d" , nodeid); + idx =srcu_read_lock (&connections_srcu); con =nodeid2con (nodeid,0 );if (con) {set_bit (CF_CLOSE , &con->flags);
@@ -1542,6 +1564,7 @@ int dlm_lowcomms_close(int nodeid)if (con->othercon)clean_one_writequeue (con->othercon); } +srcu_read_unlock (&connections_srcu, idx);spin_lock (&dlm_node_addrs_spin); na =find_node_addr (nodeid);
@@ -1621,6 +1644,8 @@ static void shutdown_conn(struct connection *con)void dlm_lowcomms_shutdown (void ) { +int idx; +/* Set all the flags to prevent any * socket activity. */
@@ -1633,7 +1658,9 @@ void dlm_lowcomms_shutdown(void)dlm_close_sock (&listen_con.sock); + idx =srcu_read_lock (&connections_srcu);foreach_conn (shutdown_conn); +srcu_read_unlock (&connections_srcu, idx); }static void _stop_conn (struct connection *con,bool and_other)
@@ -1682,7 +1709,7 @@ static void free_conn(struct connection *con)static void work_flush (void ) { -int ok, idx; +int ok;int i;struct connection *con;
@@ -1693,7 +1720,6 @@ static void work_flush(void)flush_workqueue (recv_workqueue);if (send_workqueue)flush_workqueue (send_workqueue); - idx =srcu_read_lock (&connections_srcu);for (i =0 ; i <CONN_HASH_SIZE && ok; i++) {hlist_for_each_entry_rcu (con, &connection_hash[i], list) {
@@ -1707,14 +1733,17 @@ static void work_flush(void) } } } -srcu_read_unlock (&connections_srcu, idx); }while (!ok); }void dlm_lowcomms_stop (void ) { +int idx; + + idx =srcu_read_lock (&connections_srcu);work_flush ();foreach_conn (free_conn); +srcu_read_unlock (&connections_srcu, idx);work_stop ();deinit_local (); }
Signature · 1 line
2.26.3
Alexander Aring
maintainerPATCH v5 3/15 fs: dlm: set is othercon flag
In reply to Alexander AringThere is a is othercon flag which is never used, this patch will set it and printout a warning if the othercon ever sends a dlm message which should never be the case.
--- fs/dlm/lowcomms.c | 3 +++ 1 file changed, 3 insertions(+)
fs/dlm/lowcomms.c +3 -0
@@ -938,6 +938,7 @@ static int accept_from_sock(struct listen_connection *con) }lockdep_set_subclass (&othercon->sock_mutex,1 ); +set_bit (CF_IS_OTHERCON , &othercon->flags); newcon->othercon = othercon; }else {/* close other sock con if we have something new */
@@ -1601,6 +1602,8 @@ static void process_send_sockets(struct work_struct *work) { struct connection *con = container_of(work, struct connection, swork); +WARN_ON (test_bit (CF_IS_OTHERCON , &con->flags)); +clear_bit (CF_WRITE_PENDING , &con->flags);if (con->sock ==NULL )/* not mutex protected so check it inside too */ con->connect_action (con);
Signature · 1 line
2.26.3
Alexander Aring
maintainerPATCH v5 4/15 fs: dlm: reconnect if socket error report occurs
In reply to Alexander AringThis patch will change the reconnect handling that if an error occurs if a socket error callback is occurred. This will also handle reconnects in a non blocking connecting case which is currently missing. If error ECONNREFUSED is reported we delay the reconnect by one second.
--- fs/dlm/lowcomms.c | 60 ++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 21 deletions(-)
fs/dlm/lowcomms.c +39 -21
@@ -79,6 +79,8 @@ struct connection {#define CF_CLOSING 8#define CF_SHUTDOWN 9#define CF_CONNECTED 10 +#define CF_RECONNECT 11 +#define CF_DELAY_CONNECT 12struct list_head writequeue;/* List of outgoing writequeue_entries */ spinlock_t writequeue_lock;void (*connect_action) (struct connection *);/* What to do to connect */
@@ -87,6 +89,7 @@ struct connection {#define MAX_CONNECT_RETRIES 3struct hlist_node list;struct connection *othercon; +struct connection *sendcon;struct work_struct rwork;/* Receive workqueue */ struct work_struct swork;/* Send workqueue */ wait_queue_head_t shutdown_wait;/* wait for graceful shutdown */
@@ -585,6 +588,22 @@ static void lowcomms_error_report(struct sock *sk) dlm_config.ci_tcp_port, sk->sk_err, sk->sk_err_soft); } + +/* below sendcon only handling */ +if (test_bit (CF_IS_OTHERCON , &con->flags)) + con = con->sendcon; + +switch (sk->sk_err) { +case ECONNREFUSED : +set_bit (CF_DELAY_CONNECT , &con->flags); +break ; +default : +break ; + } + +if (!test_and_set_bit (CF_RECONNECT , &con->flags)) +queue_work (send_workqueue, &con->swork); + out:read_unlock_bh (&sk->sk_callback_lock);if (orig_report)
@@ -702,6 +721,8 @@ static void close_connection(struct connection *con, bool and_other, con->rx_leftover =0 ; con->retries =0 ;clear_bit (CF_CONNECTED , &con->flags); +clear_bit (CF_DELAY_CONNECT , &con->flags); +clear_bit (CF_RECONNECT , &con->flags);mutex_unlock (&con->sock_mutex);clear_bit (CF_CLOSING , &con->flags); }
@@ -840,18 +861,15 @@ static int receive_from_sock(struct connection *con) out_close:mutex_unlock (&con->sock_mutex); -if (ret != -EAGAIN ) { -/* Reconnect when there is something to send */ +if (ret ==0 ) {close_connection (con, false, true, false); -if (ret ==0 ) { -log_print ("connection %p got EOF from %d" , - con, con->nodeid); -/* handling for tcp shutdown */ -clear_bit (CF_SHUTDOWN , &con->flags); -wake_up (&con->shutdown_wait); -/* signal to breaking receive worker */ - ret =-1 ; - } +log_print ("connection %p got EOF from %d" , + con, con->nodeid); +/* handling for tcp shutdown */ +clear_bit (CF_SHUTDOWN , &con->flags); +wake_up (&con->shutdown_wait); +/* signal to breaking receive worker */ + ret =-1 ; }return ret; }
@@ -940,6 +958,7 @@ static int accept_from_sock(struct listen_connection *con)lockdep_set_subclass (&othercon->sock_mutex,1 );set_bit (CF_IS_OTHERCON , &othercon->flags); newcon->othercon = othercon; + othercon->sendcon = newcon; }else {/* close other sock con if we have something new */ close_connection (othercon, false, true, false);
@@ -1504,7 +1523,7 @@ static void send_to_sock(struct connection *con)cond_resched (); goto out; }else if (ret <0 ) - goto send_error; + goto out; }/* Don't starve people filling buffers */
@@ -1521,14 +1540,6 @@ static void send_to_sock(struct connection *con)mutex_unlock (&con->sock_mutex);return ; -send_error: -mutex_unlock (&con->sock_mutex); -close_connection (con, false, false, true); -/* Requeue the send work. When the work daemon runs again, it will try -a new connection, then call this function again. */ -queue_work (send_workqueue, &con->swork); -return ; - out_connect:mutex_unlock (&con->sock_mutex);queue_work (send_workqueue, &con->swork);
@@ -1605,8 +1616,15 @@ static void process_send_sockets(struct work_struct *work)WARN_ON (test_bit (CF_IS_OTHERCON , &con->flags));clear_bit (CF_WRITE_PENDING , &con->flags); -if (con->sock ==NULL )/* not mutex protected so check it inside too */ + +if (test_and_clear_bit (CF_RECONNECT , &con->flags)) +close_connection (con, false, false, true); + +if (con->sock ==NULL ) {/* not mutex protected so check it inside too */ +if (test_and_clear_bit (CF_DELAY_CONNECT , &con->flags)) +msleep (1000 ); con->connect_action (con); + }if (!list_empty (&con->writequeue))send_to_sock (con); }
Signature · 1 line
2.26.3
Alexander Aring
maintainerPATCH v5 5/15 fs: dlm: fix connection tcp EOF handling
In reply to Alexander AringThis patch fixes the EOF handling for TCP that if and EOF is received we will close the socket next time the writequeue runs empty. This is a half-closed socket functionality which doesn't exists in SCTP. The midcomms layer will do a half closed socket functionality on DLM side to solve this problem for the SCTP case. However there is still the last ack flying around but other reset functionality will take care of it if it got lost.
--- fs/dlm/lowcomms.c | 48 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-)
fs/dlm/lowcomms.c +43 -5
@@ -81,10 +81,13 @@ struct connection {#define CF_CONNECTED 10#define CF_RECONNECT 11#define CF_DELAY_CONNECT 12 +#define CF_EOF 13struct list_head writequeue;/* List of outgoing writequeue_entries */ spinlock_t writequeue_lock; +atomic_t writequeue_cnt;void (*connect_action) (struct connection *);/* What to do to connect */ void (*shutdown_action)(struct connection *con);/* What to do to shutdown */ +bool (*eof_condition)(struct connection *con);/* What to do to eof check */ int retries;#define MAX_CONNECT_RETRIES 3struct hlist_node list;
@@ -179,6 +182,11 @@ static struct connection *__find_con(int nodeid, int r)return NULL ; } +static bool tcp_eof_condition (struct connection *con) +{ +return atomic_read (&con->writequeue_cnt); +} +static int dlm_con_init (struct connection *con,int nodeid) { con->rx_buflen = dlm_config.ci_buffer_size;
@@ -190,6 +198,7 @@ static int dlm_con_init(struct connection *con, int nodeid)mutex_init (&con->sock_mutex);INIT_LIST_HEAD (&con->writequeue);spin_lock_init (&con->writequeue_lock); +atomic_set (&con->writequeue_cnt,0 );INIT_WORK (&con->swork, process_send_sockets);INIT_WORK (&con->rwork, process_recv_sockets);init_waitqueue_head (&con->shutdown_wait);
@@ -197,6 +206,7 @@ static int dlm_con_init(struct connection *con, int nodeid)if (dlm_config.ci_protocol ==0 ) { con->connect_action = tcp_connect_to_sock; con->shutdown_action = dlm_tcp_shutdown; + con->eof_condition = tcp_eof_condition; }else { con->connect_action = sctp_connect_to_sock; }
@@ -723,6 +733,7 @@ static void close_connection(struct connection *con, bool and_other,clear_bit (CF_CONNECTED , &con->flags);clear_bit (CF_DELAY_CONNECT , &con->flags);clear_bit (CF_RECONNECT , &con->flags); +clear_bit (CF_EOF , &con->flags);mutex_unlock (&con->sock_mutex);clear_bit (CF_CLOSING , &con->flags); }
@@ -860,16 +871,26 @@ static int receive_from_sock(struct connection *con)return -EAGAIN ; out_close: -mutex_unlock (&con->sock_mutex);if (ret ==0 ) { -close_connection (con, false, true, false);log_print ("connection %p got EOF from %d" , con, con->nodeid); -/* handling for tcp shutdown */ -clear_bit (CF_SHUTDOWN , &con->flags); -wake_up (&con->shutdown_wait); + +if (con->eof_condition && con->eof_condition (con)) { +set_bit (CF_EOF , &con->flags); +mutex_unlock (&con->sock_mutex); + }else { +mutex_unlock (&con->sock_mutex); +close_connection (con, false, true, false); + +/* handling for tcp shutdown */ +clear_bit (CF_SHUTDOWN , &con->flags); +wake_up (&con->shutdown_wait); + } +/* signal to breaking receive worker */ ret =-1 ; + }else { +mutex_unlock (&con->sock_mutex); }return ret; }
@@ -1021,6 +1042,7 @@ static void writequeue_entry_complete(struct writequeue_entry *e, int completed)if (e->len ==0 && e->users ==0 ) {list_del (&e->list); +atomic_dec (&e->con->writequeue_cnt);free_entry (e); } }
@@ -1417,6 +1439,7 @@ static struct writequeue_entry *new_wq_entry(struct connection *con, int len, *ppc =page_address (e->page); e->end += len; +atomic_inc (&con->writequeue_cnt);spin_lock (&con->writequeue_lock);list_add_tail (&e->list, &con->writequeue);
@@ -1536,6 +1559,21 @@ static void send_to_sock(struct connection *con)writequeue_entry_complete (e, ret); }spin_unlock (&con->writequeue_lock); + +/* close if we got EOF */ +if (test_and_clear_bit (CF_EOF , &con->flags)) { +mutex_unlock (&con->sock_mutex); +close_connection (con, false, false, true); + +/* handling for tcp shutdown */ +clear_bit (CF_SHUTDOWN , &con->flags); +wake_up (&con->shutdown_wait); + }else { +mutex_unlock (&con->sock_mutex); + } + +return ; + out:mutex_unlock (&con->sock_mutex);return ;
Signature · 1 line
2.26.3
Alexander Aring
maintainerPATCH v5 6/15 fs: dlm: public header in out utility
In reply to Alexander AringThis patch allows to use header_out() and header_in() outside of dlm util functionality.
--- fs/dlm/util.c | 4 ++-- fs/dlm/util.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-)
fs/dlm/util.c +2 -2
@@ -20,7 +20,7 @@#define DLM_ERRNO_ETIMEDOUT 110#define DLM_ERRNO_EINPROGRESS 115 -static void header_out (struct dlm_header *hd) +void header_out (struct dlm_header *hd) { hd->h_version =cpu_to_le32 (hd->h_version); hd->h_lockspace =cpu_to_le32 (hd->h_lockspace);
@@ -28,7 +28,7 @@ static void header_out(struct dlm_header *hd) hd->h_length =cpu_to_le16 (hd->h_length); } -static void header_in (struct dlm_header *hd) +void header_in (struct dlm_header *hd) { hd->h_version =le32_to_cpu (hd->h_version); hd->h_lockspace =le32_to_cpu (hd->h_lockspace);
fs/dlm/util.h +2 -0
@@ -15,6 +15,8 @@ void dlm_message_out(struct dlm_message *ms);void dlm_message_in (struct dlm_message *ms);void dlm_rcom_out (struct dlm_rcom *rc);void dlm_rcom_in (struct dlm_rcom *rc); +void header_out (struct dlm_header *hd); +void header_in (struct dlm_header *hd);#endif
Signature · 1 line
2.26.3
Alexander Aring
maintainerPATCH v5 7/15 fs: dlm: add more midcomms hooks
In reply to Alexander AringThis patch prepares hooks to redirect to the midcomms layer which will be used by the midcomms re-transmit handling.
There exists the new concept of stateless buffers allocation and commits. This can be used to bypass the midcomms re-transmit handling. It is used by RCOM_STATUS and RCOM_NAMES messages, because they have their own ping-like re-transmit handling. As well these two messages will be used to determine the DLM version per node, because these two messages are per observation the first messages which are exchanged.
Cluster manager events for node membership are added to add support for half-closed connections in cases that the peer connection get to an end of file but DLM still holds membership of the node. In this time DLM can still trigger new message which we should allow. After the cluster manager node removal event occurs it safe to close the connection.
--- fs/dlm/config.c | 3 +- fs/dlm/lock.c | 8 ++-- fs/dlm/lockspace.c | 7 ++-- fs/dlm/member.c | 3 ++ fs/dlm/midcomms.c | 31 +++++++++++++- fs/dlm/midcomms.h | 8 ++++ fs/dlm/rcom.c | 101 +++++++++++++++++++++++++++++++-------------- 7 files changed, 122 insertions(+), 39 deletions(-)
fs/dlm/config.c +2 -1
@@ -20,6 +20,7 @@#include <net/sock.h> #include "config.h" +#include "midcomms.h" #include "lowcomms.h" /*
@@ -532,7 +533,7 @@ static void drop_comm(struct config_group *g, struct config_item *i)struct dlm_comm *cm =config_item_to_comm (i);if (local_comm == cm) local_comm =NULL ; -dlm_lowcomms_close (cm->nodeid); +dlm_midcomms_close (cm->nodeid);while (cm->addr_count--)kfree (cm->addr[cm->addr_count]);config_item_put (i);
fs/dlm/lock.c +4 -4
@@ -59,7 +59,7 @@#include "dlm_internal.h" #include <linux/dlm_device.h> #include "memory.h" -#include "lowcomms.h" +#include "midcomms.h" #include "requestqueue.h" #include "util.h" #include "dir.h"
@@ -3534,10 +3534,10 @@ static int _create_message(struct dlm_ls *ls, int mb_len,char *mb;/* get_buffer gives us a message handle (mh) that we need to -pass into lowcomms_commit and a message buffer (mb) that we +pass into midcomms_commit and a message buffer (mb) that we write our data into */ - mh =dlm_lowcomms_get_buffer (to_nodeid, mb_len,GFP_NOFS , &mb); + mh =dlm_midcomms_get_mhandle (to_nodeid, mb_len,GFP_NOFS , &mb);if (!mh)return -ENOBUFS ;
@@ -3589,7 +3589,7 @@ static int create_message(struct dlm_rsb *r, struct dlm_lkb *lkb,static int send_message (struct dlm_mhandle *mh,struct dlm_message *ms) {dlm_message_out (ms); -dlm_lowcomms_commit_buffer (mh); +dlm_midcomms_commit_mhandle (mh);return 0 ; }
fs/dlm/lockspace.c +4 -3
@@ -16,6 +16,7 @@#include "member.h" #include "recoverd.h" #include "dir.h" +#include "midcomms.h" #include "lowcomms.h" #include "config.h" #include "memory.h"
@@ -390,7 +391,7 @@ static int threads_start(void) }/* Thread for sending/receiving messages for all lockspace's */ - error =dlm_lowcomms_start (); + error =dlm_midcomms_start ();if (error) {log_print ("cannot start dlm lowcomms %d" , error); goto scand_fail;
@@ -698,7 +699,7 @@ int dlm_new_lockspace(const char *name, const char *cluster, error =0 ;if (!ls_count) {dlm_scand_stop (); -dlm_lowcomms_shutdown (); +dlm_midcomms_shutdown ();dlm_lowcomms_stop (); } out:
@@ -787,7 +788,7 @@ static int release_lockspace(struct dlm_ls *ls, int force)if (ls_count ==1 ) {dlm_scand_stop (); -dlm_lowcomms_shutdown (); +dlm_midcomms_shutdown (); }dlm_callback_stop (ls);
fs/dlm/member.c +3 -0
@@ -15,6 +15,7 @@#include "recover.h" #include "rcom.h" #include "config.h" +#include "midcomms.h" #include "lowcomms.h" int dlm_slots_version (struct dlm_header *h)
@@ -329,6 +330,7 @@ static int dlm_add_member(struct dlm_ls *ls, struct dlm_config_node *node) memb->nodeid = node->nodeid; memb->weight = node->weight; memb->comm_seq = node->comm_seq; +dlm_midcomms_add_member (node->nodeid);add_ordered_member (ls, memb); ls->ls_num_nodes++;return 0 ;
@@ -552,6 +554,7 @@ int dlm_recover_members(struct dlm_ls *ls, struct dlm_recover *rv, int *neg_out) neg++;list_move (&memb->list, &ls->ls_nodes_gone); +dlm_midcomms_remove_member (memb->nodeid); ls->ls_num_nodes--;dlm_lsop_recover_slot (ls, memb); }
fs/dlm/midcomms.c +30 -1
@@ -28,6 +28,36 @@#include "lock.h" #include "midcomms.h" +struct dlm_mhandle *dlm_midcomms_get_mhandle (int nodeid,int len, +gfp_t allocation,char **ppc) +{ +return dlm_lowcomms_get_buffer (nodeid, len, allocation, ppc); +} + +void dlm_midcomms_commit_mhandle (struct dlm_mhandle *mh) +{ +dlm_lowcomms_commit_buffer (mh); +} + +void dlm_midcomms_add_member (int nodeid) { } + +void dlm_midcomms_remove_member (int nodeid) { } + +int dlm_midcomms_start (void ) +{ +return dlm_lowcomms_start (); +} + +void dlm_midcomms_shutdown (void ) +{ +dlm_lowcomms_shutdown (); +} + +int dlm_midcomms_close (int nodeid) +{ +return dlm_lowcomms_close (nodeid); +} +/* * Called from the low-level comms layer to process a buffer of * commands.
@@ -101,4 +131,3 @@ int dlm_process_incoming_buffer(int nodeid, unsigned char *buf, int len)return ret; } -
fs/dlm/midcomms.h +8 -0
@@ -13,6 +13,14 @@#define __MIDCOMMS_DOT_H__int dlm_process_incoming_buffer (int nodeid,unsigned char *buf,int buflen); +struct dlm_mhandle *dlm_midcomms_get_mhandle (int nodeid,int len, +gfp_t allocation,char **ppc); +void dlm_midcomms_commit_mhandle (struct dlm_mhandle *mh); +int dlm_midcomms_close (int nodeid); +int dlm_midcomms_start (void ); +void dlm_midcomms_shutdown (void ); +void dlm_midcomms_add_member (int nodeid); +void dlm_midcomms_remove_member (int nodeid);#endif /* __MIDCOMMS_DOT_H__ */
fs/dlm/rcom.c +71 -30
212 lines not on this page · raw message
Signature · 1 line
2.26.3
Alexander Aring
maintainerPATCH v5 8/15 fs: dlm: make buffer handling per msg
In reply to Alexander AringThis patch makes the void pointer handle for lowcomms functionality per message and not per page allocation entry. A refcount handling for the handle was added to keep the message alive until the user doesn't need it anymore.
There exists now a per message callback which will be called when allocating a new buffer. This callback will be guaranteed to be called according the order of the sending buffer, which can be used that the caller increments a sequence number for the dlm message handle.
For transition process we cast the dlm_mhandle to dlm_msg and vice versa until the midcomms layer will implement a specific dlm_mhandle structure.
--- fs/dlm/dlm_internal.h | 1 + fs/dlm/lowcomms.c | 101 +++++++++++++++++++++++++++++++++++------- fs/dlm/lowcomms.h | 7 ++- fs/dlm/midcomms.c | 7 ++- fs/dlm/rcom.c | 40 +++++++++-------- 5 files changed, 117 insertions(+), 39 deletions(-)
fs/dlm/dlm_internal.h +1 -0
@@ -57,6 +57,7 @@ struct dlm_header;struct dlm_message ;struct dlm_rcom ;struct dlm_mhandle ; +struct dlm_msg ; #define log_print(fmt, args...) \ printk(KERN_ERR "dlm: "fmt"\n" , ##args)
fs/dlm/lowcomms.c +85 -16
203 lines not on this page · raw message
fs/dlm/lowcomms.h +5 -2
@@ -22,8 +22,11 @@ void dlm_lowcomms_shutdown(void);void dlm_lowcomms_stop (void );void dlm_lowcomms_exit (void );int dlm_lowcomms_close (int nodeid); -void *dlm_lowcomms_get_buffer (int nodeid,int len,gfp_t allocation,char **ppc); -void dlm_lowcomms_commit_buffer (void *mh); +struct dlm_msg *dlm_lowcomms_new_msg (int nodeid,int len,gfp_t allocation, +char **ppc,void (*cb)(struct dlm_mhandle *mh), +struct dlm_mhandle *mh); +void dlm_lowcomms_commit_msg (struct dlm_msg *msg); +void dlm_lowcomms_put_msg (struct dlm_msg *msg);int dlm_lowcomms_connect_node (int nodeid);int dlm_lowcomms_nodes_set_mark (int nodeid,unsigned int mark);int dlm_lowcomms_addr (int nodeid,struct sockaddr_storage *addr,int len);
fs/dlm/midcomms.c +5 -2
@@ -31,12 +31,15 @@struct dlm_mhandle *dlm_midcomms_get_mhandle (int nodeid,int len,gfp_t allocation,char **ppc) { -return dlm_lowcomms_get_buffer (nodeid, len, allocation, ppc); +return (struct dlm_mhandle *)dlm_lowcomms_new_msg (nodeid, len, + allocation, ppc, +NULL ,NULL ); }void dlm_midcomms_commit_mhandle (struct dlm_mhandle *mh) { -dlm_lowcomms_commit_buffer (mh); +dlm_lowcomms_commit_msg ((struct dlm_msg *)mh); +dlm_lowcomms_put_msg ((struct dlm_msg *)mh); }void dlm_midcomms_add_member (int nodeid) { }
fs/dlm/rcom.c +21 -19
@@ -70,21 +70,22 @@ static int create_rcom(struct dlm_ls *ls, int to_nodeid, int type, int len,static int create_rcom_stateless (struct dlm_ls *ls,int to_nodeid,int type,int len,struct dlm_rcom **rc_ret, -void **mh_ret) +struct dlm_msg **msg_ret) {int mb_len =sizeof (struct dlm_rcom ) + len; -void *mh; +struct dlm_msg *msg;char *mb; - mh =dlm_lowcomms_get_buffer (to_nodeid, mb_len,GFP_NOFS , &mb); -if (!mh) { + msg =dlm_lowcomms_new_msg (to_nodeid, mb_len,GFP_NOFS , &mb, +NULL ,NULL ); +if (!msg) {log_print ("create_rcom to %d type %d len %d ENOBUFS" , to_nodeid, type, len);return -ENOBUFS ; }_create_rcom (ls, to_nodeid, type, len, rc_ret, mb, mb_len); - *mh_ret = mh; + *msg_ret = msg;return 0 ; }
@@ -100,11 +101,12 @@ static void send_rcom(struct dlm_ls *ls, struct dlm_mhandle *mh,dlm_midcomms_commit_mhandle (mh); } -static void send_rcom_stateless (struct dlm_ls *ls,void *mh, +static void send_rcom_stateless (struct dlm_ls *ls,struct dlm_msg *msg,struct dlm_rcom *rc) {_send_rcom (ls, rc); -dlm_lowcomms_commit_buffer (mh); +dlm_lowcomms_commit_msg (msg); +dlm_lowcomms_put_msg (msg); } static void set_rcom_status(struct dlm_ls *ls, struct rcom_status *rs,
@@ -180,8 +182,8 @@ static void disallow_sync_reply(struct dlm_ls *ls)int dlm_rcom_status (struct dlm_ls *ls,int nodeid,uint32_t status_flags) {struct dlm_rcom *rc; +struct dlm_msg *msg;int error =0 ; -void *mh; ls->ls_recover_nodeid = nodeid;
@@ -193,7 +195,7 @@ int dlm_rcom_status(struct dlm_ls *ls, int nodeid, uint32_t status_flags) retry: error =create_rcom_stateless (ls, nodeid,DLM_RCOM_STATUS , -sizeof (struct rcom_status ), &rc, &mh); +sizeof (struct rcom_status ), &rc, &msg);if (error) goto out;
@@ -202,7 +204,7 @@ int dlm_rcom_status(struct dlm_ls *ls, int nodeid, uint32_t status_flags)allow_sync_reply (ls, &rc->rc_id);memset (ls->ls_recover_buf,0 ,LOWCOMMS_MAX_TX_BUFFER_LEN ); -send_rcom_stateless (ls, mh, rc); +send_rcom_stateless (ls, msg, rc); error =dlm_wait_function (ls, &rcom_response);disallow_sync_reply (ls);
@@ -234,9 +236,9 @@ static void receive_rcom_status(struct dlm_ls *ls, struct dlm_rcom *rc_in)uint32_t status;int nodeid = rc_in->rc_header.h_nodeid;int len =sizeof (struct rcom_config ); +struct dlm_msg *msg;int num_slots =0 ;int error; -void *mh;if (!dlm_slots_version (&rc_in->rc_header)) { status =dlm_recover_status (ls);
@@ -258,7 +260,7 @@ static void receive_rcom_status(struct dlm_ls *ls, struct dlm_rcom *rc_in) do_create: error =create_rcom_stateless (ls, nodeid,DLM_RCOM_STATUS_REPLY , - len, &rc, &mh); + len, &rc, &msg);if (error)return ;
@@ -285,7 +287,7 @@ static void receive_rcom_status(struct dlm_ls *ls, struct dlm_rcom *rc_in)spin_unlock (&ls->ls_recover_lock); do_send: -send_rcom_stateless (ls, mh, rc); +send_rcom_stateless (ls, msg, rc); }static void receive_sync_reply (struct dlm_ls *ls,struct dlm_rcom *rc_in)
@@ -310,14 +312,14 @@ static void receive_sync_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in)int dlm_rcom_names (struct dlm_ls *ls,int nodeid,char *last_name,int last_len) {struct dlm_rcom *rc; +struct dlm_msg *msg;int error =0 ; -void *mh; ls->ls_recover_nodeid = nodeid; retry: error =create_rcom_stateless (ls, nodeid,DLM_RCOM_NAMES , last_len, - &rc, &mh); + &rc, &msg);if (error) goto out;memcpy (rc->rc_buf, last_name, last_len);
@@ -325,7 +327,7 @@ int dlm_rcom_names(struct dlm_ls *ls, int nodeid, char *last_name, int last_len)allow_sync_reply (ls, &rc->rc_id);memset (ls->ls_recover_buf,0 ,LOWCOMMS_MAX_TX_BUFFER_LEN ); -send_rcom_stateless (ls, mh, rc); +send_rcom_stateless (ls, msg, rc); error =dlm_wait_function (ls, &rcom_response);disallow_sync_reply (ls);
@@ -339,14 +341,14 @@ static void receive_rcom_names(struct dlm_ls *ls, struct dlm_rcom *rc_in) {struct dlm_rcom *rc;int error, inlen, outlen, nodeid; -void *mh; +struct dlm_msg *msg; 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 ); error =create_rcom_stateless (ls, nodeid,DLM_RCOM_NAMES_REPLY , outlen, - &rc, &mh); + &rc, &msg);if (error)return ; rc->rc_id = rc_in->rc_id;
@@ -354,7 +356,7 @@ static void receive_rcom_names(struct dlm_ls *ls, struct dlm_rcom *rc_in)dlm_copy_master_names (ls, rc_in->rc_buf, inlen, rc->rc_buf, outlen, nodeid); -send_rcom_stateless (ls, mh, rc); +send_rcom_stateless (ls, msg, rc); }int dlm_send_rcom_lookup (struct dlm_rsb *r,int dir_nodeid)
Signature · 1 line
2.26.3
Alexander Aring
maintainerPATCH v5 9/15 fs: dlm: add functionality to re-transmit a message
In reply to Alexander AringThis patch introduces a retransmit functionality for a lowcomms message handle. It's just allocates a new buffer and transmit it again, no special handling about prioritize it because keeping bytestream in order.
To avoid another connection look some refactor was done to make a new buffer allocation with a preexisting connection pointer.
--- fs/dlm/lowcomms.c | 85 ++++++++++++++++++++++++++++++++++++----------- fs/dlm/lowcomms.h | 1 + 2 files changed, 67 insertions(+), 19 deletions(-)
fs/dlm/lowcomms.c +66 -19
@@ -126,6 +126,8 @@ struct writequeue_entry {struct dlm_msg {struct writequeue_entry *entry; +struct dlm_msg *orig_msg; +bool retransmit;void *ppc;int len;int idx;/* new()/commit() idx exchange */
@@ -1055,6 +1057,10 @@ static void free_entry(struct writequeue_entry *e)struct dlm_msg *msg, *tmp;list_for_each_entry_safe (msg, tmp, &e->msgs, list) { +if (msg->orig_msg) { + msg->orig_msg->retransmit = false; +kref_put (&msg->orig_msg->ref, dlm_msg_release); + }list_del (&msg->list);kref_put (&msg->ref, dlm_msg_release); }
@@ -1494,11 +1500,37 @@ static struct writequeue_entry *new_wq_entry(struct connection *con, int len,return e; }; +static struct dlm_msg *dlm_lowcomms_new_msg_con (struct connection *con,int len, +gfp_t allocation,char **ppc, +void (*cb)(struct dlm_mhandle *mh), +struct dlm_mhandle *mh) +{ +struct writequeue_entry *e; +struct dlm_msg *msg; + + msg =kzalloc (sizeof (*msg), allocation); +if (!msg) +return NULL ; + +kref_init (&msg->ref); + + e =new_wq_entry (con, len, allocation, ppc, cb, mh); +if (!e) { +kfree (msg); +return NULL ; + } + + msg->ppc = *ppc; + msg->len = len; + msg->entry = e; + +return msg; +} +struct dlm_msg *dlm_lowcomms_new_msg (int nodeid,int len,gfp_t allocation,char **ppc,void (*cb)(struct dlm_mhandle *mh),struct dlm_mhandle *mh) { -struct writequeue_entry *e;struct connection *con;struct dlm_msg *msg;int idx;
@@ -1518,32 +1550,18 @@ struct dlm_msg *dlm_lowcomms_new_msg(int nodeid, int len, gfp_t allocation,return NULL ; } - msg =kzalloc (sizeof (*msg), allocation); + msg =dlm_lowcomms_new_msg_con (con, len, allocation, ppc, cb, mh);if (!msg) {srcu_read_unlock (&connections_srcu, idx);return NULL ; } -kref_init (&msg->ref); - - e =new_wq_entry (con, len, allocation, ppc, cb, mh); -if (!e) { -srcu_read_unlock (&connections_srcu, idx); -kfree (msg); -return NULL ; - } - - msg->ppc = *ppc; - msg->len = len; - msg->entry = e; -/* we assume if successful commit must called */ msg->idx = idx; -return msg; } -void dlm_lowcomms_commit_msg (struct dlm_msg *msg) +static void _dlm_lowcomms_commit_msg (struct dlm_msg *msg) {struct writequeue_entry *e = msg->entry;struct connection *con = e->con;
@@ -1561,20 +1579,49 @@ void dlm_lowcomms_commit_msg(struct dlm_msg *msg)spin_unlock (&con->writequeue_lock);queue_work (send_workqueue, &con->swork); -srcu_read_unlock (&connections_srcu, msg->idx);return ; out:spin_unlock (&con->writequeue_lock); -srcu_read_unlock (&connections_srcu, msg->idx);return ; } +void dlm_lowcomms_commit_msg (struct dlm_msg *msg) +{ +_dlm_lowcomms_commit_msg (msg); +srcu_read_unlock (&connections_srcu, msg->idx); +} +void dlm_lowcomms_put_msg (struct dlm_msg *msg) {kref_put (&msg->ref, dlm_msg_release); } +/* does not held connections_srcu, usage workqueue only */ +int dlm_lowcomms_resend_msg (struct dlm_msg *msg) +{ +struct dlm_msg *msg_resend; +char *ppc; + +if (msg->retransmit) +return 1 ; + + msg_resend =dlm_lowcomms_new_msg_con (msg->entry->con, msg->len, +GFP_ATOMIC , &ppc,NULL ,NULL ); +if (!msg_resend) +return -ENOMEM ; + + msg->retransmit = true; +kref_get (&msg->ref); + msg_resend->orig_msg = msg; + +memcpy (ppc, msg->ppc, msg->len); +_dlm_lowcomms_commit_msg (msg_resend); +dlm_lowcomms_put_msg (msg_resend); + +return 0 ; +} +/* Send a message */ static void send_to_sock (struct connection *con) {
fs/dlm/lowcomms.h +1 -0
@@ -27,6 +27,7 @@ struct dlm_msg *dlm_lowcomms_new_msg(int nodeid, int len, gfp_t allocation, struct dlm_mhandle *mh);void dlm_lowcomms_commit_msg (struct dlm_msg *msg);void dlm_lowcomms_put_msg (struct dlm_msg *msg); +int dlm_lowcomms_resend_msg (struct dlm_msg *msg);int dlm_lowcomms_connect_node (int nodeid);int dlm_lowcomms_nodes_set_mark (int nodeid,unsigned int mark);int dlm_lowcomms_addr (int nodeid,struct sockaddr_storage *addr,int len);
Signature · 1 line
2.26.3
Alexander Aring
maintainerPATCH v5 10/15 fs: dlm: move out some hash functionality
In reply to Alexander AringThis patch moves out some lowcomms hash functionality into lowcomms header to provide them to other layers like midcomms as well.
--- fs/dlm/lowcomms.c | 9 --------- fs/dlm/lowcomms.h | 10 ++++++++++ 2 files changed, 10 insertions(+), 9 deletions(-)
fs/dlm/lowcomms.c +0 -9
@@ -59,7 +59,6 @@#include "config.h" #define NEEDED_RMEM (4*1024*1024) -#define CONN_HASH_SIZE 32/* Number of messages to send before rescheduling */ #define MAX_SEND_MSG_COUNT 25
@@ -175,14 +174,6 @@ static void sctp_connect_to_sock(struct connection *con);static void tcp_connect_to_sock (struct connection *con);static void dlm_tcp_shutdown (struct connection *con); -/* This is deliberately very simple because most clusters have simple -sequential nodeids, so we should be able to go straight to a connection -struct in the array */ -static inline int nodeid_hash (int nodeid) -{ -return nodeid & (CONN_HASH_SIZE -1 ); -} -static struct connection *__find_con (int nodeid,int r) {struct connection *con;
fs/dlm/lowcomms.h +10 -0
@@ -13,6 +13,16 @@#define __LOWCOMMS_DOT_H__#define LOWCOMMS_MAX_TX_BUFFER_LEN 4096 +#define CONN_HASH_SIZE 32 + +/* This is deliberately very simple because most clusters have simple +* sequential nodeids, so we should be able to go straight to a connection +* struct in the array +*/ +static inline int nodeid_hash (int nodeid) +{ +return nodeid & (CONN_HASH_SIZE -1 ); +}/* switch to check if dlm is running */ extern int dlm_allow_conn;
Signature · 1 line
2.26.3
Alexander Aring
maintainerPATCH v5 11/15 fs: dlm: add union in dlm header for lockspace id
In reply to Alexander AringThis patch adds union inside the lockspace id to handle it also for another use case for a different dlm command.
--- fs/dlm/dlm_internal.h | 5 ++++- fs/dlm/lock.c | 8 ++++---- fs/dlm/rcom.c | 4 ++-- fs/dlm/util.c | 6 ++++-- 4 files changed, 14 insertions(+), 9 deletions(-)
fs/dlm/dlm_internal.h +4 -1
@@ -380,7 +380,10 @@ static inline int rsb_flag(struct dlm_rsb *r, enum rsb_flags flag)struct dlm_header {uint32_t h_version; -uint32_t h_lockspace; +union { +/* for DLM_MSG and DLM_RCOM */ +uint32_t h_lockspace; + } u;uint32_t h_nodeid;/* nodeid of sender */ uint16_t h_length;uint8_t h_cmd;/* DLM_MSG, DLM_RCOM */
fs/dlm/lock.c +4 -4
@@ -3544,7 +3544,7 @@ static int _create_message(struct dlm_ls *ls, int mb_len, ms = (struct dlm_message *) mb; ms->m_header.h_version = (DLM_HEADER_MAJOR |DLM_HEADER_MINOR ); - ms->m_header.h_lockspace = ls->ls_global_id; + ms->m_header.u.h_lockspace = ls->ls_global_id; ms->m_header.h_nodeid =dlm_our_nodeid (); ms->m_header.h_length = mb_len; ms->m_header.h_cmd =DLM_MSG ;
@@ -5038,16 +5038,16 @@ void dlm_receive_buffer(union dlm_packet *p, int nodeid)if (hd->h_nodeid != nodeid) {log_print ("invalid h_nodeid %d from %d lockspace %x" , - hd->h_nodeid, nodeid, hd->h_lockspace); + hd->h_nodeid, nodeid, hd->u.h_lockspace);return ; } - ls =dlm_find_lockspace_global (hd->h_lockspace); + ls =dlm_find_lockspace_global (hd->u.h_lockspace);if (!ls) {if (dlm_config.ci_log_debug) {printk_ratelimited (KERN_DEBUG "dlm: invalid lockspace " "%u from %d cmd %d type %d\n" , - hd->h_lockspace, nodeid, hd->h_cmd, type); + hd->u.h_lockspace, nodeid, hd->h_cmd, type); }if (hd->h_cmd ==DLM_RCOM && type ==DLM_RCOM_STATUS )
fs/dlm/rcom.c +2 -2
@@ -35,7 +35,7 @@ static void _create_rcom(struct dlm_ls *ls, int to_nodeid, int type, int len, rc = (struct dlm_rcom *) mb; rc->rc_header.h_version = (DLM_HEADER_MAJOR |DLM_HEADER_MINOR ); - rc->rc_header.h_lockspace = ls->ls_global_id; + rc->rc_header.u.h_lockspace = ls->ls_global_id; rc->rc_header.h_nodeid =dlm_our_nodeid (); rc->rc_header.h_length = mb_len; rc->rc_header.h_cmd =DLM_RCOM ;
@@ -508,7 +508,7 @@ int dlm_send_ls_not_ready(int nodeid, struct dlm_rcom *rc_in) rc = (struct dlm_rcom *) mb; rc->rc_header.h_version = (DLM_HEADER_MAJOR |DLM_HEADER_MINOR ); - rc->rc_header.h_lockspace = rc_in->rc_header.h_lockspace; + rc->rc_header.u.h_lockspace = rc_in->rc_header.u.h_lockspace; rc->rc_header.h_nodeid =dlm_our_nodeid (); rc->rc_header.h_length = mb_len; rc->rc_header.h_cmd =DLM_RCOM ;
fs/dlm/util.c +4 -2
@@ -23,7 +23,8 @@void header_out (struct dlm_header *hd) { hd->h_version =cpu_to_le32 (hd->h_version); - hd->h_lockspace =cpu_to_le32 (hd->h_lockspace); +/* does it for others u32 in union as well */ + hd->u.h_lockspace =cpu_to_le32 (hd->u.h_lockspace); hd->h_nodeid =cpu_to_le32 (hd->h_nodeid); hd->h_length =cpu_to_le16 (hd->h_length); }
@@ -31,7 +32,8 @@ void header_out(struct dlm_header *hd)void header_in (struct dlm_header *hd) { hd->h_version =le32_to_cpu (hd->h_version); - hd->h_lockspace =le32_to_cpu (hd->h_lockspace); +/* does it for others u32 in union as well */ + hd->u.h_lockspace =le32_to_cpu (hd->u.h_lockspace); hd->h_nodeid =le32_to_cpu (hd->h_nodeid); hd->h_length =le16_to_cpu (hd->h_length); }
Signature · 1 line
2.26.3
Alexander Aring
maintainerPATCH v5 12/15 fs: dlm: add force flush of writequeue function
In reply to Alexander AringThis patch adds functionality that the user can force flush dlm messages in lowcomms writequeue in midcomms reset cases to flush all pending messages of lowcomms functionality.
--- fs/dlm/lowcomms.c | 27 +++++++++++++++++++++++++++ fs/dlm/lowcomms.h | 1 + 2 files changed, 28 insertions(+)
fs/dlm/lowcomms.c +27 -0
@@ -1703,6 +1703,33 @@ static void clean_one_writequeue(struct connection *con)spin_unlock (&con->writequeue_lock); } +int dlm_lowcomms_flush (int nodeid,bool cancel_rx) +{ +struct connection *con; +int idx; + +log_print ("flush writequeue of node %d" , nodeid); + idx =srcu_read_lock (&connections_srcu); + con =nodeid2con (nodeid,0 ); +if (con) { +cancel_work_sync (&con->swork); +if (cancel_rx) +cancel_work_sync (&con->rwork); + +clean_one_writequeue (con); +if (con->othercon) { +cancel_work_sync (&con->othercon->swork); +if (cancel_rx) +cancel_work_sync (&con->othercon->rwork); + +clean_one_writequeue (con->othercon); + } + } +srcu_read_unlock (&connections_srcu, idx); + +return 0 ; +} +/* Called from recovery when it knows that a node has left the cluster */ int dlm_lowcomms_close (int nodeid)
fs/dlm/lowcomms.h +1 -0
@@ -41,6 +41,7 @@ int dlm_lowcomms_resend_msg(struct dlm_msg *msg);int dlm_lowcomms_connect_node (int nodeid);int dlm_lowcomms_nodes_set_mark (int nodeid,unsigned int mark);int dlm_lowcomms_addr (int nodeid,struct sockaddr_storage *addr,int len); +int dlm_lowcomms_flush (int nodeid,bool cancel_rx);#endif /* __LOWCOMMS_DOT_H__ */
Signature · 1 line
2.26.3
Alexander Aring
maintainerPATCH v5 13/15 fs: dlm: add reliable connection if reconnect
In reply to Alexander AringThis patch introduce to make a tcp lowcomms connection reliable even if reconnects occurs. This is done by an application layer re-transmission handling and sequence numbers in dlm protocols. There are three new dlm commands:
DLM_OPTS:
This will encapsulate an existing dlm message (and rcom message if they don't have an own application side re-transmission handling). As optional handling additional tlv's (type length fields) can be appended. This can be for example a sequence number field. However because in DLM_OPTS the lockspace field is unused and a sequence number is a mandatory field it isn't made as a tlv and we put the sequence number inside the lockspace id. The possibility to add optional options are still there for future purposes.
DLM_ACK:
Just a dlm header to acknowledge the receive of a DLM_OPTS message to it's sender.
DLM_FIN:
This provides a 4 way handshake for connection termination inclusive support for half-closed connections. It's provided on application layer because SCTP doesn't support half-closed sockets, the shutdown() call can interrupted by e.g. TCP resets itself and a hard logic to implement it because the othercon paradigm in lowcomms. The 4-way termination handshake also solve problems to synchronize peer EOF arrival and that the cluster manager removes the peer in the node membership handling of DLM. In some cases messages can be still transmitted in this time and we need to wait for the node membership event.
To provide a reliable connection the node will retransmit all unacknowledges message to it's peer on reconnect. The receiver will then filtering out the next received message and drop all messages which are duplicates.
As RCOM_STATUS and RCOM_NAMES messages are the first messages which are exchanged and they have they own re-transmission handling, there exists logic that these messages must be first. If these messages arrives we store the dlm version field. This handling is on DLM 3.1 and after this patch 3.2 the same. A backwards compatibility handling has been added which seems to work on tests without tcpkill, however it's not recommended to use DLM 3.1 and 3.2 at the same time, because DLM 3.2 tries to fix long term bugs in the DLM protocol.
--- fs/dlm/dlm_internal.h | 30 +- fs/dlm/lockspace.c | 7 +- fs/dlm/lowcomms.c | 4 +- fs/dlm/lowcomms.h | 7 +- fs/dlm/midcomms.c | 1313 +++++++++++++++++++++++++++++++++++++++-- fs/dlm/midcomms.h | 1 + fs/dlm/rcom.c | 4 +- 7 files changed, 1315 insertions(+), 51 deletions(-)
fs/dlm/dlm_internal.h +28 -2
@@ -371,18 +371,26 @@ static inline int rsb_flag(struct dlm_rsb *r, enum rsb_flags flag)/* dlm_header is first element of all structs sent between nodes */ #define DLM_HEADER_MAJOR 0x00030000 -#define DLM_HEADER_MINOR 0x00000001 +#define DLM_HEADER_MINOR 0x00000002 + +#define DLM_VERSION_3_1 0x00030001 +#define DLM_VERSION_3_2 0x00030002#define DLM_HEADER_SLOTS 0x00000001#define DLM_MSG 1#define DLM_RCOM 2 +#define DLM_OPTS 3 +#define DLM_ACK 4 +#define DLM_FIN 5struct dlm_header {uint32_t h_version;union {/* for DLM_MSG and DLM_RCOM */ uint32_t h_lockspace; +/* for DLM_ACK and DLM_OPTS */ +uint32_t h_seq; } u;uint32_t h_nodeid;/* nodeid of sender */ uint16_t h_length;
@@ -390,7 +398,6 @@ struct dlm_header {uint8_t h_pad; }; -#define DLM_MSG_REQUEST 1#define DLM_MSG_CONVERT 2#define DLM_MSG_UNLOCK 3
@@ -458,10 +465,29 @@ struct dlm_rcom {char rc_buf[]; }; +struct dlm_opt_header { +uint16_t t_type; +uint16_t t_length; +uint32_t o_pad; +/* need to be 8 byte aligned */ +char t_value[]; +}; + +/* encapsulation header */ +struct dlm_opts { +struct dlm_header o_header; +uint8_t o_nextcmd; +uint8_t o_pad; +uint16_t o_optlen; +uint32_t o_pad2; +char o_opts[]; +}; +union dlm_packet {struct dlm_header header;/* common to other two */ struct dlm_message message;struct dlm_rcom rcom; +struct dlm_opts opts; };#define DLM_RSF_NEED_SLOTS 0x00000001
fs/dlm/lockspace.c +6 -1
@@ -567,7 +567,12 @@ static int new_lockspace(const char *name, const char *cluster,mutex_init (&ls->ls_requestqueue_mutex);mutex_init (&ls->ls_clear_proc_locks); - ls->ls_recover_buf =kmalloc (LOWCOMMS_MAX_TX_BUFFER_LEN ,GFP_NOFS ); +/* Due backwards compatibility with 3.1 we need to use maximum +* possible dlm message size to be sure the message will fit and +* 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 );if (!ls->ls_recover_buf) goto out_lkbidr;
fs/dlm/lowcomms.c +3 -1
@@ -1789,8 +1789,10 @@ static void process_send_sockets(struct work_struct *work)clear_bit (CF_WRITE_PENDING , &con->flags); -if (test_and_clear_bit (CF_RECONNECT , &con->flags)) +if (test_and_clear_bit (CF_RECONNECT , &con->flags)) {close_connection (con, false, false, true); +dlm_midcomms_unack_msg_resend (con->nodeid); + }if (con->sock ==NULL ) {/* not mutex protected so check it inside too */ if (test_and_clear_bit (CF_DELAY_CONNECT , &con->flags))
fs/dlm/lowcomms.h +6 -1
@@ -12,7 +12,12 @@#ifndef __LOWCOMMS_DOT_H__#define __LOWCOMMS_DOT_H__ -#define LOWCOMMS_MAX_TX_BUFFER_LEN 4096 +#include "dlm_internal.h" + +#define DLM_MIDCOMMS_OPT_LEN sizeof(struct dlm_opts) +#define LOWCOMMS_MAX_TX_BUFFER_LEN (DEFAULT_BUFFER_SIZE - \ + DLM_MIDCOMMS_OPT_LEN) +#define CONN_HASH_SIZE 32/* This is deliberately very simple because most clusters have simple
fs/dlm/midcomms.c +1269 -44
1,364 lines not on this page · raw message
fs/dlm/midcomms.h +1 -0
@@ -21,6 +21,7 @@ int dlm_midcomms_start(void);void dlm_midcomms_shutdown (void );void dlm_midcomms_add_member (int nodeid);void dlm_midcomms_remove_member (int nodeid); +void dlm_midcomms_unack_msg_resend (int nodeid);#endif /* __MIDCOMMS_DOT_H__ */
fs/dlm/rcom.c +2 -2
@@ -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 ,LOWCOMMS_MAX_TX_BUFFER_LEN ); +memset (ls->ls_recover_buf,0 ,DEFAULT_BUFFER_SIZE );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 ,LOWCOMMS_MAX_TX_BUFFER_LEN ); +memset (ls->ls_recover_buf,0 ,DEFAULT_BUFFER_SIZE );send_rcom_stateless (ls, msg, rc);
Signature · 1 line
2.26.3
Alexander Aring
maintainerPATCH v5 14/15 fs: dlm: add midcomms debugfs functionality
In reply to Alexander AringThis patch adds functionality to debug midcomms per connection state inside a comms directory which is similar like dlm configfs. Currently there exists the possibility to read out two attributes which is the send queue counter and the version of each midcomms node state.
--- fs/dlm/debug_fs.c | 54 +++++++++++++++++++++++++++++++++++++++++++ fs/dlm/dlm_internal.h | 4 ++++ fs/dlm/midcomms.c | 27 ++++++++++++++++++++++ fs/dlm/midcomms.h | 6 +++++ 4 files changed, 91 insertions(+)
fs/dlm/debug_fs.c +54 -0
@@ -16,6 +16,7 @@#include <linux/slab.h> #include "dlm_internal.h" +#include "midcomms.h" #include "lock.h" #define DLM_DEBUG_BUF_LEN 4096
@@ -23,6 +24,7 @@ static char debug_buf[DLM_DEBUG_BUF_LEN];static struct mutex debug_buf_lock;static struct dentry *dlm_root; +static struct dentry *dlm_comms;static char *print_lockmode (int mode) {
@@ -738,6 +740,57 @@ void dlm_delete_debug_file(struct dlm_ls *ls)debugfs_remove (ls->ls_debug_toss_dentry); } +static int dlm_state_show (struct seq_file *file,void *offset) +{ +seq_printf (file,"%s\n" ,dlm_midcomms_state (file->private)); +return 0 ; +} +DEFINE_SHOW_ATTRIBUTE (dlm_state); + +static int dlm_flags_show (struct seq_file *file,void *offset) +{ +seq_printf (file,"%lu\n" ,dlm_midcomms_flags (file->private)); +return 0 ; +} +DEFINE_SHOW_ATTRIBUTE (dlm_flags); + +static int dlm_send_queue_cnt_show (struct seq_file *file,void *offset) +{ +seq_printf (file,"%d\n" ,dlm_midcomms_send_queue_cnt (file->private)); +return 0 ; +} +DEFINE_SHOW_ATTRIBUTE (dlm_send_queue_cnt); + +static int dlm_version_show (struct seq_file *file,void *offset) +{ +seq_printf (file,"0x%08x\n" ,dlm_midcomms_version (file->private)); +return 0 ; +} +DEFINE_SHOW_ATTRIBUTE (dlm_version); + +void *dlm_create_debug_comms_file (int nodeid,void *data) +{ +struct dentry *d_node; +char name[256 ]; + +memset (name,0 ,sizeof (name)); +snprintf (name,256 ,"%d" , nodeid); + + d_node =debugfs_create_dir (name, dlm_comms); +debugfs_create_file ("state" ,0444 , d_node, data, &dlm_state_fops); +debugfs_create_file ("flags" ,0444 , d_node, data, &dlm_flags_fops); +debugfs_create_file ("send_queue_count" ,0444 , d_node, data, + &dlm_send_queue_cnt_fops); +debugfs_create_file ("version" ,0444 , d_node, data, &dlm_version_fops); + +return d_node; +} + +void dlm_delete_debug_comms_file (void *ctx) +{ +debugfs_remove (ctx); +} +void dlm_create_debug_file (struct dlm_ls *ls) {char name[DLM_LOCKSPACE_LEN +8 ];
@@ -797,6 +850,7 @@ void __init dlm_register_debugfs(void) {mutex_init (&debug_buf_lock); dlm_root =debugfs_create_dir ("dlm" ,NULL ); + dlm_comms =debugfs_create_dir ("comms" , dlm_root); }void dlm_unregister_debugfs (void )
fs/dlm/dlm_internal.h +4 -0
@@ -754,11 +754,15 @@ void dlm_register_debugfs(void);void dlm_unregister_debugfs (void );void dlm_create_debug_file (struct dlm_ls *ls);void dlm_delete_debug_file (struct dlm_ls *ls); +void *dlm_create_debug_comms_file (int nodeid,void *data); +void dlm_delete_debug_comms_file (void *ctx);#else static inline void dlm_register_debugfs (void ) { }static inline void dlm_unregister_debugfs (void ) { }static inline void dlm_create_debug_file (struct dlm_ls *ls) { }static inline void dlm_delete_debug_file (struct dlm_ls *ls) { } +static inline void *dlm_create_debug_comms_file (int nodeid,void *data) {return NULL ; } +static inline void dlm_delete_debug_comms_file (void *ctx) { }#endif #endif /* __DLM_INTERNAL_DOT_H__ */
fs/dlm/midcomms.c +27 -0
@@ -190,6 +190,9 @@ struct midcomms_node {*/ int users; +/* not protected by srcu, node_hash lifetime */ +void *debugfs; +struct hlist_node hlist;struct rcu_head rcu; };
@@ -245,6 +248,26 @@ static inline const char *dlm_state_str(int state) } } +const char *dlm_midcomms_state (struct midcomms_node *node) +{ +return dlm_state_str (node->state); +} + +unsigned long dlm_midcomms_flags (struct midcomms_node *node) +{ +return node->flags; +} + +int dlm_midcomms_send_queue_cnt (struct midcomms_node *node) +{ +return atomic_read (&node->send_queue_cnt); +} + +uint32_t dlm_midcomms_version (struct midcomms_node *node) +{ +return node->version; +} +static struct midcomms_node *__find_node (int nodeid,int r) {struct midcomms_node *node;
@@ -306,6 +329,8 @@ static struct midcomms_node *nodeid2node(int nodeid, gfp_t alloc)hlist_add_head_rcu (&node->hlist, &node_hash[r]);spin_unlock (&nodes_lock); + + node->debugfs =dlm_create_debug_comms_file (nodeid, node);return node; }
@@ -1307,6 +1332,8 @@ void dlm_midcomms_shutdown(void)hlist_for_each_entry_rcu (node, &node_hash[i], hlist) {midcomms_shutdown (node); +dlm_delete_debug_comms_file (node->debugfs); +spin_lock (&nodes_lock);hlist_del_rcu (&node->hlist);spin_unlock (&nodes_lock);
fs/dlm/midcomms.h +6 -0
@@ -12,6 +12,8 @@#ifndef __MIDCOMMS_DOT_H__#define __MIDCOMMS_DOT_H__ +struct midcomms_node ; +int dlm_process_incoming_buffer (int nodeid,unsigned char *buf,int buflen);struct dlm_mhandle *dlm_midcomms_get_mhandle (int nodeid,int len,gfp_t allocation,char **ppc);
@@ -22,6 +24,10 @@ void dlm_midcomms_shutdown(void);void dlm_midcomms_add_member (int nodeid);void dlm_midcomms_remove_member (int nodeid);void dlm_midcomms_unack_msg_resend (int nodeid); +const char *dlm_midcomms_state (struct midcomms_node *node); +unsigned long dlm_midcomms_flags (struct midcomms_node *node); +int dlm_midcomms_send_queue_cnt (struct midcomms_node *node); +uint32_t dlm_midcomms_version (struct midcomms_node *node);#endif /* __MIDCOMMS_DOT_H__ */
Signature · 1 line
2.26.3
Alexander Aring
maintainerPATCH v5 15/15 fs: dlm: don't allow half transmitted messages
In reply to Alexander AringThis patch will clean a dirty page buffer if a reconnect occurs. If a page buffer was half transmitted we cannot start inside the middle of a dlm message if a node connects again. I observed invalid length receptions errors and was guessing that this behaviour occurs, after this patch I never saw an invalid message length again. This patch might drops more messages for dlm version 3.1 but 3.1 can't deal with half messages as well, for 3.2 it might trigger more re-transmissions but will not leave dlm in a broken state.
--- fs/dlm/lowcomms.c | 95 ++++++++++++++++++++++++++++++----------------- 1 file changed, 60 insertions(+), 35 deletions(-)
fs/dlm/lowcomms.c +60 -35
@@ -118,6 +118,7 @@ struct writequeue_entry {int len;int end;int users; +bool dirty;struct connection *con;struct list_head msgs;struct kref ref;
@@ -700,6 +701,42 @@ static void make_sockaddr(struct sockaddr_storage *saddr, uint16_t port,memset ((char *)saddr + *addr_len,0 ,sizeof (struct sockaddr_storage ) - *addr_len); } +static void dlm_page_release (struct kref *kref) +{ + struct writequeue_entry *e = container_of(kref, struct writequeue_entry, + ref); + +__free_page (e->page); +kfree (e); +} + +static void dlm_msg_release (struct kref *kref) +{ + struct dlm_msg *msg = container_of(kref, struct dlm_msg, ref); + +kref_put (&msg->entry->ref, dlm_page_release); +kfree (msg); +} + +static void free_entry (struct writequeue_entry *e) +{ +struct dlm_msg *msg, *tmp; + +list_for_each_entry_safe (msg, tmp, &e->msgs, list) { +if (msg->orig_msg) { + msg->orig_msg->retransmit = false; +kref_put (&msg->orig_msg->ref, dlm_msg_release); + } + +list_del (&msg->list); +kref_put (&msg->ref, dlm_msg_release); + } + +list_del (&e->list); +atomic_dec (&e->con->writequeue_cnt); +kref_put (&e->ref, dlm_page_release); +} +static void dlm_close_sock (struct socket **sock) {if (*sock) {
@@ -714,6 +751,7 @@ static void close_connection(struct connection *con, bool and_other, bool tx, bool rx) { bool closing = test_and_set_bit(CF_CLOSING, &con->flags); +struct writequeue_entry *e;if (tx && !closing &&cancel_work_sync (&con->swork)) {log_print ("canceled swork for node %d" , con->nodeid);
@@ -732,6 +770,26 @@ static void close_connection(struct connection *con, bool and_other,close_connection (con->othercon, false, true, true); } +/* if we send a writequeue entry only a half way, we drop the +* whole entry because reconnection and that we not start of the +* middle of a msg which will confuse the other end. +* +* we can always drop messages because retransmits, but what we +* cannot allow is to transmit half messages which may be processed +* at the other side. +* +* our policy is to start on a clean state when disconnects, we don't +* know what's send/received on transport layer in this case. +*/ +spin_lock (&con->writequeue_lock); +if (!list_empty (&con->writequeue)) { + e = list_first_entry(&con->writequeue, struct writequeue_entry, + list); +if (e->dirty) +free_entry (e); + } +spin_unlock (&con->writequeue_lock); + con->rx_leftover =0 ; con->retries =0 ;clear_bit (CF_CONNECTED , &con->flags);
@@ -1026,41 +1084,6 @@ static int accept_from_sock(struct listen_connection *con)return result; } -static void dlm_page_release (struct kref *kref) -{ - struct writequeue_entry *e = container_of(kref, struct writequeue_entry, - ref); - -__free_page (e->page); -kfree (e); -} - -static void dlm_msg_release (struct kref *kref) -{ - struct dlm_msg *msg = container_of(kref, struct dlm_msg, ref); - -kref_put (&msg->entry->ref, dlm_page_release); -kfree (msg); -} - -static void free_entry (struct writequeue_entry *e) -{ -struct dlm_msg *msg, *tmp; - -list_for_each_entry_safe (msg, tmp, &e->msgs, list) { -if (msg->orig_msg) { - msg->orig_msg->retransmit = false; -kref_put (&msg->orig_msg->ref, dlm_msg_release); - } -list_del (&msg->list); -kref_put (&msg->ref, dlm_msg_release); - } - -list_del (&e->list); -atomic_dec (&e->con->writequeue_cnt); -kref_put (&e->ref, dlm_page_release); -} -/* * writequeue_entry_complete - try to delete and free write queue entry * @e: write queue entry to try to delete
@@ -1072,6 +1095,8 @@ static void writequeue_entry_complete(struct writequeue_entry *e, int completed) { e->offset += completed; e->len -= completed; +/* signal that page was half way transmitted */ + e->dirty = true;if (e->len ==0 && e->users ==0 )free_entry (e);
Signature · 1 line
2.26.3