openwrt/package
Rafał Miłecki 6b8407c6da base-files: call "sync" after initial setup
OpenWrt uses a lot of (b)ash scripts for initial setup. This isn't the
best solution as they almost never consider syncing files / data. Still
this is what we have and we need to try living with it.

Without proper syncing OpenWrt can easily get into an inconsistent state
on power cut. It's because:
1. Actual (flash) inode and data writes are not synchronized
2. Data writeback can take up to 30 seconds (dirty_expire_centisecs)
3. ubifs adds extra 5 seconds (dirty_writeback_centisecs) "delay"

Some possible cases (examples) for new files:
1. Power cut during 5 seconds after write() can result in all data loss
2. Power cut happening between 5 and 35 seconds after write() can result
   in empty file (inode flushed after 5 seconds, data flush queued)

Above affects e.g. uci-defaults. After executing some migration script
it may get deleted (whited out) without generated data getting actually
written. Power cut will result in missing data and deleted file.

There are three ways of dealing with that:
1. Rewriting all user-space init to proper C with syncs
2. Trying bash hacks (like creating tmp files & moving them)
3. Adding sync and hoping for no power cut during critical section

This change introduces the last solution that is the simplest. It
reduces time during which things may go wrong from ~35 seconds to
probably less than a second. Of course it applies only to IO operations
performed before /etc/init.d/boot . It's probably the stage when the
most new files get created.

All later changes are usually done using smarter C apps (e.g. busybox or
uci) that creates tmp files and uses rename() that is expected to be
atomic.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Acked-by: Hauke Mehrtens <hauke@hauke-m.de>
Acked-by: Sergey Ryazanov <ryazanov.s.a@gmail.com>
(cherry picked from commit 9851d4b6ce)
2022-03-15 10:15:39 +01:00
..
base-files base-files: call "sync" after initial setup 2022-03-15 10:15:39 +01:00
boot uboot-lantiq: danube: fix hanging lzma kernel uncompression #2 2021-11-27 22:55:25 +01:00
devel perf: build with NO_LIBCAP=1 2020-05-05 00:05:28 +02:00
firmware wireless-regdb: update to version 2021.08.28 2021-11-07 19:49:57 +01:00
kernel mac80211: Update to version 4.19.221 2021-12-14 23:38:30 +01:00
libs wolfssl: fix API breakage of SSL_get_verify_result 2022-02-22 20:32:11 +01:00
network hostapd: Apply SAE/EAP-pwd side-channel attack update 2 2022-02-13 19:14:38 +01:00
system ubus: backport fixes for UAF and other issues 2022-02-21 07:41:05 +01:00
utils busybox: delete redundant patch 2020-08-12 11:10:16 +02:00
Makefile packages: apply usign padding workarounds to package indexes if needed 2019-08-07 07:22:37 +02:00