All of lore.kernel.org
 help / color / mirror / Atom feed
* UBI: Fastmap updates (v7+)
@ 2012-06-01 15:16 Richard Weinberger
  2012-06-01 15:16 ` [PATCH 01/23] UBI: Fastmap: Fix EC overflow calculation Richard Weinberger
                   ` (23 more replies)
  0 siblings, 24 replies; 26+ messages in thread
From: Richard Weinberger @ 2012-06-01 15:16 UTC (permalink / raw)
  To: linux-mtd
  Cc: dedekind1, adrian.hunter, Heinz.Egger, shmulik.ladkani, tglx, tim.bird

These patches apply on Artems fastmap tree.
git://git.infradead.org/linux-ubi.git#fastmap

[PATCH 01/23] UBI: Fastmap: Fix EC overflow calculation
[PATCH 02/23] UBI: Fastmap: Introduce fm_mutex
[PATCH 03/23] UBI: Fastmap: Fix find_fastmap() logic.
[PATCH 04/23] UBI: Fastmap: Write a fastmap also at detaching
[PATCH 05/23] UBI: Fastmap: Fix memory corruption
[PATCH 06/23] UBI: Fastmap: Serialize ubi_wl_get_peb()
[PATCH 07/23] UBI: Fastmap: Simplify ubi_wl_put_fm_peb() logic
[PATCH 08/23] UBI: Fastmap: make ubi_is_fm_block() static
[PATCH 09/23] UBI: Fastmap: Remove ubi->old_fm logic
[PATCH 10/23] UBI: Fastmap: Allocate and free ubi_attach_info in
[PATCH 11/23] UBI: Fastmap: Fix messages
[PATCH 12/23] ubi: fastmap: harmonize medium erase-counter seek
[PATCH 13/23] UBI: Fastmap: Add comments to fastmap paremters
[PATCH 14/23] UBI: Fastmap: Rename fastmap attributes
[PATCH 15/23] UBI: Fastmap: Use reserved_pebs
[PATCH 16/23] UBI: Fastmap: Store bad_peb_count in fastmap
[PATCH 17/23] UBI: Fastmap: Add ubi_assert()
[PATCH 18/23] UBI: Fastmap: Handle bitflipps correctly
[PATCH 19/23] UBI: Fastmap: Handle protection queue correctly
[PATCH 20/23] UBI: Fastmap: Write fastmap only at detach time if
[PATCH 21/23] UBI: Fastmap: Fix error message
[PATCH 22/23] UBI: Fastmap: Address one of Artems TODOs
[PATCH 23/23] UBI: Fastmap: Make checkpatch.pl happy (again)

All patches have been tested with ubi-tests.

TODO:
- Add a function to UBI which produces a free PEB to be used as
  fastmap super block.

Thanks,
//richard

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 01/23] UBI: Fastmap: Fix EC overflow calculation
  2012-06-01 15:16 UBI: Fastmap updates (v7+) Richard Weinberger
@ 2012-06-01 15:16 ` Richard Weinberger
  2012-06-01 15:16 ` [PATCH 02/23] UBI: Fastmap: Introduce fm_mutex Richard Weinberger
                   ` (22 subsequent siblings)
  23 siblings, 0 replies; 26+ messages in thread
From: Richard Weinberger @ 2012-06-01 15:16 UTC (permalink / raw)
  To: linux-mtd
  Cc: dedekind1, Richard Weinberger, adrian.hunter, Heinz.Egger,
	shmulik.ladkani, tglx, tim.bird

Checking for an overflow without a be64_to_cpu() make no sense...

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/fastmap.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 2ba2a80..56479df 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -1163,6 +1163,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 		/* no fresh early PEB was found, reuse the old one */
 		if (new_fm->e[0]->pnum < 0) {
 			struct ubi_ec_hdr *ec_hdr;
+			long long ec;
 
 			ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
 			if (!ec_hdr) {
@@ -1193,8 +1194,9 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 				return ret;
 			}
 
-			ec_hdr->ec += ret;
-			if (ec_hdr->ec > UBI_MAX_ERASECOUNTER) {
+			ec = be64_to_cpu(ec_hdr->ec);
+			ec += ret;
+			if (ec > UBI_MAX_ERASECOUNTER) {
 				ubi_err("Erase counter overflow!");
 				kfree(new_fm);
 				kfree(ec_hdr);
-- 
1.7.6.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 02/23] UBI: Fastmap: Introduce fm_mutex
  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 ` Richard Weinberger
  2012-06-01 15:16 ` [PATCH 03/23] UBI: Fastmap: Fix find_fastmap() logic Richard Weinberger
                   ` (21 subsequent siblings)
  23 siblings, 0 replies; 26+ messages in thread
From: Richard Weinberger @ 2012-06-01 15:16 UTC (permalink / raw)
  To: linux-mtd
  Cc: dedekind1, Richard Weinberger, adrian.hunter, Heinz.Egger,
	shmulik.ladkani, tglx, tim.bird

ubi_update_fastmap() has to be serialized.
Currently it can happen that ubi_update_fastmap() gets called in parallel
if the fastmap pool runs out of free PEBs and a volume is changed.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/build.c   |    1 +
 drivers/mtd/ubi/fastmap.c |   43 +++++++++++++++++++++++++------------------
 drivers/mtd/ubi/ubi.h     |    2 ++
 3 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index bd3fa14..51113cb 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -902,6 +902,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
 	mutex_init(&ubi->buf_mutex);
 	mutex_init(&ubi->ckvol_mutex);
 	mutex_init(&ubi->device_mutex);
+	mutex_init(&ubi->fm_mutex);
 	spin_lock_init(&ubi->volumes_lock);
 
 	ubi_msg("attaching mtd%d to ubi%d", mtd->index, ubi_num);
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 56479df..75e067b 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -1152,6 +1152,8 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 		}
 	}
 
+	mutex_lock(&ubi->fm_mutex);
+
 	ubi->old_fm = ubi->fm;
 	ubi->fm = NULL;
 
@@ -1167,9 +1169,9 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 
 			ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
 			if (!ec_hdr) {
-				kfree(new_fm);
+				ret = -ENOMEM;
 
-				return -ENOMEM;
+				goto err;
 			}
 
 			/* we have to erase the block by hand */
@@ -1178,40 +1180,38 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 				ec_hdr, 0);
 			if (ret) {
 				ubi_err("Unable to read EC header");
-				kfree(new_fm);
 				kfree(ec_hdr);
 
-				return ret;
+				goto err;;
 			}
 
 			ret = ubi_io_sync_erase(ubi, ubi->old_fm->e[0]->pnum,
 				0);
 			if (ret < 0) {
 				ubi_err("Unable to erase old SB");
-				kfree(new_fm);
 				kfree(ec_hdr);
 
-				return ret;
+				goto err;
 			}
 
 			ec = be64_to_cpu(ec_hdr->ec);
 			ec += ret;
 			if (ec > UBI_MAX_ERASECOUNTER) {
 				ubi_err("Erase counter overflow!");
-				kfree(new_fm);
 				kfree(ec_hdr);
+				ret = -EINVAL;
 
-				return -EINVAL;
+				goto err;
 			}
 
+			ec_hdr->ec = cpu_to_be64(ec);
 			ret = ubi_io_write_ec_hdr(ubi, ubi->old_fm->e[0]->pnum,
 				ec_hdr);
 			kfree(ec_hdr);
 			if (ret) {
 				ubi_err("Unable to write new EC header");
-				kfree(new_fm);
 
-				return ret;
+				goto err;
 			}
 
 			new_fm->e[0]->pnum = ubi->old_fm->e[0]->pnum;
@@ -1228,18 +1228,18 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 	} else {
 		if (new_fm->e[0]->pnum < 0) {
 			ubi_err("Could not find an early PEB");
-			kfree(new_fm);
+			ret = -ENOSPC;
 
-			return -ENOSPC;
+			goto err;
 		}
 		new_fm->e[0]->ec = get_ec(ubi, new_fm->e[0]->pnum);
 	}
 
 	if (new_fm->used_blocks > UBI_FM_MAX_BLOCKS) {
 		ubi_err("Fastmap too large");
-		kfree(new_fm);
+		ret = -ENOSPC;
 
-		return -ENOSPC;
+		goto err;
 	}
 
 	/* give the wl subsystem a chance to produce some free blocks */
@@ -1257,10 +1257,9 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 				ubi_wl_put_fm_peb(ubi, new_fm->e[i]->pnum, 0);
 				kfree(new_fm->e[i]);
 			}
+			ret = -ENOSPC;
 
-			kfree(new_fm);
-
-			return -ENOSPC;
+			goto err;
 		}
 
 		new_fm->e[i]->ec = get_ec(ubi, new_fm->e[i]->pnum);
@@ -1274,5 +1273,13 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 		ubi->old_fm = NULL;
 	}
 
-	return ubi_write_fastmap(ubi, new_fm);
+	ret = ubi_write_fastmap(ubi, new_fm);
+out_unlock:
+	mutex_unlock(&ubi->fm_mutex);
+
+	return ret;
+
+err:
+	kfree(new_fm);
+	goto out_unlock;
 }
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index e5fe951..7fe1469 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -383,6 +383,7 @@ struct ubi_wl_entry;
  * @old_fm: in-memory data structure old fastmap.
  *	    (only valid while writing a new one)
  * @fm_pool: in-memory data structure of the fastmap pool
+ * @fm_mutex: serializes ubi_update_fastmap()
  * @attached_by_scanning: this UBI device was attached by the old scanning
  *			  methold. All fastmap volumes have to be deleted.
  *
@@ -481,6 +482,7 @@ struct ubi_device {
 	struct ubi_fastmap_layout *fm;
 	struct ubi_fastmap_layout *old_fm;
 	struct ubi_fm_pool fm_pool;
+	struct mutex fm_mutex;
 	int attached_by_scanning;
 
 	/* Wear-leveling sub-system's stuff */
-- 
1.7.6.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 03/23] UBI: Fastmap: Fix find_fastmap() logic.
  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 ` Richard Weinberger
  2012-06-01 15:16 ` [PATCH 04/23] UBI: Fastmap: Write a fastmap also at detaching Richard Weinberger
                   ` (20 subsequent siblings)
  23 siblings, 0 replies; 26+ messages in thread
From: Richard Weinberger @ 2012-06-01 15:16 UTC (permalink / raw)
  To: linux-mtd
  Cc: dedekind1, Richard Weinberger, adrian.hunter, Heinz.Egger,
	shmulik.ladkani, tglx, tim.bird

To grantee that we always use the newest fastmap we have to find
the fastmap super block with the highest sqnum.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/fastmap.c |   62 ++++++++++++++------------------------------
 1 files changed, 20 insertions(+), 42 deletions(-)

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 75e067b..2326e5a 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -595,58 +595,45 @@ fail:
  * ubi_find_fastmap - searches the first UBI_FM_MAX_START PEBs for the
  * fastmap super block.
  * @ubi: UBI device object
+ * @fm_start: Pointer where the fastmap suber block PEB number will be stored.
  *
- * TODO: clearly document return codes
+ * Returns:
+ *  - 0 on success: (fm_start contains suber block PEB number)
+ *  - < 0 on failure (fm_start is -1)
  */
 static int ubi_find_fastmap(struct ubi_device *ubi, int *fm_start)
 {
 	int i, ret;
 	struct ubi_vid_hdr *vhdr;
+	unsigned long long max_sqnum = 0, sqnum;
 
 	vhdr = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL);
 	if (!vhdr)
 		return -ENOMEM;
 
+	*fm_start = -1;
 	for (i = 0; i < UBI_FM_MAX_START; i++) {
 		ret = ubi_io_read_vid_hdr(ubi, i, vhdr, 0);
 		if (ret < 0)
-			break;
+			goto out;
 		else if (ret > 0)
 			continue;
 
 		if (be32_to_cpu(vhdr->vol_id) == UBI_FM_SB_VOLUME_ID) {
-			*fm_start = i;
-			/* TODO: fix globally: all UBI prints:
-			 *  a) do not need the '\n' at the end
-			 *  b) start with a small letter, because the macros
-			 *     add several prefixes.
-			 */
-			dbg_bld("Found fastmap super block at PEB %i\n", i);
-			ret = 0;
+			sqnum = be64_to_cpu(vhdr->sqnum);
+			dbg_bld("found a fastmap super block at PEB %i sqnum: %llu", i, sqnum);
 
-			break;
+			if (sqnum > max_sqnum) {
+				max_sqnum = sqnum;
+				*fm_start = i;
+			}
 		}
 	}
 
+	if (*fm_start > -1)
+		ret = 0;
+out:
 	ubi_free_vid_hdr(ubi, vhdr);
-
-	/* TODO: we can return:
-	 * < 0 - error
-	 * 0 - fastmap found
-	 * 0 - also if we did not find fastmap and the last
-	 *     'ubi_io_read_vid_hdr()' call returned 0. This was not
-	 *     tested with volumes which do not contain fastmap? We need to
-	 *     test this - we need to have a testcase for this in mtd-utils. I
-	 *     can create a branch there and we should agree on which tests are
-	 *     run before anything goes into the git repo.
-	 * > 0 - ignore?
-	 *
-	 * Please, make it instead:
-	 * return 0 - no errors
-	 * return < 0 - error
-	 * If FM not found, fm_start = -1
-	 * If FM found, fm_start is set properly
-	 */
 	return ret;
 }
 
@@ -668,19 +655,10 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info **ai)
 	unsigned long long sqnum = 0;
 
 	ret = ubi_find_fastmap(ubi, &sb_pnum);
-	if (ret) {
-		if (ret > 0)
-			ret = UBI_NO_FASTMAP;
-
-		goto out;
-	}
-	/* TODO: then this will be:
-	 * if (ret)
-	 *         return ret;
-	 * if (sb_pnum == -1)
-	 *         return UBI_NO_FASTMAP;
-	 *
-	 * Much better, I think */
+	if (ret)
+		return ret;
+	if (sb_pnum == -1)
+		return UBI_NO_FASTMAP;
 
 	fmsb = kmalloc(sizeof(*fmsb), GFP_KERNEL);
 	if (!fmsb) {
-- 
1.7.6.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 04/23] UBI: Fastmap: Write a fastmap also at detaching
  2012-06-01 15:16 UBI: Fastmap updates (v7+) Richard Weinberger
                   ` (2 preceding siblings ...)
  2012-06-01 15:16 ` [PATCH 03/23] UBI: Fastmap: Fix find_fastmap() logic Richard Weinberger
@ 2012-06-01 15:16 ` Richard Weinberger
  2012-06-01 15:16 ` [PATCH 05/23] UBI: Fastmap: Fix memory corruption Richard Weinberger
                   ` (19 subsequent siblings)
  23 siblings, 0 replies; 26+ messages in thread
