Distributed Replicated Block Device (DRBD) development
 help / color / mirror / Atom feed
From: Kitae Yoo <ryugitae777@gmail.com>
To: drbd-dev@lists.linux.dev
Subject: [RFC PATCH] drbd: re-announce peers-in-sync when an absent peer returns
Date: Mon, 30 Nov 2026 16:03:39 +0900	[thread overview]
Message-ID: <20261130070339.62536-1-ryugitae777@gmail.com> (raw)

A resync target marks the blocks it receives out of sync towards all
its other peers (drbd_set_all_out_of_sync()). Those placeholder bits
are retired only by a P_PEERS_IN_SYNC from the resync source that
names the other peer, and the source names a peer only if
bits_in_sync() holds, which needs the peer to be connected right now.
If the source's link to that peer is down while the resync runs,
nothing names it later, and the bits stay on an Established, UpToDate
pair until that pair reconnects (the handshake then drops them with
"no-sync by rule=reconnected").

The data is not at risk: online verify finds no differences. But the
out-of-sync count is wrong for as long as the pair stays connected,
which is what monitoring and tools read.

Reproduction, 3 diskful nodes A, B, C, 10G volume, quorum off, one run
is enough:

  1. C disconnects from A and B
  2. A primary, writes 512M (dd oflag=direct), secondary
  3. A disconnects B
  4. C connects B, pause-sync on C towards B
  5. C connects A (C becomes SyncTarget of A; towards B it stays
     PausedSyncT, by dependency after step 6)
  6. resume-sync on C towards B
  7. when A->C finishes, the PausedSyncT towards B is cancelled with
     its bits left (__cancel_other_resyncs())
  8. A connects B (no-sync, both UpToDate)

Result: all three UpToDate and Established, but C->B shows 524288 KiB
out of sync and B->C 256768 KiB, and they stay there.

This patch lets the source remember, per resync target, the peers it
had to leave out because they were not connected, and the range it
was announcing. When one of them becomes Established again,
w_after_state_change() runs the same in-sync announcement again over
that range for each such target. update_peers_for_interval() checks
the bitmaps again at that point, under the same interval lock and AL
check, so a range written while the peer was away is not named. The
record is in memory only and is dropped when the target disconnects.

Results on DRBD 9.3.4 (the patch applies to master and the changed
files compile there), kernel 7.0.0-43, LINSTOR:

  reproduction above:  C->B 524288 KiB -> 0, B->C 256768 KiB -> 0,
                       no additional resync; both sources logged the
                       re-announcement
  A writes 64M while B is isolated from A and C, inside and outside
  the re-announced range, then A and B reconnect: only the 64M is
  resynced, then the re-announcement runs; online verify C-B and A-B
  finds no differences in both cases
  regression run with the pull-ahead workload (2 cycles): no bits left

Known limits:
  - the record does not survive a restart of the source; the bits then
    stay until the next reconnect, as today
  - one min..max range per target; a wide range only costs extra
    bitmap checks
  - tested with 3 diskful nodes only

Questions:
  1. Is w_after_state_change() the right place, or would you rather
     hook this into the handshake path?
  2. Should the source track this at all, or should the holder of the
     placeholder bits ask for a re-announcement (that would need a new
     packet but survives a restart of the source)?

Signed-off-by: Kitae Yoo <ryugitae777@gmail.com>
---
 drbd/drbd_int.h      |  7 ++++++
 drbd/drbd_receiver.c | 56 +++++++++++++++++++++++++++++++++++++++++++-
 drbd/drbd_state.c    |  7 ++++++
 3 files changed, 69 insertions(+), 1 deletion(-)

diff --git a/drbd/drbd_int.h b/drbd/drbd_int.h
--- a/drbd/drbd_int.h
+++ b/drbd/drbd_int.h
@@ -1695,6 +1695,12 @@
 	enum drbd_disk_state resync_finished_pdsk; /* Finished while starting resync */
 	int resync_again; /* decided to resync again while resync running */
 	sector_t last_in_sync_end; /* sector after end of last completed resync request */
+	/* Peers that were away when we told this peer which of its bits were in
+	 * sync, and the range we told it about. When one of them is back and
+	 * Established, we tell this peer again: its bits towards that peer may
+	 * be placeholders only we can retire. Resource worker only. */
+	u64 revouch_mask;
+	sector_t revouch_start, revouch_end;
 	unsigned long resync_next_bit; /* bitmap bit to search from for next resync request */
 	unsigned long last_resync_pass_bits; /* bitmap weight at end of previous pass */
 
