Changeset e2b9b341 in mainline for uspace/srv/devman/main.c


Ignore:
Timestamp:
2011-09-02T16:33:02Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
224c0e7
Parents:
c1a0488
Message:

Check state for removed devices and functions.

File:
1 edited

Legend:

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

    rc1a0488 re2b9b341  
    391391        fibril_rwlock_write_lock(&tree->rwlock);
    392392       
     393        /* Check device state */
     394        if (pdev->state == DEVICE_REMOVED) {
     395                fibril_rwlock_write_unlock(&tree->rwlock);
     396                dev_del_ref(pdev);
     397                async_answer_0(callid, ENOENT);
     398                return;
     399        }
     400       
    393401        /* Check that function with same name is not there already. */
    394402        if (find_fun_node_in_device(tree, pdev, fun_name) != NULL) {
     
    453461        fibril_rwlock_read_lock(&device_tree.rwlock);
    454462       
     463        /* Check function state */
     464        if (fun->state == FUN_REMOVED) {
     465                fibril_rwlock_read_unlock(&device_tree.rwlock);
     466                async_answer_0(callid, ENOENT);
     467                return;
     468        }
     469       
    455470        rc = loc_category_get_id(cat_name, &cat_id, IPC_FLAG_BLOCKING);
    456471        if (rc == EOK) {
     
    561576       
    562577        log_msg(LVL_DEBUG, "devman_remove_function(fun='%s')", fun->pathname);
     578       
     579        /* Check function state */
     580        if (fun->state == FUN_REMOVED) {
     581                fibril_rwlock_write_unlock(&tree->rwlock);
     582                async_answer_0(callid, ENOENT);
     583                return;
     584        }
    563585       
    564586        if (fun->ftype == fun_inner) {
     
    700722
    701723        fibril_rwlock_read_lock(&device_tree.rwlock);
     724
     725        /* Check function state */
     726        if (fun->state == FUN_REMOVED) {
     727                fibril_rwlock_read_unlock(&device_tree.rwlock);
     728                async_answer_0(iid, ENOENT);
     729                return;
     730        }
    702731        handle = fun->handle;
     732
    703733        fibril_rwlock_read_unlock(&device_tree.rwlock);
    704734
     
    738768        fibril_rwlock_read_lock(&device_tree.rwlock);
    739769
     770        /* Check function state */
     771        if (fun->state == FUN_REMOVED) {
     772                fibril_rwlock_read_unlock(&device_tree.rwlock);
     773                free(buffer);
     774
     775                async_answer_0(data_callid, ENOENT);
     776                async_answer_0(iid, ENOENT);
     777                fun_del_ref(fun);
     778                return;
     779        }
     780
    740781        size_t sent_length = str_size(fun->name);
    741782        if (sent_length > data_len) {
     
    781822        fibril_rwlock_read_lock(&device_tree.rwlock);
    782823       
     824        /* Check function state */
     825        if (fun->state == FUN_REMOVED) {
     826                fibril_rwlock_read_unlock(&device_tree.rwlock);
     827                free(buffer);
     828
     829                async_answer_0(data_callid, ENOENT);
     830                async_answer_0(iid, ENOENT);
     831                fun_del_ref(fun);
     832                return;
     833        }
     834       
    783835        size_t sent_length = str_size(fun->pathname);
    784836        if (sent_length > data_len) {
     
    811863        dev_node_t *dev = find_dev_node_no_lock(&device_tree,
    812864            IPC_GET_ARG1(*icall));
    813         if (dev == NULL) {
     865        if (dev == NULL || dev->state == DEVICE_REMOVED) {
    814866                fibril_rwlock_read_unlock(&device_tree.rwlock);
    815867                async_answer_0(callid, ENOENT);
     
    850902        fibril_rwlock_read_lock(&device_tree.rwlock);
    851903       
    852         fun = find_fun_node(&device_tree, IPC_GET_ARG1(*icall));
    853         if (fun == NULL) {
     904        fun = find_fun_node_no_lock(&device_tree, IPC_GET_ARG1(*icall));
     905        if (fun == NULL || fun->state == FUN_REMOVED) {
    854906                fibril_rwlock_read_unlock(&device_tree.rwlock);
    855907                async_answer_0(iid, ENOENT);
     
    858910       
    859911        if (fun->child == NULL) {
    860                 fun_del_ref(fun);
    861912                fibril_rwlock_read_unlock(&device_tree.rwlock);
    862913                async_answer_0(iid, ENOENT);
     
    866917        async_answer_1(iid, EOK, fun->child->handle);
    867918       
    868         fun_del_ref(fun);
    869919        fibril_rwlock_read_unlock(&device_tree.rwlock);
    870920}
     
    931981
    932982        fibril_rwlock_read_lock(&device_tree.rwlock);
     983
     984        /* Check function state */
     985        if (fun->state == FUN_REMOVED) {
     986                fibril_rwlock_read_unlock(&device_tree.rwlock);
     987                async_answer_0(iid, ENOENT);
     988                return;
     989        }
     990
    933991        async_answer_1(iid, EOK, fun->handle);
    934992        fibril_rwlock_read_unlock(&device_tree.rwlock);
     
    10221080        driver_t *driver = NULL;
    10231081       
     1082        fibril_rwlock_read_lock(&device_tree.rwlock);
     1083       
    10241084        if (drv_to_parent) {
    10251085                /* Connect to parent function of a device (or device function). */
     
    10351095        }
    10361096       
     1097        fibril_rwlock_read_unlock(&device_tree.rwlock);
     1098       
    10371099        if (driver == NULL) {
    10381100                log_msg(LVL_ERROR, "IPC forwarding refused - " \
     
    10831145        fun_node_t *fun;
    10841146        dev_node_t *dev;
     1147        devman_handle_t handle;
     1148        driver_t *driver;
    10851149
    10861150        fun = find_loc_tree_function(&device_tree, service_id);
    10871151       
    1088         if (fun == NULL || fun->dev->drv == NULL) {
     1152        fibril_rwlock_read_lock(&device_tree.rwlock);
     1153       
     1154        if (fun == NULL || fun->dev == NULL || fun->dev->drv == NULL) {
    10891155                log_msg(LVL_WARN, "devman_connection_loc(): function "
    10901156                    "not found.\n");
    1091                 async_answer_0(iid, ENOENT);
    1092                 return;
    1093         }
    1094        
    1095         fibril_rwlock_read_lock(&device_tree.rwlock);
     1157                fibril_rwlock_read_unlock(&device_tree.rwlock);
     1158                async_answer_0(iid, ENOENT);
     1159                return;
     1160        }
     1161       
    10961162        dev = fun->dev;
    1097         fun_del_ref(fun);
    1098        
    1099         async_exch_t *exch = async_exchange_begin(dev->drv->sess);
    1100         async_forward_fast(iid, exch, DRIVER_CLIENT, fun->handle, 0,
     1163        driver = dev->drv;
     1164        handle = fun->handle;
     1165       
     1166        fibril_rwlock_read_unlock(&device_tree.rwlock);
     1167       
     1168        async_exch_t *exch = async_exchange_begin(driver->sess);
     1169        async_forward_fast(iid, exch, DRIVER_CLIENT, handle, 0,
    11011170            IPC_FF_NONE);
    11021171        async_exchange_end(exch);
    11031172       
    1104         fibril_rwlock_read_unlock(&device_tree.rwlock);
    1105        
    11061173        log_msg(LVL_DEBUG,
    11071174            "Forwarding loc service request for `%s' function to driver `%s'.",
    1108             fun->pathname, dev->drv->name);
     1175            fun->pathname, driver->name);
     1176
     1177        fun_del_ref(fun);
    11091178}
    11101179
Note: See TracChangeset for help on using the changeset viewer.