Changeset b2d06fa in mainline for uspace/srv


Ignore:
Timestamp:
2010-12-25T17:14:36Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
092e4f1
Parents:
59e9398b (diff), 3ac66f69 (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.

Location:
uspace/srv
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/devman/devman.c

    r59e9398b rb2d06fa  
    6262}
    6363
     64static int devmap_devices_class_compare(unsigned long key[], hash_count_t keys,
     65    link_t *item)
     66{
     67        dev_class_info_t *class_info
     68            = hash_table_get_instance(item, dev_class_info_t, devmap_link);
     69        assert(class_info != NULL);
     70
     71        return (class_info->devmap_handle == (devmap_handle_t) key[0]);
     72}
     73
    6474static void devices_remove_callback(link_t *item)
    6575{
     
    7585        .hash = devices_hash,
    7686        .compare = devmap_devices_compare,
     87        .remove_callback = devices_remove_callback
     88};
     89
     90static hash_table_operations_t devmap_devices_class_ops = {
     91        .hash = devices_hash,
     92        .compare = devmap_devices_class_compare,
    7793        .remove_callback = devices_remove_callback
    7894};
     
    368384        printf(NAME ": create_root_node\n");
    369385
     386        fibril_rwlock_write_lock(&tree->rwlock);
    370387        node = create_dev_node();
    371388        if (node != NULL) {
     
    377394                tree->root_node = node;
    378395        }
     396        fibril_rwlock_write_unlock(&tree->rwlock);
    379397
    380398        return node != NULL;
     
    439457/** Start a driver
    440458 *
    441  * The driver's mutex is assumed to be locked.
    442  *
    443459 * @param drv           The driver's structure.
    444460 * @return              True if the driver's task is successfully spawned, false
     
    449465        int rc;
    450466
     467        assert(fibril_mutex_is_locked(&drv->driver_mutex));
     468       
    451469        printf(NAME ": start_driver '%s'\n", drv->name);
    452470       
     
    670688        }
    671689       
    672         devmap_device_register(devmap_pathname, &node->devmap_handle);
     690        devmap_device_register_with_iface(devmap_pathname,
     691            &node->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP);
    673692       
    674693        tree_add_devmap_device(tree, node);
     
    842861/** Find the device node structure of the device witch has the specified handle.
    843862 *
    844  * Device tree's rwlock should be held at least for reading.
    845  *
    846863 * @param tree          The device tree where we look for the device node.
    847864 * @param handle        The handle of the device.
     
    851868{
    852869        unsigned long key = handle;
    853         link_t *link = hash_table_find(&tree->devman_devices, &key);
     870        link_t *link;
     871       
     872        assert(fibril_rwlock_is_locked(&tree->rwlock));
     873       
     874        link = hash_table_find(&tree->devman_devices, &key);
    854875        return hash_table_get_instance(link, node_t, devman_link);
    855876}
     
    907928/** Insert new device into device tree.
    908929 *
    909  * The device tree's rwlock should be already held exclusively when calling this
    910  * function.
    911  *
    912930 * @param tree          The device tree.
    913931 * @param node          The newly added device node.
     
    924942        assert(tree != NULL);
    925943        assert(dev_name != NULL);
     944        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
    926945       
    927946        node->name = dev_name;
     
    10421061       
    10431062        info = (dev_class_info_t *) malloc(sizeof(dev_class_info_t));
    1044         if (info != NULL)
     1063        if (info != NULL) {
    10451064                memset(info, 0, sizeof(dev_class_info_t));
     1065                list_initialize(&info->dev_classes);
     1066                list_initialize(&info->devmap_link);
     1067                list_initialize(&info->link);
     1068        }
    10461069       
    10471070        return info;
     
    11671190        fibril_rwlock_initialize(&class_list->rwlock);
    11681191        hash_table_create(&class_list->devmap_devices, DEVICE_BUCKETS, 1,
    1169             &devmap_devices_ops);
     1192            &devmap_devices_class_ops);
    11701193}
    11711194
     
    12151238        hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link);
    12161239        fibril_rwlock_write_unlock(&class_list->rwlock);
     1240
     1241        assert(find_devmap_class_device(class_list, cli->devmap_handle) != NULL);
    12171242}
    12181243
  • uspace/srv/devman/main.c

    r59e9398b rb2d06fa  
    281281         * handle.
    282282         */
    283         devmap_device_register(devmap_pathname, &cli->devmap_handle);
     283        devmap_device_register_with_iface(devmap_pathname,
     284            &cli->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP);
    284285       
    285286        /*
     
    486487static void devman_connection_devmapper(ipc_callid_t iid, ipc_call_t *icall)
    487488{
    488         devmap_handle_t devmap_handle = IPC_GET_IMETHOD(*icall);
     489        devmap_handle_t devmap_handle = IPC_GET_ARG2(*icall);
    489490        node_t *dev;
    490491
     
    503504        }
    504505       
    505         printf(NAME ": devman_connection_devmapper: forward connection to "
    506             "device %s to driver %s.\n", dev->pathname, dev->drv->name);
    507506        ipc_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, dev->handle, 0,
    508507            IPC_FF_NONE);
     508        printf(NAME ": devman_connection_devmapper: forwarded connection to "
     509            "device %s to driver %s.\n", dev->pathname, dev->drv->name);
    509510}
    510511
     
    512513static void devman_connection(ipc_callid_t iid, ipc_call_t *icall)
    513514{
    514         /*
    515          * Silly hack to enable the device manager to register as a driver by
    516          * the device mapper. If the ipc method is not IPC_M_CONNECT_ME_TO, this
    517          * is not the forwarded connection from naming service, so it must be a
    518          * connection from the devmapper which thinks this is a devmapper-style
    519          * driver. So pretend this is a devmapper-style driver. (This does not
    520          * work for device with handle == IPC_M_CONNECT_ME_TO, because devmapper
    521          * passes device handle to the driver as an ipc method.)
    522          */
    523         if (IPC_GET_IMETHOD(*icall) != IPC_M_CONNECT_ME_TO)
    524                 devman_connection_devmapper(iid, icall);
    525 
    526         /*
    527          * ipc method is IPC_M_CONNECT_ME_TO, so this is forwarded connection
    528          * from naming service by which we registered as device manager, so be
    529          * device manager.
    530          */
    531        
    532515        /* Select interface. */
    533516        switch ((sysarg_t) (IPC_GET_ARG1(*icall))) {
     
    542525                devman_forward(iid, icall, false);
    543526                break;
     527        case DEVMAN_CONNECT_FROM_DEVMAP:
     528                /* Someone connected through devmap node. */
     529                devman_connection_devmapper(iid, icall);
     530                break;
    544531        case DEVMAN_CONNECT_TO_PARENTS_DEVICE:
    545532                /* Connect client to selected device. */
  • uspace/srv/devmap/devmap.c

    r59e9398b rb2d06fa  
    4646#include <str.h>
    4747#include <ipc/devmap.h>
     48#include <assert.h>
    4849
    4950#define NAME          "devmap"
     
    99100        /** Device driver handling this device */
    100101        devmap_driver_t *driver;
     102        /** Use this interface when forwarding to driver. */
     103        sysarg_t forward_interface;
    101104} devmap_device_t;
    102105
     
    206209}
    207210
    208 /** Find namespace with given name.
    209  *
    210  * The devices_list_mutex should be already held when
    211  * calling this function.
    212  *
    213  */
     211/** Find namespace with given name. */
    214212static devmap_namespace_t *devmap_namespace_find_name(const char *name)
    215213{
    216214        link_t *item;
     215       
     216        assert(fibril_mutex_is_locked(&devices_list_mutex));
     217       
    217218        for (item = namespaces_list.next; item != &namespaces_list; item = item->next) {
    218219                devmap_namespace_t *namespace =
     
    227228/** Find namespace with given handle.
    228229 *
    229  * The devices_list_mutex should be already held when
    230  * calling this function.
    231  *
    232230 * @todo: use hash table
    233231 *
     
    236234{
    237235        link_t *item;
     236       
     237        assert(fibril_mutex_is_locked(&devices_list_mutex));
     238       
    238239        for (item = namespaces_list.next; item != &namespaces_list; item = item->next) {
    239240                devmap_namespace_t *namespace =
     
    246247}
    247248
    248 /** Find device with given name.
    249  *
    250  * The devices_list_mutex should be already held when
    251  * calling this function.
    252  *
    253  */
     249/** Find device with given name. */
    254250static devmap_device_t *devmap_device_find_name(const char *ns_name,
    255251    const char *name)
    256252{
    257253        link_t *item;
     254       
     255        assert(fibril_mutex_is_locked(&devices_list_mutex));
     256       
    258257        for (item = devices_list.next; item != &devices_list; item = item->next) {
    259258                devmap_device_t *device =
     
    269268/** Find device with given handle.
    270269 *
    271  * The devices_list_mutex should be already held when
    272  * calling this function.
    273  *
    274270 * @todo: use hash table
    275271 *
     
    278274{
    279275        link_t *item;
     276       
     277        assert(fibril_mutex_is_locked(&devices_list_mutex));
     278       
    280279        for (item = devices_list.next; item != &devices_list; item = item->next) {
    281280                devmap_device_t *device =
     
    288287}
    289288
    290 /** Create a namespace (if not already present)
    291  *
    292  * The devices_list_mutex should be already held when
    293  * calling this function.
    294  *
    295  */
     289/** Create a namespace (if not already present). */
    296290static devmap_namespace_t *devmap_namespace_create(const char *ns_name)
    297291{
    298         devmap_namespace_t *namespace = devmap_namespace_find_name(ns_name);
     292        devmap_namespace_t *namespace;
     293       
     294        assert(fibril_mutex_is_locked(&devices_list_mutex));
     295       
     296        namespace = devmap_namespace_find_name(ns_name);
    299297        if (namespace != NULL)
    300298                return namespace;
     
    321319}
    322320
    323 /** Destroy a namespace (if it is no longer needed)
    324  *
    325  * The devices_list_mutex should be already held when
    326  * calling this function.
    327  *
    328  */
     321/** Destroy a namespace (if it is no longer needed). */
    329322static void devmap_namespace_destroy(devmap_namespace_t *namespace)
    330323{
     324        assert(fibril_mutex_is_locked(&devices_list_mutex));
     325
    331326        if (namespace->refcnt == 0) {
    332327                list_remove(&(namespace->namespaces));
     
    337332}
    338333
    339 /** Increase namespace reference count by including device
    340  *
    341  * The devices_list_mutex should be already held when
    342  * calling this function.
    343  *
    344  */
     334/** Increase namespace reference count by including device. */
    345335static void devmap_namespace_addref(devmap_namespace_t *namespace,
    346336    devmap_device_t *device)
    347337{
     338        assert(fibril_mutex_is_locked(&devices_list_mutex));
     339
    348340        device->namespace = namespace;
    349341        namespace->refcnt++;
    350342}
    351343
    352 /** Decrease namespace reference count
    353  *
    354  * The devices_list_mutex should be already held when
    355  * calling this function.
    356  *
    357  */
     344/** Decrease namespace reference count. */
    358345static void devmap_namespace_delref(devmap_namespace_t *namespace)
    359346{
     347        assert(fibril_mutex_is_locked(&devices_list_mutex));
     348
    360349        namespace->refcnt--;
    361350        devmap_namespace_destroy(namespace);
    362351}
    363352
    364 /** Unregister device and free it
    365  *
    366  * The devices_list_mutex should be already held when
    367  * calling this function.
    368  *
    369  */
     353/** Unregister device and free it. */
    370354static void devmap_device_unregister_core(devmap_device_t *device)
    371355{
     356        assert(fibril_mutex_is_locked(&devices_list_mutex));
     357
    372358        devmap_namespace_delref(device->namespace);
    373359        list_remove(&(device->devices));
     
    517503        }
    518504       
     505        /* Set the interface, if any. */
     506        device->forward_interface = IPC_GET_ARG1(*icall);
     507
    519508        /* Get fqdn */
    520509        char *fqdn;
     
    566555        /* Get unique device handle */
    567556        device->handle = devmap_create_handle();
    568        
     557
    569558        devmap_namespace_addref(namespace, device);
    570559        device->driver = driver;
     
    617606        }
    618607       
    619         ipc_forward_fast(callid, dev->driver->phone, dev->handle,
    620             IPC_GET_ARG3(*call), 0, IPC_FF_NONE);
     608        if (dev->forward_interface == 0) {
     609                ipc_forward_fast(callid, dev->driver->phone,
     610                    dev->handle, 0, 0,
     611                    IPC_FF_NONE);
     612        } else {
     613                ipc_forward_fast(callid, dev->driver->phone,
     614                    dev->forward_interface, dev->handle, 0,
     615                    IPC_FF_NONE);
     616        }
    621617       
    622618        fibril_mutex_unlock(&devices_list_mutex);
  • uspace/srv/fs/devfs/devfs_ops.c

    r59e9398b rb2d06fa  
    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                }
     
    564609               
    565610                device_t *dev = hash_table_get_instance(lnk, device_t, link);
     611                assert(dev->phone >= 0);
    566612               
    567613                ipc_callid_t callid;
     
    627673               
    628674                device_t *dev = hash_table_get_instance(lnk, device_t, link);
     675                assert(dev->phone >= 0);
    629676               
    630677                ipc_callid_t callid;
     
    696743               
    697744                device_t *dev = hash_table_get_instance(lnk, device_t, link);
     745                assert(dev->phone >= 0);
    698746                dev->refcount--;
    699747               
     
    743791               
    744792                device_t *dev = hash_table_get_instance(lnk, device_t, link);
     793                assert(dev->phone >= 0);
    745794               
    746795                /* Make a request at the driver */
  • uspace/srv/net/tl/tcp/tcp.c

    r59e9398b rb2d06fa  
    18031803                        fibril_rwlock_write_unlock(socket_data->local_lock);
    18041804
     1805                        socket_data->state = TCP_SOCKET_SYN_SENT;
     1806
    18051807                        /* Send the packet */
    18061808                        printf("connecting %d\n", packet_get_id(packet));
     
    20852087        if (!fibril) {
    20862088                free(operation_timeout);
    2087                 return EPARTY;  /* FIXME: use another EC */
    2088         }
     2089                return ENOMEM;
     2090        }
     2091
    20892092//      fibril_mutex_lock(&socket_data->operation.mutex);
    20902093        /* Start the timeout fibril */
  • uspace/srv/vfs/vfs_lookup.c

    r59e9398b rb2d06fa  
    179179        fibril_mutex_unlock(&plb_mutex);
    180180       
    181         if (((int) rc < EOK) || (!result))
     181        if ((int) rc < EOK)
    182182                return (int) rc;
     183
     184        if (!result)
     185                return EOK;
    183186       
    184187        result->triplet.fs_handle = (fs_handle_t) rc;
Note: See TracChangeset for help on using the changeset viewer.