Skip to contentSkip to conversation

fs: dlm: introduce dlm re-transmission layer

PATCH Superseded Alexander Aring 2 participants 21 messages Mar 26, 2021 – Apr 21, 2021 Distributed lock manager (DLM)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Alexander Aring

author maintainer
#0 lore raw

v3 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 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 for his review and recommendations.

Alexander Aring (8):
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 reliable connection if reconnect
fs: dlm: don't allow half transmitted messages

 fs/dlm/config.c       |    3 +-
 fs/dlm/dlm_internal.h |   35 +-
 fs/dlm/lock.c         |   14 +-
 fs/dlm/lockspace.c    |   14 +-
 fs/dlm/lowcomms.c     |  197 +++++--
 fs/dlm/lowcomms.h     |   23 +-
 fs/dlm/member.c       |   12 +-
 fs/dlm/midcomms.c     | 1307 ++++++++++++++++++++++++++++++++++++++++-
 fs/dlm/midcomms.h     |   10 +
 fs/dlm/rcom.c         |   63 +-
 fs/dlm/util.c         |   10 +-
 fs/dlm/util.h         |    2 +
 12 files changed, 1577 insertions(+), 113 deletions(-)
Signature · 1 line
2.26.3
author maintainer
#1 lore raw

PATCH v3 1/8 fs: dlm: public header in out utility

This 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
index cfd0d00b19ae..74a8c5bfe9b5 100644
@@ -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
index cc719ca9397e..d46f23c7a6a0 100644
@@ -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
author maintainer
#2 lore raw

PATCH v3 2/8 fs: dlm: add more midcomms hooks

In reply to Alexander Aring

This 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.

The midcomms_remove_member() hook should be called when there is nothing to send to the other node and the other node is still capable to transmit dlm messages to the other node which called midcomms_remove_member(). I experienced that the dlm protocol has a lack of support for synchronize this event on protocol level. The result was that there was still something to transmit but the other node was already gone. This hook can be used to provide such synchronization. Although I am not totally sure about the placement of this hook, I did not observed issues yet when providing such synchronization on protocol layer.

---
 fs/dlm/config.c    |  3 ++-
 fs/dlm/lock.c      |  6 ++---
 fs/dlm/lockspace.c |  7 +++---
 fs/dlm/member.c    | 12 +++++++++-
 fs/dlm/midcomms.c  | 44 +++++++++++++++++++++++++++++++++++++
 fs/dlm/midcomms.h  | 10 +++++++++
 fs/dlm/rcom.c      | 55 +++++++++++++++++++++++++++-------------------
 7 files changed, 107 insertions(+), 30 deletions(-)
fs/dlm/config.c +2 -1
index 88d95d96e36c..01ae294743e9 100644
@@ -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 +3 -3
index b93df39d0915..b3fd823009f4 100644
@@ -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"
@@ -3537,7 +3537,7 @@ static int _create_message(struct dlm_ls *ls, int mb_len,
 	   pass into lowcomms_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_buffer(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_buffer(mh);
 	return 0;
 }
 
fs/dlm/lockspace.c +4 -3
index c14cf2b7faab..bf5c55ef9d0d 100644
@@ -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 +11 -1
index ceef3f2074ff..c018a995a8ab 100644
@@ -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)
@@ -378,7 +379,15 @@ void dlm_clear_members(struct dlm_ls *ls)
 
 void dlm_clear_members_gone(struct dlm_ls *ls)
 {
-	clear_memb_list(&ls->ls_nodes_gone);
+	struct list_head *head = &ls->ls_nodes_gone;
+	struct dlm_member *memb;
+
+	while (!list_empty(head)) {
+		memb = list_entry(head->next, struct dlm_member, list);
+		midcomms_remove_member(memb->nodeid);
+		list_del(&memb->list);
+		kfree(memb);
+	}
 }
 
 static void make_member_array(struct dlm_ls *ls)
@@ -563,6 +572,7 @@ int dlm_recover_members(struct dlm_ls *ls, struct dlm_recover *rv, int *neg_out)
 		if (dlm_is_member(ls, node->nodeid))
 			continue;
 		dlm_add_member(ls, node);
+		midcomms_add_member(node->nodeid);
 		log_rinfo(ls, "add member %d", node->nodeid);
 	}
 
fs/dlm/midcomms.c +44 -0

50 lines not on this page · raw message

fs/dlm/midcomms.h +10 -0
index 61e90a921849..6ce2f2947475 100644
@@ -13,6 +13,16 @@
 #define __MIDCOMMS_DOT_H__
 
 int dlm_process_incoming_buffer(int nodeid, unsigned char *buf, int buflen);
+void *dlm_midcomms_get_buffer(int nodeid, int len, gfp_t allocation, char **ppc);
+void dlm_midcomms_commit_buffer(void *mh);
+void *dlm_midcomms_stateless_get_buffer(int nodeid, int len, gfp_t allocation,
+					char **ppc);
+void dlm_midcomms_stateless_commit_buffer(void *mh);
+void midcomms_add_member(int nodeid);
+void midcomms_remove_member(int nodeid);
+int dlm_midcomms_close(int nodeid);
+int dlm_midcomms_start(void);
+void dlm_midcomms_shutdown(void);
 
 #endif				/* __MIDCOMMS_DOT_H__ */
 
fs/dlm/rcom.c +33 -22

182 lines not on this page · raw message

Signature · 1 line
2.26.3
author maintainer
#3 lore raw

PATCH v3 3/8 fs: dlm: make buffer handling per msg

In reply to Alexander Aring

This 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.

---
 fs/dlm/lowcomms.c | 100 +++++++++++++++++++++++++++++++++++++++++-----
 fs/dlm/lowcomms.h |   5 ++-
 fs/dlm/midcomms.c |   8 +++-
 3 files changed, 101 insertions(+), 12 deletions(-)
fs/dlm/lowcomms.c +91 -9
index 73cc1809050a..ba782ea84281 100644
@@ -114,6 +114,17 @@ struct writequeue_entry {
 	int end;
 	int users;
 	struct connection *con;
+	struct list_head msgs;
+	struct kref ref;
+};
+
+struct dlm_msg {
+	struct writequeue_entry *entry;
+	void *ppc;
+	int len;
+
+	struct list_head list;
+	struct kref ref;
 };
 
 struct dlm_node_addr {
@@ -976,12 +987,36 @@ static int accept_from_sock(struct listen_connection *con)
 	return result;
 }
 
-static void free_entry(struct writequeue_entry *e)
+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) {
+		list_del(&msg->list);
+		kref_put(&msg->ref, dlm_msg_release);
+	}
+
+	list_del(&e->list);
+	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
@@ -994,10 +1029,8 @@ static void writequeue_entry_complete(struct writequeue_entry *e, int completed)
 	e->offset += completed;
 	e->len -= completed;
 