From: Richard Weinberger @ 2012-06-01 15:16 UTC (permalink / raw)
  To: linux-mtd
  Cc: dedekind1, Richard Weinberger, adrian.hunter, Heinz.Egger,
	shmulik.ladkani, tglx, tim.bird

If we attach a UBI device and make no modifications we
end up with a device without a fastmap.
So UBI will fall back to scanning mode next time.
To avoid an unnecessary full scan we write a fastmap also
while detaching.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/build.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 51113cb..7cc2a37 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -1044,6 +1044,7 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
 	ubi_assert(ubi_num == ubi->ubi_num);
 	ubi_notify_all(ubi, UBI_VOLUME_REMOVED, NULL);
 	dbg_msg("detaching mtd%d from ubi%d", ubi->mtd->index, ubi_num);
+	ubi_update_fastmap(ubi);
 
 	/*
 	 * Before freeing anything, we have to stop the background thread to
@@ -1060,6 +1061,7 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
 
 	ubi_debugfs_exit_dev(ubi);
 	uif_close(ubi);
+
 	ubi_wl_close(ubi);
 	ubi_free_internal_volumes(ubi);
 	vfree(ubi->vtbl);
-- 
1.7.6.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 05/23] UBI: Fastmap: Fix memory corruption
  2012-06-01 15:16 UBI: Fastmap updates (v7+) Richard Weinberger
                   ` (3 preceding siblings ...)
  2012-06-01 15:16 ` [PATCH 04/23] UBI: Fastmap: Write a fastmap also at detaching Richard Weinberger
@ 2012-06-01 15:16 ` Richard Weinberger
  2012-06-01 15:16 ` [PATCH 06/23] UBI: Fastmap: Serialize ubi_wl_get_peb() Richard Weinberger
                   ` (18 subsequent siblings)
  23 siblings, 0 replies; 26+ messages in thread
From: Richard Weinberger @ 2012-06-01 15:16 UTC (permalink / raw)
  To: linux-mtd
  Cc: dedekind1, Richard Weinberger, adrian.hunter, Heinz.Egger,
	shmulik.ladkani, tglx, tim.bird

Use ubi_zalloc_vid_hdr().

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/fastmap.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 2326e5a..cbd8c0c 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -1067,7 +1067,8 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
 	dbg_bld("Fastmap written!");
 
 out_kfree:
-	kfree(avhdr);
+	ubi_free_vid_hdr(ubi, avhdr);
+	ubi_free_vid_hdr(ubi, dvhdr);
 out_vfree:
 	vfree(fm_raw);
 out:
-- 
1.7.6.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 06/23] UBI: Fastmap: Serialize ubi_wl_get_peb()
  2012-06-01 15:16 UBI: Fastmap updates (v7+) Richard Weinberger
                   ` (4 preceding siblings ...)
  2012-06-01 15:16 ` [PATCH 05/23] UBI: Fastmap: Fix memory corruption Richard Weinberger
@ 2012-06-01 15:16 ` Richard Weinberger
  2012-06-01 15:16 ` [PATCH 07/23] UBI: Fastmap: Simplify ubi_wl_put_fm_peb() logic Richard Weinberger
                   ` (17 subsequent siblings)
  23 siblings, 0 replies; 26+ messages in thread
From: Richard Weinberger @ 2012-06-01 15:16 UTC (permalink / raw)
  To: linux-mtd
  Cc: dedekind1, Richard Weinberger, adrian.hunter, Heinz.Egger,
	shmulik.ladkani, tglx, tim.bird

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/build.c |    1 +
 drivers/mtd/ubi/ubi.h   |    2 ++
 drivers/mtd/ubi/wl.c    |    4 ++++
 3 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 7cc2a37..4a8688a 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -902,6 +902,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
 	mutex_init(&ubi->buf_mutex);
 	mutex_init(&ubi->ckvol_mutex);
 	mutex_init(&ubi->device_mutex);
+	mutex_init(&ubi->fm_pool_mutex);
 	mutex_init(&ubi->fm_mutex);
 	spin_lock_init(&ubi->volumes_lock);
 
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 7fe1469..c19131f 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -383,6 +383,7 @@ struct ubi_wl_entry;
  * @old_fm: in-memory data structure old fastmap.
  *	    (only valid while writing a new one)
  * @fm_pool: in-memory data structure of the fastmap pool
+ * @fm_pool_mutex: serializes ubi_wl_get_peb()
  * @fm_mutex: serializes ubi_update_fastmap()
  * @attached_by_scanning: this UBI device was attached by the old scanning
  *			  methold. All fastmap volumes have to be deleted.
@@ -483,6 +484,7 @@ struct ubi_device {
 	struct ubi_fastmap_layout *old_fm;
 	struct ubi_fm_pool fm_pool;
 	struct mutex fm_mutex;
+	struct mutex fm_pool_mutex;
 	int attached_by_scanning;
 
 	/* Wear-leveling sub-system's stuff */
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 7d34495..5bd7d99 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -520,6 +520,8 @@ int ubi_wl_get_peb(struct ubi_device *ubi)
 	struct ubi_fm_pool *pool = &ubi->fm_pool;
 	int ret;
 
+	mutex_lock(&ubi->fm_pool_mutex);
+
 	/* pool contains no free blocks, create a new one
 	 * and write a fastmap */
 	if (pool->used == pool->size || !pool->size) {
@@ -534,10 +536,12 @@ int ubi_wl_get_peb(struct ubi_device *ubi)
 		ret = ubi_update_fastmap(ubi);
 		if (ret) {
 			ubi_ro_mode(ubi);
+			mutex_unlock(&ubi->fm_pool_mutex);
 
 			return ret > 0 ? -EINVAL : ret;
 		}
 	}
+	mutex_unlock(&ubi->fm_pool_mutex);
 
 	/* we got not a single free PEB */
 	if (!pool->size)
-- 
1.7.6.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 07/23] UBI: Fastmap: Simplify ubi_wl_put_fm_peb() logic
  2012-06-01 15:16 UBI: Fastmap updates (v7+) Richard Weinberger
                   ` (5 preceding siblings ...)
  2012-06-01 15:16 ` [PATCH 06/23] UBI: Fastmap: Serialize ubi_wl_get_peb() Richard Weinberger
@ 2012-06-01 15:16 ` Richard Weinberger
  2012-06-01 15:16 ` [PATCH 08/23] UBI: Fastmap: make ubi_is_fm_block() static Richard Weinberger
                   ` (16 subsequent siblings)
  23 siblings, 0 replies; 26+ messages in thread
From: Richard Weinberger @ 2012-06-01 15:16 UTC (permalink / raw)
  To: linux-mtd
  Cc: dedekind1, Richard Weinberger, adrian.hunter, Heinz.Egger,
	shmulik.ladkani, tglx, tim.bird

ubi_wl_put_fm_peb() operates now on wl_entries instead of pnums.
Modifications to scan_peb() are no longer needed.
The fastmap used for attaching gets immediately freed after attaching.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/attach.c  |   22 +++++++++-------------
 drivers/mtd/ubi/fastmap.c |   38 +++++++++++++++++++-------------------
 drivers/mtd/ubi/ubi.h     |    2 +-
 drivers/mtd/ubi/wl.c      |   22 +++++-----------------
 4 files changed, 34 insertions(+), 50 deletions(-)

diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
index 792808a..288c15c 100644
--- a/drivers/mtd/ubi/attach.c
+++ b/drivers/mtd/ubi/attach.c
@@ -978,11 +978,7 @@ static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai,
 
 	vol_id = be32_to_cpu(vidh->vol_id);
 
-	if (vol_id > UBI_MAX_VOLUMES &&
-		vol_id != UBI_LAYOUT_VOLUME_ID &&
-		(ubi->attached_by_scanning ||
-		(vol_id != UBI_FM_SB_VOLUME_ID &&
-		vol_id != UBI_FM_DATA_VOLUME_ID))) {
+	if (vol_id > UBI_MAX_VOLUMES && vol_id != UBI_LAYOUT_VOLUME_ID) {
 		int lnum = be32_to_cpu(vidh->lnum);
 
 		/* Unsupported internal volume */
@@ -1221,7 +1217,7 @@ out_ai:
  */
 int ubi_attach(struct ubi_device *ubi)
 {
-	int err;
+	int err, i;
 	struct ubi_attach_info *ai = NULL;
 
 	/* TODO: Allocate ai in this fuction. And destroy it here as well */
@@ -1238,16 +1234,11 @@ int ubi_attach(struct ubi_device *ubi)
 			ubi_err("Attach by fastmap failed! "
 				"Falling back to attach by scanning.");
 
-		/* TODO: please, remove this variable altogether, it is not
-		 * needed and it is a hack which you use to tell 'scan_peb()'
-		 * to handle fastmap volumes specially. Make this is a clean
-		 * way instead: after the scanning, go through the fastmap
-		 * volumes (if any was found) and delete them or do whatever
-		 * you need. Do not inject hacks to the scanning code. */
-		ubi->attached_by_scanning = 1;
 		ai = scan_all(ubi);
 		if (IS_ERR(ai))
 			return PTR_ERR(ai);
+		else
+			printk(KERN_ERR "attached by scanning!\n");
 	} else if (err < 0)
 		return err;
 
@@ -1282,6 +1273,11 @@ int ubi_attach(struct ubi_device *ubi)
 
 	ubi_destroy_ai(ai);
 
+	/* Return all PEBs used by the found fastmap to the WL sub-system. */
+	if (ubi->old_fm)
+		for (i = 0; i < ubi->old_fm->used_blocks; i++)
+			ubi_wl_put_fm_peb(ubi, ubi->old_fm->e[i], 0);
+
 	/* TODO: UBI auto formats the flash if it is empty (see ubi->is_empty).
 	 * It is currently done so that every sub-system writes initializes its
 	 * own stuff. Well, now it is only the vtbl sub-system - it creates
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index cbd8c0c..2e12e2c 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -836,34 +836,33 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info **ai)
 	}
 
 	/* Store the fastmap position into the ubi_device struct */
-	ubi->fm = kmalloc(sizeof(*ubi->fm), GFP_KERNEL);
-	if (!ubi->fm) {
+	ubi->old_fm = kzalloc(sizeof(*ubi->old_fm), GFP_KERNEL);
+	if (!ubi->old_fm) {
 		ret = -ENOMEM;
 
 		goto free_hdr;
 	}
 
-	ubi->fm->size = fm_size;
-	ubi->fm->used_blocks = nblocks;
+	ubi->old_fm->size = fm_size;
+	ubi->old_fm->used_blocks = nblocks;
 
 	for (i = 0; i < nblocks; i++) {
-		ubi->fm->e[i] = kmem_cache_alloc(ubi_wl_entry_slab, GFP_KERNEL);
-		if (!ubi->fm->e[i]) {
+		struct ubi_wl_entry *e;
+
+		e = kmem_cache_alloc(ubi_wl_entry_slab, GFP_KERNEL);
+		if (!e) {
 			while (i--)
-				kfree(ubi->fm->e[i]);
+				kfree(ubi->old_fm->e[i]);
 
-			kfree(ubi->fm);
+			kfree(ubi->old_fm);
 			ret = -ENOMEM;
+
 			goto free_hdr;
 		}
-	}
+		e->pnum = be32_to_cpu(fmsb->block_loc[i]);
+		e->ec = be32_to_cpu(fmsb->block_ec[i]);
 
-	for (i = 0; i < UBI_FM_MAX_BLOCKS; i++) {
-		if (i < nblocks) {
-			ubi->fm->e[i]->pnum = be32_to_cpu(fmsb->block_loc[i]);
-			ubi->fm->e[i]->ec = be32_to_cpu(fmsb->block_ec[i]);
-		} else
-			ubi->fm->e[i] = NULL;
+		ubi->old_fm->e[i] = e;
 	}
 
 free_hdr:
@@ -1103,6 +1102,8 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 	int ret, i;
 	struct ubi_fastmap_layout *new_fm;
 
+	ubi_msg("ubi_update_fastmap!!!!");
+
 	if (ubi->ro_mode)
 		return 0;
 
@@ -1197,13 +1198,12 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 			new_fm->e[0]->ec = ubi->old_fm->e[0]->ec;
 		} else {
 			/* we've got a new early PEB, return the old one */
-			ubi_wl_put_fm_peb(ubi, ubi->old_fm->e[0]->pnum, 0);
-			new_fm->e[0]->ec = get_ec(ubi, new_fm->e[0]->pnum);
+			ubi_wl_put_fm_peb(ubi, ubi->old_fm->e[0], 0);
 		}
 
 		/* return all other fastmap block to the wl system */
 		for (i = 1; i < ubi->old_fm->used_blocks; i++)
-			ubi_wl_put_fm_peb(ubi, ubi->old_fm->e[i]->pnum, 0);
+			ubi_wl_put_fm_peb(ubi, ubi->old_fm->e[i], 0);
 	} else {
 		if (new_fm->e[0]->pnum < 0) {
 			ubi_err("Could not find an early PEB");
@@ -1233,7 +1233,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 			ubi_err("Could not get any free erase block");
 
 			while (i--) {
-				ubi_wl_put_fm_peb(ubi, new_fm->e[i]->pnum, 0);
+				ubi_wl_put_fm_peb(ubi, new_fm->e[i], 0);
 				kfree(new_fm->e[i]);
 			}
 			ret = -ENOSPC;
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index c19131f..4360312 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -732,7 +732,7 @@ int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai);
 void ubi_wl_close(struct ubi_device *ubi);
 int ubi_thread(void *u);
 int ubi_wl_get_fm_peb(struct ubi_device *ubi, int max_pnum);
-int ubi_wl_put_fm_peb(struct ubi_device *ubi, int pnum, int torture);
+int ubi_wl_put_fm_peb(struct ubi_device *ubi, struct ubi_wl_entry *used_e, int torture);
 
 /* io.c */
 int ubi_io_read(const struct ubi_device *ubi, void *buf, int pnum, int offset,
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 5bd7d99..0b1cabc 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -739,10 +739,10 @@ static int schedule_erase(struct ubi_device *ubi, struct ubi_wl_entry *e,
  *
  * see: ubi_wl_put_peb()
  */
-int ubi_wl_put_fm_peb(struct ubi_device *ubi, int pnum, int torture)
+int ubi_wl_put_fm_peb(struct ubi_device *ubi, struct ubi_wl_entry *used_e, int torture)
 {
-	int i, err = 0;
 	struct ubi_wl_entry *e;
+	int pnum = used_e->pnum;
 
 	dbg_wl("PEB %d", pnum);
 	ubi_assert(pnum >= 0);
@@ -756,27 +756,15 @@ int ubi_wl_put_fm_peb(struct ubi_device *ubi, int pnum, int torture)
 	 * has never seen any PEB used by the original fastmap.
 	 */
 	if (!e) {
-		ubi_assert(ubi->old_fm);
-
-		/* use the ec value from the fastmap */
-		for (i = 0; i < ubi->old_fm->used_blocks; i++) {
-			if (ubi->old_fm->e[i] &&
-				pnum == ubi->old_fm->e[i]->pnum) {
-				e = ubi->old_fm->e[i];
-				ubi->old_fm->e[i] = NULL;
-				break;
-			}
-		}
-		ubi_assert(e);
+		e = used_e;
+
 		ubi_assert(e->ec);
 		ubi->lookuptbl[pnum] = e;
 	}
 
 	spin_unlock(&ubi->wl_lock);
 
-	err = schedule_erase(ubi, e, torture);
-
-	return err;
+	return schedule_erase(ubi, e, torture);
 }
 
 /**
-- 
1.7.6.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 08/23] UBI: Fastmap: make ubi_is_fm_block() static
  2012-06-01 15:16 UBI: Fastmap updates (v7+) Richard Weinberger
                   ` (6 preceding siblings ...)
  2012-06-01 15:16 ` [PATCH 07/23] UBI: Fastmap: Simplify ubi_wl_put_fm_peb() logic Richard Weinberger
@ 2012-06-01 15:16 ` Richard Weinberger
  2012-06-01 15:16 ` [PATCH 09/23] UBI: Fastmap: Remove ubi->old_fm logic Richard Weinberger
                   ` (15 subsequent siblings)
  23 siblings, 0 replies; 26+ messages in thread
