summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/block.c25
-rw-r--r--common/state/backend_storage.c2
-rw-r--r--common/state/state.c7
3 files changed, 28 insertions, 6 deletions
diff --git a/common/block.c b/common/block.c
index 97cf5dc4de..02be80d7cc 100644
--- a/common/block.c
+++ b/common/block.c
@@ -36,7 +36,7 @@ struct chunk {
struct list_head list;
};
-#define BUFSIZE (PAGE_SIZE * 4)
+#define BUFSIZE (PAGE_SIZE * 16)
static int writebuffer_io_len(struct block_device *blk, struct chunk *chunk)
{
@@ -161,6 +161,14 @@ static int block_cache(struct block_device *blk, int block)
dev_dbg(blk->dev, "%s: %d to %d\n", __func__, chunk->block_start,
chunk->num);
+ if (chunk->block_start * BLOCKSIZE(blk) >= blk->discard_start &&
+ chunk->block_start * BLOCKSIZE(blk) + writebuffer_io_len(blk, chunk)
+ <= blk->discard_start + blk->discard_size) {
+ memset(chunk->data, 0, writebuffer_io_len(blk, chunk));
+ list_add(&chunk->list, &blk->buffered_blocks);
+ return 0;
+ }
+
ret = blk->ops->read(blk, chunk->data, chunk->block_start,
writebuffer_io_len(blk, chunk));
if (ret) {
@@ -337,11 +345,23 @@ static int block_op_flush(struct cdev *cdev)
{
struct block_device *blk = cdev->priv;
+ blk->discard_start = blk->discard_size = 0;
+
return writebuffer_flush(blk);
}
static int block_op_close(struct cdev *cdev) __alias(block_op_flush);
+static int block_op_discard_range(struct cdev *cdev, loff_t count, loff_t offset)
+{
+ struct block_device *blk = cdev->priv;
+
+ blk->discard_start = offset;
+ blk->discard_size = count;
+
+ return 0;
+}
+
static struct cdev_operations block_ops = {
.read = block_op_read,
#ifdef CONFIG_BLOCK_WRITE
@@ -349,6 +369,7 @@ static struct cdev_operations block_ops = {
#endif
.close = block_op_close,
.flush = block_op_flush,
+ .discard_range = block_op_discard_range,
};
int blockdevice_register(struct block_device *blk)
@@ -370,7 +391,7 @@ int blockdevice_register(struct block_device *blk)
dev_dbg(blk->dev, "rdbufsize: %d blockbits: %d blkmask: 0x%08x\n",
blk->rdbufsize, blk->blockbits, blk->blkmask);
- for (i = 0; i < 32; i++) {
+ for (i = 0; i < 8; i++) {
struct chunk *chunk = xzalloc(sizeof(*chunk));
chunk->data = dma_alloc(BUFSIZE);
chunk->num = i;
diff --git a/common/state/backend_storage.c b/common/state/backend_storage.c
index fca887e93f..fe7e89e8fb 100644
--- a/common/state/backend_storage.c
+++ b/common/state/backend_storage.c
@@ -192,6 +192,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 +205,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;
}
diff --git a/common/state/state.c b/common/state/state.c
index b168387eef..1822f37f3e 100644
--- a/common/state/state.c
+++ b/common/state/state.c
@@ -94,7 +94,7 @@ out:
*/
static int state_do_load(struct state *state, enum state_flags flags)
{
- void *buf;
+ void *buf = NULL;
ssize_t len;
int ret;
@@ -103,7 +103,7 @@ static int state_do_load(struct state *state, enum state_flags flags)
if (ret) {
dev_err(&state->dev, "Failed to read state with format %s, %d\n",
state->format->name, ret);
- return ret;
+ goto out;
}
ret = state->format->unpack(state->format, state, buf, len);
@@ -114,9 +114,8 @@ static int state_do_load(struct state *state, enum state_flags flags)
}
state->init_from_defaults = 0;
- state->dirty = 0;
-
out:
+ state->dirty = !!ret; /* mark dirty on error */
free(buf);
return ret;
}