Changeset 58cbb0c8 in mainline for uspace/srv/devman/main.c
- Timestamp:
- 2011-09-01T22:19:21Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- aff587f
- Parents:
- 5f6e25e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/main.c
r5f6e25e r58cbb0c8 242 242 243 243 fibril_rwlock_write_lock(&device_tree.rwlock); 244 244 245 245 if (fun->ftype == fun_inner) { 246 246 dev = create_dev_node(); 247 247 if (dev == NULL) { 248 248 fibril_rwlock_write_unlock(&device_tree.rwlock); 249 delete_fun_node(fun);250 249 return ENOMEM; 251 250 } 252 251 253 252 insert_dev_node(&device_tree, dev, fun); 254 } 255 256 fibril_rwlock_write_unlock(&device_tree.rwlock); 253 dev_add_ref(dev); 254 } 257 255 258 256 log_msg(LVL_DEBUG, "devman_add_function(fun=\"%s\")", fun->pathname); … … 283 281 } 284 282 283 fibril_rwlock_write_unlock(&device_tree.rwlock); 284 285 285 return EOK; 286 286 } … … 289 289 { 290 290 int rc; 291 292 fibril_rwlock_write_lock(&device_tree.rwlock); 291 293 292 294 if (fun->ftype == fun_inner) { … … 296 298 dev_node_t *dev = fun->child; 297 299 298 rc = driver_dev_remove(dev); 300 dev_add_ref(dev); 301 fibril_rwlock_write_unlock(&device_tree.rwlock); 302 303 rc = driver_dev_remove(&device_tree, dev); 299 304 if (rc != EOK) { 305 dev_del_ref(dev); 300 306 return ENOTSUP; 301 307 } 302 detach_driver(dev); 308 309 detach_driver(&device_tree, dev); 310 303 311 fibril_rwlock_write_lock(&device_tree.rwlock); 304 312 remove_dev_node(&device_tree, dev); 305 fibril_rwlock_write_unlock(&device_tree.rwlock); 306 delete_dev_node(dev); 313 314 /* Delete ref created when node was inserted */ 315 dev_del_ref(dev); 316 /* Delete ref created by dev_add_ref(dev) above */ 317 dev_del_ref(dev); 307 318 } 308 319 } else { … … 310 321 rc = loc_service_unregister(fun->service_id); 311 322 if (rc != EOK) { 323 fibril_rwlock_write_unlock(&device_tree.rwlock); 312 324 log_msg(LVL_ERROR, "Failed unregistering tree service."); 313 325 return EIO; … … 317 329 } 318 330 331 fibril_rwlock_write_unlock(&device_tree.rwlock); 332 319 333 return EOK; 320 334 } … … 331 345 dev_tree_t *tree = &device_tree; 332 346 333 fibril_rwlock_write_lock(&tree->rwlock); 334 335 dev_node_t *pdev = find_dev_node_no_lock(&device_tree, dev_handle); 336 347 dev_node_t *pdev = find_dev_node(&device_tree, dev_handle); 337 348 if (pdev == NULL) { 338 fibril_rwlock_write_unlock(&tree->rwlock);339 349 async_answer_0(callid, ENOENT); 340 350 return; … … 347 357 (int) ftype); 348 358 349 fibril_rwlock_write_unlock(&tree->rwlock);359 dev_del_ref(pdev); 350 360 async_answer_0(callid, EINVAL); 351 361 return; … … 355 365 int rc = async_data_write_accept((void **)&fun_name, true, 0, 0, 0, 0); 356 366 if (rc != EOK) { 367 dev_del_ref(pdev); 368 async_answer_0(callid, rc); 369 return; 370 } 371 372 fibril_rwlock_write_lock(&tree->rwlock); 373 374 /* Check that function with same name is not there already. */ 375 if (find_fun_node_in_device(tree, pdev, fun_name) != NULL) { 357 376 fibril_rwlock_write_unlock(&tree->rwlock); 358 async_answer_0(callid, rc); 359 return; 360 } 361 362 /* Check that function with same name is not there already. */ 363 if (find_fun_node_in_device(pdev, fun_name) != NULL) { 364 fibril_rwlock_write_unlock(&tree->rwlock); 377 dev_del_ref(pdev); 365 378 async_answer_0(callid, EEXISTS); 366 379 printf(NAME ": Warning, driver tried to register `%s' twice.\n", … … 371 384 372 385 fun_node_t *fun = create_fun_node(); 386 fun_add_ref(fun); 373 387 fun->ftype = ftype; 374 388 375 389 if (!insert_fun_node(&device_tree, fun, fun_name, pdev)) { 376 390 fibril_rwlock_write_unlock(&tree->rwlock); 391 dev_del_ref(pdev); 377 392 delete_fun_node(fun); 378 393 async_answer_0(callid, ENOMEM); … … 381 396 382 397 fibril_rwlock_write_unlock(&tree->rwlock); 398 dev_del_ref(pdev); 383 399 384 400 devman_receive_match_ids(match_count, &fun->match_ids); … … 408 424 async_answer_0(callid, rc); 409 425 return; 410 } 426 } 411 427 412 428 fun_node_t *fun = find_fun_node(&device_tree, handle); … … 415 431 return; 416 432 } 433 434 fibril_rwlock_read_lock(&device_tree.rwlock); 417 435 418 436 rc = loc_category_get_id(cat_name, &cat_id, IPC_FLAG_BLOCKING); … … 427 445 fun->pathname, cat_name); 428 446 447 fibril_rwlock_read_unlock(&device_tree.rwlock); 448 fun_del_ref(fun); 449 429 450 async_answer_0(callid, EOK); 430 451 } … … 440 461 441 462 printf("devman_drv_fun_online()\n"); 442 fibril_rwlock_write_lock(&device_tree.rwlock); 443 fun = find_fun_node_no_lock(&device_tree, IPC_GET_ARG1(*icall)); 444 fibril_rwlock_write_unlock(&device_tree.rwlock); /* XXX FIXME */ 445 446 if (fun == NULL || fun->dev == NULL || fun->dev->drv != drv) { 447 async_answer_0(iid, ENOENT); 448 return; 449 } 463 fun = find_fun_node(&device_tree, IPC_GET_ARG1(*icall)); 464 if (fun == NULL) { 465 async_answer_0(iid, ENOENT); 466 return; 467 } 468 469 fibril_rwlock_read_lock(&device_tree.rwlock); 470 if (fun->dev == NULL || fun->dev->drv != drv) { 471 fibril_rwlock_read_unlock(&device_tree.rwlock); 472 fun_del_ref(fun); 473 async_answer_0(iid, ENOENT); 474 return; 475 } 476 fibril_rwlock_read_unlock(&device_tree.rwlock); 450 477 451 478 rc = online_function(fun); 452 479 if (rc != EOK) { 453 480 printf("devman_drv_fun_online() online_fun->ERROR\n"); 481 fun_del_ref(fun); 454 482 async_answer_0(iid, (sysarg_t) rc); 455 483 return; 456 484 } 485 486 fun_del_ref(fun); 457 487 printf("devman_drv_fun_online() online_fun->OK\n"); 458 488 … … 470 500 int rc; 471 501 502 fun = find_fun_node(&device_tree, IPC_GET_ARG1(*icall)); 503 if (fun == NULL) { 504 async_answer_0(iid, ENOENT); 505 return; 506 } 507 472 508 fibril_rwlock_write_lock(&device_tree.rwlock); 473 fun = find_fun_node_no_lock(&device_tree, IPC_GET_ARG1(*icall)); 474 fibril_rwlock_write_unlock(&device_tree.rwlock); /* XXX FIXME */ 475 476 if (fun == NULL || fun->dev == NULL || fun->dev->drv != drv) { 477 async_answer_0(iid, ENOENT); 478 return; 479 } 509 if (fun->dev == NULL || fun->dev->drv != drv) { 510 fun_del_ref(fun); 511 async_answer_0(iid, ENOENT); 512 return; 513 } 514 fibril_rwlock_write_unlock(&device_tree.rwlock); 480 515 481 516 rc = offline_function(fun); 482 517 if (rc != EOK) { 518 fun_del_ref(fun); 483 519 async_answer_0(iid, (sysarg_t) rc); 484 520 return; 485 521 } 486 522 523 fun_del_ref(fun); 487 524 async_answer_0(iid, (sysarg_t) EOK); 488 525 } … … 495 532 int rc; 496 533 534 535 fun_node_t *fun = find_fun_node(&device_tree, fun_handle); 536 if (fun == NULL) { 537 async_answer_0(callid, ENOENT); 538 return; 539 } 540 497 541 fibril_rwlock_write_lock(&tree->rwlock); 498 499 fun_node_t *fun = find_fun_node_no_lock(&device_tree, fun_handle);500 if (fun == NULL) {501 fibril_rwlock_write_unlock(&tree->rwlock);502 async_answer_0(callid, ENOENT);503 return;504 }505 542 506 543 log_msg(LVL_DEBUG, "devman_remove_function(fun='%s')", fun->pathname); … … 508 545 if (fun->ftype == fun_inner) { 509 546 /* Handle possible descendants */ 510 /* TODO */547 /* TODO - This is a surprise removal */ 511 548 if (fun->child != NULL) { 512 549 log_msg(LVL_WARN, "devman_remove_function(): not handling " … … 521 558 "service."); 522 559 fibril_rwlock_write_unlock(&tree->rwlock); 560 fun_del_ref(fun); 523 561 async_answer_0(callid, EIO); 524 562 return; … … 529 567 remove_fun_node(&device_tree, fun); 530 568 fibril_rwlock_write_unlock(&tree->rwlock); 531 delete_fun_node(fun); 569 570 /* Delete ref added when inserting function into tree */ 571 fun_del_ref(fun); 572 /* Delete ref added above when looking up function */ 573 fun_del_ref(fun); 532 574 533 575 log_msg(LVL_DEBUG, "devman_remove_function() succeeded."); … … 621 663 { 622 664 char *pathname; 665 devman_handle_t handle; 623 666 624 667 int rc = async_data_write_accept((void **) &pathname, true, 0, 0, 0, 0); … … 637 680 } 638 681 639 async_answer_1(iid, EOK, fun->handle); 682 fibril_rwlock_read_lock(&device_tree.rwlock); 683 handle = fun->handle; 684 fibril_rwlock_read_unlock(&device_tree.rwlock); 685 686 /* Delete reference created above by find_fun_node_by_path() */ 687 fun_del_ref(fun); 688 689 async_answer_1(iid, EOK, handle); 640 690 } 641 691 … … 655 705 if (!async_data_read_receive(&data_callid, &data_len)) { 656 706 async_answer_0(iid, EINVAL); 707 fun_del_ref(fun); 657 708 return; 658 709 } … … 662 713 async_answer_0(data_callid, ENOMEM); 663 714 async_answer_0(iid, ENOMEM); 664 return; 665 } 715 fun_del_ref(fun); 716 return; 717 } 718 719 fibril_rwlock_read_lock(&device_tree.rwlock); 666 720 667 721 size_t sent_length = str_size(fun->name); … … 673 727 async_answer_0(iid, EOK); 674 728 729 fibril_rwlock_read_unlock(&device_tree.rwlock); 730 fun_del_ref(fun); 675 731 free(buffer); 676 732 } … … 692 748 if (!async_data_read_receive(&data_callid, &data_len)) { 693 749 async_answer_0(iid, EINVAL); 750 fun_del_ref(fun); 694 751 return; 695 752 } … … 699 756 async_answer_0(data_callid, ENOMEM); 700 757 async_answer_0(iid, ENOMEM); 701 return; 702 } 703 758 fun_del_ref(fun); 759 return; 760 } 761 762 fibril_rwlock_read_lock(&device_tree.rwlock); 763 704 764 size_t sent_length = str_size(fun->pathname); 705 765 if (sent_length > data_len) { … … 710 770 async_answer_0(iid, EOK); 711 771 772 fibril_rwlock_read_unlock(&device_tree.rwlock); 773 fun_del_ref(fun); 712 774 free(buffer); 713 775 } … … 777 839 778 840 if (fun->child == NULL) { 841 fun_del_ref(fun); 779 842 fibril_rwlock_read_unlock(&device_tree.rwlock); 780 843 async_answer_0(iid, ENOENT); … … 784 847 async_answer_1(iid, EOK, fun->child->handle); 785 848 849 fun_del_ref(fun); 786 850 fibril_rwlock_read_unlock(&device_tree.rwlock); 787 851 } … … 798 862 int rc; 799 863 800 fibril_rwlock_write_lock(&device_tree.rwlock); 801 fun = find_fun_node_no_lock(&device_tree, IPC_GET_ARG1(*icall)); 802 fibril_rwlock_write_unlock(&device_tree.rwlock); /* XXX FIXME */ 803 864 fun = find_fun_node(&device_tree, IPC_GET_ARG1(*icall)); 804 865 if (fun == NULL) { 805 866 async_answer_0(iid, ENOENT); … … 807 868 } 808 869 809 rc = driver_fun_online(fun); 870 rc = driver_fun_online(&device_tree, fun); 871 fun_del_ref(fun); 810 872 811 873 async_answer_0(iid, (sysarg_t) rc); … … 825 887 int rc; 826 888 827 fibril_rwlock_write_lock(&device_tree.rwlock); 828 fun = find_fun_node_no_lock(&device_tree, IPC_GET_ARG1(*icall)); 829 fibril_rwlock_write_unlock(&device_tree.rwlock); /* XXX FIXME */ 830 889 fun = find_fun_node(&device_tree, IPC_GET_ARG1(*icall)); 831 890 if (fun == NULL) { 832 891 async_answer_0(iid, ENOENT); … … 834 893 } 835 894 836 rc = driver_fun_offline(fun); 895 rc = driver_fun_offline(&device_tree, fun); 896 fun_del_ref(fun); 837 897 838 898 async_answer_0(iid, (sysarg_t) rc); … … 851 911 } 852 912 913 fibril_rwlock_read_lock(&device_tree.rwlock); 853 914 async_answer_1(iid, EOK, fun->handle); 915 fibril_rwlock_read_unlock(&device_tree.rwlock); 916 fun_del_ref(fun); 854 917 } 855 918 … … 909 972 if (fun == NULL) 910 973 dev = find_dev_node(&device_tree, handle); 911 else 974 else { 975 fibril_rwlock_read_lock(&device_tree.rwlock); 912 976 dev = fun->dev; 977 if (dev != NULL) 978 dev_add_ref(dev); 979 fibril_rwlock_read_unlock(&device_tree.rwlock); 980 } 913 981 914 982 /* … … 922 990 "function with handle %" PRIun " was found.", handle); 923 991 async_answer_0(iid, ENOENT); 924 return;992 goto cleanup; 925 993 } 926 994 … … 930 998 handle); 931 999 async_answer_0(iid, ENOENT); 932 return;1000 goto cleanup; 933 1001 } 934 1002 … … 952 1020 "the device %" PRIun " is not in usable state.", handle); 953 1021 async_answer_0(iid, ENOENT); 954 return;1022 goto cleanup; 955 1023 } 956 1024 … … 965 1033 "Could not forward to driver `%s'.", driver->name); 966 1034 async_answer_0(iid, EINVAL); 967 return;1035 goto cleanup; 968 1036 } 969 1037 … … 981 1049 async_forward_fast(iid, exch, method, fwd_h, 0, IPC_FF_NONE); 982 1050 async_exchange_end(exch); 1051 1052 cleanup: 1053 if (dev != NULL) 1054 dev_del_ref(dev); 1055 if (fun != NULL) 1056 fun_del_ref(fun); 983 1057 } 984 1058 … … 1000 1074 } 1001 1075 1076 fibril_rwlock_read_lock(&device_tree.rwlock); 1002 1077 dev = fun->dev; 1078 fun_del_ref(fun); 1003 1079 1004 1080 async_exch_t *exch = async_exchange_begin(dev->drv->sess); … … 1006 1082 IPC_FF_NONE); 1007 1083 async_exchange_end(exch); 1084 1085 fibril_rwlock_read_unlock(&device_tree.rwlock); 1008 1086 1009 1087 log_msg(LVL_DEBUG,
Note:
See TracChangeset
for help on using the changeset viewer.