Changes in uspace/srv/fs/devfs/devfs_ops.c [7ea7db31:991f645] in mainline
- File:
-
- 1 edited
-
uspace/srv/fs/devfs/devfs_ops.c (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/devfs/devfs_ops.c
r7ea7db31 r991f645 60 60 typedef struct { 61 61 devmap_handle_t handle; 62 int phone; /**< When < 0, the structure is incomplete. */62 int phone; 63 63 size_t refcount; 64 64 link_t link; 65 fibril_condvar_t cv; /**< Broadcast when completed. */66 65 } device_t; 67 66 … … 228 227 [DEVICES_KEY_HANDLE] = (unsigned long) node->handle 229 228 }; 230 link_t *lnk; 231 229 232 230 fibril_mutex_lock(&devices_mutex); 233 restart: 234 lnk = hash_table_find(&devices, key); 231 link_t *lnk = hash_table_find(&devices, key); 235 232 if (lnk == NULL) { 236 233 device_t *dev = (device_t *) malloc(sizeof(device_t)); … … 240 237 } 241 238 242 dev->handle = node->handle;243 dev->phone = -1; /* mark as incomplete */244 dev->refcount = 1;245 fibril_condvar_initialize(&dev->cv);246 247 /*248 * Insert the incomplete device structure so that other249 * fibrils will not race with us when we drop the mutex250 * below.251 */252 hash_table_insert(&devices, key, &dev->link);253 254 /*255 * Drop the mutex to allow recursive devfs requests.256 */257 fibril_mutex_unlock(&devices_mutex);258 259 239 int phone = devmap_device_connect(node->handle, 0); 260 261 fibril_mutex_lock(&devices_mutex);262 263 /*264 * Notify possible waiters about this device structure265 * being completed (or destroyed).266 */267 fibril_condvar_broadcast(&dev->cv);268 269 240 if (phone < 0) { 270 /*271 * Connecting failed, need to remove the272 * entry and free the device structure.273 */274 hash_table_remove(&devices, key, DEVICES_KEYS);275 241 fibril_mutex_unlock(&devices_mutex); 276 277 242 free(dev); 278 243 return ENOENT; 279 244 } 280 245 281 /* Set the correct phone. */246 dev->handle = node->handle; 282 247 dev->phone = phone; 248 dev->refcount = 1; 249 250 hash_table_insert(&devices, key, &dev->link); 283 251 } else { 284 252 device_t *dev = hash_table_get_instance(lnk, device_t, link); 285 286 if (dev->phone < 0) {287 /*288 * Wait until the device structure is completed289 * and start from the beginning as the device290 * structure might have entirely disappeared291 * while we were not holding the mutex in292 * fibril_condvar_wait().293 */294 fibril_condvar_wait(&dev->cv, &devices_mutex);295 goto restart;296 }297 298 253 dev->refcount++; 299 254 } … … 454 409 return false; 455 410 411 if (devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING) < 0) 412 return false; 413 456 414 return true; 457 415 } … … 462 420 463 421 /* Accept the mount options */ 464 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, 465 423 0, NULL); 466 424 if (retval != EOK) { … … 606 564 607 565 device_t *dev = hash_table_get_instance(lnk, device_t, link); 608 assert(dev->phone >= 0);609 566 610 567 ipc_callid_t callid; … … 618 575 /* Make a request at the driver */ 619 576 ipc_call_t answer; 620 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), 621 578 IPC_GET_ARG1(*request), IPC_GET_ARG2(*request), 622 579 IPC_GET_ARG3(*request), &answer); … … 627 584 628 585 /* Wait for reply from the driver. */ 629 sysarg_t rc;586 ipcarg_t rc; 630 587 async_wait_for(msg, &rc); 631 588 size_t bytes = IPC_GET_ARG1(answer); … … 670 627 671 628 device_t *dev = hash_table_get_instance(lnk, device_t, link); 672 assert(dev->phone >= 0);673 629 674 630 ipc_callid_t callid; … … 682 638 /* Make a request at the driver */ 683 639 ipc_call_t answer; 684 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), 685 641 IPC_GET_ARG1(*request), IPC_GET_ARG2(*request), 686 642 IPC_GET_ARG3(*request), &answer); … … 692 648 693 649 /* Wait for reply from the driver. */ 694 sysarg_t rc;650 ipcarg_t rc; 695 651 async_wait_for(msg, &rc); 696 652 size_t bytes = IPC_GET_ARG1(answer); … … 740 696 741 697 device_t *dev = hash_table_get_instance(lnk, device_t, link); 742 assert(dev->phone >= 0);743 698 dev->refcount--; 744 699 … … 788 743 789 744 device_t *dev = hash_table_get_instance(lnk, device_t, link); 790 assert(dev->phone >= 0);791 745 792 746 /* Make a request at the driver */ 793 747 ipc_call_t answer; 794 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), 795 749 IPC_GET_ARG1(*request), IPC_GET_ARG2(*request), &answer); 796 750 … … 798 752 799 753 /* Wait for reply from the driver */ 800 sysarg_t rc;754 ipcarg_t rc; 801 755 async_wait_for(msg, &rc); 802 756
Note:
See TracChangeset
for help on using the changeset viewer.
