linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* UBI fastmap updates
@ 2012-06-29 15:14 Richard Weinberger
  2012-06-29 15:14 ` [PATCH 01/11] UBI: Fastmap: Fix mem leak in error path Richard Weinberger
                   ` (12 more replies)
  0 siblings, 13 replies; 23+ messages in thread
From: Richard Weinberger @ 2012-06-29 15:14 UTC (permalink / raw)
  To: linux-mtd
  Cc: linux-kernel, adrian.hunter, Heinz.Egger, thomas.wucher,
	shmulik.ladkani, tglx, tim.bird, Marius.Mazarel,
	artem.bityutskiy, nyoushchenko

This is the next round of UBI fastmap updates.

Fastmap is now disabled by default.
If you attach an image it will not automatically convert it
to the fastmap format.
UBI has a new module parameter "fm_auto".
If set to 1 UBI will create a fastmap automatically on your
flash device.
Please see commit "Add a module parameter to enable fastmap"
for more details.

If you want to test fastmap you can use my git repo:
git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubi2.git ubi2/v15

Enjoy!
//richard

[PATCH 01/11] UBI: Fastmap: Fix mem leak in error path
[PATCH 02/11] UBI: Fastmap: Amend self_check_eba()
[PATCH 03/11] UBI: Fastmap: Remove forward declaration
[PATCH 04/11] UBI: Fastmap: Move fastmap specific code into
[PATCH 05/11] UBI: Fastmap: Kill TODO
[PATCH 06/11] UBI: Fastmap: Remove unused variable
[PATCH 07/11] UBI: Fastmap: Fix scan regression
[PATCH 08/11] ubi: fastmap: Remove 'ubi' parameter of 'destroy_ai()'
[PATCH 09/11] ubi: fastmap: Do not free 'ai' in 'scan_all()'
[PATCH 10/11] UBI: Fastmap: Disable fastmap per default
[PATCH 11/11] UBI: Fastmap: Add a module parameter to enable fastmap

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

* [PATCH 01/11] UBI: Fastmap: Fix mem leak in error path
  2012-06-29 15:14 UBI fastmap updates Richard Weinberger
@ 2012-06-29 15:14 ` Richard Weinberger
  2012-06-29 15:14 ` [PATCH 02/11] UBI: Fastmap: Amend self_check_eba() Richard Weinberger
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 23+ messages in thread
From: Richard Weinberger @ 2012-06-29 15:14 UTC (permalink / raw)
  To: linux-mtd
  Cc: linux-kernel, adrian.hunter, Heinz.Egger, thomas.wucher,
	shmulik.ladkani, tglx, tim.bird, Marius.Mazarel,
	artem.bityutskiy, nyoushchenko, Richard Weinberger

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

diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
index 3d9be42..bd3a8f5 100644
--- a/drivers/mtd/ubi/attach.c
+++ b/drivers/mtd/ubi/attach.c
@@ -1325,12 +1325,12 @@ int ubi_attach(struct ubi_device *ubi, int force_scan)
 
 		scan_ai = alloc_ai();
 		if (!scan_ai)
-			goto out_ai;
+			goto out_wl;
 
 		err = scan_all(ubi, scan_ai);
 		if (err) {
 			kfree(scan_ai);
-			goto out_ai;
+			goto out_wl;
 		}
 
 		self_check_eba(ubi, ai, scan_ai);
-- 
1.7.6.5


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

