aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2011-05-11 00:48:56 -0400
committerNeilBrown <neilb@suse.de>2011-05-11 00:48:56 -0400
commit78d7f5f726deb562a51126603f2dc5d00990b223 (patch)
treeeb4255cb674028b8709c4542e2a490db3264754f /drivers/md
parenta68e58703575b9c03d610a818e0241564fc17f68 (diff)
md/raid1: tidy up new functions: process_checks and fix_sync_read_error.
These changes are mostly cosmetic: 1/ change mddev->raid_disks to conf->raid_disks because the later is technically safer, though in current practice it doesn't matter in this particular context. 2/ Rearrange two for / if loops to have an early 'continue' so the body of the 'if' doesn't need to be indented so much. Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'drivers/md')
-rw-r--r--drivers/md/raid1.c184
1 files changed, 95 insertions, 89 deletions
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 7fd7a4d6f5c7..2b9e86ceaf2f 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1203,6 +1203,7 @@ static int fix_sync_read_error(r1bio_t *r1_bio)
1203 int d = r1_bio->read_disk; 1203 int d = r1_bio->read_disk;
1204 int success = 0; 1204 int success = 0;
1205 mdk_rdev_t *rdev; 1205 mdk_rdev_t *rdev;
1206 int start;
1206 1207
1207 if (s > (PAGE_SIZE>>9)) 1208 if (s > (PAGE_SIZE>>9))
1208 s = PAGE_SIZE >> 9; 1209 s = PAGE_SIZE >> 9;
@@ -1227,41 +1228,7 @@ static int fix_sync_read_error(r1bio_t *r1_bio)
1227 d = 0; 1228 d = 0;
1228 } while (!success && d != r1_bio->read_disk); 1229 } while (!success && d != r1_bio->read_disk);
1229 1230
1230 if (success) { 1231 if (!success) {
1231 int start = d;
1232 /* write it back and re-read */
1233 set_bit(R1BIO_Uptodate, &r1_bio->state);
1234 while (d != r1_bio->read_disk) {
1235 if (d == 0)
1236 d = conf->raid_disks;
1237 d--;
1238 if (r1_bio->bios[d]->bi_end_io != end_sync_read)
1239 continue;
1240 rdev = conf->mirrors[d].rdev;
1241 atomic_add(s, &rdev->corrected_errors);
1242 if (sync_page_io(rdev,
1243 sect,
1244 s<<9,
1245 bio->bi_io_vec[idx].bv_page,
1246 WRITE, false) == 0)
1247 md_error(mddev, rdev);
1248 }
1249 d = start;
1250 while (d != r1_bio->read_disk) {
1251 if (d == 0)
1252 d = conf->raid_disks;
1253 d--;
1254 if (r1_bio->bios[d]->bi_end_io != end_sync_read)
1255 continue;
1256 rdev = conf->mirrors[d].rdev;
1257 if (sync_page_io(rdev,
1258 sect,
1259 s<<9,
1260 bio->bi_io_vec[idx].bv_page,
1261 READ, false) == 0)
1262 md_error(mddev, rdev);
1263 }
1264 } else {
1265 char b[BDEVNAME_SIZE]; 1232 char b[BDEVNAME_SIZE];
1266 /* Cannot read from anywhere, array is toast */ 1233 /* Cannot read from anywhere, array is toast */
1267 md_error(mddev, conf->mirrors[r1_bio->read_disk].rdev); 1234 md_error(mddev, conf->mirrors[r1_bio->read_disk].rdev);
@@ -1274,10 +1241,47 @@ static int fix_sync_read_error(r1bio_t *r1_bio)
1274 put_buf(r1_bio); 1241 put_buf(r1_bio);
1275 return 0; 1242 return 0;
1276 } 1243 }
1244
1245 start = d;
1246 /* write it back and re-read */
1247 while (d != r1_bio->read_disk) {
1248 if (d == 0)
1249 d = conf->raid_disks;
1250 d--;
1251 if (r1_bio->bios[d]->bi_end_io != end_sync_read)
1252 continue;
1253 rdev = conf->mirrors[d].rdev;
1254 if (sync_page_io(rdev,
1255 sect,
1256 s<<9,
1257 bio->bi_io_vec[idx].bv_page,
1258 WRITE, false) == 0) {
1259 r1_bio->bios[d]->bi_end_io = NULL;
1260 rdev_dec_pending(rdev, mddev);
1261 md_error(mddev, rdev);
1262 } else
1263 atomic_add(s, &rdev->corrected_errors);
1264 }
1265 d = start;
1266 while (d != r1_bio->read_disk) {
1267 if (d == 0)
1268 d = conf->raid_disks;
1269 d--;
1270 if (r1_bio->bios[d]->bi_end_io != end_sync_read)
1271 continue;
1272 rdev = conf->mirrors[d].rdev;
1273 if (sync_page_io(rdev,
1274 sect,
1275 s<<9,
1276 bio->bi_io_vec[idx].bv_page,
1277 READ, false) == 0)
1278 md_error(mddev, rdev);
1279 }
1277 sectors -= s; 1280 sectors -= s;
1278 sect += s; 1281 sect += s;
1279 idx ++; 1282 idx ++;
1280 } 1283 }
1284 set_bit(R1BIO_Uptodate, &r1_bio->state);
1281 return 1; 1285 return 1;
1282} 1286}
1283 1287
@@ -1296,7 +1300,7 @@ static int process_checks(r1bio_t *r1_bio)
1296 int i; 1300 int i;
1297 1301
1298 if (!test_bit(R1BIO_Uptodate, &r1_bio->state)) { 1302 if (!test_bit(R1BIO_Uptodate, &r1_bio->state)) {
1299 for (i=0; i<mddev->raid_disks; i++) 1303 for (i=0; i < conf->raid_disks; i++)
1300 if (r1_bio->bios[i]->bi_end_io == end_sync_read) 1304 if (r1_bio->bios[i]->bi_end_io == end_sync_read)
1301 md_error(mddev, conf->mirrors[i].rdev); 1305 md_error(mddev, conf->mirrors[i].rdev);
1302 1306
@@ -1304,7 +1308,7 @@ static int process_checks(r1bio_t *r1_bio)
1304 put_buf(r1_bio); 1308 put_buf(r1_bio);
1305 return -1; 1309 return -1;
1306 } 1310 }
1307 for (primary=0; primary<mddev->raid_disks; primary++) 1311 for (primary = 0; primary < conf->raid_disks; primary++)
1308 if (r1_bio->bios[primary]->bi_end_io == end_sync_read && 1312 if (r1_bio->bios[primary]->bi_end_io == end_sync_read &&
1309 test_bit(BIO_UPTODATE, &r1_bio->bios[primary]->bi_flags)) { 1313 test_bit(BIO_UPTODATE, &r1_bio->bios[primary]->bi_flags)) {
1310 r1_bio->bios[primary]->bi_end_io = NULL; 1314 r1_bio->bios[primary]->bi_end_io = NULL;
@@ -1312,61 +1316,63 @@ static int process_checks(r1bio_t *r1_bio)
1312 break; 1316 break;
1313 } 1317 }
1314 r1_bio->read_disk = primary; 1318 r1_bio->read_disk = primary;
1315 for (i=0; i<mddev->raid_disks; i++) 1319 for (i = 0; i < conf->raid_disks; i++) {
1316 if (r1_bio->bios[i]->bi_end_io == end_sync_read) { 1320 int j;
1317 int j; 1321 int vcnt = r1_bio->sectors >> (PAGE_SHIFT- 9);
1318 int vcnt = r1_bio->sectors >> (PAGE_SHIFT- 9); 1322 struct bio *pbio = r1_bio->bios[primary];
1319 struct bio *pbio = r1_bio->bios[primary]; 1323 struct bio *sbio = r1_bio->bios[i];
1320 struct bio *sbio = r1_bio->bios[i]; 1324 int size;
1321 1325
1322 if (test_bit(BIO_UPTODATE, &sbio->bi_flags)) { 1326 if (r1_bio->bios[i]->bi_end_io != end_sync_read)
1323 for (j = vcnt; j-- ; ) { 1327 continue;
1324 struct page *p, *s;
1325 p = pbio->bi_io_vec[j].bv_page;
1326 s = sbio->bi_io_vec[j].bv_page;
1327 if (memcmp(page_address(p),
1328 page_address(s),
1329 PAGE_SIZE))
1330 break;
1331 }
1332 } else
1333 j = 0;
1334 if (j >= 0)
1335 mddev->resync_mismatches += r1_bio->sectors;
1336 if (j < 0 || (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)
1337 && test_bit(BIO_UPTODATE, &sbio->bi_flags))) {
1338 sbio->bi_end_io = NULL;
1339 rdev_dec_pending(conf->mirrors[i].rdev, mddev);
1340 } else {
1341 /* fixup the bio for reuse */
1342 int size;
1343 sbio->bi_vcnt = vcnt;
1344 sbio->bi_size = r1_bio->sectors << 9;
1345 sbio->bi_idx = 0;
1346 sbio->bi_phys_segments = 0;
1347 sbio->bi_flags &= ~(BIO_POOL_MASK - 1);
1348 sbio->bi_flags |= 1 << BIO_UPTODATE;
1349 sbio->bi_next = NULL;
1350 sbio->bi_sector = r1_bio->sector +
1351 conf->mirrors[i].rdev->data_offset;
1352 sbio->bi_bdev = conf->mirrors[i].rdev->bdev;
1353 size = sbio->bi_size;
1354 for (j = 0; j < vcnt ; j++) {
1355 struct bio_vec *bi;
1356 bi = &sbio->bi_io_vec[j];
1357 bi->bv_offset = 0;
1358 if (size > PAGE_SIZE)
1359 bi->bv_len = PAGE_SIZE;
1360 else
1361 bi->bv_len = size;
1362 size -= PAGE_SIZE;
1363 memcpy(page_address(bi->bv_page),
1364 page_address(pbio->bi_io_vec[j].bv_page),
1365 PAGE_SIZE);
1366 }
1367 1328
1329 if (test_bit(BIO_UPTODATE, &sbio->bi_flags)) {
1330 for (j = vcnt; j-- ; ) {
1331 struct page *p, *s;
1332 p = pbio->bi_io_vec[j].bv_page;
1333 s = sbio->bi_io_vec[j].bv_page;
1334 if (memcmp(page_address(p),
1335 page_address(s),
1336 PAGE_SIZE))
1337 break;
1368 } 1338 }
1339 } else
1340 j = 0;
1341 if (j >= 0)
1342 mddev->resync_mismatches += r1_bio->sectors;
1343 if (j < 0 || (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)
1344 && test_bit(BIO_UPTODATE, &sbio->bi_flags))) {
1345 /* No need to write to this device. */
1346 sbio->bi_end_io = NULL;
1347 rdev_dec_pending(conf->mirrors[i].rdev, mddev);
1348 continue;
1369 } 1349 }
1350 /* fixup the bio for reuse */
1351 sbio->bi_vcnt = vcnt;
1352 sbio->bi_size = r1_bio->sectors << 9;
1353 sbio->bi_idx = 0;
1354 sbio->bi_phys_segments = 0;
1355 sbio->bi_flags &= ~(BIO_POOL_MASK - 1);
1356 sbio->bi_flags |= 1 << BIO_UPTODATE;
1357 sbio->bi_next = NULL;
1358 sbio->bi_sector = r1_bio->sector +
1359 conf->mirrors[i].rdev->data_offset;
1360 sbio->bi_bdev = conf->mirrors[i].rdev->bdev;
1361 size = sbio->bi_size;
1362 for (j = 0; j < vcnt ; j++) {
1363 struct bio_vec *bi;
1364 bi = &sbio->bi_io_vec[j];
1365 bi->bv_offset = 0;
1366 if (size > PAGE_SIZE)
1367 bi->bv_len = PAGE_SIZE;
1368 else
1369 bi->bv_len = size;
1370 size -= PAGE_SIZE;
1371 memcpy(page_address(bi->bv_page),
1372 page_address(pbio->bi_io_vec[j].bv_page),
1373 PAGE_SIZE);
1374 }
1375 }
1370 return 0; 1376 return 0;
1371} 1377}
1372 1378