Skip to contentSkip to conversation

raid5: set bio bi_vcnt 0 for discard request

PATCH In review Shaohua Li 3 participants 3 messages Oct 19, 2013 – Oct 24, 2013 MD RAID

lore
Share & tools
lore

Shaohua Li

author
#0 lore raw

PATCH 1/2 raid5: set bio bi_vcnt 0 for discard request

SCSI layer will add new payload for discard request. If two bios are merged to one, the second bio has bi_vcnt 1 which is set in raid5. This will confuse SCSI and cause oops.

Suite for backport to 3.7+

---
 drivers/md/raid5.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/md/raid5.c +12 -0
Index: linux/drivers/md/raid5.c
===================================================================
@@ -877,6 +877,12 @@ static void ops_run_io(struct stripe_hea
 			bi->bi_io_vec[0].bv_len = STRIPE_SIZE;
 			bi->bi_io_vec[0].bv_offset = 0;
 			bi->bi_size = STRIPE_SIZE;
+			/*
+			 * If this is discard request, set bi_vcnt 0. We don't
+			 * want to confuse SCSI because SCSI will replace payload
+			 */
+			if (rw & REQ_DISCARD)
+				bi->bi_vcnt = 0;
 			if (rrdev)
 				set_bit(R5_DOUBLE_LOCKED, &sh->dev[i].flags);
 
@@ -915,6 +921,12 @@ static void ops_run_io(struct stripe_hea
 			rbi->bi_io_vec[0].bv_len = STRIPE_SIZE;
 			rbi->bi_io_vec[0].bv_offset = 0;
 			rbi->bi_size = STRIPE_SIZE;
+			/*
+			 * If this is discard request, set bi_vcnt 0. We don't
+			 * want to confuse SCSI because SCSI will replace payload
+			 */
+			if (rw & REQ_DISCARD)
+				rbi->bi_vcnt = 0;
 			if (conf->mddev->gendisk)
 				trace_block_bio_remap(bdev_get_queue(rbi->bi_bdev),
 						      rbi, disk_devt(conf->mddev->gendisk),
Acked-by on v1 1/2
#1 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Shaohua" == Shaohua Li <[email protected]> writes:

Shaohua> SCSI layer will add new payload for discard request. If two Shaohua> bios are merged to one, the second bio has bi_vcnt 1 which is Shaohua> set in raid5. This will confuse SCSI and cause oops.

A discard bio does not have a payload prior to the SCSI command being prepared so vcnt should indeed be 0.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#2 lore raw
Quoted 11 lines · On Wed, 23 Oct 2013 04:07:19 -0400 "Martin K. Petersen"…
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Shaohua" == Shaohua Li <[email protected]> writes:

Shaohua> SCSI layer will add new payload for discard request. If two Shaohua> bios are merged to one, the second bio has bi_vcnt 1 which is Shaohua> set in raid5. This will confuse SCSI and cause oops.

A discard bio does not have a payload prior to the SCSI command being prepared so vcnt should indeed be 0.

Thanks Martin. I'll be sending this to Linus shortly.

NeilBrown