mailarchive of the pengutronix oss-tools mailing list
 help / color / mirror / Atom feed
From: "Ulrich Ölmann" <u.oelmann@pengutronix.de>
To: Pengutronix Public Open-Source-Development <oss-tools@pengutronix.de>
Cc: "Ulrich Ölmann" <u.oelmann@pengutronix.de>
Subject: [OSS-Tools] [PATCH dt-utils 08/13] state: keep backward compatibility
Date: Mon, 30 Sep 2019 09:26:08 +0200	[thread overview]
Message-ID: <20190930072613.17956-9-u.oelmann@pengutronix.de> (raw)
In-Reply-To: <20190930072613.17956-1-u.oelmann@pengutronix.de>

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>
---
 configure.ac                              | 28 +++++++++++++++--------
 src/barebox-state.c                       |  2 ++
 src/barebox-state/backend_bucket_direct.c | 28 +++++++++++++++--------
 3 files changed, 40 insertions(+), 18 deletions(-)

diff --git a/configure.ac b/configure.ac
index 777f4956ba5f..04c2226625c1 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 946a8dba6d8c..6b166bfe6e02 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 5b5506be002e..4522f0170f3d 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);
-- 
2.23.0


_______________________________________________
OSS-Tools mailing list
OSS-Tools@pengutronix.de

  parent reply	other threads:[~2019-09-30  7:26 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-30  7:26 [OSS-Tools] [PATCH dt-utils 00/13] Harmonize dt-utils' and barebox' shared code base Ulrich Ölmann
2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 01/13] state: Fix lseek error check in state_backend_bucket_direct_read() Ulrich Ölmann
2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 02/13] state: Fix lseek error check in state_backend_bucket_direct_write() Ulrich Ölmann
2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 03/13] state: Fix lseek error check in state_mtd_peb_read() Ulrich Ölmann
2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 04/13] state: Fix lseek error check in state_mtd_peb_write() Ulrich Ölmann
2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 05/13] state: check length Ulrich Ölmann
2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 06/13] state: backend_bucket_circular: mark block as bad if mtd_peb_torture() failed Ulrich Ölmann
2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 07/13] state: drop unused code and declarations for non-existing functions Ulrich Ölmann
2019-09-30  7:26 ` Ulrich Ölmann [this message]
2019-10-22  9:46   ` [OSS-Tools] [PATCH dt-utils 08/13] state: keep backward compatibility Roland Hieber
2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 09/13] state: backend_storage: harmonize code with barebox Ulrich Ölmann
2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 10/13] state: " Ulrich Ölmann
2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 11/13] " Ulrich Ölmann
2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 12/13] configure: remove build time option '--disable-logging' Ulrich Ölmann
2019-09-30  7:26 ` [OSS-Tools] [PATCH dt-utils 13/13] configure: remove build time option '--enable-debug' Ulrich Ölmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190930072613.17956-9-u.oelmann@pengutronix.de \
    --to=u.oelmann@pengutronix.de \
    --cc=oss-tools@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox