Changeset a35b458 in mainline for uspace/srv/devman/fun.c
- Timestamp:
- 2018-03-02T20:10:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/fun.c
r3061bc1 ra35b458 58 58 if (fun == NULL) 59 59 return NULL; 60 60 61 61 fun->state = FUN_INIT; 62 62 atomic_set(&fun->refcnt, 0); … … 64 64 link_initialize(&fun->dev_functions); 65 65 list_initialize(&fun->match_ids.ids); 66 66 67 67 return fun; 68 68 } … … 76 76 assert(fun->dev == NULL); 77 77 assert(fun->child == NULL); 78 78 79 79 clean_match_ids(&fun->match_ids); 80 80 free(fun->name); … … 125 125 { 126 126 fun_node_t *fun; 127 127 128 128 assert(fibril_rwlock_is_locked(&tree->rwlock)); 129 129 130 130 ht_link_t *link = hash_table_find(&tree->devman_functions, &handle); 131 131 if (link == NULL) 132 132 return NULL; 133 133 134 134 fun = hash_table_get_inst(link, fun_node_t, devman_fun); 135 135 136 136 return fun; 137 137 } … … 146 146 { 147 147 fun_node_t *fun = NULL; 148 148 149 149 fibril_rwlock_read_lock(&tree->rwlock); 150 150 151 151 fun = find_fun_node_no_lock(tree, handle); 152 152 if (fun != NULL) 153 153 fun_add_ref(fun); 154 154 155 155 fibril_rwlock_read_unlock(&tree->rwlock); 156 156 157 157 return fun; 158 158 } … … 170 170 assert(fibril_rwlock_is_write_locked(&tree->rwlock)); 171 171 assert(fun->name != NULL); 172 172 173 173 size_t pathsize = (str_size(fun->name) + 1); 174 174 if (parent != NULL) 175 175 pathsize += str_size(parent->pathname) + 1; 176 176 177 177 fun->pathname = (char *) malloc(pathsize); 178 178 if (fun->pathname == NULL) { … … 180 180 return false; 181 181 } 182 182 183 183 if (parent != NULL) { 184 184 str_cpy(fun->pathname, pathsize, parent->pathname); … … 188 188 str_cpy(fun->pathname, pathsize, fun->name); 189 189 } 190 190 191 191 return true; 192 192 } … … 209 209 210 210 fibril_rwlock_read_lock(&tree->rwlock); 211 211 212 212 fun_node_t *fun = tree->root_node; 213 213 fun_add_ref(fun); … … 219 219 char *next_path_elem = NULL; 220 220 bool cont = (rel_path[1] != '\0'); 221 221 222 222 while (cont && fun != NULL) { 223 223 next_path_elem = get_path_elem_end(rel_path + 1); … … 228 228 cont = false; 229 229 } 230 230 231 231 fun_node_t *cfun = find_node_child(tree, fun, rel_path + 1); 232 232 fun_del_ref(fun); 233 233 fun = cfun; 234 234 235 235 if (cont) { 236 236 /* Restore the original path. */ … … 239 239 rel_path = next_path_elem; 240 240 } 241 241 242 242 fibril_rwlock_read_unlock(&tree->rwlock); 243 243 244 244 return fun; 245 245 } … … 299 299 { 300 300 dev_node_t *dev; 301 301 302 302 fibril_rwlock_write_lock(&device_tree.rwlock); 303 303 304 304 if (fun->state == FUN_ON_LINE) { 305 305 fibril_rwlock_write_unlock(&device_tree.rwlock); … … 308 308 return EOK; 309 309 } 310 310 311 311 if (fun->ftype == fun_inner) { 312 312 dev = create_dev_node(); … … 315 315 return ENOMEM; 316 316 } 317 317 318 318 insert_dev_node(&device_tree, dev, fun); 319 319 dev_add_ref(dev); 320 320 } 321 321 322 322 log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_add_function(fun=\"%s\")", fun->pathname); 323 323 324 324 if (fun->ftype == fun_inner) { 325 325 dev = fun->child; 326 326 assert(dev != NULL); 327 327 328 328 /* Give one reference over to assign_driver_fibril(). */ 329 329 dev_add_ref(dev); 330 330 331 331 /* 332 332 * Try to find a suitable driver and assign it to the device. We do … … 347 347 } else 348 348 loc_register_tree_function(fun, &device_tree); 349 349 350 350 fun->state = FUN_ON_LINE; 351 351 fibril_rwlock_write_unlock(&device_tree.rwlock); 352 352 353 353 return EOK; 354 354 } … … 357 357 { 358 358 errno_t rc; 359 359 360 360 fibril_rwlock_write_lock(&device_tree.rwlock); 361 361 362 362 if (fun->state == FUN_OFF_LINE) { 363 363 fibril_rwlock_write_unlock(&device_tree.rwlock); … … 366 366 return EOK; 367 367 } 368 368 369 369 if (fun->ftype == fun_inner) { 370 370 log_msg(LOG_DEFAULT, LVL_DEBUG, "Offlining inner function %s.", 371 371 fun->pathname); 372 372 373 373 if (fun->child != NULL) { 374 374 dev_node_t *dev = fun->child; 375 375 device_state_t dev_state; 376 376 377 377 dev_add_ref(dev); 378 378 dev_state = dev->state; 379 379 380 380 fibril_rwlock_write_unlock(&device_tree.rwlock); 381 381 … … 388 388 } 389 389 } 390 390 391 391 /* Verify that driver removed all functions */ 392 392 fibril_rwlock_read_lock(&device_tree.rwlock); … … 396 396 return EIO; 397 397 } 398 398 399 399 driver_t *driver = dev->drv; 400 400 fibril_rwlock_read_unlock(&device_tree.rwlock); 401 401 402 402 if (driver) 403 403 detach_driver(&device_tree, dev); 404 404 405 405 fibril_rwlock_write_lock(&device_tree.rwlock); 406 406 remove_dev_node(&device_tree, dev); 407 407 408 408 /* Delete ref created when node was inserted */ 409 409 dev_del_ref(dev); … … 419 419 return EIO; 420 420 } 421 421 422 422 fun->service_id = 0; 423 423 } 424 424 425 425 fun->state = FUN_OFF_LINE; 426 426 fibril_rwlock_write_unlock(&device_tree.rwlock); 427 427 428 428 return EOK; 429 429 }
Note:
See TracChangeset
for help on using the changeset viewer.