[ECOS] POSIX close() issue

Steve Strublic SStrublic@hypercom.com
Thu Nov 13 15:29:00 GMT 2003

I'm writing an eCos POSIX file system that as part of its operation, uses the RAM file system to
perform buffered writes.  I've found what appears to be an issue in closing directories (and it
appears files).

My example is this:
-I open a directory from my application, which eventually calls my foo_fo_opendir() function.  This
function then calls opendir() for a RAM file system directory I've created.  This works fine.
-I call closedir() from my application, which eventually calls my foo_fo_close() function.
foo_fo_close() calls closedir() to close the RAM directory.  This hangs the platform.

Here's what I found tracing through code on the close operation:
-closedir() calls close().
-close() calls cyg_fp_get().  This performs a FILEIO_MUTEX_LOCK, gets the file object for the
descriptor, and performs a FILEIO_MUTEX_UNLOCK.
-close() calls cyg_fp_free().
-cyg_fp_free() performs a FILEIO_MUTEX_LOCK(), and calls fp_ucount_dec().
-if decrementing fp->ucount reaches zero, cyg_fp_ucount calls cyg_file_lock().
-cyg_file_lock calls cyg_fs_lock(), and does NOT perform a FILEIO_MUTEX_LOCK since the file's
syncmode is not CYG_SYNCMODE_IO_FILE.
-cyg_file_lock() returns.
-fp_ucount_dec() calls fp->f_ops->fo_close(), which is my foo_fo_close() function.
-foo_fo_close() calls closedir().
-closedir() calls close().
-close() calls cyg_fp_get().
-cyg_fp_get() attempts to perform a FILEIO_MUTEX_LOCK.  However, the mutex is already locked during
the cyg_fp_free() call.
-Platform hangs on a mutex acquire that can never get resolved.

Obviously, if I don't perform the FILEIO_MUTEX_LOCK() in cyg_fp_free(), the logic chain completes
with no mutex wait hangups.

My question is, why perform the FILEIO_MUTEX_LOCK at all in cyg_fp_free()?  cyg_file_lock()
conditionally performs FILEIO_MUTEX_LOCK if the file's syncmode is CYG_SYNCMODE_IO_FILE.

Or why not also condition performing the mutex lock on this same syncmode?

Or am I doing something illegal???


Steve Strublic

"Space is almost infinite.  In fact, we think it is infinite."  -- Dan Quayle

Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

More information about the Ecos-discuss mailing list