All of lore.kernel.org
 help / color / mirror / Atom feed
From: Artem Bityutskiy <dedekind@infradead.org>
To: Eric Holmberg <Eric_Holmberg@Trimble.com>
Cc: Adrian Hunter <adrian.hunter@nokia.com>,
	linux-mtd@lists.infradead.org, Urs Muff <urs_muff@Trimble.com>
Subject: RE: UBIFS Corrupt during power failure
Date: Fri, 10 Apr 2009 18:49:42 +0300	[thread overview]
Message-ID: <1239378582.3390.66.camel@localhost.localdomain> (raw)
In-Reply-To: <1239376652.3390.49.camel@localhost.localdomain>

On Fri, 2009-04-10 at 18:17 +0300, Artem Bityutskiy wrote:
> Hi,
> 
> On Fri, 2009-04-10 at 08:27 -0600, Eric Holmberg wrote:
> > Test setup:
> >  * Using U-Boot 1.3.0
> >  * Write buffering enabled
> >  * S29GL256F 256Mbit NOR flash w/ 32-word write buffer
> >  * Test software that performs read/erase/write operations
> >  * JTAG debugger that randomly resets the board
> > 
> > Reset during write (unexpected test pattern written after un-programmed
> > values):
> > 
> > 30352240  aa55aa0a aa55aa0a aa55aa0a aa55aa0a
> > 30352250  aa55aa0a aa55aa0a aa55aa0a aa55aa0a
> > 30352260  aa55aa0a aa55aa0a aa55aa0a aa55aa0a
> > 30352270  aa55aa0a aa55aa0a aa55aa0a aa55aa0a
> > 30352280  ffffffff ffffffff ffffffff ffffffff
> > 30352290  ffffffff ffffffff ffffffff ffffffff
> > 303522a0  ffffffff ffffffff ffffffff ffffffff
> > 303522b0  aa55aa0a aa55aa0a aa55aa0a aa55aa0a
> > 303522c0  ffffffff ffffffff ffffffff ffffffff
> > 303522d0  ffffffff ffffffff ffffffff ffffffff
> > 303522e0  ffffffff ffffffff ffffffff ffffffff
> 
> Yeah, I think the recovery assumes that if you cut power during
> writing than:
> 
> 1. The min. I/O unit which has been written to at the moment power
>    cut happened will contain garbage.
> 2. But the next min. I/O unit will contain 0xFFs.
> 
> We have been working only with NAND flash, and min. I/O unit
> for NAND is one NAND page (usually 2KiB). We have never worked
> with NOR flash. We only tested UBIFS several times on the mtdram
> NOR flash emulator.
> 
> In case of NOR, UBIFS assumes min. I/O unit size is 8 bytes. Well,
> it is actually 1 byte, but because UBIFS aligns all its on-flash
> data structures to 8-byte boundaries, we used 8 for NOR, because
> it was easier implementation-wise.
> 
> Thus, UBIFS will panic when it meets the above pattern. And UBIFS
> would need some changes to make it understand this type of
> corruptions. All the recovery logic is in recovery.c. It should
> not be very difficult to change this.
> 
> You may ask - if while scanning you meet a corrupted node - why do
> you keep checking the rest of the node, and want to see 0xFFs there?
> 
> The reason why we do this check is that if we meet a corrupted node,
> we want to figure out the nature of the corruption - is this a
> non-finished write or a physical corruption, e.g. due to radiation,
> worn-out flash, etc. UBIFS writes eraseblocks from the beginning,
> to the end - always. So if the corrupted node is the last, this
> is harmless corruption because of power-cut, and we recover. But
> if the corruption is in a middle, this is something serious and
> we panic.
> 
> So in your case, UBIFS decides that it met a corrupted node in
> the middle, and panics.

So you need to play with ubifs_recover_leb() function.

There is the following code:

        if (!empty_chkd && !is_empty(buf, len)) {
                if (is_last_write(c, buf, offs)) {
                        clean_buf(c, &buf, lnum, &offs, &len);
                        need_clean = 1;
                } else {
                        ubifs_err("corrupt empty space at LEB %d:%d",
                                  lnum, offs);
                        goto corrupted;
                }
        }