* [PATCH 02/11] UBI: Fastmap: Amend self_check_eba()
  2012-06-29 15:14 UBI fastmap updates Richard Weinberger
  2012-06-29 15:14 ` [PATCH 01/11] UBI: Fastmap: Fix mem leak in error path Richard Weinberger
@ 2012-06-29 15:14 ` Richard Weinberger
  2012-06-29 15:14 ` [PATCH 03/11] UBI: Fastmap: Remove forward declaration Richard Weinberger
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 23+ messages in thread
From: Richard Weinberger @ 2012-06-29 15:14 UTC (permalink / raw)
  To: linux-mtd
  Cc: linux-kernel, adrian.hunter, Heinz.Egger, thomas.wucher,
	shmulik.ladkani, tglx, tim.bird, Marius.Mazarel,
	artem.bityutskiy, nyoushchenko, Richard Weinberger

Don't BUG() on error and document return values.

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

diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
index bd3a8f5..f1dfb63 100644
--- a/drivers/mtd/ubi/attach.c
+++ b/drivers/mtd/ubi/attach.c
@@ -1333,8 +1333,11 @@ int ubi_attach(struct ubi_device *ubi, int force_scan)
 			goto out_wl;
 		}
 
-		self_check_eba(ubi, ai, scan_ai);
+		err = self_check_eba(ubi, ai, scan_ai);
 		destroy_ai(ubi, scan_ai);
+
+		if (err)
+			goto out_wl;
 	}
 
 	destroy_ai(ubi, ai);
diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
index 6d6e301..4fb80d0 100644
--- a/drivers/mtd/ubi/eba.c
+++ b/drivers/mtd/ubi/eba.c
@@ -1223,7 +1223,9 @@ static void print_rsvd_warning(struct ubi_device *ubi,
  * @ai_fastmap: UBI attach info object created by fastmap
  * @ai_scan: UBI attach info object created by scanning
  *
- * TODO: what we do and what return.
+ * Returns < 0 in case of an internal error, 0 otherwise.
+ * If a bad EBA table entry was found it will be printed out and
+ * ubi_assert() triggers.
  */
 int self_check_eba(struct ubi_device *ubi, struct ubi_attach_info *ai_fastmap,
 		   struct ubi_attach_info *ai_scan)
@@ -1291,8 +1293,7 @@ int self_check_eba(struct ubi_device *ubi, struct ubi_attach_info *ai_fastmap,
 
 				ubi_err("LEB:%i:%i is PEB:%i instead of %i!",
 					vol->vol_id, i, fm_eba[i][j], scan_eba[i][j]);
-				/* TODO: no, please, return error instead */
-				BUG();
+				ubi_assert(0);
 			}
 		}
 	}
-- 
1.7.6.5


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

* [PATCH 03/11] UBI: Fastmap: Remove forward declaration
  2012-06-29 15:14 UBI fastmap updates Richard Weinberger
  2012-06-29 15:14 ` [PATCH 01/11] UBI: Fastmap: Fix mem leak in error path Richard Weinberger
  2012-06-29 15:14 ` [PATCH 02/11] UBI: Fastmap: Amend self_check_eba() Richard Weinberger
@ 2012-06-29 15:14 ` Richard Weinberger
  2012-06-29 15:14 ` [PATCH 04/11] UBI: Fastmap: Move fastmap specific code into ubi_scan_fastmap() Richard Weinberger
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 23+ messages in thread
From: Richard Weinberger @ 2012-06-29 15:14 UTC (permalink / raw)
  To: linux-mtd
  Cc: linux-kernel, adrian.hunter, Heinz.Egger, thomas.wucher,
	shmulik.ladkani, tglx, tim.bird, Marius.Mazarel,
	artem.bityutskiy, nyoushchenko, Richard Weinberger

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

diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
index f1dfb63..e88521b 100644
--- a/drivers/mtd/ubi/attach.c
+++ b/drivers/mtd/ubi/attach.c
@@ -89,15 +89,7 @@
 #include <linux/random.h>
 #include "ubi.h"
 
-/*
- * TODO: please, no forward declarations. We do not use them in UBI code.
- * Actually initially I did use them a lot, but when upstreaming, I was asked
- * to remove. Please, follow this convention as well. Please, change globally.
- * I mean, I am already used to that _all_ the code is upside-down, let's keep
- * it that way, or re-structure all the code. :-)
- */
 static int self_check_ai(struct ubi_device *ubi, struct ubi_attach_info *ai);
-static void destroy_ai(struct ubi_device *ubi, struct ubi_attach_info *ai);
 
 /* Temporary variables used during scanning */
 static struct ubi_ec_hdr *ech;
@@ -1132,6 +1124,95 @@ static int late_analysis(struct ubi_device *ubi, struct ubi_attach_info *ai)
 }
 
 /**
+ * destroy_av - free volume attaching information.
+ * @av: volume attaching information
+ * @ai: attaching information
+ *
+ * This function destroys the volume attaching information.
+ */
+static void destroy_av(struct ubi_attach_info *ai, struct ubi_ainf_volume *av)
+{
+	struct ubi_ainf_peb *aeb;
+	struct rb_node *this = av->root.rb_node;
+
+	while (this) {
+		if (this->rb_left)
+			this = this->rb_left;
+		else if (this->rb_right)
+			this = this->rb_right;
+		else {
+			aeb = rb_entry(this, struct ubi_ainf_peb, u.rb);
+			this = rb_parent(this);
+			if (this) {
+				if (this->rb_left == &aeb->u.rb)
+					this->rb_left = NULL;
+				else
+					this->rb_right = NULL;
+			}
+
+			kmem_cache_free(ai->aeb_slab_cache, aeb);
+		}
+	}
+	kfree(av);
+}
+
+/**
+ * destroy_ai - destroy attaching information.
+ * @ubi: UBI device object
+ * @ai: attaching information
+ */
+static void destroy_ai(struct ubi_device *ubi, struct ubi_attach_info *ai)
+{
+	struct ubi_ainf_peb *aeb, *aeb_tmp;
+	struct ubi_ainf_volume *av;
+	struct rb_node *rb;
+
+	list_for_each_entry_safe(aeb, aeb_tmp, &ai->alien, u.list) {
+		list_del(&aeb->u.list);
+		kmem_cache_free(ai->aeb_slab_cache, aeb);
+	}
+	list_for_each_entry_safe(aeb, aeb_tmp, &ai->erase, u.list) {
+		list_del(&aeb->u.list);
+		kmem_cache_free(ai->aeb_slab_cache, aeb);
+	}
+	list_for_each_entry_safe(aeb, aeb_tmp, &ai->corr, u.list) {
+		list_del(&aeb->u.list);
+		kmem_cache_free(ai->aeb_slab_cache, aeb);
+	}
+	list_for_each_entry_safe(aeb, aeb_tmp, &ai->free, u.list) {
+		list_del(&aeb->u.list);
+		kmem_cache_free(ai->aeb_slab_cache, aeb);
+	}
+
+	/* Destroy the volume RB-tree */
+	rb = ai->volumes.rb_node;
+	while (rb) {
+		if (rb->rb_left)
+			rb = rb->rb_left;
+		else if (rb->rb_right)
+			rb = rb->rb_right;
+		else {
+			av = rb_entry(rb, struct ubi_ainf_volume, rb);
+
+			rb = rb_parent(rb);
+			if (rb) {
+				if (rb->rb_left == &av->rb)
+					rb->rb_left = NULL;
+				else
+					rb->rb_right = NULL;
+			}
+
+			destroy_av(ai, av);
+		}
+	}
+
+	if (ai->aeb_slab_cache)
+		kmem_cache_destroy(ai->aeb_slab_cache);
+
+	kfree(ai);
+}
+
+/**
  * scan_all - scan entire MTD device.
  * @ubi: UBI device description object
  * @ai: attach info object
@@ -1354,95 +1435,6 @@ out_ai:
 }
 
 /**
- * destroy_av - free volume attaching information.
- * @av: volume attaching information
- * @ai: attaching information
- *
- * This function destroys the volume attaching information.
- */
-static void destroy_av(struct ubi_attach_info *ai, struct ubi_ainf_volume *av)
-{
-	struct ubi_ainf_peb *aeb;
-	struct rb_node *this = av->root.rb_node;
-
-	while (this) {
-		if (this->rb_left)
-			this = this->rb_left;
-		else if (this->rb_right)
-			this = this->rb_right;
-		else {
-			aeb = rb_entry(this, struct ubi_ainf_peb, u.rb);
-			this = rb_parent(this);
-			if (this) {
-				if (this->rb_left == &aeb->u.rb)
-					this->rb_left = NULL;
-				else
-					this->rb_right = NULL;
-			}
-
-			kmem_cache_free(ai->aeb_slab_cache, aeb);
-		}
-	}
-	kfree(av);
-}
-
-/**
- * destroy_ai - destroy attaching information.
- * @ubi: UBI device object
- * @ai: attaching information
- */
-static void destroy_ai(struct ubi_device *ubi, struct ubi_attach_info *ai)
-{
-	struct ubi_ainf_peb *aeb, *aeb_tmp;
-	struct ubi_ainf_volume *av;
-	struct rb_node *rb;
-
-	list_for_each_entry_safe(aeb, aeb_tmp, &ai->alien, u.list) {
-		list_del(&aeb->u.list);
-		kmem_cache_free(ai->aeb_slab_cache, aeb);
-	}
-	list_for_each_entry_safe(aeb, aeb_tmp, &ai->erase, u.list) {
-		list_del(&aeb->u.list);
-		kmem_cache_free(ai->aeb_slab_cache, aeb);
-	}
-	list_for_each_entry_safe(aeb, aeb_tmp, &ai->corr, u.list) {
-		list_del(&aeb->u.list);
-		kmem_cache_free(ai->aeb_slab_cache, aeb);
-	}
-	list_for_each_entry_safe(aeb, aeb_tmp, &ai->free, u.list) {
-		list_del(&aeb->u.list);
-		kmem_cache_free(ai->aeb_slab_cache, aeb);
-	}
-
-	/* Destroy the volume RB-tree */
-	rb = ai->volumes.rb_node;
-	while (rb) {
-		if (rb->rb_left)
-			rb = rb->rb_left;
-		else if (rb->rb_right)
-			rb = rb->rb_right;
-		else {
-			av = rb_entry(rb, struct ubi_ainf_volume, rb);
-
-			rb = rb_parent(rb);
-			if (rb) {
-				if (rb->rb_left == &av->rb)
-					rb->rb_left = NULL;
-				else
-					rb->rb_right = NULL;
-			}
-
-			destroy_av(ai, av);
-		}
-	}
-
-	if (ai->aeb_slab_cache)
-		kmem_cache_destroy(ai->aeb_slab_cache);
-
-	kfree(ai);
-}
-
-/**
  * self_check_ai - check the attaching information.
  * @ubi: UBI device description object
  * @ai: attaching information
-- 
1.7.6.5


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

* [PATCH 04/11] UBI: Fastmap: Move fastmap specific code into ubi_scan_fastmap()
  2012-06-29 15:14 UBI fastmap updates Richard Weinberger
                   ` (2 preceding siblings ...)
  2012-06-29 15:14 ` [PATCH 03/11] UBI: Fastmap: Remove forward declaration Richard Weinberger
@ 2012-06-29 15:14 ` Richard Weinberger
  2012-06-29 15:14 ` [PATCH 05/11] UBI: Fastmap: Kill TODO Richard Weinberger
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 23+ messages in thread
From: Richard Weinberger @ 2012-06-29 15:14 UTC (permalink / raw)
  To: linux-mtd
  Cc: linux-kernel, adrian.hunter, Heinz.Egger, thomas.wucher,
	shmulik.ladkani, tglx, tim.bird, Marius.Mazarel,
	artem.bityutskiy, nyoushchenko, Richard Weinberger

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

diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
index e88521b..1b62d54 100644
--- a/drivers/mtd/ubi/attach.c
+++ b/drivers/mtd/ubi/attach.c
@@ -1384,15 +1384,6 @@ int ubi_attach(struct ubi_device *ubi, int force_scan)
 	if (err)
 		goto out_ai;
 
-	/* TODO: Hmm why this code is not hidden in 'ubi_scan_fastmap()' ? */
-	if (ubi->fm) {
-		ubi->fm_pool.max_size = ubi->fm->max_pool_size;
-		ubi->fm_wl_pool.max_size = ubi->fm->max_wl_pool_size;
-
-		ubi_msg("fastmap pool size: %d", ubi->fm_pool.max_size);
-		ubi_msg("fastmap WL pool size: %d", ubi->fm_wl_pool.max_size);
-	}
-
 	err = ubi_wl_init(ubi, ai);
 	if (err)
 		goto out_vtbl;
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 2c7c350..9b4fd34 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -1096,6 +1096,10 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai)
 	}
 
 	ubi->fm = fm;
+	ubi->fm_pool.max_size = ubi->fm->max_pool_size;
+	ubi->fm_wl_pool.max_size = ubi->fm->max_wl_pool_size;
+	ubi_msg("fastmap pool size: %d", ubi->fm_pool.max_size);
+	ubi_msg("fastmap WL pool size: %d", ubi->fm_wl_pool.max_size);
 
 free_hdr:
 	ubi_free_vid_hdr(ubi, vh);
-- 
1.7.6.5


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

* [PATCH 05/11] UBI: Fastmap: Kill TODO
  2012-06-29 15:14 UBI fastmap updates Richard Weinberger
                   ` (3 preceding siblings ...)
  2012-06-29 15:14 ` [PATCH 04/11] UBI: Fastmap: Move fastmap specific code into ubi_scan_fastmap() Richard Weinberger
@ 2012-06-29 15:14 ` Richard Weinberger
  2012-06-29 15:14 ` [PATCH 06/11] UBI: Fastmap: Remove unused variable Richard Weinberger
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 23+ messages in thread
From: Richard Weinberger @ 2012-06-29 15:14 UTC (permalink / raw)
  To: linux-mtd
  Cc: linux-kernel, adrian.hunter, Heinz.Egger, thomas.wucher,
	shmulik.ladkani, tglx, tim.bird, Marius.Mazarel,
	artem.bityutskiy, nyoushchenko, Richard Weinberger

calling late_analysis() when fastmap is used does not make sense.

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

diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
index 1b62d54..9878cc2 100644
--- a/drivers/mtd/ubi/attach.c
+++ b/drivers/mtd/ubi/attach.c
@@ -1258,7 +1258,6 @@ static int scan_all(struct ubi_device *ubi, struct ubi_attach_info *ai)
 	if (ai->ec_count)
 		ai->mean_ec = div_u64(ai->ec_sum, ai->ec_count);
 
-	/* TODO: if we attach by fastmap, we do not execute this? */
 	err = late_analysis(ubi, ai);
 	if (err)
 		goto out_vidh;
-- 
1.7.6.5


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

* [PATCH 06/11] UBI: Fastmap: Remove unused variable
  2012-06-29 15:14 UBI fastmap updates Richard Weinberger
                   ` (4 preceding siblings ...)
  2012-06-29 15:14 ` [PATCH 05/11] UBI: Fastmap: Kill TODO Richard Weinberger
@ 2012-06-29 15:14 ` Richard Weinberger
  2012-06-29 15:14 ` [PATCH 07/11] UBI: Fastmap: Fix scan regression Richard Weinberger
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 23+ messages in thread
From: Richard Weinberger @ 2012-06-29 15:14 UTC (permalink / raw)
  To: linux-mtd
  Cc: linux-kernel, adrian.hunter, Heinz.Egger, thomas.wucher,
	shmulik.ladkani, tglx, tim.bird, Marius.Mazarel,
	artem.bityutskiy, nyoushchenko, Richard Weinberger

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

diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 6bf5349..8e2592d 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -393,8 +393,6 @@ struct ubi_wl_entry;
  * @fm_mutex: serializes ubi_update_fastmap()
  * @fm_sem: allows ubi_update_fastmap() to block EBA table changes
  * @fm_work: fastmap work queue
- * @attached_by_scanning: this UBI device was attached by the old scanning
- *			  methold. All fastmap volumes have to be deleted.
  *
  * @used: RB-tree of used physical eraseblocks
  * @erroneous: RB-tree of erroneous used physical eraseblocks
@@ -494,7 +492,6 @@ struct ubi_device {
 	struct rw_semaphore fm_sem;
 	struct mutex fm_mutex;
 	struct work_struct fm_work;
-	int attached_by_scanning;
 
 	/* Wear-leveling sub-system's stuff */
 	struct rb_root used;
-- 
1.7.6.5


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

* [PATCH 07/11] UBI: Fastmap: Fix scan regression
  2012-06-29 15:14 UBI fastmap updates Richard Weinberger
                   ` (5 preceding siblings ...)
  2012-06-29 15:14 ` [PATCH 06/11] UBI: Fastmap: Remove unused variable Richard Weinberger
@ 2012-06-29 15:14 ` Richard Weinberger
  2012-06-29 15:14 ` [PATCH 08/11] ubi: fastmap: Remove 'ubi' parameter of 'destroy_ai()' Richard Weinberger
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 23+ messages in thread
From: Richard Weinberger @ 2012-06-29 15:14 UTC (permalink / raw)
  To: linux-mtd
  Cc: linux-kernel, adrian.hunter, Heinz.Egger, thomas.wucher,
	shmulik.ladkani, tglx, tim.bird, Marius.Mazarel,
	artem.bityutskiy, nyoushchenko, Richard Weinberger

... resuse scan_peb(), don't rescan the first 64 PEBs.

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

diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
index 9878cc2..bc1e4bf 100644
--- a/drivers/mtd/ubi/attach.c
+++ b/drivers/mtd/ubi/attach.c
@@ -817,10 +817,11 @@ out_unlock:
  * successfully handled and a negative error code in case of failure.
  */
 static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai,
-		    int pnum)
+		    int pnum, int *vid, unsigned long long *sqnum,
+		    int find_fastmap)
 {
 	long long uninitialized_var(ec);
-	int err, bitflips = 0, vol_id, ec_err = 0;
+	int err, bitflips = 0, vol_id = -1, ec_err = 0;
 
 	dbg_bld("scan PEB %d", pnum);
 
@@ -991,8 +992,13 @@ static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai,
 	}
 
 	vol_id = be32_to_cpu(vidh->vol_id);
+	if (vid)
+		*vid = vol_id;
+	if (sqnum)
+		*sqnum = be64_to_cpu(vidh->sqnum);
 
-	if (vol_id > UBI_MAX_VOLUMES && vol_id != UBI_LAYOUT_VOLUME_ID) {
+	if (!find_fastmap &&
+	   (vol_id > UBI_MAX_VOLUMES && vol_id != UBI_LAYOUT_VOLUME_ID)) {
 		int lnum = be32_to_cpu(vidh->lnum);
 
 		/* Unsupported internal volume */
@@ -1221,7 +1227,7 @@ static void destroy_ai(struct ubi_device *ubi, struct ubi_attach_info *ai)
  * information about it in form of a "struct ubi_attach_info" object. In case
  * of failure, an error code is returned.
  */
-static int scan_all(struct ubi_device *ubi, struct ubi_attach_info *ai)
+static int scan_all(struct ubi_device *ubi, struct ubi_attach_info *ai, int start)
 {
 	int err, pnum;
 	struct rb_node *rb1, *rb2;
@@ -1229,11 +1235,6 @@ static int scan_all(struct ubi_device *ubi, struct ubi_attach_info *ai)
 	struct ubi_ainf_peb *aeb;
 
 	err = -ENOMEM;
-	ai->aeb_slab_cache = kmem_cache_create("ubi_aeb_slab_cache",
-					       sizeof(struct ubi_ainf_peb),
-					       0, 0, NULL);
-	if (!ai->aeb_slab_cache)
-		goto out_ai;
 
 	ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
 	if (!ech)
@@ -1243,11 +1244,11 @@ static int scan_all(struct ubi_device *ubi, struct ubi_attach_info *ai)
 	if (!vidh)
 		goto out_ech;
 
-	for (pnum = 0; pnum < ubi->peb_count; pnum++) {
+	for (pnum = start; pnum < ubi->peb_count; pnum++) {
 		cond_resched();
 
 		dbg_gen("process PEB %d", pnum);
-		err = scan_peb(ubi, ai, pnum);
+		err = scan_peb(ubi, ai, pnum, NULL, NULL, 0);
 		if (err < 0)
 			goto out_vidh;
 	}
@@ -1303,17 +1304,77 @@ out_ai:
 	return err;
 }
 
+/**
+ * scan_fastmap - try to find a fastmap and attach from it.
+ * @ubi: UBI device description object
+ * @ai: attach info object
+ */
+static int scan_fast(struct ubi_device *ubi, struct ubi_attach_info *ai)
+{
+	int err, pnum, fm_anchor = -1;
+	unsigned long long max_sqnum = 0;
+
+	err = -ENOMEM;
+
+	ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
+	if (!ech)
+		goto out_ai;
+
+	vidh = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL);
+	if (!vidh)
+		goto out_ech;
+
+	for (pnum = 0; pnum < UBI_FM_MAX_START; pnum++) {
+		int vol_id = -1;
+		unsigned long long sqnum = -1;
+		cond_resched();
+
+		dbg_gen("process PEB %d", pnum);
+		err = scan_peb(ubi, ai, pnum, &vol_id, &sqnum, 1);
+		if (err < 0)
+			goto out_vidh;
+
+		if (vol_id == UBI_FM_SB_VOLUME_ID && sqnum > max_sqnum) {
+			max_sqnum = sqnum;
+			fm_anchor = pnum;
+		}
+	}
+
+	ubi_free_vid_hdr(ubi, vidh);
+	kfree(ech);
+
+	if (fm_anchor < 0)
+		return UBI_NO_FASTMAP;
+
+	return ubi_scan_fastmap(ubi, ai, fm_anchor);
+
+out_vidh:
+	ubi_free_vid_hdr(ubi, vidh);
+out_ech:
+	kfree(ech);
+out_ai:
+	destroy_ai(ubi, ai);
+	return err;
+}
 static struct ubi_attach_info *alloc_ai(void)
 {
-	static struct ubi_attach_info *ai;
+	struct ubi_attach_info *ai;
 
 	ai = kzalloc(sizeof(struct ubi_attach_info), GFP_KERNEL);
-	if (ai) {
-		INIT_LIST_HEAD(&ai->corr);
-		INIT_LIST_HEAD(&ai->free);
-		INIT_LIST_HEAD(&ai->erase);
-		INIT_LIST_HEAD(&ai->alien);
-		ai->volumes = RB_ROOT;
+	if (!ai)
+		return ai;
+
+	INIT_LIST_HEAD(&ai->corr);
+	INIT_LIST_HEAD(&ai->free);
+	INIT_LIST_HEAD(&ai->erase);
+	INIT_LIST_HEAD(&ai->alien);
+	ai->volumes = RB_ROOT;
+	ai->aeb_slab_cache = kmem_cache_create("ubi_aeb_slab_cache",
+					       sizeof(struct ubi_ainf_peb),
+					       0, 0, NULL);
+	if (!ai->aeb_slab_cache) {
+		kfree(ai);
+		ai = NULL;
 	}
 
 	return ai;
@@ -1337,35 +1398,18 @@ int ubi_attach(struct ubi_device *ubi, int force_scan)
 		return -ENOMEM;
 
 	if (force_scan)
-		err = scan_all(ubi, ai);
+		err = scan_all(ubi, ai, 0);
 	else {
-		/* TODO: this is a regression. If I have an old image, and I do
-		 * not want to use fastmap, I will be forced to waste time for
-		 * useless scan of 64 first eraseblocks. Not good.
-		 *
-		 * Can you teach ubi_scan_fastmap() to use 'scan_peb()'
-		 * function for scanning and build normal ai information? If it
-		 * finds fastmap - it can destroy the collected ai. If it does
-		 * not find, it returns ai. Then you just confinue scanning.
-		 *
-		 * I buess what we'll need is:
-		 * 1. scan_all() -> scan_range(..., int pnum1, int pnum2);
-		 * 2. ubi_scan_fastmap() returns the pnum of the last scanned
-		 *    eraseblock if fastmap was not found;
-		 *    Also 'ubi_scan_fastmap()' uses scan_peb() for scanning.
-		 * 3. You call 'scan_range(..., pnum, c->peb_cnt - 1)' and
-		 *    it continues.
-		 *
-		 * And no regressions.
-		 */
-		err = ubi_scan_fastmap(ubi, ai);
+		err = scan_fast(ubi, ai);
 		if (err > 0) {
-			destroy_ai(ubi, ai);
-			ai = alloc_ai();
-			if (!ai)
-				return -ENOMEM;
+			if (err != UBI_NO_FASTMAP) {
+				destroy_ai(ubi, ai);
+				ai = alloc_ai();
+				if (!ai)
+					return -ENOMEM;
+			}
 
-			err = scan_all(ubi, ai);
+			err = scan_all(ubi, ai, UBI_FM_MAX_START);
 		}
 	}
 
@@ -1398,7 +1442,7 @@ int ubi_attach(struct ubi_device *ubi, int force_scan)
 		if (!scan_ai)
 			goto out_wl;
 
-		err = scan_all(ubi, scan_ai);
+		err = scan_all(ubi, scan_ai, 0);
 		if (err) {
 			kfree(scan_ai);
 			goto out_wl;
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 9b4fd34..6276039 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -819,82 +819,28 @@ 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.
- *
- * 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 = -ENOENT;
-	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++) {
-		if (ubi_io_is_bad(ubi, i))
-			continue;
-
-		ret = ubi_io_read_vid_hdr(ubi, i, vhdr, 0);
-		if (ret < 0)
-			goto out;
-		else if (ret > 0 && ret != UBI_IO_BITFLIPS)
-			continue;
-
-		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);
-
-			if (sqnum > max_sqnum) {
-				max_sqnum = sqnum;
-				*fm_start = i;
-			}
-		}
-	}
-
-	if (*fm_start > -1)
-		ret = 0;
-out:
-	ubi_free_vid_hdr(ubi, vhdr);
-	return ret;
-}
-
-/**
  * ubi_scan_fastmap - scan the fastmap.
  * @ubi: UBI device object
  * @ai: UBI attach info to be filled
+ * @fm_anchor: The fastmap starts at this PEB
  *
  * Returns 0 on success, UBI_NO_FASTMAP if no fastmap was found,
  * UBI_BAD_FASTMAP if one was found but is not usable.
  * < 0 indicates an internal error.
  */
-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,
+		     int fm_anchor)
 {
 	struct ubi_fm_sb *fmsb;
 	struct ubi_vid_hdr *vh;
 	struct ubi_ec_hdr *ech;
 	struct ubi_fastmap_layout *fm;
-	int i, used_blocks, pnum, sb_pnum = 0, ret = 0;
+	int i, used_blocks, pnum, ret = 0;
 	void *fm_raw = NULL;
 	size_t fm_size;
 	__be32 crc, tmp_crc;
 	unsigned long long sqnum = 0;
 
-	ret = ubi_find_fastmap(ubi, &sb_pnum);
-	if (ret)
-		return ret;
-	if (sb_pnum == -1)
-		return UBI_NO_FASTMAP;
-
 	fmsb = kmalloc(sizeof(*fmsb), GFP_KERNEL);
 	if (!fmsb) {
 		ret = -ENOMEM;
@@ -908,7 +854,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai)
 		goto free_raw;
 	}
 
-	ret = ubi_io_read(ubi, fmsb, sb_pnum, ubi->leb_start, sizeof(*fmsb));
+	ret = ubi_io_read(ubi, fmsb, fm_anchor, ubi->leb_start, sizeof(*fmsb));
 	if (ret && ret != UBI_IO_BITFLIPS) {
 		kfree(fmsb);
 		kfree(fm);
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 8e2592d..fef9e92 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -816,7 +816,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, int fm_anchor);
 
 /*
  * ubi_rb_for_each_entry - walk an RB-tree.
-- 
1.7.6.5


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

* [PATCH 08/11] ubi: fastmap: Remove 'ubi' parameter of 'destroy_ai()'
  2012-06-29 15:14 UBI fastmap updates Richard Weinberger
                   ` (6 preceding siblings ...)
  2012-06-29 15:14 ` [PATCH 07/11] UBI: Fastmap: Fix scan regression Richard Weinberger
@ 2012-06-29 15:14 ` Richard Weinberger
  2012-06-29 15:14 ` [PATCH 09/11] ubi: fastmap: Do not free 'ai' in 'scan_all()' Richard Weinberger
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 23+ messages in thread
From: Richard Weinberger @ 2012-06-29 15:14 UTC (permalink / raw)
  To: linux-mtd
  Cc: linux-kernel, adrian.hunter, Heinz.Egger, thomas.wucher,
	shmulik.ladkani, tglx, tim.bird, Marius.Mazarel,
	artem.bityutskiy, nyoushchenko, Richard Weinberger

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

The 'ubi' argument of 'destroy_ai' was added during fastmap development,
but it is no longer used.

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

diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
index bc1e4bf..c30a0f6 100644
--- a/drivers/mtd/ubi/attach.c
+++ b/drivers/mtd/ubi/attach.c
@@ -1164,10 +1164,9 @@ static void destroy_av(struct ubi_attach_info *ai, struct ubi_ainf_volume *av)
 
 /**
  * destroy_ai - destroy attaching information.
- * @ubi: UBI device object
  * @ai: attaching information
  */
-static void destroy_ai(struct ubi_device *ubi, struct ubi_attach_info *ai)
+static void destroy_ai(struct ubi_attach_info *ai)
 {
 	struct ubi_ainf_peb *aeb, *aeb_tmp;
 	struct ubi_ainf_volume *av;
@@ -1300,7 +1299,7 @@ out_vidh:
 out_ech:
 	kfree(ech);
 out_ai:
-	destroy_ai(ubi, ai);
+	destroy_ai(ai);
 	return err;
 }
 
@@ -1353,7 +1352,7 @@ out_vidh:
 out_ech:
 	kfree(ech);
 out_ai:
-	destroy_ai(ubi, ai);
+	destroy_ai(ai);
 	return err;
 }
 static struct ubi_attach_info *alloc_ai(void)
@@ -1403,7 +1402,7 @@ int ubi_attach(struct ubi_device *ubi, int force_scan)
 		err = scan_fast(ubi, ai);
 		if (err > 0) {
 			if (err != UBI_NO_FASTMAP) {
-				destroy_ai(ubi, ai);
+				destroy_ai(ai);
 				ai = alloc_ai();
 				if (!ai)
 					return -ENOMEM;
@@ -1449,13 +1448,13 @@ int ubi_attach(struct ubi_device *ubi, int force_scan)
 		}
 
 		err = self_check_eba(ubi, ai, scan_ai);
-		destroy_ai(ubi, scan_ai);
+		destroy_ai(scan_ai);
 
 		if (err)
 			goto out_wl;
 	}
 
-	destroy_ai(ubi, ai);
+	destroy_ai(ai);
 	return 0;
 
 out_wl:
@@ -1464,7 +1463,7 @@ out_vtbl:
 	ubi_free_internal_volumes(ubi);
 	vfree(ubi->vtbl);
 out_ai:
-	destroy_ai(ubi, ai);
+	destroy_ai(ai);
 	return err;
 }
 
-- 
1.7.6.5


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

* [PATCH 09/11] ubi: fastmap: Do not free 'ai' in 'scan_all()'
  2012-06-29 15:14 UBI fastmap updates Richard Weinberger
                   ` (7 preceding siblings ...)
  2012-06-29 15:14 ` [PATCH 08/11] ubi: fastmap: Remove 'ubi' parameter of 'destroy_ai()' Richard Weinberger
@ 2012-06-29 15:14 ` Richard Weinberger
  2012-06-29 15:14 ` [PATCH 10/11] UBI: Fastmap: Disable fastmap per default Richard Weinberger
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 23+ messages in thread
From: Richard Weinberger @ 2012-06-29 15:14 UTC (permalink / raw)
  To: linux-mtd
  Cc: linux-kernel, adrian.hunter, Heinz.Egger, thomas.wucher,
	shmulik.ladkani, tglx, tim.bird, Marius.Mazarel,
	artem.bityutskiy, nyoushchenko, Richard Weinberger

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

Do not call 'destroy_ai(ai)' at error handling of 'scan_all', since:
- 'ai' is allocated in 'ubi_attach' (the caller of scan_all) and
  provided as an argument. It's not scan_all's responsibility to free it
- It is not consistent with scan_all's sister function
  'ubi_attach_fastmap()' which does not free the given 'ai'
- It will cause a double free as 'ubi_attach' (the caller of scan_all)
  already destroys 'ai' in case of an error

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

diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
index c30a0f6..a343a41 100644
--- a/drivers/mtd/ubi/attach.c
+++ b/drivers/mtd/ubi/attach.c
@@ -1237,7 +1237,7 @@ static int scan_all(struct ubi_device *ubi, struct ubi_attach_info *ai, int star
 
 	ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
 	if (!ech)
-		goto out_ai;
+		return err;
 
 	vidh = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL);
 	if (!vidh)
@@ -1298,8 +1298,6 @@ out_vidh:
 	ubi_free_vid_hdr(ubi, vidh);
 out_ech:
 	kfree(ech);
-out_ai:
-	destroy_ai(ai);
 	return err;
 }
 
-- 
1.7.6.5


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

* [PATCH 10/11] UBI: Fastmap: Disable fastmap per default
  2012-06-29 15:14 UBI fastmap updates Richard Weinberger
                   ` (8 preceding siblings ...)
  2012-06-29 15:14 ` [PATCH 09/11] ubi: fastmap: Do not free 'ai' in 'scan_all()' Richard Weinberger
@ 2012-06-29 15:14 ` Richard Weinberger
  2012-06-29 15:14 ` [PATCH 11/11] UBI: Fastmap: Add a module parameter to enable fastmap Richard Weinberger
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 23+ messages in thread
From: Richard Weinberger @ 2012-06-29 15:14 UTC (permalink / raw)
  To: linux-mtd
  Cc: linux-kernel, adrian.hunter, Heinz.Egger, thomas.wucher,
	shmulik.ladkani, tglx, tim.bird, Marius.Mazarel,
	artem.bityutskiy, nyoushchenko, Richard Weinberger

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

diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
index a343a41..c55ad0f 100644
--- a/drivers/mtd/ubi/attach.c
+++ b/drivers/mtd/ubi/attach.c
@@ -1394,7 +1394,7 @@ int ubi_attach(struct ubi_device *ubi, int force_scan)
 	if (!ai)
 		return -ENOMEM;
 
-	if (force_scan)
+	if (force_scan || ubi->fm_disabled)
 		err = scan_all(ubi, ai, 0);
 	else {
 		err = scan_fast(ubi, ai);
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 7094550..7b5dc5d 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -899,6 +899,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
 		ubi->fm_pool.max_size = UBI_FM_MIN_POOL_SIZE;
 
 	ubi->fm_wl_pool.max_size = UBI_FM_WL_POOL_SIZE;
+	ubi->fm_disabled = 1;
 
 	ubi_msg("default fastmap pool size: %d", ubi->fm_pool.max_size);
 	ubi_msg("default fastmap WL pool size: %d", ubi->fm_wl_pool.max_size);
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 6276039..0c9466d 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -1392,7 +1392,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
 
 	ubi_refill_pools(ubi);
 
-	if (ubi->ro_mode) {
+	if (ubi->ro_mode || ubi->fm_disabled) {
 		mutex_unlock(&ubi->fm_mutex);
 		return 0;
 	}
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index fef9e92..9f766ff 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -386,6 +386,7 @@ struct ubi_wl_entry;
  * @ltree: the lock tree
  * @alc_mutex: serializes "atomic LEB change" operations
  *
+ * @fm_disabled: non-zero if fastmap is disabled (default)
  * @fm: in-memory data structure of the currently used fastmap
  * @fm_pool: in-memory data structure of the fastmap pool
  * @fm_wl_pool: in-memory data structure of the fastmap pool used by the WL
@@ -486,6 +487,7 @@ struct ubi_device {
 	struct mutex alc_mutex;
 
 	/* Fastmap stuff */
+	int fm_disabled;
 	struct ubi_fastmap_layout *fm;
 	struct ubi_fm_pool fm_pool;
 	struct ubi_fm_pool fm_wl_pool;
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 28385d2..6c69017 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -376,7 +376,7 @@ static struct ubi_wl_entry *find_wl_entry(struct ubi_device *ubi,
 	/* If no fastmap has been written and this WL entry can be used
 	 * as anchor PEB, hold it back and return the second best WL entry
 	 * such that fastmap can use the anchor PEB later. */
-	if (!ubi->fm && e->pnum < UBI_FM_MAX_START)
+	if (!ubi->fm_disabled && !ubi->fm && e->pnum < UBI_FM_MAX_START)
 		return prev_e;
 
 	return e;
@@ -405,7 +405,8 @@ static struct ubi_wl_entry *find_mean_wl_entry(struct ubi_device *ubi,
 		/* If no fastmap has been written and this WL entry can be used
 		 * as anchor PEB, hold it back and return the second best
 		 * WL entry such that fastmap can use the anchor PEB later. */
-		if (e && !ubi->fm && e->pnum < UBI_FM_MAX_START)
+		if (e && !ubi->fm_disabled && !ubi->fm &&
+		    e->pnum < UBI_FM_MAX_START)
 			e = rb_entry(rb_next(root->rb_node),
 				     struct ubi_wl_entry, u.rb);
 	} else
-- 
1.7.6.5


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

* [PATCH 11/11] UBI: Fastmap: Add a module parameter to enable fastmap
  2012-06-29 15:14 UBI fastmap updates Richard Weinberger
                   ` (9 preceding siblings ...)
  2012-06-29 15:14 ` [PATCH 10/11] UBI: Fastmap: Disable fastmap per default Richard Weinberger
@ 2012-06-29 15:14 ` Richard Weinberger
  2012-07-01  6:28   ` Rusty Russell
  2012-06-30 10:43 ` UBI fastmap updates Artem Bityutskiy
  2012-07-08 11:47 ` Shmulik Ladkani
  12 siblings, 1 reply; 23+ messages in thread
From: Richard Weinberger @ 2012-06-29 15:14 UTC (permalink / raw)
  To: linux-mtd
  Cc: linux-kernel, adrian.hunter, Heinz.Egger, thomas.wucher,
	shmulik.ladkani, tglx, tim.bird, Marius.Mazarel,
	artem.bityutskiy, nyoushchenko, Richard Weinberger

The new parameter, ubi.fm_auto is per default 0.
If you attach an old image without a fastmap installed
UBI will not install a fastmap an work like in the old days.
But attaching by fastmap will work too if you attach a new image.
Of course in this case the fastmap will also get updated.

Is ubi.fm_auto set to 1 UBI automatically installs a fastmap
on old images.
This can be used to convert old images to have fastmap support.

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

diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
index c55ad0f..a343a41 100644
--- a/drivers/mtd/ubi/attach.c
+++ b/drivers/mtd/ubi/attach.c
@@ -1394,7 +1394,7 @@ int ubi_attach(struct ubi_device *ubi, int force_scan)
 	if (!ai)
 		return -ENOMEM;
 
-	if (force_scan || ubi->fm_disabled)
+	if (force_scan)
 		err = scan_all(ubi, ai, 0);
 	else {
 		err = scan_fast(ubi, ai);
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 7b5dc5d..50b7590 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -67,6 +67,8 @@ static int __initdata mtd_devs;
 
 /* MTD devices specification parameters */
 static struct mtd_dev_param __initdata mtd_dev_param[UBI_MAX_DEVICES];
+/* UBI module parameter to enable fastmap automatically on non-fastmap images */
+static bool fm_auto;
 
 /* Root UBI "class" object (corresponds to '/<sysfs>/class/ubi/') */
 struct class *ubi_class;
@@ -899,7 +901,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
 		ubi->fm_pool.max_size = UBI_FM_MIN_POOL_SIZE;
 
 	ubi->fm_wl_pool.max_size = UBI_FM_WL_POOL_SIZE;
-	ubi->fm_disabled = 1;
+	ubi->fm_disabled = !fm_auto;
 
 	ubi_msg("default fastmap pool size: %d", ubi->fm_pool.max_size);
 	ubi_msg("default fastmap WL pool size: %d", ubi->fm_wl_pool.max_size);
@@ -1392,6 +1394,10 @@ MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: "
 		      "with name \"content\" using VID header offset 1984, and "
 		      "MTD device number 4 with default VID header offset.");
 
+module_param(fm_auto, bool, 000);
+MODULE_PARM_DESC(fm_auto, "Set this parameter to enable fastmap automatically "
+			  "on images without a fastmap.");
+
 MODULE_VERSION(__stringify(UBI_VERSION));
 MODULE_DESCRIPTION("UBI - Unsorted Block Images");
 MODULE_AUTHOR("Artem Bityutskiy");
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 0c9466d..d995105 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -1044,8 +1044,10 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
 	ubi->fm = fm;
 	ubi->fm_pool.max_size = ubi->fm->max_pool_size;
 	ubi->fm_wl_pool.max_size = ubi->fm->max_wl_pool_size;
+	ubi_msg("attached by fastmap");
 	ubi_msg("fastmap pool size: %d", ubi->fm_pool.max_size);
 	ubi_msg("fastmap WL pool size: %d", ubi->fm_wl_pool.max_size);
+	ubi->fm_disabled = 0;
 
 free_hdr:
 	ubi_free_vid_hdr(ubi, vh);
-- 
1.7.6.5


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

* Re: UBI fastmap updates
  2012-06-29 15:14 UBI fastmap updates Richard Weinberger
                   ` (10 preceding siblings ...)
  2012-06-29 15:14 ` [PATCH 11/11] UBI: Fastmap: Add a module parameter to enable fastmap Richard Weinberger
@ 2012-06-30 10:43 ` Artem Bityutskiy
  2012-06-30 10:53   ` Richard Weinberger
  2012-07-08 11:47 ` Shmulik Ladkani
  12 siblings, 1 reply; 23+ messages in thread
