[lkml]   [2011]   [Mar]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH] [37/275] fix medium error problems with some arrays which can cause data corruption
2.6.35-longterm review patch.  If anyone has any objections, please let me know.

From: James Bottomley <>

commit a8733c7baf457b071528e385a0b7d4aaec79287c upstream.

Our current handling of medium error assumes that data is returned up
to the bad sector. This assumption holds good for all disk devices,
all DIF arrays and most ordinary arrays. However, an LSI array engine
was recently discovered which reports a medium error without returning
any data. This means that when we report good data up to the medium
error, we've reported junk originally in the buffer as good. Worse,
if the read consists of requested data plus a readahead, and the error
occurs in readahead, we'll just strip off the readahead and report
junk up to userspace as good data with no error.

The fix for this is to have the error position computation take into
account the amount of data returned by the driver using the scsi
residual data. Unfortunately, not every driver fills in this data,
but for those who don't, it's set to zero, which means we'll think a
full set of data was transferred and the behaviour will be identical
to the prior behaviour of the code (believe the buffer up to the error
sector). All modern drivers seem to set the residual, so that should
fix up the LSI failure/corruption case.

Reported-by: Douglas Gilbert <>
Signed-off-by: James Bottomley <>
Signed-off-by: Greg Kroah-Hartman <>
Signed-off-by: Andi Kleen <>

drivers/scsi/sd.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

Index: linux-2.6.35.y/drivers/scsi/sd.c
--- linux-2.6.35.y.orig/drivers/scsi/sd.c 2011-03-29 22:51:54.208336113 -0700
+++ linux-2.6.35.y/drivers/scsi/sd.c 2011-03-29 23:02:58.955326901 -0700
@@ -1111,6 +1111,12 @@
u64 end_lba = blk_rq_pos(scmd->request) + (scsi_bufflen(scmd) / 512);
u64 bad_lba;
int info_valid;
+ /*
+ * resid is optional but mostly filled in. When it's unused,
+ * its value is zero, so we assume the whole buffer transferred
+ */
+ unsigned int transferred = scsi_bufflen(scmd) - scsi_get_resid(scmd);
+ unsigned int good_bytes;

if (!blk_fs_request(scmd->request))
return 0;
@@ -1144,7 +1150,8 @@
/* This computation should always be done in terms of
* the resolution of the device's medium.
- return (bad_lba - start_lba) * scmd->device->sector_size;
+ good_bytes = (bad_lba - start_lba) * scmd->device->sector_size;
+ return min(good_bytes, transferred);


 \ /
  Last update: 2011-03-31 00:09    [W:0.556 / U:0.076 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site