So in your case "is_last_write()" returns zero, and UBIFS prints
cryptic "corrupt empty space" and panics.

I would try to hack the code and remove that panic part, and see
what happens. UBIFS should probably successfully recover the LEB.
This is done in 'fix_unclean_leb()'. What this function will do
it will:

1. Read all _good_ nodes from this LEB (ubi_read())
2. Atomically change the corrupted LEB (ubi_leb_change())

Atomic LEB change is UBI operation, read here about it:
http://www.linux-mtd.infradead.org/doc/ubi.html#L_lebchange

In few words, on the physical flash level it will do:

1. Write the good nodes to a new, erased physical eraseblock
2. Erase the current physical eraseblock.

So, try the suggested hack out (inlined below). See what happens,
may be you discover other problems. After you played with recovery
code and have some success, we may push some nice solution to
UBIFS, e.g.

1. Introduce a mount option which tells UBIFS to assume that power-cuts
   during writing may disturb not only the current min_io_unit, but
   also the next ones.
2. Assume this if the flash type is NOR. May be there is some limit
   we may assume?

diff --git a/fs/ubifs/recovery.c b/fs/ubifs/recovery.c
index 1066297..9afa056 100644
--- a/fs/ubifs/recovery.c
+++ b/fs/ubifs/recovery.c
@@ -675,9 +675,10 @@ struct ubifs_scan_leb *ubifs_recover_leb(struct ubifs_info *c, int lnum,
 			clean_buf(c, &buf, lnum, &offs, &len);
 			need_clean = 1;
 		} else {
-			ubifs_err("corrupt empty space at LEB %d:%d",
-				  lnum, offs);
-			goto corrupted;
+			ubifs_warn("ignore corrupt empty space at LEB %d:%d",
+				   lnum, offs);
+			clean_buf(c, &buf, lnum, &offs, &len);
+			need_clean = 1;
 		}
 	}
 
