Changeset f8e8738 in mainline for uspace/srv/devman/main.c
- Timestamp:
- 2011-04-07T20:22:40Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- fee6381
- Parents:
- 61257f4 (diff), a82889e (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
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/main.c
r61257f4 rf8e8738 43 43 #include <stdio.h> 44 44 #include <errno.h> 45 #include <str_error.h> 45 46 #include <bool.h> 46 47 #include <fibril_synch.h> … … 51 52 #include <sys/stat.h> 52 53 #include <ctype.h> 54 #include <io/log.h> 53 55 #include <ipc/devman.h> 54 56 #include <ipc/driver.h> … … 71 73 driver_t *driver = NULL; 72 74 73 printf(NAME ": devman_driver_register \n");75 log_msg(LVL_DEBUG, "devman_driver_register"); 74 76 75 77 iid = async_get_call(&icall); … … 88 90 } 89 91 90 printf(NAME ": the %s driver is trying to register by the service.\n",92 log_msg(LVL_DEBUG, "The `%s' driver is trying to register.", 91 93 drv_name); 92 94 … … 95 97 96 98 if (driver == NULL) { 97 printf(NAME ": no driver named %s was found.\n", drv_name);99 log_msg(LVL_ERROR, "No driver named `%s' was found.", drv_name); 98 100 free(drv_name); 99 101 drv_name = NULL; … … 106 108 107 109 /* Create connection to the driver. */ 108 printf(NAME ": creating connection to the %s driver.\n", driver->name); 110 log_msg(LVL_DEBUG, "Creating connection to the `%s' driver.", 111 driver->name); 109 112 ipc_call_t call; 110 113 ipc_callid_t callid = async_get_call(&call); … … 118 121 set_driver_phone(driver, IPC_GET_ARG5(call)); 119 122 120 printf(NAME ": the %s driver was successfully registered as running.\n", 123 log_msg(LVL_NOTE, 124 "The `%s' driver was successfully registered as running.", 121 125 driver->name); 122 126 … … 142 146 callid = async_get_call(&call); 143 147 if (DEVMAN_ADD_MATCH_ID != IPC_GET_IMETHOD(call)) { 144 printf(NAME ": ERROR: devman_receive_match_id - invalid "145 " protocol.\n");148 log_msg(LVL_ERROR, 149 "Invalid protocol when trying to receive match id."); 146 150 async_answer_0(callid, EINVAL); 147 151 delete_match_id(match_id); … … 150 154 151 155 if (match_id == NULL) { 152 printf(NAME ": ERROR: devman_receive_match_id - failed to " 153 "allocate match id.\n"); 156 log_msg(LVL_ERROR, "Failed to allocate match id."); 154 157 async_answer_0(callid, ENOMEM); 155 158 return ENOMEM; … … 165 168 if (rc != EOK) { 166 169 delete_match_id(match_id); 167 printf(NAME ": devman_receive_match_id - failed to receive "168 "match id string.\n");170 log_msg(LVL_ERROR, "Failed to receive match id string: %s.", 171 str_error(rc)); 169 172 return rc; 170 173 } … … 172 175 list_append(&match_id->link, &match_ids->ids); 173 176 174 printf(NAME ": received match id '%s', score = %d \n",177 log_msg(LVL_DEBUG, "Received match id `%s', score %d.", 175 178 match_id->id, match_id->score); 176 179 return rc; … … 228 231 if (ftype != fun_inner && ftype != fun_exposed) { 229 232 /* Unknown function type */ 230 printf(NAME ": Error, unknown function type provided by driver!\n"); 233 log_msg(LVL_ERROR, 234 "Unknown function type %d provided by driver.", 235 (int) ftype); 231 236 232 237 fibril_rwlock_write_unlock(&tree->rwlock); … … 243 248 } 244 249 250 /* Check that function with same name is not there already. */ 251 if (find_fun_node_in_device(pdev, fun_name) != NULL) { 252 fibril_rwlock_write_unlock(&tree->rwlock); 253 async_answer_0(callid, EEXISTS); 254 printf(NAME ": Warning, driver tried to register `%s' twice.\n", 255 fun_name); 256 free(fun_name); 257 return; 258 } 259 245 260 fun_node_t *fun = create_fun_node(); 246 261 if (!insert_fun_node(&device_tree, fun, fun_name, pdev)) { … … 265 280 fibril_rwlock_write_unlock(&tree->rwlock); 266 281 267 printf(NAME ": devman_add_function %s\n", fun->pathname);282 log_msg(LVL_DEBUG, "devman_add_function(fun=\"%s\")", fun->pathname); 268 283 269 284 devman_receive_match_ids(match_count, &fun->match_ids); … … 347 362 devmap_register_class_dev(class_info); 348 363 349 printf(NAME ": function'%s' added to class '%s', class name '%s' was "350 "asigned to it\n",fun->pathname, class_name, class_info->dev_name);364 log_msg(LVL_NOTE, "Function `%s' added to class `%s' as `%s'.", 365 fun->pathname, class_name, class_info->dev_name); 351 366 352 367 async_answer_0(callid, EOK); … … 363 378 364 379 initialize_running_driver(driver, &device_tree); 365 printf(NAME ": the %s driver was successfully initialized. \n",380 log_msg(LVL_DEBUG, "The `%s` driver was successfully initialized.", 366 381 driver->name); 367 382 return 0; … … 385 400 fid_t fid = fibril_create(init_running_drv, driver); 386 401 if (fid == 0) { 387 printf(NAME ": Error creating fibril for the initialization of "388 " the newly registered running driver.\n");402 log_msg(LVL_ERROR, "Failed to create initialization fibril " \ 403 "for driver `%s'.", driver->name); 389 404 return; 390 405 } … … 438 453 } 439 454 455 /** Find handle for the device instance identified by device class name. */ 456 static void devman_function_get_handle_by_class(ipc_callid_t iid, 457 ipc_call_t *icall) 458 { 459 char *classname; 460 char *devname; 461 462 int rc = async_data_write_accept((void **) &classname, true, 0, 0, 0, 0); 463 if (rc != EOK) { 464 async_answer_0(iid, rc); 465 return; 466 } 467 rc = async_data_write_accept((void **) &devname, true, 0, 0, 0, 0); 468 if (rc != EOK) { 469 free(classname); 470 async_answer_0(iid, rc); 471 return; 472 } 473 474 475 fun_node_t *fun = find_fun_node_by_class(&class_list, 476 classname, devname); 477 478 free(classname); 479 free(devname); 480 481 if (fun == NULL) { 482 async_answer_0(iid, ENOENT); 483 return; 484 } 485 486 async_answer_1(iid, EOK, fun->handle); 487 } 488 440 489 441 490 /** Function for handling connections from a client to the device manager. */ … … 457 506 devman_function_get_handle(callid, &call); 458 507 break; 508 case DEVMAN_DEVICE_GET_HANDLE_BY_CLASS: 509 devman_function_get_handle_by_class(callid, &call); 510 break; 459 511 default: 460 512 async_answer_0(callid, ENOENT); … … 477 529 dev = fun->dev; 478 530 479 if (fun == NULL && dev == NULL) { 480 printf(NAME ": devman_forward error - no device or function with " 481 "handle %" PRIun " was found.\n", handle); 531 /* 532 * For a valid function to connect to we need a device. The root 533 * function, for example, has no device and cannot be connected to. 534 * This means @c dev needs to be valid regardless whether we are 535 * connecting to a device or to a function. 536 */ 537 if (dev == NULL) { 538 log_msg(LVL_ERROR, "IPC forwarding failed - no device or " 539 "function with handle %" PRIun " was found.", handle); 482 540 async_answer_0(iid, ENOENT); 483 541 return; … … 485 543 486 544 if (fun == NULL && !drv_to_parent) { 487 printf(NAME ": devman_forward error - cannot connect to " 488 "handle %" PRIun ", refers to a device.\n", handle); 545 log_msg(LVL_ERROR, NAME ": devman_forward error - cannot " 546 "connect to handle %" PRIun ", refers to a device.", 547 handle); 489 548 async_answer_0(iid, ENOENT); 490 549 return; … … 507 566 508 567 if (driver == NULL) { 509 printf(NAME ": devman_forward error - the device %" PRIun\510 " (%s) is not in usable state.\n",568 log_msg(LVL_ERROR, "IPC forwarding refused - " \ 569 "the device %" PRIun "(%s) is not in usable state.", 511 570 handle, dev->pfun->pathname); 512 571 async_answer_0(iid, ENOENT); … … 521 580 522 581 if (driver->phone <= 0) { 523 printf(NAME ": devman_forward: cound not forward to driver %s ",524 driver->name);525 printf("the driver's phone is %" PRIun ").\n",driver->phone);582 log_msg(LVL_ERROR, 583 "Could not forward to driver `%s' (phone is %d).", 584 driver->name, (int) driver->phone); 526 585 async_answer_0(iid, EINVAL); 527 586 return; … … 529 588 530 589 if (fun != NULL) { 531 printf(NAME ": devman_forward: forward connection to function %s to " 532 "driver %s.\n", fun->pathname, driver->name); 590 log_msg(LVL_DEBUG, 591 "Forwarding request for `%s' function to driver `%s'.", 592 fun->pathname, driver->name); 533 593 } else { 534 printf(NAME ": devman_forward: forward connection to device %s to " 535 "driver %s.\n", dev->pfun->pathname, driver->name); 594 log_msg(LVL_DEBUG, 595 "Forwarding request for `%s' device to driver `%s'.", 596 dev->pfun->pathname, driver->name); 536 597 } 537 598 … … 565 626 async_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, fun->handle, 0, 566 627 IPC_FF_NONE); 567 printf(NAME ": devman_connection_devmapper: forwarded connection to " 568 "device %s to driver %s.\n", fun->pathname, dev->drv->name); 628 log_msg(LVL_DEBUG, 629 "Forwarding devmapper request for `%s' function to driver `%s'.", 630 fun->pathname, dev->drv->name); 569 631 } 570 632 … … 601 663 static bool devman_init(void) 602 664 { 603 printf(NAME ": devman_init - looking for available drivers.\n");665 log_msg(LVL_DEBUG, "devman_init - looking for available drivers."); 604 666 605 667 /* Initialize list of available drivers. */ … … 607 669 if (lookup_available_drivers(&drivers_list, 608 670 DRIVER_DEFAULT_STORE) == 0) { 609 printf(NAME " no drivers found.");671 log_msg(LVL_FATAL, "No drivers found."); 610 672 return false; 611 673 } 612 674 613 printf(NAME ": devman_init - list of drivers has been initialized.\n");675 log_msg(LVL_DEBUG, "devman_init - list of drivers has been initialized."); 614 676 615 677 /* Create root device node. */ 616 678 if (!init_device_tree(&device_tree, &drivers_list)) { 617 printf(NAME " failed to initialize device tree.");679 log_msg(LVL_FATAL, "Failed to initialize device tree."); 618 680 return false; 619 681 } … … 636 698 printf(NAME ": HelenOS Device Manager\n"); 637 699 700 if (log_init(NAME, LVL_ERROR) != EOK) { 701 printf(NAME ": Error initializing logging subsystem.\n"); 702 return -1; 703 } 704 638 705 if (!devman_init()) { 639 printf(NAME ": Error while initializing service\n");706 log_msg(LVL_ERROR, "Error while initializing service."); 640 707 return -1; 641 708 } … … 645 712 646 713 /* Register device manager at naming service. */ 647 if (service_register(SERVICE_DEVMAN) != EOK) 714 if (service_register(SERVICE_DEVMAN) != EOK) { 715 log_msg(LVL_ERROR, "Failed registering as a service."); 648 716 return -1; 649 650 printf(NAME ": Accepting connections\n"); 717 } 718 719 printf(NAME ": Accepting connections.\n"); 651 720 async_manager(); 652 721
Note:
See TracChangeset
for help on using the changeset viewer.