Compare commits

...

10 Commits

Author SHA1 Message Date
Liangbin Lian
b5f94355a0 target/bcm27xx: fix custom boot config reset on upgrade
Fix #1721
2024-08-09 16:27:15 +08:00
Liangbin Lian
024cfeac1b
target/rk3568: disable overlayfs index
Fix docker migration.

By default, we use /overlay/upper/opt/docker as the docker data root.
If overlayfs index is enabled, docker will not be able to use overlay2 as the storage driver (generating the log "level=error msg="failed to mount overlay: device or resource busy" storage-driver=overlay2"), and will fall back to vfs.
After the docker data is migrated, overlay2 will definitely be used as the storage driver.
This will cause the storage driver to be inconsistent before and after the docker data migration, and all containers and images will disappear after the migration.
2024-07-02 12:44:44 +08:00
Liangbin Lian
17b7b13984 package/rpcd: recovery from a failed uci commit
If uci commit failed, recovery uci, then return a error.

Signed-off-by: Liangbin Lian <jjm2473@gmail.com>
(cherry picked from commit 46ac9ad595fd492d2477e45bcbe9f4bebc13e013)
2024-06-17 11:11:50 +08:00
Liangbin Lian
97a96ca433 package/uci: prevent writing empty configuration files when disk is full
Signed-off-by: Liangbin Lian <jjm2473@gmail.com>
(cherry picked from commit 2408c5fdeead2d77529a6306a5d1b5a6c2fcf663)
2024-06-17 11:10:44 +08:00
Liangbin Lian
24a8777feb istoreos: mount_root improve performance on cleaning redundant whiteout markers 2024-06-17 11:09:14 +08:00
Liangbin Lian
4ad2a861d9 istoreos: mount_root keep custom ipk mirror on sysupgrade
fix 4642f53357
2024-06-17 11:09:14 +08:00
Liangbin Lian
f71c2863d1 luci-app-ota: we have mirror now 2024-05-27 18:59:52 +08:00
Liangbin Lian
1882e28d76 istoreos/ota: add lock to download status
and fix curl error not shown
2024-05-27 18:59:52 +08:00
Liangbin Lian
1bddd11e72 istoreos/ota: fix cancel downloading task
```
    fcurl --connect-timeout 5 --progress-bar -o /tmp/firmware.img.part "$OTA_URL_BASE/$img" 2>/tmp/firmware.img.progress &
    local pid="$!"
```

if we don't use alias, the pid will point to sub shell, not curl.

on canceling, kill signal should send to curl.
2024-05-27 18:59:52 +08:00
Liangbin Lian
37ea01fa3e istoreos: try umount rootfs on shutdown 2024-05-27 18:59:52 +08:00
12 changed files with 367 additions and 37 deletions

View File

