[PATCH 2/2] JFFS2: Add RTEMS_JFFS2_FORCE_GARBAGE_COLLECTION

Sebastian Huber sebastian.huber at embedded-brains.de
Mon Dec 19 11:37:01 UTC 2016


Add IO control to force a garbage collection.

Update #2844.
---
 cpukit/libfs/src/jffs2/include/rtems/jffs2.h |  6 +++
 cpukit/libfs/src/jffs2/src/fs-rtems.c        |  3 ++
 testsuites/fstests/fsjffs2gc01/init.c        | 57 ++++++++++++++++++++++++++++
 3 files changed, 66 insertions(+)

diff --git a/cpukit/libfs/src/jffs2/include/rtems/jffs2.h b/cpukit/libfs/src/jffs2/include/rtems/jffs2.h
index b2810e2..55e1075 100644
--- a/cpukit/libfs/src/jffs2/include/rtems/jffs2.h
+++ b/cpukit/libfs/src/jffs2/include/rtems/jffs2.h
@@ -555,6 +555,12 @@ typedef struct {
  */
 #define RTEMS_JFFS2_GET_INFO _IOR('F', 1, rtems_jffs2_info)
 
+/**
+ * @brief IO control to force a garbage collection in a JFFS2 filesystem
+ * instance.
+ */
+#define RTEMS_JFFS2_FORCE_GARBAGE_COLLECTION _IO('F', 2)
+
 /** @} */
 
 #ifdef __cplusplus
diff --git a/cpukit/libfs/src/jffs2/src/fs-rtems.c b/cpukit/libfs/src/jffs2/src/fs-rtems.c
index 54e41c6..b76381c 100644
--- a/cpukit/libfs/src/jffs2/src/fs-rtems.c
+++ b/cpukit/libfs/src/jffs2/src/fs-rtems.c
@@ -568,6 +568,9 @@ static int rtems_jffs2_ioctl(
 			rtems_jffs2_get_info(&inode->i_sb->jffs2_sb, buffer);
 			eno = 0;
 			break;
+		case RTEMS_JFFS2_FORCE_GARBAGE_COLLECTION:
+			eno = -jffs2_garbage_collect_pass(&inode->i_sb->jffs2_sb);
+			break;
 		default:
 			eno = EINVAL;
 			break;
diff --git a/testsuites/fstests/fsjffs2gc01/init.c b/testsuites/fstests/fsjffs2gc01/init.c
index df2e986..8b5658c 100644
--- a/testsuites/fstests/fsjffs2gc01/init.c
+++ b/testsuites/fstests/fsjffs2gc01/init.c
@@ -109,6 +109,38 @@ static const rtems_jffs2_info info_some_files_removed = {
   .bad_blocks = 0
 };
 
+static const rtems_jffs2_info info_after_first_gc = {
+  .flash_size = 131072,
+  .flash_blocks = 8,
+  .flash_block_size = 16384,
+  .used_size = 23540,
+  .dirty_size = 30988,
+  .wasted_size = 7368,
+  .free_size = 69176,
+  .bad_size = 0,
+  .clean_blocks = 0,
+  .dirty_blocks = 3,
+  .erasable_blocks = 0,
+  .free_blocks = 5,
+  .bad_blocks = 0
+};
+
+static const rtems_jffs2_info info_after_excessive_gc = {
+  .flash_size = 131072,
+  .flash_blocks = 8,
+  .flash_block_size = 16384,
+  .used_size = 7224,
+  .dirty_size = 0,
+  .wasted_size = 12,
+  .free_size = 123836,
+  .bad_size = 0,
+  .clean_blocks = 0,
+  .dirty_blocks = 0,
+  .erasable_blocks = 0,
+  .free_blocks = 8,
+  .bad_blocks = 0
+};
+
 static char big[] = "big";
 
 static const char * const more[] = {
@@ -225,6 +257,7 @@ void test(void)
 {
   int fd;
   int rv;
+  int counter;
   rtems_jffs2_info info;
 
   init_keg();
@@ -246,6 +279,30 @@ void test(void)
   remove_some_files();
   ASSERT_INFO(&info, &info_some_files_removed);
 
+  rv = ioctl(fd, RTEMS_JFFS2_FORCE_GARBAGE_COLLECTION);
+  rtems_test_assert(rv == 0);
+  ASSERT_INFO(&info, &info_after_first_gc);
+
+  counter = 0;
+
+  while (true) {
+    errno = ENXIO;
+    rv = ioctl(fd, RTEMS_JFFS2_FORCE_GARBAGE_COLLECTION);
+    if (rv == -1) {
+      rtems_test_assert(errno == EIO);
+      break;
+    }
+
+    ++counter;
+    rtems_test_assert(rv == 0);
+  }
+
+  rtems_test_assert(counter == 19);
+
+  rv = ioctl(fd, RTEMS_JFFS2_GET_INFO, &info);
+  rtems_test_assert(rv == 0);
+  ASSERT_INFO(&info, &info_after_excessive_gc);
+
   rv = close(fd);
   rtems_test_assert(rv == 0);
 }
-- 
1.8.4.5




More information about the devel mailing list