From: Richard Weinberger @ 2012-06-01 15:16 UTC (permalink / raw)
  To: linux-mtd
  Cc: dedekind1, Richard Weinberger, adrian.hunter, Heinz.Egger,
	shmulik.ladkani, tglx, tim.bird

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/wl.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 0b1cabc..0e4d935 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -166,7 +166,7 @@ static int self_check_in_pq(const struct ubi_device *ubi,
  *  @ubi: UBI device description object
  *  @pnum: the to be checked PEB
  */
-int ubi_is_fm_block(struct ubi_device *ubi, int pnum)
+static int ubi_is_fm_block(struct ubi_device *ubi, int pnum)
 {
 	int i;
 
-- 
1.7.6.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 09/23] UBI: Fastmap: Remove ubi->old_fm logic
  2012-06-01 15:16 UBI: Fastmap updates (v7+) Richard Weinberger
                   ` (7 preceding siblings ...)
  2012-06-01 15:16 ` [PATCH 08/23] UBI: Fastmap: make ubi_is_fm_block() static Richard Weinberger
@ 2012-06-01 15:16 ` Richard Weinberger
  2012-06-01 15:16 ` [PATCH 10/23] UBI: Fastmap: Allocate and free ubi_attach_info in ubi_attach() Richard Weinberger
                   ` (14 subsequent siblings)
  23 siblings, 0 replies; 26+ messages in thread
From: Richard Weinberger @ 2012-06-01 15:16 UTC (permalink / raw)
  To: linux-mtd
  Cc: dedekind1, Richard Weinberger, adrian.hunter, Heinz.Egger,
	shmulik.ladkani, tglx, tim.bird

There is no need to have this logic, we can do better. :-)

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/attach.c  |   24 ++++++++++++--------
 drivers/mtd/ubi/fastmap.c |   53 +++++++++++++++++++++-----------------------
 drivers/mtd/ubi/ubi.h     |    7 ++---
 3 files changed, 42 insertions(+), 42 deletions(-)

diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
index 288c15c..c4e7a3f 100644
--- a/drivers/mtd/ubi/attach.c
+++ b/drivers/mtd/ubi/attach.c
@@ -1204,7 +1204,7 @@ out_vidh:
 out_ech:
 	kfree(ech);
 out_ai:
-	ubi_destroy_ai(ai);
+	ubi_destroy_ai(ubi, ai);
 	return ERR_PTR(err);
 }
 
@@ -1217,7 +1217,7 @@ out_ai:
  */
 int ubi_attach(struct ubi_device *ubi)
 {
-	int err, i;
+	int err;
 	struct ubi_attach_info *ai = NULL;
 
 	/* TODO: Allocate ai in this fuction. And destroy it here as well */
@@ -1271,12 +1271,7 @@ int ubi_attach(struct ubi_device *ubi)
 	if (err)
 		goto out_wl;
 
-	ubi_destroy_ai(ai);
-
-	/* Return all PEBs used by the found fastmap to the WL sub-system. */
-	if (ubi->old_fm)
-		for (i = 0; i < ubi->old_fm->used_blocks; i++)
-			ubi_wl_put_fm_peb(ubi, ubi->old_fm->e[i], 0);
+	ubi_destroy_ai(ubi, ai);
 
 	/* TODO: UBI auto formats the flash if it is empty (see ubi->is_empty).
 	 * It is currently done so that every sub-system writes initializes its
@@ -1293,7 +1288,7 @@ out_vtbl:
 	ubi_free_internal_volumes(ubi);
 	vfree(ubi->vtbl);
 out_ai:
-	ubi_destroy_ai(ai);
+	ubi_destroy_ai(ubi, ai);
 	return err;
 }
 
@@ -1332,9 +1327,10 @@ static void destroy_av(struct ubi_attach_info *ai, struct ubi_ainf_volume *av)
 
 /**
  * ubi_destroy_ai - destroy attaching information.
+ * @ubi: UBI device object
  * @ai: attaching information
  */
-void ubi_destroy_ai(struct ubi_attach_info *ai)
+void ubi_destroy_ai(struct ubi_device *ubi, struct ubi_attach_info *ai)
 {
 	struct ubi_ainf_peb *aeb, *aeb_tmp;
 	struct ubi_ainf_volume *av;
@@ -1382,6 +1378,14 @@ void ubi_destroy_ai(struct ubi_attach_info *ai)
 	if (ai->aeb_slab_cache)
 		kmem_cache_destroy(ai->aeb_slab_cache);
 
+	/* Return all PEBs back to the WL sub-system */
+	if (ai->fm) {
+		while(ai->fm->used_blocks--)
+			ubi_wl_put_fm_peb(ubi, ai->fm->e[ai->fm->used_blocks], 0);
+
+		kfree(ai->fm);
+	}
+
 	kfree(ai);
 }
 
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 2e12e2c..1a5f82e 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -587,7 +587,7 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
 fail_bad:
 	ret = UBI_BAD_FASTMAP;
 fail:
-	ubi_destroy_ai(ai);
+	ubi_destroy_ai(ubi, ai);
 	return ret;
 }
 
@@ -830,21 +830,20 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info **ai)
 	if (ret) {
 		if (ret > 0)
 			ret = UBI_BAD_FASTMAP;
-		ubi_destroy_ai(*ai);
+		ubi_destroy_ai(ubi, *ai);
 
 		goto free_hdr;
 	}
 
-	/* Store the fastmap position into the ubi_device struct */
-	ubi->old_fm = kzalloc(sizeof(*ubi->old_fm), GFP_KERNEL);
-	if (!ubi->old_fm) {
+	(*ai)->fm = kzalloc(sizeof(*(*ai)->fm), GFP_KERNEL);
+	if (!(*ai)->fm) {
 		ret = -ENOMEM;
 
 		goto free_hdr;
 	}
 
-	ubi->old_fm->size = fm_size;
-	ubi->old_fm->used_blocks = nblocks;
+	(*ai)->fm->size = fm_size;
+	(*ai)->fm->used_blocks = nblocks;
 
 	for (i = 0; i < nblocks; i++) {
 		struct ubi_wl_entry *e;
@@ -852,9 +851,10 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info **ai)
 		e = kmem_cache_alloc(ubi_wl_entry_slab, GFP_KERNEL);
 		if (!e) {
 			while (i--)
-				kfree(ubi->old_fm->e[i]);
+				kfree((*ai)->fm->e[i]);
 
-			kfree(ubi->old_fm);
+			kfree((*ai)->fm);
+			(*ai)->fm = NULL;
 			ret = -ENOMEM;
 
 			goto free_hdr;
@@ -862,7 +862,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info **ai)
 		e->pnum = be32_to_cpu(fmsb->block_loc[i]);
 		e->ec = be32_to_cpu(fmsb->block_ec[i]);
 
-		ubi->old_fm->e[i] = e;
+		(*ai)->fm->e[i] = e;
 	}
 
 free_hdr:
@@ -1100,9 +1100,7 @@ static int get_ec(struct ubi_device *ubi, int pnum)
 int ubi_update_fastmap(struct ubi_device *ubi)
 {
 	int ret, i;
-	struct ubi_fastmap_layout *new_fm;
-
-	ubi_msg("ubi_update_fastmap!!!!");
+	struct ubi_fastmap_layout *new_fm, *old_fm;
 
 	if (ubi->ro_mode)
 		return 0;
@@ -1134,14 +1132,14 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 
 	mutex_lock(&ubi->fm_mutex);
 
-	ubi->old_fm = ubi->fm;
+	old_fm = ubi->fm;
 	ubi->fm = NULL;
 
 	spin_lock(&ubi->wl_lock);
 	new_fm->e[0]->pnum = ubi_wl_get_fm_peb(ubi, UBI_FM_MAX_START);
 	spin_unlock(&ubi->wl_lock);
 
-	if (ubi->old_fm) {
+	if (old_fm) {
 		/* no fresh early PEB was found, reuse the old one */
 		if (new_fm->e[0]->pnum < 0) {
 			struct ubi_ec_hdr *ec_hdr;
@@ -1156,7 +1154,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 
 			/* we have to erase the block by hand */
 
-			ret = ubi_io_read_ec_hdr(ubi, ubi->old_fm->e[0]->pnum,
+			ret = ubi_io_read_ec_hdr(ubi, old_fm->e[0]->pnum,
 				ec_hdr, 0);
 			if (ret) {
 				ubi_err("Unable to read EC header");
@@ -1165,7 +1163,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 				goto err;;
 			}
 
-			ret = ubi_io_sync_erase(ubi, ubi->old_fm->e[0]->pnum,
+			ret = ubi_io_sync_erase(ubi, old_fm->e[0]->pnum,
 				0);
 			if (ret < 0) {
 				ubi_err("Unable to erase old SB");
@@ -1185,7 +1183,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 			}
 
 			ec_hdr->ec = cpu_to_be64(ec);
-			ret = ubi_io_write_ec_hdr(ubi, ubi->old_fm->e[0]->pnum,
+			ret = ubi_io_write_ec_hdr(ubi, old_fm->e[0]->pnum,
 				ec_hdr);
 			kfree(ec_hdr);
 			if (ret) {
@@ -1194,16 +1192,16 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 				goto err;
 			}
 
-			new_fm->e[0]->pnum = ubi->old_fm->e[0]->pnum;
-			new_fm->e[0]->ec = ubi->old_fm->e[0]->ec;
+			new_fm->e[0]->pnum = old_fm->e[0]->pnum;
+			new_fm->e[0]->ec = old_fm->e[0]->ec;
 		} else {
 			/* we've got a new early PEB, return the old one */
-			ubi_wl_put_fm_peb(ubi, ubi->old_fm->e[0], 0);
+			ubi_wl_put_fm_peb(ubi, old_fm->e[0], 0);
 		}
 
 		/* return all other fastmap block to the wl system */
-		for (i = 1; i < ubi->old_fm->used_blocks; i++)
-			ubi_wl_put_fm_peb(ubi, ubi->old_fm->e[i], 0);
+		for (i = 1; i < old_fm->used_blocks; i++)
+			ubi_wl_put_fm_peb(ubi, old_fm->e[i], 0);
 	} else {
 		if (new_fm->e[0]->pnum < 0) {
 			ubi_err("Could not find an early PEB");
@@ -1244,12 +1242,11 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 		new_fm->e[i]->ec = get_ec(ubi, new_fm->e[i]->pnum);
 	}
 
-	if (ubi->old_fm) {
-		for (i = 0; i < ubi->old_fm->used_blocks; i++)
-			kfree(ubi->old_fm->e[i]);
+	if (old_fm) {
+		for (i = 0; i < old_fm->used_blocks; i++)
+			kfree(old_fm->e[i]);
 
-		kfree(ubi->old_fm);
-		ubi->old_fm = NULL;
+		kfree(old_fm);
 	}
 
 	ret = ubi_write_fastmap(ubi, new_fm);
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 4360312..c677c19 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -380,8 +380,6 @@ struct ubi_wl_entry;
  * @alc_mutex: serializes "atomic LEB change" operations
  *
  * @fm: in-memory data structure of the currently used fastmap
- * @old_fm: in-memory data structure old fastmap.
- *	    (only valid while writing a new one)
  * @fm_pool: in-memory data structure of the fastmap pool
  * @fm_pool_mutex: serializes ubi_wl_get_peb()
  * @fm_mutex: serializes ubi_update_fastmap()
@@ -481,7 +479,6 @@ struct ubi_device {
 
 	/* Fastmap stuff */
 	struct ubi_fastmap_layout *fm;
-	struct ubi_fastmap_layout *old_fm;
 	struct ubi_fm_pool fm_pool;
 	struct mutex fm_mutex;
 	struct mutex fm_pool_mutex;
@@ -626,6 +623,7 @@ struct ubi_ainf_volume {
  * @ec_sum: a temporary variable used when calculating @mean_ec
  * @ec_count: a temporary variable used when calculating @mean_ec
  * @aeb_slab_cache: slab cache for &struct ubi_ainf_peb objects
+ * @fm: the fastmap used for attaching
  *
  * This data structure contains the result of attaching an MTD device and may
  * be used by other UBI sub-systems to build final UBI data structures, further
@@ -652,6 +650,7 @@ struct ubi_attach_info {
 	uint64_t ec_sum;
 	int ec_count;
 	struct kmem_cache *aeb_slab_cache;
+	struct ubi_fastmap_layout *fm;
 };
 
 #include "debug.h"
@@ -673,7 +672,7 @@ void ubi_remove_av(struct ubi_attach_info *ai, struct ubi_ainf_volume *av);
 struct ubi_ainf_peb *ubi_early_get_peb(struct ubi_device *ubi,
 				       struct ubi_attach_info *ai);
 int ubi_attach(struct ubi_device *ubi);
-void ubi_destroy_ai(struct ubi_attach_info *ai);
+void ubi_destroy_ai(struct ubi_device *ubi, struct ubi_attach_info *ai);
 
 /* vtbl.c */
 int ubi_change_vtbl_record(struct ubi_device *ubi, int idx,
-- 
1.7.6.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 10/23] UBI: Fastmap: Allocate and free ubi_attach_info in ubi_attach()
  2012-06-01 15:16 UBI: Fastmap updates (v7+) Richard Weinberger
                   ` (8 preceding siblings ...)
  2012-06-01 15:16 ` [PATCH 09/23] UBI: Fastmap: Remove ubi->old_fm logic Richard Weinberger
@ 2012-06-01 15:16 ` Richard Weinberger
  2012-06-01 15:16 ` [PATCH 11/23] UBI: Fastmap: Fix messages Richard Weinberger
                   ` (13 subsequent siblings)
  23 siblings, 0 replies; 26+ messages in thread
From: Richard Weinberger @ 2012-06-01 15:16 UTC (permalink / raw)
  To: linux-mtd
  Cc: dedekind1, Richard Weinberger, adrian.hunter, Heinz.Egger,
	shmulik.ladkani, tglx, tim.bird

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/attach.c  |   28 ++++++++++++----------------
 drivers/mtd/ubi/fastmap.c |   29 ++++++++++-------------------
 drivers/mtd/ubi/ubi.h     |    2 +-
 3 files changed, 23 insertions(+), 36 deletions(-)

diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
index c4e7a3f..1ee4a2f 100644
--- a/drivers/mtd/ubi/attach.c
+++ b/drivers/mtd/ubi/attach.c
@@ -1110,22 +1110,18 @@ static int late_analysis(struct ubi_device *ubi, struct ubi_attach_info *ai)
 /**
  * scan_all - scan entire MTD device.
  * @ubi: UBI device description object
+ * @ai: attach info object
  *
  * This function does full scanning of an MTD device and returns complete
  * information about it in form of a "struct ubi_attach_info" object. In case
  * of failure, an error code is returned.
  */
-static struct ubi_attach_info *scan_all(struct ubi_device *ubi)
+static int scan_all(struct ubi_device *ubi, struct ubi_attach_info *ai)
 {
 	int err, pnum;
 	struct rb_node *rb1, *rb2;
 	struct ubi_ainf_volume *av;
 	struct ubi_ainf_peb *aeb;
-	struct ubi_attach_info *ai;
-
-	ai = kzalloc(sizeof(struct ubi_attach_info), GFP_KERNEL);
-	if (!ai)
-		return ERR_PTR(-ENOMEM);
 
 	INIT_LIST_HEAD(&ai->corr);
 	INIT_LIST_HEAD(&ai->free);
@@ -1197,7 +1193,7 @@ static struct ubi_attach_info *scan_all(struct ubi_device *ubi)
 	ubi_free_vid_hdr(ubi, vidh);
 	kfree(ech);
 
-	return ai;
+	return 0;
 
 out_vidh:
 	ubi_free_vid_hdr(ubi, vidh);
@@ -1205,7 +1201,7 @@ out_ech:
 	kfree(ech);
 out_ai:
 	ubi_destroy_ai(ubi, ai);
-	return ERR_PTR(err);
+	return err;
 }
 
 /**
@@ -1218,11 +1214,13 @@ out_ai:
 int ubi_attach(struct ubi_device *ubi)
 {
 	int err;
-	struct ubi_attach_info *ai = NULL;
+	struct ubi_attach_info *ai;
 
-	/* TODO: Allocate ai in this fuction. And destroy it here as well */
+	ai = kzalloc(sizeof(struct ubi_attach_info), GFP_KERNEL);
+	if (!ai)
+		return -ENOMEM;
 
-	err = ubi_scan_fastmap(ubi, &ai);
+	err = ubi_scan_fastmap(ubi, ai);
 	if (err > 0) {
 		/* TODO: in UBIFS we have a convention: every function prints
 		 * its own error messages. This makes things cleaner and easier
@@ -1234,11 +1232,9 @@ int ubi_attach(struct ubi_device *ubi)
 			ubi_err("Attach by fastmap failed! "
 				"Falling back to attach by scanning.");
 
-		ai = scan_all(ubi);
-		if (IS_ERR(ai))
-			return PTR_ERR(ai);
-		else
-			printk(KERN_ERR "attached by scanning!\n");
+		err = scan_all(ubi, ai);
+		if (err)
+			return err;
 	} else if (err < 0)
 		return err;
 
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 1a5f82e..74e7963 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -417,13 +417,12 @@ out:
  * @fm_size: size of the fastmap in bytes
  */
 static int ubi_attach_fastmap(struct ubi_device *ubi,
-			      struct ubi_attach_info **aip,
+			      struct ubi_attach_info *ai,
 			      char *fm_raw, size_t fm_size)
 {
 	struct list_head used;
 	struct ubi_ainf_volume *av;
 	struct ubi_ainf_peb *aeb, *tmp_aeb, *_tmp_aeb;
-	struct ubi_attach_info *ai;
 
 	struct ubi_fm_sb *fmsb;
 	struct ubi_fm_hdr *fmhdr;
@@ -436,12 +435,6 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
 	size_t fm_pos = 0;
 	unsigned long long max_sqnum = 0;
 
-	*aip = kzalloc(sizeof(struct ubi_attach_info), GFP_KERNEL);
-	if (!*aip)
-		return -ENOMEM;
-
-	ai = *aip;
-
 	INIT_LIST_HEAD(&used);
 	INIT_LIST_HEAD(&ai->corr);
 	INIT_LIST_HEAD(&ai->free);
@@ -587,7 +580,6 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
 fail_bad:
 	ret = UBI_BAD_FASTMAP;
 fail:
-	ubi_destroy_ai(ubi, ai);
 	return ret;
 }
 
@@ -642,7 +634,7 @@ out:
  * @ubi: UBI device object
  * @ai: UBI attach info to be filled
  */
-int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info **ai)
+int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai)
 {
 	struct ubi_fm_sb *fmsb;
 	struct ubi_vid_hdr *vh;
@@ -830,20 +822,19 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info **ai)
 	if (ret) {
 		if (ret > 0)
 			ret = UBI_BAD_FASTMAP;
-		ubi_destroy_ai(ubi, *ai);
 
 		goto free_hdr;
 	}
 
