Skip to contentSkip to conversation

fix a few problems in block layer

PATCH Superseded Jiufei Xue 5 participants 13 messages Feb 26, 2018 – Feb 27, 2018 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jiufei Xue

author
#0 lore raw

cover fix a few problems in block layer

I have found a few problems while reviewing the patch 74d46992e0d9 ("block: replace bi_bdev with a gendisk pointer and partitions index"), So fix them.

Jiufei Xue (4)
block: fix the count of PGPGOUT for WRITE_SAME
block: bio_check_eod() needs to consider partition
block: display the correct disk name for bio
block: fix a typo and modify the documentation for bio

block/blk-core.c          |   18 +++++-------------
block/partition-generic.c |    6 ------
drivers/block/pktcdvd.c   |    2 +-
include/linux/bio.h       |    4 +++-
4 files changed, 9 insertions(+), 21 deletions(-)
author
#1 lore raw

PATCH 1/4 block: fix the count of PGPGOUT for WRITE_SAME

The vm counters is counted in sectors, so we should do the conversation in submit_bio.

Fixes 74d46992e0d9 ("block: replace bi_bdev with a gendisk pointer and

partitions index")

---
 block/blk-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-core.c +1 -1
index 2d1a7bb..6d82c4f 100644
@@ -2434,7 +2434,7 @@ blk_qc_t submit_bio(struct bio *bio)
 		unsigned int count;
 
 		if (unlikely(bio_op(bio) == REQ_OP_WRITE_SAME))
-			count = queue_logical_block_size(bio->bi_disk->queue);
+			count = queue_logical_block_size(bio->bi_disk->queue) >> 9;
 		else
 			count = bio_sectors(bio);
 
Signature · 1 line
1.9.4
author
#5 lore raw

PATCH 2/4 block: bio_check_eod() needs to consider partition

In reply to Jiufei Xue

bio_check_eod() should get the capacity of partiton, not the whole disk.

---
 block/blk-core.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
block/blk-core.c +12 -4
index 6d82c4f..ef6677d 100644
@@ -2023,7 +2023,7 @@ static blk_qc_t blk_queue_bio(struct request_queue *q, struct bio *bio)
 	return BLK_QC_T_NONE;
 }
 
-static void handle_bad_sector(struct bio *bio)
+static void handle_bad_sector(struct bio *bio, sector_t maxsector)
 {
 	char b[BDEVNAME_SIZE];
 
@@ -2031,7 +2031,7 @@ static void handle_bad_sector(struct bio *bio)
 	printk(KERN_INFO "%s: rw=%d, want=%Lu, limit=%Lu\n",
 			bio_devname(bio, b), bio->bi_opf,
 			(unsigned long long)bio_end_sector(bio),
-			(long long)get_capacity(bio->bi_disk));
+			(long long)maxsector);
 }
 
 #ifdef CONFIG_FAIL_MAKE_REQUEST
@@ -2131,12 +2131,20 @@ static inline int blk_partition_remap(struct bio *bio)
 static inline int bio_check_eod(struct bio *bio, unsigned int nr_sectors)
 {
 	sector_t maxsector;
+	struct hd_struct *part;
 
 	if (!nr_sectors)
 		return 0;
 
 	/* Test device or partition size, when known. */
-	maxsector = get_capacity(bio->bi_disk);
+	rcu_read_lock();
+	part = __disk_get_part(bio->bi_disk, bio->bi_partno);
+	if (part)
+		maxsector = part_nr_sects_read(part);
+	else
+		maxsector = get_capacity(bio->bi_disk);
+	rcu_read_unlock();
+
 	if (maxsector) {
 		sector_t sector = bio->bi_iter.bi_sector;
 
@@ -2146,7 +2154,7 @@ static inline int bio_check_eod(struct bio *bio, unsigned int nr_sectors)
 			 * without checking the size of the device, e.g., when
 			 * mounting a device.
 			 */
-			handle_bad_sector(bio);
+			handle_bad_sector(bio, maxsector);
 			return 1;
 		}
 	}
Signature · 1 line
1.9.4
author
#9 lore raw

PATCH 3/4 block: display the correct diskname for bio

In reply to Jiufei Xue

bio_devname use __bdevname to display the device name, and can only show the major and minor of the part0.
Fix this by using disk_name to display the correct name.

