Commit a9971815 authored by Richard Weinberger's avatar Richard Weinberger Committed by Ben Hutchings

ubi: Deal with interrupted erasures in WL

commit 23654188 upstream.

When Fastmap is used we can face here an -EBADMSG
since Fastmap cannot know about unmaps.
If the erasure was interrupted the PEB may show ECC
errors and UBI would go to ro-mode as it assumes
that the PEB was check during attach time, which is
not the case with Fastmap.

Fixes: dbb7d2a8 ("UBI: Add fastmap core")
Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent d6983e15
...@@ -1000,7 +1000,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk, ...@@ -1000,7 +1000,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
int cancel) int cancel)
{ {
int err, scrubbing = 0, torture = 0, protect = 0, erroneous = 0; int err, scrubbing = 0, torture = 0, protect = 0, erroneous = 0;
int vol_id = -1, lnum = -1; int erase = 0, keep = 0, vol_id = -1, lnum = -1;
#ifdef CONFIG_MTD_UBI_FASTMAP #ifdef CONFIG_MTD_UBI_FASTMAP
int anchor = wrk->anchor; int anchor = wrk->anchor;
#endif #endif
...@@ -1134,6 +1134,16 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk, ...@@ -1134,6 +1134,16 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
e1->pnum); e1->pnum);
scrubbing = 1; scrubbing = 1;
goto out_not_moved; goto out_not_moved;
} else if (ubi->fast_attach && err == UBI_IO_BAD_HDR_EBADMSG) {
/*
* While a full scan would detect interrupted erasures
* at attach time we can face them here when attached from
* Fastmap.
*/
dbg_wl("PEB %d has ECC errors, maybe from an interrupted erasure",
e1->pnum);
erase = 1;
goto out_not_moved;
} }
ubi_err("error %d while reading VID header from PEB %d", ubi_err("error %d while reading VID header from PEB %d",
...@@ -1167,6 +1177,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk, ...@@ -1167,6 +1177,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
* Target PEB had bit-flips or write error - torture it. * Target PEB had bit-flips or write error - torture it.
*/ */
torture = 1; torture = 1;
keep = 1;
goto out_not_moved; goto out_not_moved;
} }
...@@ -1252,7 +1263,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk, ...@@ -1252,7 +1263,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
ubi->erroneous_peb_count += 1; ubi->erroneous_peb_count += 1;
} else if (scrubbing) } else if (scrubbing)
wl_tree_add(e1, &ubi->scrub); wl_tree_add(e1, &ubi->scrub);
else else if (keep)
wl_tree_add(e1, &ubi->used); wl_tree_add(e1, &ubi->used);
ubi_assert(!ubi->move_to_put); ubi_assert(!ubi->move_to_put);
ubi->move_from = ubi->move_to = NULL; ubi->move_from = ubi->move_to = NULL;
...@@ -1264,6 +1275,12 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk, ...@@ -1264,6 +1275,12 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
if (err) if (err)
goto out_ro; goto out_ro;
if (erase) {
err = do_sync_erase(ubi, e1, vol_id, lnum, 1);
if (err)
goto out_ro;
}
mutex_unlock(&ubi->move_mutex); mutex_unlock(&ubi->move_mutex);
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment