Ignore:
File:
1 edited

Legend:

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

    r3ad7b1c rb927375  
    4343#include <stdio.h>
    4444#include <errno.h>
    45 #include <str_error.h>
    4645#include <bool.h>
    4746#include <fibril_synch.h>
     
    5251#include <sys/stat.h>
    5352#include <ctype.h>
    54 #include <io/log.h>
    5553#include <ipc/devman.h>
    5654#include <ipc/driver.h>
     
    7371        driver_t *driver = NULL;
    7472
    75         log_msg(LVL_DEBUG, "devman_driver_register");
     73        printf(NAME ": devman_driver_register \n");
    7674       
    7775        iid = async_get_call(&icall);
     
    9088        }
    9189
    92         log_msg(LVL_DEBUG, "The `%s' driver is trying to register.",
     90        printf(NAME ": the %s driver is trying to register by the service.\n",
    9391            drv_name);
    9492       
    9593        /* Find driver structure. */
    9694        driver = find_driver(&drivers_list, drv_name);
     95       
    9796        if (driver == NULL) {
    98                 log_msg(LVL_ERROR, "No driver named `%s' was found.", drv_name);
     97                printf(NAME ": no driver named %s was found.\n", drv_name);
    9998                free(drv_name);
    10099                drv_name = NULL;
     
    106105        drv_name = NULL;
    107106       
    108         fibril_mutex_lock(&driver->driver_mutex);
    109        
    110         if (driver->phone >= 0) {
    111                 /* We already have a connection to the driver. */
    112                 log_msg(LVL_ERROR, "Driver '%s' already started.\n",
    113                     driver->name);
    114                 fibril_mutex_unlock(&driver->driver_mutex);
    115                 async_answer_0(iid, EEXISTS);
    116                 return NULL;
    117         }
    118        
    119         switch (driver->state) {
    120         case DRIVER_NOT_STARTED:
    121                 /* Somebody started the driver manually. */
    122                 log_msg(LVL_NOTE, "Driver '%s' started manually.\n",
    123                     driver->name);
    124                 driver->state = DRIVER_STARTING;
    125                 break;
    126         case DRIVER_STARTING:
    127                 /* The expected case */
    128                 break;
    129         case DRIVER_RUNNING:
    130                 /* Should not happen since we do not have a connected phone */
    131                 assert(false);
    132         }
    133        
    134107        /* Create connection to the driver. */
    135         log_msg(LVL_DEBUG, "Creating connection to the `%s' driver.",
    136             driver->name);
     108        printf(NAME ":  creating connection to the %s driver.\n", driver->name);
    137109        ipc_call_t call;
    138110        ipc_callid_t callid = async_get_call(&call);
    139111        if (IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) {
    140                 fibril_mutex_unlock(&driver->driver_mutex);
    141112                async_answer_0(callid, ENOTSUP);
    142113                async_answer_0(iid, ENOTSUP);
     
    145116       
    146117        /* Remember driver's phone. */
    147         driver->phone = IPC_GET_ARG5(call);
    148        
    149         fibril_mutex_unlock(&driver->driver_mutex);
    150        
    151         log_msg(LVL_NOTE,
    152             "The `%s' driver was successfully registered as running.",
     118        set_driver_phone(driver, IPC_GET_ARG5(call));
     119       
     120        printf(NAME ": the %s driver was successfully registered as running.\n",
    153121            driver->name);
    154122       
     
    174142        callid = async_get_call(&call);
    175143        if (DEVMAN_ADD_MATCH_ID != IPC_GET_IMETHOD(call)) {
    176                 log_msg(LVL_ERROR,
    177                     "Invalid protocol when trying to receive match id.");
     144                printf(NAME ": ERROR: devman_receive_match_id - invalid "
     145                    "protocol.\n");
    178146                async_answer_0(callid, EINVAL);
    179147                delete_match_id(match_id);
     
    182150       
    183151        if (match_id == NULL) {
    184                 log_msg(LVL_ERROR, "Failed to allocate match id.");
     152                printf(NAME ": ERROR: devman_receive_match_id - failed to "
     153                    "allocate match id.\n");
    185154                async_answer_0(callid, ENOMEM);
    186155                return ENOMEM;
     
    196165        if (rc != EOK) {
    197166                delete_match_id(match_id);
    198                 log_msg(LVL_ERROR, "Failed to receive match id string: %s.",
    199                     str_error(rc));
     167                printf(NAME ": devman_receive_match_id - failed to receive "
     168                    "match id string.\n");
    200169                return rc;
    201170        }
     
    203172        list_append(&match_id->link, &match_ids->ids);
    204173       
    205         log_msg(LVL_DEBUG, "Received match id `%s', score %d.",
     174        printf(NAME ": received match id '%s', score = %d \n",
    206175            match_id->id, match_id->score);
    207176        return rc;
     
    259228        if (ftype != fun_inner && ftype != fun_exposed) {
    260229                /* Unknown function type */
    261                 log_msg(LVL_ERROR,
    262                     "Unknown function type %d provided by driver.",
    263                     (int) ftype);
     230                printf(NAME ": Error, unknown function type provided by driver!\n");
    264231
    265232                fibril_rwlock_write_unlock(&tree->rwlock);
     
    276243        }
    277244       
    278         /* Check that function with same name is not there already. */
    279         if (find_fun_node_in_device(pdev, fun_name) != NULL) {
    280                 fibril_rwlock_write_unlock(&tree->rwlock);
    281                 async_answer_0(callid, EEXISTS);
    282                 printf(NAME ": Warning, driver tried to register `%s' twice.\n",
    283                     fun_name);
    284                 free(fun_name);
    285                 return;
    286         }
    287 
    288245        fun_node_t *fun = create_fun_node();
    289246        if (!insert_fun_node(&device_tree, fun, fun_name, pdev)) {
     
    308265        fibril_rwlock_write_unlock(&tree->rwlock);
    309266       
    310         log_msg(LVL_DEBUG, "devman_add_function(fun=\"%s\")", fun->pathname);
     267        printf(NAME ": devman_add_function %s\n", fun->pathname);
    311268       
    312269        devman_receive_match_ids(match_count, &fun->match_ids);
     
    390347        devmap_register_class_dev(class_info);
    391348       
    392         log_msg(LVL_NOTE, "Function `%s' added to class `%s' as `%s'.",
    393             fun->pathname, class_name, class_info->dev_name);
     349        printf(NAME ": function'%s' added to class '%s', class name '%s' was "
     350            "asigned to it\n", fun->pathname, class_name, class_info->dev_name);
    394351
    395352        async_answer_0(callid, EOK);
     
    406363       
    407364        initialize_running_driver(driver, &device_tree);
    408         log_msg(LVL_DEBUG, "The `%s` driver was successfully initialized.",
     365        printf(NAME ": the %s driver was successfully initialized. \n",
    409366            driver->name);
    410367        return 0;
     
    428385        fid_t fid = fibril_create(init_running_drv, driver);
    429386        if (fid == 0) {
    430                 log_msg(LVL_ERROR, "Failed to create initialization fibril " \
    431                     "for driver `%s'.", driver->name);
     387                printf(NAME ": Error creating fibril for the initialization of "
     388                    "the newly registered running driver.\n");
    432389                return;
    433390        }
     
    481438}
    482439
    483 /** Find handle for the device instance identified by device class name. */
    484 static void devman_function_get_handle_by_class(ipc_callid_t iid,
    485     ipc_call_t *icall)
    486 {
    487         char *classname;
    488         char *devname;
    489 
    490         int rc = async_data_write_accept((void **) &classname, true, 0, 0, 0, 0);
    491         if (rc != EOK) {
    492                 async_answer_0(iid, rc);
    493                 return;
    494         }
    495         rc = async_data_write_accept((void **) &devname, true, 0, 0, 0, 0);
    496         if (rc != EOK) {
    497                 free(classname);
    498                 async_answer_0(iid, rc);
    499                 return;
    500         }
    501 
    502 
    503         fun_node_t *fun = find_fun_node_by_class(&class_list,
    504             classname, devname);
    505 
    506         free(classname);
    507         free(devname);
    508 
    509         if (fun == NULL) {
    510                 async_answer_0(iid, ENOENT);
    511                 return;
    512         }
    513 
    514         async_answer_1(iid, EOK, fun->handle);
    515 }
    516 
    517440
    518441/** Function for handling connections from a client to the device manager. */
     
    534457                        devman_function_get_handle(callid, &call);
    535458                        break;
    536                 case DEVMAN_DEVICE_GET_HANDLE_BY_CLASS:
    537                         devman_function_get_handle_by_class(callid, &call);
    538                         break;
    539459                default:
    540460                        async_answer_0(callid, ENOENT);
     
    557477                dev = fun->dev;
    558478
    559         /*
    560          * For a valid function to connect to we need a device. The root
    561          * function, for example, has no device and cannot be connected to.
    562          * This means @c dev needs to be valid regardless whether we are
    563          * connecting to a device or to a function.
    564          */
    565         if (dev == NULL) {
    566                 log_msg(LVL_ERROR, "IPC forwarding failed - no device or "
    567                     "function with handle %" PRIun " was found.", handle);
     479        if (fun == NULL && dev == NULL) {
     480                printf(NAME ": devman_forward error - no device or function with "
     481                    "handle %" PRIun " was found.\n", handle);
    568482                async_answer_0(iid, ENOENT);
    569483                return;
     
    571485
    572486        if (fun == NULL && !drv_to_parent) {
    573                 log_msg(LVL_ERROR, NAME ": devman_forward error - cannot "
    574                     "connect to handle %" PRIun ", refers to a device.",
    575                     handle);
     487                printf(NAME ": devman_forward error - cannot connect to "
     488                    "handle %" PRIun ", refers to a device.\n", handle);
    576489                async_answer_0(iid, ENOENT);
    577490                return;
     
    594507       
    595508        if (driver == NULL) {
    596                 log_msg(LVL_ERROR, "IPC forwarding refused - " \
    597                     "the device %" PRIun " is not in usable state.", handle);
     509                printf(NAME ": devman_forward error - the device is not in %" PRIun
     510                    " usable state.\n", handle);
    598511                async_answer_0(iid, ENOENT);
    599512                return;
     
    606519                method = DRIVER_CLIENT;
    607520       
    608         if (driver->phone < 0) {
    609                 log_msg(LVL_ERROR,
    610                     "Could not forward to driver `%s' (phone is %d).",
    611                     driver->name, (int) driver->phone);
     521        if (driver->phone <= 0) {
     522                printf(NAME ": devman_forward: cound not forward to driver %s ",
     523                    driver->name);
     524                printf("the driver's phone is %" PRIun ").\n", driver->phone);
    612525                async_answer_0(iid, EINVAL);
    613526                return;
     
    615528
    616529        if (fun != NULL) {
    617                 log_msg(LVL_DEBUG,
    618                     "Forwarding request for `%s' function to driver `%s'.",
    619                     fun->pathname, driver->name);
     530                printf(NAME ": devman_forward: forward connection to function %s to "
     531                    "driver %s.\n", fun->pathname, driver->name);
    620532        } else {
    621                 log_msg(LVL_DEBUG,
    622                     "Forwarding request for `%s' device to driver `%s'.",
    623                     dev->pfun->pathname, driver->name);
     533                printf(NAME ": devman_forward: forward connection to device %s to "
     534                    "driver %s.\n", dev->pfun->pathname, driver->name);
    624535        }
    625536
     
    646557        dev = fun->dev;
    647558       
    648         if (dev->state != DEVICE_USABLE || dev->drv->phone < 0) {
     559        if (dev->state != DEVICE_USABLE || dev->drv->phone <= 0) {
    649560                async_answer_0(iid, EINVAL);
    650561                return;
     
    653564        async_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, fun->handle, 0,
    654565            IPC_FF_NONE);
    655         log_msg(LVL_DEBUG,
    656             "Forwarding devmapper request for `%s' function to driver `%s'.",
    657             fun->pathname, dev->drv->name);
     566        printf(NAME ": devman_connection_devmapper: forwarded connection to "
     567            "device %s to driver %s.\n", fun->pathname, dev->drv->name);
    658568}
    659569
     
    690600static bool devman_init(void)
    691601{
    692         log_msg(LVL_DEBUG, "devman_init - looking for available drivers.");
     602        printf(NAME ": devman_init - looking for available drivers.\n");
    693603       
    694604        /* Initialize list of available drivers. */
     
    696606        if (lookup_available_drivers(&drivers_list,
    697607            DRIVER_DEFAULT_STORE) == 0) {
    698                 log_msg(LVL_FATAL, "No drivers found.");
     608                printf(NAME " no drivers found.");
    699609                return false;
    700610        }
    701611
    702         log_msg(LVL_DEBUG, "devman_init - list of drivers has been initialized.");
     612        printf(NAME ": devman_init  - list of drivers has been initialized.\n");
    703613
    704614        /* Create root device node. */
    705615        if (!init_device_tree(&device_tree, &drivers_list)) {
    706                 log_msg(LVL_FATAL, "Failed to initialize device tree.");
     616                printf(NAME " failed to initialize device tree.");
    707617                return false;
    708618        }
     
    725635        printf(NAME ": HelenOS Device Manager\n");
    726636
    727         if (log_init(NAME, LVL_ERROR) != EOK) {
    728                 printf(NAME ": Error initializing logging subsystem.\n");
    729                 return -1;
    730         }
    731 
    732637        if (!devman_init()) {
    733                 log_msg(LVL_ERROR, "Error while initializing service.");
     638                printf(NAME ": Error while initializing service\n");
    734639                return -1;
    735640        }
     
    739644
    740645        /* Register device manager at naming service. */
    741         if (service_register(SERVICE_DEVMAN) != EOK) {
    742                 log_msg(LVL_ERROR, "Failed registering as a service.");
     646        if (service_register(SERVICE_DEVMAN) != EOK)
    743647                return -1;
    744         }
    745 
    746         printf(NAME ": Accepting connections.\n");
     648
     649        printf(NAME ": Accepting connections\n");
    747650        async_manager();
    748651
Note: See TracChangeset for help on using the changeset viewer.