JFFS2: Use self-contained recursive mutex

Update #2843.
This commit is contained in:
Sebastian Huber
2017-12-13 06:18:28 +01:00
parent 16fc3f9a54
commit b17bcb3855
3 changed files with 16 additions and 40 deletions

View File

@@ -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

View File

@@ -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);
}
@@ -1244,6 +1234,10 @@ int rtems_jffs2_initialize(
sb = &fs_info->sb;
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;
@@ -1260,18 +1254,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;

View File

@@ -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];
};