-	(*ai)->fm = kzalloc(sizeof(*(*ai)->fm), GFP_KERNEL);
-	if (!(*ai)->fm) {
+	ai->fm = kzalloc(sizeof(*ai->fm), GFP_KERNEL);
+	if (!ai->fm) {
 		ret = -ENOMEM;
 
 		goto free_hdr;
 	}
 
-	(*ai)->fm->size = fm_size;
-	(*ai)->fm->used_blocks = nblocks;
+	ai->fm->size = fm_size;
+	ai->fm->used_blocks = nblocks;
 
 	for (i = 0; i < nblocks; i++) {
 		struct ubi_wl_entry *e;
@@ -851,10 +842,10 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info **ai)
 		e = kmem_cache_alloc(ubi_wl_entry_slab, GFP_KERNEL);
 		if (!e) {
 			while (i--)
-				kfree((*ai)->fm->e[i]);
+				kfree(ai->fm->e[i]);
 
-			kfree((*ai)->fm);
-			(*ai)->fm = NULL;
+			kfree(ai->fm);
+			ai->fm = NULL;
 			ret = -ENOMEM;
 
 			goto free_hdr;
@@ -862,7 +853,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info **ai)
 		e->pnum = be32_to_cpu(fmsb->block_loc[i]);
 		e->ec = be32_to_cpu(fmsb->block_ec[i]);
 
-		(*ai)->fm->e[i] = e;
+		ai->fm->e[i] = e;
 	}
 
 free_hdr:
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index c677c19..0db97b0 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -774,7 +774,7 @@ int ubi_compare_lebs(struct ubi_device *ubi, const struct ubi_ainf_peb *aeb,
 
 /* fastmap.c */
 int ubi_update_fastmap(struct ubi_device *ubi);
-int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info **ai);
+int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai);
 
 /*
  * ubi_rb_for_each_entry - walk an RB-tree.
-- 
1.7.6.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 11/23] UBI: Fastmap: Fix messages
  2012-06-01 15:16 UBI: Fastmap updates (v7+) Richard Weinberger
                   ` (9 preceding siblings ...)
  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 ` Richard Weinberger
  2012-06-01 15:16 ` [PATCH 12/23] ubi: fastmap: harmonize medium erase-counter seek algorithm Richard Weinberger
                   ` (12 subsequent siblings)
  23 siblings, 0 replies; 26+ messages in thread
From: Richard Weinberger @ 2012-06-01 15:16 UTC (permalink / raw)
  To: linux-mtd
  Cc: dedekind1, Richard Weinberger, adrian.hunter, Heinz.Egger,
	shmulik.ladkani, tglx, tim.bird

Remove \n and do not start with a capital letter.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/attach.c  |    2 +-
 drivers/mtd/ubi/fastmap.c |   62 ++++++++++++++++++++++----------------------
 2 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
index 1ee4a2f..4d86621 100644
--- a/drivers/mtd/ubi/attach.c
+++ b/drivers/mtd/ubi/attach.c
@@ -331,7 +331,7 @@ int ubi_compare_lebs(struct ubi_device *ubi, const struct ubi_ainf_peb *aeb,
 		 * support these images anymore. Well, those images still work,
 		 * but only if no unclean reboots happened.
 		 */
