Ignore:
File:
1 edited

Legend:

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

    r33fc3ae r3e6a98c5  
    4444#include <errno.h>
    4545#include <str_error.h>
    46 #include <bool.h>
     46#include <stdbool.h>
    4747#include <fibril_synch.h>
    4848#include <stdlib.h>
     
    7373        char *drv_name = NULL;
    7474
    75         log_msg(LVL_DEBUG, "devman_driver_register");
     75        log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_driver_register");
    7676       
    7777        /* Get driver name. */
     
    8282        }
    8383
    84         log_msg(LVL_DEBUG, "The `%s' driver is trying to register.",
     84        log_msg(LOG_DEFAULT, LVL_DEBUG, "The `%s' driver is trying to register.",
    8585            drv_name);
    8686       
     
    8888        driver = find_driver(&drivers_list, drv_name);
    8989        if (driver == NULL) {
    90                 log_msg(LVL_ERROR, "No driver named `%s' was found.", drv_name);
     90                log_msg(LOG_DEFAULT, LVL_ERROR, "No driver named `%s' was found.", drv_name);
    9191                free(drv_name);
    9292                drv_name = NULL;
     
    102102        if (driver->sess) {
    103103                /* We already have a connection to the driver. */
    104                 log_msg(LVL_ERROR, "Driver '%s' already started.\n",
     104                log_msg(LOG_DEFAULT, LVL_ERROR, "Driver '%s' already started.\n",
    105105                    driver->name);
    106106                fibril_mutex_unlock(&driver->driver_mutex);
     
    112112        case DRIVER_NOT_STARTED:
    113113                /* Somebody started the driver manually. */
    114                 log_msg(LVL_NOTE, "Driver '%s' started manually.\n",
     114                log_msg(LOG_DEFAULT, LVL_NOTE, "Driver '%s' started manually.\n",
    115115                    driver->name);
    116116                driver->state = DRIVER_STARTING;
     
    125125       
    126126        /* Create connection to the driver. */
    127         log_msg(LVL_DEBUG, "Creating connection to the `%s' driver.",
     127        log_msg(LOG_DEFAULT, LVL_DEBUG, "Creating connection to the `%s' driver.",
    128128            driver->name);
    129129        driver->sess = async_callback_receive(EXCHANGE_PARALLEL);
     
    136136        async_sess_args_set(driver->sess, DRIVER_DEVMAN, 0, 0);
    137137       
    138         log_msg(LVL_NOTE,
     138        log_msg(LOG_DEFAULT, LVL_NOTE,
    139139            "The `%s' driver was successfully registered as running.",
    140140            driver->name);
     
    147147        fid_t fid = fibril_create(init_running_drv, driver);
    148148        if (fid == 0) {
    149                 log_msg(LVL_ERROR, "Failed to create initialization fibril " \
     149                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed to create initialization fibril " \
    150150                    "for driver `%s'.", driver->name);
    151151                fibril_mutex_unlock(&driver->driver_mutex);
     
    176176        callid = async_get_call(&call);
    177177        if (DEVMAN_ADD_MATCH_ID != IPC_GET_IMETHOD(call)) {
    178                 log_msg(LVL_ERROR,
     178                log_msg(LOG_DEFAULT, LVL_ERROR,
    179179                    "Invalid protocol when trying to receive match id.");
    180180                async_answer_0(callid, EINVAL);
     
    184184       
    185185        if (match_id == NULL) {
    186                 log_msg(LVL_ERROR, "Failed to allocate match id.");
     186                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed to allocate match id.");
    187187                async_answer_0(callid, ENOMEM);
    188188                return ENOMEM;
     
    198198        if (rc != EOK) {
    199199                delete_match_id(match_id);
    200                 log_msg(LVL_ERROR, "Failed to receive match id string: %s.",
     200                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed to receive match id string: %s.",
    201201                    str_error(rc));
    202202                return rc;
     
    205205        list_append(&match_id->link, &match_ids->ids);
    206206       
    207         log_msg(LVL_DEBUG, "Received match id `%s', score %d.",
     207        log_msg(LOG_DEFAULT, LVL_DEBUG, "Received match id `%s', score %d.",
    208208            match_id->id, match_id->score);
    209209        return rc;
     
    248248        if (fun->state == FUN_ON_LINE) {
    249249                fibril_rwlock_write_unlock(&device_tree.rwlock);
    250                 log_msg(LVL_WARN, "Function %s is already on line.",
     250                log_msg(LOG_DEFAULT, LVL_WARN, "Function %s is already on line.",
    251251                    fun->pathname);
    252252                return EOK;
     
    264264        }
    265265       
    266         log_msg(LVL_DEBUG, "devman_add_function(fun=\"%s\")", fun->pathname);
     266        log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_add_function(fun=\"%s\")", fun->pathname);
    267267       
    268268        if (fun->ftype == fun_inner) {
     
    282282                fid_t assign_fibril = fibril_create(assign_driver_fibril, dev);
    283283                if (assign_fibril == 0) {
    284                         log_msg(LVL_ERROR, "Failed to create fibril for "
     284                        log_msg(LOG_DEFAULT, LVL_ERROR, "Failed to create fibril for "
    285285                            "assigning driver.");
    286286                        /* XXX Cleanup */
     
    305305        if (fun->state == FUN_OFF_LINE) {
    306306                fibril_rwlock_write_unlock(&device_tree.rwlock);
    307                 log_msg(LVL_WARN, "Function %s is already off line.",
     307                log_msg(LOG_DEFAULT, LVL_WARN, "Function %s is already off line.",
    308308                    fun->pathname);
    309309                return EOK;
     
    311311       
    312312        if (fun->ftype == fun_inner) {
    313                 log_msg(LVL_DEBUG, "Offlining inner function %s.",
     313                log_msg(LOG_DEFAULT, LVL_DEBUG, "Offlining inner function %s.",
    314314                    fun->pathname);
    315315               
     
    359359                if (rc != EOK) {
    360360                        fibril_rwlock_write_unlock(&device_tree.rwlock);
    361                         log_msg(LVL_ERROR, "Failed unregistering tree service.");
     361                        log_msg(LOG_DEFAULT, LVL_ERROR, "Failed unregistering tree service.");
    362362                        return EIO;
    363363                }
     
    391391        if (ftype != fun_inner && ftype != fun_exposed) {
    392392                /* Unknown function type */
    393                 log_msg(LVL_ERROR,
     393                log_msg(LOG_DEFAULT, LVL_ERROR,
    394394                    "Unknown function type %d provided by driver.",
    395395                    (int) ftype);
     
    432432       
    433433        fun_node_t *fun = create_fun_node();
     434        /* One reference for creation, one for us */
     435        fun_add_ref(fun);
    434436        fun_add_ref(fun);
    435437        fun->ftype = ftype;
     438       
     439        /*
     440         * We can lock the function here even when holding the tree because
     441         * we know it cannot be held by anyone else yet.
     442         */
     443        fun_busy_lock(fun);
    436444       
    437445        if (!insert_fun_node(&device_tree, fun, fun_name, pdev)) {
    438446                fibril_rwlock_write_unlock(&tree->rwlock);
    439447                dev_del_ref(pdev);
     448                fun_busy_unlock(fun);
     449                fun_del_ref(fun);
    440450                delete_fun_node(fun);
    441451                async_answer_0(callid, ENOMEM);
     
    450460        rc = online_function(fun);
    451461        if (rc != EOK) {
    452                 /* XXX clean up */
     462                /* XXX Set some failed state? */
     463                fun_busy_unlock(fun);
     464                fun_del_ref(fun);
    453465                async_answer_0(callid, rc);
    454466                return;
    455467        }
     468       
     469        fun_busy_unlock(fun);
     470        fun_del_ref(fun);
    456471       
    457472        /* Return device handle to parent's driver. */
     
    492507        if (rc == EOK) {
    493508                loc_service_add_to_cat(fun->service_id, cat_id);
    494                 log_msg(LVL_NOTE, "Function `%s' added to category `%s'.",
     509                log_msg(LOG_DEFAULT, LVL_NOTE, "Function `%s' added to category `%s'.",
    495510                    fun->pathname, cat_name);
    496511        } else {
    497                 log_msg(LVL_ERROR, "Failed adding function `%s' to category "
     512                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed adding function `%s' to category "
    498513                    "`%s'.", fun->pathname, cat_name);
    499514        }
     
    514529        int rc;
    515530       
    516         log_msg(LVL_DEBUG, "devman_drv_fun_online()");
     531        log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_drv_fun_online()");
    517532       
    518533        fun = find_fun_node(&device_tree, IPC_GET_ARG1(*icall));
     
    521536                return;
    522537        }
     538       
     539        fun_busy_lock(fun);
    523540       
    524541        fibril_rwlock_read_lock(&device_tree.rwlock);
    525542        if (fun->dev == NULL || fun->dev->drv != drv) {
    526543                fibril_rwlock_read_unlock(&device_tree.rwlock);
     544                fun_busy_unlock(fun);
    527545                fun_del_ref(fun);
    528546                async_answer_0(iid, ENOENT);
     
    533551        rc = online_function(fun);
    534552        if (rc != EOK) {
     553                fun_busy_unlock(fun);
    535554                fun_del_ref(fun);
    536555                async_answer_0(iid, (sysarg_t) rc);
     
    538557        }
    539558       
     559        fun_busy_unlock(fun);
    540560        fun_del_ref(fun);
    541561       
     
    559579        }
    560580       
     581        fun_busy_lock(fun);
     582       
    561583        fibril_rwlock_write_lock(&device_tree.rwlock);
    562584        if (fun->dev == NULL || fun->dev->drv != drv) {
     585                fun_busy_unlock(fun);
    563586                fun_del_ref(fun);
    564587                async_answer_0(iid, ENOENT);
     
    569592        rc = offline_function(fun);
    570593        if (rc != EOK) {
     594                fun_busy_unlock(fun);
    571595                fun_del_ref(fun);
    572596                async_answer_0(iid, (sysarg_t) rc);
     
    574598        }
    575599       
     600        fun_busy_unlock(fun);
    576601        fun_del_ref(fun);
    577602        async_answer_0(iid, (sysarg_t) EOK);
     
    591616        }
    592617       
     618        fun_busy_lock(fun);
     619       
    593620        fibril_rwlock_write_lock(&tree->rwlock);
    594621       
    595         log_msg(LVL_DEBUG, "devman_remove_function(fun='%s')", fun->pathname);
     622        log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_remove_function(fun='%s')", fun->pathname);
    596623       
    597624        /* Check function state */
    598625        if (fun->state == FUN_REMOVED) {
    599626                fibril_rwlock_write_unlock(&tree->rwlock);
     627                fun_busy_unlock(fun);
     628                fun_del_ref(fun);
    600629                async_answer_0(callid, ENOENT);
    601630                return;
     
    624653                        /* Verify that driver succeeded and removed all functions */
    625654                        if (gone_rc != EOK || !list_empty(&dev->functions)) {
    626                                 log_msg(LVL_ERROR, "Driver did not remove "
     655                                log_msg(LOG_DEFAULT, LVL_ERROR, "Driver did not remove "
    627656                                    "functions for device that is gone. "
    628657                                    "Device node is now defunct.");
     
    638667                                if (gone_rc == EOK)
    639668                                        gone_rc = ENOTSUP;
     669                                fun_busy_unlock(fun);
     670                                fun_del_ref(fun);
    640671                                async_answer_0(callid, gone_rc);
    641672                                return;
     
    661692                        rc = loc_service_unregister(fun->service_id);
    662693                        if (rc != EOK) {
    663                                 log_msg(LVL_ERROR, "Failed unregistering tree "
     694                                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed unregistering tree "
    664695                                    "service.");
    665696                                fibril_rwlock_write_unlock(&tree->rwlock);
     697                                fun_busy_unlock(fun);
    666698                                fun_del_ref(fun);
    667699                                async_answer_0(callid, EIO);
     
    673705        remove_fun_node(&device_tree, fun);
    674706        fibril_rwlock_write_unlock(&tree->rwlock);
     707        fun_busy_unlock(fun);
    675708       
    676709        /* Delete ref added when inserting function into tree */
     
    679712        fun_del_ref(fun);
    680713       
    681         log_msg(LVL_DEBUG, "devman_remove_function() succeeded.");
     714        log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_remove_function() succeeded.");
    682715        async_answer_0(callid, EOK);
    683716}
     
    693726       
    694727        initialize_running_driver(driver, &device_tree);
    695         log_msg(LVL_DEBUG, "The `%s` driver was successfully initialized.",
     728        log_msg(LOG_DEFAULT, LVL_DEBUG, "The `%s` driver was successfully initialized.",
    696729            driver->name);
    697730        return 0;
     
    709742        client = async_get_client_data();
    710743        if (client == NULL) {
    711                 log_msg(LVL_ERROR, "Failed to allocate client data.");
     744                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed to allocate client data.");
    712745                return;
    713746        }
     
    11961229         */
    11971230        if (dev == NULL) {
    1198                 log_msg(LVL_ERROR, "IPC forwarding failed - no device or "
     1231                log_msg(LOG_DEFAULT, LVL_ERROR, "IPC forwarding failed - no device or "
    11991232                    "function with handle %" PRIun " was found.", handle);
    12001233                async_answer_0(iid, ENOENT);
     
    12031236
    12041237        if (fun == NULL && !drv_to_parent) {
    1205                 log_msg(LVL_ERROR, NAME ": devman_forward error - cannot "
     1238                log_msg(LOG_DEFAULT, LVL_ERROR, NAME ": devman_forward error - cannot "
    12061239                    "connect to handle %" PRIun ", refers to a device.",
    12071240                    handle);
     
    12311264       
    12321265        if (driver == NULL) {
    1233                 log_msg(LVL_ERROR, "IPC forwarding refused - " \
     1266                log_msg(LOG_DEFAULT, LVL_ERROR, "IPC forwarding refused - " \
    12341267                    "the device %" PRIun " is not in usable state.", handle);
    12351268                async_answer_0(iid, ENOENT);
     
    12441277       
    12451278        if (!driver->sess) {
    1246                 log_msg(LVL_ERROR,
     1279                log_msg(LOG_DEFAULT, LVL_ERROR,
    12471280                    "Could not forward to driver `%s'.", driver->name);
    12481281                async_answer_0(iid, EINVAL);
     
    12511284
    12521285        if (fun != NULL) {
    1253                 log_msg(LVL_DEBUG,
     1286                log_msg(LOG_DEFAULT, LVL_DEBUG,
    12541287                    "Forwarding request for `%s' function to driver `%s'.",
    12551288                    fun->pathname, driver->name);
    12561289        } else {
    1257                 log_msg(LVL_DEBUG,
     1290                log_msg(LOG_DEFAULT, LVL_DEBUG,
    12581291                    "Forwarding request for `%s' device to driver `%s'.",
    12591292                    dev->pfun->pathname, driver->name);
     
    12871320       
    12881321        if (fun == NULL || fun->dev == NULL || fun->dev->drv == NULL) {
    1289                 log_msg(LVL_WARN, "devman_connection_loc(): function "
     1322                log_msg(LOG_DEFAULT, LVL_WARN, "devman_connection_loc(): function "
    12901323                    "not found.\n");
    12911324                fibril_rwlock_read_unlock(&device_tree.rwlock);
     
    13051338        async_exchange_end(exch);
    13061339       
    1307         log_msg(LVL_DEBUG,
     1340        log_msg(LOG_DEFAULT, LVL_DEBUG,
    13081341            "Forwarding loc service request for `%s' function to driver `%s'.",
    13091342            fun->pathname, driver->name);
     
    13611394static bool devman_init(void)
    13621395{
    1363         log_msg(LVL_DEBUG, "devman_init - looking for available drivers.");
     1396        log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_init - looking for available drivers.");
    13641397       
    13651398        /* Initialize list of available drivers. */
     
    13671400        if (lookup_available_drivers(&drivers_list,
    13681401            DRIVER_DEFAULT_STORE) == 0) {
    1369                 log_msg(LVL_FATAL, "No drivers found.");
     1402                log_msg(LOG_DEFAULT, LVL_FATAL, "No drivers found.");
    13701403                return false;
    13711404        }
    13721405       
    1373         log_msg(LVL_DEBUG, "devman_init - list of drivers has been initialized.");
     1406        log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_init - list of drivers has been initialized.");
    13741407       
    13751408        /* Create root device node. */
    13761409        if (!init_device_tree(&device_tree, &drivers_list)) {
    1377                 log_msg(LVL_FATAL, "Failed to initialize device tree.");
     1410                log_msg(LOG_DEFAULT, LVL_FATAL, "Failed to initialize device tree.");
    13781411                return false;
    13791412        }
     
    13951428        printf("%s: HelenOS Device Manager\n", NAME);
    13961429       
    1397         int rc = log_init(NAME, LVL_WARN);
     1430        int rc = log_init(NAME);
    13981431        if (rc != EOK) {
    13991432                printf("%s: Error initializing logging subsystem.\n", NAME);
     
    14071440       
    14081441        if (!devman_init()) {
    1409                 log_msg(LVL_ERROR, "Error while initializing service.");
     1442                log_msg(LOG_DEFAULT, LVL_ERROR, "Error while initializing service.");
    14101443                return -1;
    14111444        }
     
    14141447        rc = service_register(SERVICE_DEVMAN);
    14151448        if (rc != EOK) {
    1416                 log_msg(LVL_ERROR, "Failed registering as a service.");
     1449                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering as a service.");
    14171450                return rc;
    14181451        }
Note: See TracChangeset for help on using the changeset viewer.