summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlrich Ölmann <u.oelmann@pengutronix.de>2019-09-30 09:26:08 +0200
committerRoland Hieber <rhi@pengutronix.de>2019-10-11 16:49:39 +0200
commit2dbca4c3284b283b9d191a423a127b0d9402a55d (patch)
tree0d42c8ba38ce5aae69454cb28516ee940d5e7954
parentbaee943b2c98155349e5f0fef5c23c76b695e90f (diff)
downloaddt-utils-2dbca4c3284b283b9d191a423a127b0d9402a55d.tar.gz
dt-utils-2dbca4c3284b283b9d191a423a127b0d9402a55d.tar.xz
state: keep backward compatibility
Introduce the new build time option '--enable-state-backward-compatibility' to port the following barebox commit. NOTE: This changes barebox-state's default behaviour. | commit 480cde1b22831febacc2a8ab91dfe99d2e5be8e9 | Author: Juergen Borleis <jbe@pengutronix.de> | Date: Tue Aug 15 15:46:31 2017 +0200 | | state: keep backward compatibility | | Previous 'state' variable set variants do not know and use metadata. The | 'direct' storage backend's read function honors this, but not its | counterpart the write function. This makes an update of the 'state' | variable set impossible. | This change makes backward compatibility explicit, else it complains in | the read function as well. With some more debug output it helps the | developer to do things right. | | Signed-off-by: Juergen Borleis <jbe@pengutronix.de> | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de>
-rw-r--r--configure.ac28
-rw-r--r--src/barebox-state.c2
-rw-r--r--src/barebox-state/backend_bucket_direct.c28
3 files changed, 40 insertions, 18 deletions
diff --git a/configure.ac b/configure.ac
index 777f495..04c2226 100644
--- a/configure.ac
+++ b/configure.ac
@@ -32,6 +32,15 @@ AS_IF([test "x$enable_debug" = "xyes"], [
AC_DEFINE(DEBUG, [1], [Debug messages.])
])
+AC_ARG_ENABLE([state-backward-compatibility],
+ AS_HELP_STRING([--enable-state-backward-compatibility], [keep the 'direct' storage backend backward compatible @<:@default=disabled@:>@]),
+ [], [enable_state_backward_compatibility=no])
+AS_IF([test "x${enable_state_backward_compatibility}" = "xyes"], [
+ AC_DEFINE(CONFIG_STATE_BACKWARD_COMPATIBLE, [1], ['direct' storage backend backward compatibility.])
+], [
+ AC_DEFINE(CONFIG_STATE_BACKWARD_COMPATIBLE, [0])
+])
+
AC_CHECK_FUNCS([__secure_getenv secure_getenv])
my_CFLAGS="-Wall \
@@ -53,15 +62,16 @@ AC_MSG_RESULT([
$PACKAGE $VERSION
=====
- prefix: ${prefix}
- sysconfdir: ${sysconfdir}
- libdir: ${libdir}
- includedir: ${includedir}
+ prefix: ${prefix}
+ sysconfdir: ${sysconfdir}
+ libdir: ${libdir}
+ includedir: ${includedir}
- compiler: ${CC}
- cflags: ${CFLAGS}
- ldflags: ${LDFLAGS}
+ compiler: ${CC}
+ cflags: ${CFLAGS}
+ ldflags: ${LDFLAGS}
- logging: ${enable_logging}
- debug: ${enable_debug}
+ logging: ${enable_logging}
+ debug: ${enable_debug}
+ state-backward-compatibility: ${enable_state_backward_compatibility}
])
diff --git a/src/barebox-state.c b/src/barebox-state.c
index 946a8db..6b166bf 100644
--- a/src/barebox-state.c
+++ b/src/barebox-state.c
@@ -439,6 +439,8 @@ int main(int argc, char *argv[])
exit(0);
case OPT_VERSION:
printf(PACKAGE_STRING "\n");
+ printf("Configured with build-time option '--%s-state-backward-compatibility'.\n",
+ (CONFIG_STATE_BACKWARD_COMPATIBLE) ? "enable" : "disable");
exit(0);
case 'g':
sg = xzalloc(sizeof(*sg));
diff --git a/src/barebox-state/backend_bucket_direct.c b/src/barebox-state/backend_bucket_direct.c
index 5b5506b..4522f01 100644
--- a/src/barebox-state/backend_bucket_direct.c
+++ b/src/barebox-state/backend_bucket_direct.c
@@ -75,6 +75,11 @@ static int state_backend_bucket_direct_read(struct state_backend_storage_bucket
} else {
if (meta.magic != ~0 && !!meta.magic)
bucket->wrong_magic = 1;
+ if (!IS_ENABLED(CONFIG_STATE_BACKWARD_COMPATIBLE)) {
+ dev_err(direct->dev, "No meta data header found\n");
+ dev_dbg(direct->dev, "Enable backward compatibility or increase stride size\n");
+ return -EINVAL;
+ }
read_len = direct->max_size;
if (lseek(direct->fd, direct->offset, SEEK_SET) !=
direct->offset) {
@@ -110,20 +115,25 @@ static int state_backend_bucket_direct_write(struct state_backend_storage_bucket
int ret;
struct state_backend_storage_bucket_direct_meta meta;
- if (len > direct->max_size - sizeof(meta))
- return -E2BIG;
-
if (lseek(direct->fd, direct->offset, SEEK_SET) != direct->offset) {
dev_err(direct->dev, "Failed to seek file, %d\n", -errno);
return -errno;
}
- meta.magic = direct_magic;
- meta.written_length = len;
- ret = write_full(direct->fd, &meta, sizeof(meta));
- if (ret < 0) {
- dev_err(direct->dev, "Failed to write metadata to file, %d\n", ret);
- return ret;
+ /* write the meta data only if there is head room */
+ if (len <= direct->max_size - sizeof(meta)) {
+ meta.magic = direct_magic;
+ meta.written_length = len;
+ ret = write_full(direct->fd, &meta, sizeof(meta));
+ if (ret < 0) {
+ dev_err(direct->dev, "Failed to write metadata to file, %d\n", ret);
+ return ret;
+ }
+ } else {
+ if (!IS_ENABLED(CONFIG_STATE_BACKWARD_COMPATIBLE)) {
+ dev_dbg(direct->dev, "Too small stride size: must skip metadata! Increase stride size\n");
+ return -EINVAL;
+ }
}
ret = write_full(direct->fd, buf, len);