Changes in uspace/srv/fs/devfs/devfs_ops.c [b366a1bc:991f645] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/devfs/devfs_ops.c
rb366a1bc r991f645 36 36 */ 37 37 38 #include <ipc/ipc.h> 38 39 #include <macros.h> 39 40 #include <bool.h> … … 59 60 typedef struct { 60 61 devmap_handle_t handle; 61 int phone; /**< When < 0, the structure is incomplete. */62 int phone; 62 63 size_t refcount; 63 64 link_t link; 64 fibril_condvar_t cv; /**< Broadcast when completed. */65 65 } device_t; 66 66 … … 130 130 { 131 131 devfs_node_t *node = (devfs_node_t *) pfn->data; 132 int ret;133 132 134 133 if (node->handle == 0) { … … 146 145 147 146 if (str_cmp(devs[pos].name, component) == 0) { 148 ret = devfs_node_get_internal(rfn, DEV_HANDLE_NAMESPACE, devs[pos].handle);149 147 free(devs); 150 return ret;148 return devfs_node_get_internal(rfn, DEV_HANDLE_NAMESPACE, devs[pos].handle); 151 149 } 152 150 } … … 164 162 for (pos = 0; pos < count; pos++) { 165 163 if (str_cmp(devs[pos].name, component) == 0) { 166 ret = devfs_node_get_internal(rfn, DEV_HANDLE_DEVICE, devs[pos].handle);167 164 free(devs); 168 return ret;165 return devfs_node_get_internal(rfn, DEV_HANDLE_DEVICE, devs[pos].handle); 169 166 } 170 167 } … … 187 184 for (pos = 0; pos < count; pos++) { 188 185 if (str_cmp(devs[pos].name, component) == 0) { 189 ret = devfs_node_get_internal(rfn, DEV_HANDLE_DEVICE, devs[pos].handle);190 186 free(devs); 191 return ret;187 return devfs_node_get_internal(rfn, DEV_HANDLE_DEVICE, devs[pos].handle); 192 188 } 193 189 } … … 231 227 [DEVICES_KEY_HANDLE] = (unsigned long) node->handle 232 228 }; 233 link_t *lnk; 234 229 235 230 fibril_mutex_lock(&devices_mutex); 236 restart: 237 lnk = hash_table_find(&devices, key); 231 link_t *lnk = hash_table_find(&devices, key); 238 232 if (lnk == NULL) { 239 233 device_t *dev = (device_t *) malloc(sizeof(device_t)); … … 243 237 } 244 238 245 dev->handle = node->handle;246 dev->phone = -1; /* mark as incomplete */247 dev->refcount = 1;248 fibril_condvar_initialize(&dev->cv);249 250 /*251 * Insert the incomplete device structure so that other252 * fibrils will not race with us when we drop the mutex253 * below.254 */255 hash_table_insert(&devices, key, &dev->link);256 257 /*258 * Drop the mutex to allow recursive devfs requests.259 */260 fibril_mutex_unlock(&devices_mutex);261 262 239 int phone = devmap_device_connect(node->handle, 0); 263 264 fibril_mutex_lock(&devices_mutex);265 266 /*267 * Notify possible waiters about this device structure268 * being completed (or destroyed).269 */270 fibril_condvar_broadcast(&dev->cv);271 272 240 if (phone < 0) { 273 /*274 * Connecting failed, need to remove the275 * entry and free the device structure.276 */277 hash_table_remove(&devices, key, DEVICES_KEYS);278 241 fibril_mutex_unlock(&devices_mutex); 279 280 242 free(dev); 281 243 return ENOENT; 282 244 } 283 245 284 /* Set the correct phone. */246 dev->handle = node->handle; 285 247 dev->phone = phone; 248 dev->refcount = 1; 249 250 hash_table_insert(&devices, key, &dev->link); 286 251 } else { 287 252 device_t *dev = hash_table_get_instance(lnk, device_t, link); 288 289 if (dev->phone < 0) {290 /*291 * Wait until the device structure is completed292 * and start from the beginning as the device293 * structure might have entirely disappeared294 * while we were not holding the mutex in295 * fibril_condvar_wait().296 */297 fibril_condvar_wait(&dev->cv, &devices_mutex);298 goto restart;299 }300 301 253 dev->refcount++; 302 254 } … … 457 409 return false; 458 410 411 if (devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING) < 0) 412 return false; 413 459 414 return true; 460 415 } … … 465 420 466 421 /* Accept the mount options */ 467 sysarg_t retval = async_data_write_accept((void **) &opts, true, 0, 0,422 ipcarg_t retval = async_data_write_accept((void **) &opts, true, 0, 0, 468 423 0, NULL); 469 424 if (retval != EOK) { 470 async_answer_0(rid, retval);425 ipc_answer_0(rid, retval); 471 426 return; 472 427 } 473 428 474 429 free(opts); 475 async_answer_3(rid, EOK, 0, 0, 0);430 ipc_answer_3(rid, EOK, 0, 0, 0); 476 431 } 477 432 … … 483 438 void devfs_unmounted(ipc_callid_t rid, ipc_call_t *request) 484 439 { 485 async_answer_0(rid, ENOTSUP);440 ipc_answer_0(rid, ENOTSUP); 486 441 } 487 442 … … 516 471 size_t size; 517 472 if (!async_data_read_receive(&callid, &size)) { 518 async_answer_0(callid, EINVAL);519 async_answer_0(rid, EINVAL);473 ipc_answer_0(callid, EINVAL); 474 ipc_answer_0(rid, EINVAL); 520 475 return; 521 476 } … … 538 493 async_data_read_finalize(callid, desc[pos].name, str_size(desc[pos].name) + 1); 539 494 free(desc); 540 async_answer_1(rid, EOK, 1);495 ipc_answer_1(rid, EOK, 1); 541 496 return; 542 497 } … … 553 508 async_data_read_finalize(callid, desc[pos].name, str_size(desc[pos].name) + 1); 554 509 free(desc); 555 async_answer_1(rid, EOK, 1);510 ipc_answer_1(rid, EOK, 1); 556 511 return; 557 512 } … … 560 515 } 561 516 562 async_answer_0(callid, ENOENT);563 async_answer_1(rid, ENOENT, 0);517 ipc_answer_0(callid, ENOENT); 518 ipc_answer_1(rid, ENOENT, 0); 564 519 return; 565 520 } … … 572 527 size_t size; 573 528 if (!async_data_read_receive(&callid, &size)) { 574 async_answer_0(callid, EINVAL);575 async_answer_0(rid, EINVAL);529 ipc_answer_0(callid, EINVAL); 530 ipc_answer_0(rid, EINVAL); 576 531 return; 577 532 } … … 583 538 async_data_read_finalize(callid, desc[pos].name, str_size(desc[pos].name) + 1); 584 539 free(desc); 585 async_answer_1(rid, EOK, 1);540 ipc_answer_1(rid, EOK, 1); 586 541 return; 587 542 } 588 543 589 544 free(desc); 590 async_answer_0(callid, ENOENT);591 async_answer_1(rid, ENOENT, 0);545 ipc_answer_0(callid, ENOENT); 546 ipc_answer_1(rid, ENOENT, 0); 592 547 return; 593 548 } … … 604 559 if (lnk == NULL) { 605 560 fibril_mutex_unlock(&devices_mutex); 606 async_answer_0(rid, ENOENT);561 ipc_answer_0(rid, ENOENT); 607 562 return; 608 563 } 609 564 610 565 device_t *dev = hash_table_get_instance(lnk, device_t, link); 611 assert(dev->phone >= 0);612 566 613 567 ipc_callid_t callid; 614 568 if (!async_data_read_receive(&callid, NULL)) { 615 569 fibril_mutex_unlock(&devices_mutex); 616 async_answer_0(callid, EINVAL);617 async_answer_0(rid, EINVAL);570 ipc_answer_0(callid, EINVAL); 571 ipc_answer_0(rid, EINVAL); 618 572 return; 619 573 } … … 621 575 /* Make a request at the driver */ 622 576 ipc_call_t answer; 623 aid_t msg = async_send_3(dev->phone, IPC_GET_ IMETHOD(*request),577 aid_t msg = async_send_3(dev->phone, IPC_GET_METHOD(*request), 624 578 IPC_GET_ARG1(*request), IPC_GET_ARG2(*request), 625 579 IPC_GET_ARG3(*request), &answer); 626 580 627 581 /* Forward the IPC_M_DATA_READ request to the driver */ 628 async_forward_fast(callid, dev->phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME);582 ipc_forward_fast(callid, dev->phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME); 629 583 fibril_mutex_unlock(&devices_mutex); 630 584 631 585 /* Wait for reply from the driver. */ 632 sysarg_t rc;586 ipcarg_t rc; 633 587 async_wait_for(msg, &rc); 634 588 size_t bytes = IPC_GET_ARG1(answer); 635 589 636 590 /* Driver reply is the final result of the whole operation */ 637 async_answer_1(rid, rc, bytes);638 return; 639 } 640 641 async_answer_0(rid, ENOENT);591 ipc_answer_1(rid, rc, bytes); 592 return; 593 } 594 595 ipc_answer_0(rid, ENOENT); 642 596 } 643 597 … … 646 600 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 647 601 if (index == 0) { 648 async_answer_0(rid, ENOTSUP);602 ipc_answer_0(rid, ENOTSUP); 649 603 return; 650 604 } … … 654 608 if (type == DEV_HANDLE_NAMESPACE) { 655 609 /* Namespace directory */ 656 async_answer_0(rid, ENOTSUP);610 ipc_answer_0(rid, ENOTSUP); 657 611 return; 658 612 } … … 668 622 if (lnk == NULL) { 669 623 fibril_mutex_unlock(&devices_mutex); 670 async_answer_0(rid, ENOENT);624 ipc_answer_0(rid, ENOENT); 671 625 return; 672 626 } 673 627 674 628 device_t *dev = hash_table_get_instance(lnk, device_t, link); 675 assert(dev->phone >= 0);676 629 677 630 ipc_callid_t callid; 678 631 if (!async_data_write_receive(&callid, NULL)) { 679 632 fibril_mutex_unlock(&devices_mutex); 680 async_answer_0(callid, EINVAL);681 async_answer_0(rid, EINVAL);633 ipc_answer_0(callid, EINVAL); 634 ipc_answer_0(rid, EINVAL); 682 635 return; 683 636 } … … 685 638 /* Make a request at the driver */ 686 639 ipc_call_t answer; 687 aid_t msg = async_send_3(dev->phone, IPC_GET_ IMETHOD(*request),640 aid_t msg = async_send_3(dev->phone, IPC_GET_METHOD(*request), 688 641 IPC_GET_ARG1(*request), IPC_GET_ARG2(*request), 689 642 IPC_GET_ARG3(*request), &answer); 690 643 691 644 /* Forward the IPC_M_DATA_WRITE request to the driver */ 692 async_forward_fast(callid, dev->phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME);645 ipc_forward_fast(callid, dev->phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME); 693 646 694 647 fibril_mutex_unlock(&devices_mutex); 695 648 696 649 /* Wait for reply from the driver. */ 697 sysarg_t rc;650 ipcarg_t rc; 698 651 async_wait_for(msg, &rc); 699 652 size_t bytes = IPC_GET_ARG1(answer); 700 653 701 654 /* Driver reply is the final result of the whole operation */ 702 async_answer_1(rid, rc, bytes);703 return; 704 } 705 706 async_answer_0(rid, ENOENT);655 ipc_answer_1(rid, rc, bytes); 656 return; 657 } 658 659 ipc_answer_0(rid, ENOENT); 707 660 } 708 661 709 662 void devfs_truncate(ipc_callid_t rid, ipc_call_t *request) 710 663 { 711 async_answer_0(rid, ENOTSUP);664 ipc_answer_0(rid, ENOTSUP); 712 665 } 713 666 … … 717 670 718 671 if (index == 0) { 719 async_answer_0(rid, EOK);672 ipc_answer_0(rid, EOK); 720 673 return; 721 674 } … … 725 678 if (type == DEV_HANDLE_NAMESPACE) { 726 679 /* Namespace directory */ 727 async_answer_0(rid, EOK);680 ipc_answer_0(rid, EOK); 728 681 return; 729 682 } … … 738 691 if (lnk == NULL) { 739 692 fibril_mutex_unlock(&devices_mutex); 740 async_answer_0(rid, ENOENT);693 ipc_answer_0(rid, ENOENT); 741 694 return; 742 695 } 743 696 744 697 device_t *dev = hash_table_get_instance(lnk, device_t, link); 745 assert(dev->phone >= 0);746 698 dev->refcount--; 747 699 748 700 if (dev->refcount == 0) { 749 async_hangup(dev->phone);701 ipc_hangup(dev->phone); 750 702 hash_table_remove(&devices, key, DEVICES_KEYS); 751 703 } … … 753 705 fibril_mutex_unlock(&devices_mutex); 754 706 755 async_answer_0(rid, EOK);756 return; 757 } 758 759 async_answer_0(rid, ENOENT);707 ipc_answer_0(rid, EOK); 708 return; 709 } 710 711 ipc_answer_0(rid, ENOENT); 760 712 } 761 713 … … 765 717 766 718 if (index == 0) { 767 async_answer_0(rid, EOK);719 ipc_answer_0(rid, EOK); 768 720 return; 769 721 } … … 773 725 if (type == DEV_HANDLE_NAMESPACE) { 774 726 /* Namespace directory */ 775 async_answer_0(rid, EOK);727 ipc_answer_0(rid, EOK); 776 728 return; 777 729 } … … 786 738 if (lnk == NULL) { 787 739 fibril_mutex_unlock(&devices_mutex); 788 async_answer_0(rid, ENOENT);740 ipc_answer_0(rid, ENOENT); 789 741 return; 790 742 } 791 743 792 744 device_t *dev = hash_table_get_instance(lnk, device_t, link); 793 assert(dev->phone >= 0);794 745 795 746 /* Make a request at the driver */ 796 747 ipc_call_t answer; 797 aid_t msg = async_send_2(dev->phone, IPC_GET_ IMETHOD(*request),748 aid_t msg = async_send_2(dev->phone, IPC_GET_METHOD(*request), 798 749 IPC_GET_ARG1(*request), IPC_GET_ARG2(*request), &answer); 799 750 … … 801 752 802 753 /* Wait for reply from the driver */ 803 sysarg_t rc;754 ipcarg_t rc; 804 755 async_wait_for(msg, &rc); 805 756 806 757 /* Driver reply is the final result of the whole operation */ 807 async_answer_0(rid, rc);808 return; 809 } 810 811 async_answer_0(rid, ENOENT);758 ipc_answer_0(rid, rc); 759 return; 760 } 761 762 ipc_answer_0(rid, ENOENT); 812 763 } 813 764 814 765 void devfs_destroy(ipc_callid_t rid, ipc_call_t *request) 815 766 { 816 async_answer_0(rid, ENOTSUP);767 ipc_answer_0(rid, ENOTSUP); 817 768 } 818 769
Note:
See TracChangeset
for help on using the changeset viewer.