Changeset b2d06fa in mainline for uspace/srv
- Timestamp:
- 2010-12-25T17:14:36Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 092e4f1
- Parents:
- 59e9398b (diff), 3ac66f69 (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. - Location:
- uspace/srv
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/devman.c
r59e9398b rb2d06fa 62 62 } 63 63 64 static int devmap_devices_class_compare(unsigned long key[], hash_count_t keys, 65 link_t *item) 66 { 67 dev_class_info_t *class_info 68 = hash_table_get_instance(item, dev_class_info_t, devmap_link); 69 assert(class_info != NULL); 70 71 return (class_info->devmap_handle == (devmap_handle_t) key[0]); 72 } 73 64 74 static void devices_remove_callback(link_t *item) 65 75 { … … 75 85 .hash = devices_hash, 76 86 .compare = devmap_devices_compare, 87 .remove_callback = devices_remove_callback 88 }; 89 90 static hash_table_operations_t devmap_devices_class_ops = { 91 .hash = devices_hash, 92 .compare = devmap_devices_class_compare, 77 93 .remove_callback = devices_remove_callback 78 94 }; … … 368 384 printf(NAME ": create_root_node\n"); 369 385 386 fibril_rwlock_write_lock(&tree->rwlock); 370 387 node = create_dev_node(); 371 388 if (node != NULL) { … … 377 394 tree->root_node = node; 378 395 } 396 fibril_rwlock_write_unlock(&tree->rwlock); 379 397 380 398 return node != NULL; … … 439 457 /** Start a driver 440 458 * 441 * The driver's mutex is assumed to be locked.442 *443 459 * @param drv The driver's structure. 444 460 * @return True if the driver's task is successfully spawned, false … … 449 465 int rc; 450 466 467 assert(fibril_mutex_is_locked(&drv->driver_mutex)); 468 451 469 printf(NAME ": start_driver '%s'\n", drv->name); 452 470 … … 670 688 } 671 689 672 devmap_device_register(devmap_pathname, &node->devmap_handle); 690 devmap_device_register_with_iface(devmap_pathname, 691 &node->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP); 673 692 674 693 tree_add_devmap_device(tree, node); … … 842 861 /** Find the device node structure of the device witch has the specified handle. 843 862 * 844 * Device tree's rwlock should be held at least for reading.845 *846 863 * @param tree The device tree where we look for the device node. 847 864 * @param handle The handle of the device. … … 851 868 { 852 869 unsigned long key = handle; 853 link_t *link = hash_table_find(&tree->devman_devices, &key); 870 link_t *link; 871 872 assert(fibril_rwlock_is_locked(&tree->rwlock)); 873 874 link = hash_table_find(&tree->devman_devices, &key); 854 875 return hash_table_get_instance(link, node_t, devman_link); 855 876 } … … 907 928 /** Insert new device into device tree. 908 929 * 909 * The device tree's rwlock should be already held exclusively when calling this910 * function.911 *912 930 * @param tree The device tree. 913 931 * @param node The newly added device node. … … 924 942 assert(tree != NULL); 925 943 assert(dev_name != NULL); 944 assert(fibril_rwlock_is_write_locked(&tree->rwlock)); 926 945 927 946 node->name = dev_name; … … 1042 1061 1043 1062 info = (dev_class_info_t *) malloc(sizeof(dev_class_info_t)); 1044 if (info != NULL) 1063 if (info != NULL) { 1045 1064 memset(info, 0, sizeof(dev_class_info_t)); 1065 list_initialize(&info->dev_classes); 1066 list_initialize(&info->devmap_link); 1067 list_initialize(&info->link); 1068 } 1046 1069 1047 1070 return info; … … 1167 1190 fibril_rwlock_initialize(&class_list->rwlock); 1168 1191 hash_table_create(&class_list->devmap_devices, DEVICE_BUCKETS, 1, 1169 &devmap_devices_ ops);1192 &devmap_devices_class_ops); 1170 1193 } 1171 1194 … … 1215 1238 hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link); 1216 1239 fibril_rwlock_write_unlock(&class_list->rwlock); 1240 1241 assert(find_devmap_class_device(class_list, cli->devmap_handle) != NULL); 1217 1242 } 1218 1243 -
uspace/srv/devman/main.c
r59e9398b rb2d06fa 281 281 * handle. 282 282 */ 283 devmap_device_register(devmap_pathname, &cli->devmap_handle); 283 devmap_device_register_with_iface(devmap_pathname, 284 &cli->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP); 284 285 285 286 /* … … 486 487 static void devman_connection_devmapper(ipc_callid_t iid, ipc_call_t *icall) 487 488 { 488 devmap_handle_t devmap_handle = IPC_GET_ IMETHOD(*icall);489 devmap_handle_t devmap_handle = IPC_GET_ARG2(*icall); 489 490 node_t *dev; 490 491 … … 503 504 } 504 505 505 printf(NAME ": devman_connection_devmapper: forward connection to "506 "device %s to driver %s.\n", dev->pathname, dev->drv->name);507 506 ipc_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, dev->handle, 0, 508 507 IPC_FF_NONE); 508 printf(NAME ": devman_connection_devmapper: forwarded connection to " 509 "device %s to driver %s.\n", dev->pathname, dev->drv->name); 509 510 } 510 511 … … 512 513 static void devman_connection(ipc_callid_t iid, ipc_call_t *icall) 513 514 { 514 /*515 * Silly hack to enable the device manager to register as a driver by516 * the device mapper. If the ipc method is not IPC_M_CONNECT_ME_TO, this517 * is not the forwarded connection from naming service, so it must be a518 * connection from the devmapper which thinks this is a devmapper-style519 * driver. So pretend this is a devmapper-style driver. (This does not520 * work for device with handle == IPC_M_CONNECT_ME_TO, because devmapper521 * passes device handle to the driver as an ipc method.)522 */523 if (IPC_GET_IMETHOD(*icall) != IPC_M_CONNECT_ME_TO)524 devman_connection_devmapper(iid, icall);525 526 /*527 * ipc method is IPC_M_CONNECT_ME_TO, so this is forwarded connection528 * from naming service by which we registered as device manager, so be529 * device manager.530 */531 532 515 /* Select interface. */ 533 516 switch ((sysarg_t) (IPC_GET_ARG1(*icall))) { … … 542 525 devman_forward(iid, icall, false); 543 526 break; 527 case DEVMAN_CONNECT_FROM_DEVMAP: 528 /* Someone connected through devmap node. */ 529 devman_connection_devmapper(iid, icall); 530 break; 544 531 case DEVMAN_CONNECT_TO_PARENTS_DEVICE: 545 532 /* Connect client to selected device. */ -
uspace/srv/devmap/devmap.c
r59e9398b rb2d06fa 46 46 #include <str.h> 47 47 #include <ipc/devmap.h> 48 #include <assert.h> 48 49 49 50 #define NAME "devmap" … … 99 100 /** Device driver handling this device */ 100 101 devmap_driver_t *driver; 102 /** Use this interface when forwarding to driver. */ 103 sysarg_t forward_interface; 101 104 } devmap_device_t; 102 105 … … 206 209 } 207 210 208 /** Find namespace with given name. 209 * 210 * The devices_list_mutex should be already held when 211 * calling this function. 212 * 213 */ 211 /** Find namespace with given name. */ 214 212 static devmap_namespace_t *devmap_namespace_find_name(const char *name) 215 213 { 216 214 link_t *item; 215 216 assert(fibril_mutex_is_locked(&devices_list_mutex)); 217 217 218 for (item = namespaces_list.next; item != &namespaces_list; item = item->next) { 218 219 devmap_namespace_t *namespace = … … 227 228 /** Find namespace with given handle. 228 229 * 229 * The devices_list_mutex should be already held when230 * calling this function.231 *232 230 * @todo: use hash table 233 231 * … … 236 234 { 237 235 link_t *item; 236 237 assert(fibril_mutex_is_locked(&devices_list_mutex)); 238 238 239 for (item = namespaces_list.next; item != &namespaces_list; item = item->next) { 239 240 devmap_namespace_t *namespace = … … 246 247 } 247 248 248 /** Find device with given name. 249 * 250 * The devices_list_mutex should be already held when 251 * calling this function. 252 * 253 */ 249 /** Find device with given name. */ 254 250 static devmap_device_t *devmap_device_find_name(const char *ns_name, 255 251 const char *name) 256 252 { 257 253 link_t *item; 254 255 assert(fibril_mutex_is_locked(&devices_list_mutex)); 256 258 257 for (item = devices_list.next; item != &devices_list; item = item->next) { 259 258 devmap_device_t *device = … … 269 268 /** Find device with given handle. 270 269 * 271 * The devices_list_mutex should be already held when272 * calling this function.273 *274 270 * @todo: use hash table 275 271 * … … 278 274 { 279 275 link_t *item; 276 277 assert(fibril_mutex_is_locked(&devices_list_mutex)); 278 280 279 for (item = devices_list.next; item != &devices_list; item = item->next) { 281 280 devmap_device_t *device = … … 288 287 } 289 288 290 /** Create a namespace (if not already present) 291 * 292 * The devices_list_mutex should be already held when 293 * calling this function. 294 * 295 */ 289 /** Create a namespace (if not already present). */ 296 290 static devmap_namespace_t *devmap_namespace_create(const char *ns_name) 297 291 { 298 devmap_namespace_t *namespace = devmap_namespace_find_name(ns_name); 292 devmap_namespace_t *namespace; 293 294 assert(fibril_mutex_is_locked(&devices_list_mutex)); 295 296 namespace = devmap_namespace_find_name(ns_name); 299 297 if (namespace != NULL) 300 298 return namespace; … … 321 319 } 322 320 323 /** Destroy a namespace (if it is no longer needed) 324 * 325 * The devices_list_mutex should be already held when 326 * calling this function. 327 * 328 */ 321 /** Destroy a namespace (if it is no longer needed). */ 329 322 static void devmap_namespace_destroy(devmap_namespace_t *namespace) 330 323 { 324 assert(fibril_mutex_is_locked(&devices_list_mutex)); 325 331 326 if (namespace->refcnt == 0) { 332 327 list_remove(&(namespace->namespaces)); … … 337 332 } 338 333 339 /** Increase namespace reference count by including device 340 * 341 * The devices_list_mutex should be already held when 342 * calling this function. 343 * 344 */ 334 /** Increase namespace reference count by including device. */ 345 335 static void devmap_namespace_addref(devmap_namespace_t *namespace, 346 336 devmap_device_t *device) 347 337 { 338 assert(fibril_mutex_is_locked(&devices_list_mutex)); 339 348 340 device->namespace = namespace; 349 341 namespace->refcnt++; 350 342 } 351 343 352 /** Decrease namespace reference count 353 * 354 * The devices_list_mutex should be already held when 355 * calling this function. 356 * 357 */ 344 /** Decrease namespace reference count. */ 358 345 static void devmap_namespace_delref(devmap_namespace_t *namespace) 359 346 { 347 assert(fibril_mutex_is_locked(&devices_list_mutex)); 348 360 349 namespace->refcnt--; 361 350 devmap_namespace_destroy(namespace); 362 351 } 363 352 364 /** Unregister device and free it 365 * 366 * The devices_list_mutex should be already held when 367 * calling this function. 368 * 369 */ 353 /** Unregister device and free it. */ 370 354 static void devmap_device_unregister_core(devmap_device_t *device) 371 355 { 356 assert(fibril_mutex_is_locked(&devices_list_mutex)); 357 372 358 devmap_namespace_delref(device->namespace); 373 359 list_remove(&(device->devices)); … … 517 503 } 518 504 505 /* Set the interface, if any. */ 506 device->forward_interface = IPC_GET_ARG1(*icall); 507 519 508 /* Get fqdn */ 520 509 char *fqdn; … … 566 555 /* Get unique device handle */ 567 556 device->handle = devmap_create_handle(); 568 557 569 558 devmap_namespace_addref(namespace, device); 570 559 device->driver = driver; … … 617 606 } 618 607 619 ipc_forward_fast(callid, dev->driver->phone, dev->handle, 620 IPC_GET_ARG3(*call), 0, IPC_FF_NONE); 608 if (dev->forward_interface == 0) { 609 ipc_forward_fast(callid, dev->driver->phone, 610 dev->handle, 0, 0, 611 IPC_FF_NONE); 612 } else { 613 ipc_forward_fast(callid, dev->driver->phone, 614 dev->forward_interface, dev->handle, 0, 615 IPC_FF_NONE); 616 } 621 617 622 618 fibril_mutex_unlock(&devices_list_mutex); -
uspace/srv/fs/devfs/devfs_ops.c
r59e9398b rb2d06fa 60 60 typedef struct { 61 61 devmap_handle_t handle; 62 int phone; 62 int phone; /**< When < 0, the structure is incomplete. */ 63 63 size_t refcount; 64 64 link_t link; 65 fibril_condvar_t cv; /**< Broadcast when completed. */ 65 66 } device_t; 66 67 … … 227 228 [DEVICES_KEY_HANDLE] = (unsigned long) node->handle 228 229 }; 229 230 link_t *lnk; 231 230 232 fibril_mutex_lock(&devices_mutex); 231 link_t *lnk = hash_table_find(&devices, key); 233 restart: 234 lnk = hash_table_find(&devices, key); 232 235 if (lnk == NULL) { 233 236 device_t *dev = (device_t *) malloc(sizeof(device_t)); … … 237 240 } 238 241 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 other 249 * fibrils will not race with us when we drop the mutex 250 * 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 239 259 int phone = devmap_device_connect(node->handle, 0); 260 261 fibril_mutex_lock(&devices_mutex); 262 263 /* 264 * Notify possible waiters about this device structure 265 * being completed (or destroyed). 266 */ 267 fibril_condvar_broadcast(&dev->cv); 268 240 269 if (phone < 0) { 270 /* 271 * Connecting failed, need to remove the 272 * entry and free the device structure. 273 */ 274 hash_table_remove(&devices, key, DEVICES_KEYS); 241 275 fibril_mutex_unlock(&devices_mutex); 276 242 277 free(dev); 243 278 return ENOENT; 244 279 } 245 280 246 dev->handle = node->handle;281 /* Set the correct phone. */ 247 282 dev->phone = phone; 248 dev->refcount = 1;249 250 hash_table_insert(&devices, key, &dev->link);251 283 } else { 252 284 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 completed 289 * and start from the beginning as the device 290 * structure might have entirely disappeared 291 * while we were not holding the mutex in 292 * fibril_condvar_wait(). 293 */ 294 fibril_condvar_wait(&dev->cv, &devices_mutex); 295 goto restart; 296 } 297 253 298 dev->refcount++; 254 299 } … … 564 609 565 610 device_t *dev = hash_table_get_instance(lnk, device_t, link); 611 assert(dev->phone >= 0); 566 612 567 613 ipc_callid_t callid; … … 627 673 628 674 device_t *dev = hash_table_get_instance(lnk, device_t, link); 675 assert(dev->phone >= 0); 629 676 630 677 ipc_callid_t callid; … … 696 743 697 744 device_t *dev = hash_table_get_instance(lnk, device_t, link); 745 assert(dev->phone >= 0); 698 746 dev->refcount--; 699 747 … … 743 791 744 792 device_t *dev = hash_table_get_instance(lnk, device_t, link); 793 assert(dev->phone >= 0); 745 794 746 795 /* Make a request at the driver */ -
uspace/srv/net/tl/tcp/tcp.c
r59e9398b rb2d06fa 1803 1803 fibril_rwlock_write_unlock(socket_data->local_lock); 1804 1804 1805 socket_data->state = TCP_SOCKET_SYN_SENT; 1806 1805 1807 /* Send the packet */ 1806 1808 printf("connecting %d\n", packet_get_id(packet)); … … 2085 2087 if (!fibril) { 2086 2088 free(operation_timeout); 2087 return EPARTY; /* FIXME: use another EC */ 2088 } 2089 return ENOMEM; 2090 } 2091 2089 2092 // fibril_mutex_lock(&socket_data->operation.mutex); 2090 2093 /* Start the timeout fibril */ -
uspace/srv/vfs/vfs_lookup.c
r59e9398b rb2d06fa 179 179 fibril_mutex_unlock(&plb_mutex); 180 180 181 if (( (int) rc < EOK) || (!result))181 if ((int) rc < EOK) 182 182 return (int) rc; 183 184 if (!result) 185 return EOK; 183 186 184 187 result->triplet.fs_handle = (fs_handle_t) rc;
Note:
See TracChangeset
for help on using the changeset viewer.