FreeCalypso > hg > freecalypso-sw
changeset 216:0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Mon, 06 Jan 2014 07:23:36 +0000 |
parents | 517dd86b45b1 |
children | 30a173257f4a |
files | gsm-fw/services/ffs/Makefile gsm-fw/services/ffs/reclaim.c |
diffstat | 2 files changed, 68 insertions(+), 73 deletions(-) [+] |
line wrap: on
line diff
--- a/gsm-fw/services/ffs/Makefile Mon Jan 06 07:12:02 2014 +0000 +++ b/gsm-fw/services/ffs/Makefile Mon Jan 06 07:23:36 2014 +0000 @@ -2,7 +2,7 @@ CFLAGS= -O2 -fno-builtin -mthumb-interwork -mthumb LD= arm-elf-ld -OBJS= cfgffs.o core.o drv.o ffs_env.o ffstrace.o fsck.o task.o +OBJS= cfgffs.o core.o drv.o ffs_env.o ffstrace.o fsck.o reclaim.o task.o HDRS= core.h drv.h ffs.h ffs_api.h ffs_env.h ffs_pool_size.h ffstrace.h \ intctl.h ramffs.h task.h tmffs.h
--- a/gsm-fw/services/ffs/reclaim.c Mon Jan 06 07:12:02 2014 +0000 +++ b/gsm-fw/services/ffs/reclaim.c Mon Jan 06 07:23:36 2014 +0000 @@ -8,14 +8,10 @@ * ******************************************************************************/ -#ifndef TARGET -#include "ffs.cfg" -#endif - -#include "ffs/ffs.h" -#include "ffs/board/core.h" -#include "ffs/board/drv.h" -#include "ffs/board/ffstrace.h" +#include "ffs.h" +#include "core.h" +#include "drv.h" +#include "ffstrace.h" #include <stdlib.h> // rand() @@ -505,23 +501,23 @@ { iref_t i, n, j; blocksize_t used_old, lost_old; - int org_res_space, result = 0; - iref_t org_block_files_reserved; + int org_res_space, result = 0; + iref_t org_block_files_reserved; offset_t lower, upper; struct inode_s *ip; - static int is_reclaim_running = 0; + static int is_reclaim_running = 0; tw(tr(TR_BEGIN, TrDReclaim, "data_block_reclaim(%d) {\n", b)); // In case of no free blocks (after sudden power off) or if the file // system is near full we risk to be reentered (infinity recursively // loop) and we can not allow that, so just return. - if (is_reclaim_running == 1) { - tw(tr(TR_END, TrDReclaim, "} (reenteret skip reclaim) 0\n")); - return EFFS_RECLAIMLOOP; - } + if (is_reclaim_running == 1) { + tw(tr(TR_END, TrDReclaim, "} (reenteret skip reclaim) 0\n")); + return EFFS_RECLAIMLOOP; + } - is_reclaim_running = 1; + is_reclaim_running = 1; // If there are more objects in this block than there are remaining // free inodes, we have to make an inodes_reclaim() first. @@ -541,18 +537,18 @@ } // Allocate a new block. NOTE: we don't return an error because if we - // get in the situation where we don't have any free blocks this is the - // only way to recover. + // get in the situation where we don't have any free blocks this is the + // only way to recover. if ((result = block_alloc(1, BF_DATA)) < 0) { tw(tr(TR_FUNC, TrAll, "WARNING: block_alloc failed\n")); } - BLOCK_RECLAIM_TEST(BLOCK_RECLAIM_ALLOC, "Oops after ffs_block_alloc()"); + BLOCK_RECLAIM_TEST(BLOCK_RECLAIM_ALLOC, "Oops after ffs_block_alloc()"); // If there are any objects at all to reclaim... if (bstat[b].objects > 0) { - BLOCK_RECOVER_TEST_INIT(BLOCK_RECOVER_OBJECTS, "Dummy") + BLOCK_RECOVER_TEST_INIT(BLOCK_RECOVER_OBJECTS, "Dummy") // Save the current journal state if (journal_push() != EFFS_OK) { is_reclaim_running = 0; // NOTEME: change to goto? @@ -574,17 +570,17 @@ tw(tr(TR_FUNC, TrDReclaim, "Block addr range = 0x%X..0x%X\n", location2offset(lower), location2offset(upper))); - // This is the only time we are allowed to use the reserved - org_block_files_reserved= fs.block_files_reserved; - fs.block_files_reserved = 0; + // This is the only time we are allowed to use the reserved + org_block_files_reserved= fs.block_files_reserved; + fs.block_files_reserved = 0; - org_res_space = fs.reserved_space; + org_res_space = fs.reserved_space; fs.reserved_space = RESERVED_NONE; - ip = inode_addr(1); + ip = inode_addr(1); for (i = 1, n = 0; i < fs.inodes_max; i++, ip++) { - BLOCK_RECOVER_TEST(BLOCK_RECOVER_OBJECTS, "Oops before relocate all objects"); + BLOCK_RECOVER_TEST(BLOCK_RECOVER_OBJECTS, "Oops before relocate all objects"); // Ensure object is valid and within the block to be reclaimed if (is_object_valid(ip) && lower <= ip->location && ip->location < upper) @@ -646,8 +642,8 @@ } } - fs.block_files_reserved = org_block_files_reserved; // Restore - fs.reserved_space = org_res_space; + fs.block_files_reserved = org_block_files_reserved; // Restore + fs.reserved_space = org_res_space; tw(tr(TR_FUNC, TrDReclaim, "Reclaimed %d objects\n", n)); if (result >= 0) @@ -659,15 +655,15 @@ tw(tr(TR_FUNC, TrAll, "WARNING: data_block_reclaim() not completed\n")); result = EFFS_DBR; - } + } // Restore the saved journal state if (journal_pop() != EFFS_OK) { - is_reclaim_running = 0; // NOTEME: change to goto? - return EFFS_CORRUPTED; - } + is_reclaim_running = 0; // NOTEME: change to goto? + return EFFS_CORRUPTED; + } } - BLOCK_RECLAIM_TEST(BLOCK_RECLAIM_NO_CLEAN, "Oops before clean old data block"); + BLOCK_RECLAIM_TEST(BLOCK_RECLAIM_NO_CLEAN, "Oops before clean old data block"); if (result >= 0) { // Clean the block (remove all inodes that refer to this block) @@ -675,14 +671,14 @@ block_clean(b); statistics_update_drec(used_old - lost_old, lost_old, candidate); - - BLOCK_RECLAIM_TEST(BLOCK_RECLAIM_CLEANING, "Oops before free old data block"); + + BLOCK_RECLAIM_TEST(BLOCK_RECLAIM_CLEANING, "Oops before free old data block"); // Free the old block block_free(b); } - is_reclaim_running = 0; + is_reclaim_running = 0; tw(tr(TR_END, TrDReclaim, "} (data_block_reclaim) %d\n", result)); ttw(ttr(TTrRec, "} %d" NL, result)); @@ -784,9 +780,8 @@ int blocks_reclaim(void) { bref_t b, n, b_lost_space; - int blocks_free = 0, lost_space; - - int free_space, b_free_space; + int blocks_free = 0, lost_space; + int free_space, b_free_space; tw(tr(TR_BEGIN, TrBlock, "blocks_reclaim() {\n")); ttw(str(TTrRec, "blocks_reclaim() {" NL)); @@ -802,46 +797,46 @@ block_reclaim(b); n++; } - if (is_block(b, BF_IS_FREE)) { - blocks_free++; - } + if (is_block(b, BF_IS_FREE)) { + blocks_free++; + } } } - // If the number of free blocks is less than fs.blocks_free_min we - // call data_block_reclaim(). We will reclaim the block with most lost - // space. This should only happend if we got a sudden power off/reset - // while we reclaimed a block. - if (blocks_free < fs.blocks_free_min) { - lost_space = 0; - free_space = 0; + // If the number of free blocks is less than fs.blocks_free_min we + // call data_block_reclaim(). We will reclaim the block with most lost + // space. This should only happend if we got a sudden power off/reset + // while we reclaimed a block. + if (blocks_free < fs.blocks_free_min) { + lost_space = 0; + free_space = 0; - // We most never reclaim the block with most free space because this - // is the only block we can relocate the objects to. - for (b = 0; b < dev.numblocks; b++) { - if (is_block_flag(b, BF_DATA)) { - if ((dev.blocksize - bstat[b].used) > free_space) { - free_space = dev.blocksize - bstat[b].used; - b_free_space = b; - } - } + // We most never reclaim the block with most free space because this + // is the only block we can relocate the objects to. + for (b = 0; b < dev.numblocks; b++) { + if (is_block_flag(b, BF_DATA)) { + if ((dev.blocksize - bstat[b].used) > free_space) { + free_space = dev.blocksize - bstat[b].used; + b_free_space = b; } - tw(tr(TR_FUNC, TrBlock, "most free space: %d in block: %d \n", - free_space, b_free_space)); + } + } + tw(tr(TR_FUNC, TrBlock, "most free space: %d in block: %d \n", + free_space, b_free_space)); - for (b = 0; b < dev.numblocks; b++) { - if (is_block_flag(b, BF_DATA) && b != b_free_space) { - if (bstat[b].lost > lost_space) { - lost_space = bstat[b].lost; - b_lost_space = b; - } - } + for (b = 0; b < dev.numblocks; b++) { + if (is_block_flag(b, BF_DATA) && b != b_free_space) { + if (bstat[b].lost > lost_space) { + lost_space = bstat[b].lost; + b_lost_space = b; } - tw(tr(TR_FUNC, TrBlock, "most lost space: %d in block: %d \n", - lost_space, b_lost_space)); + } + } + tw(tr(TR_FUNC, TrBlock, "most lost space: %d in block: %d \n", + lost_space, b_lost_space)); - data_block_reclaim(b_lost_space, MOST_LOST); - } + data_block_reclaim(b_lost_space, MOST_LOST); + } tw(tr(TR_END, TrBlock, "} %d\n", n)); ttw(ttr(TTrRec, "} %d" NL, n)); @@ -865,7 +860,7 @@ // Testing of fs.testflags is for the sake of testing block_commit() if ((fs.testflags & BLOCK_COMMIT_BASE) != 0 && - fs.testflags != BLOCK_COMMIT_OLD_FREE) { + fs.testflags != BLOCK_COMMIT_OLD_FREE) { tw(tr(TR_FUNC, TrBlock, "Bailing out because fs.testflags = 0x%X\n", fs.testflags)); }