Changes in uspace/srv/devman/main.c [a1a101d:3f57fb7] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/main.c
ra1a101d r3f57fb7 73 73 char *drv_name = NULL; 74 74 75 log_msg(L OG_DEFAULT, LVL_DEBUG, "devman_driver_register");75 log_msg(LVL_DEBUG, "devman_driver_register"); 76 76 77 77 /* Get driver name. */ … … 82 82 } 83 83 84 log_msg(L OG_DEFAULT, LVL_DEBUG, "The `%s' driver is trying to register.",84 log_msg(LVL_DEBUG, "The `%s' driver is trying to register.", 85 85 drv_name); 86 86 … … 88 88 driver = find_driver(&drivers_list, drv_name); 89 89 if (driver == NULL) { 90 log_msg(L OG_DEFAULT, LVL_ERROR, "No driver named `%s' was found.", drv_name);90 log_msg(LVL_ERROR, "No driver named `%s' was found.", drv_name); 91 91 free(drv_name); 92 92 drv_name = NULL; … … 102 102 if (driver->sess) { 103 103 /* We already have a connection to the driver. */ 104 log_msg(L OG_DEFAULT, LVL_ERROR, "Driver '%s' already started.\n",104 log_msg(LVL_ERROR, "Driver '%s' already started.\n", 105 105 driver->name); 106 106 fibril_mutex_unlock(&driver->driver_mutex); … … 112 112 case DRIVER_NOT_STARTED: 113 113 /* Somebody started the driver manually. */ 114 log_msg(L OG_DEFAULT, LVL_NOTE, "Driver '%s' started manually.\n",114 log_msg(LVL_NOTE, "Driver '%s' started manually.\n", 115 115 driver->name); 116 116 driver->state = DRIVER_STARTING; … … 125 125 126 126 /* Create connection to the driver. */ 127 log_msg(L OG_DEFAULT, LVL_DEBUG, "Creating connection to the `%s' driver.",127 log_msg(LVL_DEBUG, "Creating connection to the `%s' driver.", 128 128 driver->name); 129 129 driver->sess = async_callback_receive(EXCHANGE_PARALLEL); … … 136 136 async_sess_args_set(driver->sess, DRIVER_DEVMAN, 0, 0); 137 137 138 log_msg(L OG_DEFAULT, LVL_NOTE,138 log_msg(LVL_NOTE, 139 139 "The `%s' driver was successfully registered as running.", 140 140 driver->name); … … 147 147 fid_t fid = fibril_create(init_running_drv, driver); 148 148 if (fid == 0) { 149 log_msg(L OG_DEFAULT, LVL_ERROR, "Failed to create initialization fibril " \149 log_msg(LVL_ERROR, "Failed to create initialization fibril " \ 150 150 "for driver `%s'.", driver->name); 151 151 fibril_mutex_unlock(&driver->driver_mutex); … … 176 176 callid = async_get_call(&call); 177 177 if (DEVMAN_ADD_MATCH_ID != IPC_GET_IMETHOD(call)) { 178 log_msg(L OG_DEFAULT, LVL_ERROR,178 log_msg(LVL_ERROR, 179 179 "Invalid protocol when trying to receive match id."); 180 180 async_answer_0(callid, EINVAL); … … 184 184 185 185 if (match_id == NULL) { 186 log_msg(L OG_DEFAULT, LVL_ERROR, "Failed to allocate match id.");186 log_msg(LVL_ERROR, "Failed to allocate match id."); 187 187 async_answer_0(callid, ENOMEM); 188 188 return ENOMEM; … … 198 198 if (rc != EOK) { 199 199 delete_match_id(match_id); 200 log_msg(L OG_DEFAULT, LVL_ERROR, "Failed to receive match id string: %s.",200 log_msg(LVL_ERROR, "Failed to receive match id string: %s.", 201 201 str_error(rc)); 202 202 return rc; … … 205 205 list_append(&match_id->link, &match_ids->ids); 206 206 207 log_msg(L OG_DEFAULT, LVL_DEBUG, "Received match id `%s', score %d.",207 log_msg(LVL_DEBUG, "Received match id `%s', score %d.", 208 208 match_id->id, match_id->score); 209 209 return rc; … … 248 248 if (fun->state == FUN_ON_LINE) { 249 249 fibril_rwlock_write_unlock(&device_tree.rwlock); 250 log_msg(L OG_DEFAULT, LVL_WARN, "Function %s is already on line.",250 log_msg(LVL_WARN, "Function %s is already on line.", 251 251 fun->pathname); 252 252 return EOK; … … 264 264 } 265 265 266 log_msg(L OG_DEFAULT, LVL_DEBUG, "devman_add_function(fun=\"%s\")", fun->pathname);266 log_msg(LVL_DEBUG, "devman_add_function(fun=\"%s\")", fun->pathname); 267 267 268 268 if (fun->ftype == fun_inner) { … … 282 282 fid_t assign_fibril = fibril_create(assign_driver_fibril, dev); 283 283 if (assign_fibril == 0) { 284 log_msg(L OG_DEFAULT, LVL_ERROR, "Failed to create fibril for "284 log_msg(LVL_ERROR, "Failed to create fibril for " 285 285 "assigning driver."); 286 286 /* XXX Cleanup */ … … 305 305 if (fun->state == FUN_OFF_LINE) { 306 306 fibril_rwlock_write_unlock(&device_tree.rwlock); 307 log_msg(L OG_DEFAULT, LVL_WARN, "Function %s is already off line.",307 log_msg(LVL_WARN, "Function %s is already off line.", 308 308 fun->pathname); 309 309 return EOK; … … 311 311 312 312 if (fun->ftype == fun_inner) { 313 log_msg(L OG_DEFAULT, LVL_DEBUG, "Offlining inner function %s.",313 log_msg(LVL_DEBUG, "Offlining inner function %s.", 314 314 fun->pathname); 315 315 … … 359 359 if (rc != EOK) { 360 360 fibril_rwlock_write_unlock(&device_tree.rwlock); 361 log_msg(L OG_DEFAULT, LVL_ERROR, "Failed unregistering tree service.");361 log_msg(LVL_ERROR, "Failed unregistering tree service."); 362 362 return EIO; 363 363 } … … 391 391 if (ftype != fun_inner && ftype != fun_exposed) { 392 392 /* Unknown function type */ 393 log_msg(L OG_DEFAULT, LVL_ERROR,393 log_msg(LVL_ERROR, 394 394 "Unknown function type %d provided by driver.", 395 395 (int) ftype); … … 419 419 420 420 /* Check that function with same name is not there already. */ 421 fun_node_t *tfun = find_fun_node_in_device(tree, pdev, fun_name); 422 if (tfun) { 423 fun_del_ref(tfun); /* drop the new unwanted reference */ 421 if (find_fun_node_in_device(tree, pdev, fun_name) != NULL) { 424 422 fibril_rwlock_write_unlock(&tree->rwlock); 425 423 dev_del_ref(pdev); … … 432 430 433 431 fun_node_t *fun = create_fun_node(); 434 /* One reference for creation, one for us */435 fun_add_ref(fun);436 432 fun_add_ref(fun); 437 433 fun->ftype = ftype; 438 439 /*440 * We can lock the function here even when holding the tree because441 * we know it cannot be held by anyone else yet.442 */443 fun_busy_lock(fun);444 434 445 435 if (!insert_fun_node(&device_tree, fun, fun_name, pdev)) { 446 436 fibril_rwlock_write_unlock(&tree->rwlock); 447 437 dev_del_ref(pdev); 448 fun_busy_unlock(fun);449 fun_del_ref(fun);450 438 delete_fun_node(fun); 451 439 async_answer_0(callid, ENOMEM); … … 460 448 rc = online_function(fun); 461 449 if (rc != EOK) { 462 /* XXX Set some failed state? */ 463 fun_busy_unlock(fun); 464 fun_del_ref(fun); 450 /* XXX clean up */ 465 451 async_answer_0(callid, rc); 466 452 return; 467 453 } 468 469 fun_busy_unlock(fun);470 fun_del_ref(fun);471 454 472 455 /* Return device handle to parent's driver. */ … … 507 490 if (rc == EOK) { 508 491 loc_service_add_to_cat(fun->service_id, cat_id); 509 log_msg(L OG_DEFAULT, LVL_NOTE, "Function `%s' added to category `%s'.",492 log_msg(LVL_NOTE, "Function `%s' added to category `%s'.", 510 493 fun->pathname, cat_name); 511 494 } else { 512 log_msg(L OG_DEFAULT, LVL_ERROR, "Failed adding function `%s' to category "495 log_msg(LVL_ERROR, "Failed adding function `%s' to category " 513 496 "`%s'.", fun->pathname, cat_name); 514 497 } … … 529 512 int rc; 530 513 531 log_msg(L OG_DEFAULT, LVL_DEBUG, "devman_drv_fun_online()");514 log_msg(LVL_DEBUG, "devman_drv_fun_online()"); 532 515 533 516 fun = find_fun_node(&device_tree, IPC_GET_ARG1(*icall)); … … 536 519 return; 537 520 } 538 539 fun_busy_lock(fun);540 521 541 522 fibril_rwlock_read_lock(&device_tree.rwlock); 542 523 if (fun->dev == NULL || fun->dev->drv != drv) { 543 524 fibril_rwlock_read_unlock(&device_tree.rwlock); 544 fun_busy_unlock(fun);545 525 fun_del_ref(fun); 546 526 async_answer_0(iid, ENOENT); … … 551 531 rc = online_function(fun); 552 532 if (rc != EOK) { 553 fun_busy_unlock(fun);554 533 fun_del_ref(fun); 555 534 async_answer_0(iid, (sysarg_t) rc); … … 557 536 } 558 537 559 fun_busy_unlock(fun);560 538 fun_del_ref(fun); 561 539 … … 579 557 } 580 558 581 fun_busy_lock(fun);582 583 559 fibril_rwlock_write_lock(&device_tree.rwlock); 584 560 if (fun->dev == NULL || fun->dev->drv != drv) { 585 fun_busy_unlock(fun);586 561 fun_del_ref(fun); 587 562 async_answer_0(iid, ENOENT); … … 592 567 rc = offline_function(fun); 593 568 if (rc != EOK) { 594 fun_busy_unlock(fun);595 569 fun_del_ref(fun); 596 570 async_answer_0(iid, (sysarg_t) rc); … … 598 572 } 599 573 600 fun_busy_unlock(fun);601 574 fun_del_ref(fun); 602 575 async_answer_0(iid, (sysarg_t) EOK); … … 616 589 } 617 590 618 fun_busy_lock(fun);619 620 591 fibril_rwlock_write_lock(&tree->rwlock); 621 592 622 log_msg(L OG_DEFAULT, LVL_DEBUG, "devman_remove_function(fun='%s')", fun->pathname);593 log_msg(LVL_DEBUG, "devman_remove_function(fun='%s')", fun->pathname); 623 594 624 595 /* Check function state */ 625 596 if (fun->state == FUN_REMOVED) { 626 597 fibril_rwlock_write_unlock(&tree->rwlock); 627 fun_busy_unlock(fun);628 fun_del_ref(fun);629 598 async_answer_0(callid, ENOENT); 630 599 return; … … 653 622 /* Verify that driver succeeded and removed all functions */ 654 623 if (gone_rc != EOK || !list_empty(&dev->functions)) { 655 log_msg(L OG_DEFAULT, LVL_ERROR, "Driver did not remove "624 log_msg(LVL_ERROR, "Driver did not remove " 656 625 "functions for device that is gone. " 657 626 "Device node is now defunct."); … … 667 636 if (gone_rc == EOK) 668 637 gone_rc = ENOTSUP; 669 fun_busy_unlock(fun);670 fun_del_ref(fun);671 638 async_answer_0(callid, gone_rc); 672 639 return; … … 692 659 rc = loc_service_unregister(fun->service_id); 693 660 if (rc != EOK) { 694 log_msg(L OG_DEFAULT, LVL_ERROR, "Failed unregistering tree "661 log_msg(LVL_ERROR, "Failed unregistering tree " 695 662 "service."); 696 663 fibril_rwlock_write_unlock(&tree->rwlock); 697 fun_busy_unlock(fun);698 664 fun_del_ref(fun); 699 665 async_answer_0(callid, EIO); … … 705 671 remove_fun_node(&device_tree, fun); 706 672 fibril_rwlock_write_unlock(&tree->rwlock); 707 fun_busy_unlock(fun);708 673 709 674 /* Delete ref added when inserting function into tree */ … … 712 677 fun_del_ref(fun); 713 678 714 log_msg(L OG_DEFAULT, LVL_DEBUG, "devman_remove_function() succeeded.");679 log_msg(LVL_DEBUG, "devman_remove_function() succeeded."); 715 680 async_answer_0(callid, EOK); 716 681 } … … 726 691 727 692 initialize_running_driver(driver, &device_tree); 728 log_msg(L OG_DEFAULT, LVL_DEBUG, "The `%s` driver was successfully initialized.",693 log_msg(LVL_DEBUG, "The `%s` driver was successfully initialized.", 729 694 driver->name); 730 695 return 0; … … 742 707 client = async_get_client_data(); 743 708 if (client == NULL) { 744 log_msg(L OG_DEFAULT, LVL_ERROR, "Failed to allocate client data.");709 log_msg(LVL_ERROR, "Failed to allocate client data."); 745 710 return; 746 711 } … … 1229 1194 */ 1230 1195 if (dev == NULL) { 1231 log_msg(L OG_DEFAULT, LVL_ERROR, "IPC forwarding failed - no device or "1196 log_msg(LVL_ERROR, "IPC forwarding failed - no device or " 1232 1197 "function with handle %" PRIun " was found.", handle); 1233 1198 async_answer_0(iid, ENOENT); … … 1236 1201 1237 1202 if (fun == NULL && !drv_to_parent) { 1238 log_msg(L OG_DEFAULT, LVL_ERROR, NAME ": devman_forward error - cannot "1203 log_msg(LVL_ERROR, NAME ": devman_forward error - cannot " 1239 1204 "connect to handle %" PRIun ", refers to a device.", 1240 1205 handle); … … 1264 1229 1265 1230 if (driver == NULL) { 1266 log_msg(L OG_DEFAULT, LVL_ERROR, "IPC forwarding refused - " \1231 log_msg(LVL_ERROR, "IPC forwarding refused - " \ 1267 1232 "the device %" PRIun " is not in usable state.", handle); 1268 1233 async_answer_0(iid, ENOENT); … … 1277 1242 1278 1243 if (!driver->sess) { 1279 log_msg(L OG_DEFAULT, LVL_ERROR,1244 log_msg(LVL_ERROR, 1280 1245 "Could not forward to driver `%s'.", driver->name); 1281 1246 async_answer_0(iid, EINVAL); … … 1284 1249 1285 1250 if (fun != NULL) { 1286 log_msg(L OG_DEFAULT, LVL_DEBUG,1251 log_msg(LVL_DEBUG, 1287 1252 "Forwarding request for `%s' function to driver `%s'.", 1288 1253 fun->pathname, driver->name); 1289 1254 } else { 1290 log_msg(L OG_DEFAULT, LVL_DEBUG,1255 log_msg(LVL_DEBUG, 1291 1256 "Forwarding request for `%s' device to driver `%s'.", 1292 1257 dev->pfun->pathname, driver->name); … … 1320 1285 1321 1286 if (fun == NULL || fun->dev == NULL || fun->dev->drv == NULL) { 1322 log_msg(L OG_DEFAULT, LVL_WARN, "devman_connection_loc(): function "1287 log_msg(LVL_WARN, "devman_connection_loc(): function " 1323 1288 "not found.\n"); 1324 1289 fibril_rwlock_read_unlock(&device_tree.rwlock); … … 1338 1303 async_exchange_end(exch); 1339 1304 1340 log_msg(L OG_DEFAULT, LVL_DEBUG,1305 log_msg(LVL_DEBUG, 1341 1306 "Forwarding loc service request for `%s' function to driver `%s'.", 1342 1307 fun->pathname, driver->name); … … 1394 1359 static bool devman_init(void) 1395 1360 { 1396 log_msg(L OG_DEFAULT, LVL_DEBUG, "devman_init - looking for available drivers.");1361 log_msg(LVL_DEBUG, "devman_init - looking for available drivers."); 1397 1362 1398 1363 /* Initialize list of available drivers. */ … … 1400 1365 if (lookup_available_drivers(&drivers_list, 1401 1366 DRIVER_DEFAULT_STORE) == 0) { 1402 log_msg(L OG_DEFAULT, LVL_FATAL, "No drivers found.");1367 log_msg(LVL_FATAL, "No drivers found."); 1403 1368 return false; 1404 1369 } 1405 1370 1406 log_msg(L OG_DEFAULT, LVL_DEBUG, "devman_init - list of drivers has been initialized.");1371 log_msg(LVL_DEBUG, "devman_init - list of drivers has been initialized."); 1407 1372 1408 1373 /* Create root device node. */ 1409 1374 if (!init_device_tree(&device_tree, &drivers_list)) { 1410 log_msg(L OG_DEFAULT, LVL_FATAL, "Failed to initialize device tree.");1375 log_msg(LVL_FATAL, "Failed to initialize device tree."); 1411 1376 return false; 1412 1377 } … … 1428 1393 printf("%s: HelenOS Device Manager\n", NAME); 1429 1394 1430 int rc = log_init(NAME );1395 int rc = log_init(NAME, LVL_WARN); 1431 1396 if (rc != EOK) { 1432 1397 printf("%s: Error initializing logging subsystem.\n", NAME); … … 1440 1405 1441 1406 if (!devman_init()) { 1442 log_msg(L OG_DEFAULT, LVL_ERROR, "Error while initializing service.");1407 log_msg(LVL_ERROR, "Error while initializing service."); 1443 1408 return -1; 1444 1409 } … … 1447 1412 rc = service_register(SERVICE_DEVMAN); 1448 1413 if (rc != EOK) { 1449 log_msg(L OG_DEFAULT, LVL_ERROR, "Failed registering as a service.");1414 log_msg(LVL_ERROR, "Failed registering as a service."); 1450 1415 return rc; 1451 1416 }
Note:
See TracChangeset
for help on using the changeset viewer.