[rtems commit] JFFS2: Use self-contained recursive mutex

Sebastian Huber sebh at rtems.org
Fri Feb 2 14:22:39 UTC 2018


Module:    rtems
Branch:    master
Commit:    b17bcb3855abff75117811fce528b26eb65539a0
Changeset: http://git.rtems.org/rtems/commit/?id=b17bcb3855abff75117811fce528b26eb65539a0

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Dec 13 06:18:28 2017 +0100

JFFS2: Use self-contained recursive mutex

Update #2843.

---

 cpukit/include/rtems/confdefs.h       |  9 +------
 cpukit/libfs/src/jffs2/src/fs-rtems.c | 44 +++++++++++------------------------
 cpukit/libfs/src/jffs2/src/os-rtems.h |  3 ++-
 3 files changed, 16 insertions(+), 40 deletions(-)

diff --git a/cpukit/include/rtems/confdefs.h b/cpukit/include/rtems/confdefs.h
index 0bd3479..affd497 100755
--- a/cpukit/include/rtems/confdefs.h
+++ b/cpukit/include/rtems/confdefs.h
@@ -449,14 +449,8 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
 #if !defined(CONFIGURE_FILESYSTEM_ENTRY_JFFS2) && \
     defined(CONFIGURE_FILESYSTEM_JFFS2)
   #include <rtems/jffs2.h>
-  #if !defined(CONFIGURE_MAXIMUM_JFFS2_MOUNTS)
-    #define CONFIGURE_MAXIMUM_JFFS2_MOUNTS 1
-  #endif
   #define CONFIGURE_FILESYSTEM_ENTRY_JFFS2 \
     { RTEMS_FILESYSTEM_TYPE_JFFS2, rtems_jffs2_initialize }
-  #define _CONFIGURE_SEMAPHORES_FOR_JFFS2 CONFIGURE_MAXIMUM_JFFS2_MOUNTS
-#else
-  #define _CONFIGURE_SEMAPHORES_FOR_JFFS2 0
 #endif
 
 /**
@@ -467,8 +461,7 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
     (_CONFIGURE_SEMAPHORES_FOR_FIFOS + \
      _CONFIGURE_SEMAPHORES_FOR_NFS + \
      _CONFIGURE_SEMAPHORES_FOR_DOSFS + \
-     _CONFIGURE_SEMAPHORES_FOR_RFS + \
-     _CONFIGURE_SEMAPHORES_FOR_JFFS2)
+     _CONFIGURE_SEMAPHORES_FOR_RFS)
 
 #ifdef CONFIGURE_INIT
 
diff --git a/cpukit/libfs/src/jffs2/src/fs-rtems.c b/cpukit/libfs/src/jffs2/src/fs-rtems.c
index 262bec9..652a8e7 100644
--- a/cpukit/libfs/src/jffs2/src/fs-rtems.c
+++ b/cpukit/libfs/src/jffs2/src/fs-rtems.c
@@ -315,18 +315,14 @@ typedef struct {
 	struct jffs2_inode_cache *inode_cache[];
 } rtems_jffs2_fs_info;
 
-static void rtems_jffs2_do_lock(const struct super_block *sb)
+static void rtems_jffs2_do_lock(struct super_block *sb)
 {
-	rtems_status_code sc = rtems_semaphore_obtain(sb->s_mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
-	assert(sc == RTEMS_SUCCESSFUL);
-	(void) sc; /* avoid unused variable warning */
+	rtems_recursive_mutex_lock(&sb->s_mutex);
 }
 
-static void rtems_jffs2_do_unlock(const struct super_block *sb)
+static void rtems_jffs2_do_unlock(struct super_block *sb)
 {
-	rtems_status_code sc = rtems_semaphore_release(sb->s_mutex);
-	assert(sc == RTEMS_SUCCESSFUL);
-	(void) sc; /* avoid unused variable warning */
+	rtems_recursive_mutex_unlock(&sb->s_mutex);
 }
 
 static void rtems_jffs2_free_directory_entries(struct _inode *inode)
