Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/devfs/devfs_ops.c

    rb366a1bc r991f645  
    3636 */
    3737
     38#include <ipc/ipc.h>
    3839#include <macros.h>
    3940#include <bool.h>
     
    5960typedef struct {
    6061        devmap_handle_t handle;
    61         int phone;              /**< When < 0, the structure is incomplete. */
     62        int phone;
    6263        size_t refcount;
    6364        link_t link;
    64         fibril_condvar_t cv;    /**< Broadcast when completed. */
    6565} device_t;
    6666
     
    130130{
    131131        devfs_node_t *node = (devfs_node_t *) pfn->data;
    132         int ret;
    133132       
    134133        if (node->handle == 0) {
     
    146145                               
    147146                                if (str_cmp(devs[pos].name, component) == 0) {
    148                                         ret = devfs_node_get_internal(rfn, DEV_HANDLE_NAMESPACE, devs[pos].handle);
    149147                                        free(devs);
    150                                         return ret;
     148                                        return devfs_node_get_internal(rfn, DEV_HANDLE_NAMESPACE, devs[pos].handle);
    151149                                }
    152150                        }
     
    164162                                for (pos = 0; pos < count; pos++) {
    165163                                        if (str_cmp(devs[pos].name, component) == 0) {
    166                                                 ret = devfs_node_get_internal(rfn, DEV_HANDLE_DEVICE, devs[pos].handle);
    167164                                                free(devs);
    168                                                 return ret;
     165                                                return devfs_node_get_internal(rfn, DEV_HANDLE_DEVICE, devs[pos].handle);
    169166                                        }
    170167                                }
     
    187184                        for (pos = 0; pos < count; pos++) {
    188185                                if (str_cmp(devs[pos].name, component) == 0) {
    189                                         ret = devfs_node_get_internal(rfn, DEV_HANDLE_DEVICE, devs[pos].handle);
    190186                                        free(devs);
    191                                         return ret;
     187                                        return devfs_node_get_internal(rfn, DEV_HANDLE_DEVICE, devs[pos].handle);
    192188                                }
    193189                        }
     
    231227                        [DEVICES_KEY_HANDLE] = (unsigned long) node->handle
    232228                };
    233                 link_t *lnk;
    234 
     229               
    235230                fibril_mutex_lock(&devices_mutex);
    236 restart:
    237                 lnk = hash_table_find(&devices, key);
     231                link_t *lnk = hash_table_find(&devices, key);
    238232                if (lnk == NULL) {
    239233                        device_t *dev = (device_t *) malloc(sizeof(device_t));
     
    243237                        }
    244238                       
    245                         dev->handle = node->handle;
    246                         dev->phone = -1;        /* mark as incomplete */
    247                         dev->refcount = 1;
    248                         fibril_condvar_initialize(&dev->cv);
    249 
    250                         /*
    251                          * Insert the incomplete device structure so that other
    252                          * fibrils will not race with us when we drop the mutex
    253                          * below.
    254                          */
    255                         hash_table_insert(&devices, key, &dev->link);
    256 
    257                         /*
    258                          * Drop the mutex to allow recursive devfs requests.
    259                          */
    260                         fibril_mutex_unlock(&devices_mutex);
    261 
    262239                        int phone = devmap_device_connect(node->handle, 0);
    263 
    264                         fibril_mutex_lock(&devices_mutex);
    265 
    266                         /*
    267                          * Notify possible waiters about this device structure
    268                          * being completed (or destroyed).
    269                          */
    270                         fibril_condvar_broadcast(&dev->cv);
    271 
    272240                        if (phone < 0) {
    273                                 /*
    274                                  * Connecting failed, need to remove the
    275                                  * entry and free the device structure.
    276                                  */
    277                                 hash_table_remove(&devices, key, DEVICES_KEYS);
    278241                                fibril_mutex_unlock(&devices_mutex);
    279 
    280242                                free(dev);
    281243                                return ENOENT;
    282244                        }
    283245                       
    284                         /* Set the correct phone. */
     246                        dev->handle = node->handle;
    285247                        dev->phone = phone;
     248                        dev->refcount = 1;
     249                       
     250                        hash_table_insert(&devices, key, &dev->link);
    286251                } else {
    287252                        device_t *dev = hash_table_get_instance(lnk, device_t, link);
    288 
    289                         if (dev->phone < 0) {
    290                                 /*
    291                                  * Wait until the device structure is completed
    292                                  * and start from the beginning as the device
    293                                  * structure might have entirely disappeared
    294                                  * while we were not holding the mutex in
    295                                  * fibril_condvar_wait().
    296                                  */
    297                                 fibril_condvar_wait(&dev->cv, &devices_mutex);
    298                                 goto restart;
    299                         }
    300 
    301253                        dev->refcount++;
    302254                }
     
    457409                return false;
    458410       
     411        if (devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING) < 0)
     412                return false;
     413       
    459414        return true;
    460415}
     
    465420       
    466421        /* Accept the mount options */
    467         sysarg_t retval = async_data_write_accept((void **) &opts, true, 0, 0,
     422        ipcarg_t retval = async_data_write_accept((void **) &opts, true, 0, 0,
    468423            0, NULL);
    469424        if (retval != EOK) {
    470                 async_answer_0(rid, retval);
     425                ipc_answer_0(rid, retval);
    471426                return;
    472427        }
    473428       
    474429        free(opts);
    475         async_answer_3(rid, EOK, 0, 0, 0);
     430        ipc_answer_3(rid, EOK, 0, 0, 0);
    476431}
    477432
     
    483438void devfs_unmounted(ipc_callid_t rid, ipc_call_t *request)
    484439{
    485         async_answer_0(rid, ENOTSUP);
     440        ipc_answer_0(rid, ENOTSUP);
    486441}
    487442
     
    516471                size_t size;
    517472                if (!async_data_read_receive(&callid, &size)) {
    518                         async_answer_0(callid, EINVAL);
    519                         async_answer_0(rid, EINVAL);
     473                        ipc_answer_0(callid, EINVAL);
     474                        ipc_answer_0(rid, EINVAL);
    520475                        return;
    521476                }
     
    538493                        async_data_read_finalize(callid, desc[pos].name, str_size(desc[pos].name) + 1);
    539494                        free(desc);
    540                         async_answer_1(rid, EOK, 1);
     495                        ipc_answer_1(rid, EOK, 1);
    541496                        return;
    542497                }
     
    553508                                async_data_read_finalize(callid, desc[pos].name, str_size(desc[pos].name) + 1);
    554509                                free(desc);
    555                                 async_answer_1(rid, EOK, 1);
     510                                ipc_answer_1(rid, EOK, 1);
    556511                                return;
    557512                        }
     
    560515                }
    561516               
    562                 async_answer_0(callid, ENOENT);
    563                 async_answer_1(rid, ENOENT, 0);
     517                ipc_answer_0(callid, ENOENT);
     518                ipc_answer_1(rid, ENOENT, 0);
    564519                return;
    565520        }
     
    572527                size_t size;
    573528                if (!async_data_read_receive(&callid, &size)) {
    574                         async_answer_0(callid, EINVAL);
    575                         async_answer_0(rid, EINVAL);
     529                        ipc_answer_0(callid, EINVAL);
     530                        ipc_answer_0(rid, EINVAL);
    576531                        return;
    577532                }
     
    583538                        async_data_read_finalize(callid, desc[pos].name, str_size(desc[pos].name) + 1);
    584539                        free(desc);
    585                         async_answer_1(rid, EOK, 1);
     540                        ipc_answer_1(rid, EOK, 1);
    586541                        return;
    587542                }
    588543               
    589544                free(desc);
    590                 async_answer_0(callid, ENOENT);
    591                 async_answer_1(rid, ENOENT, 0);
     545                ipc_answer_0(callid, ENOENT);
     546                ipc_answer_1(rid, ENOENT, 0);
    592547                return;
    593548        }
     
    604559                if (lnk == NULL) {
    605560                        fibril_mutex_unlock(&devices_mutex);
    606                         async_answer_0(rid, ENOENT);
     561                        ipc_answer_0(rid, ENOENT);
    607562                        return;
    608563                }
    609564               
    610565                device_t *dev = hash_table_get_instance(lnk, device_t, link);
    611                 assert(dev->phone >= 0);
    612566               
    613567                ipc_callid_t callid;
    614568                if (!async_data_read_receive(&callid, NULL)) {
    615569                        fibril_mutex_unlock(&devices_mutex);
    616                         async_answer_0(callid, EINVAL);
    617                         async_answer_0(rid, EINVAL);
     570                        ipc_answer_0(callid, EINVAL);
     571                        ipc_answer_0(rid, EINVAL);
    618572                        return;
    619573                }
     
    621575                /* Make a request at the driver */
    622576                ipc_call_t answer;
    623                 aid_t msg = async_send_3(dev->phone, IPC_GET_IMETHOD(*request),
     577                aid_t msg = async_send_3(dev->phone, IPC_GET_METHOD(*request),
    624578                    IPC_GET_ARG1(*request), IPC_GET_ARG2(*request),
    625579                    IPC_GET_ARG3(*request), &answer);
    626580               
    627581                /* Forward the IPC_M_DATA_READ request to the driver */
    628                 async_forward_fast(callid, dev->phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME);
     582                ipc_forward_fast(callid, dev->phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME);
    629583                fibril_mutex_unlock(&devices_mutex);
    630584               
    631585                /* Wait for reply from the driver. */
    632                 sysarg_t rc;
     586                ipcarg_t rc;
    633587                async_wait_for(msg, &rc);
    634588                size_t bytes = IPC_GET_ARG1(answer);
    635589               
    636590                /* Driver reply is the final result of the whole operation */
    637                 async_answer_1(rid, rc, bytes);
    638                 return;
    639         }
    640        
    641         async_answer_0(rid, ENOENT);
     591                ipc_answer_1(rid, rc, bytes);
     592                return;
     593        }
     594       
     595        ipc_answer_0(rid, ENOENT);
    642596}
    643597
     
    646600        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
    647601        if (index == 0) {
    648                 async_answer_0(rid, ENOTSUP);
     602                ipc_answer_0(rid, ENOTSUP);
    649603                return;
    650604        }
     
    654608        if (type == DEV_HANDLE_NAMESPACE) {
    655609                /* Namespace directory */
    656                 async_answer_0(rid, ENOTSUP);
     610                ipc_answer_0(rid, ENOTSUP);
    657611                return;
    658612        }
     
    668622                if (lnk == NULL) {
    669623                        fibril_mutex_unlock(&devices_mutex);
    670                         async_answer_0(rid, ENOENT);
     624                        ipc_answer_0(rid, ENOENT);
    671625                        return;
    672626                }
    673627               
    674628                device_t *dev = hash_table_get_instance(lnk, device_t, link);
    675                 assert(dev->phone >= 0);
    676629               
    677630                ipc_callid_t callid;
    678631                if (!async_data_write_receive(&callid, NULL)) {
    679632                        fibril_mutex_unlock(&devices_mutex);
    680                         async_answer_0(callid, EINVAL);
    681                         async_answer_0(rid, EINVAL);
     633                        ipc_answer_0(callid, EINVAL);
     634                        ipc_answer_0(rid, EINVAL);
    682635                        return;
    683636                }
     
    685638                /* Make a request at the driver */
    686639                ipc_call_t answer;
    687                 aid_t msg = async_send_3(dev->phone, IPC_GET_IMETHOD(*request),
     640                aid_t msg = async_send_3(dev->phone, IPC_GET_METHOD(*request),
    688641                    IPC_GET_ARG1(*request), IPC_GET_ARG2(*request),
    689642                    IPC_GET_ARG3(*request), &answer);
    690643               
    691644                /* Forward the IPC_M_DATA_WRITE request to the driver */
    692                 async_forward_fast(callid, dev->phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME);
     645                ipc_forward_fast(callid, dev->phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME);
    693646               
    694647                fibril_mutex_unlock(&devices_mutex);
    695648               
    696649                /* Wait for reply from the driver. */
    697                 sysarg_t rc;
     650                ipcarg_t rc;
    698651                async_wait_for(msg, &rc);
    699652                size_t bytes = IPC_GET_ARG1(answer);
    700653               
    701654                /* Driver reply is the final result of the whole operation */
    702                 async_answer_1(rid, rc, bytes);
    703                 return;
    704         }
    705        
    706         async_answer_0(rid, ENOENT);
     655                ipc_answer_1(rid, rc, bytes);
     656                return;
     657        }
     658       
     659        ipc_answer_0(rid, ENOENT);
    707660}
    708661
    709662void devfs_truncate(ipc_callid_t rid, ipc_call_t *request)
    710663{
    711         async_answer_0(rid, ENOTSUP);
     664        ipc_answer_0(rid, ENOTSUP);
    712665}
    713666
     
    717670       
    718671        if (index == 0) {
    719                 async_answer_0(rid, EOK);
     672                ipc_answer_0(rid, EOK);
    720673                return;
    721674        }
     
    725678        if (type == DEV_HANDLE_NAMESPACE) {
    726679                /* Namespace directory */
    727                 async_answer_0(rid, EOK);
     680                ipc_answer_0(rid, EOK);
    728681                return;
    729682        }
     
    738691                if (lnk == NULL) {
    739692                        fibril_mutex_unlock(&devices_mutex);
    740                         async_answer_0(rid, ENOENT);
     693                        ipc_answer_0(rid, ENOENT);
    741694                        return;
    742695                }
    743696               
    744697                device_t *dev = hash_table_get_instance(lnk, device_t, link);
    745                 assert(dev->phone >= 0);
    746698                dev->refcount--;
    747699               
    748700                if (dev->refcount == 0) {
    749                         async_hangup(dev->phone);
     701                        ipc_hangup(dev->phone);
    750702                        hash_table_remove(&devices, key, DEVICES_KEYS);
    751703                }
     
    753705                fibril_mutex_unlock(&devices_mutex);
    754706               
    755                 async_answer_0(rid, EOK);
    756                 return;
    757         }
    758        
    759         async_answer_0(rid, ENOENT);
     707                ipc_answer_0(rid, EOK);
     708                return;
     709        }
     710       
     711        ipc_answer_0(rid, ENOENT);
    760712}
    761713
     
    765717       
    766718        if (index == 0) {
    767                 async_answer_0(rid, EOK);
     719                ipc_answer_0(rid, EOK);
    768720                return;
    769721        }
     
    773725        if (type == DEV_HANDLE_NAMESPACE) {
    774726                /* Namespace directory */
    775                 async_answer_0(rid, EOK);
     727                ipc_answer_0(rid, EOK);
    776728                return;
    777729        }
     
    786738                if (lnk == NULL) {
    787739                        fibril_mutex_unlock(&devices_mutex);
    788                         async_answer_0(rid, ENOENT);
     740                        ipc_answer_0(rid, ENOENT);
    789741                        return;
    790742                }
    791743               
    792744                device_t *dev = hash_table_get_instance(lnk, device_t, link);
    793                 assert(dev->phone >= 0);
    794745               
    795746                /* Make a request at the driver */
    796747                ipc_call_t answer;
    797                 aid_t msg = async_send_2(dev->phone, IPC_GET_IMETHOD(*request),
     748                aid_t msg = async_send_2(dev->phone, IPC_GET_METHOD(*request),
    798749                    IPC_GET_ARG1(*request), IPC_GET_ARG2(*request), &answer);
    799750               
     
    801752               
    802753                /* Wait for reply from the driver */
    803                 sysarg_t rc;
     754                ipcarg_t rc;
    804755                async_wait_for(msg, &rc);
    805756               
    806757                /* Driver reply is the final result of the whole operation */
    807                 async_answer_0(rid, rc);
    808                 return;
    809         }
    810        
    811         async_answer_0(rid, ENOENT);
     758                ipc_answer_0(rid, rc);
     759                return;
     760        }
     761       
     762        ipc_answer_0(rid, ENOENT);
    812763}
    813764
    814765void devfs_destroy(ipc_callid_t rid, ipc_call_t *request)
    815766{
    816         async_answer_0(rid, ENOTSUP);
     767        ipc_answer_0(rid, ENOTSUP);
    817768}
    818769
Note: See TracChangeset for help on using the changeset viewer.