Skip to contentSkip to conversation

drbd: fix resync stall when P_RS_CANCEL_AHEAD overtakes the state change

PATCH New Kitae Yoo 1 participant 1 message Nov 2 DRBD driver

lore
Share & tools
lore

Kitae Yoo

author
#0 lore raw

PATCH 1/1 drbd: fix resync stall when P_RS_CANCEL_AHEAD overtakes the state change

When the sync source pulls ahead (on-congestion pull-ahead) during a resync, it answers pending resync requests with P_RS_CANCEL_AHEAD on the control socket and sends its Ahead state change on the data socket. The two sockets are not ordered, so the cancel can arrive first. got_NegRSDReply() then sets SYNC_TARGET_TO_BEHIND while we are still L_SYNC_TARGET, and make_resync_request() returns early without re-arming resync_timer. Nothing else re-arms it.

This ends in a permanent stall in two ways:

1) The Ahead state arrives and we become Behind. With resync_timer dead, w_resync_timer() never runs the branch that clears resync_active. When the peer returns to SyncSource, the "resync-after-behind" start is postponed forever by do_start_resync() because resync_active is still set ("postponing start_resync" repeats).

2) A previously postponed resync start fires while the peer is Ahead again, so we become SyncTarget and the peer cancels our requests. The flag is set while we are SyncTarget. When the peer returns to SyncSource we never left SyncTarget, so neither the non-sync -> sync transition that clears the flag nor the "resync-after-behind" path (old peer state L_BEHIND) is taken.

In both cases the connection stays up, out-of-sync stays constant and no resync traffic flows. Only a disconnect/connect recovers.

Fix both:
- Keep re-arming resync_timer on the early return, so that once we are Behind, w_resync_timer() clears resync_active as intended.
- In receive_state(), when the peer reports SyncSource while we are SyncTarget with SYNC_TARGET_TO_BEHIND set, clear the flag and kick resync_timer.

This does not remove the reordering itself, which would need a protocol change; it makes the target recover from it.

---

Notes:
Environment:
DRBD 9.3.4 (Ubuntu PPA 9.3.4-1ppa1~noble1), kernel 6.8.0-124-generic, 2 nodes, protocol A, on-congestion pull-ahead, congestion-fill 8M, sndbuf-size 10M, max-buffers 20000, c-max-rate 200M.
Link: WireGuard tunnel (MTU 1280) between two sites. Resources managed by LINSTOR.

Reproduction:
On the primary, repeated bursts of 64k random writes (fio, iodepth 16, 20s on / 5s off) on a 5G volume, so the source repeatedly pulls ahead while a resync from the previous burst is still running.

Unpatched (both nodes): 2 stalls in one run; each needed a disconnect/connect to recover. Earlier runs showed the same, with "postponing start_resync" repeating on the target.

Patched module on the sync target only (source unpatched), two runs of 40 bursts each:
- source went Ahead 15 times, 13 of them during a resync
- "peer pulled ahead during resync" logged 5 times on the target:
2 with the case 1 order (pulled ahead -> SyncTarget->Behind ~1s later -> Behind->SyncTarget the next second), 3 with the case 2 order, each followed within 1s by "peer back from ahead, resuming resync requests"
- 0 stalls; resync finished each time shortly after the last burst
- no warnings or oopses in the kernel log

Not covered: the patched node acting as sync source, and >2 nodes.

Side note, not addressed by this patch: while we are SyncTarget, a stale queued start_resync keeps logging "postponing start_resync" about every 100ms (~1900 lines in 3 minutes in one run). An alternative/additional approach would be to drop such a stale start once we are already SyncTarget, or to not start the resync while the peer is still Ahead.

 drbd/drbd_receiver.c | 12 ++++++++++++
 drbd/drbd_sender.c   |  6 +++++-
 2 files changed, 17 insertions(+), 1 deletion(-)
drbd/drbd_receiver.c +12 -0
index 51a61fbc3..357c3aafa 100644
@@ -10569,6 +10569,18 @@ static int receive_state(struct drbd_connection *connection, struct packet_info
 		return 0;
 	}
 
+	/* The peer pulled ahead and came back while we stayed SyncTarget
+	 * (its P_RS_CANCEL_AHEAD outran the Ahead state change), so the
+	 * SyncTarget -> Behind -> SyncTarget path that would clear the flag
+	 * is never taken.  Clear it here and resume issuing requests.
+	 */
+	if (peer_state.conn == L_SYNC_SOURCE &&
+	    peer_device->repl_state[NOW] == L_SYNC_TARGET &&
+	    test_and_clear_bit(SYNC_TARGET_TO_BEHIND, peer_device->flags)) {
+		drbd_info(peer_device, "peer back from ahead, resuming resync requests\n");
+		mod_timer(&peer_device->resync_timer, jiffies + RS_MAKE_REQS_INTV);
+	}
+
 	/* Start resync after AHEAD/BEHIND */
 	if (connection->agreed_pro_version >= 110 &&
 	    peer_state.conn == L_SYNC_SOURCE && old_peer_state.conn == L_BEHIND) {
drbd/drbd_sender.c +5 -1
index 5c27980d8..a6d1be578 100644
@@ -1390,8 +1390,12 @@ static int make_resync_request(struct drbd_peer_device *peer_device, int cancel)
 	if (test_bit(SYNC_TARGET_TO_BEHIND, peer_device->flags)) {
 		/* If a P_RS_CANCEL_AHEAD on control socket overtook the
 		 * already queued data and state change to Ahead/Behind,
-		 * don't add more resync requests, just wait it out. */
+		 * don't add more resync requests, just wait it out.
+		 * Keep polling: once we are Behind, w_resync_timer() clears
+		 * resync_active; nothing else re-arms this timer.
+		 */
 		drbd_info_ratelimit(peer_device, "peer pulled ahead during resync\n");
+		mod_timer(&peer_device->resync_timer, jiffies + RS_MAKE_REQS_INTV);
 		return 0;
 	}
 	if (!get_ldev(device)) {
Signature · 1 line
2.50.1 (Apple Git-155)