---
 block/partition-generic.c | 6 ++++++
 include/linux/bio.h       | 4 +---
 2 files changed, 7 insertions(+), 3 deletions(-)
block/partition-generic.c +6 -0
index 91622db..08dabcd 100644
@@ -51,6 +51,12 @@ const char *bdevname(struct block_device *bdev, char *buf)
 
 EXPORT_SYMBOL(bdevname);
 
+const char *bio_devname(struct bio *bio, char *buf)
+{
+	return disk_name(bio->bi_disk, bio->bi_partno, buf);
+}
+EXPORT_SYMBOL(bio_devname);
+
 /*
  * There's very little reason to use this, you should really
  * have a struct block_device just about everywhere and use
include/linux/bio.h +1 -3
index d0eb659..ce547a2 100644
@@ -511,6 +511,7 @@ extern struct bio *bio_copy_user_iov(struct request_queue *,
 extern struct bio_vec *bvec_alloc(gfp_t, int, unsigned long *, mempool_t *);
 extern void bvec_free(mempool_t *, struct bio_vec *, unsigned int);
 extern unsigned int bvec_nr_vecs(unsigned short idx);
+extern const char *bio_devname(struct bio *bio, char *buffer);
 
 #define bio_set_dev(bio, bdev) 			\
 do {						\
@@ -529,9 +530,6 @@ extern struct bio *bio_copy_user_iov(struct request_queue *,
 #define bio_dev(bio) \
 	disk_devt((bio)->bi_disk)
 
-#define bio_devname(bio, buf) \
-	__bdevname(bio_dev(bio), (buf))
-
 #ifdef CONFIG_BLK_CGROUP
 int bio_associate_blkcg(struct bio *bio, struct cgroup_subsys_state *blkcg_css);
 void bio_disassociate_task(struct bio *bio);
Signature · 1 line
1.9.4
author
#11 lore raw

PATCH 4/4 block: fix a typo

In reply to Jiufei Xue
---
 drivers/block/pktcdvd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/pktcdvd.c +1 -1
index 531a091..c61d20c 100644
@@ -1122,7 +1122,7 @@ static int pkt_start_recovery(struct packet_data *pkt)
 	pkt->sector = new_sector;
 
 	bio_reset(pkt->bio);
-	bio_set_set(pkt->bio, pd->bdev);
+	bio_set_dev(pkt->bio, pd->bdev);
 	bio_set_op_attrs(pkt->bio, REQ_OP_WRITE, 0);
 	pkt->bio->bi_iter.bi_sector = new_sector;
 	pkt->bio->bi_iter.bi_size = pkt->frames * CD_FRAMESIZE;
Signature · 1 line
1.9.4
maintainer
#12 lore raw
In reply to Jiufei Xue
Quoted 3 lines · Jiufei Xue

I have found a few problems while reviewing the patch 74d46992e0d9 ("block: replace bi_bdev with a gendisk pointer and partitions index"), So fix them.

Looks good to me. It's important to include a Fixes line in the individual patches, though. Otherwise this information is lost, and it's very useful for folks backporting fixes.

Also, patch 4/4 should have some small sensible commit message.

Care to resend with these items fixed?

Signature · 1 line
Jens Axboe
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] block: fix the count of PGPGOUT for WRITE_SAME

In reply to Jiufei Xue
Quoted 5 lines · Jiufei Xue

The vm counters is counted in sectors, so we should do the conversation in submit_bio.

Fixes 74d46992e0d9 ("block: replace bi_bdev with a gendisk pointer and

partitions index")

The Fixes line shouldn't be wrapped. Besides that,

Quoted 21 lines
---
 block/blk-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-core.c +1 -1
index 2d1a7bb..6d82c4f 100644
@@ -2434,7 +2434,7 @@ blk_qc_t submit_bio(struct bio *bio)
 		unsigned int count;
 
 		if (unlikely(bio_op(bio) == REQ_OP_WRITE_SAME))
-			count = queue_logical_block_size(bio->bi_disk->queue);
+			count = queue_logical_block_size(bio->bi_disk->queue) >> 9;
 		else
 			count = bio_sectors(bio);
 
Signature · 1 line
1.9.4
#6 lore raw

Re: [PATCH 2/4] block: bio_check_eod() needs to consider partition

In reply to Jiufei Xue
Quoted 37 lines · Jiufei Xue

bio_check_eod() should get the capacity of partiton, not the whole disk.

---
 block/blk-core.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
block/blk-core.c +3 -2
index 6d82c4f..ef6677d 100644
@@ -2023,7 +2023,7 @@ static blk_qc_t blk_queue_bio(struct request_queue *q, struct bio *bio)
 	return BLK_QC_T_NONE;
 }
 
-static void handle_bad_sector(struct bio *bio)
+static void handle_bad_sector(struct bio *bio, sector_t maxsector)
 {
 	char b[BDEVNAME_SIZE];
 
@@ -2031,7 +2031,7 @@ static void handle_bad_sector(struct bio *bio)
 	printk(KERN_INFO "%s: rw=%d, want=%Lu, limit=%Lu\n",
 			bio_devname(bio, b), bio->bi_opf,
 			(unsigned long long)bio_end_sector(bio),
-			(long long)get_capacity(bio->bi_disk));
+			(long long)maxsector);
 }
 
 #ifdef CONFIG_FAIL_MAKE_REQUEST
@@ -2131,12 +2131,20 @@ static inline int blk_partition_remap(struct bio *bio)
 static inline int bio_check_eod(struct bio *bio, unsigned int nr_sectors)
 {
 	sector_t maxsector;
+	struct hd_struct *part;
 
 	if (!nr_sectors)

block/blk-core.c static inline int blk_partition_remap(struct bio *bio) · line 2145

Quoted 10 lines
block/blk-core.c +6 -1
 		return 0;
 
 	/* Test device or partition size, when known. */
