pandora-kernel.git
14 years agoUBIFS: increment commit number earlier
Artem Bityutskiy [Mon, 21 Jul 2008 14:14:29 +0000 (17:14 +0300)]
UBIFS: increment commit number earlier

Increment the commit number at the beginnig of the commit, instead
of doing this after the commit. This is needed for further
optimizations.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBIFS: remove another unneeded function parameter
Artem Bityutskiy [Tue, 22 Jul 2008 09:19:09 +0000 (12:19 +0300)]
UBIFS: remove another unneeded function parameter

The 'last_reference' parameter of 'pack_inode()' is not really
needed because 'inode->i_nlink' may be tested instead. Zap it.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBIFS: remove unneeded function parameter
Artem Bityutskiy [Tue, 22 Jul 2008 09:06:13 +0000 (12:06 +0300)]
UBIFS: remove unneeded function parameter

Simplify 'ubifs_jnl_write_inode()' by removing the 'deletion'
parameter which is not really needed because we may test
inode->i_nlink and check whether this is a deletion or not.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBIFS: do not write orphans back
Artem Bityutskiy [Tue, 22 Jul 2008 08:52:52 +0000 (11:52 +0300)]
UBIFS: do not write orphans back

Orphan inodes are deleted inodes which will disappear after FS
re-mount. There is not need to write orphan inodes back, because
they are not needed on the flash media.

So optimize orphans a little by not writing them back. Just mark
them as clean, free the budget, and report success to VFS.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: fix gcc warning
Artem Bityutskiy [Wed, 23 Jul 2008 12:51:46 +0000 (15:51 +0300)]
UBI: fix gcc warning

Fix the following warning:

drivers/mtd/ubi/vmt.c: In function 'ubi_rename_volumes':
drivers/mtd/ubi/vmt.c:642: warning: statement with no effect

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBIFS: make ubifs_ro_mode() not inline
Adrian Hunter [Mon, 21 Jul 2008 12:39:05 +0000 (15:39 +0300)]
UBIFS: make ubifs_ro_mode() not inline

We use ubifs_ro_mode() quite a lot, and not in fast-path, so
there is no reason to blow the code up by having it inlined.
Also, we usually want R/O mode change to be seen to other
CPUs as soon as possible, so when we make this a function
call, we will automatically have a memory barrier.

Signed-off-by: Adrian Hunter <ext-adrian.hunter@nokia.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBIFS: ensure UBIFS switches to read-only on error writing the log
Adrian Hunter [Fri, 18 Jul 2008 14:56:37 +0000 (17:56 +0300)]
UBIFS: ensure UBIFS switches to read-only on error writing the log

UBI transparently handles write errors by automatically copying
and remapping the affected eraseblock. If UBI is unable to do
that, for example its pool of eraseblocks reserved for bad block
handling is empty, then the error is propagated to UBIFS. UBIFS
must protect the media from falling into an inconsistent state
by immediately switching to read-only mode. In the case of log
updates, this was not being done.

Signed-off-by: Adrian Hunter <ext-adrian.hunter@nokia.com>
14 years agoUBIFS: fix error return in failure mode
Adrian Hunter [Fri, 18 Jul 2008 13:47:41 +0000 (16:47 +0300)]
UBIFS: fix error return in failure mode

UBIFS recovery testing debug facility simulates media failures.
When simulating an IO error, the error code returned must be
-EIO but it was not always if the user switched off the
debug recovery testing option at the same time.

Signed-off-by: Adrian Hunter <ext-adrian.hunter@nokia.com>
14 years agoUBIFS: free budget in delete_inode as well
Artem Bityutskiy [Mon, 21 Jul 2008 07:59:53 +0000 (10:59 +0300)]
UBIFS: free budget in delete_inode as well

Although the inode is marked as clean when it is being deleted,
it might stay and be used as orphan, and be marked as dirty.
So we have to free the budget when we delete it.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBIFS: fix budgeting calculations
Artem Bityutskiy [Fri, 18 Jul 2008 15:54:29 +0000 (18:54 +0300)]
UBIFS: fix budgeting calculations

The 'ubifs_release_dirty_inode_budget()' was buggy and incorrectly
freed the budget, which led to not freeing all dirty data budget.
This patch fixes that.

Also, this patch fixes ubifs_mkdir() which passed 1 in dirty_ino_d,
which makes no sense. Well, it is harmless though.

Also, add few more useful assertions. And improve few debugging
messages.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: remove pre-sqnum images support
Artem Bityutskiy [Fri, 18 Jul 2008 10:53:39 +0000 (13:53 +0300)]
UBI: remove pre-sqnum images support

Before UBI got into mainline, there was a slight flash format
change - we did not have sequence number support, then added it.

We have carried full support of those ancient images till this
moment. Now the support is removed, well, not fully removed.

Now UBI will support only _clean_ old images, which were cleanly
detached last time (just before kernel upgrade). This is most
likely the case.