-- 
Best regards,
Artem Bityutskiy (Битюцкий Артём)

  reply	other threads:[~2009-04-10 15:50 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-24 13:45 UBIFS Corrupt during power failure Eric Holmberg
2009-03-24 15:30 ` Adrian Hunter
2009-03-24 17:04   ` Eric Holmberg
2009-03-24 18:16     ` Eric Holmberg
2009-03-25  6:32     ` Artem Bityutskiy
2009-03-26  6:59     ` Artem Bityutskiy
2009-03-26 14:09       ` Eric Holmberg
2009-03-30 19:00         ` Eric Holmberg
2009-03-31 14:45           ` Artem Bityutskiy
2009-04-10 12:25           ` Artem Bityutskiy
2009-04-10 14:27             ` Eric Holmberg
2009-04-10 15:17               ` Artem Bityutskiy
2009-04-10 15:49                 ` Artem Bityutskiy [this message]
2009-04-10 17:00                   ` Eric Holmberg
2009-04-10 17:11                     ` Artem Bityutskiy
2009-04-10 18:33                       ` Eric Holmberg
2009-04-14  6:11                         ` Artem Bityutskiy
2009-04-14 15:09                           ` Eric Holmberg
2009-04-14 15:45                             ` Artem Bityutskiy
2009-04-14 15:53                               ` Artem Bityutskiy
2009-04-14 18:00                           ` Jamie Lokier
2009-04-15  6:00                             ` Artem Bityutskiy
2009-04-15 15:17                               ` Eric Holmberg
2009-04-15 16:09                                 ` Jamie Lokier
2009-04-15 16:12                                   ` Artem Bityutskiy
2009-04-15 16:32                                   ` Eric Holmberg
2009-04-15 16:44                                     ` Jamie Lokier
2009-04-15 18:26                                       ` Nicolas Pitre
2009-04-15 18:38                                         ` Jamie Lokier
2009-04-15 19:33                                           ` Eric Holmberg
2009-04-15 20:15                                             ` Nicolas Pitre
2009-04-15 20:46                                               ` Jamie Lokier
2009-04-16  5:51                                             ` Artem Bityutskiy
2009-04-16  5:46                                     ` Artem Bityutskiy
2009-04-16 21:34                                       ` Jamie Lokier
2009-04-17  8:56                                         ` Artem Bityutskiy
2009-04-17 13:51                                           ` Jamie Lokier
2009-04-17 14:36                                             ` Artem Bityutskiy
2009-04-17 23:49                                               ` Eric Holmberg
2009-05-15  7:16                                                 ` Stefan Roese
2009-05-18 17:30                                                   ` Eric Holmberg
2009-05-19  8:18                                                     ` Artem Bityutskiy
2009-05-19 22:16                                                       ` Eric Holmberg
2009-05-25  8:38                                                         ` Artem Bityutskiy
2009-05-25 12:54                                                           ` Artem Bityutskiy
2009-05-25 12:57                                                             ` Artem Bityutskiy
2009-07-03 13:26                                                         ` Artem Bityutskiy
2009-07-03 13:29                                                           ` Artem Bityutskiy
2009-07-03 13:33                                                             ` Urs Muff
2009-07-03 14:05                                                               ` Artem Bityutskiy
2009-07-03 14:47                                                                 ` Urs Muff
2009-07-03 14:58                                                                   ` Artem Bityutskiy
2009-07-06  4:30                                                                     ` Artem Bityutskiy
2009-07-06  4:51                                                                       ` Artem Bityutskiy
2009-07-06  6:43                                                                         ` Artem Bityutskiy
2009-07-07  6:46                                                                           ` Artem Bityutskiy
2009-07-07  7:05                                                                             ` Urs Muff
2009-07-13 18:22                                                                             ` Eric Holmberg
2009-07-14  5:34                                                                               ` Artem Bityutskiy
2009-07-15 20:52                                                                               ` Jamie Lokier
2009-07-15 21:35                                                                                 ` Eric Holmberg
2009-07-16  7:33                                                                                   ` Artem Bityutskiy
2009-07-24  6:49                                                                                   ` Artem Bityutskiy
2009-07-24 12:00                                                                                     ` Artem Bityutskiy
2009-07-24 13:39                                                                                       ` Eric Holmberg
2009-07-24 14:55                                                                                         ` Artem Bityutskiy
2009-07-24 14:05                                                                                     ` Jamie Lokier
2009-07-24 14:09                                                                                       ` Artem Bityutskiy
2009-07-16  7:09                                                                                 ` Artem Bityutskiy
2009-07-16 16:49                                                                                   ` Jamie Lokier
2009-07-17  7:07                                                                                     ` Artem Bityutskiy
2009-07-15 20:55                                                                       ` Jamie Lokier
2009-07-15 21:36                                                                         ` Eric Holmberg
2009-07-15 22:09                                                                           ` Jamie Lokier
2009-07-16  7:22                                                                             ` Artem Bityutskiy
2009-07-16  7:16                                                                           ` Artem Bityutskiy
2009-07-16 20:54                                                                             ` Gilles Casse
2009-07-17  0:29                                                                               ` Carl-Daniel Hailfinger
2009-07-24 14:08                                                                                 ` Jamie Lokier
2009-07-16  7:14                                                                         ` Artem Bityutskiy
2009-06-03  8:08                                                   ` Artem Bityutskiy
2009-06-03  8:25                                                     ` Stefan Roese
2009-06-03 13:50                                                     ` Eric Holmberg
2009-06-07 10:16                                                       ` Artem Bityutskiy
2009-07-28 12:01                                                         ` news
2009-07-28 12:24                                                           ` Adrian Hunter
2009-07-28 17:19                                                           ` Eric Holmberg
2009-08-09  4:59                                                           ` Artem Bityutskiy
2009-04-17  8:58                                         ` Artem Bityutskiy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1239378582.3390.66.camel@localhost.localdomain \
    --to=dedekind@infradead.org \
    --cc=Eric_Holmberg@Trimble.com \
    --cc=adrian.hunter@nokia.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=urs_muff@Trimble.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is 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.