Changes in uspace/srv/devman/main.c [655cc56:3f57fb7] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/main.c
r655cc56 r3f57fb7 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); … … 259 259 return ENOMEM; 260 260 } 261 261 262 262 insert_dev_node(&device_tree, dev, fun); 263 263 dev_add_ref(dev); … … 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 … … 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); … … 855 855 } 856 856 857 /** Get function driver name. */ 858 static void devman_fun_get_driver_name(ipc_callid_t iid, ipc_call_t *icall) 859 { 860 devman_handle_t handle = IPC_GET_ARG1(*icall); 861 862 fun_node_t *fun = find_fun_node(&device_tree, handle); 863 if (fun == NULL) { 864 async_answer_0(iid, ENOMEM); 865 return; 866 } 867 868 ipc_callid_t data_callid; 869 size_t data_len; 870 if (!async_data_read_receive(&data_callid, &data_len)) { 871 async_answer_0(iid, EINVAL); 872 fun_del_ref(fun); 873 return; 874 } 875 876 void *buffer = malloc(data_len); 877 if (buffer == NULL) { 878 async_answer_0(data_callid, ENOMEM); 879 async_answer_0(iid, ENOMEM); 880 fun_del_ref(fun); 881 return; 882 } 883 884 fibril_rwlock_read_lock(&device_tree.rwlock); 885 886 /* Check function state */ 887 if (fun->state == FUN_REMOVED) { 888 fibril_rwlock_read_unlock(&device_tree.rwlock); 889 free(buffer); 890 891 async_answer_0(data_callid, ENOENT); 892 async_answer_0(iid, ENOENT); 893 fun_del_ref(fun); 894 return; 895 } 896 897 /* Check whether function has a driver */ 898 if (fun->child == NULL || fun->child->drv == NULL) { 899 fibril_rwlock_read_unlock(&device_tree.rwlock); 900 free(buffer); 901 902 async_answer_0(data_callid, EINVAL); 903 async_answer_0(iid, EINVAL); 904 fun_del_ref(fun); 905 return; 906 } 907 908 size_t sent_length = str_size(fun->child->drv->name); 909 if (sent_length > data_len) { 910 sent_length = data_len; 911 } 912 913 async_data_read_finalize(data_callid, fun->child->drv->name, 914 sent_length); 915 async_answer_0(iid, EOK); 916 917 fibril_rwlock_read_unlock(&device_tree.rwlock); 918 fun_del_ref(fun); 919 free(buffer); 920 } 857 921 858 922 /** Get device path. */ … … 1083 1147 devman_fun_get_name(callid, &call); 1084 1148 break; 1149 case DEVMAN_FUN_GET_DRIVER_NAME: 1150 devman_fun_get_driver_name(callid, &call); 1151 break; 1085 1152 case DEVMAN_FUN_GET_PATH: 1086 1153 devman_fun_get_path(callid, &call); … … 1149 1216 if (dev->pfun->dev != NULL) 1150 1217 driver = dev->pfun->dev->drv; 1218 1151 1219 fwd_h = dev->pfun->handle; 1152 1220 } else if (dev->state == DEVICE_USABLE) { … … 1154 1222 driver = dev->drv; 1155 1223 assert(driver != NULL); 1156 1224 1157 1225 fwd_h = handle; 1158 1226 } … … 1181 1249 1182 1250 if (fun != NULL) { 1183 log_msg(LVL_DEBUG, 1251 log_msg(LVL_DEBUG, 1184 1252 "Forwarding request for `%s' function to driver `%s'.", 1185 1253 fun->pathname, driver->name); 1186 1254 } else { 1187 log_msg(LVL_DEBUG, 1255 log_msg(LVL_DEBUG, 1188 1256 "Forwarding request for `%s' device to driver `%s'.", 1189 1257 dev->pfun->pathname, driver->name); … … 1193 1261 async_forward_fast(iid, exch, method, fwd_h, 0, IPC_FF_NONE); 1194 1262 async_exchange_end(exch); 1195 1263 1196 1264 cleanup: 1197 1265 if (dev != NULL) 1198 1266 dev_del_ref(dev); 1267 1199 1268 if (fun != NULL) 1200 1269 fun_del_ref(fun); … … 1299 1368 return false; 1300 1369 } 1301 1370 1302 1371 log_msg(LVL_DEBUG, "devman_init - list of drivers has been initialized."); 1303 1372 1304 1373 /* Create root device node. */ 1305 1374 if (!init_device_tree(&device_tree, &drivers_list)) { … … 1307 1376 return false; 1308 1377 } 1309 1378 1310 1379 /* 1311 * !!! devman_connection ... as the device manager is not a real loc 1312 * driver (it uses a completely different ipc protocol than an ordinary 1313 * loc driver) forwarding a connection from client to the devman by 1314 * location service would not work. 1380 * Caution: As the device manager is not a real loc 1381 * driver (it uses a completely different IPC protocol 1382 * than an ordinary loc driver), forwarding a connection 1383 * from client to the devman by location service will 1384 * not work. 1315 1385 */ 1316 loc_server_register(NAME , devman_connection);1386 loc_server_register(NAME); 1317 1387 1318 1388 return true; … … 1321 1391 int main(int argc, char *argv[]) 1322 1392 { 1323 printf(NAME ": HelenOS Device Manager\n"); 1324 1325 if (log_init(NAME, LVL_WARN) != EOK) { 1326 printf(NAME ": Error initializing logging subsystem.\n"); 1327 return -1; 1328 } 1329 1330 if (!devman_init()) { 1331 log_msg(LVL_ERROR, "Error while initializing service."); 1332 return -1; 1393 printf("%s: HelenOS Device Manager\n", NAME); 1394 1395 int rc = log_init(NAME, LVL_WARN); 1396 if (rc != EOK) { 1397 printf("%s: Error initializing logging subsystem.\n", NAME); 1398 return rc; 1333 1399 } 1334 1400 … … 1337 1403 async_set_client_data_destructor(devman_client_data_destroy); 1338 1404 async_set_client_connection(devman_connection); 1339 1405 1406 if (!devman_init()) { 1407 log_msg(LVL_ERROR, "Error while initializing service."); 1408 return -1; 1409 } 1410 1340 1411 /* Register device manager at naming service. */ 1341 if (service_register(SERVICE_DEVMAN) != EOK) { 1412 rc = service_register(SERVICE_DEVMAN); 1413 if (rc != EOK) { 1342 1414 log_msg(LVL_ERROR, "Failed registering as a service."); 1343 return -1;1344 } 1345 1346 printf( NAME ": Accepting connections.\n");1415 return rc; 1416 } 1417 1418 printf("%s: Accepting connections.\n", NAME); 1347 1419 task_retval(0); 1348 1420 async_manager(); 1349 1421 1350 1422 /* Never reached. */ 1351 1423 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.