Skip to contentSkip to conversation

bug fix in function check_should_bypass

PATCH In review Dongbo Cao 2 participants 2 messages Sep 27, 2018 bcache (block layer cache)

lore
Share & tools
lore

Dongbo Cao

author
#0 lore raw

PATCH 1/1 bug fix in function check_should_bypass

bio->bi_iter.bi_sector is the sector index of current request, no need to be aligned. instead, bio->bi_iter.bi_size should be aligned to block_bytes-1, not block_size-1.
and bio_sectors is the number of sectors of current request, also no need to be aligned, just remove it.

---
 drivers/md/bcache/request.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/md/bcache/request.c +1 -2
index 13d3355a..fb3502da 100644
@@ -398,8 +398,7 @@ static bool check_should_bypass(struct cached_dev *dc, struct bio *bio)
 	    !(bio->bi_opf & REQ_PRIO))
 		goto skip;
 
-	if (bio->bi_iter.bi_sector & (c->sb.block_size - 1) ||
-	    bio_sectors(bio) & (c->sb.block_size - 1)) {
+	if (bio->bi_iter.bi_size & (block_bytes(c) - 1)) {
 		pr_debug("skipping unaligned io");
 		goto skip;
 	}
Signature · 1 line
2.17.1
#1 lore raw
Quoted 3 lines · Dongbo Cao

bio->bi_iter.bi_sector is the sector index of current request, no need to be aligned. instead, bio->bi_iter.bi_size should be aligned to block_bytes-1, not block_size-1.
and bio_sectors is the number of sectors of current request, also no need to be aligned, just remove it.

this isn't a bug fix, please don't label things as bug fixes that aren't.

also, it's wrong. an unaligned IO that overlaps with data already in the cache will result in an extent in the cache with misaligned size, which will result in misaligned IOs when reading from it.

Quoted 24 lines
---
 drivers/md/bcache/request.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/md/bcache/request.c +1 -2
index 13d3355a..fb3502da 100644
@@ -398,8 +398,7 @@ static bool check_should_bypass(struct cached_dev *dc, struct bio *bio)
 	    !(bio->bi_opf & REQ_PRIO))
 		goto skip;
 
-	if (bio->bi_iter.bi_sector & (c->sb.block_size - 1) ||
-	    bio_sectors(bio) & (c->sb.block_size - 1)) {
+	if (bio->bi_iter.bi_size & (block_bytes(c) - 1)) {
 		pr_debug("skipping unaligned io");
 		goto skip;
 	}
Signature · 1 line
2.17.1