[PATCH 1/4] drbd: assume a capable peer for the discard limit before the handshake
From: Christoph Böhmwalder
Date: Thu Nov 26 2026 - 09:53:12 EST
From: Lars Ellenberg <lars.ellenberg@xxxxxxxxxx>
Before the first handshake, agreed_features is 0, so
drbd_max_discard_sectors() limits discards to 4 MiB, the limit for
peers without WRITE_SAME support. Devices stacked on top of DRBD copy
that limit at setup and keep it, even after DRBD connects to a capable
peer and allows 128 MiB.
Assume a capable peer until a handshake has completed. If the
handshake finds an incapable peer, receive_sizes() lowers the limit
again before DRBD sends any request to that peer.
A discard that DRBD split at 128 MiB before the handshake, and that
DRBD submits to an incapable peer after it, exceeds the peer's limit.
The peer then drops the connection, and the resync after the reconnect
covers the range. A module parameter that rejects incapable peers
would avoid this, but adds a permanent interface for a rare case.
Signed-off-by: Lars Ellenberg <lars.ellenberg@xxxxxxxxxx>
Signed-off-by: Christoph Böhmwalder <christoph.boehmwalder@xxxxxxxxxx>
---
drivers/block/drbd/drbd_nl.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
index 3511a943e4b1..efa6e46326a2 100644
--- a/drivers/block/drbd/drbd_nl.c
+++ b/drivers/block/drbd/drbd_nl.c
@@ -1257,8 +1257,11 @@ static unsigned int drbd_max_peer_bio_size(struct drbd_device *device)
static unsigned int drbd_max_discard_sectors(struct drbd_connection *connection)
{
/* when we introduced REQ_WRITE_SAME support, we also bumped
- * our maximum supported batch bio size used for discards. */
- if (connection->agreed_features & DRBD_FF_WSAME)
+ * our maximum supported batch bio size used for discards.
+ * Until a handshake completed, assume a capable peer.
+ */
+ if (connection->agreed_pro_version < PRO_VERSION_MIN ||
+ connection->agreed_features & DRBD_FF_WSAME)
return DRBD_MAX_BBIO_SECTORS;
/* before, with DRBD <= 8.4.6, we only allowed up to one AL_EXTENT_SIZE. */
return AL_EXTENT_SIZE >> 9;
--
2.56.0