Changeset 16dc887 in mainline for uspace/srv/devman


Ignore:
Timestamp:
2011-08-16T14:00:32Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
278ac72, b112055
Parents:
3751a08 (diff), cc574511 (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 Location service.

Location:
uspace/srv/devman
Files:
3 edited

Legend:

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

    r3751a08 r16dc887  
    3737#include <ipc/driver.h>
    3838#include <ipc/devman.h>
    39 #include <devmap.h>
     39#include <loc.h>
    4040#include <str_error.h>
    4141#include <stdio.h>
     
    6666}
    6767
    68 static int devmap_functions_compare(unsigned long key[], hash_count_t keys,
     68static int loc_functions_compare(unsigned long key[], hash_count_t keys,
    6969    link_t *item)
    7070{
    71         fun_node_t *fun = hash_table_get_instance(item, fun_node_t, devmap_fun);
    72         return (fun->devmap_handle == (devmap_handle_t) key[0]);
    73 }
    74 
    75 static int devmap_devices_class_compare(unsigned long key[], hash_count_t keys,
     71        fun_node_t *fun = hash_table_get_instance(item, fun_node_t, loc_fun);
     72        return (fun->service_id == (service_id_t) key[0]);
     73}
     74
     75static int loc_devices_class_compare(unsigned long key[], hash_count_t keys,
    7676    link_t *item)
    7777{
    7878        dev_class_info_t *class_info
    79             = hash_table_get_instance(item, dev_class_info_t, devmap_link);
     79            = hash_table_get_instance(item, dev_class_info_t, loc_link);
    8080        assert(class_info != NULL);
    8181
    82         return (class_info->devmap_handle == (devmap_handle_t) key[0]);
     82        return (class_info->service_id == (service_id_t) key[0]);
    8383}
    8484
     
    9999};
    100100
    101 static hash_table_operations_t devmap_devices_ops = {
     101static hash_table_operations_t loc_devices_ops = {
    102102        .hash = devices_hash,
    103         .compare = devmap_functions_compare,
     103        .compare = loc_functions_compare,
    104104        .remove_callback = devices_remove_callback
    105105};
    106106
    107 static hash_table_operations_t devmap_devices_class_ops = {
     107static hash_table_operations_t loc_devices_class_ops = {
    108108        .hash = devices_hash,
    109         .compare = devmap_devices_class_compare,
     109        .compare = loc_devices_class_compare,
    110110        .remove_callback = devices_remove_callback
    111111};
     
    701701}
    702702
    703 /** Create devmap path and name for the function. */
    704 void devmap_register_tree_function(fun_node_t *fun, dev_tree_t *tree)
    705 {
    706         char *devmap_pathname = NULL;
    707         char *devmap_name = NULL;
    708        
    709         asprintf(&devmap_name, "%s", fun->pathname);
    710         if (devmap_name == NULL)
     703/** Create loc path and name for the function. */
     704void loc_register_tree_function(fun_node_t *fun, dev_tree_t *tree)
     705{
     706        char *loc_pathname = NULL;
     707        char *loc_name = NULL;
     708       
     709        asprintf(&loc_name, "%s", fun->pathname);
     710        if (loc_name == NULL)
    711711                return;
    712712       
    713         replace_char(devmap_name, '/', DEVMAP_SEPARATOR);
    714        
    715         asprintf(&devmap_pathname, "%s/%s", DEVMAP_DEVICE_NAMESPACE,
    716             devmap_name);
    717         if (devmap_pathname == NULL) {
    718                 free(devmap_name);
     713        replace_char(loc_name, '/', LOC_SEPARATOR);
     714       
     715        asprintf(&loc_pathname, "%s/%s", LOC_DEVICE_NAMESPACE,
     716            loc_name);
     717        if (loc_pathname == NULL) {
     718                free(loc_name);
    719719                return;
    720720        }
    721721       
    722         devmap_device_register_with_iface(devmap_pathname,
    723             &fun->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP);
    724        
    725         tree_add_devmap_function(tree, fun);
    726        
    727         free(devmap_name);
    728         free(devmap_pathname);
     722        loc_service_register_with_iface(loc_pathname,
     723            &fun->service_id, DEVMAN_CONNECT_FROM_LOC);
     724       
     725        tree_add_loc_function(tree, fun);
     726       
     727        free(loc_name);
     728        free(loc_pathname);
    729729}
    730730
     
    856856        hash_table_create(&tree->devman_functions, DEVICE_BUCKETS, 1,
    857857            &devman_functions_ops);
    858         hash_table_create(&tree->devmap_functions, DEVICE_BUCKETS, 1,
    859             &devmap_devices_ops);
     858        hash_table_create(&tree->loc_functions, DEVICE_BUCKETS, 1,
     859            &loc_devices_ops);
    860860       
    861861        fibril_rwlock_initialize(&tree->rwlock);
     
    952952                list_initialize(&res->classes);
    953953                link_initialize(&res->devman_fun);
    954                 link_initialize(&res->devmap_fun);
     954                link_initialize(&res->loc_fun);
    955955        }
    956956       
     
    12681268                memset(info, 0, sizeof(dev_class_info_t));
    12691269                link_initialize(&info->dev_classes);
    1270                 link_initialize(&info->devmap_link);
     1270                link_initialize(&info->loc_link);
    12711271                link_initialize(&info->link);
    12721272        }
     
    14141414        list_initialize(&class_list->classes);
    14151415        fibril_rwlock_initialize(&class_list->rwlock);
    1416         hash_table_create(&class_list->devmap_functions, DEVICE_BUCKETS, 1,
    1417             &devmap_devices_class_ops);
    1418 }
    1419 
    1420 
    1421 /* Devmap devices */
    1422 
    1423 fun_node_t *find_devmap_tree_function(dev_tree_t *tree, devmap_handle_t devmap_handle)
     1416        hash_table_create(&class_list->loc_functions, DEVICE_BUCKETS, 1,
     1417            &loc_devices_class_ops);
     1418}
     1419
     1420
     1421/* loc devices */
     1422
     1423fun_node_t *find_loc_tree_function(dev_tree_t *tree, service_id_t service_id)
    14241424{
    14251425        fun_node_t *fun = NULL;
    14261426        link_t *link;
    1427         unsigned long key = (unsigned long) devmap_handle;
     1427        unsigned long key = (unsigned long) service_id;
    14281428       
    14291429        fibril_rwlock_read_lock(&tree->rwlock);
    1430         link = hash_table_find(&tree->devmap_functions, &key);
     1430        link = hash_table_find(&tree->loc_functions, &key);
    14311431        if (link != NULL)
    1432                 fun = hash_table_get_instance(link, fun_node_t, devmap_fun);
     1432                fun = hash_table_get_instance(link, fun_node_t, loc_fun);
    14331433        fibril_rwlock_read_unlock(&tree->rwlock);
    14341434       
     
    14361436}
    14371437
    1438 fun_node_t *find_devmap_class_function(class_list_t *classes,
    1439     devmap_handle_t devmap_handle)
     1438fun_node_t *find_loc_class_function(class_list_t *classes,
     1439    service_id_t service_id)
    14401440{
    14411441        fun_node_t *fun = NULL;
    14421442        dev_class_info_t *cli;
    14431443        link_t *link;
    1444         unsigned long key = (unsigned long)devmap_handle;
     1444        unsigned long key = (unsigned long)service_id;
    14451445       
    14461446        fibril_rwlock_read_lock(&classes->rwlock);
    1447         link = hash_table_find(&classes->devmap_functions, &key);
     1447        link = hash_table_find(&classes->loc_functions, &key);
    14481448        if (link != NULL) {
    14491449                cli = hash_table_get_instance(link, dev_class_info_t,
    1450                     devmap_link);
     1450                    loc_link);
    14511451                fun = cli->fun;
    14521452        }
     
    14561456}
    14571457
    1458 void class_add_devmap_function(class_list_t *class_list, dev_class_info_t *cli)
    1459 {
    1460         unsigned long key = (unsigned long) cli->devmap_handle;
     1458void class_add_loc_function(class_list_t *class_list, dev_class_info_t *cli)
     1459{
     1460        unsigned long key = (unsigned long) cli->service_id;
    14611461       
    14621462        fibril_rwlock_write_lock(&class_list->rwlock);
    1463         hash_table_insert(&class_list->devmap_functions, &key, &cli->devmap_link);
     1463        hash_table_insert(&class_list->loc_functions, &key, &cli->loc_link);
    14641464        fibril_rwlock_write_unlock(&class_list->rwlock);
    14651465
    1466         assert(find_devmap_class_function(class_list, cli->devmap_handle) != NULL);
    1467 }
    1468 
    1469 void tree_add_devmap_function(dev_tree_t *tree, fun_node_t *fun)
    1470 {
    1471         unsigned long key = (unsigned long) fun->devmap_handle;
     1466        assert(find_loc_class_function(class_list, cli->service_id) != NULL);
     1467}
     1468
     1469void tree_add_loc_function(dev_tree_t *tree, fun_node_t *fun)
     1470{
     1471        unsigned long key = (unsigned long) fun->service_id;
    14721472        fibril_rwlock_write_lock(&tree->rwlock);
    1473         hash_table_insert(&tree->devmap_functions, &key, &fun->devmap_fun);
     1473        hash_table_insert(&tree->loc_functions, &key, &fun->loc_fun);
    14741474        fibril_rwlock_write_unlock(&tree->rwlock);
    14751475}
  • uspace/srv/devman/devman.h

    r3751a08 r16dc887  
    4141#include <adt/hash_table.h>
    4242#include <ipc/devman.h>
    43 #include <ipc/devmap.h>
     43#include <ipc/loc.h>
    4444#include <fibril_synch.h>
    4545#include <atomic.h>
     
    5353#define DEVICE_BUCKETS 256
    5454
    55 #define DEVMAP_CLASS_NAMESPACE "class"
    56 #define DEVMAP_DEVICE_NAMESPACE "devices"
    57 #define DEVMAP_SEPARATOR '\\'
     55#define LOC_CLASS_NAMESPACE "class"
     56#define LOC_DEVICE_NAMESPACE "devices"
     57#define LOC_SEPARATOR '\\'
    5858
    5959struct dev_node;
     
    172172        /** List of device classes to which this device function belongs. */
    173173        list_t classes;
    174         /** Devmap handle if the device function is registered by devmap. */
    175         devmap_handle_t devmap_handle;
     174        /** Service ID if the device function is registered with loc. */
     175        service_id_t service_id;
    176176       
    177177        /**
     
    181181       
    182182        /**
    183          * Used by the hash table of functions indexed by devmap device handles.
    184          */
    185         link_t devmap_fun;
     183         * Used by the hash table of functions indexed by service IDs.
     184         */
     185        link_t loc_fun;
    186186};
    187187
     
    208208       
    209209        /**
    210          * Hash table of devices registered by devmapper, indexed by devmap
    211          * handles.
    212          */
    213         hash_table_t devmap_functions;
     210         * Hash table of services registered with location service, indexed by
     211         * service IDs.
     212         */
     213        hash_table_t loc_functions;
    214214} dev_tree_t;
    215215
     
    267267        /** The name of the device function within the class. */
    268268        char *dev_name;
    269         /** The handle of the device by device mapper in the class namespace. */
    270         devmap_handle_t devmap_handle;
    271        
    272         /**
    273          * Link in the hash table of devices registered by the devmapper using
     269        /** Service ID in the class namespace. */
     270        service_id_t service_id;
     271       
     272        /**
     273         * Link to hash table of services registered with location service using
    274274         * their class names.
    275275         */
    276         link_t devmap_link;
     276        link_t loc_link;
    277277} dev_class_info_t;
    278278
     
    283283       
    284284        /**
    285          * Hash table of devices registered by devmapper using their class name,
    286          * indexed by devmap handles.
    287          */
    288         hash_table_t devmap_functions;
     285         * Hash table of services registered with location service using their
     286         * class name, indexed by service IDs.
     287         */
     288        hash_table_t loc_functions;
    289289       
    290290        /** Fibril mutex for list of classes. */
     
    364364extern void add_dev_class_no_lock(class_list_t *, dev_class_t *);
    365365
    366 /* Devmap devices */
    367 
    368 extern void devmap_register_tree_function(fun_node_t *, dev_tree_t *);
    369 
    370 extern fun_node_t *find_devmap_tree_function(dev_tree_t *, devmap_handle_t);
    371 extern fun_node_t *find_devmap_class_function(class_list_t *, devmap_handle_t);
    372 
    373 extern void class_add_devmap_function(class_list_t *, dev_class_info_t *);
    374 extern void tree_add_devmap_function(dev_tree_t *, fun_node_t *);
     366/* Loc services */
     367
     368extern void loc_register_tree_function(fun_node_t *, dev_tree_t *);
     369
     370extern fun_node_t *find_loc_tree_function(dev_tree_t *, service_id_t);
     371extern fun_node_t *find_loc_class_function(class_list_t *, service_id_t);
     372
     373extern void class_add_loc_function(class_list_t *, dev_class_info_t *);
     374extern void tree_add_loc_function(dev_tree_t *, fun_node_t *);
    375375
    376376#endif
  • uspace/srv/devman/main.c

    r3751a08 r16dc887  
    5656#include <ipc/driver.h>
    5757#include <thread.h>
    58 #include <devmap.h>
     58#include <loc.h>
    5959
    6060#include "devman.h"
     
    326326                }
    327327        } else {
    328                 devmap_register_tree_function(fun, tree);
     328                loc_register_tree_function(fun, tree);
    329329        }
    330330       
     
    333333}
    334334
    335 static void devmap_register_class_dev(dev_class_info_t *cli)
    336 {
    337         /* Create devmap path and name for the device. */
    338         char *devmap_pathname = NULL;
    339 
    340         asprintf(&devmap_pathname, "%s/%s%c%s", DEVMAP_CLASS_NAMESPACE,
    341             cli->dev_class->name, DEVMAP_SEPARATOR, cli->dev_name);
    342         if (devmap_pathname == NULL)
     335static void loc_register_class_dev(dev_class_info_t *cli)
     336{
     337        /* Create loc path and name for the service. */
     338        char *loc_pathname = NULL;
     339
     340        asprintf(&loc_pathname, "%s/%s%c%s", LOC_CLASS_NAMESPACE,
     341            cli->dev_class->name, LOC_SEPARATOR, cli->dev_name);
     342        if (loc_pathname == NULL)
    343343                return;
    344344       
    345345        /*
    346          * Register the device by the device mapper and remember its devmap
    347          * handle.
     346         * Register the device with location service and remember its
     347         * service ID.
    348348         */
    349         devmap_device_register_with_iface(devmap_pathname,
    350             &cli->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP);
     349        loc_service_register_with_iface(loc_pathname,
     350            &cli->service_id, DEVMAN_CONNECT_FROM_LOC);
    351351       
    352352        /*
    353          * Add device to the hash map of class devices registered by device
    354          * mapper.
     353         * Add device to the hash map of class devices registered with
     354         * location service.
    355355         */
    356         class_add_devmap_function(&class_list, cli);
    357        
    358         free(devmap_pathname);
     356        class_add_loc_function(&class_list, cli);
     357       
     358        free(loc_pathname);
    359359}
    360360
     
    362362{
    363363        devman_handle_t handle = IPC_GET_ARG1(*call);
     364        category_id_t cat_id;
     365        int rc;
    364366       
    365367        /* Get class name. */
    366368        char *class_name;
    367         int rc = async_data_write_accept((void **) &class_name, true,
     369        rc = async_data_write_accept((void **) &class_name, true,
    368370            0, 0, 0, 0);
    369371        if (rc != EOK) {
     
    381383        dev_class_info_t *class_info = add_function_to_class(fun, cl, NULL);
    382384       
    383         /* Register the device's class alias by devmapper. */
    384         devmap_register_class_dev(class_info);
     385        /* Register the device's class alias with location service. */
     386        loc_register_class_dev(class_info);
     387       
     388        rc = loc_category_get_id(class_name, &cat_id, IPC_FLAG_BLOCKING);
     389        if (rc == EOK) {
     390                loc_service_add_to_cat(fun->service_id, cat_id);
     391        } else {
     392                log_msg(LVL_ERROR, "Failed adding function `%s' to category "
     393                    "`%s'.", fun->pathname, class_name);
     394        }
    385395       
    386396        log_msg(LVL_NOTE, "Function `%s' added to class `%s' as `%s'.",
     
    659669}
    660670
    661 /** Function for handling connections from a client forwarded by the device
    662  * mapper to the device manager. */
    663 static void devman_connection_devmapper(ipc_callid_t iid, ipc_call_t *icall)
    664 {
    665         devmap_handle_t devmap_handle = IPC_GET_ARG2(*icall);
     671/** Function for handling connections from a client forwarded by the location
     672 * service to the device manager. */
     673static void devman_connection_loc(ipc_callid_t iid, ipc_call_t *icall)
     674{
     675        service_id_t service_id = IPC_GET_ARG2(*icall);
    666676        fun_node_t *fun;
    667677        dev_node_t *dev;
    668678
    669         fun = find_devmap_tree_function(&device_tree, devmap_handle);
     679        fun = find_loc_tree_function(&device_tree, service_id);
    670680        if (fun == NULL)
    671                 fun = find_devmap_class_function(&class_list, devmap_handle);
     681                fun = find_loc_class_function(&class_list, service_id);
    672682       
    673683        if (fun == NULL || fun->dev->drv == NULL) {
     
    689699       
    690700        log_msg(LVL_DEBUG,
    691             "Forwarding devmapper request for `%s' function to driver `%s'.",
     701            "Forwarding loc service request for `%s' function to driver `%s'.",
    692702            fun->pathname, dev->drv->name);
    693703}
     
    708718                devman_forward(iid, icall, false);
    709719                break;
    710         case DEVMAN_CONNECT_FROM_DEVMAP:
    711                 /* Someone connected through devmap node. */
    712                 devman_connection_devmapper(iid, icall);
     720        case DEVMAN_CONNECT_FROM_LOC:
     721                /* Someone connected through loc node. */
     722                devman_connection_loc(iid, icall);
    713723                break;
    714724        case DEVMAN_CONNECT_TO_PARENTS_DEVICE:
     
    746756       
    747757        /*
    748          * !!! devman_connection ... as the device manager is not a real devmap
     758         * !!! devman_connection ... as the device manager is not a real loc
    749759         * driver (it uses a completely different ipc protocol than an ordinary
    750          * devmap driver) forwarding a connection from client to the devman by
    751          * devmapper would not work.
     760         * loc driver) forwarding a connection from client to the devman by
     761         * location service would not work.
    752762         */
    753         devmap_driver_register(NAME, devman_connection);
     763        loc_server_register(NAME, devman_connection);
    754764       
    755765        return true;
     
    760770        printf(NAME ": HelenOS Device Manager\n");
    761771
    762         if (log_init(NAME, LVL_ERROR) != EOK) {
     772        if (log_init(NAME, LVL_WARN) != EOK) {
    763773                printf(NAME ": Error initializing logging subsystem.\n");
    764774                return -1;
Note: See TracChangeset for help on using the changeset viewer.