Changes in uspace/srv/devman/main.c [b927375:3ad7b1c] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/main.c
rb927375 r3ad7b1c 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 93 95 /* Find driver structure. */ 94 96 driver = find_driver(&drivers_list, drv_name); 95 96 97 if (driver == NULL) { 97 printf(NAME ": no driver named %s was found.\n", drv_name);98 log_msg(LVL_ERROR, "No driver named `%s' was found.", drv_name); 98 99 free(drv_name); 99 100 drv_name = NULL; … … 105 106 drv_name = NULL; 106 107 108 fibril_mutex_lock(&driver->driver_mutex); 109 110 if (driver->phone >= 0) { 111 /* We already have a connection to the driver. */ 112 log_msg(LVL_ERROR, "Driver '%s' already started.\n", 113 driver->name); 114 fibril_mutex_unlock(&driver->driver_mutex); 115 async_answer_0(iid, EEXISTS); 116 return NULL; 117 } 118 119 switch (driver->state) { 120 case DRIVER_NOT_STARTED: 121 /* Somebody started the driver manually. */ 122 log_msg(LVL_NOTE, "Driver '%s' started manually.\n", 123 driver->name); 124 driver->state = DRIVER_STARTING; 125 break; 126 case DRIVER_STARTING: 127 /* The expected case */ 128 break; 129 case DRIVER_RUNNING: 130 /* Should not happen since we do not have a connected phone */ 131 assert(false); 132 } 133 107 134 /* Create connection to the driver. */ 108 printf(NAME ": creating connection to the %s driver.\n", driver->name); 135 log_msg(LVL_DEBUG, "Creating connection to the `%s' driver.", 136 driver->name); 109 137 ipc_call_t call; 110 138 ipc_callid_t callid = async_get_call(&call); 111 139 if (IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) { 140 fibril_mutex_unlock(&driver->driver_mutex); 112 141 async_answer_0(callid, ENOTSUP); 113 142 async_answer_0(iid, ENOTSUP); … … 116 145 117 146 /* Remember driver's phone. */ 118 set_driver_phone(driver, IPC_GET_ARG5(call)); 119 120 printf(NAME ": the %s driver was successfully registered as running.\n", 147 driver->phone = IPC_GET_ARG5(call); 148 149 fibril_mutex_unlock(&driver->driver_mutex); 150 151 log_msg(LVL_NOTE, 152 "The `%s' driver was successfully registered as running.", 121 153 driver->name); 122 154 … … 142 174 callid = async_get_call(&call); 143 175 if (DEVMAN_ADD_MATCH_ID != IPC_GET_IMETHOD(call)) { 144 printf(NAME ": ERROR: devman_receive_match_id - invalid "145 " protocol.\n");176 log_msg(LVL_ERROR, 177 "Invalid protocol when trying to receive match id."); 146 178 async_answer_0(callid, EINVAL); 147 179 delete_match_id(match_id); … … 150 182 151 183 if (match_id == NULL) { 152 printf(NAME ": ERROR: devman_receive_match_id - failed to " 153 "allocate match id.\n"); 184 log_msg(LVL_ERROR, "Failed to allocate match id."); 154 185 async_answer_0(callid, ENOMEM); 155 186 return ENOMEM; … … 165 196 if (rc != EOK) { 166 197 delete_match_id(match_id); 167 printf(NAME ": devman_receive_match_id - failed to receive "168 "match id string.\n");198 log_msg(LVL_ERROR, "Failed to receive match id string: %s.", 199 str_error(rc)); 169 200 return rc; 170 201 } … … 172 203 list_append(&match_id->link, &match_ids->ids); 173 204 174 printf(NAME ": received match id '%s', score = %d \n",205 log_msg(LVL_DEBUG, "Received match id `%s', score %d.", 175 206 match_id->id, match_id->score); 176 207 return rc; … … 228 259 if (ftype != fun_inner && ftype != fun_exposed) { 229 260 /* Unknown function type */ 230 printf(NAME ": Error, unknown function type provided by driver!\n"); 261 log_msg(LVL_ERROR, 262 "Unknown function type %d provided by driver.", 263 (int) ftype); 231 264 232 265 fibril_rwlock_write_unlock(&tree->rwlock); … … 243 276 } 244 277 278 /* Check that function with same name is not there already. */ 279 if (find_fun_node_in_device(pdev, fun_name) != NULL) { 280 fibril_rwlock_write_unlock(&tree->rwlock); 281 async_answer_0(callid, EEXISTS); 282 printf(NAME ": Warning, driver tried to register `%s' twice.\n", 283 fun_name); 284 free(fun_name); 285 return; 286 } 287 245 288 fun_node_t *fun = create_fun_node(); 246 289 if (!insert_fun_node(&device_tree, fun, fun_name, pdev)) { … … 265 308 fibril_rwlock_write_unlock(&tree->rwlock); 266 309 267 printf(NAME ": devman_add_function %s\n", fun->pathname);310 log_msg(LVL_DEBUG, "devman_add_function(fun=\"%s\")", fun->pathname); 268 311 269 312 devman_receive_match_ids(match_count, &fun->match_ids); … … 347 390 devmap_register_class_dev(class_info); 348 391 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);392 log_msg(LVL_NOTE, "Function `%s' added to class `%s' as `%s'.", 393 fun->pathname, class_name, class_info->dev_name); 351 394 352 395 async_answer_0(callid, EOK); … … 363 406 364 407 initialize_running_driver(driver, &device_tree); 365 printf(NAME ": the %s driver was successfully initialized. \n",408 log_msg(LVL_DEBUG, "The `%s` driver was successfully initialized.", 366 409 driver->name); 367 410 return 0; … … 385 428 fid_t fid = fibril_create(init_running_drv, driver); 386 429 if (fid == 0) { 387 printf(NAME ": Error creating fibril for the initialization of "388 " the newly registered running driver.\n");430 log_msg(LVL_ERROR, "Failed to create initialization fibril " \ 431 "for driver `%s'.", driver->name); 389 432 return; 390 433 } … … 438 481 } 439 482 483 /** Find handle for the device instance identified by device class name. */ 484 static void devman_function_get_handle_by_class(ipc_callid_t iid, 485 ipc_call_t *icall) 486 { 487 char *classname; 488 char *devname; 489 490 int rc = async_data_write_accept((void **) &classname, true, 0, 0, 0, 0); 491 if (rc != EOK) { 492 async_answer_0(iid, rc); 493 return; 494 } 495 rc = async_data_write_accept((void **) &devname, true, 0, 0, 0, 0); 496 if (rc != EOK) { 497 free(classname); 498 async_answer_0(iid, rc); 499 return; 500 } 501 502 503 fun_node_t *fun = find_fun_node_by_class(&class_list, 504 classname, devname); 505 506 free(classname); 507 free(devname); 508 509 if (fun == NULL) { 510 async_answer_0(iid, ENOENT); 511 return; 512 } 513 514 async_answer_1(iid, EOK, fun->handle); 515 } 516 440 517 441 518 /** Function for handling connections from a client to the device manager. */ … … 457 534 devman_function_get_handle(callid, &call); 458 535 break; 536 case DEVMAN_DEVICE_GET_HANDLE_BY_CLASS: 537 devman_function_get_handle_by_class(callid, &call); 538 break; 459 539 default: 460 540 async_answer_0(callid, ENOENT); … … 477 557 dev = fun->dev; 478 558 479 if (fun == NULL && dev == NULL) { 480 printf(NAME ": devman_forward error - no device or function with " 481 "handle %" PRIun " was found.\n", handle); 559 /* 560 * For a valid function to connect to we need a device. The root 561 * function, for example, has no device and cannot be connected to. 562 * This means @c dev needs to be valid regardless whether we are 563 * connecting to a device or to a function. 564 */ 565 if (dev == NULL) { 566 log_msg(LVL_ERROR, "IPC forwarding failed - no device or " 567 "function with handle %" PRIun " was found.", handle); 482 568 async_answer_0(iid, ENOENT); 483 569 return; … … 485 571 486 572 if (fun == NULL && !drv_to_parent) { 487 printf(NAME ": devman_forward error - cannot connect to " 488 "handle %" PRIun ", refers to a device.\n", handle); 573 log_msg(LVL_ERROR, NAME ": devman_forward error - cannot " 574 "connect to handle %" PRIun ", refers to a device.", 575 handle); 489 576 async_answer_0(iid, ENOENT); 490 577 return; … … 507 594 508 595 if (driver == NULL) { 509 printf(NAME ": devman_forward error - the device is not in %" PRIun510 " usable state.\n", handle);596 log_msg(LVL_ERROR, "IPC forwarding refused - " \ 597 "the device %" PRIun " is not in usable state.", handle); 511 598 async_answer_0(iid, ENOENT); 512 599 return; … … 519 606 method = DRIVER_CLIENT; 520 607 521 if (driver->phone < =0) {522 printf(NAME ": devman_forward: cound not forward to driver %s ",523 driver->name);524 printf("the driver's phone is %" PRIun ").\n",driver->phone);608 if (driver->phone < 0) { 609 log_msg(LVL_ERROR, 610 "Could not forward to driver `%s' (phone is %d).", 611 driver->name, (int) driver->phone); 525 612 async_answer_0(iid, EINVAL); 526 613 return; … … 528 615 529 616 if (fun != NULL) { 530 printf(NAME ": devman_forward: forward connection to function %s to " 531 "driver %s.\n", fun->pathname, driver->name); 617 log_msg(LVL_DEBUG, 618 "Forwarding request for `%s' function to driver `%s'.", 619 fun->pathname, driver->name); 532 620 } else { 533 printf(NAME ": devman_forward: forward connection to device %s to " 534 "driver %s.\n", dev->pfun->pathname, driver->name); 621 log_msg(LVL_DEBUG, 622 "Forwarding request for `%s' device to driver `%s'.", 623 dev->pfun->pathname, driver->name); 535 624 } 536 625 … … 557 646 dev = fun->dev; 558 647 559 if (dev->state != DEVICE_USABLE || dev->drv->phone < =0) {648 if (dev->state != DEVICE_USABLE || dev->drv->phone < 0) { 560 649 async_answer_0(iid, EINVAL); 561 650 return; … … 564 653 async_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, fun->handle, 0, 565 654 IPC_FF_NONE); 566 printf(NAME ": devman_connection_devmapper: forwarded connection to " 567 "device %s to driver %s.\n", fun->pathname, dev->drv->name); 655 log_msg(LVL_DEBUG, 656 "Forwarding devmapper request for `%s' function to driver `%s'.", 657 fun->pathname, dev->drv->name); 568 658 } 569 659 … … 600 690 static bool devman_init(void) 601 691 { 602 printf(NAME ": devman_init - looking for available drivers.\n");692 log_msg(LVL_DEBUG, "devman_init - looking for available drivers."); 603 693 604 694 /* Initialize list of available drivers. */ … … 606 696 if (lookup_available_drivers(&drivers_list, 607 697 DRIVER_DEFAULT_STORE) == 0) { 608 printf(NAME " no drivers found.");698 log_msg(LVL_FATAL, "No drivers found."); 609 699 return false; 610 700 } 611 701 612 printf(NAME ": devman_init - list of drivers has been initialized.\n");702 log_msg(LVL_DEBUG, "devman_init - list of drivers has been initialized."); 613 703 614 704 /* Create root device node. */ 615 705 if (!init_device_tree(&device_tree, &drivers_list)) { 616 printf(NAME " failed to initialize device tree.");706 log_msg(LVL_FATAL, "Failed to initialize device tree."); 617 707 return false; 618 708 } … … 635 725 printf(NAME ": HelenOS Device Manager\n"); 636 726 727 if (log_init(NAME, LVL_ERROR) != EOK) { 728 printf(NAME ": Error initializing logging subsystem.\n"); 729 return -1; 730 } 731 637 732 if (!devman_init()) { 638 printf(NAME ": Error while initializing service\n");733 log_msg(LVL_ERROR, "Error while initializing service."); 639 734 return -1; 640 735 } … … 644 739 645 740 /* Register device manager at naming service. */ 646 if (service_register(SERVICE_DEVMAN) != EOK) 741 if (service_register(SERVICE_DEVMAN) != EOK) { 742 log_msg(LVL_ERROR, "Failed registering as a service."); 647 743 return -1; 648 649 printf(NAME ": Accepting connections\n"); 744 } 745 746 printf(NAME ": Accepting connections.\n"); 650 747 async_manager(); 651 748
Note:
See TracChangeset
for help on using the changeset viewer.