-		ubi_err("unsupported on-flash UBI format\n");
+		ubi_err("unsupported on-flash UBI format");
 		return -EINVAL;
 	}
 
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 74e7963..80edfef 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -115,7 +115,7 @@ static struct ubi_ainf_volume *add_vol(struct ubi_attach_info *ai, int vol_id,
 	av->vol_type = vol_type;
 	av->root = RB_ROOT;
 
-	dbg_bld("Found volume (ID %i)", vol_id);
+	dbg_bld("found volume (ID %i)", vol_id);
 
 	rb_link_node(&av->rb, parent, p);
 	rb_insert_color(&av->rb, &ai->volumes);
@@ -219,7 +219,7 @@ static int update_vol(struct ubi_device *ubi, struct ubi_attach_info *ai,
 				av->last_data_size = \
 					be32_to_cpu(new_vh->data_size);
 
-			dbg_bld("Vol %i: AEB %i's PEB %i is the newer\n",
+			dbg_bld("vol %i: AEB %i's PEB %i is the newer",
 				av->vol_id, aeb->lnum, new_aeb->pnum);
 
 			aeb->ec = new_aeb->ec;
@@ -229,7 +229,7 @@ static int update_vol(struct ubi_device *ubi, struct ubi_attach_info *ai,
 
 		/* new_aeb is older */
 		} else {
-			dbg_bld("Vol %i: AEB %i's PEB %i is old, dropping it\n",
+			dbg_bld("vol %i: AEB %i's PEB %i is old, dropping it",
 				av->vol_id, aeb->lnum, new_aeb->pnum);
 			list_add_tail(&new_aeb->u.list, &ai->erase);
 		}
@@ -294,7 +294,7 @@ static int process_pool_aeb(struct ubi_device *ubi, struct ubi_attach_info *ai,
 	if (found)
 		av = tmp_av;
 	else {
-		ubi_err("Orphaned volume in fastmap pool!");
+		ubi_err("orphaned volume in fastmap pool!");
 
 		return UBI_BAD_FASTMAP;
 	}
@@ -333,7 +333,7 @@ static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai,
 		return -ENOMEM;
 	}
 
-	dbg_bld("Scanning fastmap pool: size = %i", pool_size);
+	dbg_bld("scanning fastmap pool: size = %i", pool_size);
 
 	/*
 	 * Now scan all PEBs in the pool to find changes which have been made
@@ -343,7 +343,7 @@ static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai,
 		pnum = be32_to_cpu(pebs[i]);
 
 		if (ubi_io_is_bad(ubi, pnum)) {
-			dbg_bld("Bad PEB in fastmap pool!");
+			dbg_bld("bad PEB in fastmap pool!");
 			ret = UBI_BAD_FASTMAP;
 
 			goto out;
@@ -356,14 +356,14 @@ static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai,
 		else if (err == 0) {
 			err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0);
 			if (err) {
-				dbg_bld("Unable to read EC header!");
+				dbg_bld("unable to read EC header!");
 				ret = err > 0 ? UBI_BAD_FASTMAP : err;
 
 				goto out;
 			}
 
 			if (be32_to_cpu(ech->image_seq) != ubi->image_seq) {
-				dbg_bld("Image seq mismatch!");
+				dbg_bld("image seq mismatch!");
 				err = UBI_BAD_FASTMAP;
 
 				goto out;
@@ -395,7 +395,7 @@ static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai,
 				*max_sqnum = new_aeb->sqnum;
 		} else {
 			/* We are paranoid and fall back to scanning mode */
-			ubi_err("Fastmap pool PEBs contains damaged PEBs!");
+			ubi_err("fastmap pool PEBs contains damaged PEBs!");
 			ret = err > 0 ? UBI_BAD_FASTMAP : err;
 
 			goto out;
@@ -552,7 +552,7 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
 
 			assign_aeb_to_av(ai, aeb, av);
 
-			dbg_bld("Inserting PEB:%i (LEB %i) to vol %i",
+			dbg_bld("inserting PEB:%i (LEB %i) to vol %i",
 				aeb->pnum, aeb->lnum, av->vol_id);
 		}
 	}
@@ -661,7 +661,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai)
 
 	ret = ubi_io_read(ubi, fmsb, sb_pnum, ubi->leb_start, sizeof(*fmsb));
 	if (ret) {
-		ubi_err("Unable to read fastmap super block");
+		ubi_err("unable to read fastmap super block");
 		/* TODO: please, read what 'ubi_io_read()' returns.
 		 * This code is incorrect. All return codes are carefully
 		 * documented there. And do it globally, I see you ignore the
@@ -676,7 +676,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai)
 	}
 
 	if (fmsb->magic != UBI_FM_SB_MAGIC) {
-		ubi_err("Super block magic does not match");
+		ubi_err("super block magic does not match");
 		ret = UBI_BAD_FASTMAP;
 		kfree(fmsb);
 
@@ -684,7 +684,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai)
 	}
 
 	if (fmsb->version != UBI_FM_FMT_VERSION) {
-		ubi_err("Unknown fastmap format version!");
+		ubi_err("unknown fastmap format version!");
 		ret = UBI_BAD_FASTMAP;
 		kfree(fmsb);
 
@@ -694,7 +694,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai)
 	nblocks = be32_to_cpu(fmsb->nblocks);
 
 	if (nblocks > UBI_FM_MAX_BLOCKS || nblocks < 1) {
-		ubi_err("Number of fastmap blocks is invalid");
+		ubi_err("number of fastmap blocks is invalid");
 		ret = UBI_BAD_FASTMAP;
 		kfree(fmsb);
 
@@ -740,7 +740,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai)
 
 		ret = ubi_io_read_ec_hdr(ubi, pnum, ech, 0);
 		if (ret) {
-			ubi_err("Unable to read fastmap block# %i EC (PEB: %i)",
+			ubi_err("unable to read fastmap block# %i EC (PEB: %i)",
 				i, pnum);
 			if (ret > 0)
 				ret = UBI_BAD_FASTMAP;
@@ -761,7 +761,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai)
 
 		ret = ubi_io_read_vid_hdr(ubi, pnum, vh, 0);
 		if (ret) {
-			ubi_err("Unable to read fastmap block# %i (PEB: %i)",
+			ubi_err("unable to read fastmap block# %i (PEB: %i)",
 				i, pnum);
 			if (ret > 0)
 				ret = UBI_BAD_FASTMAP;
@@ -793,7 +793,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai)
 			ubi->leb_start, ubi->leb_size);
 
 		if (ret) {
-			ubi_err("Unable to read fastmap block# %i (PEB: %i)",
+			ubi_err("unable to read fastmap block# %i (PEB: %i)",
 				i, pnum);
 			if (ret > 0)
 				ret = UBI_BAD_FASTMAP;
@@ -810,7 +810,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai)
 	fmsb->data_crc = 0;
 	crc = crc32_be(UBI_CRC32_INIT, fm_raw, fm_size);
 	if (crc != tmp_crc) {
-		ubi_err("Fastmap data CRC is invalid");
+		ubi_err("fastmap data CRC is invalid");
 		ret = UBI_BAD_FASTMAP;
 
 		goto free_hdr;
@@ -1010,10 +1010,10 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
 	spin_unlock(&ubi->wl_lock);
 	spin_unlock(&ubi->volumes_lock);
 
-	dbg_bld("Writing fastmap SB to PEB %i\n", new_fm->e[0]->pnum);
+	dbg_bld("writing fastmap SB to PEB %i", new_fm->e[0]->pnum);
 	ret = ubi_io_write_vid_hdr(ubi, new_fm->e[0]->pnum, avhdr);
 	if (ret) {
-		ubi_err("Unable to write vid_hdr to fastmap SB!\n");
+		ubi_err("unable to write vid_hdr to fastmap SB!");
 
 		goto out_kfree;
 	}
@@ -1029,11 +1029,11 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
 	for (i = 1; i < new_fm->used_blocks; i++) {
 		dvhdr->sqnum = cpu_to_be64(ubi_next_sqnum(ubi));
 		dvhdr->lnum = cpu_to_be32(i);
-		dbg_bld("Writing fastmap data to PEB %i sqnum %llu\n",
+		dbg_bld("writing fastmap data to PEB %i sqnum %llu",
 			new_fm->e[i]->pnum, be64_to_cpu(dvhdr->sqnum));
 		ret = ubi_io_write_vid_hdr(ubi, new_fm->e[i]->pnum, dvhdr);
 		if (ret) {
-			ubi_err("Unable to write vid_hdr to PEB %i!\n",
+			ubi_err("unable to write vid_hdr to PEB %i!",
 				new_fm->e[i]->pnum);
 
 			goto out_kfree;
@@ -1044,7 +1044,7 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
 		ret = ubi_io_write(ubi, fm_raw + (i * ubi->leb_size),
 			new_fm->e[i]->pnum, ubi->leb_start, ubi->leb_size);
 		if (ret) {
-			ubi_err("Unable to write fastmap to PEB %i!\n",
+			ubi_err("unable to write fastmap to PEB %i!",
 				new_fm->e[i]->pnum);
 
 			goto out_kfree;
@@ -1054,7 +1054,7 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
 	ubi_assert(new_fm);
 	ubi->fm = new_fm;
 
-	dbg_bld("Fastmap written!");
+	dbg_bld("fastmap written!");
 
 out_kfree:
 	ubi_free_vid_hdr(ubi, avhdr);
@@ -1148,7 +1148,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 			ret = ubi_io_read_ec_hdr(ubi, old_fm->e[0]->pnum,
 				ec_hdr, 0);
 			if (ret) {
-				ubi_err("Unable to read EC header");
+				ubi_err("unable to read EC header");
 				kfree(ec_hdr);
 
 				goto err;;
@@ -1157,7 +1157,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 			ret = ubi_io_sync_erase(ubi, old_fm->e[0]->pnum,
 				0);
 			if (ret < 0) {
-				ubi_err("Unable to erase old SB");
+				ubi_err("unable to erase old SB");
 				kfree(ec_hdr);
 
 				goto err;
@@ -1166,7 +1166,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 			ec = be64_to_cpu(ec_hdr->ec);
 			ec += ret;
 			if (ec > UBI_MAX_ERASECOUNTER) {
-				ubi_err("Erase counter overflow!");
+				ubi_err("erase counter overflow!");
 				kfree(ec_hdr);
 				ret = -EINVAL;
 
@@ -1178,7 +1178,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 				ec_hdr);
 			kfree(ec_hdr);
 			if (ret) {
-				ubi_err("Unable to write new EC header");
+				ubi_err("unable to write new EC header");
 
 				goto err;
 			}
@@ -1195,7 +1195,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 			ubi_wl_put_fm_peb(ubi, old_fm->e[i], 0);
 	} else {
 		if (new_fm->e[0]->pnum < 0) {
-			ubi_err("Could not find an early PEB");
+			ubi_err("could not find an early PEB");
 			ret = -ENOSPC;
 
 			goto err;
@@ -1204,7 +1204,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 	}
 
 	if (new_fm->used_blocks > UBI_FM_MAX_BLOCKS) {
-		ubi_err("Fastmap too large");
+		ubi_err("fastmap too large");
 		ret = -ENOSPC;
 
 		goto err;
@@ -1219,7 +1219,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 		spin_unlock(&ubi->wl_lock);
 
 		if (new_fm->e[i]->pnum < 0) {
-			ubi_err("Could not get any free erase block");
+			ubi_err("could not get any free erase block");
 
 			while (i--) {
 				ubi_wl_put_fm_peb(ubi, new_fm->e[i], 0);
-- 
1.7.6.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 12/23] ubi: fastmap: harmonize medium erase-counter seek algorithm
  2012-06-01 15:16 UBI: Fastmap updates (v7+) Richard Weinberger
                   ` (10 preceding siblings ...)
  2012-06-01 15:16 ` [PATCH 11/23] UBI: Fastmap: Fix messages Richard Weinberger
@ 2012-06-01 15:16 ` Richard Weinberger
  2012-06-01 15:16 ` [PATCH 13/23] UBI: Fastmap: Add comments to fastmap paremters Richard Weinberger
                   ` (11 subsequent siblings)
  23 siblings, 0 replies; 26+ messages in thread
From: Richard Weinberger @ 2012-06-01 15:16 UTC (permalink / raw)
  To: linux-mtd
  Cc: dedekind1, Richard Weinberger, adrian.hunter, Heinz.Egger,
	shmulik.ladkani, tglx, tim.bird

From: Shmulik Ladkani <shmulik.ladkani@gmail.com>

Currently, there are two different locations where a wear-leveling entry
with a medium erase counter is looked-for, with the same search algorithm
duplicated.

Harmonize this by introducing a common function 'find_mean_wl_entry'.

Signed-off-by: Shmulik Ladkani <shmulik.ladkani@gmail.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/wl.c |   50 +++++++++++++++++++++++++++++---------------------
 1 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 0e4d935..2325d3d 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -386,6 +386,29 @@ static struct ubi_wl_entry *find_wl_entry(struct rb_root *root, int diff)
 }
 
 /**
+ * find_mean_wl_entry - find wear-leveling entry with medium erase counter.
+ * @root: the RB-tree where to look for
+ *
+ * This function looks for a wear leveling entry with medium erase counter,
+ * but not greater or equivalent than the lowest erase counter plus
+ * %WL_FREE_MAX_DIFF/2.
+ */
+static struct ubi_wl_entry *find_mean_wl_entry(struct rb_root *root)
+{
+	struct ubi_wl_entry *e, *first, *last;
+
+	first = rb_entry(rb_first(root), struct ubi_wl_entry, u.rb);
+	last = rb_entry(rb_last(root), struct ubi_wl_entry, u.rb);
+
+	if (last->ec - first->ec < WL_FREE_MAX_DIFF)
+		e = rb_entry(root->rb_node, struct ubi_wl_entry, u.rb);
+	else
+		e = find_wl_entry(root, WL_FREE_MAX_DIFF/2);
+
+	return e;
+}
+
+/**
  * find_early_wl_entry - find wear-leveling entry with the lowest pnum.
  * @root: the RB-tree where to look for
  * @max_pnum: highest possible pnum
@@ -419,7 +442,7 @@ static struct ubi_wl_entry *find_early_wl_entry(struct rb_root *root,
 int ubi_wl_get_fm_peb(struct ubi_device *ubi, int max_pnum)
 {
 	int ret = -ENOSPC;
-	struct ubi_wl_entry *e, *first, *last;
+	struct ubi_wl_entry *e;
 
 	if (!ubi->free.rb_node) {
 		ubi_err("no free eraseblocks");
@@ -427,18 +450,9 @@ int ubi_wl_get_fm_peb(struct ubi_device *ubi, int max_pnum)
 		goto out;
 	}
 
-	if (max_pnum < 0) {
-		first = rb_entry(rb_first(&ubi->free),
-			struct ubi_wl_entry, u.rb);
-		last = rb_entry(rb_last(&ubi->free),
-			struct ubi_wl_entry, u.rb);
-
-		if (last->ec - first->ec < WL_FREE_MAX_DIFF)
-			e = rb_entry(ubi->free.rb_node,
-				struct ubi_wl_entry, u.rb);
-		else
-			e = find_wl_entry(&ubi->free, WL_FREE_MAX_DIFF/2);
-	} else
+	if (max_pnum < 0)
+		e = find_mean_wl_entry(&ubi->free);
+	else
 		e = find_early_wl_entry(&ubi->free, max_pnum);
 
 	if (!e)
@@ -464,7 +478,7 @@ out:
 static int __ubi_wl_get_peb(struct ubi_device *ubi)
 {
 	int err;
-	struct ubi_wl_entry *e, *first, *last;
+	struct ubi_wl_entry *e;
 
 retry:
 	spin_lock(&ubi->wl_lock);
@@ -483,13 +497,7 @@ retry:
 		goto retry;
 	}
 
-	first = rb_entry(rb_first(&ubi->free), struct ubi_wl_entry, u.rb);
-	last = rb_entry(rb_last(&ubi->free), struct ubi_wl_entry, u.rb);
-
-	if (last->ec - first->ec < WL_FREE_MAX_DIFF)
-		e = rb_entry(ubi->free.rb_node, struct ubi_wl_entry, u.rb);
-	else
-		e = find_wl_entry(&ubi->free, WL_FREE_MAX_DIFF/2);
+	e = find_mean_wl_entry(&ubi->free);
 
 	self_check_in_wl_tree(ubi, e, &ubi->free);
 
-- 
1.7.6.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 13/23] UBI: Fastmap: Add comments to fastmap paremters
  2012-06-01 15:16 UBI: Fastmap updates (v7+) Richard Weinberger
                   ` (11 preceding siblings ...)
  2012-06-01 15:16 ` [PATCH 12/23] ubi: fastmap: harmonize medium erase-counter seek algorithm Richard Weinberger
@ 2012-06-01 15:16 ` Richard Weinberger
  2012-06-01 15:16 ` [PATCH 14/23] UBI: Fastmap: Rename fastmap attributes Richard Weinberger
                   ` (10 subsequent siblings)
  23 siblings, 0 replies; 26+ messages in thread
From: Richard Weinberger @ 2012-06-01 15:16 UTC (permalink / raw)
  To: linux-mtd
  Cc: dedekind1, Richard Weinberger, adrian.hunter, Heinz.Egger,
	shmulik.ladkani, tglx, tim.bird

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/ubi-media.h |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/drivers/mtd/ubi/ubi-media.h b/drivers/mtd/ubi/ubi-media.h
index 35628c3..adca33c 100644
--- a/drivers/mtd/ubi/ubi-media.h
+++ b/drivers/mtd/ubi/ubi-media.h
@@ -389,9 +389,17 @@ struct ubi_vtbl_record {
 #define UBI_FM_POOL_MAGIC	0x67AF4D08
 #define UBI_FM_EBA_MAGIC	0xf0c040a8
 
-/* TODO: would be great to have short coments for the constants */
+/* A fastmap supber block can be located between PEB 0 and
+ * UBI_FM_MAX_START */
 #define UBI_FM_MAX_START	64
+
+/* A fastmap can use up to UBI_FM_MAX_BLOCKS PEBs */
 #define UBI_FM_MAX_BLOCKS	32
+
+/* 5% of the total number of PEBs have to be scanned while attaching
+ * from a fastmap.
+ * But the size of this pool is limited to be between UBI_FM_MIN_POOL_SIZE and
+ * UBI_FM_MAX_POOL_SIZE */
 #define UBI_FM_MIN_POOL_SIZE	8
 #define UBI_FM_MAX_POOL_SIZE	256
 
-- 
1.7.6.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 14/23] UBI: Fastmap: Rename fastmap attributes
  2012-06-01 15:16 UBI: Fastmap updates (v7+) Richard Weinberger
                   ` (12 preceding siblings ...)
  2012-06-01 15:16 ` [PATCH 13/23] UBI: Fastmap: Add comments to fastmap paremters Richard Weinberger
@ 2012-06-01 15:16 ` Richard Weinberger
  2012-06-01 15:16 ` [PATCH 15/23] UBI: Fastmap: Use reserved_pebs Richard Weinberger
                   ` (9 subsequent siblings)
  23 siblings, 0 replies; 26+ messages in thread
From: Richard Weinberger @ 2012-06-01 15:16 UTC (permalink / raw)
  To: linux-mtd
  Cc: dedekind1, Richard Weinberger, adrian.hunter, Heinz.Egger,
	shmulik.ladkani, tglx, tim.bird

... rename them to match the UBI names.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/fastmap.c   |   50 +++++++++++++++++++++---------------------
 drivers/mtd/ubi/ubi-media.h |   26 ++++++++++------------
 2 files changed, 37 insertions(+), 39 deletions(-)

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 80edfef..e2600cd 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -474,7 +474,7 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
 		goto fail_bad;
 
 	/* read EC values from free list */
-	for (i = 0; i < be32_to_cpu(fmhdr->nfree); i++) {
+	for (i = 0; i < be32_to_cpu(fmhdr->free_peb_count); i++) {
 		fmec = (struct ubi_fm_ec *)(fm_raw + fm_pos);
 		fm_pos += sizeof(*fmec);
 		if (fm_pos >= fm_size)
@@ -485,7 +485,7 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
 	}
 
 	/* read EC values from used list */
-	for (i = 0; i < be32_to_cpu(fmhdr->nused); i++) {
+	for (i = 0; i < be32_to_cpu(fmhdr->used_peb_count); i++) {
 		fmec = (struct ubi_fm_ec *)(fm_raw + fm_pos);
 		fm_pos += sizeof(*fmec);
 		if (fm_pos >= fm_size)
@@ -496,10 +496,10 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
 	}
 
 	ai->mean_ec = div_u64(ai->ec_sum, ai->ec_count);
-	ai->bad_peb_count = be32_to_cpu(fmhdr->nbad);
+	ai->bad_peb_count = be32_to_cpu(fmhdr->bad_peb_count);
 
 	/* Iterate over all volumes and read their EBA table */
-	for (i = 0; i < be32_to_cpu(fmhdr->nvol); i++) {
+	for (i = 0; i < be32_to_cpu(fmhdr->vol_count); i++) {
 		fmvhdr = (struct ubi_fm_volhdr *)(fm_raw + fm_pos);
 		fm_pos += sizeof(*fmvhdr);
 		if (fm_pos >= fm_size)
@@ -522,14 +522,14 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
 
 		fm_eba = (struct ubi_fm_eba *)(fm_raw + fm_pos);
 		fm_pos += sizeof(*fm_eba);
-		fm_pos += (sizeof(__be32) * be32_to_cpu(fm_eba->nused));
+		fm_pos += (sizeof(__be32) * be32_to_cpu(fm_eba->reserved_pebs));
 		if (fm_pos >= fm_size)
 			goto fail_bad;
 
 		if (fm_eba->magic != UBI_FM_EBA_MAGIC)
 			goto fail_bad;
 
-		for (j = 0; j < be32_to_cpu(fm_eba->nused); j++) {
+		for (j = 0; j < be32_to_cpu(fm_eba->reserved_pebs); j++) {
 
 			if ((int)be32_to_cpu(fm_eba->pnum[j]) < 0)
 				continue;
@@ -639,7 +639,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai)
 	struct ubi_fm_sb *fmsb;
 	struct ubi_vid_hdr *vh;
 	struct ubi_ec_hdr *ech;
-	int ret, i, nblocks, pnum;
+	int ret, i, used_blocks, pnum;
 	int sb_pnum = 0;
 	char *fm_raw;
 	size_t fm_size;
@@ -691,9 +691,9 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai)
 		goto out;
 	}
 
-	nblocks = be32_to_cpu(fmsb->nblocks);
+	used_blocks = be32_to_cpu(fmsb->used_blocks);
 
-	if (nblocks > UBI_FM_MAX_BLOCKS || nblocks < 1) {
+	if (used_blocks > UBI_FM_MAX_BLOCKS || used_blocks < 1) {
 		ubi_err("number of fastmap blocks is invalid");
 		ret = UBI_BAD_FASTMAP;
 		kfree(fmsb);
@@ -701,7 +701,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai)
 		goto out;
 	}
 
-	fm_size = ubi->leb_size * nblocks;
+	fm_size = ubi->leb_size * used_blocks;
 	/* fm_raw will contain the whole fastmap */
 	fm_raw = vzalloc(fm_size);
 	if (!fm_raw) {
@@ -728,7 +728,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai)
 		goto free_raw;
 	}
 
-	for (i = 0; i < nblocks; i++) {
+	for (i = 0; i < used_blocks; i++) {
 		pnum = be32_to_cpu(fmsb->block_loc[i]);
 
 		if (ubi_io_is_bad(ubi, pnum)) {
@@ -834,9 +834,9 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai)
 	}
 
 	ai->fm->size = fm_size;
-	ai->fm->used_blocks = nblocks;
+	ai->fm->used_blocks = used_blocks;
 
-	for (i = 0; i < nblocks; i++) {
+	for (i = 0; i < used_blocks; i++) {
 		struct ubi_wl_entry *e;
 
 		e = kmem_cache_alloc(ubi_wl_entry_slab, GFP_KERNEL);
@@ -891,7 +891,7 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
 
 	struct ubi_vid_hdr *avhdr, *dvhdr;
 
-	int nfree, nused, nvol;
+	int free_peb_count, used_peb_count, vol_count;
 
 	fm_raw = vzalloc(new_fm->size);
 	if (!fm_raw) {
@@ -927,14 +927,14 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
 
 	fmsb->magic = UBI_FM_SB_MAGIC;
 	fmsb->version = UBI_FM_FMT_VERSION;
-	fmsb->nblocks = cpu_to_be32(new_fm->used_blocks);
+	fmsb->used_blocks = cpu_to_be32(new_fm->used_blocks);
 	/* the max sqnum will be filled in while *reading* the fastmap */
 	fmsb->sqnum = 0;
 
 	fmh->magic = UBI_FM_HDR_MAGIC;
-	nfree = 0;
-	nused = 0;
-	nvol = 0;
+	free_peb_count = 0;
+	used_peb_count = 0;
+	vol_count = 0;
 
 	fmpl = (struct ubi_fm_scan_pool *)(fm_raw + fm_pos);
 	fm_pos += sizeof(*fmpl);
@@ -951,11 +951,11 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
 		fec->pnum = cpu_to_be32(wl_e->pnum);
 		fec->ec = cpu_to_be32(wl_e->ec);
 
-		nfree++;
+		free_peb_count++;
 		fm_pos += sizeof(*fec);
 		ubi_assert(fm_pos <= new_fm->size);
 	}
-	fmh->nfree = cpu_to_be32(nfree);
+	fmh->free_peb_count = cpu_to_be32(free_peb_count);
 
 	for (node = rb_first(&ubi->used); node; node = rb_next(node)) {
 		wl_e = rb_entry(node, struct ubi_wl_entry, u.rb);
@@ -964,11 +964,11 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
 		fec->pnum = cpu_to_be32(wl_e->pnum);
 		fec->ec = cpu_to_be32(wl_e->ec);
 
-		nused++;
+		used_peb_count++;
 		fm_pos += sizeof(*fec);
 		ubi_assert(fm_pos <= new_fm->size);
 	}
-	fmh->nused = cpu_to_be32(nused);
+	fmh->used_peb_count = cpu_to_be32(used_peb_count);
 
 	for (i = 0; i < UBI_MAX_VOLUMES + UBI_INT_VOL_COUNT; i++) {
 		vol = ubi->volumes[i];
@@ -976,7 +976,7 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
 		if (!vol)
 			continue;
 
-		nvol++;
+		vol_count++;
 
 		fvh = (struct ubi_fm_volhdr *)(fm_raw + fm_pos);
 		fm_pos += sizeof(*fvh);
@@ -999,10 +999,10 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
 		for (j = 0; j < vol->used_ebs; j++)
 			feba->pnum[j] = cpu_to_be32(vol->eba_tbl[j]);
 
-		feba->nused = cpu_to_be32(j);
+		feba->reserved_pebs = cpu_to_be32(j);
 		feba->magic = UBI_FM_EBA_MAGIC;
 	}
-	fmh->nvol = cpu_to_be32(nvol);
+	fmh->vol_count = cpu_to_be32(vol_count);
 
 	avhdr->sqnum = cpu_to_be64(ubi_next_sqnum(ubi));
 	avhdr->lnum = 0;
diff --git a/drivers/mtd/ubi/ubi-media.h b/drivers/mtd/ubi/ubi-media.h
index adca33c..b4ecd1b 100644
--- a/drivers/mtd/ubi/ubi-media.h
+++ b/drivers/mtd/ubi/ubi-media.h
@@ -408,7 +408,7 @@ struct ubi_vtbl_record {
  * @magic: fastmap super block magic number (%UBI_FM_SB_MAGIC)
  * @version: format version of this fastmap
  * @data_crc: CRC over the fastmap data
- * @nblocks: number of PEBs used by this fastmap
+ * @used_blocks: number of PEBs used by this fastmap
  * @block_loc: an array containing the location of all PEBs of the fastmap
  * @block_ec: the erase counter of each used PEB
  * @sqnum: highest sequence number value at the time while taking the fastmap
@@ -419,7 +419,7 @@ struct ubi_fm_sb {
 	__u8 version;
 	__u8 padding1[3];
 	__be32 data_crc;
-	__be32 nblocks;
+	__be32 used_blocks;
 	__be32 block_loc[UBI_FM_MAX_BLOCKS];
 	__be32 block_ec[UBI_FM_MAX_BLOCKS];
 	__be64 sqnum;
@@ -429,19 +429,17 @@ struct ubi_fm_sb {
 /**
  * struct ubi_fm_hdr - header of the fastmap data set
  * @magic: fastmap header magic number (%UBI_FM_HDR_MAGIC)
- * @nfree: number of free PEBs known by this fastmap
- * @nused: number of used PEBs known by this fastmap
- * @nvol: number of UBI volumes known by this fastmap
+ * @free_peb_count: number of free PEBs known by this fastmap
+ * @free_peb_count: number of used PEBs known by this fastmap
+ * @vol_count: number of UBI volumes known by this fastmap
+ * @bad_peb_count: number of bad PEBs known by this fastmap
  */
 struct ubi_fm_hdr {
 	__be32 magic;
-	/* TODO: would you please name these fields using the same names UBI
-	 * uses in the in-RAM data structures (bad_peb_count, good_peb_count,
-	 * etc.) See struct ubi_device. */
-	__be32 nfree;
-	__be32 nused;
-	__be32 nvol;
-	__be32 nbad;
+	__be32 free_peb_count;
+	__be32 used_peb_count;
+	__be32 vol_count;
+	__be32 bad_peb_count;
 	__u8 padding[12];
 } __packed;
 
@@ -498,12 +496,12 @@ struct ubi_fm_volhdr {
 /**
  * struct ubi_fm_eba - denotes an association beween a PEB and LEB
  * @magic EBA table magic number
- * @nused: number of table entries
+ * @reserved_pebs: number of table entries
  * @pnum: PEB number of LEB (LEB is the index)
  */
 struct ubi_fm_eba {
 	__be32 magic;
-	__be32 nused;
+	__be32 reserved_pebs;
 	__be32 pnum[0];
 } __packed;
 #endif /* !__UBI_MEDIA_H__ */
-- 
1.7.6.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 15/23] UBI: Fastmap: Use reserved_pebs
  2012-06-01 15:16 UBI: Fastmap updates (v7+) Richard Weinberger
                   ` (13 preceding siblings ...)
  2012-06-01 15:16 ` [PATCH 14/23] UBI: Fastmap: Rename fastmap attributes Richard Weinberger
@ 2012-06-01 15:16 ` Richard Weinberger
  2012-06-01 15:16 ` [PATCH 16/23] UBI: Fastmap: Store bad_peb_count in fastmap Richard Weinberger
                   ` (8 subsequent siblings)
  23 siblings, 0 replies; 26+ messages in thread
From: Richard Weinberger @ 2012-06-01 15:16 UTC (permalink / raw)
  To: linux-mtd
  Cc: dedekind1, Richard Weinberger, adrian.hunter, Heinz.Egger,
	shmulik.ladkani, tglx, tim.bird

The eba_tbl is reserved_pebs sized, not used_ebs.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/fastmap.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index e2600cd..dad0251 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -993,10 +993,10 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
 			vol->vol_type == UBI_STATIC_VOLUME);
 
 		feba = (struct ubi_fm_eba *)(fm_raw + fm_pos);
-		fm_pos += sizeof(*feba) + (sizeof(__be32) * vol->used_ebs);
+		fm_pos += sizeof(*feba) + (sizeof(__be32) * vol->reserved_pebs);
 		ubi_assert(fm_pos <= new_fm->size);
 
-		for (j = 0; j < vol->used_ebs; j++)
+		for (j = 0; j < vol->reserved_pebs; j++)
 			feba->pnum[j] = cpu_to_be32(vol->eba_tbl[j]);
 
 		feba->reserved_pebs = cpu_to_be32(j);
-- 
1.7.6.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 16/23] UBI: Fastmap: Store bad_peb_count in fastmap
  2012-06-01 15:16 UBI: Fastmap updates (v7+) Richard Weinberger
                   ` (14 preceding siblings ...)
  2012-06-01 15:16 ` [PATCH 15/23] UBI: Fastmap: Use reserved_pebs Richard Weinberger
