Changes in / [bf75e3cb:a0ce870] in mainline


Ignore:
Files:
36 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/ipc/ipc.h

    rbf75e3cb ra0ce870  
    165165 *                       error is sent back to caller. Otherwise
    166166 *                       the call is accepted and the response is sent back.
    167  *                     - the hash of the client task is passed to userspace
    168  *                       (on the receiving side) as ARG4 of the call.
    169  *                     - the hash of the allocated phone is passed to userspace
     167 *                     - the allocated phoneid is passed to userspace
    170168 *                       (on the receiving side) as ARG5 of the call.
    171169 *
     
    321319typedef struct {
    322320        sysarg_t args[IPC_CALL_LEN];
    323         /** Task which made or forwarded the call with IPC_FF_ROUTE_FROM_ME. */
    324         struct task *task;
    325         /** Phone which made or last masqueraded this call. */
    326321        phone_t *phone;
    327322} ipc_data_t;
  • kernel/generic/src/ipc/ipc.c

    rbf75e3cb ra0ce870  
    295295                atomic_inc(&phone->active_calls);
    296296                call->data.phone = phone;
    297                 call->data.task = TASK;
    298297        }
    299298       
     
    407406                        call->caller_phone = call->data.phone;
    408407                call->data.phone = newphone;
    409                 call->data.task = TASK;
    410408        }
    411409       
  • kernel/generic/src/ipc/sysipc.c

    rbf75e3cb ra0ce870  
    248248                        /* The connection was accepted */
    249249                        phone_connect(phoneid, &answer->sender->answerbox);
    250                         /* Set 'task hash' as arg4 of response */
    251                         IPC_SET_ARG4(answer->data, (sysarg_t) TASK);
    252250                        /* Set 'phone hash' as arg5 of response */
    253251                        IPC_SET_ARG5(answer->data,
  • uspace/lib/c/generic/async.c

    rbf75e3cb ra0ce870  
    134134
    135135typedef struct {
    136         sysarg_t in_task_hash;
    137         link_t link;
    138         int refcnt;
    139         void *data;
    140 } client_t;
    141 
    142 typedef struct {
    143136        awaiter_t wdata;
    144137       
     
    146139        link_t link;
    147140       
    148         /** Incoming client task hash. */
    149         sysarg_t in_task_hash;
    150141        /** Incoming phone hash. */
    151142        sysarg_t in_phone_hash;
    152143       
    153         /** Link to the client tracking structure. */
    154         client_t *client;
    155 
    156144        /** Messages that should be delivered to this fibril. */
    157145        link_t msg_queue;
     
    172160fibril_local connection_t *FIBRIL_connection;
    173161
    174 static void *default_client_data_constructor(void)
    175 {
    176         return NULL;
    177 }
    178 
    179 static void default_client_data_destructor(void *data)
    180 {
    181 }
    182 
    183 static async_client_data_ctor_t async_client_data_create =
    184     default_client_data_constructor;
    185 static async_client_data_dtor_t async_client_data_destroy =
    186     default_client_data_destructor;
    187 
    188 void async_set_client_data_constructor(async_client_data_ctor_t ctor)
    189 {
    190         async_client_data_create = ctor;
    191 }
    192 
    193 void async_set_client_data_destructor(async_client_data_dtor_t dtor)
    194 {
    195         async_client_data_destroy = dtor;
    196 }
    197 
    198 void *async_client_data_get(void)
    199 {
    200         assert(FIBRIL_connection);
    201 
    202         return FIBRIL_connection->client->data;
    203 }
    204 
    205162static void default_client_connection(ipc_callid_t callid, ipc_call_t *call);
    206163static void default_interrupt_received(ipc_callid_t callid, ipc_call_t *call);
     
    217174static async_client_conn_t interrupt_received = default_interrupt_received;
    218175
    219 static hash_table_t client_hash_table;
    220176static hash_table_t conn_hash_table;
    221177static LIST_INITIALIZE(timeout_list);
    222178
    223 #define CLIENT_HASH_TABLE_BUCKETS       32
    224 #define CONN_HASH_TABLE_BUCKETS         32
    225 
    226 static hash_index_t client_hash(unsigned long *key)
     179#define CONN_HASH_TABLE_CHAINS  32
     180
     181/** Compute hash into the connection hash table based on the source phone hash.
     182 *
     183 * @param key Pointer to source phone hash.
     184 *
     185 * @return Index into the connection hash table.
     186 *
     187 */
     188static hash_index_t conn_hash(unsigned long *key)
    227189{
    228190        assert(key);
    229         return (((*key) >> 4) % CLIENT_HASH_TABLE_BUCKETS);
    230 }
    231 
    232 static int client_compare(unsigned long key[], hash_count_t keys, link_t *item)
    233 {
    234         client_t *cl = hash_table_get_instance(item, client_t, link);
    235         return (key[0] == cl->in_task_hash);
    236 }
    237 
    238 static void client_remove(link_t *item)
    239 {
    240 }
    241 
    242 /** Operations for the client hash table. */
    243 static hash_table_operations_t client_hash_table_ops = {
    244         .hash = client_hash,
    245         .compare = client_compare,
    246         .remove_callback = client_remove
    247 };
    248 
    249 /** Compute hash into the connection hash table based on the source phone hash.
    250  *
    251  * @param key Pointer to source phone hash.
    252  *
    253  * @return Index into the connection hash table.
    254  *
    255  */
    256 static hash_index_t conn_hash(unsigned long *key)
    257 {
    258         assert(key);
    259         return (((*key) >> 4) % CONN_HASH_TABLE_BUCKETS);
     191        return (((*key) >> 4) % CONN_HASH_TABLE_CHAINS);
    260192}
    261193
     
    548480static int connection_fibril(void *arg)
    549481{
    550         unsigned long key;
    551         client_t *cl;
    552         link_t *lnk;
    553         bool destroy = false;
    554 
    555482        /*
    556          * Setup fibril-local connection pointer.
     483         * Setup fibril-local connection pointer and call client_connection().
     484         *
    557485         */
    558486        FIBRIL_connection = (connection_t *) arg;
    559 
    560         /*
    561          * Add our reference for the current connection in the client task
    562          * tracking structure. If this is the first reference, create and
    563          * hash in a new tracking structure.
    564          */
    565         futex_down(&async_futex);
    566         key = FIBRIL_connection->in_task_hash;
    567         lnk = hash_table_find(&client_hash_table, &key);
    568         if (lnk) {
    569                 cl = hash_table_get_instance(lnk, client_t, link);
    570                 cl->refcnt++;
    571         } else {
    572                 cl = malloc(sizeof(client_t));
    573                 if (!cl) {
    574                         ipc_answer_0(FIBRIL_connection->callid, ENOMEM);
    575                         futex_up(&async_futex);
    576                         return 0;
    577                 }
    578                 cl->in_task_hash = FIBRIL_connection->in_task_hash;
    579                 async_serialize_start();
    580                 cl->data = async_client_data_create();
    581                 async_serialize_end();
    582                 cl->refcnt = 1;
    583                 hash_table_insert(&client_hash_table, &key, &cl->link);
    584         }
    585         futex_up(&async_futex);
    586 
    587         FIBRIL_connection->client = cl;
    588 
    589         /*
    590          * Call the connection handler function.
    591          */
    592487        FIBRIL_connection->cfibril(FIBRIL_connection->callid,
    593488            &FIBRIL_connection->call);
    594489       
    595         /*
    596          * Remove the reference for this client task connection.
    597          */
     490        /* Remove myself from the connection hash table */
    598491        futex_down(&async_futex);
    599         if (--cl->refcnt == 0) {
    600                 hash_table_remove(&client_hash_table, &key, 1);
    601                 destroy = true;
    602         }
    603         futex_up(&async_futex);
    604 
    605         if (destroy) {
    606                 if (cl->data)
    607                         async_client_data_destroy(cl->data);
    608                 free(cl);
    609         }
    610 
    611         /*
    612          * Remove myself from the connection hash table.
    613          */
    614         futex_down(&async_futex);
    615         key = FIBRIL_connection->in_phone_hash;
     492        unsigned long key = FIBRIL_connection->in_phone_hash;
    616493        hash_table_remove(&conn_hash_table, &key, 1);
    617494        futex_up(&async_futex);
    618495       
    619         /*
    620          * Answer all remaining messages with EHANGUP.
    621          */
     496        /* Answer all remaining messages with EHANGUP */
    622497        while (!list_empty(&FIBRIL_connection->msg_queue)) {
    623498                msg_t *msg;
     
    630505        }
    631506       
    632         /*
    633          * If the connection was hung-up, answer the last call,
    634          * i.e. IPC_M_PHONE_HUNGUP.
    635          */
    636507        if (FIBRIL_connection->close_callid)
    637508                ipc_answer_0(FIBRIL_connection->close_callid, EOK);
     
    646517 * particular fibrils.
    647518 *
    648  * @param in_task_hash  Identification of the incoming connection.
    649519 * @param in_phone_hash Identification of the incoming connection.
    650520 * @param callid        Hash of the opening IPC_M_CONNECT_ME_TO call.
     
    659529 *
    660530 */
    661 fid_t async_new_connection(sysarg_t in_task_hash, sysarg_t in_phone_hash,
    662     ipc_callid_t callid, ipc_call_t *call,
    663     void (*cfibril)(ipc_callid_t, ipc_call_t *))
     531fid_t async_new_connection(sysarg_t in_phone_hash, ipc_callid_t callid,
     532    ipc_call_t *call, void (*cfibril)(ipc_callid_t, ipc_call_t *))
    664533{
    665534        connection_t *conn = malloc(sizeof(*conn));
     
    670539        }
    671540       
    672         conn->in_task_hash = in_task_hash;
    673541        conn->in_phone_hash = in_phone_hash;
    674542        list_initialize(&conn->msg_queue);
     
    724592        case IPC_M_CONNECT_ME_TO:
    725593                /* Open new connection with fibril etc. */
    726                 async_new_connection(call->in_task_hash, IPC_GET_ARG5(*call),
    727                     callid, call, client_connection);
     594                async_new_connection(IPC_GET_ARG5(*call), callid, call,
     595                    client_connection);
    728596                goto out;
    729597        }
     
    876744int __async_init(void)
    877745{
    878         if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS, 1,
    879             &client_hash_table_ops) || !hash_table_create(&conn_hash_table,
    880             CONN_HASH_TABLE_BUCKETS, 1, &conn_hash_table_ops)) {
     746        if (!hash_table_create(&conn_hash_table, CONN_HASH_TABLE_CHAINS, 1,
     747            &conn_hash_table_ops)) {
     748                printf("%s: Cannot create async hash table\n", "libc");
    881749                return ENOMEM;
    882750        }
  • uspace/lib/c/generic/devman.c

    rbf75e3cb ra0ce870  
    116116        async_set_client_connection(conn);
    117117       
    118         ipc_connect_to_me(phone, 0, 0, 0, NULL, NULL);
     118        sysarg_t callback_phonehash;
     119        ipc_connect_to_me(phone, 0, 0, 0, &callback_phonehash);
    119120        async_wait_for(req, &retval);
    120121       
  • uspace/lib/c/generic/devmap.c

    rbf75e3cb ra0ce870  
    116116        async_set_client_connection(conn);
    117117       
    118         ipc_connect_to_me(phone, 0, 0, 0, NULL, NULL);
     118        sysarg_t callback_phonehash;
     119        ipc_connect_to_me(phone, 0, 0, 0, &callback_phonehash);
    119120        async_wait_for(req, &retval);
    120121       
  • uspace/lib/c/generic/ipc.c

    rbf75e3cb ra0ce870  
    578578 * @param arg2          Service-defined argument.
    579579 * @param arg3          Service-defined argument.
    580  * @param taskhash      Storage where the kernel will store an opaque
    581  *                      identifier of the client task.
    582  * @param phonehash     Storage where the kernel will store an opaque
     580 * @param phonehash     Storage where the library will store an opaque
    583581 *                      identifier of the phone that will be used for incoming
    584582 *                      calls. This identifier can be used for connection
     
    588586 */
    589587int ipc_connect_to_me(int phoneid, int arg1, int arg2, int arg3,
    590     sysarg_t *taskhash, sysarg_t *phonehash)
     588    sysarg_t *phonehash)
    591589{
    592590        return ipc_call_sync_3_5(phoneid, IPC_M_CONNECT_TO_ME, arg1, arg2,
    593             arg3, NULL, NULL, NULL, taskhash, phonehash);
     591            arg3, NULL, NULL, NULL, NULL, phonehash);
    594592}
    595593
  • uspace/lib/c/generic/net/modules.c

    rbf75e3cb ra0ce870  
    143143        if (phone >= 0) {
    144144                /* Request the bidirectional connection */
    145                 sysarg_t taskhash;
    146145                sysarg_t phonehash;
    147146               
    148                 rc = ipc_connect_to_me(phone, arg1, arg2, arg3, &taskhash,
    149                     &phonehash);
     147                rc = ipc_connect_to_me(phone, arg1, arg2, arg3, &phonehash);
    150148                if (rc != EOK) {
    151149                        ipc_hangup(phone);
    152150                        return rc;
    153151                }
    154                 async_new_connection(taskhash, phonehash, 0, NULL,
    155                     client_receiver);
     152                async_new_connection(phonehash, 0, NULL, client_receiver);
    156153        }
    157154       
  • uspace/lib/c/generic/vfs/vfs.c

    rbf75e3cb ra0ce870  
    4646#include <ipc/services.h>
    4747#include <async.h>
    48 #include <fibril_synch.h>
     48#include <atomic.h>
     49#include <futex.h>
    4950#include <errno.h>
    50 #include <assert.h>
    5151#include <str.h>
    5252#include <devmap.h>
     
    5454#include <ipc/devmap.h>
    5555
    56 static async_sess_t vfs_session;
    57 
    58 static FIBRIL_MUTEX_INITIALIZE(vfs_phone_mutex);
    5956static int vfs_phone = -1;
    60 
    61 static FIBRIL_MUTEX_INITIALIZE(cwd_mutex);
     57static futex_t vfs_phone_futex = FUTEX_INITIALIZER;
     58static futex_t cwd_futex = FUTEX_INITIALIZER;
    6259
    6360static int cwd_fd = -1;
     
    7067        char *ncwd_path_nc;
    7168
    72         fibril_mutex_lock(&cwd_mutex);
     69        futex_down(&cwd_futex);
    7370        size_t size = str_size(path);
    7471        if (*path != '/') {
    7572                if (!cwd_path) {
    76                         fibril_mutex_unlock(&cwd_mutex);
     73                        futex_up(&cwd_futex);
    7774                        return NULL;
    7875                }
    7976                ncwd_path_nc = malloc(cwd_size + 1 + size + 1);
    8077                if (!ncwd_path_nc) {
    81                         fibril_mutex_unlock(&cwd_mutex);
     78                        futex_up(&cwd_futex);
    8279                        return NULL;
    8380                }
     
    8885                ncwd_path_nc = malloc(size + 1);
    8986                if (!ncwd_path_nc) {
    90                         fibril_mutex_unlock(&cwd_mutex);
     87                        futex_up(&cwd_futex);
    9188                        return NULL;
    9289                }
     
    9693        ncwd_path = canonify(ncwd_path_nc, retlen);
    9794        if (!ncwd_path) {
    98                 fibril_mutex_unlock(&cwd_mutex);
     95                futex_up(&cwd_futex);
    9996                free(ncwd_path_nc);
    10097                return NULL;
     
    108105        free(ncwd_path_nc);
    109106        if (!ncwd_path) {
    110                 fibril_mutex_unlock(&cwd_mutex);
     107                futex_up(&cwd_futex);
    111108                return NULL;
    112109        }
    113         fibril_mutex_unlock(&cwd_mutex);
     110        futex_up(&cwd_futex);
    114111        return ncwd_path;
    115112}
    116113
    117 /** Connect to VFS service and create session. */
    118114static void vfs_connect(void)
    119115{
    120         while (vfs_phone < 0) {
    121                 vfs_phone = async_connect_me_to_blocking(PHONE_NS, SERVICE_VFS,
    122                     0, 0);
    123         }
    124        
    125         async_session_create(&vfs_session, vfs_phone, 0);
    126 }
    127 
    128 /** Start an async exchange on the VFS session.
    129  *
    130  * @return              New phone to be used during the exchange.
    131  */
    132 static int vfs_exchange_begin(void)
    133 {
    134         fibril_mutex_lock(&vfs_phone_mutex);
    135         if (vfs_phone < 0)
    136                 vfs_connect();
    137         fibril_mutex_unlock(&vfs_phone_mutex);
    138 
    139         return async_exchange_begin(&vfs_session);
    140 }
    141 
    142 /** End an async exchange on the VFS session.
    143  *
    144  * @param phone         Phone used during the exchange.
    145  */
    146 static void vfs_exchange_end(int phone)
    147 {
    148         async_exchange_end(&vfs_session, phone);
     116        while (vfs_phone < 0)
     117                vfs_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VFS, 0, 0);
    149118}
    150119
     
    185154        }
    186155       
    187         int vfs_phone = vfs_exchange_begin();
    188 
     156        futex_down(&vfs_phone_futex);
     157        async_serialize_start();
     158        vfs_connect();
     159       
    189160        sysarg_t rc_orig;
    190161        aid_t req = async_send_2(vfs_phone, VFS_IN_MOUNT, devmap_handle, flags, NULL);
    191162        sysarg_t rc = async_data_write_start(vfs_phone, (void *) mpa, mpa_size);
    192163        if (rc != EOK) {
    193                 vfs_exchange_end(vfs_phone);
     164                async_wait_for(req, &rc_orig);
     165                async_serialize_end();
     166                futex_up(&vfs_phone_futex);
    194167                free(mpa);
    195                 async_wait_for(req, &rc_orig);
    196168               
    197169                if (null_id != -1)
     
    206178        rc = async_data_write_start(vfs_phone, (void *) opts, str_size(opts));
    207179        if (rc != EOK) {
    208                 vfs_exchange_end(vfs_phone);
     180                async_wait_for(req, &rc_orig);
     181                async_serialize_end();
     182                futex_up(&vfs_phone_futex);
    209183                free(mpa);
    210                 async_wait_for(req, &rc_orig);
    211184               
    212185                if (null_id != -1)
     
    221194        rc = async_data_write_start(vfs_phone, (void *) fs_name, str_size(fs_name));
    222195        if (rc != EOK) {
    223                 vfs_exchange_end(vfs_phone);
     196                async_wait_for(req, &rc_orig);
     197                async_serialize_end();
     198                futex_up(&vfs_phone_futex);
    224199                free(mpa);
    225                 async_wait_for(req, &rc_orig);
    226200               
    227201                if (null_id != -1)
     
    237211        rc = async_req_0_0(vfs_phone, IPC_M_PING);
    238212        if (rc != EOK) {
    239                 vfs_exchange_end(vfs_phone);
     213                async_wait_for(req, &rc_orig);
     214                async_serialize_end();
     215                futex_up(&vfs_phone_futex);
    240216                free(mpa);
    241                 async_wait_for(req, &rc_orig);
    242217               
    243218                if (null_id != -1)
     
    250225        }
    251226       
    252         vfs_exchange_end(vfs_phone);
     227        async_wait_for(req, &rc);
     228        async_serialize_end();
     229        futex_up(&vfs_phone_futex);
    253230        free(mpa);
    254         async_wait_for(req, &rc);
    255231       
    256232        if ((rc != EOK) && (null_id != -1))
     
    272248                return ENOMEM;
    273249       
    274         int vfs_phone = vfs_exchange_begin();
     250        futex_down(&vfs_phone_futex);
     251        async_serialize_start();
     252        vfs_connect();
    275253       
    276254        req = async_send_0(vfs_phone, VFS_IN_UNMOUNT, NULL);
    277255        rc = async_data_write_start(vfs_phone, (void *) mpa, mpa_size);
    278256        if (rc != EOK) {
    279                 vfs_exchange_end(vfs_phone);
     257                async_wait_for(req, &rc_orig);
     258                async_serialize_end();
     259                futex_up(&vfs_phone_futex);
    280260                free(mpa);
    281                 async_wait_for(req, &rc_orig);
    282                 if (rc_orig == EOK)
    283                         return (int) rc;
    284                 else
    285                         return (int) rc_orig;
    286         }
    287        
    288 
    289         vfs_exchange_end(vfs_phone);
     261                if (rc_orig == EOK)
     262                        return (int) rc;
     263                else
     264                        return (int) rc_orig;
     265        }
     266       
     267
     268        async_wait_for(req, &rc);
     269        async_serialize_end();
     270        futex_up(&vfs_phone_futex);
    290271        free(mpa);
    291         async_wait_for(req, &rc);
    292272       
    293273        return (int) rc;
     
    296276static int open_internal(const char *abs, size_t abs_size, int lflag, int oflag)
    297277{
    298         int vfs_phone = vfs_exchange_begin();
     278        futex_down(&vfs_phone_futex);
     279        async_serialize_start();
     280        vfs_connect();
    299281       
    300282        ipc_call_t answer;
     
    303285       
    304286        if (rc != EOK) {
    305                 vfs_exchange_end(vfs_phone);
    306 
    307287                sysarg_t rc_orig;
    308288                async_wait_for(req, &rc_orig);
    309289               
    310                 if (rc_orig == EOK)
    311                         return (int) rc;
    312                 else
    313                         return (int) rc_orig;
    314         }
    315        
    316         vfs_exchange_end(vfs_phone);
    317         async_wait_for(req, &rc);
     290                async_serialize_end();
     291                futex_up(&vfs_phone_futex);
     292               
     293                if (rc_orig == EOK)
     294                        return (int) rc;
     295                else
     296                        return (int) rc_orig;
     297        }
     298       
     299        async_wait_for(req, &rc);
     300        async_serialize_end();
     301        futex_up(&vfs_phone_futex);
    318302       
    319303        if (rc != EOK)
     
    338322int open_node(fdi_node_t *node, int oflag)
    339323{
    340         int vfs_phone = vfs_exchange_begin();
     324        futex_down(&vfs_phone_futex);
     325        async_serialize_start();
     326        vfs_connect();
    341327       
    342328        ipc_call_t answer;
     
    344330            node->devmap_handle, node->index, oflag, &answer);
    345331       
    346         vfs_exchange_end(vfs_phone);
    347 
    348         sysarg_t rc;
    349         async_wait_for(req, &rc);
     332        sysarg_t rc;
     333        async_wait_for(req, &rc);
     334        async_serialize_end();
     335        futex_up(&vfs_phone_futex);
    350336       
    351337        if (rc != EOK)
     
    359345        sysarg_t rc;
    360346       
    361         int vfs_phone = vfs_exchange_begin();
     347        futex_down(&vfs_phone_futex);
     348        async_serialize_start();
     349        vfs_connect();
    362350       
    363351        rc = async_req_1_0(vfs_phone, VFS_IN_CLOSE, fildes);
    364352       
    365         vfs_exchange_end(vfs_phone);
     353        async_serialize_end();
     354        futex_up(&vfs_phone_futex);
    366355       
    367356        return (int)rc;
     
    374363        aid_t req;
    375364
    376         int vfs_phone = vfs_exchange_begin();
     365        futex_down(&vfs_phone_futex);
     366        async_serialize_start();
     367        vfs_connect();
    377368       
    378369        req = async_send_1(vfs_phone, VFS_IN_READ, fildes, &answer);
    379370        rc = async_data_read_start(vfs_phone, (void *)buf, nbyte);
    380371        if (rc != EOK) {
    381                 vfs_exchange_end(vfs_phone);
    382 
    383372                sysarg_t rc_orig;
    384                 async_wait_for(req, &rc_orig);
    385 
     373       
     374                async_wait_for(req, &rc_orig);
     375                async_serialize_end();
     376                futex_up(&vfs_phone_futex);
    386377                if (rc_orig == EOK)
    387378                        return (ssize_t) rc;
     
    389380                        return (ssize_t) rc_orig;
    390381        }
    391         vfs_exchange_end(vfs_phone);
    392         async_wait_for(req, &rc);
     382        async_wait_for(req, &rc);
     383        async_serialize_end();
     384        futex_up(&vfs_phone_futex);
    393385        if (rc == EOK)
    394386                return (ssize_t) IPC_GET_ARG1(answer);
     
    403395        aid_t req;
    404396
    405         int vfs_phone = vfs_exchange_begin();
     397        futex_down(&vfs_phone_futex);
     398        async_serialize_start();
     399        vfs_connect();
    406400       
    407401        req = async_send_1(vfs_phone, VFS_IN_WRITE, fildes, &answer);
    408402        rc = async_data_write_start(vfs_phone, (void *)buf, nbyte);
    409403        if (rc != EOK) {
    410                 vfs_exchange_end(vfs_phone);
    411 
    412404                sysarg_t rc_orig;
    413                 async_wait_for(req, &rc_orig);
    414 
     405       
     406                async_wait_for(req, &rc_orig);
     407                async_serialize_end();
     408                futex_up(&vfs_phone_futex);
    415409                if (rc_orig == EOK)
    416410                        return (ssize_t) rc;
     
    418412                        return (ssize_t) rc_orig;
    419413        }
    420         vfs_exchange_end(vfs_phone);
    421         async_wait_for(req, &rc);
     414        async_wait_for(req, &rc);
     415        async_serialize_end();
     416        futex_up(&vfs_phone_futex);
    422417        if (rc == EOK)
    423418                return (ssize_t) IPC_GET_ARG1(answer);
     
    428423int fsync(int fildes)
    429424{
    430         int vfs_phone = vfs_exchange_begin();
     425        futex_down(&vfs_phone_futex);
     426        async_serialize_start();
     427        vfs_connect();
    431428       
    432429        sysarg_t rc = async_req_1_0(vfs_phone, VFS_IN_SYNC, fildes);
    433430       
    434         vfs_exchange_end(vfs_phone);
     431        async_serialize_end();
     432        futex_up(&vfs_phone_futex);
    435433       
    436434        return (int) rc;
     
    439437off64_t lseek(int fildes, off64_t offset, int whence)
    440438{
    441         int vfs_phone = vfs_exchange_begin();
     439        futex_down(&vfs_phone_futex);
     440        async_serialize_start();
     441        vfs_connect();
    442442       
    443443        sysarg_t newoff_lo;
     
    447447            &newoff_lo, &newoff_hi);
    448448       
    449         vfs_exchange_end(vfs_phone);
     449        async_serialize_end();
     450        futex_up(&vfs_phone_futex);
    450451       
    451452        if (rc != EOK)
     
    459460        sysarg_t rc;
    460461       
    461         int vfs_phone = vfs_exchange_begin();
     462        futex_down(&vfs_phone_futex);
     463        async_serialize_start();
     464        vfs_connect();
    462465       
    463466        rc = async_req_3_0(vfs_phone, VFS_IN_TRUNCATE, fildes,
    464467            LOWER32(length), UPPER32(length));
    465         vfs_exchange_end(vfs_phone);
     468        async_serialize_end();
     469        futex_up(&vfs_phone_futex);
    466470       
    467471        return (int) rc;
     
    473477        aid_t req;
    474478
    475         int vfs_phone = vfs_exchange_begin();
     479        futex_down(&vfs_phone_futex);
     480        async_serialize_start();
     481        vfs_connect();
    476482       
    477483        req = async_send_1(vfs_phone, VFS_IN_FSTAT, fildes, NULL);
    478484        rc = async_data_read_start(vfs_phone, (void *) stat, sizeof(struct stat));
    479485        if (rc != EOK) {
    480                 vfs_exchange_end(vfs_phone);
    481 
    482486                sysarg_t rc_orig;
    483                 async_wait_for(req, &rc_orig);
    484 
     487               
     488                async_wait_for(req, &rc_orig);
     489                async_serialize_end();
     490                futex_up(&vfs_phone_futex);
    485491                if (rc_orig == EOK)
    486492                        return (ssize_t) rc;
     
    488494                        return (ssize_t) rc_orig;
    489495        }
    490         vfs_exchange_end(vfs_phone);
    491         async_wait_for(req, &rc);
     496        async_wait_for(req, &rc);
     497        async_serialize_end();
     498        futex_up(&vfs_phone_futex);
    492499
    493500        return rc;
     
    505512                return ENOMEM;
    506513       
    507         int vfs_phone = vfs_exchange_begin();
     514        futex_down(&vfs_phone_futex);
     515        async_serialize_start();
     516        vfs_connect();
    508517       
    509518        req = async_send_0(vfs_phone, VFS_IN_STAT, NULL);
    510519        rc = async_data_write_start(vfs_phone, pa, pa_size);
    511520        if (rc != EOK) {
    512                 vfs_exchange_end(vfs_phone);
     521                async_wait_for(req, &rc_orig);
     522                async_serialize_end();
     523                futex_up(&vfs_phone_futex);
    513524                free(pa);
    514                 async_wait_for(req, &rc_orig);
    515525                if (rc_orig == EOK)
    516526                        return (int) rc;
     
    520530        rc = async_data_read_start(vfs_phone, stat, sizeof(struct stat));
    521531        if (rc != EOK) {
    522                 vfs_exchange_end(vfs_phone);
     532                async_wait_for(req, &rc_orig);
     533                async_serialize_end();
     534                futex_up(&vfs_phone_futex);
    523535                free(pa);
    524                 async_wait_for(req, &rc_orig);
    525                 if (rc_orig == EOK)
    526                         return (int) rc;
    527                 else
    528                         return (int) rc_orig;
    529         }
    530         vfs_exchange_end(vfs_phone);
     536                if (rc_orig == EOK)
     537                        return (int) rc;
     538                else
     539                        return (int) rc_orig;
     540        }
     541        async_wait_for(req, &rc);
     542        async_serialize_end();
     543        futex_up(&vfs_phone_futex);
    531544        free(pa);
    532         async_wait_for(req, &rc);
    533545        return rc;
    534546}
     
    589601                return ENOMEM;
    590602       
    591         int vfs_phone = vfs_exchange_begin();
     603        futex_down(&vfs_phone_futex);
     604        async_serialize_start();
     605        vfs_connect();
    592606       
    593607        req = async_send_1(vfs_phone, VFS_IN_MKDIR, mode, NULL);
    594608        rc = async_data_write_start(vfs_phone, pa, pa_size);
    595609        if (rc != EOK) {
    596                 vfs_exchange_end(vfs_phone);
     610                sysarg_t rc_orig;
     611       
     612                async_wait_for(req, &rc_orig);
     613                async_serialize_end();
     614                futex_up(&vfs_phone_futex);
    597615                free(pa);
    598 
    599                 sysarg_t rc_orig;
    600                 async_wait_for(req, &rc_orig);
    601 
    602                 if (rc_orig == EOK)
    603                         return (int) rc;
    604                 else
    605                         return (int) rc_orig;
    606         }
    607         vfs_exchange_end(vfs_phone);
     616                if (rc_orig == EOK)
     617                        return (int) rc;
     618                else
     619                        return (int) rc_orig;
     620        }
     621        async_wait_for(req, &rc);
     622        async_serialize_end();
     623        futex_up(&vfs_phone_futex);
    608624        free(pa);
    609         async_wait_for(req, &rc);
    610625        return rc;
    611626}
     
    621636                return ENOMEM;
    622637
    623         int vfs_phone = vfs_exchange_begin();
     638        futex_down(&vfs_phone_futex);
     639        async_serialize_start();
     640        vfs_connect();
    624641       
    625642        req = async_send_0(vfs_phone, VFS_IN_UNLINK, NULL);
    626643        rc = async_data_write_start(vfs_phone, pa, pa_size);
    627644        if (rc != EOK) {
    628                 vfs_exchange_end(vfs_phone);
     645                sysarg_t rc_orig;
     646
     647                async_wait_for(req, &rc_orig);
     648                async_serialize_end();
     649                futex_up(&vfs_phone_futex);
    629650                free(pa);
    630 
    631                 sysarg_t rc_orig;
    632                 async_wait_for(req, &rc_orig);
    633 
    634                 if (rc_orig == EOK)
    635                         return (int) rc;
    636                 else
    637                         return (int) rc_orig;
    638         }
    639         vfs_exchange_end(vfs_phone);
     651                if (rc_orig == EOK)
     652                        return (int) rc;
     653                else
     654                        return (int) rc_orig;
     655        }
     656        async_wait_for(req, &rc);
     657        async_serialize_end();
     658        futex_up(&vfs_phone_futex);
    640659        free(pa);
    641         async_wait_for(req, &rc);
    642660        return rc;
    643661}
     
    671689        }
    672690
    673         int vfs_phone = vfs_exchange_begin();
     691        futex_down(&vfs_phone_futex);
     692        async_serialize_start();
     693        vfs_connect();
    674694       
    675695        req = async_send_0(vfs_phone, VFS_IN_RENAME, NULL);
    676696        rc = async_data_write_start(vfs_phone, olda, olda_size);
    677697        if (rc != EOK) {
    678                 vfs_exchange_end(vfs_phone);
     698                async_wait_for(req, &rc_orig);
     699                async_serialize_end();
     700                futex_up(&vfs_phone_futex);
    679701                free(olda);
    680702                free(newa);
    681                 async_wait_for(req, &rc_orig);
    682703                if (rc_orig == EOK)
    683704                        return (int) rc;
     
    687708        rc = async_data_write_start(vfs_phone, newa, newa_size);
    688709        if (rc != EOK) {
    689                 vfs_exchange_end(vfs_phone);
     710                async_wait_for(req, &rc_orig);
     711                async_serialize_end();
     712                futex_up(&vfs_phone_futex);
    690713                free(olda);
    691714                free(newa);
    692                 async_wait_for(req, &rc_orig);
    693                 if (rc_orig == EOK)
    694                         return (int) rc;
    695                 else
    696                         return (int) rc_orig;
    697         }
    698         vfs_exchange_end(vfs_phone);
     715                if (rc_orig == EOK)
     716                        return (int) rc;
     717                else
     718                        return (int) rc_orig;
     719        }
     720        async_wait_for(req, &rc);
     721        async_serialize_end();
     722        futex_up(&vfs_phone_futex);
    699723        free(olda);
    700724        free(newa);
    701         async_wait_for(req, &rc);
    702725        return rc;
    703726}
     
    717740        }
    718741       
    719         fibril_mutex_lock(&cwd_mutex);
     742        futex_down(&cwd_futex);
    720743       
    721744        if (cwd_fd >= 0)
     
    730753        cwd_size = abs_size;
    731754       
    732         fibril_mutex_unlock(&cwd_mutex);
     755        futex_up(&cwd_futex);
    733756        return EOK;
    734757}
     
    739762                return NULL;
    740763       
    741         fibril_mutex_lock(&cwd_mutex);
     764        futex_down(&cwd_futex);
    742765       
    743766        if ((cwd_size == 0) || (size < cwd_size + 1)) {
    744                 fibril_mutex_unlock(&cwd_mutex);
     767                futex_up(&cwd_futex);
    745768                return NULL;
    746769        }
    747770       
    748771        str_cpy(buf, size, cwd_path);
    749         fibril_mutex_unlock(&cwd_mutex);
     772        futex_up(&cwd_futex);
    750773       
    751774        return buf;
     
    783806int dup2(int oldfd, int newfd)
    784807{
    785         int vfs_phone = vfs_exchange_begin();
     808        futex_down(&vfs_phone_futex);
     809        async_serialize_start();
     810        vfs_connect();
    786811       
    787812        sysarg_t ret;
    788813        sysarg_t rc = async_req_2_1(vfs_phone, VFS_IN_DUP, oldfd, newfd, &ret);
    789814       
    790         vfs_exchange_end(vfs_phone);
     815        async_serialize_end();
     816        futex_up(&vfs_phone_futex);
    791817       
    792818        if (rc == EOK)
  • uspace/lib/c/include/async.h

    rbf75e3cb ra0ce870  
    4444
    4545typedef ipc_callid_t aid_t;
    46 
    47 typedef void *(*async_client_data_ctor_t)(void);
    48 typedef void (*async_client_data_dtor_t)(void *);
    49 
    50 typedef void (*async_client_conn_t)(ipc_callid_t, ipc_call_t *);
     46typedef void (*async_client_conn_t)(ipc_callid_t callid, ipc_call_t *call);
    5147
    5248extern atomic_t async_futex;
     
    5551
    5652extern int __async_init(void);
    57 extern ipc_callid_t async_get_call_timeout(ipc_call_t *, suseconds_t);
     53extern ipc_callid_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs);
    5854
    5955static inline ipc_callid_t async_get_call(ipc_call_t *data)
     
    8985            (arg5), (dataptr))
    9086
    91 extern aid_t async_send_fast(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t,
    92     sysarg_t, ipc_call_t *);
    93 extern aid_t async_send_slow(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t,
    94     sysarg_t, sysarg_t, ipc_call_t *);
    95 extern void async_wait_for(aid_t, sysarg_t *);
    96 extern int async_wait_timeout(aid_t, sysarg_t *, suseconds_t);
    97 
    98 extern fid_t async_new_connection(sysarg_t, sysarg_t, ipc_callid_t,
    99     ipc_call_t *, void (*)(ipc_callid_t, ipc_call_t *));
    100 extern void async_usleep(suseconds_t);
     87extern aid_t async_send_fast(int phoneid, sysarg_t method, sysarg_t arg1,
     88    sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, ipc_call_t *dataptr);
     89extern aid_t async_send_slow(int phoneid, sysarg_t method, sysarg_t arg1,
     90    sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5,
     91    ipc_call_t *dataptr);
     92extern void async_wait_for(aid_t amsgid, sysarg_t *result);
     93extern int async_wait_timeout(aid_t amsgid, sysarg_t *retval,
     94    suseconds_t timeout);
     95
     96extern fid_t async_new_connection(sysarg_t in_phone_hash, ipc_callid_t callid,
     97    ipc_call_t *call, void (*cthread)(ipc_callid_t, ipc_call_t *));
     98extern void async_usleep(suseconds_t timeout);
    10199extern void async_create_manager(void);
    102100extern void async_destroy_manager(void);
    103101
    104 extern void async_set_client_data_constructor(async_client_data_ctor_t);
    105 extern void async_set_client_data_destructor(async_client_data_dtor_t);
    106 
    107 extern void *async_client_data_get(void);
    108 
    109 extern void async_set_client_connection(async_client_conn_t);
    110 extern void async_set_interrupt_received(async_client_conn_t);
     102extern void async_set_client_connection(async_client_conn_t conn);
     103extern void async_set_interrupt_received(async_client_conn_t conn);
    111104
    112105/* Wrappers for simple communication */
     
    250243            (arg5), (rc1), (rc2), (rc3), (rc4), (rc5))
    251244
    252 extern sysarg_t async_req_fast(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t,
    253     sysarg_t, sysarg_t *, sysarg_t *, sysarg_t *, sysarg_t *, sysarg_t *);
    254 extern sysarg_t async_req_slow(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t,
    255     sysarg_t, sysarg_t, sysarg_t *, sysarg_t *, sysarg_t *, sysarg_t *,
    256     sysarg_t *);
     245extern sysarg_t async_req_fast(int phoneid, sysarg_t method, sysarg_t arg1,
     246    sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t *r1, sysarg_t *r2,
     247    sysarg_t *r3, sysarg_t *r4, sysarg_t *r5);
     248extern sysarg_t async_req_slow(int phoneid, sysarg_t method, sysarg_t arg1,
     249    sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, sysarg_t *r1,
     250    sysarg_t *r2, sysarg_t *r3, sysarg_t *r4, sysarg_t *r5);
    257251
    258252static inline void async_serialize_start(void)
  • uspace/lib/c/include/ipc/ipc.h

    rbf75e3cb ra0ce870  
    4646typedef struct {
    4747        sysarg_t args[IPC_CALL_LEN];
    48         sysarg_t in_task_hash;
    4948        sysarg_t in_phone_hash;
    5049} ipc_call_t;
     
    259258    sysarg_t, sysarg_t, void *, ipc_async_callback_t, int);
    260259
    261 extern int ipc_connect_to_me(int, int, int, int, sysarg_t *, sysarg_t *);
     260extern int ipc_connect_to_me(int, int, int, int, sysarg_t *);
    262261extern int ipc_connect_me_to(int, int, int, int);
    263262extern int ipc_connect_me_to_blocking(int, int, int, int);
  • uspace/lib/fs/libfs.c

    rbf75e3cb ra0ce870  
    102102         * Ask VFS for callback connection.
    103103         */
    104         sysarg_t taskhash;
    105         ipc_connect_to_me(vfs_phone, 0, 0, 0, &taskhash, &reg->vfs_phonehash);
     104        ipc_connect_to_me(vfs_phone, 0, 0, 0, &reg->vfs_phonehash);
    106105       
    107106        /*
     
    132131         * Create a connection fibril to handle the callback connection.
    133132         */
    134         async_new_connection(taskhash, reg->vfs_phonehash, 0, NULL, conn);
     133        async_new_connection(reg->vfs_phonehash, 0, NULL, conn);
    135134       
    136135        /*
  • uspace/lib/net/il/il_skel.c

    rbf75e3cb ra0ce870  
    115115                goto out;
    116116       
    117         rc = ipc_connect_to_me(PHONE_NS, service, 0, 0, NULL, NULL);
     117        sysarg_t phonehash;
     118        rc = ipc_connect_to_me(PHONE_NS, service, 0, 0, &phonehash);
    118119        if (rc != EOK)
    119120                goto out;
  • uspace/lib/net/nil/nil_skel.c

    rbf75e3cb ra0ce870  
    115115                goto out;
    116116       
    117         rc = ipc_connect_to_me(PHONE_NS, service, 0, 0, NULL, NULL);
     117        sysarg_t phonehash;
     118        rc = ipc_connect_to_me(PHONE_NS, service, 0, 0, &phonehash);
    118119        if (rc != EOK)
    119120                goto out;
  • uspace/lib/net/tl/tl_skel.c

    rbf75e3cb ra0ce870  
    117117                goto out;
    118118       
    119         rc = ipc_connect_to_me(PHONE_NS, service, 0, 0, NULL, NULL);
     119        sysarg_t phonehash;
     120        rc = ipc_connect_to_me(PHONE_NS, service, 0, 0, &phonehash);
    120121        if (rc != EOK)
    121122                goto out;
  • uspace/srv/clip/clip.c

    rbf75e3cb ra0ce870  
    183183        async_set_client_connection(clip_connection);
    184184       
    185         if (ipc_connect_to_me(PHONE_NS, SERVICE_CLIPBOARD, 0, 0, NULL, NULL))
     185        sysarg_t phonead;
     186        if (ipc_connect_to_me(PHONE_NS, SERVICE_CLIPBOARD, 0, 0, &phonead) != 0)
    186187                return -1;
    187188       
  • uspace/srv/devman/main.c

    rbf75e3cb ra0ce870  
    586586
    587587        /* Register device manager at naming service. */
    588         if (ipc_connect_to_me(PHONE_NS, SERVICE_DEVMAN, 0, 0, NULL, NULL) != 0)
     588        sysarg_t phonead;
     589        if (ipc_connect_to_me(PHONE_NS, SERVICE_DEVMAN, 0, 0, &phonead) != 0)
    589590                return -1;
    590591
  • uspace/srv/devmap/devmap.c

    rbf75e3cb ra0ce870  
    11501150       
    11511151        /* Register device mapper at naming service */
    1152         if (ipc_connect_to_me(PHONE_NS, SERVICE_DEVMAP, 0, 0, NULL, NULL) != 0)
     1152        sysarg_t phonead;
     1153        if (ipc_connect_to_me(PHONE_NS, SERVICE_DEVMAP, 0, 0, &phonead) != 0)
    11531154                return -1;
    11541155       
  • uspace/srv/hid/adb_mouse/adb_dev.c

    rbf75e3cb ra0ce870  
    6868
    6969        /* NB: The callback connection is slotted for removal */
    70         sysarg_t taskhash;
    7170        sysarg_t phonehash;
    72         if (ipc_connect_to_me(dev_phone, 0, 0, 0, &taskhash, &phonehash) != 0) {
     71        if (ipc_connect_to_me(dev_phone, 0, 0, 0, &phonehash) != 0) {
    7372                printf(NAME ": Failed to create callback from device\n");
    7473                return false;
    7574        }
    7675
    77         async_new_connection(taskhash, phonehash, 0, NULL, adb_dev_events);
     76        async_new_connection(phonehash, 0, NULL, adb_dev_events);
    7877
    7978        return 0;
  • uspace/srv/hid/char_mouse/chardev.c

    rbf75e3cb ra0ce870  
    7070
    7171        /* NB: The callback connection is slotted for removal */
    72         sysarg_t taskhash;
    7372        sysarg_t phonehash;
    74         if (ipc_connect_to_me(dev_phone, 0, 0, 0, &taskhash, &phonehash) != 0) {
     73        if (ipc_connect_to_me(dev_phone, 0, 0, 0, &phonehash) != 0) {
    7574                printf(NAME ": Failed to create callback from device\n");
    7675                return false;
    7776        }
    7877
    79         async_new_connection(taskhash, phonehash, 0, NULL, chardev_events);
     78        async_new_connection(phonehash, 0, NULL, chardev_events);
    8079
    8180        return 0;
  • uspace/srv/hid/console/console.c

    rbf75e3cb ra0ce870  
    726726       
    727727        /* NB: The callback connection is slotted for removal */
    728         sysarg_t taskhash;
    729728        sysarg_t phonehash;
    730         if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, &taskhash,
    731             &phonehash) != 0) {
     729        if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) {
    732730                printf(NAME ": Failed to create callback from input device\n");
    733731                return false;
    734732        }
    735733       
    736         async_new_connection(taskhash, phonehash, 0, NULL, keyboard_events);
     734        async_new_connection(phonehash, 0, NULL, keyboard_events);
    737735       
    738736        /* Connect to mouse device */
     
    751749        }
    752750       
    753         if (ipc_connect_to_me(mouse_phone, SERVICE_CONSOLE, 0, 0, &taskhash,
    754             &phonehash) != 0) {
     751        if (ipc_connect_to_me(mouse_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) {
    755752                printf(NAME ": Failed to create callback from mouse device\n");
    756753                mouse_phone = -1;
     
    758755        }
    759756       
    760         async_new_connection(taskhash, phonehash, 0, NULL, mouse_events);
     757        async_new_connection(phonehash, 0, NULL, mouse_events);
    761758skip_mouse:
    762759       
  • uspace/srv/hid/fb/main.c

    rbf75e3cb ra0ce870  
    114114                return -1;
    115115       
    116         if (ipc_connect_to_me(PHONE_NS, SERVICE_VIDEO, 0, 0, NULL, NULL) != 0)
     116        sysarg_t phonead;
     117        if (ipc_connect_to_me(PHONE_NS, SERVICE_VIDEO, 0, 0, &phonead) != 0)
    117118                return -1;
    118119       
  • uspace/srv/hid/kbd/port/adb.c

    rbf75e3cb ra0ce870  
    7171
    7272        /* NB: The callback connection is slotted for removal */
    73         sysarg_t taskhash;
    7473        sysarg_t phonehash;
    75         if (ipc_connect_to_me(dev_phone, 0, 0, 0, &taskhash, &phonehash) != 0) {
     74        if (ipc_connect_to_me(dev_phone, 0, 0, 0, &phonehash) != 0) {
    7675                printf(NAME ": Failed to create callback from device\n");
    7776                return false;
    7877        }
    7978
    80         async_new_connection(taskhash, phonehash, 0, NULL, kbd_port_events);
     79        async_new_connection(phonehash, 0, NULL, kbd_port_events);
    8180
    8281        return 0;
  • uspace/srv/hid/kbd/port/chardev.c

    rbf75e3cb ra0ce870  
    9191
    9292        /* NB: The callback connection is slotted for removal */
    93         sysarg_t taskhash;
    9493        sysarg_t phonehash;
    95         if (ipc_connect_to_me(dev_phone, 0, 0, 0, &taskhash, &phonehash) != 0) {
     94        if (ipc_connect_to_me(dev_phone, 0, 0, 0, &phonehash) != 0) {
    9695                printf(NAME ": Failed to create callback from device\n");
    9796                return -1;
    9897        }
    9998
    100         async_new_connection(taskhash, phonehash, 0, NULL, kbd_port_events);
     99        async_new_connection(phonehash, 0, NULL, kbd_port_events);
    101100
    102101        return 0;
  • uspace/srv/hw/irc/apic/apic.c

    rbf75e3cb ra0ce870  
    108108       
    109109        async_set_client_connection(apic_connection);
    110         ipc_connect_to_me(PHONE_NS, SERVICE_APIC, 0, 0, NULL, NULL);
     110        sysarg_t phonead;
     111        ipc_connect_to_me(PHONE_NS, SERVICE_APIC, 0, 0, &phonead);
    111112       
    112113        return true;
  • uspace/srv/hw/irc/fhc/fhc.c

    rbf75e3cb ra0ce870  
    137137       
    138138        async_set_client_connection(fhc_connection);
    139         ipc_connect_to_me(PHONE_NS, SERVICE_FHC, 0, 0, NULL, NULL);
     139        sysarg_t phonead;
     140        ipc_connect_to_me(PHONE_NS, SERVICE_FHC, 0, 0, &phonead);
    140141       
    141142        return true;
  • uspace/srv/hw/irc/i8259/i8259.c

    rbf75e3cb ra0ce870  
    150150       
    151151        async_set_client_connection(i8259_connection);
    152         ipc_connect_to_me(PHONE_NS, SERVICE_I8259, 0, 0, NULL, NULL);
     152        sysarg_t phonead;
     153        ipc_connect_to_me(PHONE_NS, SERVICE_I8259, 0, 0, &phonead);
    153154       
    154155        return true;
  • uspace/srv/hw/irc/obio/obio.c

    rbf75e3cb ra0ce870  
    138138       
    139139        async_set_client_connection(obio_connection);
    140         ipc_connect_to_me(PHONE_NS, SERVICE_OBIO, 0, 0, NULL, NULL);
     140        sysarg_t phonead;
     141        ipc_connect_to_me(PHONE_NS, SERVICE_OBIO, 0, 0, &phonead);
    141142       
    142143        return true;
  • uspace/srv/hw/netif/ne2000/ne2000.c

    rbf75e3cb ra0ce870  
    397397        async_set_interrupt_received(irq_handler);
    398398       
    399         return ipc_connect_to_me(PHONE_NS, SERVICE_NE2000, 0, 0, NULL, NULL);
     399        sysarg_t phonehash;
     400        return ipc_connect_to_me(PHONE_NS, SERVICE_NE2000, 0, 0, &phonehash);
    400401}
    401402
  • uspace/srv/loader/main.c

    rbf75e3cb ra0ce870  
    423423int main(int argc, char *argv[])
    424424{
     425        sysarg_t phonead;
    425426        task_id_t id;
    426427        int rc;
     
    438439       
    439440        /* Register at naming service. */
    440         if (ipc_connect_to_me(PHONE_NS, SERVICE_LOAD, 0, 0, NULL, NULL) != 0)
     441        if (ipc_connect_to_me(PHONE_NS, SERVICE_LOAD, 0, 0, &phonead) != 0)
    441442                return -2;
    442443
  • uspace/srv/net/net/net.c

    rbf75e3cb ra0ce870  
    326326static int net_module_start(async_client_conn_t client_connection)
    327327{
     328        sysarg_t phonehash;
    328329        int rc;
    329330       
     
    337338                goto out;
    338339       
    339         rc = ipc_connect_to_me(PHONE_NS, SERVICE_NETWORKING, 0, 0, NULL, NULL);
     340        rc = ipc_connect_to_me(PHONE_NS, SERVICE_NETWORKING, 0, 0, &phonehash);
    340341        if (rc != EOK)
    341342                goto out;
  • uspace/srv/net/netif/lo/lo.c

    rbf75e3cb ra0ce870  
    167167int netif_initialize(void)
    168168{
    169         return ipc_connect_to_me(PHONE_NS, SERVICE_LO, 0, 0, NULL, NULL);
     169        sysarg_t phonehash;
     170        return ipc_connect_to_me(PHONE_NS, SERVICE_LO, 0, 0, &phonehash);
    170171}
    171172
  • uspace/srv/vfs/vfs.c

    rbf75e3cb ra0ce870  
    5959        ipc_answer_0(iid, EOK);
    6060       
     61        /*
     62         * Here we enter the main connection fibril loop.
     63         * The logic behind this loop and the protocol is that we'd like to keep
     64         * each connection open until the client hangs up. When the client hangs
     65         * up, we will free its VFS state. The act of hanging up the connection
     66         * by the client is equivalent to client termination because we cannot
     67         * distinguish one from the other. On the other hand, the client can
     68         * hang up arbitrarily if it has no open files and reestablish the
     69         * connection later.
     70         */
    6171        while (keep_on_going) {
    6272                ipc_call_t call;
     
    123133                }
    124134        }
    125 
    126         /*
    127          * Open files for this client will be cleaned up when its last
    128          * connection fibril terminates.
    129          */
     135       
     136        vfs_files_done();
    130137}
    131138
     
    159166       
    160167        /*
    161          * Set client data constructor and destructor.
    162          */
    163         async_set_client_data_constructor(vfs_client_data_create);
    164         async_set_client_data_destructor(vfs_client_data_destroy);
    165 
    166         /*
    167168         * Set a connection handling function/fibril.
    168169         */
     
    172173         * Register at the naming service.
    173174         */
    174         ipc_connect_to_me(PHONE_NS, SERVICE_VFS, 0, 0, NULL, NULL);
     175        sysarg_t phonead;
     176        ipc_connect_to_me(PHONE_NS, SERVICE_VFS, 0, 0, &phonead);
    175177       
    176178        /*
  • uspace/srv/vfs/vfs.h

    rbf75e3cb ra0ce870  
    188188#define MAX_OPEN_FILES  128
    189189
    190 extern void *vfs_client_data_create(void);
    191 extern void vfs_client_data_destroy(void *);
    192 
     190extern bool vfs_files_init(void);
     191extern void vfs_files_done(void);
    193192extern vfs_file_t *vfs_file_get(int);
    194 extern void vfs_file_put(vfs_file_t *);
    195 extern int vfs_fd_assign(vfs_file_t *, int);
     193extern int vfs_fd_assign(vfs_file_t *file, int fd);
    196194extern int vfs_fd_alloc(bool desc);
    197195extern int vfs_fd_free(int);
     196
     197extern void vfs_file_addref(vfs_file_t *);
     198extern void vfs_file_delref(vfs_file_t *);
    198199
    199200extern void vfs_node_addref(vfs_node_t *);
  • uspace/srv/vfs/vfs_file.c

    rbf75e3cb ra0ce870  
    4545#include "vfs.h"
    4646
    47 #define VFS_DATA        ((vfs_client_data_t *) async_client_data_get())
    48 #define FILES           (VFS_DATA->files)
    49 
    50 typedef struct {
    51         fibril_mutex_t lock;
    52         vfs_file_t **files;
    53 } vfs_client_data_t;
     47/**
     48 * This is a per-connection table of open files.
     49 * Our assumption is that each client opens only one connection and therefore
     50 * there is one table of open files per task. However, this may not be the case
     51 * and the client can open more connections to VFS. In that case, there will be
     52 * several tables and several file handle name spaces per task. Besides of this,
     53 * the functionality will stay unchanged. So unless the client knows what it is
     54 * doing, it should open one connection to VFS only.
     55 *
     56 * Allocation of the open files table is deferred until the client makes the
     57 * first VFS_OPEN operation.
     58 *
     59 * This resource being per-connection and, in the first place, per-fibril, we
     60 * don't need to protect it by a mutex.
     61 */
     62fibril_local vfs_file_t **files = NULL;
    5463
    5564/** Initialize the table of open files. */
    56 static bool vfs_files_init(void)
    57 {
    58         fibril_mutex_lock(&VFS_DATA->lock);
    59         if (!FILES) {
    60                 FILES = malloc(MAX_OPEN_FILES * sizeof(vfs_file_t *));
    61                 if (!FILES) {
    62                         fibril_mutex_unlock(&VFS_DATA->lock);
     65bool vfs_files_init(void)
     66{
     67        if (!files) {
     68                files = malloc(MAX_OPEN_FILES * sizeof(vfs_file_t *));
     69                if (!files)
    6370                        return false;
    64                 }
    65                 memset(FILES, 0, MAX_OPEN_FILES * sizeof(vfs_file_t *));
    66         }
    67         fibril_mutex_unlock(&VFS_DATA->lock);
     71                memset(files, 0, MAX_OPEN_FILES * sizeof(vfs_file_t *));
     72        }
    6873        return true;
    6974}
    7075
    7176/** Cleanup the table of open files. */
    72 static void vfs_files_done(void)
     77void vfs_files_done(void)
    7378{
    7479        int i;
    7580
    76         if (!FILES)
     81        if (!files)
    7782                return;
    7883
    7984        for (i = 0; i < MAX_OPEN_FILES; i++) {
    80                 if (FILES[i]) {
    81                         (void) vfs_close_internal(FILES[i]);
     85                if (files[i]) {
     86                        (void) vfs_close_internal(files[i]);
    8287                        (void) vfs_fd_free(i);
    8388                }
    8489        }
    8590       
    86         free(FILES);
    87 }
    88 
    89 void *vfs_client_data_create(void)
    90 {
    91         vfs_client_data_t *vfs_data;
    92 
    93         vfs_data = malloc(sizeof(vfs_client_data_t));
    94         if (vfs_data) {
    95                 fibril_mutex_initialize(&vfs_data->lock);
    96                 vfs_data->files = NULL;
    97         }
    98        
    99         return vfs_data;
    100 }
    101 
    102 void vfs_client_data_destroy(void *data)
    103 {
    104         vfs_client_data_t *vfs_data = (vfs_client_data_t *) data;
    105 
    106         vfs_files_done();
    107         free(vfs_data);
    108 }
    109 
    110 /** Increment reference count of VFS file structure.
    111  *
    112  * @param file          File structure that will have reference count
    113  *                      incremented.
    114  */
    115 static void vfs_file_addref(vfs_file_t *file)
    116 {
    117         assert(fibril_mutex_is_locked(&VFS_DATA->lock));
    118 
    119         file->refcnt++;
    120 }
    121 
    122 /** Decrement reference count of VFS file structure.
    123  *
    124  * @param file          File structure that will have reference count
    125  *                      decremented.
    126  */
    127 static void vfs_file_delref(vfs_file_t *file)
    128 {
    129         assert(fibril_mutex_is_locked(&VFS_DATA->lock));
    130 
    131         if (file->refcnt-- == 1) {
    132                 /*
    133                  * Lost the last reference to a file, need to drop our reference
    134                  * to the underlying VFS node.
    135                  */
    136                 vfs_node_delref(file->node);
    137                 free(file);
    138         }
    139 }
    140 
     91        free(files);
     92}
    14193
    14294/** Allocate a file descriptor.
     
    159111                i = 0;
    160112       
    161         fibril_mutex_lock(&VFS_DATA->lock);
    162113        while (true) {
    163                 if (!FILES[i]) {
    164                         FILES[i] = (vfs_file_t *) malloc(sizeof(vfs_file_t));
    165                         if (!FILES[i]) {
    166                                 fibril_mutex_unlock(&VFS_DATA->lock);
     114                if (!files[i]) {
     115                        files[i] = (vfs_file_t *) malloc(sizeof(vfs_file_t));
     116                        if (!files[i])
    167117                                return ENOMEM;
    168                         }
    169118                       
    170                         memset(FILES[i], 0, sizeof(vfs_file_t));
    171                         fibril_mutex_initialize(&FILES[i]->lock);
    172                         vfs_file_addref(FILES[i]);
    173                         fibril_mutex_unlock(&VFS_DATA->lock);
     119                        memset(files[i], 0, sizeof(vfs_file_t));
     120                        fibril_mutex_initialize(&files[i]->lock);
     121                        vfs_file_addref(files[i]);
    174122                        return (int) i;
    175123                }
     
    187135                }
    188136        }
    189         fibril_mutex_unlock(&VFS_DATA->lock);
    190137       
    191138        return EMFILE;
     
    203150        if (!vfs_files_init())
    204151                return ENOMEM;
    205 
    206         fibril_mutex_lock(&VFS_DATA->lock);     
    207         if ((fd < 0) || (fd >= MAX_OPEN_FILES) || (FILES[fd] == NULL)) {
    208                 fibril_mutex_unlock(&VFS_DATA->lock);
     152       
     153        if ((fd < 0) || (fd >= MAX_OPEN_FILES) || (files[fd] == NULL))
    209154                return EBADF;
    210         }
    211        
    212         vfs_file_delref(FILES[fd]);
    213         FILES[fd] = NULL;
    214         fibril_mutex_unlock(&VFS_DATA->lock);
     155       
     156        vfs_file_delref(files[fd]);
     157        files[fd] = NULL;
    215158       
    216159        return EOK;
     
    230173        if (!vfs_files_init())
    231174                return ENOMEM;
    232 
    233         fibril_mutex_lock(&VFS_DATA->lock);     
    234         if ((fd < 0) || (fd >= MAX_OPEN_FILES) || (FILES[fd] != NULL)) {
    235                 fibril_mutex_unlock(&VFS_DATA->lock);
     175       
     176        if ((fd < 0) || (fd >= MAX_OPEN_FILES) || (files[fd] != NULL))
    236177                return EINVAL;
    237         }
    238        
    239         FILES[fd] = file;
    240         vfs_file_addref(FILES[fd]);
    241         fibril_mutex_unlock(&VFS_DATA->lock);
     178       
     179        files[fd] = file;
     180        vfs_file_addref(files[fd]);
    242181       
    243182        return EOK;
    244183}
    245184
     185/** Increment reference count of VFS file structure.
     186 *
     187 * @param file          File structure that will have reference count
     188 *                      incremented.
     189 */
     190void vfs_file_addref(vfs_file_t *file)
     191{
     192        /*
     193         * File structures are per-connection, so no-one, except the current
     194         * fibril, should have a reference to them. This is the reason we don't
     195         * do any synchronization here.
     196         */
     197        file->refcnt++;
     198}
     199
     200/** Decrement reference count of VFS file structure.
     201 *
     202 * @param file          File structure that will have reference count
     203 *                      decremented.
     204 */
     205void vfs_file_delref(vfs_file_t *file)
     206{
     207        if (file->refcnt-- == 1) {
     208                /*
     209                 * Lost the last reference to a file, need to drop our reference
     210                 * to the underlying VFS node.
     211                 */
     212                vfs_node_delref(file->node);
     213                free(file);
     214        }
     215}
     216
    246217/** Find VFS file structure for a given file descriptor.
    247218 *
     
    255226                return NULL;
    256227       
    257         fibril_mutex_lock(&VFS_DATA->lock);
    258         if ((fd >= 0) && (fd < MAX_OPEN_FILES)) {
    259                 vfs_file_t *file = FILES[fd];
    260                 vfs_file_addref(file);
    261                 fibril_mutex_unlock(&VFS_DATA->lock);
    262                 return file;
    263         }
    264         fibril_mutex_unlock(&VFS_DATA->lock);
     228        if ((fd >= 0) && (fd < MAX_OPEN_FILES))
     229                return files[fd];
    265230       
    266231        return NULL;
    267 }
    268 
    269 /** Stop using a file structure.
    270  *
    271  * @param file          VFS file structure.
    272  */
    273 void vfs_file_put(vfs_file_t *file)
    274 {
    275         fibril_mutex_lock(&VFS_DATA->lock);
    276         vfs_file_delref(file);
    277         fibril_mutex_unlock(&VFS_DATA->lock);
    278232}
    279233
  • uspace/srv/vfs/vfs_ops.c

    rbf75e3cb ra0ce870  
    491491void vfs_open(ipc_callid_t rid, ipc_call_t *request)
    492492{
     493        if (!vfs_files_init()) {
     494                ipc_answer_0(rid, ENOMEM);
     495                return;
     496        }
     497       
    493498        /*
    494499         * The POSIX interface is open(path, oflag, mode).
     
    604609        vfs_node_addref(node);
    605610        vfs_node_put(node);
    606         vfs_file_put(file);
    607611       
    608612        /* Success! Return the new file descriptor to the client. */
     
    613617{
    614618        // FIXME: check for sanity of the supplied fs, dev and index
     619       
     620        if (!vfs_files_init()) {
     621                ipc_answer_0(rid, ENOMEM);
     622                return;
     623        }
    615624       
    616625        /*
     
    677686        vfs_node_addref(node);
    678687        vfs_node_put(node);
    679         vfs_file_put(file);
    680688       
    681689        /* Success! Return the new file descriptor to the client. */
     
    713721        vfs_release_phone(file->node->fs_handle, fs_phone);
    714722        fibril_mutex_unlock(&file->lock);
    715 
    716         vfs_file_put(file);
     723       
    717724        ipc_answer_0(rid, rc);
    718725}
     
    768775                ipc_answer_0(rid, ret);
    769776       
    770         vfs_file_put(file);
    771777        ret = vfs_fd_free(fd);
    772778        ipc_answer_0(rid, ret);
     
    869875                file->pos += bytes;
    870876        fibril_mutex_unlock(&file->lock);
    871         vfs_file_put(file);     
    872 
     877       
    873878        /*
    874879         * FS server's reply is the final result of the whole operation we
     
    910915                        file->pos = (aoff64_t) off;
    911916                        fibril_mutex_unlock(&file->lock);
    912                         vfs_file_put(file);
    913917                        ipc_answer_1(rid, EOK, off);
    914918                        return;
     
    918922                if ((off >= 0) && (file->pos + off < file->pos)) {
    919923                        fibril_mutex_unlock(&file->lock);
    920                         vfs_file_put(file);
    921924                        ipc_answer_0(rid, EOVERFLOW);
    922925                        return;
     
    925928                if ((off < 0) && (file->pos < (aoff64_t) -off)) {
    926929                        fibril_mutex_unlock(&file->lock);
    927                         vfs_file_put(file);
    928930                        ipc_answer_0(rid, EOVERFLOW);
    929931                        return;
     
    934936               
    935937                fibril_mutex_unlock(&file->lock);
    936                 vfs_file_put(file);
    937938                ipc_answer_2(rid, EOK, LOWER32(newoff),
    938939                    UPPER32(newoff));
     
    945946                        fibril_rwlock_read_unlock(&file->node->contents_rwlock);
    946947                        fibril_mutex_unlock(&file->lock);
    947                         vfs_file_put(file);
    948948                        ipc_answer_0(rid, EOVERFLOW);
    949949                        return;
     
    953953                        fibril_rwlock_read_unlock(&file->node->contents_rwlock);
    954954                        fibril_mutex_unlock(&file->lock);
    955                         vfs_file_put(file);
    956955                        ipc_answer_0(rid, EOVERFLOW);
    957956                        return;
     
    963962                fibril_rwlock_read_unlock(&file->node->contents_rwlock);
    964963                fibril_mutex_unlock(&file->lock);
    965                 vfs_file_put(file);
    966964                ipc_answer_2(rid, EOK, LOWER32(newoff), UPPER32(newoff));
    967965                return;
     
    969967       
    970968        fibril_mutex_unlock(&file->lock);
    971         vfs_file_put(file);
    972969        ipc_answer_0(rid, EINVAL);
    973970}
     
    10081005
    10091006        fibril_mutex_unlock(&file->lock);
    1010         vfs_file_put(file);
    10111007        ipc_answer_0(rid, (sysarg_t)rc);
    10121008}
     
    10251021        ipc_callid_t callid;
    10261022        if (!async_data_read_receive(&callid, NULL)) {
    1027                 vfs_file_put(file);
    10281023                ipc_answer_0(callid, EINVAL);
    10291024                ipc_answer_0(rid, EINVAL);
     
    10431038
    10441039        fibril_mutex_unlock(&file->lock);
    1045         vfs_file_put(file);
    10461040        ipc_answer_0(rid, rc);
    10471041}
     
    13451339        int newfd = IPC_GET_ARG2(*request);
    13461340       
    1347         /* If the file descriptors are the same, do nothing. */
    1348         if (oldfd == newfd) {
    1349                 ipc_answer_1(rid, EOK, newfd);
    1350                 return;
    1351         }
    1352        
    13531341        /* Lookup the file structure corresponding to oldfd. */
    13541342        vfs_file_t *oldfile = vfs_file_get(oldfd);
    13551343        if (!oldfile) {
    13561344                ipc_answer_0(rid, EBADF);
     1345                return;
     1346        }
     1347       
     1348        /* If the file descriptors are the same, do nothing. */
     1349        if (oldfd == newfd) {
     1350                ipc_answer_1(rid, EOK, newfd);
    13571351                return;
    13581352        }
     
    13711365                if (ret != EOK) {
    13721366                        fibril_mutex_unlock(&oldfile->lock);
    1373                         vfs_file_put(oldfile);
    1374                         vfs_file_put(newfile);
    13751367                        ipc_answer_0(rid, ret);
    13761368                        return;
     
    13801372                if (ret != EOK) {
    13811373                        fibril_mutex_unlock(&oldfile->lock);
    1382                         vfs_file_put(oldfile);
    1383                         vfs_file_put(newfile);
    13841374                        ipc_answer_0(rid, ret);
    13851375                        return;
    13861376                }
    1387                 vfs_file_put(newfile);
    13881377        }
    13891378       
     
    13911380        int ret = vfs_fd_assign(oldfile, newfd);
    13921381        fibril_mutex_unlock(&oldfile->lock);
    1393         vfs_file_put(oldfile);
    13941382       
    13951383        if (ret != EOK)
Note: See TracChangeset for help on using the changeset viewer.