mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 06/42] state: merge backend.c into state.c
Date: Fri, 31 Mar 2017 09:03:10 +0200	[thread overview]
Message-ID: <20170331070346.26878-7-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20170331070346.26878-1-s.hauer@pengutronix.de>

The code in backend.c is too small to justify an extra file. Merge it
into state.c.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/state/Makefile  |   1 -
 common/state/backend.c | 183 -------------------------------------------------
 common/state/state.c   | 161 +++++++++++++++++++++++++++++++++++++++++++
 common/state/state.h   |   6 --
 4 files changed, 161 insertions(+), 190 deletions(-)
 delete mode 100644 common/state/backend.c

diff --git a/common/state/Makefile b/common/state/Makefile
index 3e0e2c6e55..d3518feab4 100644
--- a/common/state/Makefile
+++ b/common/state/Makefile
@@ -1,6 +1,5 @@
 obj-y += state.o
 obj-y += state_variables.o
-obj-y += backend.o
 obj-y += backend_format_dtb.o
 obj-y += backend_format_raw.o
 obj-y += backend_storage.o
diff --git a/common/state/backend.c b/common/state/backend.c
deleted file mode 100644
index 1773392e8d..0000000000
--- a/common/state/backend.c
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * Copyright (C) 2016 Pengutronix, Markus Pargmann <mpa@pengutronix.de>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- */
-
-#include <linux/kernel.h>
-#include <linux/list.h>
-#include <linux/string.h>
-#include <malloc.h>
-#include <printk.h>
-
-#include "state.h"
-
-
-/**
- * Save the state
- * @param state
- * @return
- */
-int state_save(struct state *state)
-{
-	uint8_t *buf;
-	ssize_t len;
-	int ret;
-
-	if (!state->dirty)
-		return 0;
-
-	ret = state->format->pack(state->format, state, &buf, &len);
-	if (ret) {
-		dev_err(&state->dev, "Failed to pack state with backend format %s, %d\n",
-			state->format->name, ret);
-		return ret;
-	}
-
-	ret = state_storage_write(&state->storage, buf, len);
-	if (ret) {
-		dev_err(&state->dev, "Failed to write packed state, %d\n", ret);
-		goto out;
-	}
-
-	state->dirty = 0;
-
-out:
-	free(buf);
-	return ret;
-}
-
-/**
- * state_load - Loads a state from the backend
- * @param state The state that should be updated to contain the loaded data
- * @return 0 on success, -errno on failure. If no state is loaded the previous
- * values remain in the state.
- *
- * This function uses the registered storage backend to read data. All data that
- * we read is checked for integrity by the formatter. After that we unpack the
- * data into our state.
- */
-int state_load(struct state *state)
-{
-	uint8_t *buf;
-	ssize_t len;
-	int ret;
-
-	ret = state_storage_read(&state->storage, state->format,
-				 state->magic, &buf, &len);
-	if (ret) {
-		dev_err(&state->dev, "Failed to read state with format %s, %d\n",
-			state->format->name, ret);
-		return ret;
-	}
-
-	ret = state->format->unpack(state->format, state, buf, len);
-	if (ret) {
-		dev_err(&state->dev, "Failed to unpack read data with format %s although verified, %d\n",
-			state->format->name, ret);
-		goto out;
-	}
-
-	state->dirty = 0;
-
-out:
-	free(buf);
-	return ret;
-}
-
-static int state_format_init(struct state *state,
-			     struct device_d *dev, const char *backend_format,
-			     struct device_node *node, const char *state_name)
-{
-	int ret;
-
-	if (!strcmp(backend_format, "raw")) {
-		ret = backend_format_raw_create(&state->format, node,
-						state_name, dev);
-	} else if (!strcmp(backend_format, "dtb")) {
-		ret = backend_format_dtb_create(&state->format, dev);
-	} else {
-		dev_err(dev, "Invalid backend format %s\n",
-			backend_format);
-		return -EINVAL;
-	}
-
-	if (ret && ret != -EPROBE_DEFER)
-		dev_err(dev, "Failed to initialize format %s, %d\n",
-			backend_format, ret);
-
-	return ret;
-}
-
-static void state_format_free(struct state_backend_format *format)
-{
-	if (format->free)
-		format->free(format);
-}
-
-/**
- * state_backend_init - Initiates the backend storage and format using the
- * passed arguments
- * @param backend state backend
- * @param dev Device pointer used for prints
- * @param node the DT device node corresponding to the state
- * @param backend_format a string describing the format. Valid values are 'raw'
- * and 'dtb' currently
- * @param storage_path Path to the backend storage file/device/partition/...
- * @param state_name Name of the state
- * @param of_path Path in the devicetree
- * @param stridesize stridesize in case we have a medium without eraseblocks.
- * stridesize describes how far apart copies of the same data should be stored.
- * For blockdevices it makes sense to align them on blocksize.
- * @param storagetype Type of the storage backend. This may be NULL where we
- * autoselect some backwardscompatible backend options
- * @return 0 on success, -errno otherwise
- */
-int state_backend_init(struct state *state, struct device_d *dev,
-		       struct device_node *node, const char *backend_format,
-		       const char *storage_path, const char *state_name, const
-		       char *of_path, off_t offset, size_t max_size,
-		       uint32_t stridesize, const char *storagetype)
-{
-	int ret;
-
-	ret = state_format_init(state, dev, backend_format, node, state_name);
-	if (ret)
-		return ret;
-
-	ret = state_storage_init(&state->storage, dev, storage_path, offset,
-				 max_size, stridesize, storagetype);
-	if (ret)
-		goto out_free_format;
-
-	state->of_backend_path = xstrdup(of_path);
-
-	return 0;
-
-out_free_format:
-	state_format_free(state->format);
-	state->format = NULL;
-
-	return ret;
-}
-
-void state_backend_set_readonly(struct state *state)
-{
-	state_storage_set_readonly(&state->storage);
-}
-
-void state_backend_free(struct state *state)
-{
-	state_storage_free(&state->storage);
-	if (state->format)
-		state_format_free(state->format);
-	free(state->of_path);
-}
diff --git a/common/state/state.c b/common/state/state.c
index 62357fb248..570fa498c5 100644
--- a/common/state/state.c
+++ b/common/state/state.c
@@ -34,6 +34,167 @@
 /* list of all registered state instances */
 static LIST_HEAD(state_list);
 