From: Artem Bityutskiy @ 2012-06-30 10:43 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: linux-mtd, nyoushchenko, artem.bityutskiy, linux-kernel,
	adrian.hunter, Heinz.Egger, thomas.wucher, shmulik.ladkani, tglx,
	Marius.Mazarel, tim.bird

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

On Fri, 2012-06-29 at 17:14 +0200, Richard Weinberger wrote:
> This is the next round of UBI fastmap updates.
> 
> Fastmap is now disabled by default.
> If you attach an image it will not automatically convert it
> to the fastmap format.
> UBI has a new module parameter "fm_auto".
> If set to 1 UBI will create a fastmap automatically on your
> flash device.
> Please see commit "Add a module parameter to enable fastmap"
> for more details.

One thing I've noticed is that you use vmalloc for some of the buffers
you do I/O on (fm_raw). This is a problem for many ARM platforms because
they cannot do DMA on such buffers. The drivers have to implement
various workarouns for this: either fall back to memcopies or do an
extra copy to a DMA-able buffers.

UBI and UBIFS already to I/O on vmalloc'ed buffers, an I am planning to
fix this, which is not easy. Would be great to not add more of these.

-- 
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] 23+ messages in thread

* Re: UBI fastmap updates
  2012-06-30 10:43 ` UBI fastmap updates Artem Bityutskiy
@ 2012-06-30 10:53   ` Richard Weinberger
  2012-06-30 11:24     ` Artem Bityutskiy
  2012-06-30 14:24     ` Artem Bityutskiy
  0 siblings, 2 replies; 23+ messages in thread
