mtd/fs/jffs2/ecos/src fs-ecos.c, 1.40, 1.41 gcthread.c, 1.2, 1.3 os-ecos.h, 1.22, 1.23

lunn at infradead.org lunn at infradead.org
Sat Jan 22 11:01:15 EST 2005


Update of /home/cvs/mtd/fs/jffs2/ecos/src
In directory phoenix.infradead.org:/tmp/cvs-serv27946/src

Modified Files:
	fs-ecos.c gcthread.c os-ecos.h 
Log Message:
Pushed the new garbage collect code from eCos into MTD.


Index: fs-ecos.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/ecos/src/fs-ecos.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- fs-ecos.c	11 Dec 2004 12:24:16 -0000	1.40
+++ fs-ecos.c	22 Jan 2005 16:01:12 -0000	1.41
@@ -12,20 +12,13 @@
  *
  */
 
-#include <linux/types.h>
-#include <linux/stat.h>
 #include <linux/kernel.h>
-#include <linux/jffs2.h>
-#include <linux/jffs2_fs_sb.h>
-#include <linux/jffs2_fs_i.h>
+#include "nodelist.h"
 #include <linux/pagemap.h>
 #include <linux/crc32.h>
-#include "nodelist.h"
 #include "compr.h"
-
 #include <errno.h>
 #include <string.h>
-#include <cyg/io/io.h>
 #include <cyg/io/config_keys.h>
 
 #if (__GNUC__ == 3) && (__GNUC_MINOR__ == 2) && defined (__ARM_ARCH_4__)
@@ -1721,7 +1714,6 @@
 			break;
 		}
 	}
-
 	return inode;
 }
 
@@ -1737,7 +1729,6 @@
 			break;
 		}
 	}
-
 	return inode;
 }
 
@@ -1797,8 +1788,8 @@
 		BUG();
 
 	if (i->i_count)
-		return;
-
+                return;
+        
 	if (!i->i_nlink) {
 		struct _inode *parent;
 

Index: gcthread.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/ecos/src/gcthread.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- gcthread.c	16 Nov 2004 20:36:13 -0000	1.2
+++ gcthread.c	22 Jan 2005 16:01:12 -0000	1.3
@@ -3,50 +3,122 @@
  *
  * Copyright (C) 2001-2003 Red Hat, Inc.
  *
- * Created by David Woodhouse <dwmw2 at infradead.org>
+ * Created by David Woodhouse <dwmw2 at redhat.com>
  *
  * For licensing information, see the file 'LICENCE' in this directory.
  *
  * $Id$
  *
  */
-
 #include <linux/kernel.h>
-#include <linux/types.h>
-#include <linux/jffs2.h>
 #include "nodelist.h"
+#include <cyg/kernel/kapi.h>
 
+#define GC_THREAD_FLAG_TRIG 1
+#define GC_THREAD_FLAG_STOP 2
+#define GC_THREAD_FLAG_HAS_EXIT 4
 
-static void jffs2_garbage_collect_thread(struct jffs2_sb_info *c);
+static cyg_thread_entry_t jffs2_garbage_collect_thread;
 
 void jffs2_garbage_collect_trigger(struct jffs2_sb_info *c)
 {
-	/* Wake up the thread */
-	(void)&jffs2_garbage_collect_thread;
+     struct super_block *sb=OFNI_BS_2SFFJ(c);
+     
+     /* Wake up the thread */
+     D1(printk("jffs2_garbage_collect_trigger\n"));
+
+     cyg_flag_setbits(&sb->s_gc_thread_flags,GC_THREAD_FLAG_TRIG);
 }
 
-void jffs2_start_garbage_collect_thread(struct jffs2_sb_info *c)
+
+void 
+jffs2_start_garbage_collect_thread(struct jffs2_sb_info *c)
 {
-	/* Start the thread. Doesn't matter if it fails -- it's only an optimisation anyway */
+     struct super_block *sb=OFNI_BS_2SFFJ(c);
+     
+     CYG_ASSERTC(c);
+     CYG_ASSERTC(!sb->s_gc_thread_handle);
+     
+     cyg_flag_init(&sb->s_gc_thread_flags);
+     cyg_mutex_init(&sb->s_lock);
+     
+     D1(printk("jffs2_start_garbage_collect_thread\n"));
+     /* Start the thread. Doesn't matter if it fails -- it's only an
+      * optimisation anyway */
+     cyg_thread_create(CYGNUM_JFFS2_GC_THREAD_PRIORITY,
+                       jffs2_garbage_collect_thread, 
+                       (cyg_addrword_t)c,"jffs2 gc thread",
+                       (void*)sb->s_gc_thread_stack,
+                       sizeof(sb->s_gc_thread_stack),
+                       &sb->s_gc_thread_handle, 
+                       &sb->s_gc_thread);
+     
+     cyg_thread_resume(sb->s_gc_thread_handle);
 }
 
-void jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c)
+void 
+jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c)
 {
-	/* Stop the thread and wait for it if necessary */
+     struct super_block *sb=OFNI_BS_2SFFJ(c);
+     
+     CYG_ASSERTC(sb->s_gc_thread_handle);
+     
+     D1(printk("jffs2_stop_garbage_collect_thread\n"));
+     /* Stop the thread and wait for it if necessary */
+     
+     cyg_flag_setbits(&sb->s_gc_thread_flags,GC_THREAD_FLAG_STOP);
+     
+     D1(printk("jffs2_stop_garbage_collect_thread wait\n"));
+     
+     cyg_flag_wait(&sb->s_gc_thread_flags,
+                   GC_THREAD_FLAG_HAS_EXIT,
+                   CYG_FLAG_WAITMODE_OR| CYG_FLAG_WAITMODE_CLR);
+     
+     // Kill and free the resources ...  this is safe due to the flag
+     // from the thread.
+     cyg_thread_kill(sb->s_gc_thread_handle);
+     cyg_thread_delete(sb->s_gc_thread_handle);
+     
+     cyg_mutex_destroy(&sb->s_lock);
+     cyg_flag_destroy(&sb->s_gc_thread_flags);
 }
 
 
