Skip to content

Commit 2828908

Browse files
Christoph Hellwigaxboe
authored andcommitted
drbd: refactor the backing dev max_segments calculation
Factor out a drbd_backing_dev_max_segments helper that checks the backing device limitation. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Philipp Reisner <[email protected]> Reviewed-by: Lars Ellenberg <[email protected]> Tested-by: Christoph Böhmwalder <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 342d81f commit 2828908

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

drivers/block/drbd/drbd_nl.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,30 +1295,39 @@ static void fixup_discard_support(struct drbd_device *device, struct request_que
12951295
}
12961296
}
12971297

1298+
/* This is the workaround for "bio would need to, but cannot, be split" */
1299+
static unsigned int drbd_backing_dev_max_segments(struct drbd_device *device)
1300+
{
1301+
unsigned int max_segments;
1302+
1303+
rcu_read_lock();
1304+
max_segments = rcu_dereference(device->ldev->disk_conf)->max_bio_bvecs;
1305+
rcu_read_unlock();
1306+
1307+
if (!max_segments)
1308+
return BLK_MAX_SEGMENTS;
1309+
return max_segments;
1310+
}
1311+
12981312
static void drbd_setup_queue_param(struct drbd_device *device, struct drbd_backing_dev *bdev,
12991313
unsigned int max_bio_size, struct o_qlim *o)
13001314
{
13011315
struct request_queue * const q = device->rq_queue;
13021316
unsigned int max_hw_sectors = max_bio_size >> 9;
1303-
unsigned int max_segments = 0;
1317+
unsigned int max_segments = BLK_MAX_SEGMENTS;
13041318
struct request_queue *b = NULL;
1305-
struct disk_conf *dc;
13061319

13071320
if (bdev) {
13081321
b = bdev->backing_bdev->bd_disk->queue;
13091322

13101323
max_hw_sectors = min(queue_max_hw_sectors(b), max_bio_size >> 9);
1311-
rcu_read_lock();
1312-
dc = rcu_dereference(device->ldev->disk_conf);
1313-
max_segments = dc->max_bio_bvecs;
1314-
rcu_read_unlock();
1324+
max_segments = drbd_backing_dev_max_segments(device);
13151325

13161326
blk_set_stacking_limits(&q->limits);
13171327
}
13181328

13191329
blk_queue_max_hw_sectors(q, max_hw_sectors);
1320-
/* This is the workaround for "bio would need to, but cannot, be split" */
1321-
blk_queue_max_segments(q, max_segments ? max_segments : BLK_MAX_SEGMENTS);
1330+
blk_queue_max_segments(q, max_segments);
13221331
blk_queue_segment_boundary(q, PAGE_SIZE-1);
13231332
decide_on_discard_support(device, bdev);
13241333

0 commit comments

Comments
 (0)