From: Richard Weinberger @ 2012-06-30 10:53 UTC (permalink / raw)
  To: Artem Bityutskiy
  Cc: linux-mtd, nyoushchenko, artem.bityutskiy, linux-kernel,
	adrian.hunter, Heinz.Egger, thomas.wucher, shmulik.ladkani, tglx,
	Marius.Mazarel, tim.bird

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

Am 30.06.2012 12:43, schrieb Artem Bityutskiy:
> On Fri, 2012-06-29 at 17:14 +0200, Richard Weinberger wrote:
>> This is the next round of UBI fastmap updates.
>>
>> Fastmap is now disabled by default.
>> If you attach an image it will not automatically convert it
>> to the fastmap format.
>> UBI has a new module parameter "fm_auto".
>> If set to 1 UBI will create a fastmap automatically on your
>> flash device.
>> Please see commit "Add a module parameter to enable fastmap"
>> for more details.
> 
> One thing I've noticed is that you use vmalloc for some of the buffers
> you do I/O on (fm_raw). This is a problem for many ARM platforms because
> they cannot do DMA on such buffers. The drivers have to implement
> various workarouns for this: either fall back to memcopies or do an
> extra copy to a DMA-able buffers.
> 
> UBI and UBIFS already to I/O on vmalloc'ed buffers, an I am planning to
> fix this, which is not easy. Would be great to not add more of these.

