Ignore:
Timestamp:
May 1, 2019, 5:13:47 PM (3 years ago)
Author:
alain
Message:

Replace the queuelock protectingthe FAT by a rwlock in the FATFS.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/fs/fatfs.c

    r626 r627  
    491491// FS_INFO sector on the IOC device. It can be called by a thead running in any cluster.
    492492//
    493 // WARNING : The free_lock protecting exclusive access to these variables
     493// WARNING : The lock protecting exclusive access to these variables
    494494//           must be taken by the calling function.
    495495//////////////////////////////////////////////////////////////////////////////////////////
     
    618618// FS_INFO sector on the IOC device. It can be called by a thead running in any cluster.
    619619//
    620 // WARNING : The free_lock protecting exclusive access to these variables
     620// WARNING : The lock protecting exclusive access to these variables
    621621//           must be taken by the calling function.
    622622//////////////////////////////////////////////////////////////////////////////////////////
     
    853853    uint32_t   page_count_in_file;     // index of page in file (index in linked list)
    854854    uint32_t   next_cluster_id;        // content of current FAT slot
     855    xptr_t     lock_xp;                // extended pointer on FAT lock
    855856
    856857assert( (searched_page_index > 0) ,
     
    865866#endif
    866867
     868    // get local pointer on VFS context (same in all clusters)
     869    vfs_ctx_t * vfs_ctx = &fs_context[FS_TYPE_FATFS];
     870
    867871    // get local pointer on local FATFS context
    868     fatfs_ctx_t * ctx = fs_context[FS_TYPE_FATFS].extend;
     872    fatfs_ctx_t * loc_fatfs_ctx = vfs_ctx->extend;
    869873
    870874    // get extended pointer and cluster on FAT mapper
    871     xptr_t fat_mapper_xp  = ctx->fat_mapper_xp;
    872     cxy_t  fat_mapper_cxy = GET_CXY( fat_mapper_xp );
     875    xptr_t fat_mapper_xp  = loc_fatfs_ctx->fat_mapper_xp;
     876    cxy_t  fat_cxy        = GET_CXY( fat_mapper_xp );
     877
     878    // get local pointer on FATFS context in FAT cluster
     879    fatfs_ctx_t * fat_fatfs_ctx = hal_remote_lpt( XPTR( fat_cxy , &vfs_ctx->extend ) );
     880
     881    // build extended pointer on FAT lock in FAT cluster
     882    lock_xp = XPTR( fat_cxy , &fat_fatfs_ctx->lock );
     883
     884    // take FAT lock in read mode
     885    remote_rwlock_rd_acquire( lock_xp );
    873886
    874887    // initialize loop variable (1024 slots per page)
     
    887900        {
    888901            printk("\n[ERROR] in %s : cannot get next page from FAT mapper\n", __FUNCTION__);
     902            remote_rwlock_rd_release( lock_xp );
    889903            return -1;
    890904        }
     
    895909
    896910        // get FAT slot content
    897         next_cluster_id = hal_remote_l32( XPTR( fat_mapper_cxy,
    898                                                 &buffer[current_slot_index] ) );
     911        next_cluster_id = hal_remote_l32( XPTR( fat_cxy, &buffer[current_slot_index] ) );
    899912
    900913#if (DEBUG_FATFS_GET_CLUSTER & 1)
     
    904917__FUNCTION__, current_page_index, current_slot_index , next_cluster_id );
    905918#endif
    906 
    907919        // update loop variables
    908920        current_page_index = next_cluster_id >> 10;
     
    914926    {
    915927        printk("\n[ERROR] in %s : searched_cluster_id not found in FAT\n", __FUNCTION__ );
     928        remote_rwlock_rd_release( lock_xp );
    916929        return -1;
    917930    }
    918931   
     932    // release FAT lock
     933    remote_rwlock_rd_release( lock_xp );
     934
    919935#if DEBUG_FATFS_GET_CLUSTER
    920936cycle = (uint32_t)hal_get_cycles();
     
    10931109    fatfs_ctx->fs_info_buffer        = buffer;
    10941110
    1095     remote_queuelock_init( XPTR( local_cxy , &fatfs_ctx->free_lock ) , LOCK_FATFS_FREE );
     1111    remote_rwlock_init( XPTR( local_cxy , &fatfs_ctx->lock ) , LOCK_FATFS_FREE );
    10961112
    10971113#if (DEBUG_FATFS_CTX_INIT & 0x1)
     
    23432359
    23442360    // build relevant extended pointers on free clusters info in mapper cluster
    2345     lock_xp = XPTR( fat_cxy , &fat_fatfs_ctx->free_lock );
     2361    lock_xp = XPTR( fat_cxy , &fat_fatfs_ctx->lock );
    23462362    hint_xp = XPTR( fat_cxy , &fat_fatfs_ctx->free_cluster_hint );
    23472363    free_xp = XPTR( fat_cxy , &fat_fatfs_ctx->free_clusters );
    23482364
    2349     // take the lock protecting free clusters
    2350     remote_queuelock_acquire( lock_xp );
     2365    // take the FAT lock in write mode
     2366    remote_rwlock_wr_acquire( lock_xp );
    23512367
    23522368    // get hint and free_clusters values from FATFS context in FAT cluster
     
    23642380    {
    23652381        printk("\n[ERROR] in %s : no more free FATFS clusters\n", __FUNCTION__ );
    2366         remote_queuelock_acquire( lock_xp );
     2382        remote_rwlock_wr_release( lock_xp );
    23672383        return -1;
    23682384    }
     
    23832399    {
    23842400        printk("\n[ERROR] in %s : cannot acces FAT mapper\n", __FUNCTION__ );
     2401        remote_rwlock_wr_release( lock_xp );
    23852402        return -1;
    23862403    }
     
    23932410    {
    23942411        printk("\n[ERROR] in %s : selected cluster %x not free\n", __FUNCTION__, cluster );
    2395         remote_queuelock_acquire( lock_xp );
     2412        remote_rwlock_wr_release( lock_xp );
    23962413        return -1;
    23972414    }
     
    24032420    {
    24042421        printk("\n[ERROR] in %s : cannot update free cluster info\n", __FUNCTION__ );
    2405         remote_queuelock_acquire( lock_xp );
     2422        remote_rwlock_wr_release( lock_xp );
    24062423        return -1;
    24072424    }
     
    24162433    {
    24172434        printk("\n[ERROR] in %s : cannot update FAT on IOC device\n", __FUNCTION__ );
    2418         remote_queuelock_acquire( lock_xp );
     2435        remote_rwlock_wr_release( lock_xp );
    24192436        return -1;
    24202437    }
    24212438
    2422     // release free clusters busylock
    2423     remote_queuelock_release( lock_xp );
     2439    // release FAT lock
     2440    remote_rwlock_wr_release( lock_xp );
    24242441
    24252442#if DEBUG_FATFS_CLUSTER_ALLOC
     
    24922509    fat_fatfs_ctx = hal_remote_lpt( XPTR( mapper_cxy , &vfs_ctx->extend ) );
    24932510
    2494     // get extended pointer on free clusters lock in FAT cluster
    2495     lock_xp = XPTR( mapper_cxy , &fat_fatfs_ctx->free_lock );
    2496 
    2497     // take lock protecting free clusters
    2498     remote_queuelock_acquire( lock_xp );
     2511    // get extended pointer on FAT lock in FAT cluster
     2512    lock_xp = XPTR( mapper_cxy , &fat_fatfs_ctx->lock );
     2513
     2514    // take FAT lock in write mode
     2515    remote_rwlock_wr_acquire( lock_xp );
    24992516
    25002517    // call the recursive function to release all clusters from FAT mapper
     
    25052522    {
    25062523        printk("\n[ERROR] in %s : cannot update FAT mapper\n", __FUNCTION__ );
    2507         remote_queuelock_release( lock_xp );
     2524        remote_rwlock_wr_release( lock_xp );
    25082525        return -1;
    25092526    }
    2510 
    2511     // release lock protecting free cluster
    2512     remote_queuelock_release( lock_xp );
    25132527
    25142528#if (DEBUG_FATFS_RELEASE_INODE & 1)
     
    25212535    {
    25222536        printk("\n[ERROR] in %s : cannot update FAT on device\n", __FUNCTION__ );
     2537        remote_rwlock_wr_release( lock_xp );
    25232538        return -1;
    25242539    }
     
    25332548    {
    25342549        printk("\n[ERROR] in %s: cannot update FS_INFO on device\n", __FUNCTION__ );
     2550        remote_rwlock_wr_release( lock_xp );
    25352551        return -1;
    25362552    }
     2553
     2554    // release FAT lock
     2555    remote_rwlock_wr_release( lock_xp );
    25372556
    25382557#if DEBUG_FATFS_RELEASE_INODE
Note: See TracChangeset for help on using the changeset viewer.