@ 2012-06-01 15:16 ` Richard Weinberger
  2012-06-01 15:16 ` [PATCH 17/23] UBI: Fastmap: Add ubi_assert() Richard Weinberger
                   ` (7 subsequent siblings)
  23 siblings, 0 replies; 26+ messages in thread
From: Richard Weinberger @ 2012-06-01 15:16 UTC (permalink / raw)
  To: linux-mtd
  Cc: dedekind1, Richard Weinberger, adrian.hunter, Heinz.Egger,
	shmulik.ladkani, tglx, tim.bird

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/fastmap.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index dad0251..85474a8 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -1003,6 +1003,7 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
 		feba->magic = UBI_FM_EBA_MAGIC;
 	}
 	fmh->vol_count = cpu_to_be32(vol_count);
+	fmh->bad_peb_count = cpu_to_be32(ubi->bad_peb_count);
 
 	avhdr->sqnum = cpu_to_be64(ubi_next_sqnum(ubi));
 	avhdr->lnum = 0;
-- 
1.7.6.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 17/23] UBI: Fastmap: Add ubi_assert()
  2012-06-01 15:16 UBI: Fastmap updates (v7+) Richard Weinberger
                   ` (15 preceding siblings ...)
  2012-06-01 15:16 ` [PATCH 16/23] UBI: Fastmap: Store bad_peb_count in fastmap Richard Weinberger
@ 2012-06-01 15:16 ` Richard Weinberger
  2012-06-01 15:16 ` [PATCH 18/23] UBI: Fastmap: Handle bitflipps correctly Richard Weinberger
                   ` (6 subsequent siblings)
  23 siblings, 0 replies; 26+ messages in thread
