drbd: cleanup decide_on_discard_support

Sanitize the calling conventions and use a goto label to cleanup the
code flow.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Christoph Böhmwalder <christoph.boehmwalder@linbit.com>
Link: https://lore.kernel.org/r/20220415045258.199825-8-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Christoph Hellwig 2022-04-15 06:52:38 +02:00 committed by Jens Axboe
parent c6f23b1a05
commit 998e9cbcd6

View File

@ -1204,38 +1204,42 @@ static unsigned int drbd_max_discard_sectors(struct drbd_connection *connection)
} }
static void decide_on_discard_support(struct drbd_device *device, static void decide_on_discard_support(struct drbd_device *device,
struct request_queue *q, struct drbd_backing_dev *bdev)
struct request_queue *b,
bool discard_zeroes_if_aligned)
{ {
/* q = drbd device queue (device->rq_queue) struct drbd_connection *connection =
* b = backing device queue (device->ldev->backing_bdev->bd_disk->queue), first_peer_device(device)->connection;
* or NULL if diskless struct request_queue *q = device->rq_queue;
*/
struct drbd_connection *connection = first_peer_device(device)->connection;
bool can_do = b ? blk_queue_discard(b) : true;
if (can_do && connection->cstate >= C_CONNECTED && !(connection->agreed_features & DRBD_FF_TRIM)) { if (bdev && !blk_queue_discard(bdev->backing_bdev->bd_disk->queue))
can_do = false; goto not_supported;
drbd_info(connection, "peer DRBD too old, does not support TRIM: disabling discards\n");
} if (connection->cstate >= C_CONNECTED &&
if (can_do) { !(connection->agreed_features & DRBD_FF_TRIM)) {
/* We don't care for the granularity, really. drbd_info(connection,
* Stacking limits below should fix it for the local "peer DRBD too old, does not support TRIM: disabling discards\n");
* device. Whether or not it is a suitable granularity goto not_supported;
* on the remote device is not our problem, really. If
* you care, you need to use devices with similar
* topology on all peers. */
blk_queue_discard_granularity(q, 512);
q->limits.max_discard_sectors = drbd_max_discard_sectors(connection);
blk_queue_flag_set(QUEUE_FLAG_DISCARD, q);
q->limits.max_write_zeroes_sectors = drbd_max_discard_sectors(connection);
} else {
blk_queue_flag_clear(QUEUE_FLAG_DISCARD, q);
blk_queue_discard_granularity(q, 0);
q->limits.max_discard_sectors = 0;
q->limits.max_write_zeroes_sectors = 0;
} }
/*
* We don't care for the granularity, really.
*
* Stacking limits below should fix it for the local device. Whether or
* not it is a suitable granularity on the remote device is not our
* problem, really. If you care, you need to use devices with similar
* topology on all peers.
*/
blk_queue_discard_granularity(q, 512);
q->limits.max_discard_sectors = drbd_max_discard_sectors(connection);
blk_queue_flag_set(QUEUE_FLAG_DISCARD, q);
q->limits.max_write_zeroes_sectors =
drbd_max_discard_sectors(connection);
return;
not_supported:
blk_queue_flag_clear(QUEUE_FLAG_DISCARD, q);
blk_queue_discard_granularity(q, 0);
q->limits.max_discard_sectors = 0;
q->limits.max_write_zeroes_sectors = 0;
} }
static void fixup_discard_if_not_supported(struct request_queue *q) static void fixup_discard_if_not_supported(struct request_queue *q)
@ -1273,7 +1277,6 @@ static void drbd_setup_queue_param(struct drbd_device *device, struct drbd_backi
unsigned int max_segments = 0; unsigned int max_segments = 0;
struct request_queue *b = NULL; struct request_queue *b = NULL;
struct disk_conf *dc; struct disk_conf *dc;
bool discard_zeroes_if_aligned = true;
if (bdev) { if (bdev) {
b = bdev->backing_bdev->bd_disk->queue; b = bdev->backing_bdev->bd_disk->queue;
@ -1282,7 +1285,6 @@ static void drbd_setup_queue_param(struct drbd_device *device, struct drbd_backi
rcu_read_lock(); rcu_read_lock();
dc = rcu_dereference(device->ldev->disk_conf); dc = rcu_dereference(device->ldev->disk_conf);
max_segments = dc->max_bio_bvecs; max_segments = dc->max_bio_bvecs;
discard_zeroes_if_aligned = dc->discard_zeroes_if_aligned;
rcu_read_unlock(); rcu_read_unlock();
blk_set_stacking_limits(&q->limits); blk_set_stacking_limits(&q->limits);
@ -1292,7 +1294,7 @@ static void drbd_setup_queue_param(struct drbd_device *device, struct drbd_backi
/* This is the workaround for "bio would need to, but cannot, be split" */ /* This is the workaround for "bio would need to, but cannot, be split" */
blk_queue_max_segments(q, max_segments ? max_segments : BLK_MAX_SEGMENTS); blk_queue_max_segments(q, max_segments ? max_segments : BLK_MAX_SEGMENTS);
blk_queue_segment_boundary(q, PAGE_SIZE-1); blk_queue_segment_boundary(q, PAGE_SIZE-1);
decide_on_discard_support(device, q, b, discard_zeroes_if_aligned); decide_on_discard_support(device, bdev);
if (b) { if (b) {
blk_stack_limits(&q->limits, &b->limits, 0); blk_stack_limits(&q->limits, &b->limits, 0);