@ -3,11 +3,7 @@
STOP=90 STOP=90
restart() { shutdown() {
:
}
stop() {
if [ ! -f /rom/rom/note ]; then if [ ! -f /rom/rom/note ]; then
sync /overlay sync /overlay
umount /overlay umount /overlay
@ -15,6 +11,11 @@ stop() {
umount /ext_overlay umount /ext_overlay
else else
# pivot # pivot
mount --make-private / 2>&-
mount --make-private /tmp 2>&-
mount --make-private /mnt 2>&-
mount --make-private /overlay 2>&-
mount --make-private /ext_overlay 2>&-
mount --move /dev /rom/dev mount --move /dev /rom/dev
mount --move /tmp /rom/tmp mount --move /tmp /rom/tmp
mount --move /sys /rom/sys mount --move /sys /rom/sys
@ -22,6 +23,7 @@ stop() {
mount --move /overlay /rom/overlay mount --move /overlay /rom/overlay
mount --move /proc /rom/proc mount --move /proc /rom/proc
if pivot_root /rom /rom/mnt; then if pivot_root /rom /rom/mnt; then
echo "<1>umount: pivot_root success" >/dev/kmsg
sync sync
/usr/bin/umount -R -d /mnt /usr/bin/umount -R -d /mnt
sync /mnt sync /mnt
@ -31,8 +33,13 @@ stop() {
sync /ext_overlay sync /ext_overlay
umount /ext_overlay umount /ext_overlay
else else
echo "<1>umount: pivot_root failed!" >/rom/dev/kmsg
mount --move /rom/proc /proc mount --move /rom/proc /proc
mount --move /rom/dev /dev mount --move /rom/dev /dev
mount --move /rom/tmp /tmp
mount --move /rom/sys /sys
mount --move /rom/ext_overlay /ext_overlay
mount --move /rom/overlay /overlay
sync sync
fi fi
fi fi

View File

@ -144,9 +144,9 @@ clean_overlayfs_redundant_whiteout_marker()
{ {
local line local line
cd "$1" cd "$1"
find upper ! -path 'upper/opt/*' -type c -perm 0 -user 0 -group 0 | sed 's#^upper/#/#g' | while read; do find upper -xdev -path 'upper/opt' -prune ! -type d -o -type c -perm 0 -user 0 -group 0 | sed 's#^upper/#/#g' | while read; do
line="$REPLY" line="$REPLY"
[ ! -e "$line" -a \( -z "$2" -o ! -f "$2/upper$line" \) ] && \ [ ! -e "$line" -a \( -z "$2" -o ! -e "$2/upper$line" \) ] && \
busybox ls -l "upper$line" | grep -Fq 'c--------- 1 root root 0, 0 ' && \ busybox ls -l "upper$line" | grep -Fq 'c--------- 1 root root 0, 0 ' && \
rm -f "upper$line" rm -f "upper$line"
done done
@ -158,9 +158,9 @@ clean_overlayfs_redundant_whiteout_marker_luci()
local line local line
[ -d "$1/upper/usr/lib/lua/luci" ] || return 0 [ -d "$1/upper/usr/lib/lua/luci" ] || return 0
cd "$1/upper/usr/lib/lua" cd "$1/upper/usr/lib/lua"
find luci -type c -perm 0 -user 0 -group 0 | while read; do find luci -xdev -type c -perm 0 -user 0 -group 0 | while read; do
line="$REPLY" line="$REPLY"
[ ! -e "/usr/lib/lua/$line" -a \( -z "$2" -o ! -f "$2/upper/usr/lib/lua/$line" \) ] && \ [ ! -e "/usr/lib/lua/$line" -a \( -z "$2" -o ! -e "$2/upper/usr/lib/lua/$line" \) ] && \
busybox ls -l "$line" | grep -Fq 'c--------- 1 root root 0, 0 ' && \ busybox ls -l "$line" | grep -Fq 'c--------- 1 root root 0, 0 ' && \
rm -f "$line" rm -f "$line"
done done
@ -198,7 +198,6 @@ prepare_primary_overlay()
else else
if [ -d /overlay/upper ] ; then if [ -d /overlay/upper ] ; then
if update_overlay_lower_uuid /overlay || [ -f /overlay/.upgrading ] ; then if update_overlay_lower_uuid /overlay || [ -f /overlay/.upgrading ] ; then
rm -f /overlay/upper/etc/opkg/distfeeds.conf
is_overlayfs_use_xattr && clean_overlayfs_origin /overlay/upper is_overlayfs_use_xattr && clean_overlayfs_origin /overlay/upper
clean_overlayfs_redundant_whiteout_marker /overlay clean_overlayfs_redundant_whiteout_marker /overlay
else else
@ -272,7 +271,6 @@ prepare_ext_overlay()
fi fi
# should change to $newoverlaydir/.upgrading # should change to $newoverlaydir/.upgrading
if [ -f "$newoverlaydir/upper/usr/lib/opkg/.upgrading" ]; then if [ -f "$newoverlaydir/upper/usr/lib/opkg/.upgrading" ]; then
rm -f "$newoverlaydir/upper/etc/opkg/distfeeds.conf"
is_overlayfs_use_xattr && clean_overlayfs_origin "$newoverlaydir/upper" is_overlayfs_use_xattr && clean_overlayfs_origin "$newoverlaydir/upper"
fi fi
if [ -f "$newoverlaydir/.commit" ]; then if [ -f "$newoverlaydir/.commit" ]; then
@ -342,6 +340,8 @@ prepare_mnt()
rm -f "/overlay/.sandbox" rm -f "/overlay/.sandbox"
fi fi
sync
return 0 return 0
} }

View File

@ -3,7 +3,7 @@ include $(TOPDIR)/rules.mk
LUCI_TITLE:=LuCI for OTA upgrade LUCI_TITLE:=LuCI for OTA upgrade
LUCI_PKGARCH:=all LUCI_PKGARCH:=all
PKG_VERSION:=1.3.1 PKG_VERSION:=1.4.0
PKG_RELEASE:=1 PKG_RELEASE:=1
PKG_MAINTAINER:=jjm2473 <jjm2473@gmail.com> PKG_MAINTAINER:=jjm2473 <jjm2473@gmail.com>

View File

@ -182,10 +182,13 @@
state_switch("downloading", "downloaded"); state_switch("downloading", "downloaded");
break; break;
case 1: case 1:
if (d.msg.startsWith('#')) { if (d.msg.startsWith('#') || d.msg.startsWith(' ') || d.msg.startsWith('-')) {
if (!refresh_download_progress_paused) if (!refresh_download_progress_paused)
cancel.disabled = undefined; cancel.disabled = undefined;
download_progress.innerText = "<%:Downloading%>: "+d.msg.replaceAll(/[# ]/g, ''); if (d.msg.endsWith('%'))
download_progress.innerText = "<%:Downloading%>: "+d.msg.replaceAll(/[# ]/g, '');
else
download_progress.innerText = "<%:Downloading%>";
} else { } else {
if (!refresh_download_progress_paused) if (!refresh_download_progress_paused)
cancel.disabled = 'disabled'; cancel.disabled = 'disabled';

View File

@ -1,5 +1,20 @@
#!/bin/sh #!/bin/sh
# author jjm2473 # author jjm2473
mirrors() {
local url="$1"
case "$url" in
https://fw0.koolcenter.com/iStoreOS/*|\
https://fw.koolcenter.com/iStoreOS/*)
local path=$(echo "$url" | sed -E 's#^https?://[^/]+/(.*)#\1#')
# echo "https://dl2.istoreos.com/$path"
echo "https://dl.istoreos.com/$path"
;;
esac
echo "$url"
return 0
}
if [ -f /lib/upgrade/ota.sh ]; then if [ -f /lib/upgrade/ota.sh ]; then
. /lib/upgrade/ota.sh . /lib/upgrade/ota.sh
export_ota_url export_ota_url
@ -11,6 +26,7 @@ if [ -z "$OTA_URL_BASE" ]; then
fi fi
WRLOCK=/var/lock/ota_background.lock WRLOCK=/var/lock/ota_background.lock
STLOCK=/var/lock/ota_status.lock
action=${1} action=${1}
shift shift
@ -19,42 +35,66 @@ sha256() {
sha256sum $1 | cut -d' ' -f1 sha256sum $1 | cut -d' ' -f1
} }
fcurl() { alias fcurl='curl -L --fail --show-error'
curl -L --fail --show-error "$@"
}
download() { download() {
local img=$1 local img=$1
local sum=$2 local sum=$2
exec 300>$STLOCK
flock 300
touch /tmp/firmware.img.part touch /tmp/firmware.img.part
echo >/tmp/firmware.img.progress echo >/tmp/firmware.img.progress
rm -f /tmp/firmware.img.sha256sum rm -f /tmp/firmware.img.sha256sum
flock -u 300
if [ -f /tmp/firmware.img ]; then if [ -f /tmp/firmware.img ]; then
echo "Checking existed firmware.img..." >> /tmp/firmware.img.progress echo "Checking existed firmware.img..." >> /tmp/firmware.img.progress
if [ "`sha256 /tmp/firmware.img`" = "$sum" ]; then if [ "`sha256 /tmp/firmware.img`" = "$sum" ]; then
flock 300
echo $sum > /tmp/firmware.img.sha256sum; echo $sum > /tmp/firmware.img.sha256sum;
rm -f /tmp/firmware.img.part rm -f /tmp/firmware.img.part
rm -f /tmp/firmware.img.progress rm -f /tmp/firmware.img.progress
flock -u 300
return 0; return 0;
else else
echo "Check failed, redownload" >> /tmp/firmware.img.progress echo "Check failed, redownload" >> /tmp/firmware.img.progress
rm -f /tmp/firmware.img rm -f /tmp/firmware.img
fi fi
fi fi
fcurl --connect-timeout 5 --progress-bar -o /tmp/firmware.img.part "$OTA_URL_BASE/$img" 2>/tmp/firmware.img.progress & local pid url
local pid="$!" mirrors "$OTA_URL_BASE/$img" | while read; do
echo "$pid" > /var/run/ota/download.pid url="$REPLY"
if wait $pid; then echo "Try $url" >>/tmp/firmware.img.progress
rm -f /var/run/ota/download.pid flock 300
echo "Checking new firmware.img.part..." > /tmp/firmware.img.progress echo "#=#=#" >>/tmp/firmware.img.progress
if [ "`sha256 /tmp/firmware.img.part`" = "$sum" ]; then fcurl --connect-timeout 5 --progress-bar -o /tmp/firmware.img.part "$url" 2>>/tmp/firmware.img.progress &
mv /tmp/firmware.img.part /tmp/firmware.img && echo $sum > /tmp/firmware.img.sha256sum pid="$!"
rm -f /tmp/firmware.img.progress echo "$pid" > /var/run/ota/download.pid
return 0 flock -u 300
if wait $pid; then
rm -f /var/run/ota/download.pid
echo "Checking new firmware.img.part..." > /tmp/firmware.img.progress
if [ "`sha256 /tmp/firmware.img.part`" = "$sum" ]; then
flock 300
mv /tmp/firmware.img.part /tmp/firmware.img && echo $sum > /tmp/firmware.img.sha256sum
rm -f /tmp/firmware.img.progress
flock -u 300
return 0
else
echo "Checksum failed!" >>/tmp/firmware.img.progress
fi
else else
echo "Checksum failed!" >>/tmp/firmware.img.progress # on Terminated $? == 143, on Timeout $? == 28
local ecode=$?
echo >>/tmp/firmware.img.progress
if [ $ecode -eq 143 ]; then
echo "Canceled!" >> /tmp/firmware.img.progress
break
fi
fi fi
fi flock 300
sed -i '/\r/d' /tmp/firmware.img.progress
flock -u 300
done
rm -f /var/run/ota/download.pid rm -f /var/run/ota/download.pid
rm -f /tmp/firmware.img.part rm -f /tmp/firmware.img.part
return 1 return 1
@ -139,10 +179,20 @@ do_progress() {
[ -f /tmp/firmware.img.progress ] || { echo "download not in progress" >&2 ; return 254; } [ -f /tmp/firmware.img.progress ] || { echo "download not in progress" >&2 ; return 254; }
[ -f /tmp/firmware.img.part ] && { cat /tmp/firmware.img.progress | tr '\r' '\n' | tail -n1; return 1; } [ -f /tmp/firmware.img.part ] && { cat /tmp/firmware.img.progress | tr '\r' '\n' | tail -n1; return 1; }
tail -1 /tmp/firmware.img.progress | grep -Fq 'Canceled!' && { echo "Canceled"; return 2; } tail -1 /tmp/firmware.img.progress | grep -Fq 'Canceled!' && { echo "Canceled"; return 2; }
grep -v '\r' /tmp/firmware.img.progress >&2 cat /tmp/firmware.img.progress | tr '\r' '\n' | grep -v '^$' | tail -n1 >&2
return 3 return 3
} }
do_progress_locked() {
local ret
exec 300>$STLOCK
flock -s 300
do_progress
ret=$?
flock -u 300
return $ret
}
do_cancel() { do_cancel() {
if [ -f /var/run/ota/download.pid ]; then if [ -f /var/run/ota/download.pid ]; then
local pid=`cat /var/run/ota/download.pid` local pid=`cat /var/run/ota/download.pid`
@ -153,8 +203,6 @@ do_cancel() {
break break
fi fi
done done
echo "" >> /tmp/firmware.img.progress
echo "Canceled!" >> /tmp/firmware.img.progress
fi fi
fi fi
return 0 return 0
@ -183,7 +231,7 @@ case $action in
do_download do_download
;; ;;
"progress") "progress")
do_progress do_progress_locked
;; ;;
"cancel") "cancel")
do_cancel do_cancel

View File

@ -8,7 +8,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=rpcd PKG_NAME:=rpcd
PKG_RELEASE:=2 PKG_RELEASE:=3
PKG_SOURCE_PROTO:=git PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL=$(PROJECT_GIT)/project/rpcd.git PKG_SOURCE_URL=$(PROJECT_GIT)/project/rpcd.git

View File

@ -0,0 +1,119 @@
From 9047361575e7219f46665637180ce4a9012006ab Mon Sep 17 00:00:00 2001
From: Liangbin Lian <jjm2473@gmail.com>
Date: Fri, 14 Jun 2024 14:19:24 +0800
Subject: [PATCH] uci: recovery from a failed uci commit
---
uci.c | 50 +++++++++++++++++++++++++++++++++++++-------------
1 file changed, 37 insertions(+), 13 deletions(-)
diff --git a/uci.c b/uci.c
index 3cd2b82..d4ea103 100644
--- a/uci.c
+++ b/uci.c
@@ -1320,11 +1320,13 @@ rpc_uci_trigger_event(struct ubus_context *ctx, const char *config)
free(pkg);
}
+static int
+rpc_uci_apply_config(struct ubus_context *ctx, const char *config);
+
static int
rpc_uci_revert_commit(struct ubus_context *ctx, struct blob_attr *msg, bool commit)
{
struct blob_attr *tb[__RPC_C_MAX];
- struct uci_package *p = NULL;
struct uci_ptr ptr = { 0 };
if (apply_sid[0])
@@ -1343,12 +1345,7 @@ rpc_uci_revert_commit(struct ubus_context *ctx, struct blob_attr *msg, bool comm
if (commit)
{
- if (!uci_load(cursor, ptr.package, &p))
- {
- uci_commit(cursor, &p, false);
- uci_unload(cursor, p);
- rpc_uci_trigger_event(ctx, blobmsg_get_string(tb[RPC_C_CONFIG]));
- }
+ rpc_uci_apply_config(ctx, ptr.package);
}
else
{
@@ -1441,17 +1438,19 @@ rpc_uci_purge_dir(const char *path)
}
static int
-rpc_uci_apply_config(struct ubus_context *ctx, char *config)
+rpc_uci_apply_config(struct ubus_context *ctx, const char *config)
{
struct uci_package *p = NULL;
+ int ret = 0;
if (!uci_load(cursor, config, &p)) {
- uci_commit(cursor, &p, false);
+ ret = uci_commit(cursor, &p, false);
uci_unload(cursor, p);
}
- rpc_uci_trigger_event(ctx, config);
+ if (!ret)
+ rpc_uci_trigger_event(ctx, config);
- return 0;
+ return ret;
}
static void
@@ -1531,7 +1530,7 @@ rpc_uci_do_rollback(struct ubus_context *ctx, glob_t *gl)
continue;
rpc_uci_copy_file(RPC_SNAPSHOT_FILES, RPC_UCI_DIR, config);
- rpc_uci_apply_config(ctx, config);
+ rpc_uci_trigger_event(ctx, config);
if (deny)
continue;
@@ -1547,6 +1546,25 @@ rpc_uci_do_rollback(struct ubus_context *ctx, glob_t *gl)
apply_ctx = NULL;
}
+static void
+rpc_uci_do_rollback_im(struct ubus_context *ctx, glob_t *gl, int end) {
+ int i;
+ char tmp[PATH_MAX];
+ for (i = end; i >= 0; i--) {
+ char *config = basename(gl->gl_pathv[i]);
+
+ if (*config == '.')
+ continue;
+
+ rpc_uci_copy_file(RPC_SNAPSHOT_FILES, RPC_UCI_DIR, config);
+ rpc_uci_trigger_event(ctx, config);
+
+ rpc_uci_copy_file(RPC_SNAPSHOT_DELTA, tmp, config);
+ }
+ rpc_uci_purge_dir(RPC_SNAPSHOT_FILES);
+ rpc_uci_purge_dir(RPC_SNAPSHOT_DELTA);
+}
+
static void
rpc_uci_apply_timeout(struct uloop_timeout *t)
{
@@ -1629,7 +1647,13 @@ rpc_uci_apply(struct ubus_context *ctx, struct ubus_object *obj,
rpc_uci_copy_file(RPC_UCI_DIR, RPC_SNAPSHOT_FILES, config);
rpc_uci_copy_file(tmp, RPC_SNAPSHOT_DELTA, config);
- rpc_uci_apply_config(ctx, config);
+ ret = rpc_uci_apply_config(ctx, config);
+ if (ret) {
+ rpc_uci_do_rollback_im(ctx, &gl, i - 1);
+ apply_sid[0] = 0;
+ globfree(&gl);
+ return UBUS_STATUS_UNKNOWN_ERROR;
+ }
}
globfree(&gl);
--
2.41.0

View File

@ -9,7 +9,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=uci PKG_NAME:=uci
PKG_RELEASE:=5 PKG_RELEASE:=6
PKG_SOURCE_URL=$(PROJECT_GIT)/project/uci.git PKG_SOURCE_URL=$(PROJECT_GIT)/project/uci.git
PKG_SOURCE_PROTO:=git PKG_SOURCE_PROTO:=git

View File

@ -0,0 +1,97 @@
From 237d5542986ddb00733e172e638339544058d2d8 Mon Sep 17 00:00:00 2001
From: Liangbin Lian <jjm2473@gmail.com>
Date: Thu, 6 Jun 2024 15:42:11 +0800
Subject: [PATCH] file: don't save broken uci config
Signed-off-by: Liangbin Lian <jjm2473@gmail.com>
---
file.c | 32 +++++++++++++++++++++++---------
1 file changed, 23 insertions(+), 9 deletions(-)
diff --git a/file.c b/file.c
index 93abfae..5c942b8 100644
--- a/file.c
+++ b/file.c
@@ -607,7 +607,7 @@ static const char *uci_escape(struct uci_context *ctx, const char *str)
/*
* export a single config package to a file stream
*/
-static void uci_export_package(struct uci_package *p, FILE *stream, bool header)
+static int uci_export_package(struct uci_package *p, FILE *stream, bool header)
{
struct uci_context *ctx = p->ctx;
struct uci_element *s, *o, *i;
@@ -639,7 +639,8 @@ static void uci_export_package(struct uci_package *p, FILE *stream, bool header)
}
}
}
- fprintf(stream, "\n");
+ /* return last fprintf to check 'No space left on device' error */
+ return fprintf(stream, "\n");
}
int uci_export(struct uci_context *ctx, FILE *stream, struct uci_package *package, bool header)
@@ -649,11 +650,15 @@ int uci_export(struct uci_context *ctx, FILE *stream, struct uci_package *packag
UCI_HANDLE_ERR(ctx);
UCI_ASSERT(ctx, stream != NULL);
- if (package)
- uci_export_package(package, stream, header);
- else {
+ if (package) {
+ if (uci_export_package(package, stream, header) < 0) {
+ return UCI_ERR_IO;
+ }
+ } else {
uci_foreach_element(&ctx->root, e) {
- uci_export_package(uci_to_package(e), stream, header);
+ if (uci_export_package(uci_to_package(e), stream, header) < 0) {
+ return UCI_ERR_IO;
+ }
}
}
@@ -739,6 +744,7 @@ static void uci_file_commit(struct uci_context *ctx, struct uci_package **packag
char *filename = NULL;
struct stat statbuf;
volatile bool do_rename = false;
+ volatile bool clean_temp = false;
int fd, sz;
if (!p->path) {
@@ -800,14 +806,19 @@ static void uci_file_commit(struct uci_context *ctx, struct uci_package **packag
if (!f2)
UCI_THROW(ctx, UCI_ERR_IO);
- uci_export(ctx, f2, p, false);
+ clean_temp = true;
+ if (uci_export(ctx, f2, p, false))
+ goto no_space;
- fflush(f2);
+ if (fflush(f2))
+ goto no_space;
fsync(fileno(f2));
- uci_close_stream(f2);
do_rename = true;
+no_space:
+ uci_close_stream(f2);
+
UCI_TRAP_RESTORE(ctx);
done:
@@ -821,6 +832,9 @@ done:
UCI_THROW(ctx, UCI_ERR_IO);
}
free(path);
+ } else if (clean_temp) {
+ unlink(filename);
+ UCI_THROW(ctx, UCI_ERR_IO);
}
if (ctx->err)
UCI_THROW(ctx, ctx->err);
--
2.41.0

View File

@ -0,0 +1,46 @@
From 17586039934498210dc0a10bbe5a21cc042cdcd2 Mon Sep 17 00:00:00 2001
From: Liangbin Lian <jjm2473@gmail.com>
Date: Thu, 6 Jun 2024 15:42:46 +0800
Subject: [PATCH] file: flush delta only after successful save
Signed-off-by: Liangbin Lian <jjm2473@gmail.com>
---
file.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/file.c b/file.c
index 5c942b8..a6f30fe 100644
--- a/file.c
+++ b/file.c
@@ -787,8 +787,8 @@ static void uci_file_commit(struct uci_context *ctx, struct uci_package **packag
path = NULL;
}
- /* flush delta */
- if (!uci_load_delta(ctx, p, true))
+ /* flush delta after successful save */
+ if (!uci_load_delta(ctx, p, false))
goto done;
}
@@ -830,6 +830,17 @@ done:
if (!path || stat(path, &statbuf) || chmod(filename, statbuf.st_mode) || rename(filename, path)) {
unlink(filename);
UCI_THROW(ctx, UCI_ERR_IO);
+ } else if (p->has_delta) {
+ /* flush delta */
+ filename = NULL;
+ if ((asprintf(&filename, "%s/%s", ctx->savedir, p->e.name) < 0) || !filename)
+ UCI_THROW(ctx, UCI_ERR_MEM);
+ f1 = uci_open_stream(ctx, filename, NULL, SEEK_SET, true, false);
+ if (f1) {
+ ftruncate(fileno(f1), 0);
+ uci_close_stream(f1);
+ }
+ free(filename);
}
free(path);
} else if (clean_temp) {
--
2.41.0

View File

@ -93,3 +93,15 @@ platform_do_upgrade() {
echo "Writing new UUID to /dev/$diskdev..." echo "Writing new UUID to /dev/$diskdev..."
get_image "$@" | dd of="/dev/$diskdev" bs=1 skip=440 count=4 seek=440 conv=fsync get_image "$@" | dd of="/dev/$diskdev" bs=1 skip=440 count=4 seek=440 conv=fsync
} }
platform_copy_config() {
local partdev
if export_partdevice partdev 1; then
mkdir -p /boot
[ -f /boot/kernel.img ] || mount -t vfat -o rw,noatime "/dev/$partdev" /boot
tar -C / -zxvf "$UPGRADE_BACKUP" boot/cmdline.txt boot/config.txt
sync
umount /boot
fi
}

View File

@ -670,8 +670,6 @@ CONFIG_OLD_SIGSUSPEND3=y
CONFIG_OPTEE=y CONFIG_OPTEE=y
CONFIG_OPTEE_SHM_NUM_PRIV_PAGES=1 CONFIG_OPTEE_SHM_NUM_PRIV_PAGES=1
# CONFIG_OPTIMIZE_INLINING is not set # CONFIG_OPTIMIZE_INLINING is not set
CONFIG_OVERLAY_FS_INDEX=y
CONFIG_OVERLAY_FS_NFS_EXPORT=y
# CONFIG_PANIC_ON_OOPS is not set # CONFIG_PANIC_ON_OOPS is not set
CONFIG_PANIC_ON_OOPS_VALUE=0 CONFIG_PANIC_ON_OOPS_VALUE=0
CONFIG_PANIC_TIMEOUT=0 CONFIG_PANIC_TIMEOUT=0