All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mtdoops : don't erase flash at each boot
@ 2012-10-19 15:29 Matthieu CASTET
  2012-11-12 15:50 ` Artem Bityutskiy
  0 siblings, 1 reply; 4+ messages in thread
From: Matthieu CASTET @ 2012-10-19 15:29 UTC (permalink / raw)
  To: linux-mtd; +Cc: Matthieu CASTET

If there is no oops stored (flash is erased), find_next_position will
exit with maxcount == 0xffffffff and erase the first page.

Only erase it if mark_is_used.

Signed-off-by: Matthieu Castet <matthieu.castet@parrot@com>
---
 drivers/mtd/mtdoops.c |   15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c
index f5b3f91..97bb8f6 100644
--- a/drivers/mtd/mtdoops.c
+++ b/drivers/mtd/mtdoops.c
@@ -271,7 +271,7 @@ static void find_next_position(struct mtdoops_context *cxt)
 
 		if (count[0] == 0xffffffff && count[1] == 0xffffffff)
 			mark_page_unused(cxt, page);
-		if (count[0] == 0xffffffff)
+		if (count[0] == 0xffffffff || count[1] != MTDOOPS_KERNMSG_MAGIC)
 			continue;
 		if (maxcount == 0xffffffff) {
 			maxcount = count[0];
@@ -289,14 +289,13 @@ static void find_next_position(struct mtdoops_context *cxt)
 		}
 	}
 	if (maxcount == 0xffffffff) {
-		cxt->nextpage = 0;
-		cxt->nextcount = 1;
-		schedule_work(&cxt->work_erase);
-		return;
+		cxt->nextpage = cxt->oops_pages - 1;
+		cxt->nextcount = 0;
+	}
+	else {
+		cxt->nextpage = maxpos;
+		cxt->nextcount = maxcount;
 	}
-
-	cxt->nextpage = maxpos;
-	cxt->nextcount = maxcount;
 
 	mtdoops_inc_counter(cxt);
 }
-- 
1.7.10.4

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

* Re: [PATCH] mtdoops : don't erase flash at each boot
  2012-10-19 15:29 [PATCH] mtdoops : don't erase flash at each boot Matthieu CASTET
@ 2012-11-12 15:50 ` Artem Bityutskiy
  2012-11-13  9:56   ` Matthieu CASTET
  0 siblings, 1 reply; 4+ messages in thread
From: Artem Bityutskiy @ 2012-11-12 15:50 UTC (permalink / raw)
  To: Matthieu CASTET; +Cc: linux-mtd

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

On Fri, 2012-10-19 at 17:29 +0200, Matthieu CASTET wrote:
> If there is no oops stored (flash is erased), find_next_position will
> exit with maxcount == 0xffffffff and erase the first page.
> 
> Only erase it if mark_is_used.
> 
> Signed-off-by: Matthieu Castet <matthieu.castet@parrot@com>

The code of mtdoops is really hard to read. Could you please provide a
better commit message with better description about what you do:

1. what problem you fix exactly, and why is it a problem
2. how the code currently works
3. how you change it to make the problem go away

Thanks!

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

* Re: [PATCH] mtdoops : don't erase flash at each boot
  2012-11-12 15:50 ` Artem Bityutskiy
@ 2012-11-13  9:56   ` Matthieu CASTET
  2012-11-15 13:03     ` Artem Bityutskiy
  0 siblings, 1 reply; 4+ messages in thread
From: Matthieu CASTET @ 2012-11-13  9:56 UTC (permalink / raw)
  To: dedekind1@gmail.com; +Cc: linux-mtd@lists.infradead.org

Artem Bityutskiy a écrit :
> On Fri, 2012-10-19 at 17:29 +0200, Matthieu CASTET wrote:
>> If there is no oops stored (flash is erased), find_next_position will
>> exit with maxcount == 0xffffffff and erase the first page.
>>
>> Only erase it if mark_is_used.
>>
>> Signed-off-by: Matthieu Castet <matthieu.castet@parrot@com>
> 
> The code of mtdoops is really hard to read. Could you please provide a
> better commit message with better description about what you do:
> 
> 1. what problem you fix exactly, and why is it a problem
> 2. how the code currently works
> 3. how you change it to make the problem go away
> 
> Thanks!
> 

Is the following changelog ok ?


The current version on mtdoops erase first block of mtdoops partition at each
boot if there is no oops stored in flash. This can wear the flash.

When mtdoops start, find_next_position is called to find the next free entry in
the circular buffer. But if the flash is erased, find_next_position don't find
anything (maxcount == 0xffffffff) and start with the first entry after erasing it.

The scanning that is done in find_next_position already track free/used entries.
So if at the end of the scanning we don't find anything, we can start at the
first entry and erased the entry only if it is marked as used.
Most of this is implemented in mtdoops_inc_counter, so to avoid duplicating
code, if we don't find anything we set position to -1. mtdoops_inc_counter with
increment it, erase the entry if needed and start as before with nextpage = 0
and nextcount = 1).

Also during the scan phase, we use the MTDOOPS_KERNMSG_MAGIC to detect corruped
entries.

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

* Re: [PATCH] mtdoops : don't erase flash at each boot
  2012-11-13  9:56   ` Matthieu CASTET
@ 2012-11-15 13:03     ` Artem Bityutskiy
  0 siblings, 0 replies; 4+ messages in thread
From: Artem Bityutskiy @ 2012-11-15 13:03 UTC (permalink / raw)
  To: Matthieu CASTET; +Cc: linux-mtd@lists.infradead.org

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

On Tue, 2012-11-13 at 10:56 +0100, Matthieu CASTET wr
> Is the following changelog ok ?

Better, thanks. I've pushed this patch to l2-mtd.git.

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

end of thread, other threads:[~2012-11-15 13:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-19 15:29 [PATCH] mtdoops : don't erase flash at each boot Matthieu CASTET
2012-11-12 15:50 ` Artem Bityutskiy
2012-11-13  9:56   ` Matthieu CASTET
2012-11-15 13:03     ` Artem Bityutskiy

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.