Changeset ad7a6c9 in mainline for uspace/srv/devmap/devmap.c


Ignore:
Timestamp:
2011-03-30T13:10:24Z (15 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4ae90f9
Parents:
6e50466 (diff), d6b81941 (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

File:
1 edited

Legend:

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

    r6e50466 rad7a6c9  
    4646#include <str.h>
    4747#include <ipc/devmap.h>
     48#include <assert.h>
    4849
    4950#define NAME          "devmap"
     
    122123static devmap_handle_t last_handle = 0;
    123124static devmap_device_t *null_devices[NULL_DEVICES];
     125
     126/*
     127 * Dummy list for null devices. This is necessary so that null devices can
     128 * be used just as any other devices, e.g. in devmap_device_unregister_core().
     129 */
     130static LIST_INITIALIZE(dummy_null_driver_devices);
    124131
    125132static devmap_handle_t devmap_create_handle(void)
     
    208215}
    209216
    210 /** Find namespace with given name.
    211  *
    212  * The devices_list_mutex should be already held when
    213  * calling this function.
    214  *
    215  */
     217/** Find namespace with given name. */
    216218static devmap_namespace_t *devmap_namespace_find_name(const char *name)
    217219{
    218220        link_t *item;
     221       
     222        assert(fibril_mutex_is_locked(&devices_list_mutex));
     223       
    219224        for (item = namespaces_list.next; item != &namespaces_list; item = item->next) {
    220225                devmap_namespace_t *namespace =
     
    229234/** Find namespace with given handle.
    230235 *
    231  * The devices_list_mutex should be already held when
    232  * calling this function.
    233  *
    234236 * @todo: use hash table
    235237 *
     
    238240{
    239241        link_t *item;
     242       
     243        assert(fibril_mutex_is_locked(&devices_list_mutex));
     244       
    240245        for (item = namespaces_list.next; item != &namespaces_list; item = item->next) {
    241246                devmap_namespace_t *namespace =
     
    248253}
    249254
    250 /** Find device with given name.
    251  *
    252  * The devices_list_mutex should be already held when
    253  * calling this function.
    254  *
    255  */
     255/** Find device with given name. */
    256256static devmap_device_t *devmap_device_find_name(const char *ns_name,
    257257    const char *name)
    258258{
    259259        link_t *item;
     260       
     261        assert(fibril_mutex_is_locked(&devices_list_mutex));
     262       
    260263        for (item = devices_list.next; item != &devices_list; item = item->next) {
    261264                devmap_device_t *device =
     
    271274/** Find device with given handle.
    272275 *
    273  * The devices_list_mutex should be already held when
    274  * calling this function.
    275  *
    276276 * @todo: use hash table
    277277 *
     
    280280{
    281281        link_t *item;
     282       
     283        assert(fibril_mutex_is_locked(&devices_list_mutex));
     284       
    282285        for (item = devices_list.next; item != &devices_list; item = item->next) {
    283286                devmap_device_t *device =
     
    290293}
    291294
    292 /** Create a namespace (if not already present)
    293  *
    294  * The devices_list_mutex should be already held when
    295  * calling this function.
    296  *
    297  */
     295/** Create a namespace (if not already present). */
    298296static devmap_namespace_t *devmap_namespace_create(const char *ns_name)
    299297{
    300         devmap_namespace_t *namespace = devmap_namespace_find_name(ns_name);
     298        devmap_namespace_t *namespace;
     299       
     300        assert(fibril_mutex_is_locked(&devices_list_mutex));
     301       
     302        namespace = devmap_namespace_find_name(ns_name);
    301303        if (namespace != NULL)
    302304                return namespace;
     
    323325}
    324326
    325 /** Destroy a namespace (if it is no longer needed)
    326  *
    327  * The devices_list_mutex should be already held when
    328  * calling this function.
    329  *
    330  */
     327/** Destroy a namespace (if it is no longer needed). */
    331328static void devmap_namespace_destroy(devmap_namespace_t *namespace)
    332329{
     330        assert(fibril_mutex_is_locked(&devices_list_mutex));
     331
    333332        if (namespace->refcnt == 0) {
    334333                list_remove(&(namespace->namespaces));
     
    339338}
    340339
    341 /** Increase namespace reference count by including device
    342  *
    343  * The devices_list_mutex should be already held when
    344  * calling this function.
    345  *
    346  */
     340/** Increase namespace reference count by including device. */
    347341static void devmap_namespace_addref(devmap_namespace_t *namespace,
    348342    devmap_device_t *device)
    349343{
     344        assert(fibril_mutex_is_locked(&devices_list_mutex));
     345
    350346        device->namespace = namespace;
    351347        namespace->refcnt++;
    352348}
    353349
    354 /** Decrease namespace reference count
    355  *
    356  * The devices_list_mutex should be already held when
    357  * calling this function.
    358  *
    359  */
     350/** Decrease namespace reference count. */
    360351static void devmap_namespace_delref(devmap_namespace_t *namespace)
    361352{
     353        assert(fibril_mutex_is_locked(&devices_list_mutex));
     354
    362355        namespace->refcnt--;
    363356        devmap_namespace_destroy(namespace);
    364357}
    365358
    366 /** Unregister device and free it
    367  *
    368  * The devices_list_mutex should be already held when
    369  * calling this function.
    370  *
    371  */
     359/** Unregister device and free it. */
    372360static void devmap_device_unregister_core(devmap_device_t *device)
    373361{
     362        assert(fibril_mutex_is_locked(&devices_list_mutex));
     363
    374364        devmap_namespace_delref(device->namespace);
    375365        list_remove(&(device->devices));
     
    390380       
    391381        if (IPC_GET_IMETHOD(icall) != DEVMAP_DRIVER_REGISTER) {
    392                 ipc_answer_0(iid, EREFUSED);
     382                async_answer_0(iid, EREFUSED);
    393383                return NULL;
    394384        }
     
    397387            (devmap_driver_t *) malloc(sizeof(devmap_driver_t));
    398388        if (driver == NULL) {
    399                 ipc_answer_0(iid, ENOMEM);
     389                async_answer_0(iid, ENOMEM);
    400390                return NULL;
    401391        }
     
    408398        if (rc != EOK) {
    409399                free(driver);
    410                 ipc_answer_0(iid, rc);
     400                async_answer_0(iid, rc);
    411401                return NULL;
    412402        }
     
    421411                free(driver->name);
    422412                free(driver);
    423                 ipc_answer_0(callid, ENOTSUP);
    424                 ipc_answer_0(iid, ENOTSUP);
     413                async_answer_0(callid, ENOTSUP);
     414                async_answer_0(iid, ENOTSUP);
    425415                return NULL;
    426416        }
    427417       
    428418        driver->phone = IPC_GET_ARG5(call);
    429         ipc_answer_0(callid, EOK);
     419        async_answer_0(callid, EOK);
    430420       
    431421        /*
     
    439429         */
    440430        list_initialize(&driver->devices);
    441         list_initialize(&(driver->drivers));
     431
     432        link_initialize(&driver->drivers);
    442433       
    443434        fibril_mutex_lock(&drivers_list_mutex);
     
    454445        fibril_mutex_unlock(&drivers_list_mutex);
    455446       
    456         ipc_answer_0(iid, EOK);
     447        async_answer_0(iid, EOK);
    457448       
    458449        return driver;
     
    472463       
    473464        if (driver->phone != 0)
    474                 ipc_hangup(driver->phone);
     465                async_hangup(driver->phone);
    475466       
    476467        /* Remove it from list of drivers */
     
    507498{
    508499        if (driver == NULL) {
    509                 ipc_answer_0(iid, EREFUSED);
     500                async_answer_0(iid, EREFUSED);
    510501                return;
    511502        }
     
    515506            (devmap_device_t *) malloc(sizeof(devmap_device_t));
    516507        if (device == NULL) {
    517                 ipc_answer_0(iid, ENOMEM);
     508                async_answer_0(iid, ENOMEM);
    518509                return;
    519510        }
     
    528519        if (rc != EOK) {
    529520                free(device);
    530                 ipc_answer_0(iid, rc);
     521                async_answer_0(iid, rc);
    531522                return;
    532523        }
     
    536527                free(fqdn);
    537528                free(device);
    538                 ipc_answer_0(iid, EINVAL);
     529                async_answer_0(iid, EINVAL);
    539530                return;
    540531        }
     
    550541                free(device->name);
    551542                free(device);
    552                 ipc_answer_0(iid, ENOMEM);
    553                 return;
    554         }
    555        
    556         list_initialize(&(device->devices));
    557         list_initialize(&(device->driver_devices));
     543                async_answer_0(iid, ENOMEM);
     544                return;
     545        }
     546       
     547        link_initialize(&device->devices);
     548        link_initialize(&device->driver_devices);
    558549       
    559550        /* Check that device is not already registered */
     
    565556                free(device->name);
    566557                free(device);
    567                 ipc_answer_0(iid, EEXISTS);
     558                async_answer_0(iid, EEXISTS);
    568559                return;
    569560        }
     
    587578        fibril_mutex_unlock(&devices_list_mutex);
    588579       
    589         ipc_answer_1(iid, EOK, device->handle);
     580        async_answer_1(iid, EOK, device->handle);
    590581}
    591582
     
    618609        if ((dev == NULL) || (dev->driver == NULL) || (dev->driver->phone == 0)) {
    619610                fibril_mutex_unlock(&devices_list_mutex);
    620                 ipc_answer_0(callid, ENOENT);
     611                async_answer_0(callid, ENOENT);
    621612                return;
    622613        }
    623614       
    624615        if (dev->forward_interface == 0) {
    625                 /* The IPC_GET_ARG3(*icall) would be always zero,
    626                  * wouldn't it? So why to pass it at all?
    627                  */
    628                 ipc_forward_fast(callid, dev->driver->phone,
     616                async_forward_fast(callid, dev->driver->phone,
    629617                    dev->handle, 0, 0,
    630618                    IPC_FF_NONE);
    631619        } else {
    632                 ipc_forward_fast(callid, dev->driver->phone,
     620                async_forward_fast(callid, dev->driver->phone,
    633621                    dev->forward_interface, dev->handle, 0,
    634622                    IPC_FF_NONE);
     
    652640            DEVMAP_NAME_MAXLEN, 0, NULL);
    653641        if (rc != EOK) {
    654                 ipc_answer_0(iid, rc);
     642                async_answer_0(iid, rc);
    655643                return;
    656644        }
     
    660648        if (!devmap_fqdn_split(fqdn, &ns_name, &name)) {
    661649                free(fqdn);
    662                 ipc_answer_0(iid, EINVAL);
     650                async_answer_0(iid, EINVAL);
    663651                return;
    664652        }
     
    687675                }
    688676               
    689                 ipc_answer_0(iid, ENOENT);
     677                async_answer_0(iid, ENOENT);
    690678                free(ns_name);
    691679                free(name);
     
    694682        }
    695683       
    696         ipc_answer_1(iid, EOK, dev->handle);
     684        async_answer_1(iid, EOK, dev->handle);
    697685       
    698686        fibril_mutex_unlock(&devices_list_mutex);
     
    715703            DEVMAP_NAME_MAXLEN, 0, NULL);
    716704        if (rc != EOK) {
    717                 ipc_answer_0(iid, rc);
     705                async_answer_0(iid, rc);
    718706                return;
    719707        }
     
    740728                }
    741729               
    742                 ipc_answer_0(iid, ENOENT);
     730                async_answer_0(iid, ENOENT);
    743731                free(name);
    744732                fibril_mutex_unlock(&devices_list_mutex);
     
    746734        }
    747735       
    748         ipc_answer_1(iid, EOK, namespace->handle);
     736        async_answer_1(iid, EOK, namespace->handle);
    749737       
    750738        fibril_mutex_unlock(&devices_list_mutex);
     
    762750                    devmap_device_find_handle(IPC_GET_ARG1(*icall));
    763751                if (dev == NULL)
    764                         ipc_answer_1(iid, EOK, DEV_HANDLE_NONE);
     752                        async_answer_1(iid, EOK, DEV_HANDLE_NONE);
    765753                else
    766                         ipc_answer_1(iid, EOK, DEV_HANDLE_DEVICE);
     754                        async_answer_1(iid, EOK, DEV_HANDLE_DEVICE);
    767755        } else
    768                 ipc_answer_1(iid, EOK, DEV_HANDLE_NAMESPACE);
     756                async_answer_1(iid, EOK, DEV_HANDLE_NAMESPACE);
    769757       
    770758        fibril_mutex_unlock(&devices_list_mutex);
     
    774762{
    775763        fibril_mutex_lock(&devices_list_mutex);
    776         ipc_answer_1(iid, EOK, list_count(&namespaces_list));
     764        async_answer_1(iid, EOK, list_count(&namespaces_list));
    777765        fibril_mutex_unlock(&devices_list_mutex);
    778766}
     
    785773            devmap_namespace_find_handle(IPC_GET_ARG1(*icall));
    786774        if (namespace == NULL)
    787                 ipc_answer_0(iid, EEXISTS);
     775                async_answer_0(iid, EEXISTS);
    788776        else
    789                 ipc_answer_1(iid, EOK, namespace->refcnt);
     777                async_answer_1(iid, EOK, namespace->refcnt);
    790778       
    791779        fibril_mutex_unlock(&devices_list_mutex);
     
    797785        size_t size;
    798786        if (!async_data_read_receive(&callid, &size)) {
    799                 ipc_answer_0(callid, EREFUSED);
    800                 ipc_answer_0(iid, EREFUSED);
     787                async_answer_0(callid, EREFUSED);
     788                async_answer_0(iid, EREFUSED);
    801789                return;
    802790        }
    803791       
    804792        if ((size % sizeof(dev_desc_t)) != 0) {
    805                 ipc_answer_0(callid, EINVAL);
    806                 ipc_answer_0(iid, EINVAL);
     793                async_answer_0(callid, EINVAL);
     794                async_answer_0(iid, EINVAL);
    807795                return;
    808796        }
     
    813801        if (count != list_count(&namespaces_list)) {
    814802                fibril_mutex_unlock(&devices_list_mutex);
    815                 ipc_answer_0(callid, EOVERFLOW);
    816                 ipc_answer_0(iid, EOVERFLOW);
     803                async_answer_0(callid, EOVERFLOW);
     804                async_answer_0(iid, EOVERFLOW);
    817805                return;
    818806        }
     
    821809        if (desc == NULL) {
    822810                fibril_mutex_unlock(&devices_list_mutex);
    823                 ipc_answer_0(callid, ENOMEM);
    824                 ipc_answer_0(iid, ENOMEM);
     811                async_answer_0(callid, ENOMEM);
     812                async_answer_0(iid, ENOMEM);
    825813                return;
    826814        }
     
    843831        fibril_mutex_unlock(&devices_list_mutex);
    844832       
    845         ipc_answer_0(iid, retval);
     833        async_answer_0(iid, retval);
    846834}
    847835
     
    854842        size_t size;
    855843        if (!async_data_read_receive(&callid, &size)) {
    856                 ipc_answer_0(callid, EREFUSED);
    857                 ipc_answer_0(iid, EREFUSED);
     844                async_answer_0(callid, EREFUSED);
     845                async_answer_0(iid, EREFUSED);
    858846                return;
    859847        }
    860848       
    861849        if ((size % sizeof(dev_desc_t)) != 0) {
    862                 ipc_answer_0(callid, EINVAL);
    863                 ipc_answer_0(iid, EINVAL);
     850                async_answer_0(callid, EINVAL);
     851                async_answer_0(iid, EINVAL);
    864852                return;
    865853        }
     
    871859        if (namespace == NULL) {
    872860                fibril_mutex_unlock(&devices_list_mutex);
    873                 ipc_answer_0(callid, ENOENT);
    874                 ipc_answer_0(iid, ENOENT);
     861                async_answer_0(callid, ENOENT);
     862                async_answer_0(iid, ENOENT);
    875863                return;
    876864        }
     
    879867        if (count != namespace->refcnt) {
    880868                fibril_mutex_unlock(&devices_list_mutex);
    881                 ipc_answer_0(callid, EOVERFLOW);
    882                 ipc_answer_0(iid, EOVERFLOW);
     869                async_answer_0(callid, EOVERFLOW);
     870                async_answer_0(iid, EOVERFLOW);
    883871                return;
    884872        }
     
    887875        if (desc == NULL) {
    888876                fibril_mutex_unlock(&devices_list_mutex);
    889                 ipc_answer_0(callid, ENOMEM);
    890                 ipc_answer_0(iid, EREFUSED);
     877                async_answer_0(callid, ENOMEM);
     878                async_answer_0(iid, EREFUSED);
    891879                return;
    892880        }
     
    910898        fibril_mutex_unlock(&devices_list_mutex);
    911899       
    912         ipc_answer_0(iid, retval);
     900        async_answer_0(iid, retval);
    913901}
    914902
     
    929917        if (!fnd) {
    930918                fibril_mutex_unlock(&null_devices_mutex);
    931                 ipc_answer_0(iid, ENOMEM);
     919                async_answer_0(iid, ENOMEM);
    932920                return;
    933921        }
     
    939927        if (dev_name == NULL) {
    940928                fibril_mutex_unlock(&null_devices_mutex);
    941                 ipc_answer_0(iid, ENOMEM);
     929                async_answer_0(iid, ENOMEM);
    942930                return;
    943931        }
     
    947935        if (device == NULL) {
    948936                fibril_mutex_unlock(&null_devices_mutex);
    949                 ipc_answer_0(iid, ENOMEM);
     937                async_answer_0(iid, ENOMEM);
    950938                return;
    951939        }
     
    957945                fibril_mutex_lock(&devices_list_mutex);
    958946                fibril_mutex_unlock(&null_devices_mutex);
    959                 ipc_answer_0(iid, ENOMEM);
    960                 return;
    961         }
    962        
    963         list_initialize(&(device->devices));
    964         list_initialize(&(device->driver_devices));
     947                async_answer_0(iid, ENOMEM);
     948                return;
     949        }
     950       
     951        link_initialize(&device->devices);
     952        link_initialize(&device->driver_devices);
    965953       
    966954        /* Get unique device handle */
     
    971959        device->name = dev_name;
    972960       
    973         /* Insert device into list of all devices
    974            and into null devices array */
     961        /*
     962         * Insert device into list of all devices and into null devices array.
     963         * Insert device into a dummy list of null driver's devices so that it
     964         * can be safely removed later.
     965         */
    975966        list_append(&device->devices, &devices_list);
     967        list_append(&device->driver_devices, &dummy_null_driver_devices);
    976968        null_devices[i] = device;
    977969       
     
    979971        fibril_mutex_unlock(&null_devices_mutex);
    980972       
    981         ipc_answer_1(iid, EOK, (sysarg_t) i);
     973        async_answer_1(iid, EOK, (sysarg_t) i);
    982974}
    983975
     
    986978        sysarg_t i = IPC_GET_ARG1(*icall);
    987979        if (i >= NULL_DEVICES) {
    988                 ipc_answer_0(iid, ELIMIT);
     980                async_answer_0(iid, ELIMIT);
    989981                return;
    990982        }
     
    994986        if (null_devices[i] == NULL) {
    995987                fibril_mutex_unlock(&null_devices_mutex);
    996                 ipc_answer_0(iid, ENOENT);
     988                async_answer_0(iid, ENOENT);
    997989                return;
    998990        }
     
    1005997       
    1006998        fibril_mutex_unlock(&null_devices_mutex);
    1007         ipc_answer_0(iid, EOK);
     999        async_answer_0(iid, EOK);
    10081000}
    10091001
     
    10311023{
    10321024        /* Accept connection */
    1033         ipc_answer_0(iid, EOK);
     1025        async_answer_0(iid, EOK);
    10341026       
    10351027        devmap_driver_t *driver = devmap_driver_register();
     
    10481040                case DEVMAP_DRIVER_UNREGISTER:
    10491041                        if (NULL == driver)
    1050                                 ipc_answer_0(callid, ENOENT);
     1042                                async_answer_0(callid, ENOENT);
    10511043                        else
    1052                                 ipc_answer_0(callid, EOK);
     1044                                async_answer_0(callid, EOK);
    10531045                        break;
    10541046                case DEVMAP_DEVICE_REGISTER:
     
    10671059                        break;
    10681060                default:
    1069                         ipc_answer_0(callid, ENOENT);
     1061                        async_answer_0(callid, ENOENT);
    10701062                }
    10711063        }
     
    10861078{
    10871079        /* Accept connection */
    1088         ipc_answer_0(iid, EOK);
     1080        async_answer_0(iid, EOK);
    10891081       
    10901082        bool cont = true;
     
    11251117                        break;
    11261118                default:
    1127                         ipc_answer_0(callid, ENOENT);
     1119                        async_answer_0(callid, ENOENT);
    11281120                }
    11291121        }
     
    11491141        default:
    11501142                /* No such interface */
    1151                 ipc_answer_0(iid, ENOENT);
     1143                async_answer_0(iid, ENOENT);
    11521144        }
    11531145}
     
    11691161       
    11701162        /* Register device mapper at naming service */
    1171         sysarg_t phonead;
    1172         if (ipc_connect_to_me(PHONE_NS, SERVICE_DEVMAP, 0, 0, &phonead) != 0)
     1163        if (service_register(SERVICE_DEVMAP) != EOK)
    11731164                return -1;
    11741165       
Note: See TracChangeset for help on using the changeset viewer.