-static void jffs2_garbage_collect_thread(struct jffs2_sb_info *c)
+static void
+jffs2_garbage_collect_thread(cyg_addrword_t data)
 {
-#define this_thread_should_die() 0
-	while(!this_thread_should_die()) {
-		while(!jffs2_thread_should_wake(c)) {
-			/* Sleep.... */
-			continue;
-		}
-		if (jffs2_garbage_collect_pass(c) == -ENOSPC) {
-			printf("No space for garbage collection. Aborting JFFS2 GC thread\n");
-			break;
-		}
-	}
+     struct jffs2_sb_info *c=(struct jffs2_sb_info *)data;
+     struct super_block *sb=OFNI_BS_2SFFJ(c);
+     cyg_flag_value_t flag;
+     cyg_mtab_entry *mte;
+     
+     D1(printk("jffs2_garbage_collect_thread START\n"));
+     
+     while(1) {
+          flag=cyg_flag_timed_wait(&sb->s_gc_thread_flags,
+                                   GC_THREAD_FLAG_TRIG|GC_THREAD_FLAG_STOP,
+                                   CYG_FLAG_WAITMODE_OR| CYG_FLAG_WAITMODE_CLR,
+                                   cyg_current_time()+
+                                   CYGNUM_JFFS2_GS_THREAD_TICKS);
+          
+          if (flag & GC_THREAD_FLAG_STOP)
+               break;
+          
+          D1(printk("jffs2: GC THREAD GC BEGIN\n"));
+
+          mte=cyg_fs_root_lookup((cyg_dir *) sb->s_root);
+          CYG_ASSERT(mte, "Bad mount point");
+          cyg_fs_lock(mte, mte->fs->syncmode);
+          
+          if (jffs2_garbage_collect_pass(c) == -ENOSPC) {
+               printf("No space for garbage collection. "
+                      "Aborting JFFS2 GC thread\n");
+               break;
+          }
+          cyg_fs_unlock(mte, mte->fs->syncmode);
+          D1(printk("jffs2: GC THREAD GC END\n"));
+     }
+     
+     D1(printk("jffs2_garbage_collect_thread EXIT\n"));
+     cyg_flag_setbits(&sb->s_gc_thread_flags,GC_THREAD_FLAG_HAS_EXIT);
 }

Index: os-ecos.h
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/ecos/src/os-ecos.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- os-ecos.h	12 Nov 2004 16:49:18 -0000	1.22
+++ os-ecos.h	22 Jan 2005 16:01:12 -0000	1.23
@@ -127,6 +127,19 @@
 	struct _inode *		s_root;
         unsigned long		s_mount_count;
 	cyg_io_handle_t		s_dev;
+
+#ifdef CYGOPT_FS_JFFS2_GCTHREAD
+	cyg_mutex_t s_lock;             // Lock the inode cache
+	cyg_flag_t  s_gc_thread_flags;  // Communication with the gcthread
+	cyg_handle_t s_gc_thread_handle; 
+	cyg_thread s_gc_thread;
+#if (CYGNUM_JFFS2_GC_THREAD_STACK_SIZE >= CYGNUM_HAL_STACK_SIZE_MINIMUM)
+        char s_gc_thread_stack[CYGNUM_JFFS2_GC_THREAD_STACK_SIZE];
+#else
+        char s_gc_thread_stack[CYGNUM_HAL_STACK_SIZE_MINIMUM];
+#endif
+       cyg_mtab_entry *mte;
+#endif
 };
 
 #define sleep_on_spinunlock(wq, sl) spin_unlock(sl)





More information about the linux-mtd-cvs mailing list