Changes in uspace/srv/devman/main.c [f302586:c4f7bf6] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/main.c
rf302586 rc4f7bf6 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; … … 245 245 246 246 fibril_rwlock_write_lock(&device_tree.rwlock); 247 247 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; … … 259 259 return ENOMEM; 260 260 } 261 261 262 262 insert_dev_node(&device_tree, dev, fun); 263 263 dev_add_ref(dev); 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) { … … 272 272 /* Give one reference over to assign_driver_fibril(). */ 273 273 dev_add_ref(dev); 274 274 275 /* 275 276 * Try to find a suitable driver and assign it to the device. We do … … 281 282 fid_t assign_fibril = fibril_create(assign_driver_fibril, dev); 282 283 if (assign_fibril == 0) { 283 log_msg(L VL_ERROR, "Failed to create fibril for "284 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed to create fibril for " 284 285 "assigning driver."); 285 286 /* XXX Cleanup */ … … 288 289 } 289 290 fibril_add_ready(assign_fibril); 290 } else {291 } else 291 292 loc_register_tree_function(fun, &device_tree); 292 }293 293 294 294 fibril_rwlock_write_unlock(&device_tree.rwlock); … … 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); … … 419 419 420 420 /* Check that function with same name is not there already. */ 421 if (find_fun_node_in_device(tree, pdev, fun_name) != NULL) { 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 */ 422 424 fibril_rwlock_write_unlock(&tree->rwlock); 423 425 dev_del_ref(pdev); … … 430 432 431 433 fun_node_t *fun = create_fun_node(); 434 /* One reference for creation, one for us */ 435 fun_add_ref(fun); 432 436 fun_add_ref(fun); 433 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); 434 444 435 445 if (!insert_fun_node(&device_tree, fun, fun_name, pdev)) { 436 446 fibril_rwlock_write_unlock(&tree->rwlock); 437 447 dev_del_ref(pdev); 448 fun_busy_unlock(fun); 449 fun_del_ref(fun); 438 450 delete_fun_node(fun); 439 451 async_answer_0(callid, ENOMEM); … … 448 460 rc = online_function(fun); 449 461 if (rc != EOK) { 450 /* XXX clean up */ 462 /* XXX Set some failed state? */ 463 fun_busy_unlock(fun); 464 fun_del_ref(fun); 451 465 async_answer_0(callid, rc); 452 466 return; 453 467 } 468 469 fun_busy_unlock(fun); 470 fun_del_ref(fun); 454 471 455 472 /* Return device handle to parent's driver. */ … … 490 507 if (rc == EOK) { 491 508 loc_service_add_to_cat(fun->service_id, cat_id); 492 log_msg(L VL_NOTE, "Function `%s' added to category `%s'.",509 log_msg(LOG_DEFAULT, LVL_NOTE, "Function `%s' added to category `%s'.", 493 510 fun->pathname, cat_name); 494 511 } else { 495 log_msg(L VL_ERROR, "Failed adding function `%s' to category "512 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed adding function `%s' to category " 496 513 "`%s'.", fun->pathname, cat_name); 497 514 } … … 512 529 int rc; 513 530 514 log_msg(L VL_DEBUG, "devman_drv_fun_online()");531 log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_drv_fun_online()"); 515 532 516 533 fun = find_fun_node(&device_tree, IPC_GET_ARG1(*icall)); … … 519 536 return; 520 537 } 538 539 fun_busy_lock(fun); 521 540 522 541 fibril_rwlock_read_lock(&device_tree.rwlock); 523 542 if (fun->dev == NULL || fun->dev->drv != drv) { 524 543 fibril_rwlock_read_unlock(&device_tree.rwlock); 544 fun_busy_unlock(fun); 525 545 fun_del_ref(fun); 526 546 async_answer_0(iid, ENOENT); … … 531 551 rc = online_function(fun); 532 552 if (rc != EOK) { 553 fun_busy_unlock(fun); 533 554 fun_del_ref(fun); 534 555 async_answer_0(iid, (sysarg_t) rc); … … 536 557 } 537 558 559 fun_busy_unlock(fun); 538 560 fun_del_ref(fun); 539 561 … … 557 579 } 558 580 581 fun_busy_lock(fun); 582 559 583 fibril_rwlock_write_lock(&device_tree.rwlock); 560 584 if (fun->dev == NULL || fun->dev->drv != drv) { 585 fun_busy_unlock(fun); 561 586 fun_del_ref(fun); 562 587 async_answer_0(iid, ENOENT); … … 567 592 rc = offline_function(fun); 568 593 if (rc != EOK) { 594 fun_busy_unlock(fun); 569 595 fun_del_ref(fun); 570 596 async_answer_0(iid, (sysarg_t) rc); … … 572 598 } 573 599 600 fun_busy_unlock(fun); 574 601 fun_del_ref(fun); 575 602 async_answer_0(iid, (sysarg_t) EOK); … … 589 616 } 590 617 618 fun_busy_lock(fun); 619 591 620 fibril_rwlock_write_lock(&tree->rwlock); 592 621 593 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); 594 623 595 624 /* Check function state */ 596 625 if (fun->state == FUN_REMOVED) { 597 626 fibril_rwlock_write_unlock(&tree->rwlock); 627 fun_busy_unlock(fun); 628 fun_del_ref(fun); 598 629 async_answer_0(callid, ENOENT); 599 630 return; … … 622 653 /* Verify that driver succeeded and removed all functions */ 623 654 if (gone_rc != EOK || !list_empty(&dev->functions)) { 624 log_msg(L VL_ERROR, "Driver did not remove "655 log_msg(LOG_DEFAULT, LVL_ERROR, "Driver did not remove " 625 656 "functions for device that is gone. " 626 657 "Device node is now defunct."); … … 636 667 if (gone_rc == EOK) 637 668 gone_rc = ENOTSUP; 669 fun_busy_unlock(fun); 670 fun_del_ref(fun); 638 671 async_answer_0(callid, gone_rc); 639 672 return; … … 659 692 rc = loc_service_unregister(fun->service_id); 660 693 if (rc != EOK) { 661 log_msg(L VL_ERROR, "Failed unregistering tree "694 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed unregistering tree " 662 695 "service."); 663 696 fibril_rwlock_write_unlock(&tree->rwlock); 697 fun_busy_unlock(fun); 664 698 fun_del_ref(fun); 665 699 async_answer_0(callid, EIO); … … 671 705 remove_fun_node(&device_tree, fun); 672 706 fibril_rwlock_write_unlock(&tree->rwlock); 707 fun_busy_unlock(fun); 673 708 674 709 /* Delete ref added when inserting function into tree */ … … 677 712 fun_del_ref(fun); 678 713 679 log_msg(L VL_DEBUG, "devman_remove_function() succeeded.");714 log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_remove_function() succeeded."); 680 715 async_answer_0(callid, EOK); 681 716 } … … 691 726 692 727 initialize_running_driver(driver, &device_tree); 693 log_msg(L VL_DEBUG, "The `%s` driver was successfully initialized.",728 log_msg(LOG_DEFAULT, LVL_DEBUG, "The `%s` driver was successfully initialized.", 694 729 driver->name); 695 730 return 0; … … 700 735 { 701 736 client_t *client; 702 driver_t *driver ;737 driver_t *driver = NULL; 703 738 704 739 /* Accept the connection. */ … … 707 742 client = async_get_client_data(); 708 743 if (client == NULL) { 709 log_msg(L VL_ERROR, "Failed to allocate client data.");744 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed to allocate client data."); 710 745 return; 711 746 } … … 855 890 } 856 891 892 /** Get function driver name. */ 893 static void devman_fun_get_driver_name(ipc_callid_t iid, ipc_call_t *icall) 894 { 895 devman_handle_t handle = IPC_GET_ARG1(*icall); 896 897 fun_node_t *fun = find_fun_node(&device_tree, handle); 898 if (fun == NULL) { 899 async_answer_0(iid, ENOMEM); 900 return; 901 } 902 903 ipc_callid_t data_callid; 904 size_t data_len; 905 if (!async_data_read_receive(&data_callid, &data_len)) { 906 async_answer_0(iid, EINVAL); 907 fun_del_ref(fun); 908 return; 909 } 910 911 void *buffer = malloc(data_len); 912 if (buffer == NULL) { 913 async_answer_0(data_callid, ENOMEM); 914 async_answer_0(iid, ENOMEM); 915 fun_del_ref(fun); 916 return; 917 } 918 919 fibril_rwlock_read_lock(&device_tree.rwlock); 920 921 /* Check function state */ 922 if (fun->state == FUN_REMOVED) { 923 fibril_rwlock_read_unlock(&device_tree.rwlock); 924 free(buffer); 925 926 async_answer_0(data_callid, ENOENT); 927 async_answer_0(iid, ENOENT); 928 fun_del_ref(fun); 929 return; 930 } 931 932 /* Check whether function has a driver */ 933 if (fun->child == NULL || fun->child->drv == NULL) { 934 fibril_rwlock_read_unlock(&device_tree.rwlock); 935 free(buffer); 936 937 async_answer_0(data_callid, EINVAL); 938 async_answer_0(iid, EINVAL); 939 fun_del_ref(fun); 940 return; 941 } 942 943 size_t sent_length = str_size(fun->child->drv->name); 944 if (sent_length > data_len) { 945 sent_length = data_len; 946 } 947 948 async_data_read_finalize(data_callid, fun->child->drv->name, 949 sent_length); 950 async_answer_0(iid, EOK); 951 952 fibril_rwlock_read_unlock(&device_tree.rwlock); 953 fun_del_ref(fun); 954 free(buffer); 955 } 857 956 858 957 /** Get device path. */ … … 1083 1182 devman_fun_get_name(callid, &call); 1084 1183 break; 1184 case DEVMAN_FUN_GET_DRIVER_NAME: 1185 devman_fun_get_driver_name(callid, &call); 1186 break; 1085 1187 case DEVMAN_FUN_GET_PATH: 1086 1188 devman_fun_get_path(callid, &call); … … 1127 1229 */ 1128 1230 if (dev == NULL) { 1129 log_msg(L VL_ERROR, "IPC forwarding failed - no device or "1231 log_msg(LOG_DEFAULT, LVL_ERROR, "IPC forwarding failed - no device or " 1130 1232 "function with handle %" PRIun " was found.", handle); 1131 1233 async_answer_0(iid, ENOENT); … … 1134 1236 1135 1237 if (fun == NULL && !drv_to_parent) { 1136 log_msg(L VL_ERROR, NAME ": devman_forward error - cannot "1238 log_msg(LOG_DEFAULT, LVL_ERROR, NAME ": devman_forward error - cannot " 1137 1239 "connect to handle %" PRIun ", refers to a device.", 1138 1240 handle); … … 1149 1251 if (dev->pfun->dev != NULL) 1150 1252 driver = dev->pfun->dev->drv; 1253 1151 1254 fwd_h = dev->pfun->handle; 1152 1255 } else if (dev->state == DEVICE_USABLE) { … … 1154 1257 driver = dev->drv; 1155 1258 assert(driver != NULL); 1156 1259 1157 1260 fwd_h = handle; 1158 1261 } … … 1161 1264 1162 1265 if (driver == NULL) { 1163 log_msg(L VL_ERROR, "IPC forwarding refused - " \1266 log_msg(LOG_DEFAULT, LVL_ERROR, "IPC forwarding refused - " \ 1164 1267 "the device %" PRIun " is not in usable state.", handle); 1165 1268 async_answer_0(iid, ENOENT); … … 1174 1277 1175 1278 if (!driver->sess) { 1176 log_msg(L VL_ERROR,1279 log_msg(LOG_DEFAULT, LVL_ERROR, 1177 1280 "Could not forward to driver `%s'.", driver->name); 1178 1281 async_answer_0(iid, EINVAL); … … 1181 1284 1182 1285 if (fun != NULL) { 1183 log_msg(L VL_DEBUG,1286 log_msg(LOG_DEFAULT, LVL_DEBUG, 1184 1287 "Forwarding request for `%s' function to driver `%s'.", 1185 1288 fun->pathname, driver->name); 1186 1289 } else { 1187 log_msg(L VL_DEBUG,1290 log_msg(LOG_DEFAULT, LVL_DEBUG, 1188 1291 "Forwarding request for `%s' device to driver `%s'.", 1189 1292 dev->pfun->pathname, driver->name); … … 1193 1296 async_forward_fast(iid, exch, method, fwd_h, 0, IPC_FF_NONE); 1194 1297 async_exchange_end(exch); 1195 1298 1196 1299 cleanup: 1197 1300 if (dev != NULL) 1198 1301 dev_del_ref(dev); 1302 1199 1303 if (fun != NULL) 1200 1304 fun_del_ref(fun); … … 1216 1320 1217 1321 if (fun == NULL || fun->dev == NULL || fun->dev->drv == NULL) { 1218 log_msg(L VL_WARN, "devman_connection_loc(): function "1322 log_msg(LOG_DEFAULT, LVL_WARN, "devman_connection_loc(): function " 1219 1323 "not found.\n"); 1220 1324 fibril_rwlock_read_unlock(&device_tree.rwlock); … … 1234 1338 async_exchange_end(exch); 1235 1339 1236 log_msg(L VL_DEBUG,1340 log_msg(LOG_DEFAULT, LVL_DEBUG, 1237 1341 "Forwarding loc service request for `%s' function to driver `%s'.", 1238 1342 fun->pathname, driver->name); … … 1290 1394 static bool devman_init(void) 1291 1395 { 1292 log_msg(L VL_DEBUG, "devman_init - looking for available drivers.");1396 log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_init - looking for available drivers."); 1293 1397 1294 1398 /* Initialize list of available drivers. */ … … 1296 1400 if (lookup_available_drivers(&drivers_list, 1297 1401 DRIVER_DEFAULT_STORE) == 0) { 1298 log_msg(L VL_FATAL, "No drivers found.");1402 log_msg(LOG_DEFAULT, LVL_FATAL, "No drivers found."); 1299 1403 return false; 1300 1404 } 1301 1302 log_msg(L VL_DEBUG, "devman_init - list of drivers has been initialized.");1303 1405 1406 log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_init - list of drivers has been initialized."); 1407 1304 1408 /* Create root device node. */ 1305 1409 if (!init_device_tree(&device_tree, &drivers_list)) { 1306 log_msg(L VL_FATAL, "Failed to initialize device tree.");1410 log_msg(LOG_DEFAULT, LVL_FATAL, "Failed to initialize device tree."); 1307 1411 return false; 1308 1412 } 1309 1413 1310 1414 /* 1311 1415 * Caution: As the device manager is not a real loc … … 1322 1426 int main(int argc, char *argv[]) 1323 1427 { 1324 printf(NAME ": HelenOS Device Manager\n"); 1325 1326 if (log_init(NAME, LVL_WARN) != EOK) { 1327 printf(NAME ": Error initializing logging subsystem.\n"); 1328 return -1; 1428 printf("%s: HelenOS Device Manager\n", NAME); 1429 1430 int rc = log_init(NAME); 1431 if (rc != EOK) { 1432 printf("%s: Error initializing logging subsystem.\n", NAME); 1433 return rc; 1329 1434 } 1330 1435 … … 1333 1438 async_set_client_data_destructor(devman_client_data_destroy); 1334 1439 async_set_client_connection(devman_connection); 1335 1440 1336 1441 if (!devman_init()) { 1337 log_msg(L VL_ERROR, "Error while initializing service.");1442 log_msg(LOG_DEFAULT, LVL_ERROR, "Error while initializing service."); 1338 1443 return -1; 1339 1444 } 1340 1445 1341 1446 /* Register device manager at naming service. */ 1342 if (service_register(SERVICE_DEVMAN) != EOK) { 1343 log_msg(LVL_ERROR, "Failed registering as a service."); 1344 return -1; 1345 } 1346 1347 printf(NAME ": Accepting connections.\n"); 1447 rc = service_register(SERVICE_DEVMAN); 1448 if (rc != EOK) { 1449 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering as a service."); 1450 return rc; 1451 } 1452 1453 printf("%s: Accepting connections.\n", NAME); 1348 1454 task_retval(0); 1349 1455 async_manager(); 1350 1456 1351 1457 /* Never reached. */ 1352 1458 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.