Changeset 27b76ca in mainline


Ignore:
Timestamp:
2011-08-18T14:05:10Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
44451ee
Parents:
b33ec43
Message:

Synchronize VFS handle acceptor with VFS.

  • Introduce VFS_IN_WAIT_HANDLE.
  • Add vfs_wait_handle() to VFS.
  • Add fd_wait() to libc.
  • Use fd_wait() in loader.
Location:
uspace
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/vfs/vfs.c

    rb33ec43 r27b76ca  
    815815}
    816816
     817int fd_wait(void)
     818{
     819        async_exch_t *exch = vfs_exchange_begin();
     820       
     821        sysarg_t ret;
     822        sysarg_t rc = async_req_0_1(exch, VFS_IN_WAIT_HANDLE, &ret);
     823       
     824        vfs_exchange_end(exch);
     825       
     826        if (rc == EOK)
     827                return (int) ret;
     828       
     829        return (int) rc;
     830}
     831
    817832/** @}
    818833 */
  • uspace/lib/c/include/ipc/vfs.h

    rb33ec43 r27b76ca  
    7777        VFS_IN_RENAME,
    7878        VFS_IN_STAT,
    79         VFS_IN_DUP
     79        VFS_IN_DUP,
     80        VFS_IN_WAIT_HANDLE,
    8081} vfs_in_request_t;
    8182
  • uspace/lib/c/include/vfs/vfs.h

    rb33ec43 r27b76ca  
    5555extern int fhandle(FILE *, int *);
    5656
     57extern int fd_wait(void);
     58
    5759extern async_exch_t *vfs_exchange_begin(void);
    5860extern void vfs_exchange_end(async_exch_t *);
  • uspace/srv/loader/main.c

    rb33ec43 r27b76ca  
    242242        for (filc = 0; filc < count; filc++) {
    243243                ipc_callid_t callid;
     244                int fd;
    244245
    245246                if (!async_state_change_receive(&callid, NULL, NULL, NULL)) {
     
    248249                }
    249250                async_state_change_finalize(callid, vfs_exch);
     251                fd = fd_wait();
     252                assert(fd == (int) filc);
    250253        }
    251254
  • uspace/srv/vfs/vfs.c

    rb33ec43 r27b76ca  
    118118                case VFS_IN_DUP:
    119119                        vfs_dup(callid, &call);
     120                        break;
     121                case VFS_IN_WAIT_HANDLE:
     122                        vfs_wait_handle(callid, &call);
     123                        break;
    120124                default:
    121125                        async_answer_0(callid, ENOTSUP);
  • uspace/srv/vfs/vfs.h

    rb33ec43 r27b76ca  
    189189
    190190extern void vfs_pass_handle(sysarg_t, sysarg_t, int);
     191extern int vfs_wait_handle_internal(void);
    191192
    192193extern vfs_file_t *vfs_file_get(int);
     
    215216extern void vfs_unlink(ipc_callid_t, ipc_call_t *);
    216217extern void vfs_rename(ipc_callid_t, ipc_call_t *);
     218extern void vfs_wait_handle(ipc_callid_t, ipc_call_t *);
    217219
    218220#endif
  • uspace/srv/vfs/vfs_file.c

    rb33ec43 r27b76ca  
    4343#include <fibril.h>
    4444#include <fibril_synch.h>
     45#include <adt/list.h>
    4546#include "vfs.h"
    4647
     
    5051typedef struct {
    5152        fibril_mutex_t lock;
     53        fibril_condvar_t cv;
     54        list_t passed_handles;
    5255        vfs_file_t **files;
    5356} vfs_client_data_t;
     57
     58typedef struct {
     59        link_t link;
     60        int handle;
     61} vfs_boxed_handle_t;
    5462
    5563static int _vfs_fd_free(vfs_client_data_t *, int);
     
    8593       
    8694        free(vfs_data->files);
     95
     96        while (!list_empty(&vfs_data->passed_handles)) {
     97                link_t *lnk;
     98                vfs_boxed_handle_t *bh;
     99               
     100                lnk = list_first(&vfs_data->passed_handles);
     101                list_remove(lnk);
     102
     103                bh = list_get_instance(lnk, vfs_boxed_handle_t, link);
     104                free(bh);
     105        }
    87106}
    88107
     
    94113        if (vfs_data) {
    95114                fibril_mutex_initialize(&vfs_data->lock);
     115                fibril_condvar_initialize(&vfs_data->cv);
     116                list_initialize(&vfs_data->passed_handles);
    96117                vfs_data->files = NULL;
    97118        }
     
    331352        vfs_file_t *donor_file = NULL;
    332353        vfs_file_t *acceptor_file = NULL;
     354        vfs_boxed_handle_t *bh;
    333355        int acceptor_fd;
     356
     357        acceptor_data = async_get_client_data_by_hash(acceptor_hash);
     358        if (!acceptor_data)
     359                return;
     360
     361        bh = malloc(sizeof(vfs_boxed_handle_t));
     362        assert(bh);
     363
     364        link_initialize(&bh->link);
     365        bh->handle = -1;
    334366
    335367        donor_data = async_get_client_data_by_hash(donor_hash);
    336368        if (!donor_data)
    337                 return;
    338         acceptor_data = async_get_client_data_by_hash(acceptor_hash);
    339         if (!acceptor_data)
    340369                goto out;
    341370
     
    347376        if (acceptor_fd < 0)
    348377                goto out;
     378
     379        bh->handle = acceptor_fd;
    349380
    350381        /*
     
    364395
    365396out:
     397        fibril_mutex_lock(&acceptor_data->lock);
     398        list_append(&bh->link, &acceptor_data->passed_handles);
     399        fibril_condvar_broadcast(&acceptor_data->cv);
     400        fibril_mutex_unlock(&acceptor_data->lock);
     401
    366402        if (donor_data)
    367403                async_put_client_data_by_hash(donor_hash);
     
    372408        if (acceptor_file)
    373409                _vfs_file_put(acceptor_data, acceptor_file);
     410
     411}
     412
     413int vfs_wait_handle_internal(void)
     414{
     415        vfs_client_data_t *vfs_data = VFS_DATA;
     416        int fd;
     417       
     418        fibril_mutex_lock(&vfs_data->lock);
     419        while (list_empty(&vfs_data->passed_handles))
     420                fibril_condvar_wait(&vfs_data->cv, &vfs_data->lock);
     421        link_t *lnk = list_first(&vfs_data->passed_handles);
     422        list_remove(lnk);
     423        fibril_mutex_unlock(&vfs_data->lock);
     424
     425        vfs_boxed_handle_t *bh = list_get_instance(lnk, vfs_boxed_handle_t, link);
     426        fd = bh->handle;
     427        free(bh);
     428
     429        return fd;
    374430}
    375431
  • uspace/srv/vfs/vfs_ops.c

    rb33ec43 r27b76ca  
    12761276}
    12771277
     1278void vfs_wait_handle(ipc_callid_t rid, ipc_call_t *request)
     1279{
     1280        int fd = vfs_wait_handle_internal();
     1281        async_answer_1(rid, EOK, fd);
     1282}
     1283
    12781284/**
    12791285 * @}
Note: See TracChangeset for help on using the changeset viewer.