[rtems commit] IMFS: Use unprotected chain operations

Joel Sherrill joel at rtems.org
Thu Mar 29 14:14:29 UTC 2012


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue Feb 21 17:24:10 2012 +0100

IMFS: Use unprotected chain operations

Directory entry add or removal operations are protected by the file
system instance lock.  There is no need for protected chain operations.

---

 cpukit/libfs/src/imfs/imfs.h        |   15 +++++++++++++++
 cpukit/libfs/src/imfs/imfs_creat.c  |   17 ++++++++++-------
 cpukit/libfs/src/imfs/imfs_rename.c |   10 ++--------
 cpukit/libfs/src/imfs/imfs_rmnod.c  |    3 +--
 4 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/cpukit/libfs/src/imfs/imfs.h b/cpukit/libfs/src/imfs/imfs.h
index 8d68c07..c2d95f0 100644
--- a/cpukit/libfs/src/imfs/imfs.h
+++ b/cpukit/libfs/src/imfs/imfs.h
@@ -489,6 +489,21 @@ extern int IMFS_rmnod(
   const rtems_filesystem_location_info_t *loc
 );
 
+static inline void IMFS_add_to_directory(
+  IMFS_jnode_t *dir,
+  IMFS_jnode_t *node
+)
+{
+  node->Parent = dir;
+  rtems_chain_append_unprotected( &dir->info.directory.Entries, &node->Node );
+}
+
+static inline void IMFS_remove_from_directory( IMFS_jnode_t *node )
+{
+  node->Parent = NULL;
+  rtems_chain_extract_unprotected( &node->Node );
+}
+
 /*
  *  Turn on IMFS assertions when RTEMS_DEBUG is defined.
  */
diff --git a/cpukit/libfs/src/imfs/imfs_creat.c b/cpukit/libfs/src/imfs/imfs_creat.c
index 4c030a2..caf82be 100644
--- a/cpukit/libfs/src/imfs/imfs_creat.c
+++ b/cpukit/libfs/src/imfs/imfs_creat.c
@@ -22,6 +22,11 @@
 #include <stdlib.h>
 #include <string.h>
 
+static void IMFS_initialize_directory( IMFS_jnode_t *dir )
+{
+  rtems_chain_initialize_empty( &dir->info.directory.Entries );
+}
+
 /*
  *  Create an IMFS filesystem node of an arbitrary type that is NOT
  *  the root directory node.
@@ -39,8 +44,6 @@ IMFS_jnode_t *IMFS_create_node(
   IMFS_jnode_t        *parent;
   IMFS_fs_info_t      *fs_info;
 
-  IMFS_assert( parent_loc != NULL );
-
   parent = parent_loc->node_access;
   fs_info = parent_loc->mt_entry->fs_info;
 
@@ -55,7 +58,7 @@ IMFS_jnode_t *IMFS_create_node(
    *  Set the type specific information
    */
   if ( type == IMFS_DIRECTORY ) {
-    rtems_chain_initialize_empty(&node->info.directory.Entries);
+    IMFS_initialize_directory( node );
   } else if ( type == IMFS_HARD_LINK ) {
     node->info.hard_link.link_node = info->hard_link.link_node;
   } else if ( type == IMFS_SYM_LINK ) {
@@ -80,10 +83,10 @@ IMFS_jnode_t *IMFS_create_node(
   /*
    *  This node MUST have a parent, so put it in that directory list.
    */
-  node->Parent = parent;
-  node->st_ino = ++fs_info->ino_count;
+  IMFS_assert( parent != NULL );
+  IMFS_add_to_directory( parent, node );
 
-  rtems_chain_append( &parent->info.directory.Entries, &node->Node );
+  node->st_ino = ++fs_info->ino_count;
 
   return node;
 }
@@ -165,7 +168,7 @@ IMFS_jnode_t *IMFS_create_root_node(void)
    *
    *  NOTE: Root node is always a directory.
    */
-  rtems_chain_initialize_empty(&node->info.directory.Entries);
+  IMFS_initialize_directory( node );
 
   return node;
 }
diff --git a/cpukit/libfs/src/imfs/imfs_rename.c b/cpukit/libfs/src/imfs/imfs_rename.c
index 855d026..57d1957 100644
--- a/cpukit/libfs/src/imfs/imfs_rename.c
+++ b/cpukit/libfs/src/imfs/imfs_rename.c
@@ -42,14 +42,8 @@ int IMFS_rename(
       memcpy( node->name, name, namelen );
       node->name [namelen] = '\0';
 
-      rtems_chain_extract( &node->Node );
-
-      node->Parent = new_parent;
-      rtems_chain_append(
-        &new_parent->info.directory.Entries,
-        &node->Node
-      );
-
+      IMFS_remove_from_directory( node );
+      IMFS_add_to_directory( new_parent, node );
       IMFS_update_ctime( node );
     } else {
       errno = ENAMETOOLONG;
diff --git a/cpukit/libfs/src/imfs/imfs_rmnod.c b/cpukit/libfs/src/imfs/imfs_rmnod.c
index c500419..ae4d8fb 100644
--- a/cpukit/libfs/src/imfs/imfs_rmnod.c
+++ b/cpukit/libfs/src/imfs/imfs_rmnod.c
@@ -28,8 +28,7 @@
 void IMFS_create_orphan( IMFS_jnode_t *jnode )
 {
   if ( jnode->Parent != NULL ) {
-    rtems_chain_extract( &jnode->Node );
-    jnode->Parent = NULL;
+    IMFS_remove_from_directory( jnode );
   }
 
   --jnode->st_nlink;




More information about the vc mailing list