* [PATCH 0/4] drbd: assorted fixes for discard limits, bitmap IO and resize
@ 2026-11-26 14:52 Christoph Böhmwalder
2026-11-26 14:52 ` [PATCH 1/4] drbd: assume a capable peer for the discard limit before the handshake Christoph Böhmwalder
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Christoph Böhmwalder @ 2026-11-26 14:52 UTC (permalink / raw)
To: Jens Axboe
Cc: Philipp Reisner, Lars Ellenberg, drbd-dev, linux-block,
linux-kernel, Christoph Böhmwalder
Hi Jens,
a few DRBD fixes for for-7.5/block:
- Assume a capable peer for the discard limit before the first handshake,
so devices stacked on top of DRBD don't latch the 4 MiB limit.
- Fix a lost bitmap-work wakeup on weakly ordered CPUs (seen on aarch64)
that froze application IO until the connection timed out.
- Two resize fixes: don't silently truncate the device after rejecting a
too small peer, and refuse implicit shrinks on resize unless an explicit
size is given.
Lars Ellenberg (4):
drbd: assume a capable peer for the discard limit before the handshake
drbd: fix lost bitmap-work wakeup on weakly ordered CPUs
drbd: resize: do not silently "truncate" the effective size
drbd: refuse to shrink on resize unless an explicit size is requested
drivers/block/drbd/drbd_int.h | 3 +++
drivers/block/drbd/drbd_main.c | 8 ++++++++
drivers/block/drbd/drbd_nl.c | 22 ++++++++++++----------
drivers/block/drbd/drbd_receiver.c | 5 +++++
4 files changed, 28 insertions(+), 10 deletions(-)
base-commit: 64e3fd6772bd8621a751fb916274be2f2dee3a16
--
2.56.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/4] drbd: assume a capable peer for the discard limit before the handshake
2026-11-26 14:52 [PATCH 0/4] drbd: assorted fixes for discard limits, bitmap IO and resize Christoph Böhmwalder
@ 2026-11-26 14:52 ` Christoph Böhmwalder
2026-11-26 14:52 ` [PATCH 2/4] drbd: fix lost bitmap-work wakeup on weakly ordered CPUs Christoph Böhmwalder
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Christoph Böhmwalder @ 2026-11-26 14:52 UTC (permalink / raw)
To: Jens Axboe
Cc: Philipp Reisner, Lars Ellenberg, drbd-dev, linux-block,
linux-kernel, Christoph Böhmwalder
From: Lars Ellenberg <lars.ellenberg@linbit.com>
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@linbit.com>
Signed-off-by: Christoph Böhmwalder <christoph.boehmwalder@linbit.com>
---
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/4] drbd: fix lost bitmap-work wakeup on weakly ordered CPUs
2026-11-26 14:52 [PATCH 0/4] drbd: assorted fixes for discard limits, bitmap IO and resize Christoph Böhmwalder
2026-11-26 14:52 ` [PATCH 1/4] drbd: assume a capable peer for the discard limit before the handshake Christoph Böhmwalder
@ 2026-11-26 14:52 ` Christoph Böhmwalder
2026-11-26 14:52 ` [PATCH 3/4] drbd: resize: do not silently "truncate" the effective size Christoph Böhmwalder
2026-11-26 14:52 ` [PATCH 4/4] drbd: refuse to shrink on resize unless an explicit size is requested Christoph Böhmwalder
3 siblings, 0 replies; 5+ messages in thread
From: Christoph Böhmwalder @ 2026-11-26 14:52 UTC (permalink / raw)
To: Jens Axboe
Cc: Philipp Reisner, Lars Ellenberg, drbd-dev, linux-block,
linux-kernel, Christoph Böhmwalder
From: Lars Ellenberg <lars.ellenberg@linbit.com>
drbd_queue_bitmap_io(): set_bit(BITMAP_IO); read ap_bio_cnt (req_lock)
dec_ap_bio(): dec ap_bio_cnt; test_bit(BITMAP_IO)
Both sites decide whether to queue the whole-bitmap work by inspecting
the same two locations in opposite order. dec_ap_bio() does not take
req_lock, so the lock gives no mutual exclusion between them. On a
weakly ordered CPU the queue-side set_bit/atomic_read store-load pair
may reorder, so both sites read the other's pre-update value and neither
queues the work. BITMAP_IO then stays set and application IO is frozen
until the connection times out.
Observed on aarch64: a source-side reconnect parks in WFBitMapS,
drbd_send_bitmap never runs (no "send bitmap stats", no WFBitMapS ->
SyncSource), database threads hang in fdatasync/writeback. Not
reproducible on x86, where set_bit() is a full barrier.
Order the BITMAP_IO store before the ap_bio_cnt load.
atomic_dec_return() already orders the dec_ap_bio() side.
Commit 22afd7ee94c1 ("drbd: Fixed race condition in
drbd_queue_bitmap_io") added the req_lock on the queue side only; it
does not close this reorder.
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
Signed-off-by: Christoph Böhmwalder <christoph.boehmwalder@linbit.com>
---
drivers/block/drbd/drbd_int.h | 3 +++
drivers/block/drbd/drbd_main.c | 8 ++++++++
2 files changed, 11 insertions(+)
diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
index 40be382b24d2..20899a0d7e45 100644
--- a/drivers/block/drbd/drbd_int.h
+++ b/drivers/block/drbd/drbd_int.h
@@ -2213,6 +2213,9 @@ static inline void dec_ap_bio(struct drbd_device *device)
D_ASSERT(device, ap_bio >= 0);
+ /* atomic_dec_return() above orders this against the
+ * set_bit(BITMAP_IO) / ap_bio_cnt read in drbd_queue_bitmap_io().
+ */
if (ap_bio == 0 && test_bit(BITMAP_IO, &device->flags)) {
if (!test_and_set_bit(BITMAP_IO_QUEUED, &device->flags))
drbd_queue_work(&first_peer_device(device)->
diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
index aed1d1ab6d0f..fd83fc492a79 100644
--- a/drivers/block/drbd/drbd_main.c
+++ b/drivers/block/drbd/drbd_main.c
@@ -3497,6 +3497,14 @@ void drbd_queue_bitmap_io(struct drbd_device *device,
spin_lock_irq(&device->resource->req_lock);
set_bit(BITMAP_IO, &device->flags);
+ /* Pair with atomic_dec_return() in dec_ap_bio(): order this BITMAP_IO
+ * store before the ap_bio_cnt load below. dec_ap_bio() decrements
+ * ap_bio_cnt and then tests BITMAP_IO in the reverse order. Without
+ * this barrier, on weakly ordered CPUs both sites may observe the
+ * other's stale value, so neither queues the bitmap work: BITMAP_IO
+ * stays set and application IO freezes.
+ */
+ smp_mb__after_atomic();
/* don't wait for pending application IO if the caller indicates that
* application IO does not conflict anyways. */
if (flags == BM_LOCKED_CHANGE_ALLOWED || atomic_read(&device->ap_bio_cnt) == 0) {
--
2.56.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 3/4] drbd: resize: do not silently "truncate" the effective size
2026-11-26 14:52 [PATCH 0/4] drbd: assorted fixes for discard limits, bitmap IO and resize Christoph Böhmwalder
2026-11-26 14:52 ` [PATCH 1/4] drbd: assume a capable peer for the discard limit before the handshake Christoph Böhmwalder
2026-11-26 14:52 ` [PATCH 2/4] drbd: fix lost bitmap-work wakeup on weakly ordered CPUs Christoph Böhmwalder
@ 2026-11-26 14:52 ` Christoph Böhmwalder
2026-11-26 14:52 ` [PATCH 4/4] drbd: refuse to shrink on resize unless an explicit size is requested Christoph Böhmwalder
3 siblings, 0 replies; 5+ messages in thread
From: Christoph Böhmwalder @ 2026-11-26 14:52 UTC (permalink / raw)
To: Jens Axboe
Cc: Philipp Reisner, Lars Ellenberg, drbd-dev, linux-block,
linux-kernel, Christoph Böhmwalder
From: Lars Ellenberg <lars.ellenberg@linbit.com>
During the connection handshake, a node with an established "effective"
(aka last agreed to) size can detect that a peer has a "too small"
backing disk, and refuse to connect to that peer.
Unfortunately it still "caches" the maximum size that peer could
support. We remember that size so we could still grow to an agreeable
size on an unconnected node, if this node's backend size was the
limiting factor and the peer was known to be able to support more.
Now, if we remember a size we rejected because it was too small, that
same logic will silently truncate our own size if we are asked to
"resize" before that cached information is properly reset (by taking
DRBD down/up, or by connecting to a peer that has a backing device of
sufficient size).
Workaround: only ask DRBD to resize when the connection to the peer is
fully established.
Fix: reset that cached size to zero in the moment we refuse the
connection.
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
Signed-off-by: Christoph Böhmwalder <christoph.boehmwalder@linbit.com>
---
drivers/block/drbd/drbd_receiver.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index 101192d8398f..9cc41bc07ae5 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -3931,6 +3931,11 @@ static int receive_sizes(struct drbd_connection *connection, struct packet_info
(device->state.conn < C_CONNECTED || device->state.pdsk == D_DISKLESS)) {
drbd_err(device, "The peer's disk size is too small! (%llu < %llu sectors)\n",
(unsigned long long)new_size, (unsigned long long)cur_size);
+ /* We rejected that size, reset to zero so it won't
+ * confuse the aggregation with min_not_zero() if
+ * someone requests a resize later.
+ */
+ device->p_size = 0;
conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD);
put_ldev(device);
return -EIO;
--
2.56.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 4/4] drbd: refuse to shrink on resize unless an explicit size is requested
2026-11-26 14:52 [PATCH 0/4] drbd: assorted fixes for discard limits, bitmap IO and resize Christoph Böhmwalder
` (2 preceding siblings ...)
2026-11-26 14:52 ` [PATCH 3/4] drbd: resize: do not silently "truncate" the effective size Christoph Böhmwalder
@ 2026-11-26 14:52 ` Christoph Böhmwalder
3 siblings, 0 replies; 5+ messages in thread
From: Christoph Böhmwalder @ 2026-11-26 14:52 UTC (permalink / raw)
To: Jens Axboe
Cc: Philipp Reisner, Lars Ellenberg, drbd-dev, linux-block,
linux-kernel, Christoph Böhmwalder
From: Lars Ellenberg <lars.ellenberg@linbit.com>
There is a check for implicit shrinking, but it was only active
when _also_ changing the activity log on disk layout.
Make it active always.
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
Signed-off-by: Christoph Böhmwalder <christoph.boehmwalder@linbit.com>
---
drivers/block/drbd/drbd_nl.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
index efa6e46326a2..5c8a3ab326d7 100644
--- a/drivers/block/drbd/drbd_nl.c
+++ b/drivers/block/drbd/drbd_nl.c
@@ -981,7 +981,7 @@ drbd_determine_dev_size(struct drbd_device *device, enum dds_flags flags, struct
struct drbd_md *md = &device->ldev->md;
void *buffer;
- int md_moved, la_size_changed;
+ bool md_moved, la_size_changed, al_layout_changed;
enum determine_dev_size rv = DS_UNCHANGED;
/* We may change the on-disk offsets of our meta data below. Lock out
@@ -1009,7 +1009,6 @@ drbd_determine_dev_size(struct drbd_device *device, enum dds_flags flags, struct
prev.al_stripe_size_4k = md->al_stripe_size_4k;
if (rs) {
- /* rs is non NULL if we should change the AL layout only */
md->al_stripes = rs->al_stripes;
md->al_stripe_size_4k = rs->al_stripe_size / 4;
md->al_size_4k = (u64)rs->al_stripes * rs->al_stripe_size / 4;
@@ -1064,8 +1063,11 @@ drbd_determine_dev_size(struct drbd_device *device, enum dds_flags flags, struct
md_moved = prev.md_offset != md->md_offset
|| prev.md_size_sect != md->md_size_sect;
+ al_layout_changed =
+ prev.al_stripes != md->al_stripes
+ || prev.al_stripe_size_4k != md->al_stripe_size_4k;
- if (la_size_changed || md_moved || rs) {
+ if (la_size_changed || md_moved || al_layout_changed) {
u32 prev_flags;
/* We do some synchronous IO below, which may take some time.
@@ -1098,7 +1100,7 @@ drbd_determine_dev_size(struct drbd_device *device, enum dds_flags flags, struct
md->flags = prev_flags;
drbd_md_write(device, buffer);
- if (rs)
+ if (al_layout_changed)
drbd_info(device, "Changed AL layout to al-stripes = %d, al-stripe-size-kB = %d\n",
md->al_stripes, md->al_stripe_size_4k * 4);
}
@@ -2861,7 +2863,6 @@ int drbd_nl_resize_doit(struct sk_buff *skb, struct genl_info *info)
struct drbd_device *device;
enum drbd_ret_code retcode;
enum determine_dev_size dd;
- bool change_al_layout = false;
enum dds_flags ddsf;
sector_t u_size;
int err;
@@ -2936,8 +2937,6 @@ int drbd_nl_resize_doit(struct sk_buff *skb, struct genl_info *info)
retcode = ERR_MD_LAYOUT_CONNECTED;
goto fail_ldev;
}
-
- change_al_layout = true;
}
if (device->ldev->known_size != drbd_get_capacity(device->ldev->backing_bdev))
@@ -2955,7 +2954,7 @@ int drbd_nl_resize_doit(struct sk_buff *skb, struct genl_info *info)
}
ddsf = (rs.resize_force ? DDSF_FORCED : 0) | (rs.no_resync ? DDSF_NO_RESYNC : 0);
- dd = drbd_determine_dev_size(device, ddsf, change_al_layout ? &rs : NULL);
+ dd = drbd_determine_dev_size(device, ddsf, &rs);
drbd_md_sync(device);
put_ldev(device);
if (dd == DS_ERROR) {
--
2.56.0
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-26 14:53 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-26 14:52 [PATCH 0/4] drbd: assorted fixes for discard limits, bitmap IO and resize Christoph Böhmwalder
2026-11-26 14:52 ` [PATCH 1/4] drbd: assume a capable peer for the discard limit before the handshake Christoph Böhmwalder
2026-11-26 14:52 ` [PATCH 2/4] drbd: fix lost bitmap-work wakeup on weakly ordered CPUs Christoph Böhmwalder
2026-11-26 14:52 ` [PATCH 3/4] drbd: resize: do not silently "truncate" the effective size Christoph Böhmwalder
2026-11-26 14:52 ` [PATCH 4/4] drbd: refuse to shrink on resize unless an explicit size is requested Christoph Böhmwalder
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®