Skip to contentSkip to conversation

fs: dlm: recovery ops and wait changes

PATCH New Alexander Aring 1 participant 4 messages Sep 15, 2021 Distributed lock manager (DLM)

lore
Share & tools
lore

Alexander Aring

author maintainer
#0 lore raw

cover fs: dlm: recovery ops and wait changes

Hi,

this patch series changes the recovery behaviour to call dlm_lsop_recover_prep() callback only once between dlm_ls_start() and dlm_ls_stop(). Currently if recovery gets interrupted by another dlm_ls_stop() it could be we calling this callback multiple times and the dlm_lsop_recover_done() was not called yet. Users might depend on the behaviour that the dlm_lsop_recover_prep() is only called once followed by a final dlm_lsop_recover_done() call.

Another change is that dlm_new_lockspace() will wait until the recovery is done. The current behaviour is that the dlm_new_lockspace() will wait until lockspace member configuration seems to be valid. After the members configuration the recovery can still get interrupted by another dlm_ls_stop() call and dlm_new_lockspace() moves on at that point when recovery is still not done yet. The most kernel users have already a wait for the dlm_lsop_recover_done() after calling dlm_new_lockspace() which is not necessary now. However the old behaviour should still work.

I tested this patch series with an experimental python bindings to libdlm. I will send soon patches which will add those bindings and test to the dlm user space software repository.

- Alex

Alexander Aring (3):
fs: dlm: add notes for recovery and membership handling
fs: dlm: call dlm_lsop_recover_prep once
fs: dlm: let new_lockspace() wait until recovery

 fs/dlm/dlm_internal.h |  4 ++--
 fs/dlm/lockspace.c    |  9 +++++----
 fs/dlm/member.c       | 30 +++++++++++++++---------------
 fs/dlm/recoverd.c     | 17 +++++++++++++++++
 4 files changed, 39 insertions(+), 21 deletions(-)
Signature · 1 line
2.27.0
author maintainer
#1 lore raw

PATCH 1/3 fs: dlm: add notes for recovery and membership handling

This patch adds some comment sections to make aware that the ls_recover() function should never fail before membership handling. Membership handling means to add/remove nodes from the lockspace ls_nodes attribute in dlm_recover_members().

This is because there are functionality like dlm_midcomms_add_member(), dlm_midcomms_remove_member() or dlm_lsop_recover_slot() which should always get aware of any join or leave of lockspace members. If we add a e.g. dlm_locking_stopped() before dlm_recover_members() to check if the recovery was interrupted and abort it we might skip to call dlm_midcomms_add_member(), dlm_midcomms_remove_member() or dlm_lsop_recover_slot().

A reason because the recovery is interrupted could be that the cluster manager notified about a new configuration .e.g. members joined or leaved. It is fine to interrupt or fail the recovery handling after the mentioned handling of dlm_recover_members() but never before.

---
 fs/dlm/member.c   | 6 +++++-
 fs/dlm/recoverd.c | 4 ++++
 2 files changed, 9 insertions(+), 1 deletion(-)
fs/dlm/member.c +5 -1
index 731d489aa323..5f5b07bdbcc3 100644
@@ -540,7 +540,11 @@ int dlm_recover_members(struct dlm_ls *ls, struct dlm_recover *rv, int *neg_out)
 	int i, error, neg = 0, low = -1;
 
 	/* previously removed members that we've not finished removing need to
-	   count as a negative change so the "neg" recovery steps will happen */
+	 * count as a negative change so the "neg" recovery steps will happen
+	 *
+	 * This functionality must report all member changes to lsops or
+	 * midcomms layer and must never return before.
+	 */
 
 	list_for_each_entry(memb, &ls->ls_nodes_gone, list) {
 		log_rinfo(ls, "prev removed member %d", memb->nodeid);
fs/dlm/recoverd.c +4 -0
index 97d052cea5a9..208b69f46baf 100644
@@ -70,6 +70,10 @@ static int ls_recover(struct dlm_ls *ls, struct dlm_recover *rv)
 
 	/*
 	 * Add or remove nodes from the lockspace's ls_nodes list.
+	 *
+	 * Due the fact we must report all membership changes to lsops or
+	 * midcomms layer it is not permitted to abort ls_recover() until
+	 * this is done.
 	 */
 
 	error = dlm_recover_members(ls, rv, &neg);
Signature · 1 line
2.27.0
author maintainer
#2 lore raw

PATCH 2/3 fs: dlm: call dlm_lsop_recover_prep once

In reply to Alexander Aring

This patch changes the behaviour of "dlm_lsop_recover_prep" callback. It will be called once when locking was stopped if it was previously running not if dlm_ls_stop() is called multiple times when locking was already stopped. Now it will be called only if a dlm_ls_start() was before.

---
 fs/dlm/member.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
fs/dlm/member.c +10 -1
index 5f5b07bdbcc3..446e1635229d 100644
@@ -685,7 +685,16 @@ int dlm_ls_stop(struct dlm_ls *ls)
 	if (!ls->ls_recover_begin)
 		ls->ls_recover_begin = jiffies;
 
-	dlm_lsop_recover_prep(ls);
+	/* call recover_prep ops only once and not multiple times
+	 * for each possible dlm_ls_stop() when recovery is already
+	 * stopped.
+	 *
+	 * If we successful was able to clear LSFL_RUNNING bit and
+	 * it was set we know it is the first dlm_ls_stop() call.
+	 */
+	if (new)
+		dlm_lsop_recover_prep(ls);
+
 	return 0;
 }
 
