[PATCH 2/2] state: storage: direct: skip writing meta data if this makes data fit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When a direct bucket is read it handles missing meta data just fine for
compatibility reasons. This allows to skip writing meta data if that
makes the data small enough to fit in the bucket to be written.

The motivation for this change is that the storage format in
pre-mainline state didn't use meta data and some machines still have to
stick to this format. For these the stride size exactly fits the data
size such that there is no place for additional meta data and so the
data is written in the old format.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@xxxxxxxxxxxxxx>
---
 common/state/backend_bucket_direct.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/common/state/backend_bucket_direct.c b/common/state/backend_bucket_direct.c
index 4465ed0e4115..8bf9a945643c 100644
--- a/common/state/backend_bucket_direct.c
+++ b/common/state/backend_bucket_direct.c
@@ -102,8 +102,14 @@ static int state_backend_bucket_direct_write(struct state_backend_storage_bucket
 	    get_bucket_direct(bucket);
 	int ret;
 	struct state_backend_storage_bucket_direct_meta meta;
+	int write_meta = 1;
 
-	if (len > direct->max_size - sizeof(meta))
+	if (len > direct->max_size - sizeof(meta)) {
+		dev_info(direct->dev, "skip writing metadata because of size constraints\n");
+		write_meta = 0;
+	}
+
+	if (len > direct->max_size)
 		return -E2BIG;
 
 	ret = lseek(direct->fd, direct->offset, SEEK_SET);
@@ -112,12 +118,15 @@ static int state_backend_bucket_direct_write(struct state_backend_storage_bucket
 		return ret;
 	}
 
-	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;
+	if (write_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;
+		}
 	}
 
 	ret = write_full(direct->fd, buf, len);
-- 
2.11.0


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




[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux