Commit f6ff53d3611b564661896be23369b54d84941a0e
Committed by
Jens Axboe
1 parent
1a9b4993b7
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
block: reorganize rounding of max_discard_sectors
Mostly a preparation for the next patch. In principle this fixes an infinite loop if max_discard_sectors < granularity, but that really shouldn't happen. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Acked-by: Vivek Goyal <vgoyal@redhat.com> Tested-by: Mike Snitzer <snitzer@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Showing 1 changed file with 5 additions and 4 deletions Side-by-side Diff
block/blk-lib.c
... | ... | @@ -44,6 +44,7 @@ |
44 | 44 | struct request_queue *q = bdev_get_queue(bdev); |
45 | 45 | int type = REQ_WRITE | REQ_DISCARD; |
46 | 46 | unsigned int max_discard_sectors; |
47 | + unsigned int granularity; | |
47 | 48 | struct bio_batch bb; |
48 | 49 | struct bio *bio; |
49 | 50 | int ret = 0; |
50 | 51 | |
51 | 52 | |
... | ... | @@ -54,18 +55,18 @@ |
54 | 55 | if (!blk_queue_discard(q)) |
55 | 56 | return -EOPNOTSUPP; |
56 | 57 | |
58 | + /* Zero-sector (unknown) and one-sector granularities are the same. */ | |
59 | + granularity = max(q->limits.discard_granularity >> 9, 1U); | |
60 | + | |
57 | 61 | /* |
58 | 62 | * Ensure that max_discard_sectors is of the proper |
59 | 63 | * granularity |
60 | 64 | */ |
61 | 65 | max_discard_sectors = min(q->limits.max_discard_sectors, UINT_MAX >> 9); |
66 | + max_discard_sectors = round_down(max_discard_sectors, granularity); | |
62 | 67 | if (unlikely(!max_discard_sectors)) { |
63 | 68 | /* Avoid infinite loop below. Being cautious never hurts. */ |
64 | 69 | return -EOPNOTSUPP; |
65 | - } else if (q->limits.discard_granularity) { | |
66 | - unsigned int disc_sects = q->limits.discard_granularity >> 9; | |
67 | - | |
68 | - max_discard_sectors &= ~(disc_sects - 1); | |
69 | 70 | } |
70 | 71 | |
71 | 72 | if (flags & BLKDEV_DISCARD_SECURE) { |