@@ -366,15 +362,9 @@ static void rtems_jffs2_free_fs_info(rtems_jffs2_fs_info *fs_info, bool do_mount
 		free(c->blocks);
 	}
 
-	if (sb->s_mutex != 0) {
-		rtems_status_code sc = rtems_semaphore_delete(sb->s_mutex);
-		assert(sc == RTEMS_SUCCESSFUL);
-		(void) sc; /* avoid unused variable warning */
-	}
-
 	rtems_jffs2_flash_control_destroy(fs_info->sb.s_flash_control);
 	rtems_jffs2_compressor_control_destroy(fs_info->sb.s_compressor_control);
-
+	rtems_recursive_mutex_destroy(&sb->s_mutex);
 	free(fs_info);
 }
 
@@ -883,16 +873,16 @@ static const rtems_filesystem_eval_path_generic_config rtems_jffs2_eval_config =
 
 static void rtems_jffs2_lock(const rtems_filesystem_mount_table_entry_t *mt_entry)
 {
-	const rtems_jffs2_fs_info *fs_info = mt_entry->fs_info;
-	const struct super_block *sb = &fs_info->sb;
+	rtems_jffs2_fs_info *fs_info = mt_entry->fs_info;
+	struct super_block *sb = &fs_info->sb;
 
 	rtems_jffs2_do_lock(sb);
 }
 
 static void rtems_jffs2_unlock(const rtems_filesystem_mount_table_entry_t *mt_entry)
 {
-	const rtems_jffs2_fs_info *fs_info = mt_entry->fs_info;
-	const struct super_block *sb = &fs_info->sb;
+	rtems_jffs2_fs_info *fs_info = mt_entry->fs_info;
+	struct super_block *sb = &fs_info->sb;
 
 	rtems_jffs2_do_unlock(sb);
 }
@@ -1245,6 +1235,10 @@ int rtems_jffs2_initialize(
 	c = JFFS2_SB_INFO(sb);
 
 	if (err == 0) {
+		rtems_recursive_mutex_init(&sb->s_mutex, RTEMS_FILESYSTEM_TYPE_JFFS2);
+	}
+
+	if (err == 0) {
 		uint32_t blocks = fc->flash_size / fc->block_size;
 
 		if ((fc->block_size * blocks) != fc->flash_size) {
@@ -1261,18 +1255,6 @@ int rtems_jffs2_initialize(
 	}
 
 	if (err == 0) {
-		rtems_status_code sc = rtems_semaphore_create(
-			rtems_build_name('J', 'F', 'F', 'S'),
-			1,
-			RTEMS_PRIORITY | RTEMS_INHERIT_PRIORITY | RTEMS_BINARY_SEMAPHORE,
-			0,
-			&sb->s_mutex
-		);
-
-		err = sc == RTEMS_SUCCESSFUL ? 0 : -ENOMEM;
-	}
-
-	if (err == 0) {
 		sb->s_is_readonly = !mt_entry->writeable;
 		sb->s_flash_control = fc;
 		sb->s_compressor_control = jffs2_mount_data->compressor_control;
diff --git a/cpukit/libfs/src/jffs2/src/os-rtems.h b/cpukit/libfs/src/jffs2/src/os-rtems.h
index 8dbde68..ab4f6d7 100644
--- a/cpukit/libfs/src/jffs2/src/os-rtems.h
+++ b/cpukit/libfs/src/jffs2/src/os-rtems.h
@@ -32,6 +32,7 @@
 #include <time.h>
 
 #include <rtems/jffs2.h>
+#include <rtems/thread.h>
 
 #define CONFIG_JFFS2_RTIME
 
@@ -104,7 +105,7 @@ struct super_block {
 	rtems_jffs2_compressor_control	*s_compressor_control;
 	bool			s_is_readonly;
 	unsigned char		s_gc_buffer[PAGE_CACHE_SIZE]; // Avoids malloc when user may be under memory pressure
-	rtems_id		s_mutex;
+	rtems_recursive_mutex	s_mutex;
 	char			s_name_buf[JFFS2_MAX_NAME_LEN];
 };
 



More information about the vc mailing list