Changes in uspace/srv/devman/main.c [3ad7b1c:b927375] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/main.c
r3ad7b1c rb927375 43 43 #include <stdio.h> 44 44 #include <errno.h> 45 #include <str_error.h>46 45 #include <bool.h> 47 46 #include <fibril_synch.h> … … 52 51 #include <sys/stat.h> 53 52 #include <ctype.h> 54 #include <io/log.h>55 53 #include <ipc/devman.h> 56 54 #include <ipc/driver.h> … … 73 71 driver_t *driver = NULL; 74 72 75 log_msg(LVL_DEBUG, "devman_driver_register");73 printf(NAME ": devman_driver_register \n"); 76 74 77 75 iid = async_get_call(&icall); … … 90 88 } 91 89 92 log_msg(LVL_DEBUG, "The `%s' driver is trying to register.",90 printf(NAME ": the %s driver is trying to register by the service.\n", 93 91 drv_name); 94 92 95 93 /* Find driver structure. */ 96 94 driver = find_driver(&drivers_list, drv_name); 95 97 96 if (driver == NULL) { 98 log_msg(LVL_ERROR, "No driver named `%s' was found.", drv_name);97 printf(NAME ": no driver named %s was found.\n", drv_name); 99 98 free(drv_name); 100 99 drv_name = NULL; … … 106 105 drv_name = NULL; 107 106 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 134 107 /* Create connection to the driver. */ 135 log_msg(LVL_DEBUG, "Creating connection to the `%s' driver.", 136 driver->name); 108 printf(NAME ": creating connection to the %s driver.\n", driver->name); 137 109 ipc_call_t call; 138 110 ipc_callid_t callid = async_get_call(&call); 139 111 if (IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) { 140 fibril_mutex_unlock(&driver->driver_mutex);141 112 async_answer_0(callid, ENOTSUP); 142 113 async_answer_0(iid, ENOTSUP); … … 145 116 146 117 /* Remember driver's phone. */ 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.", 118 set_driver_phone(driver, IPC_GET_ARG5(call)); 119 120 printf(NAME ": the %s driver was successfully registered as running.\n", 153 121 driver->name); 154 122 … … 174 142 callid = async_get_call(&call); 175 143 if (DEVMAN_ADD_MATCH_ID != IPC_GET_IMETHOD(call)) { 176 log_msg(LVL_ERROR,177 " Invalid protocol when trying to receive match id.");144 printf(NAME ": ERROR: devman_receive_match_id - invalid " 145 "protocol.\n"); 178 146 async_answer_0(callid, EINVAL); 179 147 delete_match_id(match_id); … … 182 150 183 151 if (match_id == NULL) { 184 log_msg(LVL_ERROR, "Failed to allocate match id."); 152 printf(NAME ": ERROR: devman_receive_match_id - failed to " 153 "allocate match id.\n"); 185 154 async_answer_0(callid, ENOMEM); 186 155 return ENOMEM; … … 196 165 if (rc != EOK) { 197 166 delete_match_id(match_id); 198 log_msg(LVL_ERROR, "Failed to receive match id string: %s.",199 str_error(rc));167 printf(NAME ": devman_receive_match_id - failed to receive " 168 "match id string.\n"); 200 169 return rc; 201 170 } … … 203 172 list_append(&match_id->link, &match_ids->ids); 204 173 205 log_msg(LVL_DEBUG, "Received match id `%s', score %d.",174 printf(NAME ": received match id '%s', score = %d \n", 206 175 match_id->id, match_id->score); 207 176 return rc; … … 259 228 if (ftype != fun_inner && ftype != fun_exposed) { 260 229 /* Unknown function type */ 261 log_msg(LVL_ERROR, 262 "Unknown function type %d provided by driver.", 263 (int) ftype); 230 printf(NAME ": Error, unknown function type provided by driver!\n"); 264 231 265 232 fibril_rwlock_write_unlock(&tree->rwlock); … … 276 243 } 277 244 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 288 245 fun_node_t *fun = create_fun_node(); 289 246 if (!insert_fun_node(&device_tree, fun, fun_name, pdev)) { … … 308 265 fibril_rwlock_write_unlock(&tree->rwlock); 309 266 310 log_msg(LVL_DEBUG, "devman_add_function(fun=\"%s\")", fun->pathname);267 printf(NAME ": devman_add_function %s\n", fun->pathname); 311 268 312 269 devman_receive_match_ids(match_count, &fun->match_ids); … … 390 347 devmap_register_class_dev(class_info); 391 348 392 log_msg(LVL_NOTE, "Function `%s' added to class `%s' as `%s'.",393 fun->pathname, class_name, class_info->dev_name);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); 394 351 395 352 async_answer_0(callid, EOK); … … 406 363 407 364 initialize_running_driver(driver, &device_tree); 408 log_msg(LVL_DEBUG, "The `%s` driver was successfully initialized.",365 printf(NAME ": the %s driver was successfully initialized. \n", 409 366 driver->name); 410 367 return 0; … … 428 385 fid_t fid = fibril_create(init_running_drv, driver); 429 386 if (fid == 0) { 430 log_msg(LVL_ERROR, "Failed to create initialization fibril " \431 " for driver `%s'.", driver->name);387 printf(NAME ": Error creating fibril for the initialization of " 388 "the newly registered running driver.\n"); 432 389 return; 433 390 } … … 481 438 } 482 439 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 517 440 518 441 /** Function for handling connections from a client to the device manager. */ … … 534 457 devman_function_get_handle(callid, &call); 535 458 break; 536 case DEVMAN_DEVICE_GET_HANDLE_BY_CLASS:537 devman_function_get_handle_by_class(callid, &call);538 break;539 459 default: 540 460 async_answer_0(callid, ENOENT); … … 557 477 dev = fun->dev; 558 478 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); 479 if (fun == NULL && dev == NULL) { 480 printf(NAME ": devman_forward error - no device or function with " 481 "handle %" PRIun " was found.\n", handle); 568 482 async_answer_0(iid, ENOENT); 569 483 return; … … 571 485 572 486 if (fun == NULL && !drv_to_parent) { 573 log_msg(LVL_ERROR, NAME ": devman_forward error - cannot " 574 "connect to handle %" PRIun ", refers to a device.", 575 handle); 487 printf(NAME ": devman_forward error - cannot connect to " 488 "handle %" PRIun ", refers to a device.\n", handle); 576 489 async_answer_0(iid, ENOENT); 577 490 return; … … 594 507 595 508 if (driver == NULL) { 596 log_msg(LVL_ERROR, "IPC forwarding refused - " \597 " the device %" PRIun " is not in usable state.", handle);509 printf(NAME ": devman_forward error - the device is not in %" PRIun 510 " usable state.\n", handle); 598 511 async_answer_0(iid, ENOENT); 599 512 return; … … 606 519 method = DRIVER_CLIENT; 607 520 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);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); 612 525 async_answer_0(iid, EINVAL); 613 526 return; … … 615 528 616 529 if (fun != NULL) { 617 log_msg(LVL_DEBUG, 618 "Forwarding request for `%s' function to driver `%s'.", 619 fun->pathname, driver->name); 530 printf(NAME ": devman_forward: forward connection to function %s to " 531 "driver %s.\n", fun->pathname, driver->name); 620 532 } else { 621 log_msg(LVL_DEBUG, 622 "Forwarding request for `%s' device to driver `%s'.", 623 dev->pfun->pathname, driver->name); 533 printf(NAME ": devman_forward: forward connection to device %s to " 534 "driver %s.\n", dev->pfun->pathname, driver->name); 624 535 } 625 536 … … 646 557 dev = fun->dev; 647 558 648 if (dev->state != DEVICE_USABLE || dev->drv->phone < 0) {559 if (dev->state != DEVICE_USABLE || dev->drv->phone <= 0) { 649 560 async_answer_0(iid, EINVAL); 650 561 return; … … 653 564 async_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, fun->handle, 0, 654 565 IPC_FF_NONE); 655 log_msg(LVL_DEBUG, 656 "Forwarding devmapper request for `%s' function to driver `%s'.", 657 fun->pathname, dev->drv->name); 566 printf(NAME ": devman_connection_devmapper: forwarded connection to " 567 "device %s to driver %s.\n", fun->pathname, dev->drv->name); 658 568 } 659 569 … … 690 600 static bool devman_init(void) 691 601 { 692 log_msg(LVL_DEBUG, "devman_init - looking for available drivers.");602 printf(NAME ": devman_init - looking for available drivers.\n"); 693 603 694 604 /* Initialize list of available drivers. */ … … 696 606 if (lookup_available_drivers(&drivers_list, 697 607 DRIVER_DEFAULT_STORE) == 0) { 698 log_msg(LVL_FATAL, "No drivers found.");608 printf(NAME " no drivers found."); 699 609 return false; 700 610 } 701 611 702 log_msg(LVL_DEBUG, "devman_init - list of drivers has been initialized.");612 printf(NAME ": devman_init - list of drivers has been initialized.\n"); 703 613 704 614 /* Create root device node. */ 705 615 if (!init_device_tree(&device_tree, &drivers_list)) { 706 log_msg(LVL_FATAL, "Failed to initialize device tree.");616 printf(NAME " failed to initialize device tree."); 707 617 return false; 708 618 } … … 725 635 printf(NAME ": HelenOS Device Manager\n"); 726 636 727 if (log_init(NAME, LVL_ERROR) != EOK) {728 printf(NAME ": Error initializing logging subsystem.\n");729 return -1;730 }731 732 637 if (!devman_init()) { 733 log_msg(LVL_ERROR, "Error while initializing service.");638 printf(NAME ": Error while initializing service\n"); 734 639 return -1; 735 640 } … … 739 644 740 645 /* Register device manager at naming service. */ 741 if (service_register(SERVICE_DEVMAN) != EOK) { 742 log_msg(LVL_ERROR, "Failed registering as a service."); 646 if (service_register(SERVICE_DEVMAN) != EOK) 743 647 return -1; 744 } 745 746 printf(NAME ": Accepting connections.\n"); 648 649 printf(NAME ": Accepting connections\n"); 747 650 async_manager(); 748 651
Note:
See TracChangeset
for help on using the changeset viewer.