From: Charles Manning Date: Fri, 3 Sep 2010 04:11:52 +0000 (+1200) Subject: Merge branch 'master' of ssh://www.aleph1.co.uk/home/aleph1/git/yaffs2 X-Git-Tag: pre-name-change~17 X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=commitdiff_plain;h=0035e396dc2b872289b8e6320ced59e2eea81962;hp=62f2c2d27cfaa401f298f6c2a6dabecae951ec95 Merge branch 'master' of ssh://aleph1.co.uk/home/aleph1/git/yaffs2 --- diff --git a/direct/basic-test/dtest.c b/direct/basic-test/dtest.c index b9fc0ea..3ac5604 100644 --- a/direct/basic-test/dtest.c +++ b/direct/basic-test/dtest.c @@ -22,6 +22,9 @@ #include "yaffsfs.h" +#include "yaffs_guts.h" /* Only for dumping device innards */ + +extern int yaffs_traceMask; void dumpDir(const char *dname); @@ -177,21 +180,22 @@ void create_file_of_size(const char *fn,int syze) int h; int n; int result; - + int iteration = 0; char xx[200]; - - int iterations = (syze + strlen(fn) -1)/ strlen(fn); - + h = yaffs_open(fn, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE); - while (iterations > 0) + while (syze > 0) { - sprintf(xx,"%s %8d",fn,iterations); + sprintf(xx,"%s %8d",fn,iteration); n = strlen(xx); result = yaffs_write(h,xx,n); - if(result != n) - printf("Wrote %d, should have been %d\n",result,n); - iterations--; + if(result != n){ + printf("Wrote %d, should have been %d. syze is %d\n",result,n,syze); + syze = 0; + } else + syze-=n; + iteration++; } yaffs_close (h); } @@ -2639,7 +2643,48 @@ void big_xattr_test(const char *mountpt) list_xattr(name); } + + +void dump_dev_stats(yaffs_Device *dev, const char * str) +{ + printf("%s\n",str); + printf( "space free %d erased %d " + "nand reads %d writes %d erases %d " + "gc all %d passive %d oldestdirty %d blocks %d copies %d \n", + dev->nFreeChunks, dev->nErasedBlocks * dev->param.nChunksPerBlock, + dev->nPageReads, dev->nPageWrites, dev->nBlockErasures, + dev->allGCs, dev->passiveGCs, dev->oldestDirtyGCs, dev->nGCBlocks, dev->nGCCopies); +} + +void test_flash_traffic(const char *mountpt) +{ + char name0[100]; + char name1[100]; + int i; + yaffs_Device *dev; + + yaffs_traceMask = 0; + + yaffs_StartUp(); + + yaffs_mount(mountpt); + dev = yaffs_getdev(mountpt); + + strcpy(name0,mountpt); + strcat(name0,"/x"); + + strcpy(name1,mountpt); + strcat(name1,"/y"); + + dump_dev_stats(dev,"start"); + create_file_of_size(name0,32 * 1024 * 1024); + dump_dev_stats(dev,"32MB written"); + for(i = 0; i < 20; i++) + create_file_of_size(name1,1024 * 1024); + dump_dev_stats(dev,"20x 1MB files written"); + +} int random_seed; int simulate_power_failure; @@ -2693,9 +2738,6 @@ int main(int argc, char *argv[]) //link_test("/flash/flash"); - - - // cache_bypass_bug_test(); //free_space_check(); @@ -2705,7 +2747,9 @@ int main(int argc, char *argv[]) //basic_xattr_test("/yaffs2"); //big_xattr_test("/yaffs2"); - null_name_test("yaffs2"); + //null_name_test("yaffs2"); + + test_flash_traffic("yaffs2"); return 0; diff --git a/direct/basic-test/yaffsnewcfg.c b/direct/basic-test/yaffsnewcfg.c index 6ee43b7..fa99342 100644 --- a/direct/basic-test/yaffsnewcfg.c +++ b/direct/basic-test/yaffsnewcfg.c @@ -101,7 +101,7 @@ int yaffs_StartUp(void) // Stuff to configure YAFFS // Stuff to initialise anything special (eg lock semaphore). yaffsfs_LocalInitialisation(); - yramsim_CreateRamSim("yaffs2",1,200,0,0); + yramsim_CreateRamSim("yaffs2",1,1000,0,0); yramsim_CreateRamSim("p0",0,0x400,1,0xff); yramsim_CreateRamSim("p1",0,0x400,1,0); diff --git a/direct/yaffsfs.c b/direct/yaffsfs.c index b93f295..9ac08ab 100644 --- a/direct/yaffsfs.c +++ b/direct/yaffsfs.c @@ -1637,7 +1637,10 @@ int yaffs_mkdir(const YCHAR *path, mode_t mode) yaffsfs_Lock(); parent = yaffsfs_FindDirectory(NULL,path,&name,0); - if(parent && parent->myDev->readOnly){ + if(parent && yaffs_strnlen(name,5) == 0){ + /* Trying to make the root itself */ + yaffsfs_SetError(-EEXIST); + } else if(parent && parent->myDev->readOnly){ yaffsfs_SetError(-EINVAL); } else { if(parent) @@ -1660,6 +1663,14 @@ int yaffs_mkdir(const YCHAR *path, mode_t mode) return retVal; } +void * yaffs_getdev(const YCHAR *path) +{ + yaffs_Device *dev=NULL; + YCHAR *dummy; + dev = yaffsfs_FindDevice(path,&dummy); + return (void *)dev; +} + int yaffs_mount2(const YCHAR *path,int readOnly) { int retVal=-1; diff --git a/direct/yaffsfs.h b/direct/yaffsfs.h index 7961dff..4b2ebe9 100644 --- a/direct/yaffsfs.h +++ b/direct/yaffsfs.h @@ -164,6 +164,10 @@ void yaffs_AddDevice(struct yaffs_DeviceStruct *dev); int yaffs_StartUp(void); + +/* Function only for debugging */ +void * yaffs_getdev(const YCHAR *path); + #endif diff --git a/linux-tests/write_test.sh b/linux-tests/write_test.sh new file mode 100755 index 0000000..7abe522 --- /dev/null +++ b/linux-tests/write_test.sh @@ -0,0 +1,22 @@ +#! /bin/bash + +TESTDIR=/mnt + +echo "start" +echo " " +cat /proc/yaffs + +for(( i=0; i < 32; i++ )); do +dd of=$TESTDIR/$i if=/dev/urandom bs=1024 count=1024 +done + +echo "32 x 1MB written" +cat /proc/yaffs +for(( i=0; i < 32; i++ )); do +dd of=$TESTDIR/xx if=/dev/urandom bs=1024 count=1024 +done + +echo "32 x 1MB overwites" +cat /proc/yaffs + + diff --git a/patch-ker.sh b/patch-ker.sh index 67e7a51..ad92e7c 100755 --- a/patch-ker.sh +++ b/patch-ker.sh @@ -12,7 +12,8 @@ # # Patch YAFFS into the kernel # -# args: kpath : Full path to kernel sources to be patched +# args: l/c : link or copy +# kpath : Full path to kernel sources to be patched # # Somewhat "inspired by" the mtd patchin script # @@ -111,7 +112,9 @@ YAFFSDIR=$LINUXDIR/fs/yaffs2 if [ -e $YAFFSDIR ] then - echo "$YAFFSDIR exists, not patching" + echo "$YAFFSDIR exists, not patching." + echo "If you want to replace what is already there then delete $YAFFSDIR" + echo " eg. \"rm -rf $YAFFSDIR\" " else mkdir $LINUXDIR/fs/yaffs2 $CPY $PWD/Makefile.kernel $LINUXDIR/fs/yaffs2/Makefile diff --git a/yaffs_fs.c b/yaffs_fs.c index 7c51041..ecf2bbe 100644 --- a/yaffs_fs.c +++ b/yaffs_fs.c @@ -117,6 +117,12 @@ #define YPROC_ROOT NULL #endif +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)) +#define Y_INIT_TIMER(a) init_timer(a) +#else +#define Y_INIT_TIMER(a) init_timer_on_stack(a) +#endif + #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17)) #define WRITE_SIZE_STR "writesize" #define WRITE_SIZE(mtd) ((mtd)->writesize) @@ -2358,7 +2364,7 @@ static int yaffs_BackgroundThread(void *data) if(time_before(expires,now)) expires = now + HZ; - init_timer_on_stack(&timer); + Y_INIT_TIMER(&timer); timer.expires = expires+1; timer.data = (unsigned long) current; timer.function = yaffs_background_waker; diff --git a/yaffs_guts.c b/yaffs_guts.c index 389a57c..75eeb84 100644 --- a/yaffs_guts.c +++ b/yaffs_guts.c @@ -2435,7 +2435,16 @@ static unsigned yaffs_FindBlockForGarbageCollection(yaffs_Device *dev, threshold = dev->param.nChunksPerBlock; iterations = nBlocks; } else { - int maxThreshold = dev->param.nChunksPerBlock/2; + int maxThreshold; + + if(background) + maxThreshold = dev->param.nChunksPerBlock/2; + else + maxThreshold = dev->param.nChunksPerBlock/8; + + if(maxThreshold < YAFFS_GC_PASSIVE_THRESHOLD) + maxThreshold = YAFFS_GC_PASSIVE_THRESHOLD; + threshold = background ? (dev->gcNotDone + 2) * 2 : 0; if(threshold param.gcControl && @@ -2568,6 +2575,9 @@ static int yaffs_CheckGarbageCollection(yaffs_Device *dev, int background) if (dev->nErasedBlocks < minErased) aggressive = 1; else { + if(!background && erasedChunks > (dev->nFreeChunks / 4)) + break; + if(dev->gcSkip > 20) dev->gcSkip = 20; if(erasedChunks < dev->nFreeChunks/2 ||