+/**
+ * Save the state
+ * @param state
+ * @return
+ */
+int state_save(struct state *state)
+{
+	uint8_t *buf;
+	ssize_t len;
+	int ret;
+
+	if (!state->dirty)
+		return 0;
+
+	ret = state->format->pack(state->format, state, &buf, &len);
+	if (ret) {
+		dev_err(&state->dev, "Failed to pack state with backend format %s, %d\n",
+			state->format->name, ret);
+		return ret;
+	}
+
+	ret = state_storage_write(&state->storage, buf, len);
+	if (ret) {
+		dev_err(&state->dev, "Failed to write packed state, %d\n", ret);
+		goto out;
+	}
+
+	state->dirty = 0;
+
+out:
+	free(buf);
+	return ret;
+}
+
+/**
+ * state_load - Loads a state from the backend
+ * @param state The state that should be updated to contain the loaded data
+ * @return 0 on success, -errno on failure. If no state is loaded the previous
+ * values remain in the state.
+ *
+ * This function uses the registered storage backend to read data. All data that
+ * we read is checked for integrity by the formatter. After that we unpack the
+ * data into our state.
+ */
+int state_load(struct state *state)
+{
+	uint8_t *buf;
+	ssize_t len;
+	int ret;
+
+	ret = state_storage_read(&state->storage, state->format,
+				 state->magic, &buf, &len);
+	if (ret) {
+		dev_err(&state->dev, "Failed to read state with format %s, %d\n",
+			state->format->name, ret);
+		return ret;
+	}
+
+	ret = state->format->unpack(state->format, state, buf, len);
+	if (ret) {
+		dev_err(&state->dev, "Failed to unpack read data with format %s although verified, %d\n",
+			state->format->name, ret);
+		goto out;
+	}
+
+	state->dirty = 0;
+
+out:
+	free(buf);
+	return ret;
+}
+
+static int state_format_init(struct state *state,
+			     struct device_d *dev, const char *backend_format,
+			     struct device_node *node, const char *state_name)
+{
+	int ret;
+
+	if (!backend_format || !strcmp(backend_format, "raw")) {
+		ret = backend_format_raw_create(&state->format, node,
+						state_name, dev);
+	} else if (!strcmp(backend_format, "dtb")) {
+		ret = backend_format_dtb_create(&state->format, dev);
+	} else {
+		dev_err(dev, "Invalid backend format %s\n",
+			backend_format);
+		return -EINVAL;
+	}
+
+	if (ret && ret != -EPROBE_DEFER)
+		dev_err(dev, "Failed to initialize format %s, %d\n",
+			backend_format, ret);
+
+	return ret;
+}
+
+static void state_format_free(struct state_backend_format *format)
+{
+	if (format->free)
+		format->free(format);
+}
+
+/**
+ * state_backend_init - Initiates the backend storage and format using the
+ * passed arguments
+ * @param backend state backend
+ * @param dev Device pointer used for prints
+ * @param node the DT device node corresponding to the state
+ * @param backend_format a string describing the format. Valid values are 'raw'
+ * and 'dtb' currently
+ * @param storage_path Path to the backend storage file/device/partition/...
+ * @param state_name Name of the state
+ * @param of_path Path in the devicetree
+ * @param stridesize stridesize in case we have a medium without eraseblocks.
+ * stridesize describes how far apart copies of the same data should be stored.
+ * For blockdevices it makes sense to align them on blocksize.
+ * @param storagetype Type of the storage backend. This may be NULL where we
+ * autoselect some backwardscompatible backend options
+ * @return 0 on success, -errno otherwise
+ */
+static int state_backend_init(struct state *state, struct device_d *dev,
+		       struct device_node *node, const char *backend_format,
+		       const char *storage_path, const char *state_name, const
+		       char *of_path, off_t offset, size_t max_size,
+		       uint32_t stridesize, const char *storagetype)
+{
+	int ret;
+
+	ret = state_format_init(state, dev, backend_format, node, state_name);
+	if (ret)
+		return ret;
+
+	ret = state_storage_init(&state->storage, dev, storage_path, offset,
+				 max_size, stridesize, storagetype);
+	if (ret)
+		goto out_free_format;
+
+	state->of_backend_path = xstrdup(of_path);
+
+	return 0;
+
+out_free_format:
+	state_format_free(state->format);
+	state->format = NULL;
+
+	return ret;
+}
+
+void state_backend_set_readonly(struct state *state)
+{
+	state_storage_set_readonly(&state->storage);
+}
+
+void state_backend_free(struct state *state)
+{
+	state_storage_free(&state->storage);
+	if (state->format)
+		state_format_free(state->format);
+	free(state->of_path);
+}
+
 static struct state *state_new(const char *name)
 {
 	struct state *state;
diff --git a/common/state/state.h b/common/state/state.h
index cb248fc609..254ff31a06 100644
--- a/common/state/state.h
+++ b/common/state/state.h
@@ -205,13 +205,7 @@ int state_backend_bucket_cached_create(struct device_d *dev,
 struct state_variable *state_find_var(struct state *state, const char *name);
 struct digest *state_backend_format_raw_get_digest(struct state_backend_format
 						   *format);
-int state_backend_init(struct state *state, struct device_d *dev,
-		       struct device_node *node, const char *backend_format,
-		       const char *storage_path, const char *state_name, const
-		       char *of_path, off_t offset, size_t max_size,
-		       uint32_t stridesize, const char *storagetype);
 void state_backend_set_readonly(struct state *state);
-void state_backend_free(struct state *state);
 void state_storage_free(struct state_backend_storage *storage);
 int state_backend_bucket_direct_create(struct device_d *dev, const char *path,
 				       struct state_backend_storage_bucket **bucket,
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2017-03-31  7:04 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-31  7:03 State patches Sascha Hauer
2017-03-31  7:03 ` [PATCH 01/42] state: Make pointing to the backend using a phandle the only supported method Sascha Hauer
2017-05-15  9:18   ` Jan Remmet
2017-05-15 10:14     ` Jan Remmet
2017-05-16  5:33       ` Sascha Hauer
2017-05-17  9:13         ` Jan Remmet
2017-03-31  7:03 ` [PATCH 02/42] state: Use positive logic Sascha Hauer
2017-03-31  7:03 ` [PATCH 03/42] state: backend: remove .get_packed_len Sascha Hauer
2017-03-31  7:03 ` [PATCH 04/42] state: backend: remove len_hint argument from state_storage_read Sascha Hauer
2017-03-31  7:03 ` [PATCH 05/42] state: Drop backend as extra struct type Sascha Hauer
2017-03-31  7:03 ` Sascha Hauer [this message]
2017-03-31  7:03 ` [PATCH 07/42] state: open code state_backend_init in caller Sascha Hauer
2017-03-31  7:03 ` [PATCH 08/42] state: remove unnecessary argument from state_format_init Sascha Hauer
2017-03-31  7:03 ` [PATCH 09/42] state: pass struct state * to storage functions Sascha Hauer
2017-03-31  7:03 ` [PATCH 10/42] state: storage: initialize variable once outside loop Sascha Hauer
2017-03-31  7:03 ` [PATCH 11/42] state: backend_circular: Read whole PEB Sascha Hauer
2017-04-15  8:40   ` Sam Ravnborg
2017-03-31  7:03 ` [PATCH 12/42] state: drop lazy_init Sascha Hauer
2017-03-31  7:03 ` [PATCH 13/42] state: simplify direct backend Sascha Hauer
2017-03-31  7:03 ` [PATCH 14/42] state: replace len_hint logic Sascha Hauer
2017-03-31  7:03 ` [PATCH 15/42] state: Convert all bufs to void * Sascha Hauer
2017-03-31  7:03 ` [PATCH 16/42] state: Drop cache bucket Sascha Hauer
2017-04-15  8:53   ` Sam Ravnborg
2017-04-19  8:22     ` Sascha Hauer
2017-03-31  7:03 ` [PATCH 17/42] state: backend-direct: Fix max_size Sascha Hauer
2017-03-31  7:03 ` [PATCH 18/42] state: bucket: Make output more informative Sascha Hauer
2017-03-31  7:03 ` [PATCH 19/42] state: backend_bucket_direct: max_size is always given Sascha Hauer
2017-03-31  7:03 ` [PATCH 20/42] state: backend: Add more fields to struct state_backend_storage Sascha Hauer
2017-03-31  7:03 ` [PATCH 21/42] state: backend_circular: remove unnecessary warning Sascha Hauer
2017-03-31  7:03 ` [PATCH 22/42] state: storage: direct: do not close file that is not opened Sascha Hauer
2017-03-31  7:03 ` [PATCH 23/42] state: backend: Add some documentation Sascha Hauer
2017-03-31  7:03 ` [PATCH 24/42] state: backend_circular: default to circular storage Sascha Hauer
2017-03-31  7:03 ` [PATCH 25/42] state: backend_circular: rewrite function doc Sascha Hauer
2017-03-31  7:03 ` [PATCH 26/42] state: backend_storage: Rename variable nr_copies to n_buckets Sascha Hauer
2017-03-31  7:03 ` [PATCH 27/42] state: backend_storage: Rename variable desired_copies to desired_buckets Sascha Hauer
2017-03-31  7:03 ` [PATCH 28/42] state: backend_storage: rewrite function doc Sascha Hauer
2017-03-31  7:03 ` [PATCH 29/42] state: backend_storage: make locally used variable static Sascha Hauer
2017-03-31  7:03 ` [PATCH 30/42] state: backend_storage: rename more variables Sascha Hauer
2017-03-31  7:03 ` [PATCH 31/42] keystore: implement forgetting secrets Sascha Hauer
2017-03-31  7:03 ` [PATCH 32/42] commands: implement keystore command Sascha Hauer
2017-03-31  7:03 ` [PATCH 33/42] commands: state: allow loading state with -l Sascha Hauer
2017-03-31  7:03 ` [PATCH 34/42] crypto: digest: initialize earlier Sascha Hauer
2017-03-31  7:03 ` [PATCH 35/42] state: backend_raw: alloc digest only when needed Sascha Hauer
2017-03-31  7:03 ` [PATCH 36/42] state: backend_circular: Set minumum writesize to 8 Sascha Hauer
2017-03-31  7:03 ` [PATCH 37/42] state: backend bucket circular: Explain metadata Sascha Hauer
2017-03-31  7:03 ` [PATCH 38/42] state: Allow to load without authentification Sascha Hauer
2017-03-31  7:03 ` [PATCH 39/42] state: Update documentation Sascha Hauer
2017-03-31  7:03 ` [PATCH 40/42] state: Do not load state during state_new_from_node Sascha Hauer
2017-03-31  7:03 ` [PATCH 41/42] state: Remove -EUCLEAN check from userspace tool Sascha Hauer
2017-03-31  7:03 ` [PATCH 42/42] state: find device node from device path, not from device node path Sascha Hauer
2017-04-03 20:15 ` State patches Sam Ravnborg
2017-04-04  6:19   ` Sascha Hauer

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=20170331070346.26878-7-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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