|
55 | 55 | * |
56 | 56 | * As it was said, for the UBI sub-system all physical eraseblocks are either |
57 | 57 | * "free" or "used". Free eraseblock are kept in the @wl->free RB-tree, while |
58 | | - * used eraseblocks are kept in @wl->used or @wl->scrub RB-trees, or |
59 | | - * (temporarily) in the @wl->pq queue. |
| 58 | + * used eraseblocks are kept in @wl->used, @wl->erroneous, or @wl->scrub |
| 59 | + * RB-trees, as well as (temporarily) in the @wl->pq queue. |
60 | 60 | * |
61 | 61 | * When the WL sub-system returns a physical eraseblock, the physical |
62 | 62 | * eraseblock is protected from being moved for some "time". For this reason, |
|
83 | 83 | * used. The former state corresponds to the @wl->free tree. The latter state |
84 | 84 | * is split up on several sub-states: |
85 | 85 | * o the WL movement is allowed (@wl->used tree); |
| 86 | + * o the WL movement is disallowed (@wl->erroneous) becouse the PEB is |
| 87 | + * erroneous - e.g., there was a read error; |
86 | 88 | * o the WL movement is temporarily prohibited (@wl->pq queue); |
87 | 89 | * o scrubbing is needed (@wl->scrub tree). |
88 | 90 | * |
@@ -653,7 +655,7 @@ static int schedule_erase(struct ubi_device *ubi, struct ubi_wl_entry *e, |
653 | 655 | static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk, |
654 | 656 | int cancel) |
655 | 657 | { |
656 | | - int err, scrubbing = 0, torture = 0, protect = 0; |
| 658 | + int err, scrubbing = 0, torture = 0, protect = 0, erroneous = 0; |
657 | 659 | struct ubi_wl_entry *e1, *e2; |
658 | 660 | struct ubi_vid_hdr *vid_hdr; |
659 | 661 |
|
@@ -769,13 +771,31 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk, |
769 | 771 | goto out_not_moved; |
770 | 772 | } |
771 | 773 |
|
772 | | - if (err == MOVE_CANCEL_BITFLIPS || |
773 | | - err == MOVE_TARGET_WR_ERR) { |
| 774 | + if (err == MOVE_CANCEL_BITFLIPS || err == MOVE_TARGET_WR_ERR || |
| 775 | + err == MOVE_TARGET_RD_ERR) { |
774 | 776 | /* Target PEB bit-flips or write error, torture it */ |
775 | 777 | torture = 1; |
776 | 778 | goto out_not_moved; |
777 | 779 | } |
778 | 780 |
|
| 781 | + if (err == MOVE_SOURCE_RD_ERR) { |
| 782 | + /* |
| 783 | + * An error happened while reading the source PEB. Do |
| 784 | + * not switch to R/O mode in this case, and give the |
| 785 | + * upper layers a possibility to recover from this, |
| 786 | + * e.g. by unmapping corresponding LEB. Instead, just |
| 787 | + * put thie PEB to the @ubi->erroneus list to prevent |
| 788 | + * UBI from trying to move the over and over again. |
| 789 | + */ |
| 790 | + if (ubi->erroneous_peb_count > ubi->max_erroneous) { |
| 791 | + ubi_err("too many erroneous eraseblocks (%d)", |
| 792 | + ubi->erroneous_peb_count); |
| 793 | + goto out_error; |
| 794 | + } |
| 795 | + erroneous = 1; |
| 796 | + goto out_not_moved; |
| 797 | + } |
| 798 | + |
779 | 799 | if (err < 0) |
780 | 800 | goto out_error; |
781 | 801 |
|
@@ -832,7 +852,10 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk, |
832 | 852 | spin_lock(&ubi->wl_lock); |
833 | 853 | if (protect) |
834 | 854 | prot_queue_add(ubi, e1); |
835 | | - else if (scrubbing) |
| 855 | + else if (erroneous) { |
| 856 | + wl_tree_add(e1, &ubi->erroneous); |
| 857 | + ubi->erroneous_peb_count += 1; |
| 858 | + } else if (scrubbing) |
836 | 859 | wl_tree_add(e1, &ubi->scrub); |
837 | 860 | else |
838 | 861 | wl_tree_add(e1, &ubi->used); |
@@ -1116,6 +1139,13 @@ int ubi_wl_put_peb(struct ubi_device *ubi, int pnum, int torture) |
1116 | 1139 | } else if (in_wl_tree(e, &ubi->scrub)) { |
1117 | 1140 | paranoid_check_in_wl_tree(e, &ubi->scrub); |
1118 | 1141 | rb_erase(&e->u.rb, &ubi->scrub); |
| 1142 | + } else if (in_wl_tree(e, &ubi->erroneous)) { |
| 1143 | + paranoid_check_in_wl_tree(e, &ubi->erroneous); |
| 1144 | + rb_erase(&e->u.rb, &ubi->erroneous); |
| 1145 | + ubi->erroneous_peb_count -= 1; |
| 1146 | + ubi_assert(ubi->erroneous_peb_count >= 0); |
| 1147 | + /* Erronious PEBs should be tortured */ |
| 1148 | + torture = 1; |
1119 | 1149 | } else { |
1120 | 1150 | err = prot_queue_del(ubi, e->pnum); |
1121 | 1151 | if (err) { |
@@ -1364,7 +1394,7 @@ int ubi_wl_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si) |
1364 | 1394 | struct ubi_scan_leb *seb, *tmp; |
1365 | 1395 | struct ubi_wl_entry *e; |
1366 | 1396 |
|
1367 | | - ubi->used = ubi->free = ubi->scrub = RB_ROOT; |
| 1397 | + ubi->used = ubi->erroneous = ubi->free = ubi->scrub = RB_ROOT; |
1368 | 1398 | spin_lock_init(&ubi->wl_lock); |
1369 | 1399 | mutex_init(&ubi->move_mutex); |
1370 | 1400 | init_rwsem(&ubi->work_sem); |
@@ -1502,6 +1532,7 @@ void ubi_wl_close(struct ubi_device *ubi) |
1502 | 1532 | cancel_pending(ubi); |
1503 | 1533 | protection_queue_destroy(ubi); |
1504 | 1534 | tree_destroy(&ubi->used); |
| 1535 | + tree_destroy(&ubi->erroneous); |
1505 | 1536 | tree_destroy(&ubi->free); |
1506 | 1537 | tree_destroy(&ubi->scrub); |
1507 | 1538 | kfree(ubi->lookuptbl); |
|
0 commit comments