From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: dm-devel@redhat.com, linux-xfs@vger.kernel.org,
linux-fsdevel@vger.kernel.org, linux-um@lists.infradead.org,
linux-block@vger.kernel.org, drbd-dev@lists.linbit.com,
nbd@other.debian.org, ceph-devel@vger.kernel.org,
virtualization@lists.linux-foundation.org,
xen-devel@lists.xenproject.org, linux-bcache@vger.kernel.org,
linux-raid@vger.kernel.org, linux-mmc@vger.kernel.org,
linux-mtd@lists.infradead.org, linux-nvme@lists.infradead.org,
linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org,
target-devel@vger.kernel.org, linux-btrfs@vger.kernel.org,
linux-ext4@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com,
jfs-discussion@lists.sourceforge.net,
linux-nilfs@vger.kernel.org, ntfs3@lists.linux.dev,
ocfs2-devel@oss.oracle.com, linux-mm@kvack.org,
"Christoph Böhmwalder" <christoph.boehmwalder@linbit.com>
Subject: [PATCH 07/27] drbd: cleanup decide_on_discard_support
Date: Fri, 15 Apr 2022 06:52:38 +0200 [thread overview]
Message-ID: <20220415045258.199825-8-hch@lst.de> (raw)
In-Reply-To: <20220415045258.199825-1-hch@lst.de>
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>
---
drivers/block/drbd/drbd_nl.c | 68 +++++++++++++++++++-----------------
1 file changed, 35 insertions(+), 33 deletions(-)
diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
index b7216c186ba4d..4d00986d6f588 100644
--- a/drivers/block/drbd/drbd_nl.c
+++ b/drivers/block/drbd/drbd_nl.c
@@ -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,
- struct request_queue *q,
- struct request_queue *b,
- bool discard_zeroes_if_aligned)
+ struct drbd_backing_dev *bdev)
{
- /* q = drbd device queue (device->rq_queue)
- * b = backing device queue (device->ldev->backing_bdev->bd_disk->queue),
- * or NULL if diskless
- */
- 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)) {
- can_do = false;
- drbd_info(connection, "peer DRBD too old, does not support TRIM: disabling discards\n");
- }
- if (can_do) {
- /* 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);
- } 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;
+ struct drbd_connection *connection =
+ first_peer_device(device)->connection;
+ struct request_queue *q = device->rq_queue;
+
+ if (bdev && !blk_queue_discard(bdev->backing_bdev->bd_disk->queue))
+ 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.
+ *
+ * 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)
@@ -1273,7 +1277,6 @@ static void drbd_setup_queue_param(struct drbd_device *device, struct drbd_backi
unsigned int max_segments = 0;
struct request_queue *b = NULL;
struct disk_conf *dc;
- bool discard_zeroes_if_aligned = true;
if (bdev) {
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();
dc = rcu_dereference(device->ldev->disk_conf);
max_segments = dc->max_bio_bvecs;
- discard_zeroes_if_aligned = dc->discard_zeroes_if_aligned;
rcu_read_unlock();
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" */
blk_queue_max_segments(q, max_segments ? max_segments : BLK_MAX_SEGMENTS);
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) {
blk_stack_limits(&q->limits, &b->limits, 0);
--
2.30.2
next prev parent reply other threads:[~2022-04-15 4:54 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-15 4:52 use block_device based APIs in block layer consumers v3 Christoph Hellwig
2022-04-15 4:52 ` [PATCH 01/27] target: remove an incorrect unmap zeroes data deduction Christoph Hellwig
2022-04-15 5:36 ` Chaitanya Kulkarni
2022-04-15 4:52 ` [PATCH 02/27] target: pass a block_device to target_configure_unmap_from_queue Christoph Hellwig
2022-04-15 5:38 ` Chaitanya Kulkarni
2022-04-15 4:52 ` [PATCH 03/27] target: fix discard alignment on partitions Christoph Hellwig
2022-04-15 5:39 ` Chaitanya Kulkarni
2022-04-15 4:52 ` [PATCH 04/27] drbd: remove assign_p_sizes_qlim Christoph Hellwig
2022-04-15 4:52 ` [PATCH 05/27] drbd: use bdev based limit helpers in drbd_send_sizes Christoph Hellwig
2022-04-15 4:52 ` [PATCH 06/27] drbd: use bdev_alignment_offset instead of queue_alignment_offset Christoph Hellwig
2022-04-15 4:52 ` Christoph Hellwig [this message]
2022-04-15 4:52 ` [PATCH 08/27] btrfs: use bdev_max_active_zones instead of open coding it Christoph Hellwig
2022-04-15 5:40 ` Chaitanya Kulkarni
2022-04-19 12:02 ` Anand Jain
2022-04-15 4:52 ` [PATCH 09/27] ntfs3: use bdev_logical_block_size " Christoph Hellwig
2022-04-15 4:52 ` [PATCH 10/27] mm: use bdev_is_zoned in claim_swapfile Christoph Hellwig
2022-04-15 5:09 ` Damien Le Moal
2022-04-15 5:40 ` Chaitanya Kulkarni
2022-04-15 4:52 ` [PATCH 11/27] block: add a bdev_nonrot helper Christoph Hellwig
2022-04-15 5:41 ` Chaitanya Kulkarni
2022-04-15 4:52 ` [PATCH 12/27] block: add a bdev_write_cache helper Christoph Hellwig
2022-04-15 5:41 ` Chaitanya Kulkarni
2022-04-15 4:52 ` [PATCH 13/27] block: add a bdev_fua helper Christoph Hellwig
2022-04-15 5:42 ` Chaitanya Kulkarni
2022-04-15 4:52 ` [PATCH 14/27] block: add a bdev_stable_writes helper Christoph Hellwig
2022-04-15 5:42 ` Chaitanya Kulkarni
2022-04-15 4:52 ` [PATCH 15/27] block: add a bdev_max_zone_append_sectors helper Christoph Hellwig
2022-04-15 5:43 ` Chaitanya Kulkarni
2022-04-15 4:52 ` [PATCH 16/27] block: use bdev_alignment_offset in part_alignment_offset_show Christoph Hellwig
2022-04-15 5:43 ` Chaitanya Kulkarni
2022-04-15 4:52 ` [PATCH 17/27] block: use bdev_alignment_offset in disk_alignment_offset_show Christoph Hellwig
2022-04-15 4:52 ` [PATCH 18/27] block: move bdev_alignment_offset and queue_limit_alignment_offset out of line Christoph Hellwig
2022-04-15 4:52 ` [PATCH 19/27] block: remove queue_discard_alignment Christoph Hellwig
2022-04-15 4:52 ` [PATCH 20/27] block: use bdev_discard_alignment in part_discard_alignment_show Christoph Hellwig
2022-04-15 4:52 ` [PATCH 21/27] block: move {bdev,queue_limit}_discard_alignment out of line Christoph Hellwig
2022-04-15 4:52 ` [PATCH 22/27] block: refactor discard bio size limiting Christoph Hellwig
2022-04-15 5:46 ` Chaitanya Kulkarni
2022-04-15 4:52 ` [PATCH 23/27] block: add a bdev_max_discard_sectors helper Christoph Hellwig
2022-04-15 5:47 ` Chaitanya Kulkarni
2022-04-15 4:52 ` [PATCH 24/27] block: remove QUEUE_FLAG_DISCARD Christoph Hellwig
2022-04-15 5:47 ` Chaitanya Kulkarni
2022-04-15 4:52 ` [PATCH 25/27] block: add a bdev_discard_granularity helper Christoph Hellwig
2022-04-15 4:52 ` [PATCH 26/27] block: decouple REQ_OP_SECURE_ERASE from REQ_OP_DISCARD Christoph Hellwig
2022-04-15 5:51 ` Chaitanya Kulkarni
2022-04-16 2:28 ` [f2fs-dev] " Chao Yu
2022-04-15 4:52 ` [PATCH 27/27] direct-io: remove random prefetches Christoph Hellwig
2022-04-15 5:08 ` Damien Le Moal
2022-04-19 12:55 ` David Sterba
2022-04-18 12:52 ` use block_device based APIs in block layer consumers v3 Jens Axboe
-- strict thread matches above, loose matches on Subject: below --
2022-04-09 4:50 use block_device based APIs in block layer consumers v2 Christoph Hellwig
2022-04-09 4:50 ` [PATCH 07/27] drbd: cleanup decide_on_discard_support Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220415045258.199825-8-hch@lst.de \
--to=hch@lst.de \
--cc=axboe@kernel.dk \
--cc=ceph-devel@vger.kernel.org \
--cc=christoph.boehmwalder@linbit.com \
--cc=cluster-devel@redhat.com \
--cc=dm-devel@redhat.com \
--cc=drbd-dev@lists.linbit.com \
--cc=jfs-discussion@lists.sourceforge.net \
--cc=linux-bcache@vger.kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-mmc@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=linux-nilfs@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-raid@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=linux-um@lists.infradead.org \
--cc=linux-xfs@vger.kernel.org \
--cc=nbd@other.debian.org \
--cc=ntfs3@lists.linux.dev \
--cc=ocfs2-devel@oss.oracle.com \
--cc=target-devel@vger.kernel.org \
--cc=virtualization@lists.linux-foundation.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).