There are only two buffers which use vmalloc() both are used to hold the raw fastmap and have
the same size.
If it helps I could preallocate a buffer in ubi-> and use it in both functions ubi_write_fastmap()
and ubi_scan_fastmap().

So basically you want me to get rid of any vmalloc()'ed buffer?
That's not easy.

Thanks,
//richard


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

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

* Re: UBI fastmap updates
  2012-06-30 10:53   ` Richard Weinberger
@ 2012-06-30 11:24     ` Artem Bityutskiy
  2012-06-30 14:24     ` Artem Bityutskiy
  1 sibling, 0 replies; 23+ messages in thread
From: Artem Bityutskiy @ 2012-06-30 11:24 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: linux-mtd, nyoushchenko, artem.bityutskiy, linux-kernel,
	adrian.hunter, Heinz.Egger, thomas.wucher, shmulik.ladkani, tglx,
	Marius.Mazarel, tim.bird

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

On Sat, 2012-06-30 at 12:53 +0200, Richard Weinberger wrote:
> So basically you want me to get rid of any vmalloc()'ed buffer?
> That's not easy.

How big is the buffer. What is its maximum possible size?

-- 
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] 23+ messages in thread

* Re: UBI fastmap updates
  2012-06-30 10:53   ` Richard Weinberger
  2012-06-30 11:24     ` Artem Bityutskiy
@ 2012-06-30 14:24     ` Artem Bityutskiy
  1 sibling, 0 replies; 23+ messages in thread
