summaryrefslogtreecommitdiffstats
path: root/common/state/backend_storage.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/state/backend_storage.c')
-rw-r--r--common/state/backend_storage.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/common/state/backend_storage.c b/common/state/backend_storage.c
index fca887e93f..df81902bf7 100644
--- a/common/state/backend_storage.c
+++ b/common/state/backend_storage.c
@@ -21,7 +21,7 @@
#include <linux/mtd/mtd-abi.h>
#include <sys/stat.h>
#include <malloc.h>
-#include <printk.h>
+#include <linux/printk.h>
#include "state.h"
@@ -144,6 +144,7 @@ int state_storage_read(struct state_backend_storage *storage,
enum state_flags flags)
{
struct state_backend_storage_bucket *bucket, *bucket_used = NULL;
+ int zerobuckets = 0, totalbuckets = 0;
int ret;
dev_dbg(storage->dev, "Checking redundant buckets...\n");
@@ -152,30 +153,35 @@ int state_storage_read(struct state_backend_storage *storage,
* one we want to use.
*/
list_for_each_entry(bucket, &storage->buckets, bucket_list) {
+ totalbuckets++;
+
ret = bucket->read(bucket, &bucket->buf, &bucket->len);
- if (ret == -EUCLEAN)
+ if (ret == -EUCLEAN) {
bucket->needs_refresh = 1;
- else if (ret)
+ } else if (ret) {
+ if (ret == -ENOMEDIUM)
+ zerobuckets++;
continue;
+ }
/*
* Verify the buffer crcs. The buffer length is passed in the len argument,
* .verify overwrites it with the length actually used.
*/
ret = format->verify(format, magic, bucket->buf, &bucket->len, flags);
- if (!ret && !bucket_used)
+ if (ret == -ENOMEDIUM)
+ zerobuckets++;
+ else if (!ret && !bucket_used)
bucket_used = bucket;
- if (ret)
+ else if (ret)
dev_info(storage->dev, "Ignoring broken bucket %d@0x%08llx...\n", bucket->num, (long long) bucket->offset);
}
dev_dbg(storage->dev, "Checking redundant buckets finished.\n");
- if (!bucket_used) {
- dev_err(storage->dev, "Failed to find any valid state copy in any bucket\n");
-
- return -ENOENT;
- }
+ if (!bucket_used)
+ return dev_err_state_init(storage->dev, zerobuckets == totalbuckets ? -ENOMEDIUM : -ENOENT,
+ "no valid state copy in any bucket\n");
dev_info(storage->dev, "Using bucket %d@0x%08llx\n", bucket_used->num, (long long) bucket_used->offset);
@@ -192,6 +198,7 @@ int state_storage_read(struct state_backend_storage *storage,
/* Free buffer from the unused buckets */
free(bucket->buf);
bucket->buf = NULL;
+ bucket->len = 0;
}
/*
@@ -204,6 +211,7 @@ int state_storage_read(struct state_backend_storage *storage,
/* buffer from the used bucket is passed to the caller, do not free */
bucket_used->buf = NULL;
+ bucket_used->len = 0;
return 0;
}
@@ -324,7 +332,7 @@ static int state_storage_file_buckets_init(struct state_backend_storage *storage
offset = storage->offset + n * stridesize;
ret = state_backend_bucket_direct_create(storage->dev, storage->path,
&bucket, offset,
- stridesize);
+ stridesize, storage->readonly);
if (ret) {
dev_warn(storage->dev, "Failed to create direct bucket at '%s' offset %lld\n",
storage->path, (long long) offset);