Signature · 1 line
2.27.0
author maintainer
#3 lore raw

PATCH 3/3 fs: dlm: let new_lockspace() wait until recovery

In reply to Alexander Aring

This patch changes the behaviour in dlm_new_lockspace() function to wait until a recovery was successful or failed. Before a possible waiter in ls_members_done was waiting until dlm_recover_members() was done either if it was successful (inclusive interrupted) or failed. The result was returned to the waiter of dlm_new_lockspace(), if success the caller was able to use the lockspace at this point.

This behaviour is now changed to wait of a complete run of recovery functionality which is done by ls_recover(). The result can be either successful or failed and delivered back to a possible waiter of ls_recovery_done. A possible waiter is then able to use the lockspace or run error handling if failed. If recovery gets interrupted e.g. checked at several places if dlm_locking_stopped() is true, a possible waiter of ls_recovery_done is still waiting until ls_recover() is successful or fails.

A reason why the recovery task gets interrupted is that an another dlm_ls_stop() was called while ls_recover() runs. The call of an another dlm_ls_stop() means that the recovery task will call ls_recover() again with a possible new configuration delivered by the cluster manager.

Most dlm kernel users e.g. gfs2 or cluster-md have their own wait handling to wait for recovery done after calling dlm_new_lockspace(). This becomes unnecessary now but still works. Users can update their code because dlm takes care about it now.

An example to simple interrupt recovery can be done by calling dlm_new_lockspace() and dlm_release_lockspace() in a loop on several cluster nodes. This has the effect that the cluster manager will interrupt the recovery with new membership information over and over again.

---
 fs/dlm/dlm_internal.h |  4 ++--
 fs/dlm/lockspace.c    |  9 +++++----
 fs/dlm/member.c       | 13 -------------
 fs/dlm/recoverd.c     | 13 +++++++++++++
 4 files changed, 20 insertions(+), 19 deletions(-)
fs/dlm/dlm_internal.h +2 -2
index 5f57538b5d45..de6c9fb5dd30 100644
@@ -610,8 +610,8 @@ struct dlm_ls {
 
 	wait_queue_head_t	ls_uevent_wait;	/* user part of join/leave */
 	int			ls_uevent_result;
-	struct completion	ls_members_done;
-	int			ls_members_result;
+	struct completion	ls_recovery_done;
+	int			ls_recovery_result;
 
 	struct miscdevice       ls_device;
 
fs/dlm/lockspace.c +5 -4
index 10eddfa6c3d7..0feffdeeb329 100644
@@ -547,8 +547,8 @@ static int new_lockspace(const char *name, const char *cluster,
 
 	init_waitqueue_head(&ls->ls_uevent_wait);
 	ls->ls_uevent_result = 0;
-	init_completion(&ls->ls_members_done);
-	ls->ls_members_result = -1;
+	init_completion(&ls->ls_recovery_done);
+	ls->ls_recovery_result = -1;
 
 	mutex_init(&ls->ls_cb_mutex);
 	INIT_LIST_HEAD(&ls->ls_cb_delay);
@@ -642,8 +642,9 @@ static int new_lockspace(const char *name, const char *cluster,
 	if (error)
 		goto out_recoverd;
 
-	wait_for_completion(&ls->ls_members_done);
-	error = ls->ls_members_result;
+	/* wait until recovery is successful or failed */
+	wait_for_completion(&ls->ls_recovery_done);
+	error = ls->ls_recovery_result;
 	if (error)
 		goto out_members;
 
fs/dlm/member.c +0 -13
index 446e1635229d..3122c5a718c4 100644
@@ -593,19 +593,6 @@ int dlm_recover_members(struct dlm_ls *ls, struct dlm_recover *rv, int *neg_out)
 	*neg_out = neg;
 
 	error = ping_members(ls);
-	/* error -EINTR means that a new recovery action is triggered.
-	 * We ignore this recovery action and let run the new one which might
-	 * have new member configuration.
-	 */
-	if (error == -EINTR)
-		error = 0;
-
-	/* new_lockspace() may be waiting to know if the config
-	 * is good or bad
-	 */
-	ls->ls_members_result = error;
-	complete(&ls->ls_members_done);
-
 	log_rinfo(ls, "dlm_recover_members %d nodes", ls->ls_num_nodes);
 	return error;
 }
fs/dlm/recoverd.c +13 -0
index 208b69f46baf..eaf310fdcb7d 100644
@@ -244,6 +244,9 @@ static int ls_recover(struct dlm_ls *ls, struct dlm_recover *rv)
 		  jiffies_to_msecs(jiffies - start));
 	mutex_unlock(&ls->ls_recoverd_active);
 
+	ls->ls_recovery_result = 0;
+	complete(&ls->ls_recovery_done);
+
 	dlm_lsop_recover_done(ls);
 	return 0;
 
@@ -252,6 +255,16 @@ static int ls_recover(struct dlm_ls *ls, struct dlm_recover *rv)
 	log_rinfo(ls, "dlm_recover %llu error %d",
 		  (unsigned long long)rv->seq, error);
 	mutex_unlock(&ls->ls_recoverd_active);
+
+	/* let new_lockspace() get aware of critical error if recovery
+	 * was interrupted -EINTR we wait for the next ls_recover()
+	 * iteration until it succeeds.
+	 */
+	if (error != -EINTR) {
+		ls->ls_recovery_result = error;
+		complete(&ls->ls_recovery_done);
+	}
+
 	return error;
 }
 
Signature · 1 line
2.27.0