Skip to content

Commit 342d81f

Browse files
Christoph Hellwigaxboe
authored andcommitted
drbd: refactor drbd_reconsider_queue_parameters
Split out a drbd_max_peer_bio_size helper for the peer I/O size, and condense the various checks to a nested min3(..., max())) instead of using a lot of local variables. Signed-off-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent aa06732 commit 342d81f

File tree

1 file changed

+49
-35
lines changed

1 file changed

+49
-35
lines changed

drivers/block/drbd/drbd_nl.c

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,33 @@ static int drbd_check_al_size(struct drbd_device *device, struct disk_conf *dc)
11891189
return 0;
11901190
}
11911191

1192+
static unsigned int drbd_max_peer_bio_size(struct drbd_device *device)
1193+
{
1194+
/*
1195+
* We may ignore peer limits if the peer is modern enough. From 8.3.8
1196+
* onwards the peer can use multiple BIOs for a single peer_request.
1197+
*/
1198+
if (device->state.conn < C_WF_REPORT_PARAMS)
1199+
return device->peer_max_bio_size;
1200+
1201+
if (first_peer_device(device)->connection->agreed_pro_version < 94)
1202+
return min(device->peer_max_bio_size, DRBD_MAX_SIZE_H80_PACKET);
1203+
1204+
/*
1205+
* Correct old drbd (up to 8.3.7) if it believes it can do more than
1206+
* 32KiB.
1207+
*/
1208+
if (first_peer_device(device)->connection->agreed_pro_version == 94)
1209+
return DRBD_MAX_SIZE_H80_PACKET;
1210+
1211+
/*
1212+
* drbd 8.3.8 onwards, before 8.4.0
1213+
*/
1214+
if (first_peer_device(device)->connection->agreed_pro_version < 100)
1215+
return DRBD_MAX_BIO_SIZE_P95;
1216+
return DRBD_MAX_BIO_SIZE;
1217+
}
1218+
11921219
static void blk_queue_discard_granularity(struct request_queue *q, unsigned int granularity)
11931220
{
11941221
q->limits.discard_granularity = granularity;
@@ -1303,48 +1330,35 @@ static void drbd_setup_queue_param(struct drbd_device *device, struct drbd_backi
13031330
fixup_discard_support(device, q);
13041331
}
13051332

1306-
void drbd_reconsider_queue_parameters(struct drbd_device *device, struct drbd_backing_dev *bdev, struct o_qlim *o)
1333+
void drbd_reconsider_queue_parameters(struct drbd_device *device,
1334+
struct drbd_backing_dev *bdev, struct o_qlim *o)
13071335
{
1308-
unsigned int now, new, local, peer;
1309-
1310-
now = queue_max_hw_sectors(device->rq_queue) << 9;
1311-
local = device->local_max_bio_size; /* Eventually last known value, from volatile memory */
1312-
peer = device->peer_max_bio_size; /* Eventually last known value, from meta data */
1336+
unsigned int now = queue_max_hw_sectors(device->rq_queue) <<
1337+
SECTOR_SHIFT;
1338+
unsigned int new;
13131339

13141340
if (bdev) {
1315-
local = queue_max_hw_sectors(bdev->backing_bdev->bd_disk->queue) << 9;
1316-
device->local_max_bio_size = local;
1317-
}
1318-
local = min(local, DRBD_MAX_BIO_SIZE);
1319-
1320-
/* We may ignore peer limits if the peer is modern enough.
1321-
Because new from 8.3.8 onwards the peer can use multiple
1322-
BIOs for a single peer_request */
1323-
if (device->state.conn >= C_WF_REPORT_PARAMS) {
1324-
if (first_peer_device(device)->connection->agreed_pro_version < 94)
1325-
peer = min(device->peer_max_bio_size, DRBD_MAX_SIZE_H80_PACKET);
1326-
/* Correct old drbd (up to 8.3.7) if it believes it can do more than 32KiB */
1327-
else if (first_peer_device(device)->connection->agreed_pro_version == 94)
1328-
peer = DRBD_MAX_SIZE_H80_PACKET;
1329-
else if (first_peer_device(device)->connection->agreed_pro_version < 100)
1330-
peer = DRBD_MAX_BIO_SIZE_P95; /* drbd 8.3.8 onwards, before 8.4.0 */
1331-
else
1332-
peer = DRBD_MAX_BIO_SIZE;
1341+
struct request_queue *b = bdev->backing_bdev->bd_disk->queue;
13331342

1334-
/* We may later detach and re-attach on a disconnected Primary.
1335-
* Avoid this setting to jump back in that case.
1336-
* We want to store what we know the peer DRBD can handle,
1337-
* not what the peer IO backend can handle. */
1338-
if (peer > device->peer_max_bio_size)
1339-
device->peer_max_bio_size = peer;
1343+
device->local_max_bio_size =
1344+
queue_max_hw_sectors(b) << SECTOR_SHIFT;
13401345
}
1341-
new = min(local, peer);
13421346

1343-
if (device->state.role == R_PRIMARY && new < now)
1344-
drbd_err(device, "ASSERT FAILED new < now; (%u < %u)\n", new, now);
1345-
1346-
if (new != now)
1347+
/*
1348+
* We may later detach and re-attach on a disconnected Primary. Avoid
1349+
* decreasing the value in this case.
1350+
*
1351+
* We want to store what we know the peer DRBD can handle, not what the
1352+
* peer IO backend can handle.
1353+
*/
1354+
new = min3(DRBD_MAX_BIO_SIZE, device->local_max_bio_size,
1355+
max(drbd_max_peer_bio_size(device), device->peer_max_bio_size));
1356+
if (new != now) {
1357+
if (device->state.role == R_PRIMARY && new < now)
1358+
drbd_err(device, "ASSERT FAILED new < now; (%u < %u)\n",
1359+
new, now);
13471360
drbd_info(device, "max BIO size = %u\n", new);
1361+
}
13481362

13491363
drbd_setup_queue_param(device, bdev, new, o);
13501364
}

0 commit comments

Comments
 (0)