@@ -2865,6 +2871,7 @@
 };
 
 
+void drbd_revouch_for_returned_peer(struct drbd_peer_device *returned);
 void drbd_queue_update_peers(struct drbd_peer_device *peer_device,
 			     sector_t sector_start, sector_t sector_end);
 int drbd_issue_discard_or_zero_out(struct drbd_device *device, sector_t start,
diff --git a/drbd/drbd_receiver.c b/drbd/drbd_receiver.c
--- a/drbd/drbd_receiver.c
+++ b/drbd/drbd_receiver.c
@@ -2804,8 +2804,23 @@
 		if (p == peer_device)
 			continue;
 
-		if (bits_in_sync(p, interval->sector, sector_end))
+		if (bits_in_sync(p, interval->sector, sector_end)) {
 			mask |= NODE_MASK(p->node_id);
+		} else if (p->connection->cstate[NOW] < C_CONNECTED) {
+			/* We cannot speak for an absent peer now; remember to
+			 * once it is back. */
+			if (!peer_device->revouch_mask) {
+				peer_device->revouch_start = interval->sector;
+				peer_device->revouch_end = sector_end;
+			} else {
+				peer_device->revouch_start = min(peer_device->revouch_start, interval->sector);
+				peer_device->revouch_end = max(peer_device->revouch_end, sector_end);
+			}
+			if (!(peer_device->revouch_mask & NODE_MASK(p->node_id)))
+				drbd_info(peer_device, "peer %d absent, will re-announce in-sync when it is back\n",
+					  p->node_id);
+			peer_device->revouch_mask |= NODE_MASK(p->node_id);
+		}
 	}
 
 	for_each_peer_device_ref(p, im, device) {
@@ -2879,6 +2894,45 @@
 	}
 
 	put_ldev(device);
+}
+
+/*
+ * A peer is Established again. Placeholder bits that a resync target set
+ * towards it while it was away are retired only by P_PEERS_IN_SYNC from the
+ * resync source naming it, and the source left it out then (bits_in_sync()
+ * needs the peer connected). Now it can be named: re-run the in-sync
+ * announcement over the range we covered. update_peers_for_interval() checks
+ * the bits again, so blocks written while the peer was away are not named.
+ * Called from w_after_state_change(), on the resource worker.
+ */
+void drbd_revouch_for_returned_peer(struct drbd_peer_device *returned)
+{
+	struct drbd_device *device = returned->device;
+	u64 m = NODE_MASK(returned->node_id);
+	struct drbd_peer_device *q;
+	u64 im;
+
+	if (returned->repl_state[NOW] != L_ESTABLISHED ||
+	    device->disk_state[NOW] != D_UP_TO_DATE)
+		return;
+
+	for_each_peer_device_ref(q, im, device) {
+		sector_t start, end;
+
+		if (q == returned || !(q->revouch_mask & m))
+			continue;
+		q->revouch_mask &= ~m;
+		start = q->revouch_start;
+		end = q->revouch_end;
+		if (q->repl_state[NOW] != L_ESTABLISHED ||
+		    q->disk_state[NOW] != D_UP_TO_DATE ||
+		    q->connection->agreed_pro_version < 110)
+			continue;
+		drbd_info(q, "re-announcing in-sync %llu..%llu, peer %d is back\n",
+			  (unsigned long long)start, (unsigned long long)end,
+			  returned->node_id);
+		update_peers_for_range(q, start, end);
+	}
 }
 
 static int w_update_peers(struct drbd_work *w, int unused)
diff --git a/drbd/drbd_state.c b/drbd/drbd_state.c
--- a/drbd/drbd_state.c
+++ b/drbd/drbd_state.c
@@ -5163,6 +5163,13 @@
 			if (repl_state[OLD] == L_OFF && repl_state[NEW] >= L_ESTABLISHED)
 				send_state = true;
 
+			/* A peer is Established and in sync again: name it to the
+			 * peers we left it out for. A peer gone forgets that. */
+			if (repl_state[OLD] != L_ESTABLISHED && repl_state[NEW] == L_ESTABLISHED)
+				drbd_revouch_for_returned_peer(peer_device);
+			if (repl_state[NEW] == L_OFF)
+				peer_device->revouch_mask = 0;
+
 			if (repl_state[OLD] != L_AHEAD && repl_state[NEW] == L_AHEAD)
 				send_state = true;
 

                 reply	other threads:[~2026-11-30  7:03 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261130070339.62536-1-ryugitae777@gmail.com \
    --to=ryugitae777@gmail.com \
    --cc=drbd-dev@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox