summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2017-03-22 16:16:26 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2017-03-31 13:57:46 +0200
commit5079c67e049039f3b6f7e94b4b020f8032b5108e (patch)
treed340571dd8f6edfe2df87cbf0c7a8e31898c6891
parenteee08770763c327385650c8b7b343dcc590875d0 (diff)
downloaddt-utils-5079c67e049039f3b6f7e94b4b020f8032b5108e.tar.gz
state: drop lazy_init
lazy_init is an optimization that makes it possible to read only up to the first valid bucket when starting. However, when restoring consistency, immediately afterwards we have we have to initialize all buckets anyway, so being lazy doesn't give us any gain. Remove it to simplify the code. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--src/barebox-state/backend_bucket_cached.c14
-rw-r--r--src/barebox-state/backend_bucket_circular.c13
-rw-r--r--src/barebox-state/backend_storage.c34
-rw-r--r--src/barebox-state/state.h5
4 files changed, 6 insertions, 60 deletions
diff --git a/src/barebox-state/backend_bucket_cached.c b/src/barebox-state/backend_bucket_cached.c
index ba0af7f..5e7f44c 100644
--- a/src/barebox-state/backend_bucket_cached.c
+++ b/src/barebox-state/backend_bucket_cached.c
@@ -110,19 +110,6 @@ static int state_backend_bucket_cache_write(struct state_backend_storage_bucket
return 0;
}
-static int state_backend_bucket_cache_init(
- struct state_backend_storage_bucket *bucket)
-{
- struct state_backend_storage_bucket_cache *cache =
- get_bucket_cache(bucket);
-
- if (cache->raw->init) {
- return cache->raw->init(cache->raw);
- }
-
- return 0;
-}
-
static void state_backend_bucket_cache_free(
struct state_backend_storage_bucket *bucket)
{
@@ -147,7 +134,6 @@ int state_backend_bucket_cached_create(struct device_d *dev,
cache->bucket.free = state_backend_bucket_cache_free;
cache->bucket.read = state_backend_bucket_cache_read;
cache->bucket.write = state_backend_bucket_cache_write;
- cache->bucket.init = state_backend_bucket_cache_init;
*out = &cache->bucket;
diff --git a/src/barebox-state/backend_bucket_circular.c b/src/barebox-state/backend_bucket_circular.c
index 53c2aae..8eae866 100644
--- a/src/barebox-state/backend_bucket_circular.c
+++ b/src/barebox-state/backend_bucket_circular.c
@@ -456,8 +456,7 @@ int state_backend_bucket_circular_create(struct device_d *dev, const char *path,
struct state_backend_storage_bucket **bucket,
unsigned int eraseblock,
ssize_t writesize,
- struct mtd_info_user *mtd_uinfo,
- bool lazy_init)
+ struct mtd_info_user *mtd_uinfo)
{
struct state_backend_storage_bucket_circular *circ;
int ret;
@@ -493,13 +492,9 @@ int state_backend_bucket_circular_create(struct device_d *dev, const char *path,
circ->bucket.free = state_backend_bucket_circular_free;
*bucket = &circ->bucket;
- if (!lazy_init) {
- ret = state_backend_bucket_circular_init(*bucket);
- if (ret)
- goto out_free;
- } else {
- circ->bucket.init = state_backend_bucket_circular_init;
- }
+ ret = state_backend_bucket_circular_init(*bucket);
+ if (ret)
+ goto out_free;
return 0;
diff --git a/src/barebox-state/backend_storage.c b/src/barebox-state/backend_storage.c
index 3c2fdd9..b793fb6 100644
--- a/src/barebox-state/backend_storage.c
+++ b/src/barebox-state/backend_storage.c
@@ -28,23 +28,6 @@
const unsigned int min_copies_written = 1;
-static int bucket_lazy_init(struct state_backend_storage_bucket *bucket)
-{
- int ret;
-
- if (bucket->initialized)
- return 0;
-
- if (bucket->init) {
- ret = bucket->init(bucket);
- if (ret)
- return ret;
- }
- bucket->initialized = true;
-
- return 0;
-}
-
/**
* state_storage_write - Writes the given data to the storage
* @param storage Storage object
@@ -70,13 +53,6 @@ int state_storage_write(struct state_backend_storage *storage,
return 0;
list_for_each_entry(bucket, &storage->buckets, bucket_list) {
- ret = bucket_lazy_init(bucket);
- if (ret) {
- dev_warn(storage->dev, "Failed to init bucket/write state backend bucket, %d\n",
- ret);
- continue;
- }
-
ret = bucket->write(bucket, buf, len);
if (ret < 0) {
dev_warn(storage->dev, "Failed to write state backend bucket, %d\n",
@@ -137,12 +113,6 @@ int state_storage_read(struct state_backend_storage *storage,
list_for_each_entry(bucket, &storage->buckets, bucket_list) {
*len = 0;
- ret = bucket_lazy_init(bucket);
- if (ret) {
- dev_warn(storage->dev, "Failed to init bucket/read state backend bucket, %d\n",
- ret);
- continue;
- }
ret = bucket->read(bucket, buf, len);
if (ret) {
@@ -288,14 +258,12 @@ static int state_storage_mtd_buckets_init(struct state_backend_storage *storage,
for (offset = dev_offset; offset < end; offset += meminfo->erasesize) {
int ret;
unsigned int eraseblock = offset / meminfo->erasesize;
- bool lazy_init = true;
ret = state_backend_bucket_circular_create(storage->dev, path,
&bucket,
eraseblock,
writesize,
- meminfo,
- lazy_init);
+ meminfo);
if (ret) {
dev_warn(storage->dev, "Failed to create bucket at '%s' eraseblock %u\n",
path, eraseblock);
diff --git a/src/barebox-state/state.h b/src/barebox-state/state.h
index 4ef4669..6f5de31 100644
--- a/src/barebox-state/state.h
+++ b/src/barebox-state/state.h
@@ -20,14 +20,12 @@ struct mtd_info_user;
* @bucket_list A list element struct to attach this bucket to a list
*/
struct state_backend_storage_bucket {
- int (*init) (struct state_backend_storage_bucket * bucket);
int (*write) (struct state_backend_storage_bucket * bucket,
const uint8_t * buf, ssize_t len);
int (*read) (struct state_backend_storage_bucket * bucket,
uint8_t ** buf, ssize_t * len_hint);
void (*free) (struct state_backend_storage_bucket * bucket);
- bool initialized;
struct list_head bucket_list;
};
@@ -196,8 +194,7 @@ int state_backend_bucket_circular_create(struct device_d *dev, const char *path,
struct state_backend_storage_bucket **bucket,
unsigned int eraseblock,
ssize_t writesize,
- struct mtd_info_user *mtd_uinfo,
- bool lazy_init);
+ struct mtd_info_user *mtd_uinfo);
int state_backend_bucket_cached_create(struct device_d *dev,
struct state_backend_storage_bucket *raw,
struct state_backend_storage_bucket **out);