[PATCH 2/3] cpukit/jffs2: Implement JFFS2 spinlocks

Kinsey Moore kinsey.moore at oarcorp.com
Fri Oct 6 20:09:05 UTC 2023


This provides a non-noop implementation of spinlocks for JFFS2 in terms
of RTEMS mutexes. POSIX spinlocks are not appropriate for the types of
actions that occur during a held JFFS2 spinlock and can cause bad
dispatch level conditions.
---
 .../libfs/src/jffs2/include/linux/spinlock.h  | 30 ++++---------------
 cpukit/libfs/src/jffs2/src/fs-rtems.c         |  2 ++
 2 files changed, 8 insertions(+), 24 deletions(-)

diff --git a/cpukit/libfs/src/jffs2/include/linux/spinlock.h b/cpukit/libfs/src/jffs2/include/linux/spinlock.h
index 22eba0ba55..44f6b7c53e 100644
--- a/cpukit/libfs/src/jffs2/include/linux/spinlock.h
+++ b/cpukit/libfs/src/jffs2/include/linux/spinlock.h
@@ -1,34 +1,16 @@
 #ifndef __LINUX_SPINLOCK_H__
 #define __LINUX_SPINLOCK_H__
 
+#include <rtems/thread.h>
 
-typedef struct { } spinlock_t;
-#define SPIN_LOCK_UNLOCKED (spinlock_t) { }
-#define DEFINE_SPINLOCK(x) spinlock_t x = SPIN_LOCK_UNLOCKED
+typedef struct { rtems_mutex r_m; } spinlock_t;
 
-#define spin_lock_init(lock)             \
-CYG_MACRO_START;                         \
-CYG_UNUSED_PARAM(spinlock_t *, lock);    \
-CYG_MACRO_END
+#define DEFINE_SPINLOCK(x) spinlock_t x
 
-#define spin_lock(lock)                  \
-CYG_MACRO_START;                         \
-CYG_UNUSED_PARAM(spinlock_t *, lock);    \
-CYG_MACRO_END
+#define spin_lock_init(x) rtems_mutex_init(&(x)->r_m, "JFFS2 Spinlock");
 
-#define spin_unlock(lock)                \
-CYG_MACRO_START;                         \
-CYG_UNUSED_PARAM(spinlock_t *, lock);    \
-CYG_MACRO_END
+#define spin_lock(x) rtems_mutex_lock(&(x)->r_m);
 
-#define spin_lock_bh(lock)               \
-CYG_MACRO_START;                         \
-CYG_UNUSED_PARAM(spinlock_t *, lock);    \
-CYG_MACRO_END
-
-#define spin_unlock_bh(lock)             \
-CYG_MACRO_START;                         \
-CYG_UNUSED_PARAM(spinlock_t *, lock);    \
-CYG_MACRO_END
+#define spin_unlock(x) rtems_mutex_unlock(&(x)->r_m);
 
 #endif /* __LINUX_SPINLOCK_H__ */
diff --git a/cpukit/libfs/src/jffs2/src/fs-rtems.c b/cpukit/libfs/src/jffs2/src/fs-rtems.c
index e47f2e7fd2..0d97e7a6fb 100644
--- a/cpukit/libfs/src/jffs2/src/fs-rtems.c
+++ b/cpukit/libfs/src/jffs2/src/fs-rtems.c
@@ -1384,6 +1384,8 @@ int rtems_jffs2_initialize(
 #ifdef CONFIG_JFFS2_FS_WRITEBUFFER
 		add_delayed_work_to_chain(&c->wbuf_dwork);
 #endif
+		spin_lock_init(&c->erase_completion_lock);
+		spin_lock_init(&c->inocache_lock);
 		c->mtd = NULL;
 		rtems_recursive_mutex_init(&sb->s_mutex, RTEMS_FILESYSTEM_TYPE_JFFS2);
 	}
-- 
2.39.2



More information about the devel mailing list