From 5eaee6e9c8f9940ecee93678972774fb8dd450d5 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Wed, 6 Mar 2024 15:03:31 +0100 Subject: [PATCH] drbd: split out a drbd_discard_supported helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a helper to check if discard is supported for a given connection / backing device combination. Signed-off-by: Christoph Hellwig Reviewed-by: Philipp Reisner Reviewed-by: Lars Ellenberg Tested-by: Christoph Böhmwalder Link: https://lore.kernel.org/r/20240306140332.623759-7-philipp.reisner@linbit.com Signed-off-by: Jens Axboe --- drivers/block/drbd/drbd_nl.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c index a79b7fe5335d..94ed2b3ea636 100644 --- a/drivers/block/drbd/drbd_nl.c +++ b/drivers/block/drbd/drbd_nl.c @@ -1231,6 +1231,22 @@ static unsigned int drbd_max_discard_sectors(struct drbd_connection *connection) return AL_EXTENT_SIZE >> 9; } +static bool drbd_discard_supported(struct drbd_connection *connection, + struct drbd_backing_dev *bdev) +{ + if (bdev && !bdev_max_discard_sectors(bdev->backing_bdev)) + return false; + + if (connection->cstate >= C_CONNECTED && + !(connection->agreed_features & DRBD_FF_TRIM)) { + drbd_info(connection, + "peer DRBD too old, does not support TRIM: disabling discards\n"); + return false; + } + + return true; +} + static void decide_on_discard_support(struct drbd_device *device, struct drbd_backing_dev *bdev) { @@ -1239,16 +1255,9 @@ static void decide_on_discard_support(struct drbd_device *device, struct request_queue *q = device->rq_queue; unsigned int max_discard_sectors; - if (bdev && !bdev_max_discard_sectors(bdev->backing_bdev)) + if (!drbd_discard_supported(connection, bdev)) goto not_supported; - if (connection->cstate >= C_CONNECTED && - !(connection->agreed_features & DRBD_FF_TRIM)) { - drbd_info(connection, - "peer DRBD too old, does not support TRIM: disabling discards\n"); - goto not_supported; - } - /* * We don't care for the granularity, really. *