diff options
author | NeilBrown <neilb@suse.de> | 2006-01-06 03:20:24 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-01-06 11:34:04 -0500 |
commit | 9910f16af35419a5382fa7850eecc220103036fa (patch) | |
tree | 3b5145b8a706e03a6f2b4da4bd84fe98c83de31a /drivers/md | |
parent | cf30a473a02901fe4db37abc0b0fa26dd5ba3f72 (diff) |
[PATCH] md: fix up some rdev rcu locking in raid5/6
There is this "FIXME" comment with a typo in it!! that been annoying me for
days, so I just had to remove it.
conf->disks[i].rdev should only be accessed if
- we know we hold a reference or
- the mddev->reconfig_sem is down or
- we have a rcu_readlock
handle_stripe was referencing rdev in three places without any of these. For
the first two, get an rcu_readlock. For the last, the same access
(md_sync_acct call) is made a little later after the rdev has been claimed
under and rcu_readlock, if R5_Syncio is set. So just use that access...
However R5_Syncio isn't really needed as the 'syncing' variable contains the
same information. So use that instead.
Issues, comment, and fix are identical in raid5 and raid6.
Signed-off-by: Neil Brown <neilb@suse.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/md')
-rw-r--r-- | drivers/md/raid5.c | 16 | ||||
-rw-r--r-- | drivers/md/raid6main.c | 19 |
2 files changed, 16 insertions, 19 deletions
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index 0d016a844ec6..0222ba1a6d35 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c | |||
@@ -961,11 +961,11 @@ static void handle_stripe(struct stripe_head *sh) | |||
961 | syncing = test_bit(STRIPE_SYNCING, &sh->state); | 961 | syncing = test_bit(STRIPE_SYNCING, &sh->state); |
962 | /* Now to look around and see what can be done */ | 962 | /* Now to look around and see what can be done */ |
963 | 963 | ||
964 | rcu_read_lock(); | ||
964 | for (i=disks; i--; ) { | 965 | for (i=disks; i--; ) { |
965 | mdk_rdev_t *rdev; | 966 | mdk_rdev_t *rdev; |
966 | dev = &sh->dev[i]; | 967 | dev = &sh->dev[i]; |
967 | clear_bit(R5_Insync, &dev->flags); | 968 | clear_bit(R5_Insync, &dev->flags); |
968 | clear_bit(R5_Syncio, &dev->flags); | ||
969 | 969 | ||
970 | PRINTK("check %d: state 0x%lx read %p write %p written %p\n", | 970 | PRINTK("check %d: state 0x%lx read %p write %p written %p\n", |
971 | i, dev->flags, dev->toread, dev->towrite, dev->written); | 971 | i, dev->flags, dev->toread, dev->towrite, dev->written); |
@@ -1004,7 +1004,7 @@ static void handle_stripe(struct stripe_head *sh) | |||
1004 | non_overwrite++; | 1004 | non_overwrite++; |
1005 | } | 1005 | } |
1006 | if (dev->written) written++; | 1006 | if (dev->written) written++; |
1007 | rdev = conf->disks[i].rdev; /* FIXME, should I be looking rdev */ | 1007 | rdev = rcu_dereference(conf->disks[i].rdev); |
1008 | if (!rdev || !test_bit(In_sync, &rdev->flags)) { | 1008 | if (!rdev || !test_bit(In_sync, &rdev->flags)) { |
1009 | /* The ReadError flag will just be confusing now */ | 1009 | /* The ReadError flag will just be confusing now */ |
1010 | clear_bit(R5_ReadError, &dev->flags); | 1010 | clear_bit(R5_ReadError, &dev->flags); |
@@ -1017,6 +1017,7 @@ static void handle_stripe(struct stripe_head *sh) | |||
1017 | } else | 1017 | } else |
1018 | set_bit(R5_Insync, &dev->flags); | 1018 | set_bit(R5_Insync, &dev->flags); |
1019 | } | 1019 | } |
1020 | rcu_read_unlock(); | ||
1020 | PRINTK("locked=%d uptodate=%d to_read=%d" | 1021 | PRINTK("locked=%d uptodate=%d to_read=%d" |
1021 | " to_write=%d failed=%d failed_num=%d\n", | 1022 | " to_write=%d failed=%d failed_num=%d\n", |
1022 | locked, uptodate, to_read, to_write, failed, failed_num); | 1023 | locked, uptodate, to_read, to_write, failed, failed_num); |
@@ -1028,10 +1029,13 @@ static void handle_stripe(struct stripe_head *sh) | |||
1028 | int bitmap_end = 0; | 1029 | int bitmap_end = 0; |
1029 | 1030 | ||
1030 | if (test_bit(R5_ReadError, &sh->dev[i].flags)) { | 1031 | if (test_bit(R5_ReadError, &sh->dev[i].flags)) { |
1031 | mdk_rdev_t *rdev = conf->disks[i].rdev; | 1032 | mdk_rdev_t *rdev; |
1033 | rcu_read_lock(); | ||
1034 | rdev = rcu_dereference(conf->disks[i].rdev); | ||
1032 | if (rdev && test_bit(In_sync, &rdev->flags)) | 1035 | if (rdev && test_bit(In_sync, &rdev->flags)) |
1033 | /* multiple read failures in one stripe */ | 1036 | /* multiple read failures in one stripe */ |
1034 | md_error(conf->mddev, rdev); | 1037 | md_error(conf->mddev, rdev); |
1038 | rcu_read_unlock(); | ||
1035 | } | 1039 | } |
1036 | 1040 | ||
1037 | spin_lock_irq(&conf->device_lock); | 1041 | spin_lock_irq(&conf->device_lock); |
@@ -1180,9 +1184,6 @@ static void handle_stripe(struct stripe_head *sh) | |||
1180 | locked++; | 1184 | locked++; |
1181 | PRINTK("Reading block %d (sync=%d)\n", | 1185 | PRINTK("Reading block %d (sync=%d)\n", |
1182 | i, syncing); | 1186 | i, syncing); |
1183 | if (syncing) | ||
1184 | md_sync_acct(conf->disks[i].rdev->bdev, | ||
1185 | STRIPE_SECTORS); | ||
1186 | } | 1187 | } |
1187 | } | 1188 | } |
1188 | } | 1189 | } |
@@ -1326,7 +1327,6 @@ static void handle_stripe(struct stripe_head *sh) | |||
1326 | clear_bit(STRIPE_DEGRADED, &sh->state); | 1327 | clear_bit(STRIPE_DEGRADED, &sh->state); |
1327 | locked++; | 1328 | locked++; |
1328 | set_bit(STRIPE_INSYNC, &sh->state); | 1329 | set_bit(STRIPE_INSYNC, &sh->state); |
1329 | set_bit(R5_Syncio, &dev->flags); | ||
1330 | } | 1330 | } |
1331 | } | 1331 | } |
1332 | if (syncing && locked == 0 && test_bit(STRIPE_INSYNC, &sh->state)) { | 1332 | if (syncing && locked == 0 && test_bit(STRIPE_INSYNC, &sh->state)) { |
@@ -1392,7 +1392,7 @@ static void handle_stripe(struct stripe_head *sh) | |||
1392 | rcu_read_unlock(); | 1392 | rcu_read_unlock(); |
1393 | 1393 | ||
1394 | if (rdev) { | 1394 | if (rdev) { |
1395 | if (test_bit(R5_Syncio, &sh->dev[i].flags)) | 1395 | if (syncing) |
1396 | md_sync_acct(rdev->bdev, STRIPE_SECTORS); | 1396 | md_sync_acct(rdev->bdev, STRIPE_SECTORS); |
1397 | 1397 | ||
1398 | bi->bi_bdev = rdev->bdev; | 1398 | bi->bi_bdev = rdev->bdev; |
diff --git a/drivers/md/raid6main.c b/drivers/md/raid6main.c index 7a51553d8be5..b5b7a8d0b165 100644 --- a/drivers/md/raid6main.c +++ b/drivers/md/raid6main.c | |||
@@ -1060,11 +1060,11 @@ static void handle_stripe(struct stripe_head *sh, struct page *tmp_page) | |||
1060 | syncing = test_bit(STRIPE_SYNCING, &sh->state); | 1060 | syncing = test_bit(STRIPE_SYNCING, &sh->state); |
1061 | /* Now to look around and see what can be done */ | 1061 | /* Now to look around and see what can be done */ |
1062 | 1062 | ||
1063 | rcu_read_lock(); | ||
1063 | for (i=disks; i--; ) { | 1064 | for (i=disks; i--; ) { |
1064 | mdk_rdev_t *rdev; | 1065 | mdk_rdev_t *rdev; |
1065 | dev = &sh->dev[i]; | 1066 | dev = &sh->dev[i]; |
1066 | clear_bit(R5_Insync, &dev->flags); | 1067 | clear_bit(R5_Insync, &dev->flags); |
1067 | clear_bit(R5_Syncio, &dev->flags); | ||
1068 | 1068 | ||
1069 | PRINTK("check %d: state 0x%lx read %p write %p written %p\n", | 1069 | PRINTK("check %d: state 0x%lx read %p write %p written %p\n", |
1070 | i, dev->flags, dev->toread, dev->towrite, dev->written); | 1070 | i, dev->flags, dev->toread, dev->towrite, dev->written); |
@@ -1103,7 +1103,7 @@ static void handle_stripe(struct stripe_head *sh, struct page *tmp_page) | |||
1103 | non_overwrite++; | 1103 | non_overwrite++; |
1104 | } | 1104 | } |
1105 | if (dev->written) written++; | 1105 | if (dev->written) written++; |
1106 | rdev = conf->disks[i].rdev; /* FIXME, should I be looking rdev */ | 1106 | rdev = rcu_dereference(conf->disks[i].rdev); |
1107 | if (!rdev || !test_bit(In_sync, &rdev->flags)) { | 1107 | if (!rdev || !test_bit(In_sync, &rdev->flags)) { |
1108 | /* The ReadError flag will just be confusing now */ | 1108 | /* The ReadError flag will just be confusing now */ |
1109 | clear_bit(R5_ReadError, &dev->flags); | 1109 | clear_bit(R5_ReadError, &dev->flags); |
@@ -1117,6 +1117,7 @@ static void handle_stripe(struct stripe_head *sh, struct page *tmp_page) | |||
1117 | } else | 1117 | } else |
1118 | set_bit(R5_Insync, &dev->flags); | 1118 | set_bit(R5_Insync, &dev->flags); |
1119 | } | 1119 | } |
1120 | rcu_read_unlock(); | ||
1120 | PRINTK("locked=%d uptodate=%d to_read=%d" | 1121 | PRINTK("locked=%d uptodate=%d to_read=%d" |
1121 | " to_write=%d failed=%d failed_num=%d,%d\n", | 1122 | " to_write=%d failed=%d failed_num=%d,%d\n", |
1122 | locked, uptodate, to_read, to_write, failed, | 1123 | locked, uptodate, to_read, to_write, failed, |
@@ -1129,10 +1130,13 @@ static void handle_stripe(struct stripe_head *sh, struct page *tmp_page) | |||
1129 | int bitmap_end = 0; | 1130 | int bitmap_end = 0; |
1130 | 1131 | ||
1131 | if (test_bit(R5_ReadError, &sh->dev[i].flags)) { | 1132 | if (test_bit(R5_ReadError, &sh->dev[i].flags)) { |
1132 | mdk_rdev_t *rdev = conf->disks[i].rdev; | 1133 | mdk_rdev_t *rdev; |
1134 | rcu_read_lock(); | ||
1135 | rdev = rcu_dereference(conf->disks[i].rdev); | ||
1133 | if (rdev && test_bit(In_sync, &rdev->flags)) | 1136 | if (rdev && test_bit(In_sync, &rdev->flags)) |
1134 | /* multiple read failures in one stripe */ | 1137 | /* multiple read failures in one stripe */ |
1135 | md_error(conf->mddev, rdev); | 1138 | md_error(conf->mddev, rdev); |
1139 | rcu_read_unlock(); | ||
1136 | } | 1140 | } |
1137 | 1141 | ||
1138 | spin_lock_irq(&conf->device_lock); | 1142 | spin_lock_irq(&conf->device_lock); |
@@ -1307,9 +1311,6 @@ static void handle_stripe(struct stripe_head *sh, struct page *tmp_page) | |||
1307 | locked++; | 1311 | locked++; |
1308 | PRINTK("Reading block %d (sync=%d)\n", | 1312 | PRINTK("Reading block %d (sync=%d)\n", |
1309 | i, syncing); | 1313 | i, syncing); |
1310 | if (syncing) | ||
1311 | md_sync_acct(conf->disks[i].rdev->bdev, | ||
1312 | STRIPE_SECTORS); | ||
1313 | } | 1314 | } |
1314 | } | 1315 | } |
1315 | } | 1316 | } |
@@ -1463,14 +1464,12 @@ static void handle_stripe(struct stripe_head *sh, struct page *tmp_page) | |||
1463 | locked++; | 1464 | locked++; |
1464 | set_bit(R5_LOCKED, &dev->flags); | 1465 | set_bit(R5_LOCKED, &dev->flags); |
1465 | set_bit(R5_Wantwrite, &dev->flags); | 1466 | set_bit(R5_Wantwrite, &dev->flags); |
1466 | set_bit(R5_Syncio, &dev->flags); | ||
1467 | } | 1467 | } |
1468 | if (failed >= 1) { | 1468 | if (failed >= 1) { |
1469 | dev = &sh->dev[failed_num[0]]; | 1469 | dev = &sh->dev[failed_num[0]]; |
1470 | locked++; | 1470 | locked++; |
1471 | set_bit(R5_LOCKED, &dev->flags); | 1471 | set_bit(R5_LOCKED, &dev->flags); |
1472 | set_bit(R5_Wantwrite, &dev->flags); | 1472 | set_bit(R5_Wantwrite, &dev->flags); |
1473 | set_bit(R5_Syncio, &dev->flags); | ||
1474 | } | 1473 | } |
1475 | 1474 | ||
1476 | if (update_p) { | 1475 | if (update_p) { |
@@ -1478,14 +1477,12 @@ static void handle_stripe(struct stripe_head *sh, struct page *tmp_page) | |||
1478 | locked ++; | 1477 | locked ++; |
1479 | set_bit(R5_LOCKED, &dev->flags); | 1478 | set_bit(R5_LOCKED, &dev->flags); |
1480 | set_bit(R5_Wantwrite, &dev->flags); | 1479 | set_bit(R5_Wantwrite, &dev->flags); |
1481 | set_bit(R5_Syncio, &dev->flags); | ||
1482 | } | 1480 | } |
1483 | if (update_q) { | 1481 | if (update_q) { |
1484 | dev = &sh->dev[qd_idx]; | 1482 | dev = &sh->dev[qd_idx]; |
1485 | locked++; | 1483 | locked++; |
1486 | set_bit(R5_LOCKED, &dev->flags); | 1484 | set_bit(R5_LOCKED, &dev->flags); |
1487 | set_bit(R5_Wantwrite, &dev->flags); | 1485 | set_bit(R5_Wantwrite, &dev->flags); |
1488 | set_bit(R5_Syncio, &dev->flags); | ||
1489 | } | 1486 | } |
1490 | clear_bit(STRIPE_DEGRADED, &sh->state); | 1487 | clear_bit(STRIPE_DEGRADED, &sh->state); |
1491 | 1488 | ||
@@ -1557,7 +1554,7 @@ static void handle_stripe(struct stripe_head *sh, struct page *tmp_page) | |||
1557 | rcu_read_unlock(); | 1554 | rcu_read_unlock(); |
1558 | 1555 | ||
1559 | if (rdev) { | 1556 | if (rdev) { |
1560 | if (test_bit(R5_Syncio, &sh->dev[i].flags)) | 1557 | if (syncing) |
1561 | md_sync_acct(rdev->bdev, STRIPE_SECTORS); | 1558 | md_sync_acct(rdev->bdev, STRIPE_SECTORS); |
1562 | 1559 | ||
1563 | bi->bi_bdev = rdev->bdev; | 1560 | bi->bi_bdev = rdev->bdev; |