Changeset 86ef0df in rtems


Ignore:
Timestamp:
May 9, 2012, 12:33:51 PM (7 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
25f814c
Parents:
84ab4fce
git-author:
Sebastian Huber <sebastian.huber@…> (05/09/12 12:33:51)
git-committer:
Sebastian Huber <sebastian.huber@…> (05/11/12 11:58:43)
Message:

dosfs: Remove fat_file_datasync()

The fat_file_datasync() read every cluster of the file into the cache
and then synchronized it step-by-step. For unmodified buffers this is a
non-operation. For modified buffers this will wake-up the swapout task
which performs then a single buffer write operation. This is usually
quite inefficient. Firstly we do single buffer writes, secondly we
may perform a lot of unnecessary read operations (for huge files this is
really bad), and thirdly this leads likely to cache evictions.

The synchronization procedure is replaced by a simple
rtems_bdbuf_sync_dev(). This has the side-effect that also buffers not
related to the file are synchronized, but since the modified list is
normally short this should be acceptable.

Files:
4 added
10 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libfs/src/dosfs/fat_file.c

    r84ab4fce r86ef0df  
    775775}
    776776
    777 /* fat_file_datasync --
    778  *     Synchronize fat-file -  flush all buffered data to the media.
    779  *
    780  * PARAMETERS:
    781  *     mt_entry - mount table entry
    782  *     fat_fd   - fat-file descriptor
    783  *
    784  * RETURNS:
    785  *     RC_OK on success, or -1 if error occured and errno set appropriately
    786  */
    787 int
    788 fat_file_datasync(
    789     rtems_filesystem_mount_table_entry_t *mt_entry,
    790     fat_file_fd_t                        *fat_fd
    791     )
    792 {
    793     int                 rc = RC_OK;
    794     rtems_status_code   sc = RTEMS_SUCCESSFUL;
    795     fat_fs_info_t      *fs_info = mt_entry->fs_info;
    796     uint32_t            cur_cln = fat_fd->cln;
    797     rtems_bdbuf_buffer *block = NULL;
    798     uint32_t            sec = 0;
    799     uint32_t            i = 0;
    800 
    801     if (fat_fd->fat_file_size == 0)
    802         return RC_OK;
    803 
    804     /*
    805      * we can use only one bdbuf :( and we also know that cache is useless
    806      * for sync operation, so don't use it
    807      */
    808     rc = fat_buf_release(fs_info);
    809     if (rc != RC_OK)
    810         return rc;
    811 
    812     /* for each cluster of the file ... */
    813     while ((cur_cln & fs_info->vol.mask) < fs_info->vol.eoc_val)
    814     {
    815         sec = fat_cluster_num_to_sector_num(mt_entry, cur_cln);
    816         /* for each sector in cluster ... */
    817         for ( i = 0; i < fs_info->vol.spc; i++ )
    818         {
    819             /* ... sync it */
    820             sc = rtems_bdbuf_read(fs_info->vol.dd, (sec + i), &block);
    821             if (sc != RTEMS_SUCCESSFUL)
    822                 rtems_set_errno_and_return_minus_one( EIO );
    823 
    824             sc = rtems_bdbuf_sync(block);
    825             if ( sc != RTEMS_SUCCESSFUL )
    826                 rtems_set_errno_and_return_minus_one( EIO );
    827         }
    828 
    829         rc = fat_get_fat_cluster(mt_entry, cur_cln, &cur_cln);
    830         if ( rc != RC_OK )
    831             return rc;
    832     }
    833     return rc;
    834 }
    835 
    836777/* fat_file_size --
    837778 *     Calculate fat-file size - fat-file is nothing that clusters chain, so
  • cpukit/libfs/src/dosfs/fat_file.h

    r84ab4fce r86ef0df  
    169169
    170170int
    171 fat_file_datasync(rtems_filesystem_mount_table_entry_t *mt_entry,
    172                   fat_file_fd_t                        *fat_fd);
    173 
    174 
    175 int
    176171fat_file_ioctl(rtems_filesystem_mount_table_entry_t *mt_entry,
    177172               fat_file_fd_t                        *fat_fd,
  • cpukit/libfs/src/dosfs/msdos.h

    r84ab4fce r86ef0df  
    400400);
    401401
     402int msdos_sync_unprotected(msdos_fs_info_t *fs_info);
     403
     404int msdos_sync(rtems_libio_t *iop);
     405
    402406#ifdef __cplusplus
    403407}
  • cpukit/libfs/src/dosfs/msdos_dir.c

    r84ab4fce r86ef0df  
    458458 *
    459459 */
    460 
    461 /* msdos_dir_sync --
    462  *     The following routine does a syncronization on a MSDOS directory node.
    463  *     DIR_WrtTime, DIR_WrtDate and DIR_fileSize fields of 32 Bytes Directory
    464  *     Entry Structure should not be updated for directories, so only call
    465  *     to corresponding fat-file routine.
    466  *
    467  * PARAMETERS:
    468  *     iop - file control block
    469  *
    470  * RETURNS:
    471  *     RC_OK on success, or -1 if error occured (errno set apropriately).
    472  */
    473 int
    474 msdos_dir_sync(rtems_libio_t *iop)
    475 {
    476     int                rc = RC_OK;
    477     rtems_status_code  sc = RTEMS_SUCCESSFUL;
    478     fat_file_fd_t     *fat_fd = iop->pathinfo.node_access;
    479     msdos_fs_info_t   *fs_info = iop->pathinfo.mt_entry->fs_info;
    480 
    481     sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
    482                                 MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
    483     if (sc != RTEMS_SUCCESSFUL)
    484         rtems_set_errno_and_return_minus_one(EIO);
    485 
    486     rc = fat_file_datasync(iop->pathinfo.mt_entry, fat_fd);
    487 
    488     rtems_semaphore_release(fs_info->vol_sema);
    489     return rc;
    490 }
  • cpukit/libfs/src/dosfs/msdos_file.c

    r84ab4fce r86ef0df  
    2828#include "msdos.h"
    2929
    30 /* msdos_file_close --
    31  *     Close fat-file which correspondes to the file. If fat-file descriptor
    32  *     which correspondes to the file is not marked "removed", synchronize
    33  *     size, first cluster number, write time and date fields of the file.
    34  *
    35  * PARAMETERS:
    36  *     iop - file control block
    37  *
    38  * RETURNS:
    39  *     RC_OK, if file closed successfully, or -1 if error occured (errno set
    40  *     appropriately)
    41  */
    42 int
    43 msdos_file_close(rtems_libio_t *iop)
    44 {
    45     int                rc = RC_OK;
    46     rtems_status_code  sc = RTEMS_SUCCESSFUL;
    47     msdos_fs_info_t   *fs_info = iop->pathinfo.mt_entry->fs_info;
    48     fat_file_fd_t     *fat_fd = iop->pathinfo.node_access;
    49 
    50     sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
    51                                 MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
    52     if (sc != RTEMS_SUCCESSFUL)
    53         rtems_set_errno_and_return_minus_one(EIO);
     30static int
     31msdos_file_update(rtems_libio_t *iop)
     32{
     33    int              rc = RC_OK;
     34    fat_file_fd_t   *fat_fd = iop->pathinfo.node_access;
    5435
    5536    /*
     
    6243        if (rc != RC_OK)
    6344        {
    64             rtems_semaphore_release(fs_info->vol_sema);
    6545            return rc;
    6646        }
     
    6949        if (rc != RC_OK)
    7050        {
    71             rtems_semaphore_release(fs_info->vol_sema);
    7251            return rc;
    7352        }
     
    7655        if (rc != RC_OK)
    7756        {
    78             rtems_semaphore_release(fs_info->vol_sema);
    7957            return rc;
    8058        }
    8159    }
     60
     61    return rc;
     62}
     63
     64/* msdos_file_close --
     65 *     Close fat-file which correspondes to the file. If fat-file descriptor
     66 *     which correspondes to the file is not marked "removed", synchronize
     67 *     size, first cluster number, write time and date fields of the file.
     68 *
     69 * PARAMETERS:
     70 *     iop - file control block
     71 *
     72 * RETURNS:
     73 *     RC_OK, if file closed successfully, or -1 if error occured (errno set
     74 *     appropriately)
     75 */
     76int
     77msdos_file_close(rtems_libio_t *iop)
     78{
     79    int                rc = RC_OK;
     80    rtems_status_code  sc = RTEMS_SUCCESSFUL;
     81    msdos_fs_info_t   *fs_info = iop->pathinfo.mt_entry->fs_info;
     82
     83    sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
     84                                MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
     85    if (sc != RTEMS_SUCCESSFUL)
     86        rtems_set_errno_and_return_minus_one(EIO);
     87
     88    rc = msdos_file_update(iop);
    8289
    8390    rtems_semaphore_release(fs_info->vol_sema);
     
    277284        rtems_set_errno_and_return_minus_one(EIO);
    278285
    279     /* synchronize file data */
    280     rc = fat_file_datasync(iop->pathinfo.mt_entry, fat_fd);
     286    rc = msdos_file_update(iop);
    281287    if (rc != RC_OK)
    282288    {
     
    285291    }
    286292
    287     /*
    288      * if fat-file descriptor is not marked "removed" - synchronize file
    289      * metadata
    290      */
    291     if (!FAT_FILE_IS_REMOVED(fat_fd))
    292     {
    293         rc = msdos_set_first_cluster_num(iop->pathinfo.mt_entry, fat_fd);
    294         if (rc != RC_OK)
    295         {
    296             rtems_semaphore_release(fs_info->vol_sema);
    297             return rc;
    298         }
    299         rc = msdos_set_file_size(iop->pathinfo.mt_entry, fat_fd);
    300         if (rc != RC_OK)
    301         {
    302             rtems_semaphore_release(fs_info->vol_sema);
    303             return rc;
    304         }
    305         rc = msdos_set_dir_wrt_time_and_date(iop->pathinfo.mt_entry, fat_fd);
    306         if (rc != RC_OK)
    307         {
    308             rtems_semaphore_release(fs_info->vol_sema);
    309             return rc;
    310         }
    311     }
     293    rc = msdos_sync_unprotected(fs_info);
    312294
    313295    rtems_semaphore_release(fs_info->vol_sema);
    314296    return RC_OK;
    315297}
    316 
    317 /* msdos_file_datasync --
    318  *     Synchronize file - synchronize only file data (metadata is letf intact).
    319  *
    320  * PARAMETERS:
    321  *     iop - file control block
    322  *
    323  * RETURNS:
    324  *     RC_OK on success, or -1 if error occured (errno set appropriately)
    325  */
    326 int
    327 msdos_file_datasync(rtems_libio_t *iop)
    328 {
    329     rtems_status_code  sc = RTEMS_SUCCESSFUL;
    330     fat_file_fd_t     *fat_fd = iop->pathinfo.node_access;
    331     msdos_fs_info_t   *fs_info = iop->pathinfo.mt_entry->fs_info;
    332 
    333     sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
    334                                 MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
    335     if (sc != RTEMS_SUCCESSFUL)
    336         rtems_set_errno_and_return_minus_one(EIO);
    337 
    338     /* synchronize file data */
    339     fat_file_datasync(iop->pathinfo.mt_entry, fat_fd);
    340 
    341     rtems_semaphore_release(fs_info->vol_sema);
    342     return RC_OK;
    343 }
  • cpukit/libfs/src/dosfs/msdos_handlers_dir.c

    r84ab4fce r86ef0df  
    2828    msdos_dir_stat,
    2929    rtems_filesystem_default_ftruncate_directory,
    30     msdos_dir_sync,
    31     msdos_dir_sync,
     30    msdos_sync,
     31    msdos_sync,
    3232    rtems_filesystem_default_fcntl
    3333};
  • cpukit/libfs/src/dosfs/msdos_handlers_file.c

    r84ab4fce r86ef0df  
    2929    msdos_file_ftruncate,
    3030    msdos_file_sync,
    31     msdos_file_datasync,
     31    msdos_sync,
    3232    rtems_filesystem_default_fcntl
    3333};
  • cpukit/libfs/src/dosfs/msdos_misc.c

    r84ab4fce r86ef0df  
    16471647    return MSDOS_NAME_NOT_FOUND_ERR;
    16481648}
     1649
     1650int
     1651msdos_sync_unprotected(msdos_fs_info_t *fs_info)
     1652{
     1653    int rc = fat_buf_release(&fs_info->fat);
     1654    rtems_status_code sc = rtems_bdbuf_syncdev(fs_info->fat.vol.dd);
     1655    if (sc != RTEMS_SUCCESSFUL) {
     1656        errno = EIO;
     1657        rc = -1;
     1658    }
     1659
     1660    return rc;
     1661}
     1662
     1663int
     1664msdos_sync(rtems_libio_t *iop)
     1665{
     1666    int                rc = RC_OK;
     1667    rtems_status_code  sc = RTEMS_SUCCESSFUL;
     1668    msdos_fs_info_t   *fs_info = iop->pathinfo.mt_entry->fs_info;
     1669
     1670    sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
     1671                                MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
     1672    if (sc != RTEMS_SUCCESSFUL)
     1673        rtems_set_errno_and_return_minus_one(EIO);
     1674
     1675    rc = msdos_sync_unprotected(fs_info);
     1676
     1677    rtems_semaphore_release(fs_info->vol_sema);
     1678    return rc;
     1679}
  • testsuites/fstests/Makefile.am

    r84ab4fce r86ef0df  
    66
    77SUBDIRS =
     8SUBDIRS += fsdosfssync01
    89SUBDIRS += imfs_fserror
    910SUBDIRS += imfs_fslink
  • testsuites/fstests/configure.ac

    r84ab4fce r86ef0df  
    8080# Explicitly list all Makefiles here
    8181AC_CONFIG_FILES([Makefile
     82fsdosfssync01/Makefile
    8283imfs_fserror/Makefile
    8384imfs_fslink/Makefile
Note: See TracChangeset for help on using the changeset viewer.