But we will not support unclean ancient images. Surprisingly,
this allows us to remove a big chunk of legacy code.

And the same should be true for downgrading: clean images should
downgrade fine, but unclean ones will not.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: fix kernel-doc errors and warnings
Artem Bityutskiy [Fri, 18 Jul 2008 10:34:32 +0000 (13:34 +0300)]
UBI: fix kernel-doc errors and warnings

No functional changes, just tweak comments to make kernel-doc
work fine and stop complaining.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: fix checkpatch.pl errors and warnings
Artem Bityutskiy [Fri, 18 Jul 2008 10:19:52 +0000 (13:19 +0300)]
UBI: fix checkpatch.pl errors and warnings

Just out or curiousity ran checkpatch.pl for whole UBI,
and discovered there are quite a few of stylistic issues.
Fix them.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: bugfix - do not torture PEB needlessly
Artem Bityutskiy [Fri, 18 Jul 2008 09:42:14 +0000 (12:42 +0300)]
UBI: bugfix - do not torture PEB needlessly

This is probably a copy-paste bug - we torture the old PEB
in the atomic LEB change function, but we should not do this.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: rework scrubbing messages
Artem Bityutskiy [Fri, 18 Jul 2008 09:20:23 +0000 (12:20 +0300)]
UBI: rework scrubbing messages

If bit-flips happen often, UBI prints to many messages. Lessen
the amount by only printing the messages when the PEB has been
scrubbed. Also, print torturing messages.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBIFS: print volume name as well
Artem Bityutskiy [Fri, 18 Jul 2008 09:54:21 +0000 (12:54 +0300)]
UBIFS: print volume name as well

We encouredge people to mount using volume name, not device
numbers. So print the name of the mounted UBI volume, not just
IDs.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoDocumentation: fix typo in ubifs.txt
Sebastian Siewior [Thu, 17 Jul 2008 12:16:09 +0000 (14:16 +0200)]
Documentation: fix typo in ubifs.txt

Signed-off-by: Sebastian Siewior <bigeasy@linutronix.de>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBIFS: add the file-system
Artem Bityutskiy [Thu, 17 Jul 2008 09:21:55 +0000 (12:21 +0300)]
UBIFS: add the file-system

This commit adds full UBIFS at the same state as it was pulled
by Linus on "Wed Jul 16 15:02:57 2008 -0700", commit number
9c1be0c4712fe760d8969427ef91107e9c062d91

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agodo_mounts: allow UBI root device name
Adrian Hunter [Thu, 31 Jan 2008 15:25:00 +0000 (17:25 +0200)]
do_mounts: allow UBI root device name

Similarly to MTD devices, allow UBI devices.

Signed-off-by: Adrian Hunter <ext-adrian.hunter@nokia.com>
14 years agoVFS: export sync_sb_inodes
Artem Bityutskiy [Wed, 7 May 2008 18:01:30 +0000 (21:01 +0300)]
VFS: export sync_sb_inodes

This patch exports the 'sync_sb_inodes()' which is needed for
UBIFS because it have to force write-back from time to time.
Namely, the UBIFS budgeting subsystem forces write-back when
its pessimistic callculations show that there is not free
space on the media.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoVFS: move inode_lock into sync_sb_inodes
Hans Reiser [Wed, 7 May 2008 12:48:57 +0000 (15:48 +0300)]
VFS: move inode_lock into sync_sb_inodes

This patch makes 'sync_sb_inodes()' lock 'inode_lock', rather
than expect that the caller will do this.

This change was previously done by Hans Reiser <reiser@namesys.com>
and sat in the -mm tree.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: implement multiple volumes rename
Artem Bityutskiy [Sun, 13 Jul 2008 18:47:47 +0000 (21:47 +0300)]
UBI: implement multiple volumes rename

Quite useful ioctl which allows to make atomic system upgrades.
The idea belongs to Richard Titmuss <richard_titmuss@logitech.com>

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: fix and re-work debugging stuff
Artem Bityutskiy [Wed, 16 Jul 2008 14:40:22 +0000 (17:40 +0300)]
UBI: fix and re-work debugging stuff

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: amend commentaries
Artem Bityutskiy [Wed, 16 Jul 2008 07:25:56 +0000 (10:25 +0300)]
UBI: amend commentaries

Hch asked not to use "unit" for sub-systems, let it be so.
Also some other commentaries modifications.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: fix error message
Artem Bityutskiy [Mon, 14 Jul 2008 09:57:27 +0000 (12:57 +0300)]
UBI: fix error message

The ubi_err() macro will add \n.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: improve mkvol request validation
Artem Bityutskiy [Sun, 13 Jul 2008 18:46:24 +0000 (21:46 +0300)]
UBI: improve mkvol request validation

Check that volume name is not shorter than 'name_len'.

No need to copy the trailing zero byte because whole array
was zeroed earlier.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: add ubi_sync() interface
Artem Bityutskiy [Thu, 10 Jul 2008 15:38:33 +0000 (18:38 +0300)]
UBI: add ubi_sync() interface