-	if (e->len == 0 && e->users == 0) {
-		list_del(&e->list);
+	if (e->len == 0 && e->users == 0)
 		free_entry(e);
-	}
 }
 
 /*
@@ -1363,12 +1396,16 @@ static struct writequeue_entry *new_writequeue_entry(struct connection *con,
 
 	entry->con = con;
 	entry->users = 1;
+	kref_init(&entry->ref);
+	INIT_LIST_HEAD(&entry->msgs);
 
 	return entry;
 }
 
 static struct writequeue_entry *new_wq_entry(struct connection *con, int len,
-					     gfp_t allocation, char **ppc)
+					     gfp_t allocation, char **ppc,
+					     void (*cb)(void *buf, void *priv),
+					     void *priv)
 {
 	struct writequeue_entry *e;
 
@@ -1376,7 +1413,12 @@ static struct writequeue_entry *new_wq_entry(struct connection *con, int len,
 	if (!list_empty(&con->writequeue)) {
 		e = list_last_entry(&con->writequeue, struct writequeue_entry, list);
 		if (DLM_WQ_REMAIN_BYTES(e) >= len) {
+			kref_get(&e->ref);
+
 			*ppc = page_address(e->page) + e->end;
+			if (cb)
+				cb(*ppc, priv);
+
 			e->end += len;
 			e->users++;
 			spin_unlock(&con->writequeue_lock);
@@ -1390,19 +1432,26 @@ static struct writequeue_entry *new_wq_entry(struct connection *con, int len,
 	if (!e)
 		return NULL;
 
+	kref_get(&e->ref);
 	*ppc = page_address(e->page);
 	e->end += len;
 
 	spin_lock(&con->writequeue_lock);
+	if (cb)
+		cb(*ppc, priv);
+
 	list_add_tail(&e->list, &con->writequeue);
 	spin_unlock(&con->writequeue_lock);
 
 	return e;
 };
 
-void *dlm_lowcomms_get_buffer(int nodeid, int len, gfp_t allocation, char **ppc)
+void *dlm_lowcomms_new_buffer(int nodeid, int len, gfp_t allocation, char **ppc,
+			      void (*cb)(void *buf, void *priv), void *priv)
 {
+	struct writequeue_entry *e;
 	struct connection *con;
+	struct dlm_msg *msg;
 
 	if (len > DEFAULT_BUFFER_SIZE ||
 	    len < sizeof(struct dlm_header)) {
@@ -1416,16 +1465,36 @@ void *dlm_lowcomms_get_buffer(int nodeid, int len, gfp_t allocation, char **ppc)
 	if (!con)
 		return NULL;
 
-	return new_wq_entry(con, len, allocation, ppc);
+	msg = kzalloc(sizeof(*msg), allocation);
+	if (!msg)
+		return NULL;
+
+	kref_init(&msg->ref);
+
+	e = new_wq_entry(con, len, allocation, ppc, cb, priv);
+	if (!e) {
+		kfree(msg);
+		return NULL;
+	}
+
+	msg->ppc = *ppc;
+	msg->len = len;
+	msg->entry = e;
+
+	return msg;
 }
 
 void dlm_lowcomms_commit_buffer(void *mh)
 {
-	struct writequeue_entry *e = (struct writequeue_entry *)mh;
+	struct dlm_msg *msg = mh;
+	struct writequeue_entry *e = msg->entry;
 	struct connection *con = e->con;
 	int users;
 
 	spin_lock(&con->writequeue_lock);
+	list_add(&msg->list, &e->msgs);
+	kref_get(&msg->ref);
+
 	users = --e->users;
 	if (users)
 		goto out;
@@ -1441,6 +1510,20 @@ void dlm_lowcomms_commit_buffer(void *mh)
 	return;
 }
 
+void dlm_lowcomms_put_buffer(void *mh)
+{
+	struct dlm_msg *msg = mh;
+
+	kref_put(&msg->ref, dlm_msg_release);
+}
+
+void dlm_lowcomms_get_buffer(void *mh)
+{
+	struct dlm_msg *msg = mh;
+
+	kref_get(&msg->ref);
+}
+
 /* Send a message */
 static void send_to_sock(struct connection *con)
 {
@@ -1519,7 +1602,6 @@ static void clean_one_writequeue(struct connection *con)
 
 	spin_lock(&con->writequeue_lock);
 	list_for_each_entry_safe(e, safe, &con->writequeue, list) {
-		list_del(&e->list);
 		free_entry(e);
 	}
 	spin_unlock(&con->writequeue_lock);
fs/dlm/lowcomms.h +4 -1
index 48bbc4e18761..fa735497dad8 100644
@@ -22,11 +22,14 @@ 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_new_buffer(int nodeid, int len, gfp_t allocation, char **ppc,
+			      void (*cb)(void *buf, void *priv), void *priv);
 void dlm_lowcomms_commit_buffer(void *mh);
 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);
+void dlm_lowcomms_put_buffer(void *mh);
+void dlm_lowcomms_get_buffer(void *mh);
 
 #endif				/* __LOWCOMMS_DOT_H__ */
 
fs/dlm/midcomms.c +6 -2
index bbcb242e6101..2ea0449a82ab 100644
@@ -30,23 +30,27 @@
 
 void *dlm_midcomms_get_buffer(int nodeid, int len, gfp_t allocation, char **ppc)
 {
-	return dlm_lowcomms_get_buffer(nodeid, len, allocation, ppc);
+	return dlm_lowcomms_new_buffer(nodeid, len, allocation, ppc, NULL,
+				       NULL);
 }
 
 void dlm_midcomms_commit_buffer(void *mh)
 {
 	dlm_lowcomms_commit_buffer(mh);
+	dlm_lowcomms_put_buffer(mh);
 }
 
 void *dlm_midcomms_stateless_get_buffer(int nodeid, int len, gfp_t allocation,
 					char **ppc)
 {
-	return dlm_lowcomms_get_buffer(nodeid, len, allocation, ppc);
+	return dlm_lowcomms_new_buffer(nodeid, len, allocation, ppc, NULL,
+				       NULL);
 }
 
 void dlm_midcomms_stateless_commit_buffer(void *mh)
 {
 	dlm_lowcomms_commit_buffer(mh);
+	dlm_lowcomms_put_buffer(mh);
 }
 
 void midcomms_add_member(int nodeid)
Signature · 1 line
2.26.3
author maintainer
#4 lore raw

PATCH v3 4/8 fs: dlm: add functionality to re-transmit a message

In reply to Alexander Aring

This patch introduces a irqsafe 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 | 84 +++++++++++++++++++++++++++++++----------------
 fs/dlm/lowcomms.h |  1 +
 2 files changed, 56 insertions(+), 29 deletions(-)
