Changeset 357b5f5 in mainline for uspace/srv/fs/devfs/devfs_ops.c


Ignore:
Timestamp:
2011-01-23T20:09:13Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fdb9982c
Parents:
cead2aa (diff), 7e36c8d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

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

    rcead2aa r357b5f5  
    6060typedef struct {
    6161        devmap_handle_t handle;
    62         int phone;
     62        int phone;              /**< When < 0, the structure is incomplete. */
    6363        size_t refcount;
    6464        link_t link;
     65        fibril_condvar_t cv;    /**< Broadcast when completed. */
    6566} device_t;
    6667
     
    227228                        [DEVICES_KEY_HANDLE] = (unsigned long) node->handle
    228229                };
    229                
     230                link_t *lnk;
     231
    230232                fibril_mutex_lock(&devices_mutex);
    231                 link_t *lnk = hash_table_find(&devices, key);
     233restart:
     234                lnk = hash_table_find(&devices, key);
    232235                if (lnk == NULL) {
    233236                        device_t *dev = (device_t *) malloc(sizeof(device_t));
     
    237240                        }
    238241                       
     242                        dev->handle = node->handle;
     243                        dev->phone = -1;        /* mark as incomplete */
     244                        dev->refcount = 1;
     245                        fibril_condvar_initialize(&dev->cv);
     246
     247                        /*
     248                         * Insert the incomplete device structure so that other
     249                         * fibrils will not race with us when we drop the mutex
     250                         * below.
     251                         */
     252                        hash_table_insert(&devices, key, &dev->link);
     253
     254                        /*
     255                         * Drop the mutex to allow recursive devfs requests.
     256                         */
     257                        fibril_mutex_unlock(&devices_mutex);
     258
    239259                        int phone = devmap_device_connect(node->handle, 0);
     260
     261                        fibril_mutex_lock(&devices_mutex);
     262
     263                        /*
     264                         * Notify possible waiters about this device structure
     265                         * being completed (or destroyed).
     266                         */
     267                        fibril_condvar_broadcast(&dev->cv);
     268
    240269                        if (phone < 0) {
     270                                /*
     271                                 * Connecting failed, need to remove the
     272                                 * entry and free the device structure.
     273                                 */
     274                                hash_table_remove(&devices, key, DEVICES_KEYS);
    241275                                fibril_mutex_unlock(&devices_mutex);
     276
    242277                                free(dev);
    243278                                return ENOENT;
    244279                        }
    245280                       
    246                         dev->handle = node->handle;
     281                        /* Set the correct phone. */
    247282                        dev->phone = phone;
    248                         dev->refcount = 1;
    249                        
    250                         hash_table_insert(&devices, key, &dev->link);
    251283                } else {
    252284                        device_t *dev = hash_table_get_instance(lnk, device_t, link);
     285
     286                        if (dev->phone < 0) {
     287                                /*
     288                                 * Wait until the device structure is completed
     289                                 * and start from the beginning as the device
     290                                 * structure might have entirely disappeared
     291                                 * while we were not holding the mutex in
     292                                 * fibril_condvar_wait().
     293                                 */
     294                                fibril_condvar_wait(&dev->cv, &devices_mutex);
     295                                goto restart;
     296                        }
     297
    253298                        dev->refcount++;
    254299                }
     
    409454                return false;
    410455       
    411         if (devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING) < 0)
    412                 return false;
    413        
    414456        return true;
    415457}
     
    420462       
    421463        /* Accept the mount options */
    422         ipcarg_t retval = async_data_write_accept((void **) &opts, true, 0, 0,
     464        sysarg_t retval = async_data_write_accept((void **) &opts, true, 0, 0,
    423465            0, NULL);
    424466        if (retval != EOK) {
     
    564606               
    565607                device_t *dev = hash_table_get_instance(lnk, device_t, link);
     608                assert(dev->phone >= 0);
    566609               
    567610                ipc_callid_t callid;
     
    575618                /* Make a request at the driver */
    576619                ipc_call_t answer;
    577                 aid_t msg = async_send_3(dev->phone, IPC_GET_METHOD(*request),
     620                aid_t msg = async_send_3(dev->phone, IPC_GET_IMETHOD(*request),
    578621                    IPC_GET_ARG1(*request), IPC_GET_ARG2(*request),
    579622                    IPC_GET_ARG3(*request), &answer);
     
    584627               
    585628                /* Wait for reply from the driver. */
    586                 ipcarg_t rc;
     629                sysarg_t rc;
    587630                async_wait_for(msg, &rc);
    588631                size_t bytes = IPC_GET_ARG1(answer);
     
    627670               
    628671                device_t *dev = hash_table_get_instance(lnk, device_t, link);
     672                assert(dev->phone >= 0);
    629673               
    630674                ipc_callid_t callid;
     
    638682                /* Make a request at the driver */
    639683                ipc_call_t answer;
    640                 aid_t msg = async_send_3(dev->phone, IPC_GET_METHOD(*request),
     684                aid_t msg = async_send_3(dev->phone, IPC_GET_IMETHOD(*request),
    641685                    IPC_GET_ARG1(*request), IPC_GET_ARG2(*request),
    642686                    IPC_GET_ARG3(*request), &answer);
     
    648692               
    649693                /* Wait for reply from the driver. */
    650                 ipcarg_t rc;
     694                sysarg_t rc;
    651695                async_wait_for(msg, &rc);
    652696                size_t bytes = IPC_GET_ARG1(answer);
     
    696740               
    697741                device_t *dev = hash_table_get_instance(lnk, device_t, link);
     742                assert(dev->phone >= 0);
    698743                dev->refcount--;
    699744               
     
    743788               
    744789                device_t *dev = hash_table_get_instance(lnk, device_t, link);
     790                assert(dev->phone >= 0);
    745791               
    746792                /* Make a request at the driver */
    747793                ipc_call_t answer;
    748                 aid_t msg = async_send_2(dev->phone, IPC_GET_METHOD(*request),
     794                aid_t msg = async_send_2(dev->phone, IPC_GET_IMETHOD(*request),
    749795                    IPC_GET_ARG1(*request), IPC_GET_ARG2(*request), &answer);
    750796               
     
    752798               
    753799                /* Wait for reply from the driver */
    754                 ipcarg_t rc;
     800                sysarg_t rc;
    755801                async_wait_for(msg, &rc);
    756802               
Note: See TracChangeset for help on using the changeset viewer.