summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKinsey Moore <kinsey.moore@oarcorp.com>2023-11-08 15:55:38 -0600
committerJoel Sherrill <joel@rtems.org>2023-12-22 19:51:52 -0600
commitefc36cb467984f142b9fdec22042b768a1da16bd (patch)
tree0681ef27c287ee7af9fd1fc8724737350a7b00f8
parentfstests/tftpfs: Use rtems_test_run() (diff)
downloadrtems-efc36cb467984f142b9fdec22042b768a1da16bd.tar.bz2
cpukit/jffs2: Revert to non-granular locking
Revert JFFS2 to non-granular locking. This makes the superblock available to the delayed work that it owns so that delayed work processing can ensure that shared resources are being exclusively accessed. This change only affects NAND systems. Moving forward with granular locking will require a significant investment of time in producing a test harness that doesn't require hardware such that this can get a reasonable amount of test coverage.
-rw-r--r--cpukit/libfs/src/jffs2/include/linux/mutex.h31
-rw-r--r--cpukit/libfs/src/jffs2/include/linux/rwsem.h16
-rw-r--r--cpukit/libfs/src/jffs2/include/linux/spinlock.h30
-rw-r--r--cpukit/libfs/src/jffs2/include/linux/workqueue.h2
-rw-r--r--cpukit/libfs/src/jffs2/src/fs-rtems.c5
-rw-r--r--cpukit/libfs/src/jffs2/src/os-rtems.h4
6 files changed, 61 insertions, 27 deletions
diff --git a/cpukit/libfs/src/jffs2/include/linux/mutex.h b/cpukit/libfs/src/jffs2/include/linux/mutex.h
index be8709f125..cc82a3f17a 100644
--- a/cpukit/libfs/src/jffs2/include/linux/mutex.h
+++ b/cpukit/libfs/src/jffs2/include/linux/mutex.h
@@ -1,19 +1,30 @@
#ifndef __LINUX_MUTEX_H
#define __LINUX_MUTEX_H
-#include <rtems/thread.h>
-
-struct mutex { rtems_mutex r_m; };
+struct mutex { };
#define DEFINE_MUTEX(m) struct mutex m
-#define mutex_init(m) rtems_mutex_init(&(m)->r_m, "JFFS2 Mutex");
-
-#define mutex_lock(m) rtems_mutex_lock(&(m)->r_m);
-
-#define mutex_lock_interruptible(m) ({ mutex_lock(m); 0; })
-
-#define mutex_unlock(m) rtems_mutex_unlock(&(m)->r_m);
+static inline void mutex_init(struct mutex *m)
+{
+ (void) m;
+}
+
+static inline void mutex_lock(struct mutex *m)
+{
+ (void) m;
+}
+
+static inline int mutex_lock_interruptible(struct mutex *m)
+{
+ (void) m;
+ return 0;
+}
+
+static inline void mutex_unlock(struct mutex *m)
+{
+ (void) m;
+}
#define mutex_is_locked(m) 1
diff --git a/cpukit/libfs/src/jffs2/include/linux/rwsem.h b/cpukit/libfs/src/jffs2/include/linux/rwsem.h
index 9db6d45ad2..e59e1cede3 100644
--- a/cpukit/libfs/src/jffs2/include/linux/rwsem.h
+++ b/cpukit/libfs/src/jffs2/include/linux/rwsem.h
@@ -1,20 +1,16 @@
#ifndef __LINUX_RWSEM_H__
#define __LINUX_RWSEM_H__
-#include <pthread.h>
+struct rw_semaphore {};
-struct rw_semaphore {
- pthread_rwlock_t lock;
-};
+#define init_rwsem(rwsem)
-#define init_rwsem(rwsem) pthread_rwlock_init(&(rwsem)->lock, NULL)
+#define down_read(rwsem)
-#define down_read(rwsem) pthread_rwlock_rdlock(&(rwsem)->lock)
+#define down_write(rwsem)
-#define down_write(rwsem) pthread_rwlock_wrlock(&(rwsem)->lock)
+#define up_read(rwsem)
-#define up_read(rwsem) pthread_rwlock_unlock(&(rwsem)->lock)
-
-#define up_write(rwsem) pthread_rwlock_unlock(&(rwsem)->lock)
+#define up_write(rwsem)
#endif /* __LINUX_RWSEM_H__ */
diff --git a/cpukit/libfs/src/jffs2/include/linux/spinlock.h b/cpukit/libfs/src/jffs2/include/linux/spinlock.h
index 44f6b7c53e..22eba0ba55 100644
--- a/cpukit/libfs/src/jffs2/include/linux/spinlock.h
+++ b/cpukit/libfs/src/jffs2/include/linux/spinlock.h
@@ -1,16 +1,34 @@
#ifndef __LINUX_SPINLOCK_H__
#define __LINUX_SPINLOCK_H__
-#include <rtems/thread.h>
-typedef struct { rtems_mutex r_m; } spinlock_t;
+typedef struct { } spinlock_t;
+#define SPIN_LOCK_UNLOCKED (spinlock_t) { }
+#define DEFINE_SPINLOCK(x) spinlock_t x = SPIN_LOCK_UNLOCKED
-#define DEFINE_SPINLOCK(x) spinlock_t x
+#define spin_lock_init(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_lock(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_unlock(lock) \
+CYG_MACRO_START; \
+CYG_UNUSED_PARAM(spinlock_t *, lock); \
+CYG_MACRO_END
-#define spin_unlock(x) rtems_mutex_unlock(&(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
#endif /* __LINUX_SPINLOCK_H__ */
diff --git a/cpukit/libfs/src/jffs2/include/linux/workqueue.h b/cpukit/libfs/src/jffs2/include/linux/workqueue.h
index dceb328417..9811c7cd3e 100644
--- a/cpukit/libfs/src/jffs2/include/linux/workqueue.h
+++ b/cpukit/libfs/src/jffs2/include/linux/workqueue.h
@@ -24,6 +24,8 @@ struct delayed_work {
volatile bool pending;
volatile uint64_t execution_time;
work_callback_t callback;
+ /* Superblock provided for locking */
+ struct super_block *sb;
};
#define to_delayed_work(work) RTEMS_CONTAINER_OF(work, struct delayed_work, work)
diff --git a/cpukit/libfs/src/jffs2/src/fs-rtems.c b/cpukit/libfs/src/jffs2/src/fs-rtems.c
index 8e8dfe8b0c..8191dffe53 100644
--- a/cpukit/libfs/src/jffs2/src/fs-rtems.c
+++ b/cpukit/libfs/src/jffs2/src/fs-rtems.c
@@ -1307,7 +1307,9 @@ static void process_delayed_work(void)
work->pending = false;
mutex_unlock(&work->dw_mutex);
+ rtems_jffs2_do_lock(work->sb);
work->callback(&work->work);
+ rtems_jffs2_do_unlock(work->sb);
}
mutex_unlock(&delayed_work_mutex);
}
@@ -1382,6 +1384,7 @@ int rtems_jffs2_initialize(
sb = &fs_info->sb;
c = JFFS2_SB_INFO(sb);
#ifdef CONFIG_JFFS2_FS_WRITEBUFFER
+ c->wbuf_dwork.sb = sb;
add_delayed_work_to_chain(&c->wbuf_dwork);
#endif
spin_lock_init(&c->erase_completion_lock);
@@ -1523,7 +1526,7 @@ static struct _inode *new_inode(struct super_block *sb)
inode->i_cache_next = NULL; // Newest inode, about to be cached
- mutex_init(&JFFS2_INODE_INFO(inode)->sem)
+ mutex_init(&JFFS2_INODE_INFO(inode)->sem);
// Add to the icache
for (cached_inode = sb->s_root; cached_inode != NULL;
diff --git a/cpukit/libfs/src/jffs2/src/os-rtems.h b/cpukit/libfs/src/jffs2/src/os-rtems.h
index 63841a5e50..4bc6f5df13 100644
--- a/cpukit/libfs/src/jffs2/src/os-rtems.h
+++ b/cpukit/libfs/src/jffs2/src/os-rtems.h
@@ -100,6 +100,10 @@ struct _inode {
struct super_block {
struct jffs2_sb_info jffs2_sb;
+ /*
+ * If granular locking is ever enabled for JFFS2, the inode cache
+ * (s_root) needs to be protected due to NAND delayed writes.
+ */
struct _inode * s_root;
rtems_jffs2_flash_control *s_flash_control;
rtems_jffs2_compressor_control *s_compressor_control;