fs/dlm/lowcomms.c +55 -29
index ba782ea84281..d2be58496fd0 100644
@@ -1409,7 +1409,7 @@ static struct writequeue_entry *new_wq_entry(struct connection *con, int len,
 {
 	struct writequeue_entry *e;
 
-	spin_lock(&con->writequeue_lock);
+	spin_lock_bh(&con->writequeue_lock);
 	if (!list_empty(&con->writequeue)) {
 		e = list_last_entry(&con->writequeue, struct writequeue_entry, list);
 		if (DLM_WQ_REMAIN_BYTES(e) >= len) {
@@ -1421,12 +1421,12 @@ static struct writequeue_entry *new_wq_entry(struct connection *con, int len,
 
 			e->end += len;
 			e->users++;
-			spin_unlock(&con->writequeue_lock);
+			spin_unlock_bh(&con->writequeue_lock);
 
 			return e;
 		}
 	}
-	spin_unlock(&con->writequeue_lock);
+	spin_unlock_bh(&con->writequeue_lock);
 
 	e = new_writequeue_entry(con, allocation);
 	if (!e)
@@ -1436,35 +1436,24 @@ static struct writequeue_entry *new_wq_entry(struct connection *con, int len,
 	*ppc = page_address(e->page);
 	e->end += len;
 
-	spin_lock(&con->writequeue_lock);
+	spin_lock_bh(&con->writequeue_lock);
 	if (cb)
 		cb(*ppc, priv);
 
 	list_add_tail(&e->list, &con->writequeue);
-	spin_unlock(&con->writequeue_lock);
+	spin_unlock_bh(&con->writequeue_lock);
 
 	return e;
 };
 
-void *dlm_lowcomms_new_buffer(int nodeid, int len, gfp_t allocation, char **ppc,
-			      void (*cb)(void *buf, void *priv), void *priv)
+static void *dlm_lowcomms_new_buffer_con(struct connection *con, int len,
+					 gfp_t allocation, char **ppc,
+					 void (*cb)(void *buf, void *priv),
+					 void *priv)
 {
 	struct writequeue_entry *e;
-	struct connection *con;
 	struct dlm_msg *msg;
 
-	if (len > DEFAULT_BUFFER_SIZE ||
-	    len < sizeof(struct dlm_header)) {
-		BUILD_BUG_ON(PAGE_SIZE < DEFAULT_BUFFER_SIZE);
-		log_print("failed to allocate a buffer of size %d", len);
-		WARN_ON(1);
-		return NULL;
-	}
-
-	con = nodeid2con(nodeid, allocation);
-	if (!con)
-		return NULL;
-
 	msg = kzalloc(sizeof(*msg), allocation);
 	if (!msg)
 		return NULL;
@@ -1484,6 +1473,26 @@ void *dlm_lowcomms_new_buffer(int nodeid, int len, gfp_t allocation, char **ppc,
 	return msg;
 }
 
+void *dlm_lowcomms_new_buffer(int nodeid, int len, gfp_t allocation, char **ppc,
+			      void (*cb)(void *buf, void *priv), void *priv)
+{
+	struct connection *con;
+
+	if (len > DEFAULT_BUFFER_SIZE ||
+	    len < sizeof(struct dlm_header)) {
+		BUILD_BUG_ON(PAGE_SIZE < DEFAULT_BUFFER_SIZE);
+		log_print("failed to allocate a buffer of size %d", len);
+		WARN_ON(1);
+		return NULL;
+	}
+
+	con = nodeid2con(nodeid, allocation);
+	if (!con)
+		return NULL;
+
+	return dlm_lowcomms_new_buffer_con(con, len, GFP_ATOMIC, ppc, cb, priv);
+}
+
 void dlm_lowcomms_commit_buffer(void *mh)
 {
 	struct dlm_msg *msg = mh;
@@ -1491,7 +1500,7 @@ void dlm_lowcomms_commit_buffer(void *mh)
 	struct connection *con = e->con;
 	int users;
 
-	spin_lock(&con->writequeue_lock);
+	spin_lock_bh(&con->writequeue_lock);
 	list_add(&msg->list, &e->msgs);
 	kref_get(&msg->ref);
 
@@ -1500,13 +1509,13 @@ void dlm_lowcomms_commit_buffer(void *mh)
 		goto out;
 
 	e->len = DLM_WQ_LENGTH_BYTES(e);
-	spin_unlock(&con->writequeue_lock);
+	spin_unlock_bh(&con->writequeue_lock);
 
 	queue_work(send_workqueue, &con->swork);
 	return;
 
 out:
-	spin_unlock(&con->writequeue_lock);
+	spin_unlock_bh(&con->writequeue_lock);
 	return;
 }
 
@@ -1524,6 +1533,23 @@ void dlm_lowcomms_get_buffer(void *mh)
 	kref_get(&msg->ref);
 }
 
+/* irqsafe */
+void dlm_lowcomms_resend_buffer(void *mh)
+{
+	struct dlm_msg *msg = mh;
+	void *mh_new;
+	char *ppc;
+
+	mh_new = dlm_lowcomms_new_buffer_con(msg->entry->con, msg->len, GFP_ATOMIC,
+					     &ppc, NULL, NULL);
+	if (!mh_new)
+		return;
+
+	memcpy(ppc, msg->ppc, msg->len);
+	dlm_lowcomms_commit_buffer(mh_new);
+	dlm_lowcomms_put_buffer(mh_new);
+}
+
 /* Send a message */
 static void send_to_sock(struct connection *con)
 {
@@ -1537,7 +1563,7 @@ static void send_to_sock(struct connection *con)
 	if (con->sock == NULL)
 		goto out_connect;
 
-	spin_lock(&con->writequeue_lock);
+	spin_lock_bh(&con->writequeue_lock);
 	for (;;) {
 		if (list_empty(&con->writequeue))
 			break;
@@ -1546,7 +1572,7 @@ static void send_to_sock(struct connection *con)
 		len = e->len;
 		offset = e->offset;
 		BUG_ON(len == 0 && e->users == 0);
-		spin_unlock(&con->writequeue_lock);
+		spin_unlock_bh(&con->writequeue_lock);
 
 		ret = 0;
 		if (len) {
@@ -1574,10 +1600,10 @@ static void send_to_sock(struct connection *con)
 			count = 0;
 		}
 
-		spin_lock(&con->writequeue_lock);
+		spin_lock_bh(&con->writequeue_lock);
 		writequeue_entry_complete(e, ret);
 	}
-	spin_unlock(&con->writequeue_lock);
+	spin_unlock_bh(&con->writequeue_lock);
 out:
 	mutex_unlock(&con->sock_mutex);
 	return;
@@ -1600,11 +1626,11 @@ static void clean_one_writequeue(struct connection *con)
 {
 	struct writequeue_entry *e, *safe;
 
-	spin_lock(&con->writequeue_lock);
+	spin_lock_bh(&con->writequeue_lock);
 	list_for_each_entry_safe(e, safe, &con->writequeue, list) {
 		free_entry(e);
 	}
-	spin_unlock(&con->writequeue_lock);
+	spin_unlock_bh(&con->writequeue_lock);
 }
 
 /* Called from recovery when it knows that a node has
fs/dlm/lowcomms.h +1 -0
index fa735497dad8..345aed7e00cc 100644
@@ -30,6 +30,7 @@ int dlm_lowcomms_nodes_set_mark(int nodeid, unsigned int mark);
 int dlm_lowcomms_addr(int nodeid, struct sockaddr_storage *addr, int len);
 void dlm_lowcomms_put_buffer(void *mh);
 void dlm_lowcomms_get_buffer(void *mh);
+void dlm_lowcomms_resend_buffer(void *mh);
 
 #endif				/* __LOWCOMMS_DOT_H__ */
 
Signature · 1 line
2.26.3
author maintainer
#5 lore raw

PATCH v3 5/8 fs: dlm: move out some hash functionality

In reply to Alexander Aring

This 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
index d2be58496fd0..5cb6d7c9ddc1 100644
@@ -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
@@ -166,14 +165,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, idx;
fs/dlm/lowcomms.h +10 -0
index 345aed7e00cc..cacfc5620f54 100644
@@ -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
author maintainer
#6 lore raw

PATCH v3 6/8 fs: dlm: add union in dlm header for lockspace id

In reply to Alexander Aring

This 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/midcomms.c     | 1 -
 fs/dlm/rcom.c         | 4 ++--
 fs/dlm/util.c         | 6 ++++--
 5 files changed, 14 insertions(+), 10 deletions(-)
fs/dlm/dlm_internal.h +4 -1
index 04fe9f525ac7..917de7367a32 100644
@@ -377,7 +377,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
index b3fd823009f4..daa5747c8556 100644
@@ -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/midcomms.c +0 -1
index 2ea0449a82ab..d86dcc95f736 100644
@@ -149,4 +149,3 @@ int dlm_process_incoming_buffer(int nodeid, unsigned char *buf, int len)
 
 	return ret;
 }
-
fs/dlm/rcom.c +2 -2
index 7a7d4a8e4706..06f7a5f1d99d 100644
@@ -49,7 +49,7 @@ static int 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;
@@ -476,7 +476,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
index 74a8c5bfe9b5..58acbcc2081a 100644
@@ -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
author maintainer
#7 lore raw

PATCH v3 7/8 fs: dlm: add reliable connection if reconnect

In reply to Alexander Aring

This 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:

A new DLM message to synchronize pending message to the other dlm end if the node want to disconnects. Each side waits until it receives this message and disconnects. It's important that this message has nothing to do with the application logic because it might run in a timeout if acknowledge messages are dropped. The problem which we try to solve with DLM_FIN is that the node membership is handled by corosync and not the kernel dlm protocol itself, DLM_FIN tries to synchronize the kernel dlm protocol with corosync join/leave membership callbacks.

To explain the basic functionality take a look into the dlm_midcomms_receive_buffer() function. This function will take care that dlm messages are delivered according to their sequence numbers and request re-transmission via sending acknowledge messages. However there exists three cases:

1. sequence number is the one which is expected. That means everything is working fine. Additional there is always a check if the next message was already queued for future, this will occur when there was some messages drops before.

2. A sequence number is in the future, in this case we queue it for might future delivery, see case 1.

3. A sequence number is in the past, in this case we drop this message because it was already delivered.

To send acknowledge we always send the sequence number which is expected, if the other node sends multiple acknowledge for the same sequence numbers it will trigger a re-transmission. In case no acknowledge is send back, a timer with a timeout handling is running and will trigger a re-tranmission as well. Sending multiple ack's with the same sequence or messages with the same sequence should not have any effects that breaks dlm. Only messages in the far future can break dlm, that's why important that the closing connection is right synchronized with DLM_FIN which also resets the sequence numbers.

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.h     |    7 +-
 fs/dlm/midcomms.c     | 1302 +++++++++++++++++++++++++++++++++++++++--
 fs/dlm/rcom.c         |    4 +-
 5 files changed, 1295 insertions(+), 55 deletions(-)
fs/dlm/dlm_internal.h +28 -2
index 917de7367a32..da2297705713 100644
@@ -368,18 +368,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			5
 
 struct 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;
@@ -387,7 +395,6 @@ struct dlm_header {
 	uint8_t			h_pad;
 };
 
-
 #define DLM_MSG_REQUEST		1
 #define DLM_MSG_CONVERT		2
 #define DLM_MSG_UNLOCK		3
@@ -455,10 +462,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
index bf5c55ef9d0d..2b738be8d7e4 100644
@@ -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.h +6 -1
index cacfc5620f54..1554d8c078c9 100644
@@ -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 +1253 -49

1,363 lines not on this page · raw message

fs/dlm/rcom.c +2 -2
index 06f7a5f1d99d..d731d9e65c3b 100644
@@ -168,7 +168,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(ls, mh, rc, true);
 
@@ -291,7 +291,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(ls, mh, rc, true);
 
Signature · 1 line
2.26.3
author maintainer
#20 lore raw

PATCH v3 8/8 fs: dlm: don't allow half transmitted messages

In reply to Alexander Aring

This 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 | 84 ++++++++++++++++++++++++++++++-----------------
 1 file changed, 54 insertions(+), 30 deletions(-)
fs/dlm/lowcomms.c +54 -30
index 5cb6d7c9ddc1..d70a554c6b2b 100644
@@ -112,6 +112,7 @@ struct writequeue_entry {
 	int len;
 	int end;
 	int users;
+	bool dirty;
 	struct connection *con;
 	struct list_head msgs;
 	struct kref ref;
@@ -671,6 +672,36 @@ 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) {
+		list_del(&msg->list);
+		kref_put(&msg->ref, dlm_msg_release);
+	}
+
+	list_del(&e->list);
+	kref_put(&e->ref, dlm_page_release);
+}
+
 static void dlm_close_sock(struct socket **sock)
 {
 	if (*sock) {
@@ -685,6 +716,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);
@@ -703,6 +735,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_bh(&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_bh(&con->writequeue_lock);
+
 	con->rx_leftover = 0;
 	con->retries = 0;
 	clear_bit(CF_CONNECTED, &con->flags);
@@ -978,36 +1030,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) {
-		list_del(&msg->list);
-		kref_put(&msg->ref, dlm_msg_release);
-	}
-
-	list_del(&e->list);
-	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
@@ -1019,6 +1041,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
#8 lore raw

PATCH v3 7/8 fs: dlm: add reliable connection if reconnect

In reply to Alexander Aring
Quoted 23 lines · Alexander Aring

This 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:

Quoted 8 lines

A new DLM message to synchronize pending message to the other dlm end if the node want to disconnects. Each side waits until it receives this message and disconnects. It's important that this message has nothing to do with the application logic because it might run in a timeout if acknowledge messages are dropped. The problem which we try to solve with DLM_FIN is that the node membership is handled by corosync and not the kernel dlm protocol itself, DLM_FIN tries to synchronize the kernel dlm protocol with corosync join/leave membership callbacks.

If I understand correctly, currently, when DLM faces a hard but temporary connection failure (like receiving a stray TCP RST), it automatically recreates a new connection. However, the in-flight data of the previous connection are lost. The problem is that such data loss can turn the participating nodes into inconsistent states.

Therefore this patch series implements sequence number tracking at the application level, so that a new connection can retransmit unacknowledged data from the previous, failed, connection.

Is that an accurate summary or is there anything I've missed?

I feel that this patch goes very far into re-implementing TCP-like features. For example, why is fast-retransmit even needed? DLM seems to always uses a transport protocol that guarantees reliable and in order delivery. Therefore, duplicate DLM acknowledgements can't happen on an established connection. Even when reconnecting, it'd be the sender's responsibility to resend the last unackowledged data first. How could this lead to holes in the DLM sequence numbers on the receiver's side?

It seems to me that the only time DLM might need to retransmit data, is when recovering from a connection failure. So why can't we just resend unacknowledged data at reconnection time? That'd probably simplify the code a lot (no need to maintain a retransmission timeout on TX, no need to handle sequence numbers that are in the future on RX).

Also, couldn't we set the DLM sequence numbers in dlm_midcomms_commit_buffer_3_2() rather than using a callback function in dlm_lowcomms_new_buffer()?

Finally, I wonder if we could avoid adding DLM sequence numbers entirely. Have you considered using the TCP_REPAIR infrastructure to retrieve the send queue of the failed socket and resend that data once the new socket is connected?

Please correct me if the above suggestions don't make sense. I'm not familiar with DLM so I can very well be missing important points.

Thanks,

Quoted 37 lines

To explain the basic functionality take a look into the dlm_midcomms_receive_buffer() function. This function will take care that dlm messages are delivered according to their sequence numbers and request re-transmission via sending acknowledge messages. However there exists three cases:

1. sequence number is the one which is expected. That means everything is working fine. Additional there is always a check if the next message was already queued for future, this will occur when there was some messages drops before.

2. A sequence number is in the future, in this case we queue it for might future delivery, see case 1.

3. A sequence number is in the past, in this case we drop this message because it was already delivered.

To send acknowledge we always send the sequence number which is expected, if the other node sends multiple acknowledge for the same sequence numbers it will trigger a re-transmission. In case no acknowledge is send back, a timer with a timeout handling is running and will trigger a re-tranmission as well. Sending multiple ack's with the same sequence or messages with the same sequence should not have any effects that breaks dlm. Only messages in the far future can break dlm, that's why important that the closing connection is right synchronized with DLM_FIN which also resets the sequence numbers.

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.

author maintainer
#9 lore raw

PATCH v3 7/8 fs: dlm: add reliable connection if reconnect

Hi Guillaume,

Quoted 40 lines · Guillaume Nault
Quoted 23 lines · Alexander Aring

This 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:

Quoted 8 lines

A new DLM message to synchronize pending message to the other dlm end if the node want to disconnects. Each side waits until it receives this message and disconnects. It's important that this message has nothing to do with the application logic because it might run in a timeout if acknowledge messages are dropped. The problem which we try to solve with DLM_FIN is that the node membership is handled by corosync and not the kernel dlm protocol itself, DLM_FIN tries to synchronize the kernel dlm protocol with corosync join/leave membership callbacks.

If I understand correctly, currently, when DLM faces a hard but temporary connection failure (like receiving a stray TCP RST), it automatically recreates a new connection. However, the in-flight data of the previous connection are lost. The problem is that such data loss can turn the participating nodes into inconsistent states.

Quoted 6 lines

Therefore this patch series implements sequence number tracking at the application level, so that a new connection can retransmit unacknowledged data from the previous, failed, connection.

Is that an accurate summary or is there anything I've missed?

Yes, there is one thing missing. I detected a synchronization issue because the node membership of a lockspace is done by a different protocol handled in user space. This protocol declares the actual peer of the DLM protocol. In short, there are two protocols here, whereas one handles the membership of peers and the other handles the actual operations. There is a missing synchronization between operations and membership which I solved with a DLM_FIN message.

Quoted 8 lines

I feel that this patch goes very far into re-implementing TCP-like features. For example, why is fast-retransmit even needed? DLM seems to always uses a transport protocol that guarantees reliable and in order delivery. Therefore, duplicate DLM acknowledgements can't happen on an established connection. Even when reconnecting, it'd be the sender's responsibility to resend the last unackowledged data first. How could this lead to holes in the DLM sequence numbers on the receiver's side?

I agree it's a TCP re-implementation on the application layer.

Fast-retransmit is not needed as it is not needed in TCP. However it solves drops faster, in DLM and GFS2 you would experience a stuck in some filesystem syscalls until the drop is resolved.

Quoted 6 lines

It seems to me that the only time DLM might need to retransmit data, is when recovering from a connection failure. So why can't we just resend unacknowledged data at reconnection time? That'd probably simplify the code a lot (no need to maintain a retransmission timeout on TX, no need to handle sequence numbers that are in the future on RX).

I can try to remove the timer, timeout and do the above approach to retransmit at reconnect. Then I test it again and I will report back to see if it works or why we have other problems.

Quoted 4 lines

Also, couldn't we set the DLM sequence numbers in dlm_midcomms_commit_buffer_3_2() rather than using a callback function in dlm_lowcomms_new_buffer()?

That has something to do with the internal buffer allocator. The order is defined in dlm_lowcomms_new_buffer() and there is an internal lock which needs to be held there. I can't do this without somehow making the lock accessible in dlm_midcomms_commit_buffer_3_2(). The code is also optimized that the lock isn't held during kmalloc().

Quoted 5 lines

Finally, I wonder if we could avoid adding DLM sequence numbers entirely. Have you considered using the TCP_REPAIR infrastructure to retrieve the send queue of the failed socket and resend that data once the new socket is connected?

Yes, I looked into TCP_REPAIR at first and I agree it can be used to solve this problem. However TCP_REPAIR can be used as a part of a more generic solution, there needs to be something "additional handling" done e.g. additional socket options to let the application layer save states before receiving errors. I am also concerned how it would work with haproxy, etc. It also has some advantages to restore window size, etc. I was thinking about submitting a proposal to the next netdevconf after doing some experiments with it.

We decided to solve this problem at the application layer first, then look into how to make a more generic solution. For me, I am not sure how cifs deals with reconnects or it just allows drops.

Quoted 3 lines

Please correct me if the above suggestions don't make sense. I'm not familiar with DLM so I can very well be missing important points.

No problem, it does make sense for me.

- Alex

author maintainer
#10 lore raw

PATCH v3 7/8 fs: dlm: add reliable connection if reconnect

Hi,

Quoted 1 line · Alexander Ahring Oder Aring

...

Quoted 8 lines
Quoted 7 lines

It seems to me that the only time DLM might need to retransmit data, is when recovering from a connection failure. So why can't we just resend unacknowledged data at reconnection time? That'd probably simplify the code a lot (no need to maintain a retransmission timeout on TX, no need to handle sequence numbers that are in the future on RX).

Quoted 4 lines

I can try to remove the timer, timeout and do the above approach to retransmit at reconnect. Then I test it again and I will report back to see if it works or why we have other problems.

I have an implementation of this running and so far I don't see any problems.

Quoted 4 lines
Quoted 4 lines

Also, couldn't we set the DLM sequence numbers in dlm_midcomms_commit_buffer_3_2() rather than using a callback function in dlm_lowcomms_new_buffer()?

...

Quoted 6 lines

Yes, I looked into TCP_REPAIR at first and I agree it can be used to solve this problem. However TCP_REPAIR can be used as a part of a more generic solution, there needs to be something "additional handling" done e.g. additional socket options to let the application layer save states before receiving errors. I am also concerned how it would work

The code [0] is what I meant above. It will call tcp_write_queue_purge(); before reporting the error over error queue/callback. That need to be handled differently to allow dumping the actual TCP state and restore at reconnect, at least that is what I have in my mind.

- Alex

[0] https://elixir.bootlin.com/linux/v5.12-rc6/source/net/ipv4/tcp_input.c#L4239

author maintainer
#11 lore raw

PATCH v3 7/8 fs: dlm: add reliable connection if reconnect

Hi,

Quoted 15 lines · Alexander Ahring Oder Aring

Hi,

Quoted 1 line · Alexander Ahring Oder Aring

...

Quoted 8 lines
Quoted 7 lines

It seems to me that the only time DLM might need to retransmit data, is when recovering from a connection failure. So why can't we just resend unacknowledged data at reconnection time? That'd probably simplify the code a lot (no need to maintain a retransmission timeout on TX, no need to handle sequence numbers that are in the future on RX).

Quoted 6 lines
Quoted 4 lines

I can try to remove the timer, timeout and do the above approach to retransmit at reconnect. Then I test it again and I will report back to see if it works or why we have other problems.

I have an implementation of this running and so far I don't see any problems.

There is a problem but it's related to the behaviour how reconnections are triggered. The whole communication can be stuck because the send() triggers a reconnection if not connected anymore. Before, the timer was triggering some send() and this was triggering a reconnection in a periodic way. Therefore we never had any stuck situation where nobody was sending anything anymore. It's a rare case but I am currently running into it. However I think I need to change how the reconnections are triggered with some "forever periodic try" which should solve this issue.

- Alex

#17 lore raw

PATCH v3 7/8 fs: dlm: add reliable connection if reconnect

In reply to Alexander Ahring Oder Aring
Quoted 50 lines · Alexander Ahring Oder Aring

Hi Guillaume,

Quoted 40 lines · Guillaume Nault
Quoted 23 lines · Alexander Aring

This 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:

Quoted 8 lines

A new DLM message to synchronize pending message to the other dlm end if the node want to disconnects. Each side waits until it receives this message and disconnects. It's important that this message has nothing to do with the application logic because it might run in a timeout if acknowledge messages are dropped. The problem which we try to solve with DLM_FIN is that the node membership is handled by corosync and not the kernel dlm protocol itself, DLM_FIN tries to synchronize the kernel dlm protocol with corosync join/leave membership callbacks.

If I understand correctly, currently, when DLM faces a hard but temporary connection failure (like receiving a stray TCP RST), it automatically recreates a new connection. However, the in-flight data of the previous connection are lost. The problem is that such data loss can turn the participating nodes into inconsistent states.

Quoted 6 lines

Therefore this patch series implements sequence number tracking at the application level, so that a new connection can retransmit unacknowledged data from the previous, failed, connection.

Is that an accurate summary or is there anything I've missed?

Quoted 7 lines

Yes, there is one thing missing. I detected a synchronization issue because the node membership of a lockspace is done by a different protocol handled in user space. This protocol declares the actual peer of the DLM protocol. In short, there are two protocols here, whereas one handles the membership of peers and the other handles the actual operations. There is a missing synchronization between operations and membership which I solved with a DLM_FIN message.

Thanks, I'll re-read the parts about DLM_FIN with this explanation in mind.

Quoted 9 lines
Quoted 8 lines

I feel that this patch goes very far into re-implementing TCP-like features. For example, why is fast-retransmit even needed? DLM seems to always uses a transport protocol that guarantees reliable and in order delivery. Therefore, duplicate DLM acknowledgements can't happen on an established connection. Even when reconnecting, it'd be the sender's responsibility to resend the last unackowledged data first. How could this lead to holes in the DLM sequence numbers on the receiver's side?

Quoted 5 lines

I agree it's a TCP re-implementation on the application layer.

Fast-retransmit is not needed as it is not needed in TCP. However it solves drops faster, in DLM and GFS2 you would experience a stuck in some filesystem syscalls until the drop is resolved.

I was not talking about fast retransmits in general. My question was:
how could a DLM fast retransmit even be triggered? This can only happen when some DLM messages get lost or are received out of order. But the transport layer guarantees lossless and in order delivery. Even in case of a reconnection, I can't see how the peer could get holes in its receive queue. What am I missing?

Quoted 10 lines
Quoted 6 lines

It seems to me that the only time DLM might need to retransmit data, is when recovering from a connection failure. So why can't we just resend unacknowledged data at reconnection time? That'd probably simplify the code a lot (no need to maintain a retransmission timeout on TX, no need to handle sequence numbers that are in the future on RX).

I can try to remove the timer, timeout and do the above approach to retransmit at reconnect. Then I test it again and I will report back to see if it works or why we have other problems.

I see you've posted a new version of the patch series. I'll look at it soon.

Quoted 10 lines
Quoted 4 lines

Also, couldn't we set the DLM sequence numbers in dlm_midcomms_commit_buffer_3_2() rather than using a callback function in dlm_lowcomms_new_buffer()?

That has something to do with the internal buffer allocator. The order is defined in dlm_lowcomms_new_buffer() and there is an internal lock which needs to be held there. I can't do this without somehow making the lock accessible in dlm_midcomms_commit_buffer_3_2(). The code is also optimized that the lock isn't held during kmalloc().

I missed that. Thanks for the explanation.

Quoted 6 lines
Quoted 5 lines

Finally, I wonder if we could avoid adding DLM sequence numbers entirely. Have you considered using the TCP_REPAIR infrastructure to retrieve the send queue of the failed socket and resend that data once the new socket is connected?

Quoted 8 lines

Yes, I looked into TCP_REPAIR at first and I agree it can be used to solve this problem. However TCP_REPAIR can be used as a part of a more generic solution, there needs to be something "additional handling" done e.g. additional socket options to let the application layer save states before receiving errors. I am also concerned how it would work with haproxy, etc. It also has some advantages to restore window size, etc. I was thinking about submitting a proposal to the next netdevconf after doing some experiments with it.

Well, I was thinking of using TCP_REPAIR only to retrieve the send queue. I didn't mean to avoid the hand-check like in the CRIU use case. A TCP connection break is a sign that something went wrong between the peers, so a full reconnection is in order IMHO.

Quoted 3 lines

We decided to solve this problem at the application layer first, then look into how to make a more generic solution. For me, I am not sure how cifs deals with reconnects or it just allows drops.

Indeed, it'd be interesting to know how other protocols handle this case.

Quoted 8 lines
Quoted 3 lines

Please correct me if the above suggestions don't make sense. I'm not familiar with DLM so I can very well be missing important points.

No problem, it does make sense for me.

- Alex

#14 lore raw

PATCH v3 7/8 fs: dlm: add reliable connection if reconnect

In reply to Alexander Ahring Oder Aring
Quoted 33 lines · Alexander Ahring Oder Aring

Hi,

Quoted 1 line · Alexander Ahring Oder Aring

...

Quoted 8 lines
Quoted 7 lines

It seems to me that the only time DLM might need to retransmit data, is when recovering from a connection failure. So why can't we just resend unacknowledged data at reconnection time? That'd probably simplify the code a lot (no need to maintain a retransmission timeout on TX, no need to handle sequence numbers that are in the future on RX).

Quoted 4 lines

I can try to remove the timer, timeout and do the above approach to retransmit at reconnect. Then I test it again and I will report back to see if it works or why we have other problems.

I have an implementation of this running and so far I don't see any problems.

Quoted 4 lines
Quoted 4 lines

Also, couldn't we set the DLM sequence numbers in dlm_midcomms_commit_buffer_3_2() rather than using a callback function in dlm_lowcomms_new_buffer()?

...

Quoted 6 lines

Yes, I looked into TCP_REPAIR at first and I agree it can be used to solve this problem. However TCP_REPAIR can be used as a part of a more generic solution, there needs to be something "additional handling" done e.g. additional socket options to let the application layer save states before receiving errors. I am also concerned how it would work

Quoted 5 lines

The code [0] is what I meant above. It will call tcp_write_queue_purge(); before reporting the error over error queue/callback. That need to be handled differently to allow dumping the actual TCP state and restore at reconnect, at least that is what I have in my mind.

Thanks. That's not usable as is, indeed.
Also, by retransmitting data from the previous send-queue, we risk resending messages that the peer already received (for example because the previous connection didn't receive the latest ACKs). I guess that receiving the same DLM messages twice is going to confuse the peer. So it looks like we'll need application level sequence numbers anyway.

Quoted 4 lines

- Alex

[0] https://elixir.bootlin.com/linux/v5.12-rc6/source/net/ipv4/tcp_input.c#L4239

#12 lore raw

PATCH v3 7/8 fs: dlm: add reliable connection if reconnect

In reply to Alexander Ahring Oder Aring
Quoted 26 lines · Alexander Ahring Oder Aring

Hi,

Quoted 15 lines · Alexander Ahring Oder Aring

Hi,

Quoted 1 line · Alexander Ahring Oder Aring

...

Quoted 8 lines
Quoted 7 lines

It seems to me that the only time DLM might need to retransmit data, is when recovering from a connection failure. So why can't we just resend unacknowledged data at reconnection time? That'd probably simplify the code a lot (no need to maintain a retransmission timeout on TX, no need to handle sequence numbers that are in the future on RX).

Quoted 6 lines
Quoted 4 lines

I can try to remove the timer, timeout and do the above approach to retransmit at reconnect. Then I test it again and I will report back to see if it works or why we have other problems.

I have an implementation of this running and so far I don't see any problems.

Quoted 9 lines

There is a problem but it's related to the behaviour how reconnections are triggered. The whole communication can be stuck because the send() triggers a reconnection if not connected anymore. Before, the timer was triggering some send() and this was triggering a reconnection in a periodic way. Therefore we never had any stuck situation where nobody was sending anything anymore. It's a rare case but I am currently running into it. However I think I need to change how the reconnections are triggered with some "forever periodic try" which should solve this issue.

Would it be sufficient to detect socket errors to avoid this problem? For example by letting lowcomms_error_report() do the reconnection when necessary?

Quoted 3 lines

- Alex

author maintainer
#18 lore raw

PATCH v3 7/8 fs: dlm: add reliable connection if reconnect

In reply to Guillaume Nault

Hi,

On Fri, Apr 9, 2021 at 4:32 PM Guillaume Nault <[email protected]> wrote:
...

Quoted 9 lines
Quoted 8 lines

Yes, there is one thing missing. I detected a synchronization issue because the node membership of a lockspace is done by a different protocol handled in user space. This protocol declares the actual peer of the DLM protocol. In short, there are two protocols here, whereas one handles the membership of peers and the other handles the actual operations. There is a missing synchronization between operations and membership which I solved with a DLM_FIN message.

Quoted 3 lines

Thanks, I'll re-read the parts about DLM_FIN with this explanation in mind.

okay. Thank you.

Quoted 15 lines
Quoted 9 lines
Quoted 8 lines

I feel that this patch goes very far into re-implementing TCP-like features. For example, why is fast-retransmit even needed? DLM seems to always uses a transport protocol that guarantees reliable and in order delivery. Therefore, duplicate DLM acknowledgements can't happen on an established connection. Even when reconnecting, it'd be the sender's responsibility to resend the last unackowledged data first. How could this lead to holes in the DLM sequence numbers on the receiver's side?

Quoted 5 lines

I agree it's a TCP re-implementation on the application layer.

Fast-retransmit is not needed as it is not needed in TCP. However it solves drops faster, in DLM and GFS2 you would experience a stuck in some filesystem syscalls until the drop is resolved.

Quoted 7 lines

I was not talking about fast retransmits in general. My question was:
how could a DLM fast retransmit even be triggered? This can only happen when some DLM messages get lost or are received out of order. But the transport layer guarantees lossless and in order delivery. Even in case of a reconnection, I can't see how the peer could get holes in its receive queue. What am I missing?

It can be triggered in cases that DLM just does some other operations which triggers new messages after a reconnect and drop. The receiver will send back multiple ack frames back with the same sequence number which indicates for the sender a drop. If the ack count with multiple times the same sequence number (the receiver expected sequence number) a retransmission will be triggered. Just like in [0].

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

It seems to me that the only time DLM might need to retransmit data, is when recovering from a connection failure. So why can't we just resend unacknowledged data at reconnection time? That'd probably simplify the code a lot (no need to maintain a retransmission timeout on TX, no need to handle sequence numbers that are in the future on RX).

Quoted 7 lines
Quoted 3 lines

I can try to remove the timer, timeout and do the above approach to retransmit at reconnect. Then I test it again and I will report back to see if it works or why we have other problems.

I see you've posted a new version of the patch series. I'll look at it soon.

ok.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

Also, couldn't we set the DLM sequence numbers in dlm_midcomms_commit_buffer_3_2() rather than using a callback function in dlm_lowcomms_new_buffer()?

Quoted 8 lines
Quoted 5 lines

That has something to do with the internal buffer allocator. The order is defined in dlm_lowcomms_new_buffer() and there is an internal lock which needs to be held there. I can't do this without somehow making the lock accessible in dlm_midcomms_commit_buffer_3_2(). The code is also optimized that the lock isn't held during kmalloc().

I missed that. Thanks for the explanation.

ok, no problem. It took some time for me to figure that out as well.

Quoted 15 lines
Quoted 6 lines
Quoted 5 lines

Finally, I wonder if we could avoid adding DLM sequence numbers entirely. Have you considered using the TCP_REPAIR infrastructure to retrieve the send queue of the failed socket and resend that data once the new socket is connected?

Quoted 8 lines

Yes, I looked into TCP_REPAIR at first and I agree it can be used to solve this problem. However TCP_REPAIR can be used as a part of a more generic solution, there needs to be something "additional handling" done e.g. additional socket options to let the application layer save states before receiving errors. I am also concerned how it would work with haproxy, etc. It also has some advantages to restore window size, etc. I was thinking about submitting a proposal to the next netdevconf after doing some experiments with it.

Quoted 5 lines

Well, I was thinking of using TCP_REPAIR only to retrieve the send queue. I didn't mean to avoid the hand-check like in the CRIU use case. A TCP connection break is a sign that something went wrong between the peers, so a full reconnection is in order IMHO.

I am somehow worried about what data-format they are in the "queues" and even if we can figure out message boundaries? Yes "queues" so far I remember/know there exists two queues for TCP, a write queue and retransmit queue. I am not sure if the data payload is with TCP header or not, something to figure out. Otherwise we would need to parse TCP here?

Quoted 7 lines
Quoted 3 lines

We decided to solve this problem at the application layer first, then look into how to make a more generic solution. For me, I am not sure how cifs deals with reconnects or it just allows drops.

Indeed, it'd be interesting to know how other protocols handle this case.

Yes, this protocol is very picky if there is any drop. Of course we are talking about lock operations over the network, it can be very fatal if drops occur. Pablo review mentions a lot of "security" related things and disconnecting peers if they happen. We work here in the cluster world which operates a little bit differently. What we can do is send an event to the cluster manager to fence nodes. However I am not aware that we currently support such handling if something runs out-of-boundaries of queues, sequence numbers, etc. We need to trust the network anyway because you can easily trigger deadlocks from outside, I guess. Trusting network != things run crazy, for the crazy case we could send events to fence a specific node.

- Alex

[0] https://www.isi.edu/nsnam/DIRECTED_RESEARCH/DR_WANIDA/DR/images/fast-retransmit-2.gif

author maintainer
#15 lore raw

PATCH v3 7/8 fs: dlm: add reliable connection if reconnect

In reply to Guillaume Nault

Hi,

Quoted 41 lines · Guillaume Nault
Quoted 33 lines · Alexander Ahring Oder Aring

Hi,

Quoted 1 line · Alexander Ahring Oder Aring

...

Quoted 8 lines
Quoted 7 lines

It seems to me that the only time DLM might need to retransmit data, is when recovering from a connection failure. So why can't we just resend unacknowledged data at reconnection time? That'd probably simplify the code a lot (no need to maintain a retransmission timeout on TX, no need to handle sequence numbers that are in the future on RX).

Quoted 4 lines

I can try to remove the timer, timeout and do the above approach to retransmit at reconnect. Then I test it again and I will report back to see if it works or why we have other problems.

I have an implementation of this running and so far I don't see any problems.

Quoted 4 lines
Quoted 4 lines

Also, couldn't we set the DLM sequence numbers in dlm_midcomms_commit_buffer_3_2() rather than using a callback function in dlm_lowcomms_new_buffer()?

...

Quoted 6 lines

Yes, I looked into TCP_REPAIR at first and I agree it can be used to solve this problem. However TCP_REPAIR can be used as a part of a more generic solution, there needs to be something "additional handling" done e.g. additional socket options to let the application layer save states before receiving errors. I am also concerned how it would work

Quoted 5 lines

The code [0] is what I meant above. It will call tcp_write_queue_purge(); before reporting the error over error queue/callback. That need to be handled differently to allow dumping the actual TCP state and restore at reconnect, at least that is what I have in my mind.

Quoted 6 lines

Thanks. That's not usable as is, indeed.
Also, by retransmitting data from the previous send-queue, we risk resending messages that the peer already received (for example because the previous connection didn't receive the latest ACKs). I guess that receiving the same DLM messages twice is going to confuse the peer. So it looks like we'll need application level sequence numbers anyway.

I agree, the new "retransmit all unacknowledged messages on reconnect" method will filter at the receiving side the already received messages because they have the sequence numbers, this case occurs a lot.

However I think there is still the possibility to use TCP_REPAIR here, we need to restore states about all 3 queues, rx, tx (write, retransmit) and sequence numbers. Window size is an optional additional thing. On the application layer we need to be sure that we don't drop anything if error occurs and start to transmit them after restoring the state again. Of course both endpoints need to support it and have been correctly configured.

- Alex

author maintainer
#13 lore raw

PATCH v3 7/8 fs: dlm: add reliable connection if reconnect

In reply to Guillaume Nault

Hi,

Quoted 38 lines · Guillaume Nault
Quoted 26 lines · Alexander Ahring Oder Aring

Hi,

Quoted 15 lines · Alexander Ahring Oder Aring

Hi,

Quoted 1 line · Alexander Ahring Oder Aring

...

Quoted 8 lines
Quoted 7 lines

It seems to me that the only time DLM might need to retransmit data, is when recovering from a connection failure. So why can't we just resend unacknowledged data at reconnection time? That'd probably simplify the code a lot (no need to maintain a retransmission timeout on TX, no need to handle sequence numbers that are in the future on RX).

Quoted 6 lines
Quoted 4 lines

I can try to remove the timer, timeout and do the above approach to retransmit at reconnect. Then I test it again and I will report back to see if it works or why we have other problems.

I have an implementation of this running and so far I don't see any problems.

Quoted 9 lines

There is a problem but it's related to the behaviour how reconnections are triggered. The whole communication can be stuck because the send() triggers a reconnection if not connected anymore. Before, the timer was triggering some send() and this was triggering a reconnection in a periodic way. Therefore we never had any stuck situation where nobody was sending anything anymore. It's a rare case but I am currently running into it. However I think I need to change how the reconnections are triggered with some "forever periodic try" which should solve this issue.

Quoted 3 lines

Would it be sufficient to detect socket errors to avoid this problem? For example by letting lowcomms_error_report() do the reconnection when necessary?

I have something like that as a patch for afterwards, it also contains some change in the lowcomms workqueue handling and removal of the "othercon" race paradigm. There are sometimes two connections established because of a race which I mentioned in midcomms as well for version detection. In short every node wants to connect immediately after the cluster manager reports membership to the kernel dlm implementation. However I ignored that problem of reconnection for now as it occurs never/rarely but I think it's still there.

Thanks for your review.

- Alex

author maintainer
#16 lore raw

PATCH v3 7/8 fs: dlm: add reliable connection if reconnect

In reply to Alexander Ahring Oder Aring

Hi,

Quoted 56 lines · Alexander Ahring Oder Aring

Hi,

Quoted 41 lines · Guillaume Nault
Quoted 33 lines · Alexander Ahring Oder Aring

Hi,

Quoted 1 line · Alexander Ahring Oder Aring

...

Quoted 8 lines
Quoted 7 lines

It seems to me that the only time DLM might need to retransmit data, is when recovering from a connection failure. So why can't we just resend unacknowledged data at reconnection time? That'd probably simplify the code a lot (no need to maintain a retransmission timeout on TX, no need to handle sequence numbers that are in the future on RX).

Quoted 4 lines

I can try to remove the timer, timeout and do the above approach to retransmit at reconnect. Then I test it again and I will report back to see if it works or why we have other problems.

I have an implementation of this running and so far I don't see any problems.

Quoted 4 lines
Quoted 4 lines

Also, couldn't we set the DLM sequence numbers in dlm_midcomms_commit_buffer_3_2() rather than using a callback function in dlm_lowcomms_new_buffer()?

...

Quoted 6 lines

Yes, I looked into TCP_REPAIR at first and I agree it can be used to solve this problem. However TCP_REPAIR can be used as a part of a more generic solution, there needs to be something "additional handling" done e.g. additional socket options to let the application layer save states before receiving errors. I am also concerned how it would work

Quoted 5 lines

The code [0] is what I meant above. It will call tcp_write_queue_purge(); before reporting the error over error queue/callback. That need to be handled differently to allow dumping the actual TCP state and restore at reconnect, at least that is what I have in my mind.

Quoted 6 lines

Thanks. That's not usable as is, indeed.
Also, by retransmitting data from the previous send-queue, we risk resending messages that the peer already received (for example because the previous connection didn't receive the latest ACKs). I guess that receiving the same DLM messages twice is going to confuse the peer. So it looks like we'll need application level sequence numbers anyway.

I agree, the new "retransmit all unacknowledged messages on reconnect" method will filter at the receiving side the already received messages because they have the sequence numbers, this case occurs a lot.

Quoted 7 lines

However I think there is still the possibility to use TCP_REPAIR here, we need to restore states about all 3 queues, rx, tx (write, retransmit) and sequence numbers. Window size is an optional additional thing. On the application layer we need to be sure that we don't drop anything if error occurs and start to transmit them after restoring the state again. Of course both endpoints need to support it and have been correctly configured.

I am not sure if this ends in something like "ignore some error cases in TCP", at least TCP_RST is something which seems to be triggered sometimes because "smart hardware" in the network e.g. but cable out and in again (not sure about that one). I think restoring the state might be work, but transparent proxies (haproxy, etc.) could be confused? I am not sure here...

- Alex

author maintainer
#19 lore raw

PATCH v3 7/8 fs: dlm: add reliable connection if reconnect

In reply to Alexander Ahring Oder Aring

Hi,

Quoted 14 lines · Alexander Ahring Oder Aring

Hi,

On Fri, Apr 9, 2021 at 4:32 PM Guillaume Nault <[email protected]> wrote:
...

Quoted 9 lines
Quoted 8 lines

Yes, there is one thing missing. I detected a synchronization issue because the node membership of a lockspace is done by a different protocol handled in user space. This protocol declares the actual peer of the DLM protocol. In short, there are two protocols here, whereas one handles the membership of peers and the other handles the actual operations. There is a missing synchronization between operations and membership which I solved with a DLM_FIN message.

Quoted 6 lines
Quoted 3 lines

Thanks, I'll re-read the parts about DLM_FIN with this explanation in mind.

okay. Thank you.

Additional note:

The DLM_FIN is like a 4 way close handshake with the possibility of having a half-close socket. We probably can do that on TCP with shutdown, but not on SCTP. However it's now on the application layer.

- Alex