Changes in uspace/srv/devman/main.c [33fc3ae:3e6a98c5] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/main.c
r33fc3ae r3e6a98c5 44 44 #include <errno.h> 45 45 #include <str_error.h> 46 #include < bool.h>46 #include <stdbool.h> 47 47 #include <fibril_synch.h> 48 48 #include <stdlib.h> … … 73 73 char *drv_name = NULL; 74 74 75 log_msg(L VL_DEBUG, "devman_driver_register");75 log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_driver_register"); 76 76 77 77 /* Get driver name. */ … … 82 82 } 83 83 84 log_msg(L VL_DEBUG, "The `%s' driver is trying to register.",84 log_msg(LOG_DEFAULT, 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 VL_ERROR, "No driver named `%s' was found.", drv_name);90 log_msg(LOG_DEFAULT, 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 VL_ERROR, "Driver '%s' already started.\n",104 log_msg(LOG_DEFAULT, 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 VL_NOTE, "Driver '%s' started manually.\n",114 log_msg(LOG_DEFAULT, 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 VL_DEBUG, "Creating connection to the `%s' driver.",127 log_msg(LOG_DEFAULT, 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 VL_NOTE,138 log_msg(LOG_DEFAULT, 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 VL_ERROR, "Failed to create initialization fibril " \149 log_msg(LOG_DEFAULT, 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 VL_ERROR,178 log_msg(LOG_DEFAULT, 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 VL_ERROR, "Failed to allocate match id.");186 log_msg(LOG_DEFAULT, 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 VL_ERROR, "Failed to receive match id string: %s.",200 log_msg(LOG_DEFAULT, 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 VL_DEBUG, "Received match id `%s', score %d.",207 log_msg(LOG_DEFAULT, 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 VL_WARN, "Function %s is already on line.",250 log_msg(LOG_DEFAULT, LVL_WARN, "Function %s is already on line.", 251 251 fun->pathname); 252 252 return EOK; … … 264 264 } 265 265 266 log_msg(L VL_DEBUG, "devman_add_function(fun=\"%s\")", fun->pathname);266 log_msg(LOG_DEFAULT, 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 VL_ERROR, "Failed to create fibril for "284 log_msg(LOG_DEFAULT, 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 VL_WARN, "Function %s is already off line.",307 log_msg(LOG_DEFAULT, 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 VL_DEBUG, "Offlining inner function %s.",313 log_msg(LOG_DEFAULT, 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 VL_ERROR, "Failed unregistering tree service.");361 log_msg(LOG_DEFAULT, 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 VL_ERROR,393 log_msg(LOG_DEFAULT, LVL_ERROR, 394 394 "Unknown function type %d provided by driver.", 395 395 (int) ftype); … … 432 432 433 433 fun_node_t *fun = create_fun_node(); 434 /* One reference for creation, one for us */ 435 fun_add_ref(fun); 434 436 fun_add_ref(fun); 435 437 fun->ftype = ftype; 438 439 /* 440 * We can lock the function here even when holding the tree because 441 * we know it cannot be held by anyone else yet. 442 */ 443 fun_busy_lock(fun); 436 444 437 445 if (!insert_fun_node(&device_tree, fun, fun_name, pdev)) { 438 446 fibril_rwlock_write_unlock(&tree->rwlock); 439 447 dev_del_ref(pdev); 448 fun_busy_unlock(fun); 449 fun_del_ref(fun); 440 450 delete_fun_node(fun); 441 451 async_answer_0(callid, ENOMEM); … … 450 460 rc = online_function(fun); 451 461 if (rc != EOK) { 452 /* XXX clean up */ 462 /* XXX Set some failed state? */ 463 fun_busy_unlock(fun); 464 fun_del_ref(fun); 453 465 async_answer_0(callid, rc); 454 466 return; 455 467 } 468 469 fun_busy_unlock(fun); 470 fun_del_ref(fun); 456 471 457 472 /* Return device handle to parent's driver. */ … … 492 507 if (rc == EOK) { 493 508 loc_service_add_to_cat(fun->service_id, cat_id); 494 log_msg(L VL_NOTE, "Function `%s' added to category `%s'.",509 log_msg(LOG_DEFAULT, LVL_NOTE, "Function `%s' added to category `%s'.", 495 510 fun->pathname, cat_name); 496 511 } else { 497 log_msg(L VL_ERROR, "Failed adding function `%s' to category "512 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed adding function `%s' to category " 498 513 "`%s'.", fun->pathname, cat_name); 499 514 } … … 514 529 int rc; 515 530 516 log_msg(L VL_DEBUG, "devman_drv_fun_online()");531 log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_drv_fun_online()"); 517 532 518 533 fun = find_fun_node(&device_tree, IPC_GET_ARG1(*icall)); … … 521 536 return; 522 537 } 538 539 fun_busy_lock(fun); 523 540 524 541 fibril_rwlock_read_lock(&device_tree.rwlock); 525 542 if (fun->dev == NULL || fun->dev->drv != drv) { 526 543 fibril_rwlock_read_unlock(&device_tree.rwlock); 544 fun_busy_unlock(fun); 527 545 fun_del_ref(fun); 528 546 async_answer_0(iid, ENOENT); … … 533 551 rc = online_function(fun); 534 552 if (rc != EOK) { 553 fun_busy_unlock(fun); 535 554 fun_del_ref(fun); 536 555 async_answer_0(iid, (sysarg_t) rc); … … 538 557 } 539 558 559 fun_busy_unlock(fun); 540 560 fun_del_ref(fun); 541 561 … … 559 579 } 560 580 581 fun_busy_lock(fun); 582 561 583 fibril_rwlock_write_lock(&device_tree.rwlock); 562 584 if (fun->dev == NULL || fun->dev->drv != drv) { 585 fun_busy_unlock(fun); 563 586 fun_del_ref(fun); 564 587 async_answer_0(iid, ENOENT); … … 569 592 rc = offline_function(fun); 570 593 if (rc != EOK) { 594 fun_busy_unlock(fun); 571 595 fun_del_ref(fun); 572 596 async_answer_0(iid, (sysarg_t) rc); … … 574 598 } 575 599 600 fun_busy_unlock(fun); 576 601 fun_del_ref(fun); 577 602 async_answer_0(iid, (sysarg_t) EOK); … … 591 616 } 592 617 618 fun_busy_lock(fun); 619 593 620 fibril_rwlock_write_lock(&tree->rwlock); 594 621 595 log_msg(L VL_DEBUG, "devman_remove_function(fun='%s')", fun->pathname);622 log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_remove_function(fun='%s')", fun->pathname); 596 623 597 624 /* Check function state */ 598 625 if (fun->state == FUN_REMOVED) { 599 626 fibril_rwlock_write_unlock(&tree->rwlock); 627 fun_busy_unlock(fun); 628 fun_del_ref(fun); 600 629 async_answer_0(callid, ENOENT); 601 630 return; … … 624 653 /* Verify that driver succeeded and removed all functions */ 625 654 if (gone_rc != EOK || !list_empty(&dev->functions)) { 626 log_msg(L VL_ERROR, "Driver did not remove "655 log_msg(LOG_DEFAULT, LVL_ERROR, "Driver did not remove " 627 656 "functions for device that is gone. " 628 657 "Device node is now defunct."); … … 638 667 if (gone_rc == EOK) 639 668 gone_rc = ENOTSUP; 669 fun_busy_unlock(fun); 670 fun_del_ref(fun); 640 671 async_answer_0(callid, gone_rc); 641 672 return; … … 661 692 rc = loc_service_unregister(fun->service_id); 662 693 if (rc != EOK) { 663 log_msg(L VL_ERROR, "Failed unregistering tree "694 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed unregistering tree " 664 695 "service."); 665 696 fibril_rwlock_write_unlock(&tree->rwlock); 697 fun_busy_unlock(fun); 666 698 fun_del_ref(fun); 667 699 async_answer_0(callid, EIO); … … 673 705 remove_fun_node(&device_tree, fun); 674 706 fibril_rwlock_write_unlock(&tree->rwlock); 707 fun_busy_unlock(fun); 675 708 676 709 /* Delete ref added when inserting function into tree */ … … 679 712 fun_del_ref(fun); 680 713 681 log_msg(L VL_DEBUG, "devman_remove_function() succeeded.");714 log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_remove_function() succeeded."); 682 715 async_answer_0(callid, EOK); 683 716 } … … 693 726 694 727 initialize_running_driver(driver, &device_tree); 695 log_msg(L VL_DEBUG, "The `%s` driver was successfully initialized.",728 log_msg(LOG_DEFAULT, LVL_DEBUG, "The `%s` driver was successfully initialized.", 696 729 driver->name); 697 730 return 0; … … 709 742 client = async_get_client_data(); 710 743 if (client == NULL) { 711 log_msg(L VL_ERROR, "Failed to allocate client data.");744 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed to allocate client data."); 712 745 return; 713 746 } … … 1196 1229 */ 1197 1230 if (dev == NULL) { 1198 log_msg(L VL_ERROR, "IPC forwarding failed - no device or "1231 log_msg(LOG_DEFAULT, LVL_ERROR, "IPC forwarding failed - no device or " 1199 1232 "function with handle %" PRIun " was found.", handle); 1200 1233 async_answer_0(iid, ENOENT); … … 1203 1236 1204 1237 if (fun == NULL && !drv_to_parent) { 1205 log_msg(L VL_ERROR, NAME ": devman_forward error - cannot "1238 log_msg(LOG_DEFAULT, LVL_ERROR, NAME ": devman_forward error - cannot " 1206 1239 "connect to handle %" PRIun ", refers to a device.", 1207 1240 handle); … … 1231 1264 1232 1265 if (driver == NULL) { 1233 log_msg(L VL_ERROR, "IPC forwarding refused - " \1266 log_msg(LOG_DEFAULT, LVL_ERROR, "IPC forwarding refused - " \ 1234 1267 "the device %" PRIun " is not in usable state.", handle); 1235 1268 async_answer_0(iid, ENOENT); … … 1244 1277 1245 1278 if (!driver->sess) { 1246 log_msg(L VL_ERROR,1279 log_msg(LOG_DEFAULT, LVL_ERROR, 1247 1280 "Could not forward to driver `%s'.", driver->name); 1248 1281 async_answer_0(iid, EINVAL); … … 1251 1284 1252 1285 if (fun != NULL) { 1253 log_msg(L VL_DEBUG,1286 log_msg(LOG_DEFAULT, LVL_DEBUG, 1254 1287 "Forwarding request for `%s' function to driver `%s'.", 1255 1288 fun->pathname, driver->name); 1256 1289 } else { 1257 log_msg(L VL_DEBUG,1290 log_msg(LOG_DEFAULT, LVL_DEBUG, 1258 1291 "Forwarding request for `%s' device to driver `%s'.", 1259 1292 dev->pfun->pathname, driver->name); … … 1287 1320 1288 1321 if (fun == NULL || fun->dev == NULL || fun->dev->drv == NULL) { 1289 log_msg(L VL_WARN, "devman_connection_loc(): function "1322 log_msg(LOG_DEFAULT, LVL_WARN, "devman_connection_loc(): function " 1290 1323 "not found.\n"); 1291 1324 fibril_rwlock_read_unlock(&device_tree.rwlock); … … 1305 1338 async_exchange_end(exch); 1306 1339 1307 log_msg(L VL_DEBUG,1340 log_msg(LOG_DEFAULT, LVL_DEBUG, 1308 1341 "Forwarding loc service request for `%s' function to driver `%s'.", 1309 1342 fun->pathname, driver->name); … … 1361 1394 static bool devman_init(void) 1362 1395 { 1363 log_msg(L VL_DEBUG, "devman_init - looking for available drivers.");1396 log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_init - looking for available drivers."); 1364 1397 1365 1398 /* Initialize list of available drivers. */ … … 1367 1400 if (lookup_available_drivers(&drivers_list, 1368 1401 DRIVER_DEFAULT_STORE) == 0) { 1369 log_msg(L VL_FATAL, "No drivers found.");1402 log_msg(LOG_DEFAULT, LVL_FATAL, "No drivers found."); 1370 1403 return false; 1371 1404 } 1372 1405 1373 log_msg(L VL_DEBUG, "devman_init - list of drivers has been initialized.");1406 log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_init - list of drivers has been initialized."); 1374 1407 1375 1408 /* Create root device node. */ 1376 1409 if (!init_device_tree(&device_tree, &drivers_list)) { 1377 log_msg(L VL_FATAL, "Failed to initialize device tree.");1410 log_msg(LOG_DEFAULT, LVL_FATAL, "Failed to initialize device tree."); 1378 1411 return false; 1379 1412 } … … 1395 1428 printf("%s: HelenOS Device Manager\n", NAME); 1396 1429 1397 int rc = log_init(NAME , LVL_WARN);1430 int rc = log_init(NAME); 1398 1431 if (rc != EOK) { 1399 1432 printf("%s: Error initializing logging subsystem.\n", NAME); … … 1407 1440 1408 1441 if (!devman_init()) { 1409 log_msg(L VL_ERROR, "Error while initializing service.");1442 log_msg(LOG_DEFAULT, LVL_ERROR, "Error while initializing service."); 1410 1443 return -1; 1411 1444 } … … 1414 1447 rc = service_register(SERVICE_DEVMAN); 1415 1448 if (rc != EOK) { 1416 log_msg(L VL_ERROR, "Failed registering as a service.");1449 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering as a service."); 1417 1450 return rc; 1418 1451 }
Note:
See TracChangeset
for help on using the changeset viewer.