Changeset b7c62a9 in mainline


Ignore:
Timestamp:
2013-07-29T11:44:35Z (11 years ago)
Author:
Jiri Zarevucky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
677745a
Parents:
9e9b168
Message:

Make the server oblivious to the link count. It is just another source of potential problems. Also clean up some confusion with file types and node refcount.

Location:
uspace
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/fs/libfs.c

    r9e9b168 rb7c62a9  
    203203        service_id_t service_id = (service_id_t) IPC_GET_ARG1(*req);
    204204        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*req);
     205
    205206        int rc;
    206 
    207         rc = vfs_out_ops->destroy(service_id, index);
    208 
     207        fs_node_t *node = NULL;
     208        rc = libfs_ops->node_get(&node, service_id, index);
     209        if (rc == EOK && node != NULL) {
     210                bool destroy = (libfs_ops->lnkcnt_get(node) == 0);
     211                libfs_ops->node_put(node);
     212                if (destroy) {
     213                        rc = vfs_out_ops->destroy(service_id, index);
     214                }
     215        }
    209216        async_answer_0(rid, rc);
    210217}
     
    769776                        async_answer_5(rid, fs_handle, service_id,
    770777                            ops->index_get(cur), LOWER32(size), UPPER32(size),
    771                             ops->lnkcnt_get(cur));
     778                            ops->is_directory(cur) ? VFS_NODE_DIRECTORY : VFS_NODE_FILE);
    772779                        LOG_EXIT(EOK);
    773780                } else {
     
    831838        async_answer_5(rid, fs_handle, service_id,
    832839                ops->index_get(cur), LOWER32(size), UPPER32(size),
    833                 ops->lnkcnt_get(cur));
     840                ops->is_directory(cur) ? VFS_NODE_DIRECTORY : VFS_NODE_FILE);
    834841       
    835842        LOG_EXIT(EOK);
  • uspace/srv/vfs/vfs.h

    r9e9b168 rb7c62a9  
    9494        vfs_node_type_t type;
    9595        aoff64_t size;
    96         unsigned int lnkcnt;
    9796} vfs_lookup_res_t;
    9897
     
    110109        unsigned refcnt;
    111110       
    112         /** Number of names this node has in the file system namespace. */
    113         unsigned lnkcnt;
    114 
    115111        ht_link_t nh_link;              /**< Node hash-table link. */
    116112
  • uspace/srv/vfs/vfs_lookup.c

    r9e9b168 rb7c62a9  
    280280        result->size =
    281281            (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(answer), IPC_GET_ARG4(answer));
    282         result->lnkcnt = (unsigned int) IPC_GET_ARG5(answer);
    283        
    284         if (lflag & L_FILE)
    285                 result->type = VFS_NODE_FILE;
    286         else if (lflag & L_DIRECTORY)
    287                 result->type = VFS_NODE_DIRECTORY;
    288         else
    289                 result->type = VFS_NODE_UNKNOWN;
    290 
     282        result->type = IPC_GET_ARG5(answer);
    291283        rc = EOK;
    292284
  • uspace/srv/vfs/vfs_node.c

    r9e9b168 rb7c62a9  
    106106void vfs_node_delref(vfs_node_t *node)
    107107{
    108         bool free_vfs_node = false;
    109         bool free_fs_node = false;
    110        
    111         fibril_mutex_lock(&nodes_mutex);
    112        
    113         if (node->refcnt-- == 1) {
     108        bool free_node = false;
     109       
     110        fibril_mutex_lock(&nodes_mutex);
     111       
     112        node->refcnt--;
     113        if (node->refcnt == 0) {
    114114               
    115115                /*
     
    119119               
    120120                hash_table_remove_item(&nodes, &node->nh_link);
    121                 free_vfs_node = true;
    122                
    123                 if (!node->lnkcnt)
    124                         free_fs_node = true;
     121                free_node = true;
    125122        }
    126123       
    127124        fibril_mutex_unlock(&nodes_mutex);
    128125       
    129         if (free_fs_node) {
    130                
     126        if (free_node) {
    131127                /*
    132                  * The node is not visible in the file system namespace.
    133                  * Free up its resources.
     128                 * DESTROY will free up the file's resources if there are no more hard links.
    134129                 */
    135130               
    136131                async_exch_t *exch = vfs_exchange_grab(node->fs_handle);
    137                 sysarg_t rc = async_req_2_0(exch, VFS_OUT_DESTROY,
    138                     (sysarg_t) node->service_id, (sysarg_t)node->index);
    139                
    140                 assert(rc == EOK);
     132                async_msg_2(exch, VFS_OUT_DESTROY,
     133                        (sysarg_t) node->service_id, (sysarg_t)node->index);
    141134                vfs_exchange_release(exch);
     135
     136                free(node);
    142137        }
    143        
    144         if (free_vfs_node)
    145                 free(node);
    146138}
    147139
     
    190182                node->index = result->triplet.index;
    191183                node->size = result->size;
    192                 node->lnkcnt = result->lnkcnt;
    193184                node->type = result->type;
    194185                fibril_rwlock_initialize(&node->contents_rwlock);
     
    196187        } else {
    197188                node = hash_table_get_inst(tmp, vfs_node_t, nh_link);
    198                 if (node->type == VFS_NODE_UNKNOWN &&
    199                     result->type != VFS_NODE_UNKNOWN) {
    200                         /* Upgrade the node type. */
    201                         node->type = result->type;
    202                 }
    203189        }
    204 
    205         assert(node->size == result->size || node->type != VFS_NODE_FILE);
    206         assert(node->lnkcnt == result->lnkcnt);
    207         assert(node->type == result->type || result->type == VFS_NODE_UNKNOWN);
    208190
    209191        _vfs_node_addref(node);
  • uspace/srv/vfs/vfs_ops.c

    r9e9b168 rb7c62a9  
    7979        fs_index_t rindex;
    8080        aoff64_t rsize;
    81         unsigned rlnkcnt;
    8281        async_exch_t *exch;
    8382        sysarg_t rc;
     
    130129                rsize = (aoff64_t) MERGE_LOUP32(IPC_GET_ARG2(answer),
    131130                    IPC_GET_ARG3(answer));
    132                 rlnkcnt = (unsigned) IPC_GET_ARG4(answer);
    133131               
    134132                mr_res.triplet.fs_handle = fs_handle;
     
    136134                mr_res.triplet.index = rindex;
    137135                mr_res.size = rsize;
    138                 mr_res.lnkcnt = rlnkcnt;
    139136                mr_res.type = VFS_NODE_DIRECTORY;
    140137                       
     
    237234                rsize = (aoff64_t) MERGE_LOUP32(IPC_GET_ARG2(answer),
    238235                    IPC_GET_ARG3(answer));
    239                 rlnkcnt = (unsigned) IPC_GET_ARG4(answer);
    240236               
    241237                mr_res.triplet.fs_handle = fs_handle;
     
    243239                mr_res.triplet.index = rindex;
    244240                mr_res.size = rsize;
    245                 mr_res.lnkcnt = rlnkcnt;
    246241                mr_res.type = VFS_NODE_DIRECTORY;
    247242               
     
    668663        file->open_write = false;
    669664       
    670         vfs_node_addref(node);
    671         vfs_node_put(node);
    672665        vfs_file_put(file);
    673666        if (parent) {
     
    858851        size_t bytes = IPC_GET_ARG1(answer);
    859852       
    860         if (file->node->type == VFS_NODE_DIRECTORY)
     853        if (file->node->type == VFS_NODE_DIRECTORY) {
    861854                fibril_rwlock_read_unlock(&namespace_rwlock);
     855        }
    862856       
    863857        /* Unlock the VFS node. */
     
    11201114         * VFS_OUT_DESTROY'ed after the last reference to it is dropped.
    11211115         */
    1122         vfs_node_t *node = vfs_node_get(&lr);
    1123         vfs_node_delref(node);
    1124         vfs_node_put(node);
     1116        vfs_node_put(vfs_node_get(&lr));
    11251117
    11261118exit:
     
    12251217       
    12261218        if (orig_unlinked) {
    1227                 vfs_node_t *node = vfs_node_get(&new_lr_orig);
    1228                 vfs_node_delref(node);
    1229                 vfs_node_put(node);
     1219                vfs_node_put(vfs_node_get(&new_lr_orig));
    12301220        }
    12311221       
Note: See TracChangeset for help on using the changeset viewer.