-	maxsector = get_capacity(bio->bi_disk);
+	rcu_read_lock();
+	part = __disk_get_part(bio->bi_disk, bio->bi_partno);
+	if (part)
+		maxsector = part_nr_sects_read(part);
+	else
+		maxsector = get_capacity(bio->bi_disk);

This case means that bio->bi_partno was invalid, right? Shouldn't this be an error? I see that this is copied from guard_bio_eod(), but that serves a slightly different purpose.

Quoted 18 lines
block/blk-core.c +3 -1
+	rcu_read_unlock();
+
 	if (maxsector) {
 		sector_t sector = bio->bi_iter.bi_sector;
 
@@ -2146,7 +2154,7 @@ static inline int bio_check_eod(struct bio *bio, unsigned int nr_sectors)
 			 * without checking the size of the device, e.g., when
 			 * mounting a device.
 			 */
-			handle_bad_sector(bio);
+			handle_bad_sector(bio, maxsector);
 			return 1;
 		}
 	}
Signature · 1 line
1.9.4
Reviewed-by on v1 3/4
#10 lore raw

Re: [PATCH 3/4] block: display the correct diskname for bio

In reply to Jiufei Xue
Quoted 3 lines · Jiufei Xue

bio_devname use __bdevname to display the device name, and can only show the major and minor of the part0.
Fix this by using disk_name to display the correct name.

Besides adding a Fixes: tag like Jens said,

Quoted 49 lines
---
 block/partition-generic.c | 6 ++++++
 include/linux/bio.h       | 4 +---
 2 files changed, 7 insertions(+), 3 deletions(-)
block/partition-generic.c +6 -0
index 91622db..08dabcd 100644
@@ -51,6 +51,12 @@ const char *bdevname(struct block_device *bdev, char *buf)
 
 EXPORT_SYMBOL(bdevname);
 
