Filesystem: Move operations to mount table entry

The scope of the file system operations is the file system instance.
The scope of the file system node handlers is the file location.  The
benefit of moving the operations to the mount table entry is a size
reduction of the file location (rtems_filesystem_location_info_t).  The
code size is slightly increased due to additional load instructions.

Restructure rtems_filesystem_mount_table_entry_t to improve cache
efficiency.
This commit is contained in:
Sebastian Huber
2012-05-14 16:55:41 +02:00
parent 7666afc97a
commit da154e14f6
39 changed files with 77 additions and 66 deletions

View File

@@ -92,8 +92,8 @@ static int rtems_tfs_mount_me(
rtems_set_errno_and_return_minus_one(ENOMEM);
}
mt_entry->ops = &rtems_tfs_ops;
mt_entry->mt_fs_root->location.handlers = &rtems_tfs_handlers;
mt_entry->mt_fs_root->location.ops = &rtems_tfs_ops;
mt_entry->mt_fs_root->location.node_access = root_path;
return 0;

View File

@@ -53,7 +53,6 @@ typedef struct rtems_filesystem_location_info_tt {
void *node_access;
void *node_access_2;
const rtems_filesystem_file_handlers_r *handlers;
const rtems_filesystem_operations_table *ops;
rtems_filesystem_mount_table_entry_t *mt_entry;
} rtems_filesystem_location_info_t;

View File