From: Artem Bityutskiy @ 2012-06-30 14:24 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: linux-mtd, nyoushchenko, artem.bityutskiy, linux-kernel,
	adrian.hunter, Heinz.Egger, thomas.wucher, shmulik.ladkani, tglx,
	Marius.Mazarel, tim.bird

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

On Sat, 2012-06-30 at 12:53 +0200, Richard Weinberger wrote:
> So basically you want me to get rid of any vmalloc()'ed buffer?
> That's not easy.

Yeah, I guess it is difficult, we probably can let it be vmalloc() since
we already have plenty...

-- 
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] 23+ messages in thread

* Re: [PATCH 11/11] UBI: Fastmap: Add a module parameter to enable fastmap
  2012-06-29 15:14 ` [PATCH 11/11] UBI: Fastmap: Add a module parameter to enable fastmap Richard Weinberger
@ 2012-07-01  6:28   ` Rusty Russell
  2012-07-01  9:41     ` Richard Weinberger
  0 siblings, 1 reply; 23+ messages in thread
From: Rusty Russell @ 2012-07-01  6:28 UTC (permalink / raw)
  To: Richard Weinberger, linux-mtd
  Cc: linux-kernel, adrian.hunter, Heinz.Egger, thomas.wucher,
	shmulik.ladkani, tglx, tim.bird, Marius.Mazarel,
	artem.bityutskiy, nyoushchenko, Richard Weinberger

On Fri, 29 Jun 2012 17:14:29 +0200, Richard Weinberger <richard@nod.at> wrote:
> The new parameter, ubi.fm_auto is per default 0.

...
> +module_param(fm_auto, bool, 000);

Hmm, do you really not want to see this in sysfs?  Or set it?

Cheers,
Rusty.

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

* Re: [PATCH 11/11] UBI: Fastmap: Add a module parameter to enable fastmap
  2012-07-01  6:28   ` Rusty Russell