To flush MTD device caches.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: fix 64-bit calculations
Bruce Leonard [Thu, 3 Jul 2008 07:35:49 +0000 (10:35 +0300)]
UBI: fix 64-bit calculations

Signed-off-by: Bruce Leonard <brucle@selinc.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: fix LEB locking
Artem Bityutskiy [Mon, 16 Jun 2008 10:35:23 +0000 (13:35 +0300)]
UBI: fix LEB locking

leb_read_unlock() may be called simultaniously by several tasks.
The would race at the following code:

 up_read(&le->mutex);
 if (free)
         kfree(le);

And it is possible that one task frees 'le' before the other tasks
do 'up_read()'. Fix this by doing up_read and free inside the
'ubi->ltree' lock. Below it the oops we had because of this:

BUG: spinlock bad magic on CPU#0, integck/7504
BUG: unable to handle kernel paging request at 6b6b6c4f
IP: [<c0211221>] spin_bug+0x5c/0xdb
*pde = 00000000 Oops: 0000 [#1] PREEMPT SMP Modules linked in: ubifs ubi nandsim nand nand_ids nand_ecc video output

Pid: 7504, comm: integck Not tainted (2.6.26-rc3ubifs26 #8)
EIP: 0060:[<c0211221>] EFLAGS: 00010002 CPU: 0
EIP is at spin_bug+0x5c/0xdb
EAX: 00000032 EBX: 6b6b6b6b ECX: 6b6b6b6b EDX: f7f7ce30
ESI: f76491dc EDI: c044f51f EBP: e8a736cc ESP: e8a736a8
DS: 007b ES: 007b FS: 00d8 GS: 0033 SS: 0068
Process integck (pid: 7504, ti=e8a72000 task=f7f7ce30 task.ti=e8a72000)
Stack: c044f754 c044f51f 00000000 f7f7d024 00001d50 00000001 f76491dc 00000296       f6df50e0 e8a736d8 c02112f0 f76491dc e8a736e8 c039157a f7d9e830 f76491d8       e8a7370c c020b975 f76491dc 00000296 f76491f8 00000000 f76491d8 00000000 Call Trace:
[<c02112f0>] ? _raw_spin_unlock+0x50/0x7c
[<c039157a>] ? _spin_unlock_irqrestore+0x20/0x58
[<c020b975>] ? rwsem_wake+0x4b/0x122
[<c0390e0a>] ? call_rwsem_wake+0xa/0xc
[<c0139ee7>] ? up_read+0x28/0x31
[<f8873b3c>] ? leb_read_unlock+0x73/0x7b [ubi]
[<f88742a3>] ? ubi_eba_read_leb+0x195/0x2b0 [ubi]
[<f8872a04>] ? ubi_leb_read+0xaf/0xf8 [ubi]

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: fix memory leak on error path
Artem Bityutskiy [Wed, 4 Jun 2008 14:58:37 +0000 (17:58 +0300)]
UBI: fix memory leak on error path

Normally UBI volumes are freed in the release function of
the struct device object. However, on error path they may
have to be freed before the struct device objects have been
initialized.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: do not forget to free internal volumes
Artem Bityutskiy [Wed, 4 Jun 2008 14:00:35 +0000 (17:00 +0300)]
UBI: do not forget to free internal volumes

UBI forgets to free internal volumes when detaching MTD device.
Fix this.

Pointed-out-by: Adrian Hunter <ext-adrian.hunter@nokia.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: fix memory leak
Artem Bityutskiy [Wed, 4 Jun 2008 13:48:12 +0000 (16:48 +0300)]
UBI: fix memory leak

ubi_free_volume() function sets ubi->volumes[] to NULL, so
ubi_eba_close() is useless, it does not free what has to be freed.
So zap it and free vol->eba_tbl at the volume release function.

Pointed-out-by: Adrian Hunter <ext-adrian.hunter@nokia.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: avoid unnecessary division operations
Kyungmin Park [Thu, 22 May 2008 01:32:18 +0000 (10:32 +0900)]
UBI: avoid unnecessary division operations

UBI already checks that @min io size is the power of 2 at io_init.
It is save to use bit operations then.

Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: fix buffer padding
Kyungmin Park [Wed, 21 May 2008 11:34:56 +0000 (14:34 +0300)]
UBI: fix buffer padding

Instead of correctly pad the buffer wich we are writing to the
eraseblock during update, we used weird construct:

memset(buf + len, 0xFF, len - len);

Fix this.

Signed-off-by: Kyungmin Park <kmpark@infradead.org>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: add a comment
Artem Bityutskiy [Tue, 20 May 2008 06:54:02 +0000 (09:54 +0300)]
UBI: add a comment

It is not clear why we schedule PEB for scrubbing in case of
-EBADMSG. Elaborate.

Requested-by: Kyungmin Park <kmpark@infradead.org>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: print error code
Artem Bityutskiy [Wed, 14 May 2008 13:10:33 +0000 (16:10 +0300)]
UBI: print error code

Print error code if checking failed which is very useful
to identify problems.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: add a message
Artem Bityutskiy [Wed, 23 Apr 2008 10:43:21 +0000 (13:43 +0300)]
UBI: add a message

UBI scan takes quite a time on some systems, so it is nice
to print a message that we started attaching an MTD device.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: print media information earlier
Artem Bityutskiy [Sun, 20 Apr 2008 15:00:33 +0000 (18:00 +0300)]
UBI: print media information earlier

Print information about logicale eraseblock size, sub-page
size and so on at early stage, befor an attempt to attach
the MTD device was made. This is more convenient to do so
because the attempt to attach may fail, and the information
is never printed then.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: fix mean EC calculation
Artem Bityutskiy [Sat, 19 Apr 2008 17:44:31 +0000 (20:44 +0300)]
UBI: fix mean EC calculation

(a + b) / (c + d) != a / c + b / d. The old code errornously
assumed this incorrect formuld. Instead, just sum all erase
counters in a 64-bit variable and divide to the number of EBs
at the end.

Thanks to Adrian Hunter for pointing this out.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: initialize static volumes with vol->used_bytes
Jan Altenberg [Fri, 28 Mar 2008 15:13:53 +0000 (16:13 +0100)]
UBI: initialize static volumes with vol->used_bytes

I came across a problem which seems to be present since:

commit 941dfb07ed91451b1c58626a0d258dfdf468b593
UBI: set correct gluebi device size

ubi_create_gluebi() leaves mtd->size = 0 for static volumes. So even
existing static volumes are initialized with a size of 0.

Signed-off-by: Jan Altenberg <jan.altenberg@linutronix.de>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: improve Kconfig documentation
Artem Bityutskiy [Thu, 27 Mar 2008 15:18:45 +0000 (17:18 +0200)]
UBI: improve Kconfig documentation

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoDocumentation: add UBI sysfs ABI docs
Artem Bityutskiy [Fri, 8 Feb 2008 10:13:08 +0000 (12:13 +0200)]
Documentation: add UBI sysfs ABI docs

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Acked-by: Greg KH <greg@kroah.com>
14 years agoUBI: make ubi-header.h local
Artem Bityutskiy [Sat, 16 Feb 2008 13:42:52 +0000 (15:42 +0200)]
UBI: make ubi-header.h local

The new trend in linux is not to store headers which define
on-media format in the include/ directory, but instead, store
them locally. This is because these headers "do not define any
kernel<->userspace interface".

Do so for UBI as well.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: fix sparse errors in ubi.h
Harvey Harrison [Fri, 15 Feb 2008 08:47:51 +0000 (10:47 +0200)]
UBI: fix sparse errors in ubi.h

In C, signed 1-bit bitfields can only take the values 0 and -1, only 0 and 1
are ever assigned in current code.  Make them unsigned bitfields.

Fixes the (repeated) sparse errors:
drivers/mtd/ubi/ubi.h:220:15: error: dubious one-bit signed bitfield
drivers/mtd/ubi/ubi.h:221:17: error: dubious one-bit signed bitfield
drivers/mtd/ubi/ubi.h:222:18: error: dubious one-bit signed bitfield
drivers/mtd/ubi/ubi.h:223:16: error: dubious one-bit signed bitfield
drivers/mtd/ubi/ubi.h:224:20: error: dubious one-bit signed bitfield

Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
Cc: Artem Bityutskiy <dedekind@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: fix error printing
Artem Bityutskiy [Tue, 12 Feb 2008 14:36:41 +0000 (16:36 +0200)]
UBI: fix error printing

Use existing ubi_err() as the rest of the code does.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: fix error message
Artem Bityutskiy [Tue, 12 Feb 2008 14:32:35 +0000 (16:32 +0200)]
UBI: fix error message

Make it print "UBI error: cannot attach mtd4"
instead of "UBI error: cannot attach 4"

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: silence warning
S.Çağlar Onur [Tue, 12 Feb 2008 11:25:06 +0000 (13:25 +0200)]
UBI: silence warning

drivers/mtd/ubi/vmt.c: In function `ubi_create_volume':
drivers/mtd/ubi/vmt.c:379: warning: statement with no effect

Signed-off-by: S.Çağlar Onur <caglar@pardus.org.tr>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: be verbose when debuggin is enabled
Artem Bityutskiy [Tue, 12 Feb 2008 11:26:31 +0000 (13:26 +0200)]
UBI: be verbose when debuggin is enabled

Make I/O function to be always verbose when about CRC errors
and magic number errors when I/O debugging is enabled.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: do not flush queue on each vtbl change
Artem Bityutskiy [Fri, 1 Feb 2008 11:48:49 +0000 (13:48 +0200)]
UBI: do not flush queue on each vtbl change

This is just not necessary. We re-write whole layout copy, so
the old contents cannot show up again sice scan process will
drop it.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: implement atomic LEB change ioctl
Artem Bityutskiy [Thu, 24 Jan 2008 16:48:21 +0000 (18:48 +0200)]
UBI: implement atomic LEB change ioctl

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: introduce atomic LEB change ioctl
Artem Bityutskiy [Thu, 24 Jan 2008 14:15:14 +0000 (16:15 +0200)]
UBI: introduce atomic LEB change ioctl

We have to be able to change individual LEBs for utilities like
ubifsck, ubifstune. For example, ubifsck has to be able to fix
errors on the media, ubifstune has to be able to change the
the superblock, hence this ioctl.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: handle zero-length case
Artem Bityutskiy [Thu, 24 Jan 2008 15:56:14 +0000 (17:56 +0200)]
UBI: handle zero-length case

ubi_eba_atomic_leb_change() has to just map the LEB to a free PEB
if data length is zero.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: simplify internal interfaces
Artem Bityutskiy [Thu, 24 Jan 2008 15:04:01 +0000 (17:04 +0200)]
UBI: simplify internal interfaces

Instead of passing vol_id to all functions and then find
struct ubi_volume, pass struct ubi_volume pointer.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: do not change file pointer while updating
Artem Bityutskiy [Thu, 24 Jan 2008 14:45:57 +0000 (16:45 +0200)]
UBI: do not change file pointer while updating

Since we do not change semantics of seek(), changing the file
pointer while updating does not make much sense.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: add layout volume information
Artem Bityutskiy [Thu, 24 Jan 2008 09:23:23 +0000 (11:23 +0200)]
UBI: add layout volume information

Add more information about layout volume to make userspace tools
use the macros instead of constants. Also rename UBI_LAYOUT_VOL_ID
to make it consistent with other macros.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: fix warnings
Artem Bityutskiy [Thu, 24 Jan 2008 09:19:14 +0000 (11:19 +0200)]
UBI: fix warnings

Old gcc complains:

CC      drivers/mtd/ubi/wl.o
drivers/mtd/ubi/wl.c: In function 'wear_leveling_worker':
drivers/mtd/ubi/wl.c:746: warning: 'pe' may be used uninitialized in this function
CC      drivers/mtd/ubi/scan.o
drivers/mtd/ubi/scan.c: In function 'ubi_scan':
drivers/mtd/ubi/scan.c:772: warning: 'ec' may be used uninitialized in this function
drivers/mtd/ubi/scan.c:772: note: 'ec' was declared here

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: add sanity check
Artem Bityutskiy [Tue, 22 Jan 2008 10:38:15 +0000 (12:38 +0200)]
UBI: add sanity check

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: remove bogus assertion
Artem Bityutskiy [Tue, 22 Jan 2008 10:31:30 +0000 (12:31 +0200)]
UBI: remove bogus assertion

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: bugfix: calculate data offset properly
Artem Bityutskiy [Thu, 17 Jan 2008 13:41:14 +0000 (15:41 +0200)]
UBI: bugfix: calculate data offset properly

Data offset is VID header offset + VID header size aligned to
the min. I/O unit size up.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: amend array size
Artem Bityutskiy [Thu, 17 Jan 2008 13:35:57 +0000 (15:35 +0200)]
UBI: amend array size

Since the data offset parameter was removed, the size of
the parameters array is now 2, not 3.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: add auto-resize feature
Artem Bityutskiy [Wed, 16 Jan 2008 13:44:24 +0000 (15:44 +0200)]
UBI: add auto-resize feature

The problem: NAND flashes have different amount of initial bad physical
eraseblocks (marked as bad by the manufacturer). For example, for 256MiB
Samsung OneNAND flash there might be from 0 to 40 bad initial eraseblocks,
which is about 2%. When UBI is used as the base system, one needs to know
the exact amount of good physical eraseblocks, because this number is
needed to create the UBI image which is put to the devices during
production. But this number is not know, which forces us to use the
minimum number of good physical eraseblocks. And UBI additionally
reserves some percentage of physical eraseblocks for bad block handling
(default is 1%), so we have 1-3% of PEBs reserved at the end, depending
on the amount of initial bad PEBs. But it is desired to always have
1% (or more, depending on the configuration).

Solution: this patch adds an "auto-resize" flag to the volume table.
The volume which has the "auto-resize" flag will automatically be re-sized
(enlarged) on the first UBI initialization. UBI clears the flag when
the volume is re-sized. Only one volume may have the "auto-resize" flag.

So, the production UBI image may have one volume with "auto-resize"
flag set, and its size is automatically adjusted on the first boot
of the device.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: use bit-fields
Artem Bityutskiy [Wed, 16 Jan 2008 12:24:14 +0000 (14:24 +0200)]
UBI: use bit-fields

Save 12 bytes of RAM per volume by using bit-fields instead of integers.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: fix warnings
Artem Bityutskiy [Wed, 16 Jan 2008 10:15:47 +0000 (12:15 +0200)]
UBI: fix warnings

drivers/mtd/ubi/cdev.c: In function ‘vol_cdev_read’:
drivers/mtd/ubi/cdev.c:187: warning: unused variable ‘vol_id’
CC [M]  drivers/mtd/ubi/kapi.o
drivers/mtd/ubi/kapi.c: In function ‘ubi_leb_erase’:
drivers/mtd/ubi/kapi.c:483: warning: unused variable ‘vol_id’
drivers/mtd/ubi/kapi.c: In function ‘ubi_leb_unmap’:
drivers/mtd/ubi/kapi.c:544: warning: unused variable ‘vol_id’
drivers/mtd/ubi/kapi.c: In function ‘ubi_leb_map’:
drivers/mtd/ubi/kapi.c:582: warning: unused variable ‘vol_id’

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: get rid of ubi_ltree_slab
Artem Bityutskiy [Wed, 16 Jan 2008 10:11:54 +0000 (12:11 +0200)]
UBI: get rid of ubi_ltree_slab

This slab cache is not really needed since the number of objects
is low and the constructor does not make much sense because we
allocate oblects when doint I/O, which is way slower then allocation.

Suggested-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: bugfix: do not forget to increment vol_count
Artem Bityutskiy [Wed, 26 Dec 2007 13:59:39 +0000 (15:59 +0200)]
UBI: bugfix: do not forget to increment vol_count

When creating a new volume, do not forget to increment the
vol_count variable.

Also, users are not interested in internal volumes, so do not show
them in the volumes_count sysfs file.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: do not support kiB
Artem Bityutskiy [Wed, 26 Dec 2007 12:25:58 +0000 (14:25 +0200)]
UBI: do not support kiB

Be strict and accept only KiB, MiB and GiB, not Kib, not kib, etc.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: add mtd_num sysfs attribute
Artem Bityutskiy [Wed, 26 Dec 2007 11:46:46 +0000 (13:46 +0200)]
UBI: add mtd_num sysfs attribute

Expose number or the underlying MTD device in sysfs.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: fix mtd device string parsing
Artem Bityutskiy [Tue, 25 Dec 2007 17:17:00 +0000 (19:17 +0200)]
UBI: fix mtd device string parsing

UBI allows to specify MTD device name or number when the module is being
loaded. When parsing MTD device identity string, it first tries to treat
it as device NAME, and if that fails, it treats it as device number.

Make it vice-versa as this is more logical and makes less troubles when
you have an MTD device named "1" and try to load mtd1 which has different
name. This is especially easy to hit when gluebi is enabled.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: use separate mutex for volumes checking
Artem Bityutskiy [Tue, 25 Dec 2007 16:13:33 +0000 (18:13 +0200)]
UBI: use separate mutex for volumes checking

Introduce a separate mutex which serializes volumes checking,
because we cammot really use volumes_mutex - it cases reverse
locking problems with mtd_tbl_mutex when gluebi is used -
thanks to lockdep.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: handle attach ioctl
Artem Bityutskiy [Tue, 18 Dec 2007 16:23:39 +0000 (18:23 +0200)]
UBI: handle attach ioctl

Actually implement the MTD device attach/detach handlers.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: introduce attach ioctls
Artem Bityutskiy [Tue, 18 Dec 2007 16:22:16 +0000 (18:22 +0200)]
UBI: introduce attach ioctls

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: remove data_offset
Artem Bityutskiy [Wed, 19 Dec 2007 19:43:32 +0000 (21:43 +0200)]
UBI: remove data_offset

'data_offset' parameter does not really make sense and it is not
needed. Get rid of it.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: prepare attach and detach functions
Artem Bityutskiy [Mon, 17 Dec 2007 18:33:20 +0000 (20:33 +0200)]
UBI: prepare attach and detach functions

Prepare the attach and detach functions to by used outside of
module initialization:

* detach function checks reference count before detaching
* it kills the background thread as well

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: add UBI devices reference counting
Artem Bityutskiy [Mon, 17 Dec 2007 15:37:26 +0000 (17:37 +0200)]
UBI: add UBI devices reference counting

This is one more step on the way to "removable" UBI devices. It
adds reference counting for UBI devices. Every time a volume on
this device is opened - the device's refcount is increased. It
is also increased if someone is reading any sysfs file of this
UBI device or of one of its volumes.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: add UBI control device
Artem Bityutskiy [Sun, 16 Dec 2007 14:59:31 +0000 (16:59 +0200)]
UBI: add UBI control device

This patch is a preparation to make UBI devices dynamic. It
adds an UBI control device which has dynamically allocated
major number and registers itself as "ubi_ctrl". It does not
do anything so far. The idea is that this device will allow
to attach/detach MTD devices from userspace.

This is symilar to what the Linux device mapper has.

The next things to do are:
* Fix UBI, because it now assumes UBI devices cannot go away
* Implement control device ioctls which will attach/detach MTD
  devices

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: fix comment
Artem Bityutskiy [Wed, 19 Dec 2007 14:03:17 +0000 (16:03 +0200)]
UBI: fix comment

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: fix ubi_wl_flush
Artem Bityutskiy [Tue, 18 Dec 2007 13:54:35 +0000 (15:54 +0200)]
UBI: fix ubi_wl_flush

The flush function should finish all the pending jobs. But if
somebody else is doing a work, this function should wait and let
it finish.

This patche uses rw semaphore for synchronization purpose - it
just looks quite convinient.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: fix printk
Artem Bityutskiy [Wed, 19 Dec 2007 15:03:42 +0000 (17:03 +0200)]
UBI: fix printk

Add proper log level to printk's.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: bugfix: protect from volume removal
Artem Bityutskiy [Tue, 18 Dec 2007 13:06:55 +0000 (15:06 +0200)]
UBI: bugfix: protect from volume removal

When the WL worker is moving an LEB, the volume might go away
occasionally. UBI does not handle these situations correctly.

This patch introduces a new mutex which serializes wear-levelling
worker and the the 'ubi_wl_put_peb()' function. Now, if one puts
an LEB, and its PEB is being moved, it will wait on the mutex.
And because we unmap all LEBs when removing volumes, this will make
the volume remove function to wait while the LEB movement
finishes.

Below is an example of an oops which should be fixed by this patch:

Pid: 9167, comm: io_paral Not tainted (2.6.24-rc5-ubi-2.6.git #2)
EIP: 0060:[<f884a379>] EFLAGS: 00010246 CPU: 0
EIP is at prot_tree_del+0x2a/0x63 [ubi]
EAX: f39a90e0 EBX: 00000000 ECX: 00000000 EDX: 00000134
ESI: f39a90e0 EDI: f39a90e0 EBP: f2d55ddc ESP: f2d55dd4
 DS: 007b ES: 007b FS: 00d8 GS: 0033 SS: 0068
Process io_paral (pid: 9167, ti=f2d54000 task=f72a8030 task.ti=f2d54000)
Stack: f39a95f8 ef6aae50 f2d55e08 f884a511 f88538e1 f884ecea 00000134 00000000
       f39a9604 f39a95f0 efea8280 00000000 f39a90e0 f2d55e40 f8847261 f8850c3c
       f884eaad 00000001 000000b9 00000134 00000172 000000b9 00000134 00000001
Call Trace:
 [<c0105227>] show_trace_log_lvl+0x1a/0x30
 [<c01052e2>] show_stack_log_lvl+0xa5/0xca
 [<c01053d6>] show_registers+0xcf/0x21b
 [<c0105648>] die+0x126/0x224
 [<c0119a62>] do_page_fault+0x27f/0x60d
 [<c037dd62>] error_code+0x72/0x78
 [<f884a511>] ubi_wl_put_peb+0xf0/0x191 [ubi]
 [<f8847261>] ubi_eba_unmap_leb+0xaf/0xcc [ubi]
 [<f8843c21>] ubi_remove_volume+0x102/0x1e8 [ubi]
 [<f8846077>] ubi_cdev_ioctl+0x22a/0x383 [ubi]
 [<c017d768>] do_ioctl+0x68/0x71
 [<c017d7c6>] vfs_ioctl+0x55/0x271
 [<c017da15>] sys_ioctl+0x33/0x52
 [<c0104152>] sysenter_past_esp+0x5f/0xa5
 =======================

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: improve comment
Artem Bityutskiy [Tue, 18 Dec 2007 11:17:24 +0000 (13:17 +0200)]
UBI: improve comment

Explain better the purpose of thie 'move_to_put' stuff.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: add PID to debugging prints
Artem Bityutskiy [Tue, 18 Dec 2007 10:57:52 +0000 (12:57 +0200)]
UBI: add PID to debugging prints

Also, use single dbg_msg() macro for all prints.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: tweak volumes locking some more
Artem Bityutskiy [Mon, 17 Dec 2007 15:08:55 +0000 (17:08 +0200)]
UBI: tweak volumes locking some more

Make the code more consistent by requiring the caller to lock the
ubi->volume_mutex, because this is what we do for updates.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: introduce volume refcounting
Artem Bityutskiy [Mon, 17 Dec 2007 13:42:57 +0000 (15:42 +0200)]
UBI: introduce volume refcounting

Add ref_count field to UBI volumes and remove weired "vol->removed"
field. This way things are better understandable and we do not have
to do whold show_attr operation under spinlock.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: simplify error handling
Artem Bityutskiy [Mon, 17 Dec 2007 13:48:49 +0000 (15:48 +0200)]
UBI: simplify error handling

If we fail halfway through sysfs file creation, we may just call
sysfs remove function and it will delete all the files we created.
For non-existing files it will also be OK - the remove functions
just return -ENOENT.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: fix and cleanup volume opening functions
Artem Bityutskiy [Mon, 17 Dec 2007 12:22:55 +0000 (14:22 +0200)]
UBI: fix and cleanup volume opening functions

This patch fixes error codes of the functions - if the device number
is out of range, -EINVAL should be returned. It also removes unneeded
try_module_get call from the open by name function.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: fix error path
Artem Bityutskiy [Mon, 17 Dec 2007 12:02:09 +0000 (14:02 +0200)]
UBI: fix error path

Error path in volume creation is bogus. First of, it ovverrides the
'err' variable and returns zero to the caller. Second, ubi_assert()
in the release function is wrong.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: get device when opening volume
Artem Bityutskiy [Mon, 17 Dec 2007 11:09:09 +0000 (13:09 +0200)]
UBI: get device when opening volume

When a volume is opened, get its kref via get_device() call.
And put the reference when closing the volume. With this, we
may have a bit saner volume delete.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: add some more comments
Artem Bityutskiy [Mon, 17 Dec 2007 11:21:07 +0000 (13:21 +0200)]
UBI: add some more comments

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: tweak volumes locking
Artem Bityutskiy [Mon, 17 Dec 2007 10:46:48 +0000 (12:46 +0200)]
UBI: tweak volumes locking

Transform vtbl_mutex to volumes_mutex - this just makes code
easier to understand.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: improve internal interfaces
Artem Bityutskiy [Sun, 16 Dec 2007 18:00:38 +0000 (20:00 +0200)]
UBI: improve internal interfaces

Pass volume description object to the EBA function which makes
more sense, and EBA function do not have to find the volume
description object by volume ID.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: bugfix: dont oops with NULL module parameter
Artem Bityutskiy [Sun, 16 Dec 2007 14:46:57 +0000 (16:46 +0200)]
UBI: bugfix: dont oops with NULL module parameter

E.g., it oopsed in case of: modprobe ubi mtd = 0

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: remove ubi_devices_cnt
Artem Bityutskiy [Sun, 16 Dec 2007 11:01:03 +0000 (13:01 +0200)]
UBI: remove ubi_devices_cnt

This global variablea is not really needed, remove it

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: create ubi_wl_entry slab on initialization
Artem Bityutskiy [Sun, 16 Dec 2007 10:49:01 +0000 (12:49 +0200)]
UBI: create ubi_wl_entry slab on initialization

Similarly to ltree_entry_slab, it makes more sense to create
and destroy ubi_wl_entry slab on module initialization/exit.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: create ltree_entry slab on initialization
Artem Bityutskiy [Sun, 16 Dec 2007 10:32:51 +0000 (12:32 +0200)]
UBI: create ltree_entry slab on initialization

Since the ltree_entry slab cache is a global entity, which is
used by all UBI devices, it is more logical to create it on
module initialization time and destro on module exit time.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: improve error messages
Artem Bityutskiy [Sat, 15 Dec 2007 17:56:51 +0000 (19:56 +0200)]
UBI: improve error messages

Always print error code with error messages, sometimes it is
extremely helpful info.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: remove redundant field
Artem Bityutskiy [Sat, 15 Dec 2007 16:13:56 +0000 (18:13 +0200)]
UBI: remove redundant field

Remove redundant ubi->major field - we have it in ubi->cdev.dev
already.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: minor tidy-ups
Artem Bityutskiy [Sat, 15 Dec 2007 13:09:07 +0000 (15:09 +0200)]
UBI: minor tidy-ups

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: silence a warning
Jesper Juhl [Thu, 13 Dec 2007 22:53:08 +0000 (23:53 +0100)]
UBI: silence a warning

This patch silences the following warning :

  drivers/mtd/ubi/vmt.c:73: warning: 'ret' may be used uninitialized in this function

gcc can't see that we always initialize ret in all situations where it is
actually used. The one case where it's not initialized is when we BUG(),
but gcc doesn't know that we won't then continue and use an uninitialized
'ret'.

This patch results in code that does exactely the same as before, but it
also makes gcc shut up, so we generate one less line of warning noise.

Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: add ubi_leb_map interface
Artem Bityutskiy [Thu, 6 Dec 2007 16:47:30 +0000 (18:47 +0200)]
UBI: add ubi_leb_map interface

The idea of this interface belongs to Adrian Hunter. The
interface is extremely useful when one has to have a guarantee
that an LEB will contain all 0xFFs even in case of an unclean
reboot. UBI does have an 'ubi_leb_erase()' call which may do
this, but it is stupid and ineffecient, because it flushes whole
queue. I should be re-worked to just be a pair of unmap,
map calls.

The user of the interfaci is UBIFS at the moment.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
14 years agoUBI: bugfix: allocate mandatory EBs first
Artem Bityutskiy [Tue, 4 Dec 2007 19:36:12 +0000 (21:36 +0200)]
UBI: bugfix: allocate mandatory EBs first

First allocate the necessary eraseblocks, then the optional ones.
Otherwise it allocates all PEBs for bad EB handling, and fails
on then following EBA LEB allocation.

Reported-by: Adrian Hunter <ext-adrian.hunter@nokia.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>