summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2017-03-16 11:54:29 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2017-03-16 15:33:56 +0100
commit66fac03fae3af9dded964b01c89662819dbfc5c2 (patch)
tree2d866941dc2ae2b633f62cfeec830e34d1e4c059
parentpsxstrsignal01: New test (diff)
downloadrtems-66fac03fae3af9dded964b01c89662819dbfc5c2.tar.bz2
libio: Fix deadlock in location management
Perform a context-dependent deferred location release to avoid a deadlock on the file system instance locks, for example during a chdir(). Update #2936.
-rw-r--r--cpukit/libcsupport/include/rtems/libio_.h5
-rw-r--r--cpukit/libcsupport/src/chdir.c2
-rw-r--r--cpukit/libcsupport/src/chroot.c4
-rw-r--r--cpukit/libcsupport/src/mount.c2
-rw-r--r--cpukit/libcsupport/src/privateenv.c4
-rw-r--r--cpukit/libcsupport/src/sup_fs_eval_path.c4
-rw-r--r--cpukit/libcsupport/src/sup_fs_location.c9
-rw-r--r--testsuites/fstests/fsnofs01/init.c8
8 files changed, 21 insertions, 17 deletions
diff --git a/cpukit/libcsupport/include/rtems/libio_.h b/cpukit/libcsupport/include/rtems/libio_.h
index 0c5e9ed30b..c2fb975bf7 100644
--- a/cpukit/libcsupport/include/rtems/libio_.h
+++ b/cpukit/libcsupport/include/rtems/libio_.h
@@ -507,11 +507,14 @@ rtems_filesystem_global_location_t *rtems_filesystem_global_location_obtain(
* deferred. The next obtain call will do the actual release.
*
* @param[in] global_loc The global file system location. It must not be NULL.
+ * @param[in] deferred If true, then do a deferred release, otherwise release
+ * it immediately.
*
* @see rtems_filesystem_global_location_obtain().
*/
void rtems_filesystem_global_location_release(
- rtems_filesystem_global_location_t *global_loc
+ rtems_filesystem_global_location_t *global_loc,
+ bool deferred
);
void rtems_filesystem_location_detach(
diff --git a/cpukit/libcsupport/src/chdir.c b/cpukit/libcsupport/src/chdir.c
index 4bcb30075e..83a359a982 100644
--- a/cpukit/libcsupport/src/chdir.c
+++ b/cpukit/libcsupport/src/chdir.c
@@ -39,7 +39,7 @@ int rtems_filesystem_chdir( rtems_filesystem_location_info_t *loc )
);
} else {
rtems_filesystem_location_error( &global_loc->location, ENOTDIR );
- rtems_filesystem_global_location_release( global_loc );
+ rtems_filesystem_global_location_release( global_loc, true );
rv = -1;
}
diff --git a/cpukit/libcsupport/src/chroot.c b/cpukit/libcsupport/src/chroot.c
index 9ec4ad470f..0c498e6a6f 100644
--- a/cpukit/libcsupport/src/chroot.c
+++ b/cpukit/libcsupport/src/chroot.c
@@ -80,7 +80,7 @@ int chroot( const char *path )
}
if ( rv != 0 ) {
- rtems_filesystem_global_location_release( new_root_loc );
+ rtems_filesystem_global_location_release( new_root_loc, true );
}
} else {
rv = -1;
@@ -89,7 +89,7 @@ int chroot( const char *path )
rtems_filesystem_eval_path_cleanup( &ctx );
if ( rv != 0 ) {
- rtems_filesystem_global_location_release( new_current_loc );
+ rtems_filesystem_global_location_release( new_current_loc, false );
}
return rv;
diff --git a/cpukit/libcsupport/src/mount.c b/cpukit/libcsupport/src/mount.c
index 0d66477fe3..5328d24e7f 100644
--- a/cpukit/libcsupport/src/mount.c
+++ b/cpukit/libcsupport/src/mount.c
@@ -126,7 +126,7 @@ static int register_subordinate_file_system(
);
rtems_filesystem_mt_unlock();
} else {
- rtems_filesystem_global_location_release( mt_point_node );
+ rtems_filesystem_global_location_release( mt_point_node, true );
}
} else {
rtems_filesystem_eval_path_error( &ctx, EBUSY );
diff --git a/cpukit/libcsupport/src/privateenv.c b/cpukit/libcsupport/src/privateenv.c
index bf6036a1b3..d7f5090c33 100644
--- a/cpukit/libcsupport/src/privateenv.c
+++ b/cpukit/libcsupport/src/privateenv.c
@@ -44,8 +44,8 @@ void rtems_libio_free_user_env(void *arg)
bool uses_global_env = env == &rtems_global_user_env;
if (!uses_global_env) {
- rtems_filesystem_global_location_release(env->current_directory);
- rtems_filesystem_global_location_release(env->root_directory);
+ rtems_filesystem_global_location_release(env->current_directory, false);
+ rtems_filesystem_global_location_release(env->root_directory, false);
free(env);
}
}
diff --git a/cpukit/libcsupport/src/sup_fs_eval_path.c b/cpukit/libcsupport/src/sup_fs_eval_path.c
index 459fa6bfc8..a05472f834 100644
--- a/cpukit/libcsupport/src/sup_fs_eval_path.c
+++ b/cpukit/libcsupport/src/sup_fs_eval_path.c
@@ -301,8 +301,8 @@ void rtems_filesystem_eval_path_cleanup(
{
free_location(&ctx->currentloc);
rtems_filesystem_instance_unlock(&ctx->startloc->location);
- rtems_filesystem_global_location_release(ctx->startloc);
- rtems_filesystem_global_location_release(ctx->rootloc);
+ rtems_filesystem_global_location_release(ctx->startloc, false);
+ rtems_filesystem_global_location_release(ctx->rootloc, false);
}
void rtems_filesystem_eval_path_cleanup_with_parent(
diff --git a/cpukit/libcsupport/src/sup_fs_location.c b/cpukit/libcsupport/src/sup_fs_location.c
index 2b8126ee8b..db40d4f21a 100644
--- a/cpukit/libcsupport/src/sup_fs_location.c
+++ b/cpukit/libcsupport/src/sup_fs_location.c
@@ -106,7 +106,7 @@ void rtems_filesystem_global_location_assign(
*lhs_global_loc_ptr = rhs_global_loc;
rtems_filesystem_mt_entry_unlock(lock_context);
- rtems_filesystem_global_location_release(lhs_global_loc);
+ rtems_filesystem_global_location_release(lhs_global_loc, true);
}
static void release_with_count(
@@ -184,10 +184,11 @@ rtems_filesystem_global_location_t *rtems_filesystem_global_location_obtain(
}
void rtems_filesystem_global_location_release(
- rtems_filesystem_global_location_t *global_loc
+ rtems_filesystem_global_location_t *global_loc,
+ bool deferred
)
{
- if (_Thread_Dispatch_is_enabled()) {
+ if (!deferred) {
release_with_count(global_loc, 1);
} else {
rtems_interrupt_lock_context lock_context;
@@ -233,7 +234,7 @@ void rtems_filesystem_do_unmount(
rtems_filesystem_mt_lock();
rtems_chain_extract_unprotected(&mt_entry->mt_node);
rtems_filesystem_mt_unlock();
- rtems_filesystem_global_location_release(mt_entry->mt_point_node);
+ rtems_filesystem_global_location_release(mt_entry->mt_point_node, false);
(*mt_entry->ops->fsunmount_me_h)(mt_entry);
if (mt_entry->unmount_task != 0) {
diff --git a/testsuites/fstests/fsnofs01/init.c b/testsuites/fstests/fsnofs01/init.c
index ff2c2a8075..37ebac1771 100644
--- a/testsuites/fstests/fsnofs01/init.c
+++ b/testsuites/fstests/fsnofs01/init.c
@@ -74,9 +74,9 @@ static void test_initial_values(void)
rtems_test_assert(null_mt->mt_fs_root == null_loc);
rtems_test_assert(!null_mt->mounted);
rtems_test_assert(!null_mt->writeable);
- rtems_test_assert(null_loc->reference_count == 6);
+ rtems_test_assert(null_loc->reference_count == 4);
rtems_test_assert(null_loc->deferred_released_next == NULL);
- rtems_test_assert(null_loc->deferred_released_count == 2);
+ rtems_test_assert(null_loc->deferred_released_count == 0);
}
static void test_location_obtain(void)
@@ -90,7 +90,7 @@ static void test_location_obtain(void)
rtems_test_assert(node_count(loc_chain) == 1);
rtems_test_assert(null_loc->reference_count == 5);
- rtems_filesystem_global_location_release(null_loc);
+ rtems_filesystem_global_location_release(null_loc, false);
rtems_test_assert(node_count(loc_chain) == 1);
rtems_test_assert(null_loc->reference_count == 4);
@@ -106,7 +106,7 @@ static void test_null_location_obtain(void)
rtems_test_assert(node_count(loc_chain) == 1);
rtems_test_assert(null_loc->reference_count == 5);
- rtems_filesystem_global_location_release(null_loc);
+ rtems_filesystem_global_location_release(null_loc, false);
rtems_test_assert(node_count(loc_chain) == 1);
rtems_test_assert(null_loc->reference_count == 4);