From: Richard Weinberger @ 2012-06-01 15:16 UTC (permalink / raw)
  To: linux-mtd
  Cc: dedekind1, Richard Weinberger, adrian.hunter, Heinz.Egger,
	shmulik.ladkani, tglx, tim.bird

Ensure that this corner case is valid.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/fastmap.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 85474a8..a0919ec 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -195,6 +195,7 @@ static int update_vol(struct ubi_device *ubi, struct ubi_attach_info *ai,
 		 * Then a PEB can be within the persistent EBA and the pool.
 		 */
 		if (aeb->pnum == new_aeb->pnum) {
+			ubi_assert(aeb->lnum == new_aeb->lnum);
 			kmem_cache_free(ai->aeb_slab_cache, new_aeb);
 
 			return 0;
-- 
1.7.6.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 18/23] UBI: Fastmap: Handle bitflipps correctly
  2012-06-01 15:16 UBI: Fastmap updates (v7+) Richard Weinberger
                   ` (16 preceding siblings ...)
  2012-06-01 15:16 ` [PATCH 17/23] UBI: Fastmap: Add ubi_assert() Richard Weinberger
@ 2012-06-01 15:16 ` Richard Weinberger
  2012-06-01 15:16 ` [PATCH 19/23] UBI: Fastmap: Handle protection queue correctly Richard Weinberger
                   ` (5 subsequent siblings)
  23 siblings, 0 replies; 26+ messages in thread
From: Richard Weinberger @ 2012-06-01 15:16 UTC (permalink / raw)
  To: linux-mtd
  Cc: dedekind1, Richard Weinberger, adrian.hunter, Heinz.Egger,
	shmulik.ladkani, tglx, tim.bird

Do not treat UBI_IO_BITFLIPS and UBI_FF_BITFLIPS as errors.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/fastmap.c |   37 ++++++++++++++++++++-----------------
 1 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index a0919ec..9edc6a1 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -226,6 +226,7 @@ static int update_vol(struct ubi_device *ubi, struct ubi_attach_info *ai,
 			aeb->ec = new_aeb->ec;
 			aeb->pnum = new_aeb->pnum;
 			aeb->copy_flag = new_vh->copy_flag;
+			aeb->scrub = new_aeb->scrub;
 			kmem_cache_free(ai->aeb_slab_cache, new_aeb);
 
 		/* new_aeb is older */
@@ -352,16 +353,24 @@ static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai,
 
 		err = ubi_io_read_vid_hdr(ubi, pnum, vh, 0);
 
-		if (err == UBI_IO_FF)
+		if (err == UBI_IO_FF || err == UBI_IO_FF_BITFLIPS)
 			continue;
-		else if (err == 0) {
+		else if (err == 0 || err == UBI_IO_BITFLIPS) {
+			int scrub = 0;
+
+			ubi_msg("Found non empty PEB:%i in pool", pnum);
+
+			if (err == UBI_IO_BITFLIPS)
+				scrub = 1;
+
 			err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0);
-			if (err) {
+			if (err && err != UBI_IO_BITFLIPS) {
 				dbg_bld("unable to read EC header!");
 				ret = err > 0 ? UBI_BAD_FASTMAP : err;
 
 				goto out;
-			}
+			} else if (ret == UBI_IO_BITFLIPS)
+				scrub = 1;
 
 			if (be32_to_cpu(ech->image_seq) != ubi->image_seq) {
 				dbg_bld("image seq mismatch!");
@@ -383,7 +392,10 @@ static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai,
 			new_aeb->lnum = be32_to_cpu(vh->lnum);
 			new_aeb->sqnum = be64_to_cpu(vh->sqnum);
 			new_aeb->copy_flag = vh->copy_flag;
-			new_aeb->scrub = 0;
+			new_aeb->scrub = scrub;
+
+			if (*max_sqnum < new_aeb->sqnum)
+				*max_sqnum = new_aeb->sqnum;
 
 			err = process_pool_aeb(ubi, ai, vh, new_aeb);
 			if (err) {
@@ -391,9 +403,6 @@ static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai,
 
 				goto out;
 			}
-
-			if (*max_sqnum < new_aeb->sqnum)
-				*max_sqnum = new_aeb->sqnum;
 		} else {
 			/* We are paranoid and fall back to scanning mode */
 			ubi_err("fastmap pool PEBs contains damaged PEBs!");
@@ -661,13 +670,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai)
 	}
 
 	ret = ubi_io_read(ubi, fmsb, sb_pnum, ubi->leb_start, sizeof(*fmsb));
-	if (ret) {
-		ubi_err("unable to read fastmap super block");
-		/* TODO: please, read what 'ubi_io_read()' returns.
-		 * This code is incorrect. All return codes are carefully
-		 * documented there. And do it globally, I see you ignore the
-		 * bitflips error code and treat it as error everywhere.
-		 * Please, start testing with UBI bit-flips emulation enabled */
+	if (ret && ret != UBI_IO_BITFLIPS) {
 		if (ret > 0)
 			ret = UBI_BAD_FASTMAP;
 
@@ -740,7 +743,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai)
 		}
 
 		ret = ubi_io_read_ec_hdr(ubi, pnum, ech, 0);
-		if (ret) {
+		if (ret && ret != UBI_IO_BITFLIPS) {
 			ubi_err("unable to read fastmap block# %i EC (PEB: %i)",
 				i, pnum);
 			if (ret > 0)
@@ -1149,7 +1152,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 
 			ret = ubi_io_read_ec_hdr(ubi, old_fm->e[0]->pnum,
 				ec_hdr, 0);
-			if (ret) {
+			if (ret && ret != UBI_IO_BITFLIPS) {
 				ubi_err("unable to read EC header");
 				kfree(ec_hdr);
 
-- 
1.7.6.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 19/23] UBI: Fastmap: Handle protection queue correctly
  2012-06-01 15:16 UBI: Fastmap updates (v7+) Richard Weinberger
                   ` (17 preceding siblings ...)
  2012-06-01 15:16 ` [PATCH 18/23] UBI: Fastmap: Handle bitflipps correctly Richard Weinberger
@ 2012-06-01 15:16 ` Richard Weinberger
  2012-06-01 15:16 ` [PATCH 20/23] UBI: Fastmap: Write fastmap only at detach time if none is present Richard Weinberger
                   ` (4 subsequent siblings)
  23 siblings, 0 replies; 26+ messages in thread
From: Richard Weinberger @ 2012-06-01 15:16 UTC (permalink / raw)
  To: linux-mtd
  Cc: dedekind1, Richard Weinberger, adrian.hunter, Heinz.Egger,
	shmulik.ladkani, tglx, tim.bird

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

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 20/23] UBI: Fastmap: Write fastmap only at detach time if none is present
  2012-06-01 15:16 UBI: Fastmap updates (v7+) Richard Weinberger
                   ` (18 preceding siblings ...)
  2012-06-01 15:16 ` [PATCH 19/23] UBI: Fastmap: Handle protection queue correctly Richard Weinberger