+const char *bio_devname(struct bio *bio, char *buf)
+{
+	return disk_name(bio->bi_disk, bio->bi_partno, buf);
+}
+EXPORT_SYMBOL(bio_devname);
+
 /*
  * There's very little reason to use this, you should really
  * have a struct block_device just about everywhere and use
include/linux/bio.h +1 -3
index d0eb659..ce547a2 100644
@@ -511,6 +511,7 @@ extern struct bio *bio_copy_user_iov(struct request_queue *,
 extern struct bio_vec *bvec_alloc(gfp_t, int, unsigned long *, mempool_t *);
 extern void bvec_free(mempool_t *, struct bio_vec *, unsigned int);
 extern unsigned int bvec_nr_vecs(unsigned short idx);
+extern const char *bio_devname(struct bio *bio, char *buffer);
 
 #define bio_set_dev(bio, bdev) 			\
 do {						\
@@ -529,9 +530,6 @@ extern struct bio *bio_copy_user_iov(struct request_queue *,
 #define bio_dev(bio) \
 	disk_devt((bio)->bi_disk)
 
-#define bio_devname(bio, buf) \
-	__bdevname(bio_dev(bio), (buf))
-
 #ifdef CONFIG_BLK_CGROUP
 int bio_associate_blkcg(struct bio *bio, struct cgroup_subsys_state *blkcg_css);
 void bio_disassociate_task(struct bio *bio);
Signature · 1 line
1.9.4
#3 lore raw

Re: [PATCH 1/4] block: fix the count of PGPGOUT for WRITE_SAME

In reply to Jiufei Xue

T24gTW9uLCAyMDE4LTAyLTI2IGF0IDIwOjA0ICswODAwLCBKaXVmZWkgWHVlIHdyb3RlOg0KPiBU aGUgdm0gY291bnRlcnMgaXMgY291bnRlZCBpbiBzZWN0b3JzLCBzbyB3ZSBzaG91bGQgZG8gdGhl IGNvbnZlcnNhdGlvbg0KPiBpbiBzdWJtaXRfYmlvLg0KPiANCj4gRml4ZXM6IDc0ZDQ2OTkyZTBk OSAoImJsb2NrOiByZXBsYWNlIGJpX2JkZXYgd2l0aCBhIGdlbmRpc2sgcG9pbnRlciBhbmQNCj4g cGFydGl0aW9ucyBpbmRleCIpDQo+IA0KPiBTaWduZWQtb2ZmLWJ5OiBKaXVmZWkgWHVlIDxqaXVm ZWkueHVlQGxpbnV4LmFsaWJhYmEuY29tPg0KPiAtLS0NCj4gIGJsb2NrL2Jsay1jb3JlLmMgfCAy ICstDQo+ICAxIGZpbGUgY2hhbmdlZCwgMSBpbnNlcnRpb24oKyksIDEgZGVsZXRpb24oLSkNCj4g DQo+IGRpZmYgLS1naXQgYS9ibG9jay9ibGstY29yZS5jIGIvYmxvY2svYmxrLWNvcmUuYw0KPiBp bmRleCAyZDFhN2JiLi42ZDgyYzRmIDEwMDY0NA0KPiAtLS0gYS9ibG9jay9ibGstY29yZS5jDQo+ ICsrKyBiL2Jsb2NrL2Jsay1jb3JlLmMNCj4gQEAgLTI0MzQsNyArMjQzNCw3IEBAIGJsa19xY190 IHN1Ym1pdF9iaW8oc3RydWN0IGJpbyAqYmlvKQ0KPiAgCQl1bnNpZ25lZCBpbnQgY291bnQ7DQo+ ICANCj4gIAkJaWYgKHVubGlrZWx5KGJpb19vcChiaW8pID09IFJFUV9PUF9XUklURV9TQU1FKSkN Cj4gLQkJCWNvdW50ID0gcXVldWVfbG9naWNhbF9ibG9ja19zaXplKGJpby0+YmlfZGlzay0+cXVl dWUpOw0KPiArCQkJY291bnQgPSBxdWV1ZV9sb2dpY2FsX2Jsb2NrX3NpemUoYmlvLT5iaV9kaXNr LT5xdWV1ZSkgPj4gOTsNCj4gIAkJZWxzZQ0KPiAgCQkJY291bnQgPSBiaW9fc2VjdG9ycyhiaW8p Ow0KDQpTaW5jZSB0aGlzIGlzIGEgZml4IGZvciBhIGtlcm5lbCB2NC4xNCBjaGFuZ2UsIHBsZWFz ZSBhZGQgYQ0KIkNjOiBzdGFibGVAdmdlci5rZXJuZWwub3JnIiB0YWcuDQoNClRoYW5rcywNCg0K QmFydC4NCg0KDQo=

author
#8 lore raw

Re: [PATCH 2/4] block: bio_check_eod() needs to consider partition

Quoted 3 lines · Christoph Hellwig

The issue looks real, but please try to do this without another partition lookup.

Yes, I think the partition size test can be moved to blk_partition_remap(). I will send version 2 later.