linux/drivers/mtd/ubi
Sebastian Siewior 6550ef6fe4 ubi/upd: Always flush after prepared for an update
commit 9cd9a21ce0 upstream.

In commit 6afaf8a484 ("UBI: flush wl before clearing update marker") I
managed to trigger and fix a similar bug. Now here is another version of
which I assumed it wouldn't matter back then but it turns out UBI has a
check for it and will error out like this:

|ubi0 warning: validate_vid_hdr: inconsistent used_ebs
|ubi0 error: validate_vid_hdr: inconsistent VID header at PEB 592

All you need to trigger this is? "ubiupdatevol /dev/ubi0_0 file" + a
powercut in the middle of the operation.
ubi_start_update() sets the update-marker and puts all EBs on the erase
list. After that userland can proceed to write new data while the old EB
aren't erased completely. A powercut at this point is usually not that
much of a tragedy. UBI won't give read access to the static volume
because it has the update marker. It will most likely set the corrupted
flag because it misses some EBs.
So we are all good. Unless the size of the image that has been written
differs from the old image in the magnitude of at least one EB. In that
case UBI will find two different values for `used_ebs' and refuse to
attach the image with the error message mentioned above.

So in order not to get in the situation, the patch will ensure that we
wait until everything is removed before it tries to write any data.
The alternative would be to detect such a case and remove all EBs at the
attached time after we processed the volume-table and see the
update-marker set. The patch looks bigger and I doubt it is worth it
since usually the write() will wait from time to time for a new EB since
usually there not that many spare EB that can be used.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
History 2017-07-18 18:40:25 +01:00
..
attach.c ubi: Be more paranoid while seaching for the most recent Fastmap 2016-11-20 01:17:01 +00:00
block.c UBI: block: Add missing cache flushes 2015-09-30 13:20:56 +01:00
build.c ubi: Fix race condition between ubi device creation and udev 2016-11-20 01:17:01 +00:00
cdev.c UBI: fix check for "too many bytes" 2015-05-05 11:09:36 +01:00
debug.c UBI: embed ubi_debug_info field in ubi_device struct 2012-12-10 13:38:59 +02:00
debug.h mtd: rename random32() to prandom_u32() 2013-02-04 09:26:28 +02:00
eba.c ubi: Fix races around ubi_refill_pools() 2017-02-23 03:54:08 +00:00
fastmap.c ubi: Fix Fastmap's update_vol() 2017-02-23 03:54:08 +00:00
gluebi.c UBI: gluebi: rename misleading variables 2012-11-30 13:54:41 +02:00
io.c UBI: Validate data_size 2015-10-19 15:42:37 +01:00
kapi.c UBI: modify ubi_wl_flush function to clear work queue for a lnum 2012-05-21 11:34:41 +03:00
Kconfig UBI: block: Add CONFIG_BLOCK dependency 2014-03-04 14:49:53 +02:00
Makefile UBI: R/O block driver on top of UBI volumes 2014-02-28 16:29:48 +02:00
misc.c UBI: fix soft lockup in ubi_check_volume() 2015-05-12 09:36:35 +01:00
ubi-media.h UBI: Add fastmap on-flash data structures 2012-10-03 12:29:37 +03:00
ubi.h ubi: Be more paranoid while seaching for the most recent Fastmap 2016-11-20 01:17:01 +00:00
upd.c ubi/upd: Always flush after prepared for an update 2017-07-18 18:40:25 +01:00
vmt.c ubi: Make volume resize power cut aware 2016-11-20 01:17:01 +00:00
vtbl.c UBI: return ENOSPC if no enough space available 2015-10-19 15:47:00 +01:00
wl.c ubi: Fix races around ubi_refill_pools() 2017-02-23 03:54:08 +00:00