summaryrefslogtreecommitdiff
path: root/yaffs_summary.c
diff options
context:
space:
mode:
authorCharles Manning <cdhmanning@gmail.com>2011-03-31 14:42:56 +1300
committerCharles Manning <cdhmanning@gmail.com>2011-03-31 14:42:56 +1300
commit7cf801a7e52bba91529fbc9f29be50bec808a545 (patch)
treefa9e266bbe7b09114e3daff836b0c7ed9b281c03 /yaffs_summary.c
parent1570788072c1154eff93282e0bb8564de40bd8aa (diff)
yaffs: Tweaks to summary code
Trying some different ideas for handling free space cleaner. Signed-off-by: Charles Manning <cdhmanning@gmail.com>
Diffstat (limited to 'yaffs_summary.c')
-rw-r--r--yaffs_summary.c88
1 files changed, 70 insertions, 18 deletions
diff --git a/yaffs_summary.c b/yaffs_summary.c
index 04ef96b..31d443a 100644
--- a/yaffs_summary.c
+++ b/yaffs_summary.c
@@ -18,11 +18,18 @@
*
* Chunks holding summaries are marked with tags making it look like
* they are part of a fake file.
+ *
+ * The chunks that hold the summary are removed from free space and are marked
+ * as being in use.
+ *
+ * THa above might need to be revisited.
*/
#include "yaffs_summary.h"
#include "yaffs_packedtags2.h"
#include "yaffs_nand.h"
+#include "yaffs_getblockinfo.h"
+#include "yaffs_bitmap.h"
/* Summary tags don't need the sequence number becase that is redundant. */
struct yaffs_summary_tags {
@@ -41,7 +48,6 @@ static void yaffs_summary_clear(struct yaffs_dev *dev)
int yaffs_summary_init(struct yaffs_dev *dev)
{
- struct yaffs_summary_tags *sum;
int sum_bytes;
int chunks_used; /* Number of chunks used by summary */
@@ -51,12 +57,16 @@ int yaffs_summary_init(struct yaffs_dev *dev)
chunks_used = (sum_bytes + dev->data_bytes_per_chunk - 1)/
dev->data_bytes_per_chunk;
dev->chunks_per_summary = dev->param.chunks_per_block - chunks_used;
- sum = kmalloc(sizeof(struct yaffs_summary_tags) *
+ dev->sum_tags = kmalloc(sizeof(struct yaffs_summary_tags) *
dev->chunks_per_summary, GFP_NOFS);
- if(!sum)
+ dev->gc_sum_tags = kmalloc(sizeof(struct yaffs_summary_tags) *
+ dev->chunks_per_summary, GFP_NOFS);
+ if(!dev->sum_tags || !dev->gc_sum_tags) {
+ kfree(dev->sum_tags);
+ kfree(dev->gc_sum_tags);
return YAFFS_FAIL;
+ }
- dev->sum_tags = sum;
yaffs_summary_clear(dev);
return YAFFS_OK;
@@ -64,28 +74,31 @@ int yaffs_summary_init(struct yaffs_dev *dev)
void yaffs_summary_deinit(struct yaffs_dev *dev)
{
- if(dev->sum_tags) {
- kfree(dev->sum_tags);
- dev->sum_tags = NULL;
- }
+ kfree(dev->sum_tags);
+ dev->sum_tags = NULL;
+ kfree(dev->sum_tags);
+ dev->sum_tags = NULL;
dev->chunks_per_summary = 0;
}
-static int yaffs_summary_write(struct yaffs_dev *dev)
+static int yaffs_summary_write(struct yaffs_dev *dev, int blk)
{
struct yaffs_ext_tags tags;
u8 *buffer;
u8 *sum_buffer = (u8 *)dev->sum_tags;
int n_bytes;
int chunk_in_nand;
+ int chunk_in_block;
int result;
int this_tx;
+ struct yaffs_block_info *bi = yaffs_get_block_info(dev, blk);
buffer = yaffs_get_temp_buffer(dev);
n_bytes = sizeof(struct yaffs_summary_tags) * dev->chunks_per_summary;
memset(&tags, 0, sizeof(struct yaffs_ext_tags));
tags.obj_id = YAFFS_OBJECTID_SUMMARY;
tags.chunk_id = 1;
+ chunk_in_block = dev-> chunks_per_summary;
chunk_in_nand = dev->alloc_block * dev->param.chunks_per_block +
dev-> chunks_per_summary;
do {
@@ -96,28 +109,49 @@ static int yaffs_summary_write(struct yaffs_dev *dev)
tags.n_bytes = this_tx;
result = yaffs_wr_chunk_tags_nand(dev, chunk_in_nand,
buffer, &tags);
+
+ if (result != YAFFS_OK)
+ break;
+ yaffs_set_chunk_bit(dev, blk, chunk_in_block);
+ bi->pages_in_use++;
+ dev->n_free_chunks--;
+
n_bytes -= this_tx;
sum_buffer += this_tx;
chunk_in_nand++;
+ chunk_in_block++;
tags.chunk_id++;
+
+ chunk_in_block++;
} while (result == YAFFS_OK && n_bytes > 0);
yaffs_release_temp_buffer(dev, buffer);
+
+
+ if (result == YAFFS_OK)
+ bi->has_summary = 1;
+
+
return result;
}
-int yaffs_summary_read(struct yaffs_dev *dev, int blk)
+int yaffs_summary_read(struct yaffs_dev *dev,
+ struct yaffs_summary_tags *st,
+ int blk)
{
struct yaffs_ext_tags tags;
u8 *buffer;
- u8 *sum_buffer = (u8 *)dev->sum_tags;
+ u8 *sum_buffer = (u8 *)st;
int n_bytes;
int chunk_id;
int chunk_in_nand;
+ int chunk_in_block;
int result;
int this_tx;
+ struct yaffs_block_info *bi = yaffs_get_block_info(dev, blk);
buffer = yaffs_get_temp_buffer(dev);
n_bytes = sizeof(struct yaffs_summary_tags) * dev->chunks_per_summary;
+ chunk_in_block = dev->chunks_per_summary;
chunk_in_nand = blk * dev->param.chunks_per_block +
dev->chunks_per_summary;
chunk_id = 1;
@@ -137,14 +171,24 @@ int yaffs_summary_read(struct yaffs_dev *dev, int blk)
if (result != YAFFS_OK)
break;
+ if (st == dev->sum_tags) {
+ /* If we're scanning then update the block info */
+ yaffs_set_chunk_bit(dev, blk, chunk_in_block);
+ bi->pages_in_use++;
+ }
+
memcpy(sum_buffer, buffer, this_tx);
n_bytes -= this_tx;
sum_buffer += this_tx;
chunk_in_nand++;
+ chunk_in_block++;
chunk_id++;
- dev->n_free_chunks--;
} while (result == YAFFS_OK && n_bytes > 0);
yaffs_release_temp_buffer(dev, buffer);
+
+ if (st == dev->sum_tags && result == YAFFS_OK)
+ bi->has_summary = 1;
+
return result;
}
int yaffs_summary_add(struct yaffs_dev *dev,
@@ -153,30 +197,26 @@ int yaffs_summary_add(struct yaffs_dev *dev,
{
struct yaffs_packed_tags2_tags_only tags_only;
struct yaffs_summary_tags *sum_tags;
+ int block_in_nand = chunk_in_nand / dev->param.chunks_per_block;
int chunk_in_block = chunk_in_nand % dev->param.chunks_per_block;
if(!dev->sum_tags)
return YAFFS_OK;
- printf("Add summary for chunk %d tags (%d %d %d)",chunk_in_block,
- tags->seq_number, tags->obj_id, tags->chunk_id);
if(chunk_in_block >= 0 && chunk_in_block < dev->chunks_per_summary) {
yaffs_pack_tags2_tags_only(&tags_only, tags);
sum_tags = &dev->sum_tags[chunk_in_block];
sum_tags->chunk_id = tags_only.chunk_id;
sum_tags->n_bytes = tags_only.n_bytes;
sum_tags->obj_id = tags_only.obj_id;
- printf(" added %d %d %d", sum_tags->obj_id, sum_tags->chunk_id, sum_tags->n_bytes);
if(chunk_in_block == dev->chunks_per_summary - 1) {
- printf(" Write summary");
/* Time to write out the summary */
- yaffs_summary_write(dev);
+ yaffs_summary_write(dev, block_in_nand);
yaffs_summary_clear(dev);
yaffs_skip_rest_of_block(dev);
}
}
- printf("\n");
return YAFFS_OK;
}
@@ -196,3 +236,15 @@ int yaffs_summary_fetch(struct yaffs_dev *dev,
}
return YAFFS_FAIL;
}
+
+void yaffs_summary_gc(struct yaffs_dev *dev, int blk)
+{
+ struct yaffs_block_info *bi = yaffs_get_block_info(dev, blk);
+ int i;
+
+ if (!bi->has_summary)
+ return;
+
+ for (i = dev->chunks_per_summary; i < dev->param.chunks_per_block; i++)
+ yaffs_clear_chunk_bit(dev, blk, i);
+}