Changeset c577a9a in mainline


Ignore:
Timestamp:
2017-03-05T20:23:05Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
354b642
Parents:
1dff985
git-author:
Jiri Zarevucky <zarevucky.jiri@…> (2017-03-05 20:23:05)
git-committer:
Jakub Jermar <jakub@…> (2017-03-05 20:23:05)
Message:

Merge from lp:~zarevucky-jiri/helenos/vfs-2.5 revisions 1929-1930

Location:
uspace/srv/vfs
Files:
4 edited

Legend:

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

    r1dff985 rc577a9a  
    129129typedef struct {
    130130        /** Serializes access to this open file. */
    131         fibril_mutex_t lock;
     131        fibril_mutex_t _lock;
    132132
    133133        vfs_node_t *node;
     
    202202extern void vfs_file_put(vfs_file_t *);
    203203extern int vfs_fd_assign(vfs_file_t *, int);
    204 extern int vfs_fd_alloc(bool desc);
     204extern int vfs_fd_alloc(vfs_file_t **file, bool desc);
    205205extern int vfs_fd_free(int);
    206206
  • uspace/srv/vfs/vfs_file.c

    r1dff985 rc577a9a  
    187187}
    188188
    189 static int _vfs_fd_alloc(vfs_client_data_t *vfs_data, bool desc)
     189static int _vfs_fd_alloc(vfs_client_data_t *vfs_data, vfs_file_t **file, bool desc)
    190190{
    191191        if (!vfs_files_init(vfs_data))
     
    207207                        }
    208208                       
     209                       
    209210                        memset(vfs_data->files[i], 0, sizeof(vfs_file_t));
    210                         fibril_mutex_initialize(&vfs_data->files[i]->lock);
     211                       
     212                        fibril_mutex_initialize(&vfs_data->files[i]->_lock);
     213                        fibril_mutex_lock(&vfs_data->files[i]->_lock);
    211214                        vfs_file_addref(vfs_data, vfs_data->files[i]);
     215                       
     216                        *file = vfs_data->files[i];
     217                        vfs_file_addref(vfs_data, *file);
     218                       
    212219                        fibril_mutex_unlock(&vfs_data->lock);
    213220                        return (int) i;
     
    233240/** Allocate a file descriptor.
    234241 *
     242 * @param file Is set to point to the newly created file structure. Must be put afterwards.
    235243 * @param desc If true, look for an available file descriptor
    236244 *             in a descending order.
     
    239247 *         code.
    240248 */
    241 int vfs_fd_alloc(bool desc)
    242 {
    243         return _vfs_fd_alloc(VFS_DATA, desc);
     249int vfs_fd_alloc(vfs_file_t **file, bool desc)
     250{
     251        return _vfs_fd_alloc(VFS_DATA, file, desc);
    244252}
    245253
     
    314322                        vfs_file_addref(vfs_data, file);
    315323                        fibril_mutex_unlock(&vfs_data->lock);
     324                        fibril_mutex_lock(&file->_lock);
    316325                        return file;
    317326                }
     
    335344static void _vfs_file_put(vfs_client_data_t *vfs_data, vfs_file_t *file)
    336345{
     346        fibril_mutex_unlock(&file->_lock);
     347       
    337348        fibril_mutex_lock(&vfs_data->lock);
    338349        vfs_file_delref(vfs_data, file);
     
    376387                goto out;
    377388
    378         acceptor_fd = _vfs_fd_alloc(acceptor_data, false);
     389        acceptor_fd = _vfs_fd_alloc(acceptor_data, &acceptor_file, false);
    379390        if (acceptor_fd < 0)
    380391                goto out;
     
    388399        (void) vfs_open_node_remote(donor_file->node);
    389400
    390         acceptor_file = _vfs_file_get(acceptor_data, acceptor_fd);
    391401        assert(acceptor_file);
    392402
  • uspace/srv/vfs/vfs_ops.c

    r1dff985 rc577a9a  
    500500        vfs_node_t *node = vfs_node_get(&lr);
    501501       
    502         int fd = vfs_fd_alloc(false);
     502        vfs_file_t *file;
     503        int fd = vfs_fd_alloc(&file, false);
    503504        if (fd < 0) {
    504505                vfs_node_put(node);
     
    509510                return;
    510511        }
    511        
    512         vfs_file_t *file = vfs_file_get(fd);
    513512        assert(file != NULL);
    514513       
     
    598597         * the same open file at a time.
    599598         */
    600         fibril_mutex_lock(&file->lock);
    601599        async_exch_t *fs_exch = vfs_exchange_grab(file->node->fs_handle);
    602600       
     
    612610        sysarg_t rc;
    613611        async_wait_for(msg, &rc);
    614        
    615         fibril_mutex_unlock(&file->lock);
    616612       
    617613        vfs_file_put(file);
     
    702698                return ENOENT;
    703699       
    704         /*
    705          * Lock the open file structure so that no other thread can manipulate
    706          * the same open file at a time.
    707          */
    708         fibril_mutex_lock(&file->lock);
    709        
    710700        if ((read && !file->open_read) || (!read && !file->open_write)) {
    711                 fibril_mutex_unlock(&file->lock);
     701                vfs_file_put(file);
    712702                return EINVAL;
    713703        }
     
    770760        if (rc == EOK)
    771761                file->pos += bytes;
    772         fibril_mutex_unlock(&file->lock);
    773762        vfs_file_put(file);     
    774763
     
    812801                return;
    813802        }
    814        
    815         fibril_mutex_lock(&file->lock);
    816803       
    817804        off64_t newoff;
     
    820807                if (off >= 0) {
    821808                        file->pos = (aoff64_t) off;
    822                         fibril_mutex_unlock(&file->lock);
    823809                        vfs_file_put(file);
    824810                        async_answer_1(rid, EOK, off);
     
    828814        case SEEK_CUR:
    829815                if ((off >= 0) && (file->pos + off < file->pos)) {
    830                         fibril_mutex_unlock(&file->lock);
    831816                        vfs_file_put(file);
    832817                        async_answer_0(rid, EOVERFLOW);
     
    835820               
    836821                if ((off < 0) && (file->pos < (aoff64_t) -off)) {
    837                         fibril_mutex_unlock(&file->lock);
    838822                        vfs_file_put(file);
    839823                        async_answer_0(rid, EOVERFLOW);
     
    844828                newoff = (file->pos > OFF64_MAX) ? OFF64_MAX : file->pos;
    845829               
    846                 fibril_mutex_unlock(&file->lock);
    847830                vfs_file_put(file);
    848831                async_answer_2(rid, EOK, LOWER32(newoff),
     
    855838                if ((off >= 0) && (size + off < size)) {
    856839                        fibril_rwlock_read_unlock(&file->node->contents_rwlock);
    857                         fibril_mutex_unlock(&file->lock);
    858840                        vfs_file_put(file);
    859841                        async_answer_0(rid, EOVERFLOW);
     
    863845                if ((off < 0) && (size < (aoff64_t) -off)) {
    864846                        fibril_rwlock_read_unlock(&file->node->contents_rwlock);
    865                         fibril_mutex_unlock(&file->lock);
    866847                        vfs_file_put(file);
    867848                        async_answer_0(rid, EOVERFLOW);
     
    873854               
    874855                fibril_rwlock_read_unlock(&file->node->contents_rwlock);
    875                 fibril_mutex_unlock(&file->lock);
    876856                vfs_file_put(file);
    877857                async_answer_2(rid, EOK, LOWER32(newoff), UPPER32(newoff));
     
    879859        }
    880860       
    881         fibril_mutex_unlock(&file->lock);
    882861        vfs_file_put(file);
    883862        async_answer_0(rid, EINVAL);
     
    908887                return;
    909888        }
    910         fibril_mutex_lock(&file->lock);
    911889
    912890        fibril_rwlock_write_lock(&file->node->contents_rwlock);
     
    917895        fibril_rwlock_write_unlock(&file->node->contents_rwlock);
    918896
    919         fibril_mutex_unlock(&file->lock);
    920897        vfs_file_put(file);
    921898        async_answer_0(rid, (sysarg_t)rc);
     
    932909                return;
    933910        }
     911        assert(file->node);
    934912
    935913        ipc_callid_t callid;
     
    941919        }
    942920
    943         fibril_mutex_lock(&file->lock);
    944 
    945921        async_exch_t *exch = vfs_exchange_grab(file->node->fs_handle);
     922        assert(exch);
    946923       
    947924        aid_t msg;
    948925        msg = async_send_3(exch, VFS_OUT_STAT, file->node->service_id,
    949926            file->node->index, true, NULL);
     927        assert(msg);
    950928        async_forward_fast(callid, exch, 0, 0, 0, IPC_FF_ROUTE_FROM_ME);
    951929       
     
    954932        async_wait_for(msg, &rc);
    955933       
    956         fibril_mutex_unlock(&file->lock);
    957934        vfs_file_put(file);
    958935        async_answer_0(rid, rc);
     
    989966        int lflag = (wflag&WALK_DIRECTORY) ? L_DIRECTORY: 0;
    990967
    991         if (parentfd >= 0) {
     968        /* Files are retrieved in order of file descriptors, to prevent deadlock. */
     969        if (parentfd >= 0 && parentfd < expectfd) {
    992970                parent = vfs_file_get(parentfd);
    993971                if (!parent) {
     
    995973                        goto exit;
    996974                }
    997                 parent_node = parent->node;
    998975        }
    999976       
     
    1004981                        goto exit;
    1005982                }
    1006                
     983        }
     984       
     985        if (parentfd >= 0 && parentfd >= expectfd) {
     986                parent = vfs_file_get(parentfd);
     987                if (!parent) {
     988                        rc = ENOENT;
     989                        goto exit;
     990                }
     991        }
     992       
     993        if (parent) {
     994                parent_node = parent->node;
     995        }
     996       
     997        if (expectfd >= 0) {
    1007998                vfs_lookup_res_t lr;
    1008999                rc = vfs_lookup_internal(parent_node, path, lflag, &lr);
     
    12281219        }
    12291220       
    1230         /*
    1231          * Lock the open file structure so that no other thread can manipulate
    1232          * the same open file at a time.
    1233          */
    1234         fibril_mutex_lock(&oldfile->lock);
    1235        
    12361221        /* Make sure newfd is closed. */
    12371222        (void) vfs_fd_free(newfd);
     
    12391224        /* Assign the old file to newfd. */
    12401225        int ret = vfs_fd_assign(oldfile, newfd);
    1241         fibril_mutex_unlock(&oldfile->lock);
    12421226        vfs_file_put(oldfile);
    12431227       
  • uspace/srv/vfs/vfs_pager.c

    r1dff985 rc577a9a  
    7171        };
    7272
    73         fibril_mutex_lock(&file->lock);
    7473        file->pos = offset;
    75         fibril_mutex_unlock(&file->lock);
    7674
    7775        size_t total = 0;
Note: See TracChangeset for help on using the changeset viewer.