Changeset ad7a6c9 in mainline for uspace/srv/devmap/devmap.c
- Timestamp:
- 2011-03-30T13:10:24Z (15 years ago)
- 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. - File:
-
- 1 edited
-
uspace/srv/devmap/devmap.c (modified) (61 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devmap/devmap.c
r6e50466 rad7a6c9 46 46 #include <str.h> 47 47 #include <ipc/devmap.h> 48 #include <assert.h> 48 49 49 50 #define NAME "devmap" … … 122 123 static devmap_handle_t last_handle = 0; 123 124 static 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 */ 130 static LIST_INITIALIZE(dummy_null_driver_devices); 124 131 125 132 static devmap_handle_t devmap_create_handle(void) … … 208 215 } 209 216 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. */ 216 218 static devmap_namespace_t *devmap_namespace_find_name(const char *name) 217 219 { 218 220 link_t *item; 221 222 assert(fibril_mutex_is_locked(&devices_list_mutex)); 223 219 224 for (item = namespaces_list.next; item != &namespaces_list; item = item->next) { 220 225 devmap_namespace_t *namespace = … … 229 234 /** Find namespace with given handle. 230 235 * 231 * The devices_list_mutex should be already held when232 * calling this function.233 *234 236 * @todo: use hash table 235 237 * … … 238 240 { 239 241 link_t *item; 242 243 assert(fibril_mutex_is_locked(&devices_list_mutex)); 244 240 245 for (item = namespaces_list.next; item != &namespaces_list; item = item->next) { 241 246 devmap_namespace_t *namespace = … … 248 253 } 249 254 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. */ 256 256 static devmap_device_t *devmap_device_find_name(const char *ns_name, 257 257 const char *name) 258 258 { 259 259 link_t *item; 260 261 assert(fibril_mutex_is_locked(&devices_list_mutex)); 262 260 263 for (item = devices_list.next; item != &devices_list; item = item->next) { 261 264 devmap_device_t *device = … … 271 274 /** Find device with given handle. 272 275 * 273 * The devices_list_mutex should be already held when274 * calling this function.275 *276 276 * @todo: use hash table 277 277 * … … 280 280 { 281 281 link_t *item; 282 283 assert(fibril_mutex_is_locked(&devices_list_mutex)); 284 282 285 for (item = devices_list.next; item != &devices_list; item = item->next) { 283 286 devmap_device_t *device = … … 290 293 } 291 294 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). */ 298 296 static devmap_namespace_t *devmap_namespace_create(const char *ns_name) 299 297 { 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); 301 303 if (namespace != NULL) 302 304 return namespace; … … 323 325 } 324 326 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). */ 331 328 static void devmap_namespace_destroy(devmap_namespace_t *namespace) 332 329 { 330 assert(fibril_mutex_is_locked(&devices_list_mutex)); 331 333 332 if (namespace->refcnt == 0) { 334 333 list_remove(&(namespace->namespaces)); … … 339 338 } 340 339 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. */ 347 341 static void devmap_namespace_addref(devmap_namespace_t *namespace, 348 342 devmap_device_t *device) 349 343 { 344 assert(fibril_mutex_is_locked(&devices_list_mutex)); 345 350 346 device->namespace = namespace; 351 347 namespace->refcnt++; 352 348 } 353 349 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. */ 360 351 static void devmap_namespace_delref(devmap_namespace_t *namespace) 361 352 { 353 assert(fibril_mutex_is_locked(&devices_list_mutex)); 354 362 355 namespace->refcnt--; 363 356 devmap_namespace_destroy(namespace); 364 357 } 365 358 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. */ 372 360 static void devmap_device_unregister_core(devmap_device_t *device) 373 361 { 362 assert(fibril_mutex_is_locked(&devices_list_mutex)); 363 374 364 devmap_namespace_delref(device->namespace); 375 365 list_remove(&(device->devices)); … … 390 380 391 381 if (IPC_GET_IMETHOD(icall) != DEVMAP_DRIVER_REGISTER) { 392 ipc_answer_0(iid, EREFUSED);382 async_answer_0(iid, EREFUSED); 393 383 return NULL; 394 384 } … … 397 387 (devmap_driver_t *) malloc(sizeof(devmap_driver_t)); 398 388 if (driver == NULL) { 399 ipc_answer_0(iid, ENOMEM);389 async_answer_0(iid, ENOMEM); 400 390 return NULL; 401 391 } … … 408 398 if (rc != EOK) { 409 399 free(driver); 410 ipc_answer_0(iid, rc);400 async_answer_0(iid, rc); 411 401 return NULL; 412 402 } … … 421 411 free(driver->name); 422 412 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); 425 415 return NULL; 426 416 } 427 417 428 418 driver->phone = IPC_GET_ARG5(call); 429 ipc_answer_0(callid, EOK);419 async_answer_0(callid, EOK); 430 420 431 421 /* … … 439 429 */ 440 430 list_initialize(&driver->devices); 441 list_initialize(&(driver->drivers)); 431 432 link_initialize(&driver->drivers); 442 433 443 434 fibril_mutex_lock(&drivers_list_mutex); … … 454 445 fibril_mutex_unlock(&drivers_list_mutex); 455 446 456 ipc_answer_0(iid, EOK);447 async_answer_0(iid, EOK); 457 448 458 449 return driver; … … 472 463 473 464 if (driver->phone != 0) 474 ipc_hangup(driver->phone);465 async_hangup(driver->phone); 475 466 476 467 /* Remove it from list of drivers */ … … 507 498 { 508 499 if (driver == NULL) { 509 ipc_answer_0(iid, EREFUSED);500 async_answer_0(iid, EREFUSED); 510 501 return; 511 502 } … … 515 506 (devmap_device_t *) malloc(sizeof(devmap_device_t)); 516 507 if (device == NULL) { 517 ipc_answer_0(iid, ENOMEM);508 async_answer_0(iid, ENOMEM); 518 509 return; 519 510 } … … 528 519 if (rc != EOK) { 529 520 free(device); 530 ipc_answer_0(iid, rc);521 async_answer_0(iid, rc); 531 522 return; 532 523 } … … 536 527 free(fqdn); 537 528 free(device); 538 ipc_answer_0(iid, EINVAL);529 async_answer_0(iid, EINVAL); 539 530 return; 540 531 } … … 550 541 free(device->name); 551 542 free(device); 552 ipc_answer_0(iid, ENOMEM);553 return; 554 } 555 556 li st_initialize(&(device->devices));557 li st_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); 558 549 559 550 /* Check that device is not already registered */ … … 565 556 free(device->name); 566 557 free(device); 567 ipc_answer_0(iid, EEXISTS);558 async_answer_0(iid, EEXISTS); 568 559 return; 569 560 } … … 587 578 fibril_mutex_unlock(&devices_list_mutex); 588 579 589 ipc_answer_1(iid, EOK, device->handle);580 async_answer_1(iid, EOK, device->handle); 590 581 } 591 582 … … 618 609 if ((dev == NULL) || (dev->driver == NULL) || (dev->driver->phone == 0)) { 619 610 fibril_mutex_unlock(&devices_list_mutex); 620 ipc_answer_0(callid, ENOENT);611 async_answer_0(callid, ENOENT); 621 612 return; 622 613 } 623 614 624 615 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, 629 617 dev->handle, 0, 0, 630 618 IPC_FF_NONE); 631 619 } else { 632 ipc_forward_fast(callid, dev->driver->phone,620 async_forward_fast(callid, dev->driver->phone, 633 621 dev->forward_interface, dev->handle, 0, 634 622 IPC_FF_NONE); … … 652 640 DEVMAP_NAME_MAXLEN, 0, NULL); 653 641 if (rc != EOK) { 654 ipc_answer_0(iid, rc);642 async_answer_0(iid, rc); 655 643 return; 656 644 } … … 660 648 if (!devmap_fqdn_split(fqdn, &ns_name, &name)) { 661 649 free(fqdn); 662 ipc_answer_0(iid, EINVAL);650 async_answer_0(iid, EINVAL); 663 651 return; 664 652 } … … 687 675 } 688 676 689 ipc_answer_0(iid, ENOENT);677 async_answer_0(iid, ENOENT); 690 678 free(ns_name); 691 679 free(name); … … 694 682 } 695 683 696 ipc_answer_1(iid, EOK, dev->handle);684 async_answer_1(iid, EOK, dev->handle); 697 685 698 686 fibril_mutex_unlock(&devices_list_mutex); … … 715 703 DEVMAP_NAME_MAXLEN, 0, NULL); 716 704 if (rc != EOK) { 717 ipc_answer_0(iid, rc);705 async_answer_0(iid, rc); 718 706 return; 719 707 } … … 740 728 } 741 729 742 ipc_answer_0(iid, ENOENT);730 async_answer_0(iid, ENOENT); 743 731 free(name); 744 732 fibril_mutex_unlock(&devices_list_mutex); … … 746 734 } 747 735 748 ipc_answer_1(iid, EOK, namespace->handle);736 async_answer_1(iid, EOK, namespace->handle); 749 737 750 738 fibril_mutex_unlock(&devices_list_mutex); … … 762 750 devmap_device_find_handle(IPC_GET_ARG1(*icall)); 763 751 if (dev == NULL) 764 ipc_answer_1(iid, EOK, DEV_HANDLE_NONE);752 async_answer_1(iid, EOK, DEV_HANDLE_NONE); 765 753 else 766 ipc_answer_1(iid, EOK, DEV_HANDLE_DEVICE);754 async_answer_1(iid, EOK, DEV_HANDLE_DEVICE); 767 755 } else 768 ipc_answer_1(iid, EOK, DEV_HANDLE_NAMESPACE);756 async_answer_1(iid, EOK, DEV_HANDLE_NAMESPACE); 769 757 770 758 fibril_mutex_unlock(&devices_list_mutex); … … 774 762 { 775 763 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)); 777 765 fibril_mutex_unlock(&devices_list_mutex); 778 766 } … … 785 773 devmap_namespace_find_handle(IPC_GET_ARG1(*icall)); 786 774 if (namespace == NULL) 787 ipc_answer_0(iid, EEXISTS);775 async_answer_0(iid, EEXISTS); 788 776 else 789 ipc_answer_1(iid, EOK, namespace->refcnt);777 async_answer_1(iid, EOK, namespace->refcnt); 790 778 791 779 fibril_mutex_unlock(&devices_list_mutex); … … 797 785 size_t size; 798 786 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); 801 789 return; 802 790 } 803 791 804 792 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); 807 795 return; 808 796 } … … 813 801 if (count != list_count(&namespaces_list)) { 814 802 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); 817 805 return; 818 806 } … … 821 809 if (desc == NULL) { 822 810 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); 825 813 return; 826 814 } … … 843 831 fibril_mutex_unlock(&devices_list_mutex); 844 832 845 ipc_answer_0(iid, retval);833 async_answer_0(iid, retval); 846 834 } 847 835 … … 854 842 size_t size; 855 843 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); 858 846 return; 859 847 } 860 848 861 849 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); 864 852 return; 865 853 } … … 871 859 if (namespace == NULL) { 872 860 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); 875 863 return; 876 864 } … … 879 867 if (count != namespace->refcnt) { 880 868 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); 883 871 return; 884 872 } … … 887 875 if (desc == NULL) { 888 876 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); 891 879 return; 892 880 } … … 910 898 fibril_mutex_unlock(&devices_list_mutex); 911 899 912 ipc_answer_0(iid, retval);900 async_answer_0(iid, retval); 913 901 } 914 902 … … 929 917 if (!fnd) { 930 918 fibril_mutex_unlock(&null_devices_mutex); 931 ipc_answer_0(iid, ENOMEM);919 async_answer_0(iid, ENOMEM); 932 920 return; 933 921 } … … 939 927 if (dev_name == NULL) { 940 928 fibril_mutex_unlock(&null_devices_mutex); 941 ipc_answer_0(iid, ENOMEM);929 async_answer_0(iid, ENOMEM); 942 930 return; 943 931 } … … 947 935 if (device == NULL) { 948 936 fibril_mutex_unlock(&null_devices_mutex); 949 ipc_answer_0(iid, ENOMEM);937 async_answer_0(iid, ENOMEM); 950 938 return; 951 939 } … … 957 945 fibril_mutex_lock(&devices_list_mutex); 958 946 fibril_mutex_unlock(&null_devices_mutex); 959 ipc_answer_0(iid, ENOMEM);960 return; 961 } 962 963 li st_initialize(&(device->devices));964 li st_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); 965 953 966 954 /* Get unique device handle */ … … 971 959 device->name = dev_name; 972 960 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 */ 975 966 list_append(&device->devices, &devices_list); 967 list_append(&device->driver_devices, &dummy_null_driver_devices); 976 968 null_devices[i] = device; 977 969 … … 979 971 fibril_mutex_unlock(&null_devices_mutex); 980 972 981 ipc_answer_1(iid, EOK, (sysarg_t) i);973 async_answer_1(iid, EOK, (sysarg_t) i); 982 974 } 983 975 … … 986 978 sysarg_t i = IPC_GET_ARG1(*icall); 987 979 if (i >= NULL_DEVICES) { 988 ipc_answer_0(iid, ELIMIT);980 async_answer_0(iid, ELIMIT); 989 981 return; 990 982 } … … 994 986 if (null_devices[i] == NULL) { 995 987 fibril_mutex_unlock(&null_devices_mutex); 996 ipc_answer_0(iid, ENOENT);988 async_answer_0(iid, ENOENT); 997 989 return; 998 990 } … … 1005 997 1006 998 fibril_mutex_unlock(&null_devices_mutex); 1007 ipc_answer_0(iid, EOK);999 async_answer_0(iid, EOK); 1008 1000 } 1009 1001 … … 1031 1023 { 1032 1024 /* Accept connection */ 1033 ipc_answer_0(iid, EOK);1025 async_answer_0(iid, EOK); 1034 1026 1035 1027 devmap_driver_t *driver = devmap_driver_register(); … … 1048 1040 case DEVMAP_DRIVER_UNREGISTER: 1049 1041 if (NULL == driver) 1050 ipc_answer_0(callid, ENOENT);1042 async_answer_0(callid, ENOENT); 1051 1043 else 1052 ipc_answer_0(callid, EOK);1044 async_answer_0(callid, EOK); 1053 1045 break; 1054 1046 case DEVMAP_DEVICE_REGISTER: … … 1067 1059 break; 1068 1060 default: 1069 ipc_answer_0(callid, ENOENT);1061 async_answer_0(callid, ENOENT); 1070 1062 } 1071 1063 } … … 1086 1078 { 1087 1079 /* Accept connection */ 1088 ipc_answer_0(iid, EOK);1080 async_answer_0(iid, EOK); 1089 1081 1090 1082 bool cont = true; … … 1125 1117 break; 1126 1118 default: 1127 ipc_answer_0(callid, ENOENT);1119 async_answer_0(callid, ENOENT); 1128 1120 } 1129 1121 } … … 1149 1141 default: 1150 1142 /* No such interface */ 1151 ipc_answer_0(iid, ENOENT);1143 async_answer_0(iid, ENOENT); 1152 1144 } 1153 1145 } … … 1169 1161 1170 1162 /* 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) 1173 1164 return -1; 1174 1165
Note:
See TracChangeset
for help on using the changeset viewer.
