Changeset 25bef0ff in mainline


Ignore:
Timestamp:
2011-05-31T23:04:53Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6a44ee4, e8d5f9f
Parents:
d362410
Message:

Make sure to send VFS_OUT_CLOSE upon dropping the last file reference.

Location:
uspace/srv/vfs
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/vfs/vfs.h

    rd362410 r25bef0ff  
    176176    vfs_pair_t *, ...);
    177177extern int vfs_open_node_internal(vfs_lookup_res_t *);
    178 extern int vfs_close_internal(vfs_file_t *);
    179178
    180179extern bool vfs_nodes_init(void);
  • uspace/srv/vfs/vfs_file.c

    rd362410 r25bef0ff  
    7979        for (i = 0; i < MAX_OPEN_FILES; i++) {
    8080                if (FILES[i]) {
    81                         (void) vfs_close_internal(FILES[i]);
    8281                        (void) vfs_fd_free(i);
    8382                }
     
    108107}
    109108
     109/** Close the file in the endpoint FS server. */
     110static int vfs_file_close_remote(vfs_file_t *file)
     111{
     112        ipc_call_t answer;
     113        aid_t msg;
     114        sysarg_t rc;
     115        int phone;
     116
     117        assert(!file->refcnt);
     118
     119        phone = vfs_grab_phone(file->node->fs_handle);
     120        msg = async_send_2(phone, VFS_OUT_CLOSE, file->node->devmap_handle,
     121            file->node->index, &answer);
     122        async_wait_for(msg, &rc);
     123        vfs_release_phone(file->node->fs_handle, phone);
     124
     125        return IPC_GET_ARG1(answer);
     126}
     127
     128
    110129/** Increment reference count of VFS file structure.
    111130 *
     
    125144 *                      decremented.
    126145 */
    127 static void vfs_file_delref(vfs_file_t *file)
    128 {
     146static int vfs_file_delref(vfs_file_t *file)
     147{
     148        int rc = EOK;
     149
    129150        assert(fibril_mutex_is_locked(&VFS_DATA->lock));
    130151
    131152        if (file->refcnt-- == 1) {
    132153                /*
    133                  * Lost the last reference to a file, need to drop our reference
    134                  * to the underlying VFS node.
     154                 * Lost the last reference to a file, need to close it in the
     155                 * endpoint FS and drop our reference to the underlying VFS node.
    135156                 */
     157                rc = vfs_file_close_remote(file);
    136158                vfs_node_delref(file->node);
    137159                free(file);
    138160        }
     161
     162        return rc;
    139163}
    140164
     
    201225int vfs_fd_free(int fd)
    202226{
     227        int rc;
     228
    203229        if (!vfs_files_init())
    204230                return ENOMEM;
     
    210236        }
    211237       
    212         vfs_file_delref(FILES[fd]);
     238        rc = vfs_file_delref(FILES[fd]);
    213239        FILES[fd] = NULL;
    214240        fibril_mutex_unlock(&VFS_DATA->lock);
    215241       
    216         return EOK;
     242        return rc;
    217243}
    218244
  • uspace/srv/vfs/vfs_ops.c

    rd362410 r25bef0ff  
    717717}
    718718
    719 int vfs_close_internal(vfs_file_t *file)
    720 {
    721         /*
    722          * Lock the open file structure so that no other thread can manipulate
    723          * the same open file at a time.
    724          */
    725         fibril_mutex_lock(&file->lock);
    726        
    727         if (file->refcnt <= 1) {
    728                 /* Only close the file on the destination FS server
    729                    if there are no more file descriptors (except the
    730                    present one) pointing to this file. */
    731                
    732                 int fs_phone = vfs_grab_phone(file->node->fs_handle);
    733                
    734                 /* Make a VFS_OUT_CLOSE request at the destination FS server. */
    735                 aid_t msg;
    736                 ipc_call_t answer;
    737                 msg = async_send_2(fs_phone, VFS_OUT_CLOSE,
    738                     file->node->devmap_handle, file->node->index, &answer);
    739                
    740                 /* Wait for reply from the FS server. */
    741                 sysarg_t rc;
    742                 async_wait_for(msg, &rc);
    743                
    744                 vfs_release_phone(file->node->fs_handle, fs_phone);
    745                 fibril_mutex_unlock(&file->lock);
    746                
    747                 return IPC_GET_ARG1(answer);
    748         }
    749        
    750         fibril_mutex_unlock(&file->lock);
    751         return EOK;
    752 }
    753 
    754719void vfs_close(ipc_callid_t rid, ipc_call_t *request)
    755720{
    756721        int fd = IPC_GET_ARG1(*request);
    757        
    758         /* Lookup the file structure corresponding to the file descriptor. */
    759         vfs_file_t *file = vfs_file_get(fd);
    760         if (!file) {
    761                 async_answer_0(rid, ENOENT);
    762                 return;
    763         }
    764        
    765         int ret = vfs_close_internal(file);
    766         if (ret != EOK)
    767                 async_answer_0(rid, ret);
    768        
    769         vfs_file_put(file);
     722        int ret;
     723       
    770724        ret = vfs_fd_free(fd);
    771725        async_answer_0(rid, ret);
     
    13691323        fibril_mutex_lock(&oldfile->lock);
    13701324       
    1371         /* Lookup an open file structure possibly corresponding to newfd. */
    1372         vfs_file_t *newfile = vfs_file_get(newfd);
    1373         if (newfile) {
    1374                 /* Close the originally opened file. */
    1375                 int ret = vfs_close_internal(newfile);
    1376                 if (ret != EOK) {
    1377                         fibril_mutex_unlock(&oldfile->lock);
    1378                         vfs_file_put(oldfile);
    1379                         vfs_file_put(newfile);
    1380                         async_answer_0(rid, ret);
    1381                         return;
    1382                 }
    1383                
    1384                 ret = vfs_fd_free(newfd);
    1385                 if (ret != EOK) {
    1386                         fibril_mutex_unlock(&oldfile->lock);
    1387                         vfs_file_put(oldfile);
    1388                         vfs_file_put(newfile);
    1389                         async_answer_0(rid, ret);
    1390                         return;
    1391                 }
    1392                 vfs_file_put(newfile);
    1393         }
     1325        /* Make sure newfd is closed. */
     1326        (void) vfs_fd_free(newfd);
    13941327       
    13951328        /* Assign the old file to newfd. */
Note: See TracChangeset for help on using the changeset viewer.