@ 2012-07-01  9:41     ` Richard Weinberger
  0 siblings, 0 replies; 23+ messages in thread
From: Richard Weinberger @ 2012-07-01  9:41 UTC (permalink / raw)
  To: Rusty Russell
  Cc: linux-mtd, linux-kernel, adrian.hunter, Heinz.Egger,
	thomas.wucher, shmulik.ladkani, tglx, tim.bird, Marius.Mazarel,
	artem.bityutskiy, nyoushchenko

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

Am 01.07.2012 08:28, schrieb Rusty Russell:
> On Fri, 29 Jun 2012 17:14:29 +0200, Richard Weinberger <richard@nod.at> wrote:
>> The new parameter, ubi.fm_auto is per default 0.
> 
> ...
>> +module_param(fm_auto, bool, 000);
> 
> Hmm, do you really not want to see this in sysfs?  Or set it?

Okay, exposing this parameter to sysfs does not hurt and may be useful.
I'll change the permission to 0600.

Thanks,
//richard


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

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

* Re: UBI fastmap updates
  2012-06-29 15:14 UBI fastmap updates Richard Weinberger
                   ` (11 preceding siblings ...)
  2012-06-30 10:43 ` UBI fastmap updates Artem Bityutskiy
@ 2012-07-08 11:47 ` Shmulik Ladkani
  2012-07-08 12:07   ` Richard Weinberger
  12 siblings, 1 reply; 23+ messages in thread
From: Shmulik Ladkani @ 2012-07-08 11:47 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: linux-mtd, linux-kernel, adrian.hunter, Heinz.Egger,
	thomas.wucher, tglx, tim.bird, Marius.Mazarel, artem.bityutskiy,
	nyoushchenko

Hi Richard,

On Fri, 29 Jun 2012 17:14:18 +0200 Richard Weinberger <richard@nod.at> wrote:
> This is the next round of UBI fastmap updates.

Please examine some TODOs (and questions) I've spotted while diffing
against "vanilla" ubi.

This patch should apply to linux-ubi at d41a140

Sorry I couldn't review entirely, diff has gotten really enormous...
I'll try to pick it up again when you'll get to the final merge
submitting incremental patches.

Regards,
Shmulik

diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
index a343a41..dae9674 100644
--- a/drivers/mtd/ubi/attach.c
+++ b/drivers/mtd/ubi/attach.c
@@ -999,6 +999,13 @@ static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai,
 
 	if (!find_fastmap &&
 	   (vol_id > UBI_MAX_VOLUMES && vol_id != UBI_LAYOUT_VOLUME_ID)) {
+
+		/* TODO: if find_fastmap==1, we do not enter this block at all.
+		 * shouldn't we? shouldn't we care of compatability of unknown
+		 * internal volumes OTHER than the fastmap ones, even if
+		 * find_fastmap==1?
+		 */
+
 		int lnum = be32_to_cpu(vidh->lnum);
 
 		/* Unsupported internal volume */
@@ -1221,6 +1228,7 @@ static void destroy_ai(struct ubi_attach_info *ai)
  * scan_all - scan entire MTD device.
  * @ubi: UBI device description object
  * @ai: attach info object
+ * TODO: document @start
  *
  * 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
@@ -1350,6 +1358,11 @@ out_vidh:
 out_ech:
 	kfree(ech);
 out_ai:
+	/* TODO: doesn't seem clean to destroy 'ai' as it was allocated by the
+	 * caller, its his responsibility.
+	 * also looks like it leads to double freee in case 'err' returned is
+	 * negative
+	 */
 	destroy_ai(ai);
 	return err;
 }
@@ -1441,6 +1454,7 @@ int ubi_attach(struct ubi_device *ubi, int force_scan)
 
 		err = scan_all(ubi, scan_ai, 0);
 		if (err) {
+			/* TODO: hmm... kfree or destroy_ai ? */
 			kfree(scan_ai);
 			goto out_wl;
 		}
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 50b7590..f769c22 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -1053,6 +1053,7 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
 	ubi_notify_all(ubi, UBI_VOLUME_REMOVED, NULL);
 	dbg_msg("detaching mtd%d from ubi%d", ubi->mtd->index, ubi_num);
 
+	/* TODO: any action on failure? */
 	ubi_update_fastmap(ubi);
 
 	/*
@@ -1070,7 +1071,6 @@ 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);
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 9f766ff..0b2d0cf 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -219,7 +219,7 @@ struct ubi_volume_desc;
  * @size: size of the fastmap in bytes
  * @used_blocks: number of used PEBs
  * @max_pool_size: maximal size of the user pool
- * @max_wl_pool_size: maximal size of the pooly used by the WL sub-system
+ * @max_wl_pool_size: maximal size of the pool used by the WL sub-system
  * @raw: the fastmap itself as byte array (only valid while attaching)
  */
 struct ubi_fastmap_layout {
@@ -242,7 +242,6 @@ struct ubi_fastmap_layout {
  * A pool gets filled with up to max_size.
  * If all PEBs within the pool are used a new fastmap will be written
  * to the flash and the pool gets refilled with empty PEBs.
- *
  */
 struct ubi_fm_pool {
 	int pebs[UBI_FM_MAX_POOL_SIZE];
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 6c69017..688881b 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -272,6 +272,10 @@ static int produce_free_peb(struct ubi_device *ubi)
 		dbg_wl("do one work synchronously");
 		err = do_work(ubi);
 		if (err)
+			/* TODO: in the new locking scheme, produce_free_peb is
+			 * called under wl_lock taken.
+			 * so when returning, should reacquire the lock
+			 */
 			return err;
 
 		spin_lock(&ubi->wl_lock);
@@ -377,6 +381,7 @@ static struct ubi_wl_entry *find_wl_entry(struct ubi_device *ubi,
 	 * as anchor PEB, hold it back and return the second best WL entry
 	 * such that fastmap can use the anchor PEB later. */
 	if (!ubi->fm_disabled && !ubi->fm && e->pnum < UBI_FM_MAX_START)
+		/* TODO: do we have a risk returning NULL here? */
 		return prev_e;
 
 	return e;
@@ -405,6 +410,7 @@ static struct ubi_wl_entry *find_mean_wl_entry(struct ubi_device *ubi,
 		/* If no fastmap has been written and this WL entry can be used
 		 * as anchor PEB, hold it back and return the second best
 		 * WL entry such that fastmap can use the anchor PEB later. */
+		/* TODO: why this is specific just to < WL_FREE_MAX_DIFF case? */
 		if (e && !ubi->fm_disabled && !ubi->fm &&
 		    e->pnum < UBI_FM_MAX_START)
 			e = rb_entry(rb_next(root->rb_node),

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

* Re: UBI fastmap updates
  2012-07-08 11:47 ` Shmulik Ladkani
@ 2012-07-08 12:07   ` Richard Weinberger
  2012-07-08 15:11     ` Richard Weinberger
  2012-07-09  7:37     ` Shmulik Ladkani
  0 siblings, 2 replies; 23+ messages in thread
From: Richard Weinberger @ 2012-07-08 12:07 UTC (permalink / raw)
  To: Shmulik Ladkani
  Cc: linux-mtd, linux-kernel, adrian.hunter, Heinz.Egger,
	thomas.wucher, tglx, tim.bird, Marius.Mazarel, artem.bityutskiy,
	nyoushchenko

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

Hi Shmulik!

Am 08.07.2012 13:47, schrieb Shmulik Ladkani:
> +
> +		/* TODO: if find_fastmap==1, we do not enter this block at all.
> +		 * shouldn't we? shouldn't we care of compatability of unknown
> +		 * internal volumes OTHER than the fastmap ones, even if
> +		 * find_fastmap==1?
> +		 */
> +

If find_fastmap=1 we scan only the first 64 PEBs (now by using scan_peb()).
When using fastmap can do not care about compatibility of unknown internal volumes
at all.
Fastmap keeps only track of known (and compatible volumes).
Taking care of unknown internal volumes would imply a full scan.

		int lnum = be32_to_cpu(vidh->lnum);
>  
>  		/* Unsupported internal volume */
> @@ -1221,6 +1228,7 @@ static void destroy_ai(struct ubi_attach_info *ai)
>   * scan_all - scan entire MTD device.
>   * @ubi: UBI device description object
>   * @ai: attach info object
> + * TODO: document @start

Tomorrow I'll send another kernel-doc update.
There more tags missing.

>   * 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
> @@ -1350,6 +1358,11 @@ out_vidh:
>  out_ech:
>  	kfree(ech);
>  out_ai:
> +	/* TODO: doesn't seem clean to destroy 'ai' as it was allocated by the
> +	 * caller, its his responsibility.
> +	 * also looks like it leads to double freee in case 'err' returned is
> +	 * negative
> +	 */

I have to look closer into this.
It looks like the call to destroy_ai() in scan_fast() has to go.

>  	destroy_ai(ai);
>  	return err;
>  }
> @@ -1441,6 +1454,7 @@ int ubi_attach(struct ubi_device *ubi, int force_scan)
>  
>  		err = scan_all(ubi, scan_ai, 0);
>  		if (err) {
> +			/* TODO: hmm... kfree or destroy_ai ? */

True. Must be desroy_ai().

>  			kfree(scan_ai);
>  			goto out_wl;
>  		}
> diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
> index 50b7590..f769c22 100644
> --- a/drivers/mtd/ubi/build.c
> +++ b/drivers/mtd/ubi/build.c
> @@ -1053,6 +1053,7 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
>  	ubi_notify_all(ubi, UBI_VOLUME_REMOVED, NULL);
>  	dbg_msg("detaching mtd%d from ubi%d", ubi->mtd->index, ubi_num);
>  
> +	/* TODO: any action on failure? */

What do you expect on failure?
At this point we have either no fastmap or a valid fastmap on flash.
If ubi_update_fastmap() fails it will ensure that no invalid fastmap remains on flash.
See invalidate_fastmap().

> --- a/drivers/mtd/ubi/wl.c
> +++ b/drivers/mtd/ubi/wl.c
> @@ -272,6 +272,10 @@ static int produce_free_peb(struct ubi_device *ubi)
>  		dbg_wl("do one work synchronously");
>  		err = do_work(ubi);
>  		if (err)
> +			/* TODO: in the new locking scheme, produce_free_peb is
> +			 * called under wl_lock taken.
> +			 * so when returning, should reacquire the lock
> +			 */

Which new locking scheme?

>  			return err;
>  
>  		spin_lock(&ubi->wl_lock);
> @@ -377,6 +381,7 @@ static struct ubi_wl_entry *find_wl_entry(struct ubi_device *ubi,
>  	 * as anchor PEB, hold it back and return the second best WL entry
>  	 * such that fastmap can use the anchor PEB later. */
>  	if (!ubi->fm_disabled && !ubi->fm && e->pnum < UBI_FM_MAX_START)
> +		/* TODO: do we have a risk returning NULL here? */

How?

>  		return prev_e;
>  
>  	return e;
> @@ -405,6 +410,7 @@ static struct ubi_wl_entry *find_mean_wl_entry(struct ubi_device *ubi,
>  		/* If no fastmap has been written and this WL entry can be used
>  		 * as anchor PEB, hold it back and return the second best
>  		 * WL entry such that fastmap can use the anchor PEB later. */
> +		/* TODO: why this is specific just to < WL_FREE_MAX_DIFF case? */

Because find_wl_entry() already takes care of this.

Thanks,
//richard


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

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

* Re: UBI fastmap updates
  2012-07-08 12:07   ` Richard Weinberger
