linux/drivers/mtd/ubi
Sebastian Siewior 9cd9a21ce0 ubi/upd: Always flush after prepared for an update
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.

Cc: stable@vger.kernel.org
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Richard Weinberger <richard@nod.at>
2017-03-30 09:27:11 +02:00
..
attach.c UBI: introduce the VID buffer concept 2016-10-02 22:48:14 +02:00
block.c block: fold cmd_type into the REQ_OP_ space 2017-01-31 14:00:44 -07:00
build.c statx: Add a system call to make enhanced file info available 2017-03-02 20:51:15 -05:00
cdev.c UBI: add an helper to check lnum validity 2016-10-02 22:48:14 +02:00
debug.c UBI: Silence an unintialized variable warning 2016-05-24 15:24:30 +02:00
debug.h UBI: power cut emulation for testing 2015-04-13 21:05:17 +02:00
eba.c UBI: Fix crash in try_recover_peb() 2016-10-20 00:06:06 +02:00
fastmap-wl.c ubi: Fix races around ubi_refill_pools() 2016-10-02 22:54:01 +02:00
fastmap.c ubi: fastmap: Fix add_vol() return value test in ubi_attach_fastmap() 2016-10-28 14:48:18 +02:00
gluebi.c ubi: gluebi: Fix double refcounting 2016-07-29 23:31:54 +02:00
io.c UBI: introduce the VID buffer concept 2016-10-02 22:48:14 +02:00
kapi.c statx: Add a system call to make enhanced file info available 2017-03-02 20:51:15 -05: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 mtd: ubi: Add logging functions ubi_msg, ubi_warn and ubi_err 2016-03-20 21:36:05 +01:00
ubi-media.h UBI: Fix typo in comment 2015-10-03 20:09:41 +02:00
ubi.h UBI: introduce the VID buffer concept 2016-10-02 22:48:14 +02:00
upd.c ubi/upd: Always flush after prepared for an update 2017-03-30 09:27:11 +02:00
vmt.c UBI: hide EBA internals 2016-10-02 22:48:14 +02:00
vtbl.c UBI: introduce the VID buffer concept 2016-10-02 22:48:14 +02:00
wl.c ubi: Fix races around ubi_refill_pools() 2016-10-02 22:54:01 +02:00
wl.h UBI: Fastmap: Remove is_fm_block() 2015-03-26 22:47:38 +01:00