From: Richard Weinberger <richard@nod.at>
To: linux-mtd@lists.infradead.org
Cc: dedekind1@gmail.com, Richard Weinberger <richard@nod.at>,
adrian.hunter@intel.com, Heinz.Egger@linutronix.de,
shmulik.ladkani@gmail.com, tglx@linutronix.de,
tim.bird@am.sony.com
Subject: [PATCH 19/23] UBI: Fastmap: Handle protection queue correctly
Date: Fri, 1 Jun 2012 17:16:40 +0200 [thread overview]
Message-ID: <1338563804-85990-20-git-send-email-richard@nod.at> (raw)
In-Reply-To: <1338563804-85990-1-git-send-email-richard@nod.at>
It can happen that fastmap finds a PEBs in the EBA of a volume
which is not in the used list nor in the fastmap pool.
In this case the fastmap was written while this PEB was protected.
Such a PEB has to be treated like a pool PEB.
Signed-off-by: Richard Weinberger <richard@nod.at>
---
drivers/mtd/ubi/fastmap.c | 82 +++++++++++++++++++++++++++++++++++++++++---
1 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 9edc6a1..78f196d 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -313,17 +313,20 @@ static int process_pool_aeb(struct ubi_device *ubi, struct ubi_attach_info *ai,
* @pebs: an array of all PEB numbers in the to be scanned pool
* @pool_size: size of the pool (number of entries in @pebs)
* @max_sqnum: pointer to the maximal sequence number
+ * @eba_orphans: list of PEBs which need to be scanned
*/
static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai,
- int *pebs, int pool_size, unsigned long long *max_sqnum)
+ int *pebs, int pool_size, unsigned long long *max_sqnum,
+ struct list_head *eba_orphans)
{
struct ubi_vid_hdr *vh;
struct ubi_ec_hdr *ech;
- struct ubi_ainf_peb *new_aeb;
+ struct ubi_ainf_peb *new_aeb, *tmp_aeb;
int i;
int pnum;
int err;
int ret = 0;
+ int found_orphan;
ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
if (!ech)
@@ -379,6 +382,18 @@ static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai,
goto out;
}
+ found_orphan = 0;
+ list_for_each_entry(tmp_aeb, eba_orphans, u.list) {
+ if (tmp_aeb->pnum == pnum) {
+ found_orphan = 1;
+ break;
+ }
+ }
+ if (found_orphan) {
+ kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
+ list_del(&tmp_aeb->u.list);
+ }
+
new_aeb = kmem_cache_alloc(ai->aeb_slab_cache,
GFP_KERNEL);
if (!new_aeb) {
@@ -431,8 +446,10 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
char *fm_raw, size_t fm_size)
{
struct list_head used;
+ struct list_head eba_orphans;
struct ubi_ainf_volume *av;
struct ubi_ainf_peb *aeb, *tmp_aeb, *_tmp_aeb;
+ struct ubi_ec_hdr *ech;
struct ubi_fm_sb *fmsb;
struct ubi_fm_hdr *fmhdr;
@@ -446,6 +463,7 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
unsigned long long max_sqnum = 0;
INIT_LIST_HEAD(&used);
+ INIT_LIST_HEAD(&eba_orphans);
INIT_LIST_HEAD(&ai->corr);
INIT_LIST_HEAD(&ai->free);
INIT_LIST_HEAD(&ai->erase);
@@ -551,9 +569,28 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
aeb = tmp_aeb;
}
- /* Corner case, this PEB must be in the pool */
- if (!aeb)
+ /* This can happen if a PEB is already in an EBA known
+ * by this fastmap but the PEB itself is not in the used list.
+ * In this case the PEB can be within the fastmap pool or
+ * while writing the fastmap it was in the protected queue.
+ */
+ if (!aeb) {
+ aeb = kmem_cache_alloc(ai->aeb_slab_cache, GFP_KERNEL);
+ if (!aeb) {
+ ret = -ENOMEM;
+
+ goto fail;
+ }
+
+ aeb->lnum = j;
+ aeb->pnum = be32_to_cpu(fm_eba->pnum[j]);
+ aeb->ec = -1;
+ aeb->scrub = aeb->copy_flag = aeb->sqnum = 0;
+
+ list_add_tail(&aeb->u.list, &eba_orphans);
+
continue;
+ }
aeb->lnum = j;
@@ -565,10 +602,43 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
dbg_bld("inserting PEB:%i (LEB %i) to vol %i",
aeb->pnum, aeb->lnum, av->vol_id);
}
+
+ ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
+ if (!ech) {
+ ret = -ENOMEM;
+
+ goto fail;
+ }
+
+ list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &eba_orphans, u.list) {
+ int err;
+
+ if (ubi_io_is_bad(ubi, tmp_aeb->pnum)) {
+ ret = UBI_BAD_FASTMAP;
+ kfree(ech);
+
+ goto fail;
+ }
+
+ err = ubi_io_read_ec_hdr(ubi, tmp_aeb->pnum, ech, 0);
+ if (err && err != UBI_IO_BITFLIPS) {
+ dbg_bld("unable to read EC header!");
+ ret = err > 0 ? UBI_BAD_FASTMAP : err;
+ kfree(ech);
+
+ goto fail;
+ } else if (err == UBI_IO_BITFLIPS)
+ tmp_aeb->scrub = 1;
+
+ tmp_aeb->ec = be64_to_cpu(ech->ec);
+ assign_aeb_to_av(ai, tmp_aeb, av);
+ }
+
+ kfree(ech);
}
/*
- * The remainning PEB in the used list are not used.
+ * The remainning PEBs in the used list are not used.
* They lived in the fastmap pool but got never used.
*/
list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &used, u.list) {
@@ -577,7 +647,7 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
}
ret = scan_pool(ubi, ai, fmpl->pebs, be32_to_cpu(fmpl->size),
- &max_sqnum);
+ &max_sqnum, &eba_orphans);
if (ret)
goto fail;
--
1.7.6.5
next prev parent reply other threads:[~2012-06-01 15:17 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-01 15:16 UBI: Fastmap updates (v7+) Richard Weinberger
2012-06-01 15:16 ` [PATCH 01/23] UBI: Fastmap: Fix EC overflow calculation Richard Weinberger
2012-06-01 15:16 ` [PATCH 02/23] UBI: Fastmap: Introduce fm_mutex Richard Weinberger
2012-06-01 15:16 ` [PATCH 03/23] UBI: Fastmap: Fix find_fastmap() logic Richard Weinberger
2012-06-01 15:16 ` [PATCH 04/23] UBI: Fastmap: Write a fastmap also at detaching Richard Weinberger
2012-06-01 15:16 ` [PATCH 05/23] UBI: Fastmap: Fix memory corruption Richard Weinberger
2012-06-01 15:16 ` [PATCH 06/23] UBI: Fastmap: Serialize ubi_wl_get_peb() Richard Weinberger
2012-06-01 15:16 ` [PATCH 07/23] UBI: Fastmap: Simplify ubi_wl_put_fm_peb() logic Richard Weinberger
2012-06-01 15:16 ` [PATCH 08/23] UBI: Fastmap: make ubi_is_fm_block() static Richard Weinberger
2012-06-01 15:16 ` [PATCH 09/23] UBI: Fastmap: Remove ubi->old_fm logic Richard Weinberger
2012-06-01 15:16 ` [PATCH 10/23] UBI: Fastmap: Allocate and free ubi_attach_info in ubi_attach() Richard Weinberger
2012-06-01 15:16 ` [PATCH 11/23] UBI: Fastmap: Fix messages Richard Weinberger
2012-06-01 15:16 ` [PATCH 12/23] ubi: fastmap: harmonize medium erase-counter seek algorithm Richard Weinberger
2012-06-01 15:16 ` [PATCH 13/23] UBI: Fastmap: Add comments to fastmap paremters Richard Weinberger
2012-06-01 15:16 ` [PATCH 14/23] UBI: Fastmap: Rename fastmap attributes Richard Weinberger
2012-06-01 15:16 ` [PATCH 15/23] UBI: Fastmap: Use reserved_pebs Richard Weinberger
2012-06-01 15:16 ` [PATCH 16/23] UBI: Fastmap: Store bad_peb_count in fastmap Richard Weinberger
2012-06-01 15:16 ` [PATCH 17/23] UBI: Fastmap: Add ubi_assert() Richard Weinberger
2012-06-01 15:16 ` [PATCH 18/23] UBI: Fastmap: Handle bitflipps correctly Richard Weinberger
2012-06-01 15:16 ` Richard Weinberger [this message]
2012-06-01 15:16 ` [PATCH 20/23] UBI: Fastmap: Write fastmap only at detach time if none is present Richard Weinberger
2012-06-01 15:16 ` [PATCH 21/23] UBI: Fastmap: Fix error message Richard Weinberger
2012-06-01 15:16 ` [PATCH 22/23] UBI: Fastmap: Address one of Artems TODOs Richard Weinberger
2012-06-01 15:16 ` [PATCH 23/23] UBI: Fastmap: Make checkpatch.pl happy (again) Richard Weinberger
2012-06-01 17:50 ` UBI: Fastmap updates (v7+) Artem Bityutskiy
2012-06-01 18:00 ` Richard Weinberger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1338563804-85990-20-git-send-email-richard@nod.at \
--to=richard@nod.at \
--cc=Heinz.Egger@linutronix.de \
--cc=adrian.hunter@intel.com \
--cc=dedekind1@gmail.com \
--cc=linux-mtd@lists.infradead.org \
--cc=shmulik.ladkani@gmail.com \
--cc=tglx@linutronix.de \
--cc=tim.bird@am.sony.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).