@ 2012-07-08 15:11     ` Richard Weinberger
  2012-07-09  7:37     ` Shmulik Ladkani
  1 sibling, 0 replies; 23+ messages in thread
From: Richard Weinberger @ 2012-07-08 15:11 UTC (permalink / raw)
  To: Shmulik Ladkani
  Cc: linux-mtd, linux-kernel, adrian.hunter, Heinz.Egger,
	thomas.wucher, tglx, tim.bird, Marius.Mazarel, artem.bityutskiy,
	nyoushchenko

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

Am 08.07.2012 14:07, schrieb Richard Weinberger:
> Hi Shmulik!
> 
> Am 08.07.2012 13:47, schrieb Shmulik Ladkani:
>> +
>> +		/* TODO: if find_fastmap==1, we do not enter this block at all.
>> +		 * shouldn't we? shouldn't we care of compatability of unknown
>> +		 * internal volumes OTHER than the fastmap ones, even if
>> +		 * find_fastmap==1?
>> +		 */
>> +
> 
> If find_fastmap=1 we scan only the first 64 PEBs (now by using scan_peb()).
> When using fastmap can do not care about compatibility of unknown internal volumes
> at all.
> Fastmap keeps only track of known (and compatible volumes).
> Taking care of unknown internal volumes would imply a full scan.

Please forget the above statement.
We have to think of the case where no fastmap was found and the
64 scanned PEBs get reused by scan_all().
Thanks for pointing this out!

Thanks,
//richard


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

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

* Re: UBI fastmap updates
  2012-07-08 12:07   ` Richard Weinberger
  2012-07-08 15:11     ` Richard Weinberger
@ 2012-07-09  7:37     ` Shmulik Ladkani
  2012-07-09  8:19       ` Richard Weinberger
  1 sibling, 1 reply; 23+ messages in thread
From: Shmulik Ladkani @ 2012-07-09  7:37 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: linux-mtd, linux-kernel, adrian.hunter, Heinz.Egger,
	thomas.wucher, tglx, tim.bird, Marius.Mazarel, artem.bityutskiy,
	nyoushchenko

Hi Richard,

On Sun, 08 Jul 2012 14:07:41 +0200 Richard Weinberger <richard@nod.at> wrote:
> > +			/* TODO: in the new locking scheme, produce_free_peb is
> > +			 * called under wl_lock taken.
> > +			 * so when returning, should reacquire the lock
> > +			 */
> 
> Which new locking scheme?

I am diffing linux-ubi fastmap HEAD against its fork point (vanilla
ubi), that's 6b16351..d41a140 on linux-ubi.

Which gives the following diff in produce_free_pebs:

@@ -261,7 +266,6 @@ static int produce_free_peb(struct ubi_device *ubi)
 {
 	int err;
 
-	spin_lock(&ubi->wl_lock);
 	while (!ubi->free.rb_node) {
 		spin_unlock(&ubi->wl_lock);
 
@@ -272,7 +276,6 @@ static int produce_free_peb(struct ubi_device *ubi)
 
 		spin_lock(&ubi->wl_lock);
 	}
-	spin_unlock(&ubi->wl_lock);
 
 	return 0;
 }

Which is probably okay, since you obtain the lock in the new
'ubi_refill_pools', which calls produce_free_peb:

+void ubi_refill_pools(struct ubi_device *ubi)
+{
+	spin_lock(&ubi->wl_lock);
+	refill_wl_pool(ubi);
+	refill_wl_user_pool(ubi);
+	spin_unlock(&ubi->wl_lock);
+}

However if 'do_work' fails within 'produce_free_peb', you return the
error but leave wl_lock unlocked - where it is expected to be locked
(otherwise, ubi_refill_pools will unlock it again):

static int produce_free_peb(struct ubi_device *ubi)
{
	int err;

	while (!ubi->free.rb_node) {
		spin_unlock(&ubi->wl_lock);

		dbg_wl("do one work synchronously");
		err = do_work(ubi);
		if (err)
			return err;

		spin_lock(&ubi->wl_lock);
	}

	return 0;
}

Regards,
Shmulik

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

* Re: UBI fastmap updates
  2012-07-09  7:37     ` Shmulik Ladkani
@ 2012-07-09  8:19       ` Richard Weinberger
  0 siblings, 0 replies; 23+ messages in thread
From: Richard Weinberger @ 2012-07-09  8:19 UTC (permalink / raw)
  To: Shmulik Ladkani
  Cc: linux-mtd, linux-kernel, adrian.hunter, Heinz.Egger,
	thomas.wucher, tglx, tim.bird, Marius.Mazarel, artem.bityutskiy,
	nyoushchenko

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

Am 09.07.2012 09:37, schrieb Shmulik Ladkani:
> Hi Richard,
> 
> On Sun, 08 Jul 2012 14:07:41 +0200 Richard Weinberger <richard@nod.at> wrote:
>>> +			/* TODO: in the new locking scheme, produce_free_peb is
>>> +			 * called under wl_lock taken.
>>> +			 * so when returning, should reacquire the lock
>>> +			 */
>>
>> Which new locking scheme?
> 
> I am diffing linux-ubi fastmap HEAD against its fork point (vanilla
> ubi), that's 6b16351..d41a140 on linux-ubi.
> 
> Which gives the following diff in produce_free_pebs:

Ahh. _my_ new locking scheme. I feared someone else changed it meanwhile in mainline. ;)
Yes, the &ubi->wl_lock in produce_free_peb() is no  longer needed.
Again, thanks for pointing this out!

Thanks,
//richard


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

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

end of thread, other threads:[~2012-07-09  8:19 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-29 15:14 UBI fastmap updates Richard Weinberger
2012-06-29 15:14 ` [PATCH 01/11] UBI: Fastmap: Fix mem leak in error path Richard Weinberger
2012-06-29 15:14 ` [PATCH 02/11] UBI: Fastmap: Amend self_check_eba() Richard Weinberger
2012-06-29 15:14 ` [PATCH 03/11] UBI: Fastmap: Remove forward declaration Richard Weinberger
2012-06-29 15:14 ` [PATCH 04/11] UBI: Fastmap: Move fastmap specific code into ubi_scan_fastmap() Richard Weinberger
2012-06-29 15:14 ` [PATCH 05/11] UBI: Fastmap: Kill TODO Richard Weinberger
2012-06-29 15:14 ` [PATCH 06/11] UBI: Fastmap: Remove unused variable Richard Weinberger
2012-06-29 15:14 ` [PATCH 07/11] UBI: Fastmap: Fix scan regression Richard Weinberger
2012-06-29 15:14 ` [PATCH 08/11] ubi: fastmap: Remove 'ubi' parameter of 'destroy_ai()' Richard Weinberger
2012-06-29 15:14 ` [PATCH 09/11] ubi: fastmap: Do not free 'ai' in 'scan_all()' Richard Weinberger
2012-06-29 15:14 ` [PATCH 10/11] UBI: Fastmap: Disable fastmap per default Richard Weinberger
2012-06-29 15:14 ` [PATCH 11/11] UBI: Fastmap: Add a module parameter to enable fastmap Richard Weinberger
2012-07-01  6:28   ` Rusty Russell
2012-07-01  9:41     ` Richard Weinberger
2012-06-30 10:43 ` UBI fastmap updates Artem Bityutskiy
2012-06-30 10:53   ` Richard Weinberger
2012-06-30 11:24     ` Artem Bityutskiy
2012-06-30 14:24     ` Artem Bityutskiy
2012-07-08 11:47 ` Shmulik Ladkani
2012-07-08 12:07   ` Richard Weinberger
2012-07-08 15:11     ` Richard Weinberger
2012-07-09  7:37     ` Shmulik Ladkani
2012-07-09  8:19       ` Richard Weinberger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).