@ 2012-06-01 15:16 ` Richard Weinberger
  2012-06-01 15:16 ` [PATCH 21/23] UBI: Fastmap: Fix error message Richard Weinberger
                   ` (3 subsequent siblings)
  23 siblings, 0 replies; 26+ messages in thread
From: Richard Weinberger @ 2012-06-01 15:16 UTC (permalink / raw)
  To: linux-mtd
  Cc: dedekind1, Richard Weinberger, adrian.hunter, Heinz.Egger,
	shmulik.ladkani, tglx, tim.bird

Write a fastmap only if currently no fastmap is present on the FLASH.
Also write it after the UBI thread has stopped.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/build.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 4a8688a..2acfe5b 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -1045,7 +1045,6 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
 	ubi_assert(ubi_num == ubi->ubi_num);
 	ubi_notify_all(ubi, UBI_VOLUME_REMOVED, NULL);
 	dbg_msg("detaching mtd%d from ubi%d", ubi->mtd->index, ubi_num);
-	ubi_update_fastmap(ubi);
 
 	/*
 	 * Before freeing anything, we have to stop the background thread to
@@ -1054,6 +1053,10 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
 	if (ubi->bgt_thread)
 		kthread_stop(ubi->bgt_thread);
 
+	/* If no fastmap is present on the FLASH write one. */
+	if (!ubi->fm)
+		ubi_update_fastmap(ubi);
+
 	/*
 	 * Get a reference to the device in order to prevent 'dev_release()'
 	 * from freeing the @ubi object.
-- 
1.7.6.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 21/23] UBI: Fastmap: Fix error message
  2012-06-01 15:16 UBI: Fastmap updates (v7+) Richard Weinberger
                   ` (19 preceding siblings ...)
  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 ` Richard Weinberger
  2012-06-01 15:16 ` [PATCH 22/23] UBI: Fastmap: Address one of Artems TODOs Richard Weinberger
                   ` (2 subsequent siblings)
  23 siblings, 0 replies; 26+ messages in thread
From: Richard Weinberger @ 2012-06-01 15:16 UTC (permalink / raw)
  To: linux-mtd
  Cc: dedekind1, Richard Weinberger, adrian.hunter, Heinz.Egger,
	shmulik.ladkani, tglx, tim.bird

Print the message in ubi_scan_fastmap().

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/attach.c  |   10 ----------
 drivers/mtd/ubi/fastmap.c |    3 +++
 2 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
index 4d86621..44f3770 100644
--- a/drivers/mtd/ubi/attach.c
+++ b/drivers/mtd/ubi/attach.c
@@ -1222,16 +1222,6 @@ int ubi_attach(struct ubi_device *ubi)
 
 	err = ubi_scan_fastmap(ubi, ai);
 	if (err > 0) {
-		/* TODO: in UBIFS we have a convention: every function prints
-		 * its own error messages. This makes things cleaner and easier
-		 * - the caller should not care about printing anything.
-		 * Please, move this error message to 'ubi_scan_fastmap()'. And
-		 * keep this in mind, and do similar thing globally for entire
-		 * fastmap code. */
-		if (err == UBI_BAD_FASTMAP)
-			ubi_err("Attach by fastmap failed! "
-				"Falling back to attach by scanning.");
-
 		err = scan_all(ubi, ai);
 		if (err)
 			return err;
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 78f196d..90bcaf0 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -936,6 +936,9 @@ free_hdr:
 free_raw:
 	vfree(fm_raw);
 out:
+	if (ret == UBI_BAD_FASTMAP)
+		ubi_err("Attach by fastmap failed, doing a full scan!");
+
 	return ret;
 }
 
-- 
1.7.6.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 22/23] UBI: Fastmap: Address one of Artems TODOs
  2012-06-01 15:16 UBI: Fastmap updates (v7+) Richard Weinberger
                   ` (20 preceding siblings ...)
  2012-06-01 15:16 ` [PATCH 21/23] UBI: Fastmap: Fix error message Richard Weinberger
@ 2012-06-01 15:16 ` 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
  23 siblings, 0 replies; 26+ messages in thread
From: Richard Weinberger @ 2012-06-01 15:16 UTC (permalink / raw)
  To: linux-mtd
  Cc: dedekind1, Richard Weinberger, adrian.hunter, Heinz.Egger,
	shmulik.ladkani, tglx, tim.bird

/* TODO: If you support fastmap but it was not found, you need to check
 * here that ai does not contain fastmap volumes. If it was corrupted,
 * you need to delete fastmap volumes or possible leftovers of them.
 * And then you have to create _new_ fastmap */

If we support fastmap and it was not found or corrupted we fall back to
scanning mode. While scanning mode the corrupted/partial fastmap will be
deleted.
There is also no need to create a new fastmap here.
It will be created automatically.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/attach.c |    4 ----
 1 files changed, 0 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
index 44f3770..acf7db3 100644
--- a/drivers/mtd/ubi/attach.c
+++ b/drivers/mtd/ubi/attach.c
@@ -1241,10 +1241,6 @@ int ubi_attach(struct ubi_device *ubi)
 	ubi->mean_ec = ai->mean_ec;
 	ubi_msg("max. sequence number:       %llu", ai->max_sqnum);
 
-	/* TODO: If you support fastmap but it was not found, you need to check
-	 * here that ai does not contain fastmap volumes. If it was corrupted,
-	 * you need to delete fastmap volumes or possible leftovers of them.
-	 * And then you have to create _new_ fastmap */
 	err = ubi_read_volume_table(ubi, ai);
 	if (err)
 		goto out_ai;
-- 
1.7.6.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 23/23] UBI: Fastmap: Make checkpatch.pl happy (again)
  2012-06-01 15:16 UBI: Fastmap updates (v7+) Richard Weinberger
                   ` (21 preceding siblings ...)
  2012-06-01 15:16 ` [PATCH 22/23] UBI: Fastmap: Address one of Artems TODOs Richard Weinberger
@ 2012-06-01 15:16 ` Richard Weinberger
  2012-06-01 17:50 ` UBI: Fastmap updates (v7+) Artem Bityutskiy
  23 siblings, 0 replies; 26+ messages in thread
From: Richard Weinberger @ 2012-06-01 15:16 UTC (permalink / raw)
  To: linux-mtd
  Cc: dedekind1, Richard Weinberger, adrian.hunter, Heinz.Egger,
	shmulik.ladkani, tglx, tim.bird

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/fastmap.c |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 90bcaf0..a8143da 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -570,12 +570,15 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
 			}
 
 			/* 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.
+			 * 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 protection
+			 * queue.
 			 */
 			if (!aeb) {
-				aeb = kmem_cache_alloc(ai->aeb_slab_cache, GFP_KERNEL);
+				aeb = kmem_cache_alloc(ai->aeb_slab_cache,
+					GFP_KERNEL);
 				if (!aeb) {
 					ret = -ENOMEM;
 
@@ -610,7 +613,8 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
 			goto fail;
 		}
 
-		list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &eba_orphans, u.list) {
+		list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &eba_orphans,
+			u.list) {
 			int err;
 
 			if (ubi_io_is_bad(ubi, tmp_aeb->pnum)) {
@@ -693,7 +697,8 @@ static int ubi_find_fastmap(struct ubi_device *ubi, int *fm_start)
 
 		if (be32_to_cpu(vhdr->vol_id) == UBI_FM_SB_VOLUME_ID) {
 			sqnum = be64_to_cpu(vhdr->sqnum);
-			dbg_bld("found a fastmap super block at PEB %i sqnum: %llu", i, sqnum);
+			dbg_bld("found a fastmap super block at PEB %i " \
+				"sqnum: %llu", i, sqnum);
 
 			if (sqnum > max_sqnum) {
 				max_sqnum = sqnum;
@@ -1229,7 +1234,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 				ubi_err("unable to read EC header");
 				kfree(ec_hdr);
 
-				goto err;;
+				goto err;
 			}
 
 			ret = ubi_io_sync_erase(ubi, old_fm->e[0]->pnum,
-- 
1.7.6.5

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: UBI: Fastmap updates (v7+)
  2012-06-01 15:16 UBI: Fastmap updates (v7+) Richard Weinberger
                   ` (22 preceding siblings ...)
  2012-06-01 15:16 ` [PATCH 23/23] UBI: Fastmap: Make checkpatch.pl happy (again) Richard Weinberger
@ 2012-06-01 17:50 ` Artem Bityutskiy
  2012-06-01 18:00   ` Richard Weinberger
  23 siblings, 1 reply; 26+ messages in thread
From: Artem Bityutskiy @ 2012-06-01 17:50 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: adrian.hunter, Heinz.Egger, linux-mtd, shmulik.ladkani, tglx, tim.bird

[-- Attachment #1: Type: text/plain, Size: 307 bytes --]

On Fri, 2012-06-01 at 17:16 +0200, Richard Weinberger wrote:
> All patches have been tested with ubi-tests.

While this is being reviewed, you could enable the bit-flips emulation
in UBI (there is a debugfs switch for this) and test how this handles
bit-flips.

-- 
Best Regards,
Artem Bityutskiy

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: UBI: Fastmap updates (v7+)
  2012-06-01 17:50 ` UBI: Fastmap updates (v7+) Artem Bityutskiy
@ 2012-06-01 18:00   ` Richard Weinberger
  0 siblings, 0 replies; 26+ messages in thread
From: Richard Weinberger @ 2012-06-01 18:00 UTC (permalink / raw)
  To: Artem Bityutskiy
  Cc: adrian.hunter, Heinz.Egger, linux-mtd, shmulik.ladkani, tglx, tim.bird

[-- Attachment #1: Type: text/plain, Size: 421 bytes --]

Am 01.06.2012 19:50, schrieb Artem Bityutskiy:
> On Fri, 2012-06-01 at 17:16 +0200, Richard Weinberger wrote:
>> All patches have been tested with ubi-tests.
> 
> While this is being reviewed, you could enable the bit-flips emulation
> in UBI (there is a debugfs switch for this) and test how this handles
> bit-flips.

Of course I've tested fastmap already with bit-flips emulation. :-)

Thanks,
//richard


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2012-06-01 18:00 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 19/23] UBI: Fastmap: Handle protection queue correctly Richard Weinberger
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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.