@@ -1431,13 +1431,14 @@ extern int rtems_mkdir(const char *path, mode_t mode);
*/
struct rtems_filesystem_mount_table_entry_tt {
rtems_chain_node mt_node;
void *fs_info;
const rtems_filesystem_operations_table *ops;
const void *immutable_fs_info;
rtems_chain_control location_chain;
rtems_filesystem_global_location_t *mt_point_node;
rtems_filesystem_global_location_t *mt_fs_root;
bool mounted;
bool writeable;
void *fs_info;
const void *immutable_fs_info;
rtems_filesystem_limits_and_options_t pathconf_limits_and_options;
/*

View File

@@ -250,14 +250,18 @@ static inline void rtems_filesystem_instance_lock(
const rtems_filesystem_location_info_t *loc
)
{
(*loc->ops->lock_h)( loc->mt_entry );
const rtems_filesystem_mount_table_entry_t *mt_entry = loc->mt_entry;
(*mt_entry->ops->lock_h)( mt_entry );
}
static inline void rtems_filesystem_instance_unlock(
const rtems_filesystem_location_info_t *loc
)
{
(*loc->ops->unlock_h)( loc->mt_entry );
const rtems_filesystem_mount_table_entry_t *mt_entry = loc->mt_entry;
(*mt_entry->ops->unlock_h)( mt_entry );
}
/*
@@ -582,9 +586,11 @@ static inline bool rtems_filesystem_location_is_root(
const rtems_filesystem_location_info_t *loc
)
{
return (*loc->ops->are_nodes_equal_h)(
const rtems_filesystem_mount_table_entry_t *mt_entry = loc->mt_entry;
return (*mt_entry->ops->are_nodes_equal_h)(
loc,
&loc->mt_entry->mt_fs_root->location
&mt_entry->mt_fs_root->location
);
}

View File

@@ -220,6 +220,7 @@ rtems_filesystem_mount_table_entry_t rtems_filesystem_null_mt_entry = {
.fill = &rtems_filesystem_global_location_null.location.mt_entry_node,
}
},
.ops = &null_ops,
.mt_point_node = &rtems_filesystem_global_location_null,
.mt_fs_root = &rtems_filesystem_global_location_null,
.mounted = false,
@@ -233,7 +234,6 @@ rtems_filesystem_global_location_t rtems_filesystem_global_location_null = {
.previous = &rtems_filesystem_null_mt_entry.location_chain.Head.Node
},
.handlers = &rtems_filesystem_null_handlers,
.ops = &null_ops,
.mt_entry = &rtems_filesystem_null_mt_entry
},

View File

@@ -57,7 +57,7 @@ int _rename_r(
new_currentloc
);
if ( rv == 0 ) {
rv = (*new_currentloc->ops->rename_h)(
rv = (*new_currentloc->mt_entry->ops->rename_h)(
&old_parentloc,
old_currentloc,
new_currentloc,

View File

@@ -25,7 +25,7 @@ int chmod( const char *path, mode_t mode )
const rtems_filesystem_location_info_t *currentloc =
rtems_filesystem_eval_path_start( &ctx, path, eval_flags );
rv = (*currentloc->ops->fchmod_h)( currentloc, mode );
rv = (*currentloc->mt_entry->ops->fchmod_h)( currentloc, mode );
rtems_filesystem_eval_path_cleanup( &ctx );

View File

@@ -32,12 +32,9 @@ int rtems_filesystem_chown(
int eval_flags = eval_follow_link;
const rtems_filesystem_location_info_t *currentloc =
rtems_filesystem_eval_path_start( &ctx, path, eval_flags );
const rtems_filesystem_operations_table *ops = currentloc->mt_entry->ops;
rv = (*currentloc->ops->chown_h)(
currentloc,
owner,
group
);
rv = (*ops->chown_h)( currentloc, owner, group );
rtems_filesystem_eval_path_cleanup( &ctx );

View File

@@ -49,7 +49,9 @@ int chroot( const char *path )
rtems_filesystem_global_location_t *new_root_loc =
rtems_filesystem_global_location_obtain( &new_current_loc );
rtems_filesystem_node_types_t type =
(*new_root_loc->location.ops->node_type_h)( &new_root_loc->location );
(*new_root_loc->location.mt_entry->ops->node_type_h)(
&new_root_loc->location
);
if ( type == RTEMS_FILESYSTEM_DIRECTORY ) {
sc = rtems_libio_set_private_env();

View File

@@ -26,7 +26,7 @@ void rtems_filesystem_location_clone(
int rv = 0;
clone = rtems_filesystem_location_copy( clone, master );
rv = (*clone->ops->clonenod_h)( clone );
rv = (*clone->mt_entry->ops->clonenod_h)( clone );
if ( rv != 0 ) {
rtems_filesystem_location_remove_from_mt_entry( clone );
rtems_filesystem_location_initialize_to_null( clone );

View File

@@ -28,7 +28,7 @@ int fchmod( int fd, mode_t mode )
if (iop->pathinfo.mt_entry->writeable) {
rtems_filesystem_instance_lock( &iop->pathinfo );
rv = (*iop->pathinfo.ops->fchmod_h)( &iop->pathinfo, mode );
rv = (*iop->pathinfo.mt_entry->ops->fchmod_h)( &iop->pathinfo, mode );
rtems_filesystem_instance_unlock( &iop->pathinfo );
} else {
errno = EROFS;

View File

@@ -28,7 +28,11 @@ int fchown( int fd, uid_t owner, gid_t group )
if (iop->pathinfo.mt_entry->writeable) {
rtems_filesystem_instance_lock( &iop->pathinfo );
rv = (*iop->pathinfo.ops->chown_h)( &iop->pathinfo, owner, group );
rv = (*iop->pathinfo.mt_entry->ops->chown_h)(
&iop->pathinfo,
owner,
group
);
rtems_filesystem_instance_unlock( &iop->pathinfo );
} else {
errno = EROFS;

View File

@@ -21,7 +21,7 @@
void rtems_filesystem_location_free( rtems_filesystem_location_info_t *loc )
{
rtems_filesystem_instance_lock( loc );
(*loc->ops->freenod_h)( loc );
(*loc->mt_entry->ops->freenod_h)( loc );
rtems_filesystem_instance_unlock( loc );
rtems_filesystem_location_remove_from_mt_entry( loc );
}

View File

@@ -36,7 +36,7 @@ int link( const char *path1, const char *path2 )
currentloc_2
);
if ( rv == 0 ) {
rv = (*currentloc_2->ops->link_h)(
rv = (*currentloc_2->mt_entry->ops->link_h)(
currentloc_2,
currentloc_1,
rtems_filesystem_eval_path_get_token( &ctx_2 ),

View File

@@ -47,7 +47,9 @@ int rtems_filesystem_mknod(
}
if ( rv == 0 ) {
rv = (*parentloc->ops->mknod_h)( parentloc, name, namelen, mode, dev );
const rtems_filesystem_operations_table *ops = parentloc->mt_entry->ops;
rv = (*ops->mknod_h)( parentloc, name, namelen, mode, dev );
}
return rv;

View File

@@ -122,7 +122,7 @@ static int register_subordinate_file_system(
rtems_filesystem_eval_path_extract_currentloc( &ctx, &targetloc );
mt_point_node = rtems_filesystem_location_transform_to_global( &targetloc );
mt_entry->mt_point_node = mt_point_node;
rv = (*mt_point_node->location.ops->mount_h)( mt_entry );
rv = (*mt_point_node->location.mt_entry->ops->mount_h)( mt_entry );
if ( rv == 0 ) {
rtems_filesystem_mt_lock();
rtems_chain_append_unprotected(
@@ -218,7 +218,7 @@ int mount(
}
if ( rv != 0 ) {
(*mt_entry->mt_fs_root->location.ops->fsunmount_me_h)( mt_entry );
(*mt_entry->ops->fsunmount_me_h)( mt_entry );
}
}

View File

@@ -85,7 +85,7 @@ static int do_open(
const rtems_filesystem_location_info_t *currentloc =
rtems_filesystem_eval_path_get_currentloc( &ctx );
rtems_filesystem_node_types_t type =
(*currentloc->ops->node_type_h)( currentloc );
(*currentloc->mt_entry->ops->node_type_h)( currentloc );
if ( type == RTEMS_FILESYSTEM_DIRECTORY ) {
rtems_filesystem_eval_path_error( &ctx, EISDIR );

View File

@@ -24,11 +24,11 @@ ssize_t readlink( const char *path, char *buf, size_t bufsize )
int eval_flags = RTEMS_FS_FOLLOW_HARD_LINK;
const rtems_filesystem_location_info_t *currentloc =
rtems_filesystem_eval_path_start( &ctx, path, eval_flags );
rtems_filesystem_node_types_t type =
(*currentloc->ops->node_type_h)( currentloc );
const rtems_filesystem_operations_table *ops = currentloc->mt_entry->ops;
rtems_filesystem_node_types_t type = (*ops->node_type_h)( currentloc );
if ( type == RTEMS_FILESYSTEM_SYM_LINK ) {
rv = (*currentloc->ops->readlink_h)( currentloc, buf, bufsize );
rv = (*ops->readlink_h)( currentloc, buf, bufsize );
} else {
rtems_filesystem_eval_path_error( &ctx, EINVAL );
rv = -1;

View File

@@ -34,14 +34,11 @@ int rmdir( const char *path )
&parentloc,
parent_eval_flags
);
rtems_filesystem_node_types_t type =
(*currentloc->ops->node_type_h)( currentloc );
const rtems_filesystem_operations_table *ops = currentloc->mt_entry->ops;
rtems_filesystem_node_types_t type = (*ops->node_type_h)( currentloc );
if ( type == RTEMS_FILESYSTEM_DIRECTORY ) {
rv = (*currentloc->ops->rmnod_h)(
&parentloc,
currentloc
);
rv = (*ops->rmnod_h)( &parentloc, currentloc );
} else {
rtems_filesystem_eval_path_error( &ctx, ENOTDIR );
rv = -1;

View File

@@ -29,7 +29,7 @@ int statvfs( const char *path, struct statvfs *buf )
memset( buf, 0, sizeof( *buf ) );
rv = (*currentloc->ops->statvfs_h)( currentloc, buf );
rv = (*currentloc->mt_entry->ops->statvfs_h)( currentloc, buf );
rtems_filesystem_eval_path_cleanup( &ctx );

View File

@@ -104,7 +104,7 @@ void rtems_filesystem_eval_path_continue(
int eval_flags;
while (ctx->pathlen > 0) {
(*ctx->currentloc.ops->eval_path_h)(ctx);
(*ctx->currentloc.mt_entry->ops->eval_path_h)(ctx);
}
eval_flags = rtems_filesystem_eval_path_get_flags(ctx);
@@ -260,7 +260,7 @@ void rtems_filesystem_eval_path_recursive(
++ctx->recursionlevel;
while (ctx->pathlen > 0) {
(*ctx->currentloc.ops->eval_path_h)(ctx);
(*ctx->currentloc.mt_entry->ops->eval_path_h)(ctx);
}
--ctx->recursionlevel;
@@ -297,7 +297,7 @@ static void free_location(rtems_filesystem_location_info_t *loc)
{
rtems_filesystem_mt_entry_declare_lock_context(lock_context);
(*loc->ops->freenod_h)(loc);
(*loc->mt_entry->ops->freenod_h)(loc);
rtems_filesystem_mt_entry_lock(lock_context);
rtems_chain_extract_unprotected(&loc->mt_entry_node);

View File

@@ -20,10 +20,11 @@
static bool is_fs_root( const rtems_filesystem_location_info_t *loc )
{
const rtems_filesystem_mount_table_entry_t *mt_entry = loc->mt_entry;
const rtems_filesystem_location_info_t *mt_fs_root =
&loc->mt_entry->mt_fs_root->location;
&mt_entry->mt_fs_root->location;
return (*loc->ops->are_nodes_equal_h)( loc, mt_fs_root );
return (*mt_entry->ops->are_nodes_equal_h)( loc, mt_fs_root );
}
static bool is_eval_path_root(
@@ -31,10 +32,11 @@ static bool is_eval_path_root(
const rtems_filesystem_location_info_t *loc
)
{
const rtems_filesystem_mount_table_entry_t *mt_entry = loc->mt_entry;
const rtems_filesystem_location_info_t *rootloc = &ctx->rootloc->location;
return loc->mt_entry == rootloc->mt_entry
&& (*loc->ops->are_nodes_equal_h)( loc, rootloc );
return mt_entry == rootloc->mt_entry
&& (*mt_entry->ops->are_nodes_equal_h)( loc, rootloc );
}
void rtems_filesystem_eval_path_generic(

View File

@@ -33,7 +33,6 @@ rtems_filesystem_location_info_t *rtems_filesystem_location_copy(
dst->node_access = src->node_access;
dst->node_access_2 = src->node_access_2;
dst->handlers = src->handlers;
dst->ops = src->ops;
dst->mt_entry = src->mt_entry;
rtems_filesystem_location_add_to_mt_entry(dst);
@@ -213,6 +212,6 @@ void rtems_filesystem_do_unmount(
rtems_chain_extract_unprotected(&mt_entry->mt_node);
rtems_filesystem_mt_unlock();
rtems_filesystem_global_location_release(mt_entry->mt_point_node);
(*mt_entry->mt_fs_root->location.ops->fsunmount_me_h)(mt_entry);
(*mt_entry->ops->fsunmount_me_h)(mt_entry);
free(mt_entry);
}

View File

@@ -25,7 +25,7 @@ rtems_filesystem_node_types_t rtems_filesystem_node_type(
rtems_filesystem_node_types_t type;
rtems_filesystem_instance_lock(loc);
type = (*loc->ops->node_type_h)(loc);
type = (*loc->mt_entry->ops->node_type_h)(loc);
rtems_filesystem_instance_unlock(loc);
return type;

View File

@@ -27,7 +27,7 @@ int symlink( const char *path1, const char *path2 )
const rtems_filesystem_location_info_t *currentloc =
rtems_filesystem_eval_path_start( &ctx, path2, eval_flags );
rv = (*currentloc->ops->symlink_h)(
rv = (*currentloc->mt_entry->ops->symlink_h)(
currentloc,
rtems_filesystem_eval_path_get_token( &ctx ),
rtems_filesystem_eval_path_get_tokenlen( &ctx ),

View File

@@ -34,11 +34,9 @@ int unlink( const char *path )
&parentloc,
parent_eval_flags
);
const rtems_filesystem_operations_table *ops = currentloc->mt_entry->ops;
rv = (*currentloc->ops->rmnod_h)(
&parentloc,
currentloc
);
rv = (*ops->rmnod_h)( &parentloc, currentloc );
rtems_filesystem_eval_path_cleanup_with_parent( &ctx, &parentloc );

View File

@@ -32,7 +32,10 @@ int unmount( const char *path )
rtems_filesystem_mount_table_entry_t *mt_entry = currentloc->mt_entry;
if ( rtems_filesystem_location_is_root( currentloc ) ) {
rv = (*mt_entry->mt_point_node->location.ops->unmount_h)( mt_entry );
const rtems_filesystem_operations_table *mt_point_ops =
mt_entry->mt_point_node->location.mt_entry->ops;
rv = (*mt_point_ops->unmount_h)( mt_entry );
if ( rv == 0 ) {
rtems_filesystem_mt_entry_declare_lock_context( lock_context );

View File

@@ -38,7 +38,7 @@ int utime( const char *path, const struct utimbuf *times )
times = &now_times;
}
rv = (*currentloc->ops->utime_h)(
rv = (*currentloc->mt_entry->ops->utime_h)(
currentloc,
times->actime,
times->modtime

View File

@@ -56,9 +56,9 @@ int devFS_initialize(
int rv = 0;
if (data != NULL) {
mt_entry->ops = &devFS_ops;
mt_entry->immutable_fs_info = data;
mt_entry->mt_fs_root->location.handlers = &devFS_file_handlers;
mt_entry->mt_fs_root->location.ops = &devFS_ops;
} else {
errno = EINVAL;
rv = -1;

View File

@@ -14,7 +14,7 @@ void devFS_Show(void)
{
rtems_filesystem_location_info_t *rootloc = &rtems_filesystem_root->location;
if (rootloc->ops == &devFS_ops) {
if (rootloc->mt_entry->ops == &devFS_ops) {
const devFS_data *data = devFS_get_data(rootloc);
size_t i = 0;
size_t n = data->count;

View File

@@ -141,7 +141,7 @@ msdos_initialize_support(
temp_mt_entry->mt_fs_root->location.node_access = fat_fd;
temp_mt_entry->mt_fs_root->location.handlers = directory_handlers;
temp_mt_entry->mt_fs_root->location.ops = op_table;
temp_mt_entry->ops = op_table;
return rc;
}

View File

@@ -79,9 +79,9 @@ int IMFS_initialize_support(
);
if ( root_node != NULL ) {
mt_entry->fs_info = fs_info;
mt_entry->ops = op_table;
mt_entry->pathconf_limits_and_options = IMFS_LIMITS_AND_OPTIONS;
mt_entry->mt_fs_root->location.node_access = root_node;
mt_entry->mt_fs_root->location.ops = op_table;
IMFS_Set_handlers( &mt_entry->mt_fs_root->location );
} else {
errno = ENOMEM;

View File

@@ -101,7 +101,11 @@ int rtems_tarfs_load(
&ctx,
RTEMS_FS_MAKE | RTEMS_FS_EXCLUSIVE
);
if (rootloc.ops != &IMFS_ops && rootloc.ops != &fifoIMFS_ops) {
if (
rootloc.mt_entry->ops != &IMFS_ops
&& rootloc.mt_entry->ops != &fifoIMFS_ops
) {
rv = -1;
}

View File

@@ -1753,7 +1753,7 @@ char *path = mt_entry->dev;
rootNode = 0;
mt_entry->mt_fs_root->location.ops = &nfs_fs_ops;
mt_entry->ops = &nfs_fs_ops;
mt_entry->mt_fs_root->location.handlers = &nfs_dir_file_handlers;
mt_entry->pathconf_limits_and_options = nfs_limits_and_options;

View File

@@ -918,11 +918,10 @@ rtems_rfs_rtems_initialise (rtems_filesystem_mount_table_entry_t* mt_entry,
return rtems_rfs_rtems_error ("initialise: open", rc);
}
mt_entry->fs_info = fs;
mt_entry->fs_info = fs;
mt_entry->ops = &rtems_rfs_ops;
mt_entry->mt_fs_root->location.node_access = (void*) RTEMS_RFS_ROOT_INO;
mt_entry->mt_fs_root->location.handlers = &rtems_rfs_rtems_dir_handlers;
mt_entry->mt_fs_root->location.ops = &rtems_rfs_ops;
rtems_rfs_rtems_unlock (fs);

View File

@@ -1194,7 +1194,7 @@ int rtems_ftpfs_initialize(
/* Set handler and oparations table */
e->mt_fs_root->location.handlers = &rtems_ftpfs_root_handlers;
e->mt_fs_root->location.ops = &rtems_ftpfs_ops;
e->ops = &rtems_ftpfs_ops;
/* We maintain no real file system nodes, so there is no real root */
e->mt_fs_root->location.node_access = NULL;

View File

@@ -205,7 +205,7 @@ int rtems_tftpfs_initialize(
mt_entry->fs_info = fs;
mt_entry->mt_fs_root->location.node_access = root_path;
mt_entry->mt_fs_root->location.handlers = &rtems_tftp_handlers;
mt_entry->mt_fs_root->location.ops = &rtems_tftp_ops;
mt_entry->ops = &rtems_tftp_ops;
/*
* Now allocate a semaphore for mutual exclusion.

View File

@@ -88,7 +88,6 @@ rtems_bsdnet_makeFdForSocket (void *so)
iop->data0 = fd;
iop->data1 = so;
iop->pathinfo.handlers = &socket_handlers;
iop->pathinfo.ops = &rtems_filesystem_operations_default;
iop->pathinfo.mt_entry = &rtems_filesystem_null_mt_entry;
rtems_filesystem_location_add_to_mt_entry(&iop->pathinfo);
return fd;

View File

@@ -53,7 +53,6 @@ static void rtems_test_assert_equal_to_null_loc(
rtems_test_assert(null_loc->location.node_access == local_loc->node_access);
rtems_test_assert(null_loc->location.node_access_2 == local_loc->node_access_2);
rtems_test_assert(null_loc->location.handlers == local_loc->handlers);
rtems_test_assert(null_loc->location.ops == local_loc->ops);
rtems_test_assert(null_loc->location.mt_entry == local_loc->mt_entry);
}