Changeset 1a9174e in mainline for uspace/srv/volsrv/part.c
- Timestamp:
- 2018-06-29T15:35:50Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d3b2ffa
- Parents:
- 72c72d4
- git-author:
- Jiri Svoboda <jiri@…> (2018-06-28 18:34:52)
- git-committer:
- Jiri Svoboda <jiri@…> (2018-06-29 15:35:50)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/volsrv/part.c
r72c72d4 r1a9174e 51 51 52 52 static errno_t vol_part_add_locked(service_id_t); 53 static void vol_part_remove_locked(vol_part_t *); 54 static errno_t vol_part_find_by_id_ref_locked(service_id_t, vol_part_t **); 55 53 56 static LIST_INITIALIZE(vol_parts); /* of vol_part_t */ 54 57 static FIBRIL_MUTEX_INITIALIZE(vol_parts_lock); … … 83 86 } 84 87 85 /** Check for new partitions */88 /** Check for new and removed partitions */ 86 89 static errno_t vol_part_check_new(void) 87 90 { 88 91 bool already_known; 92 bool still_exists; 89 93 category_id_t part_cat; 90 94 service_id_t *svcs; 91 95 size_t count, i; 96 link_t *cur, *next; 97 vol_part_t *part; 92 98 errno_t rc; 93 99 … … 109 115 } 110 116 117 /* Check for new partitions */ 111 118 for (i = 0; i < count; i++) { 112 119 already_known = false; 113 120 121 // XXX Make this faster 114 122 list_foreach(vol_parts, lparts, vol_part_t, part) { 115 123 if (part->svc_id == svcs[i]) { … … 130 138 } 131 139 140 /* Check for removed partitions */ 141 cur = list_first(&vol_parts); 142 while (cur != NULL) { 143 next = list_next(cur, &vol_parts); 144 part = list_get_instance(cur, vol_part_t, lparts); 145 146 still_exists = false; 147 // XXX Make this faster 148 for (i = 0; i < count; i++) { 149 if (part->svc_id == svcs[i]) { 150 still_exists = true; 151 break; 152 } 153 } 154 155 if (!still_exists) { 156 log_msg(LOG_DEFAULT, LVL_NOTE, "Partition '%zu' is gone", 157 part->svc_id); 158 vol_part_remove_locked(part); 159 } 160 161 cur = next; 162 } 163 164 free(svcs); 165 132 166 fibril_mutex_unlock(&vol_parts_lock); 133 167 return EOK; … … 144 178 } 145 179 180 atomic_set(&part->refcnt, 1); 146 181 link_initialize(&part->lparts); 147 182 part->pcnt = vpc_empty; … … 152 187 static void vol_part_delete(vol_part_t *part) 153 188 { 189 log_msg(LOG_DEFAULT, LVL_ERROR, "Freeing partition %p", part); 154 190 if (part == NULL) 155 191 return; … … 263 299 } 264 300 265 266 301 static errno_t vol_part_add_locked(service_id_t sid) 267 302 { … … 273 308 274 309 /* Check for duplicates */ 275 rc = vol_part_find_by_id(sid, &part); 276 if (rc == EOK) 310 rc = vol_part_find_by_id_ref_locked(sid, &part); 311 if (rc == EOK) { 312 vol_part_del_ref(part); 277 313 return EEXIST; 314 } 278 315 279 316 log_msg(LOG_DEFAULT, LVL_NOTE, "partition %zu is new", sid); … … 308 345 vol_part_delete(part); 309 346 return rc; 347 } 348 349 static void vol_part_remove_locked(vol_part_t *part) 350 { 351 assert(fibril_mutex_is_locked(&vol_parts_lock)); 352 log_msg(LOG_DEFAULT, LVL_NOTE, "vol_part_remove_locked(%zu)", part->svc_id); 353 354 list_remove(&part->lparts); 355 356 log_msg(LOG_DEFAULT, LVL_NOTE, "Removed partition."); 357 vol_part_del_ref(part); 310 358 } 311 359 … … 374 422 } 375 423 376 errno_t vol_part_find_by_id(service_id_t sid, vol_part_t **rpart) 377 { 424 static errno_t vol_part_find_by_id_ref_locked(service_id_t sid, 425 vol_part_t **rpart) 426 { 427 assert(fibril_mutex_is_locked(&vol_parts_lock)); 428 378 429 list_foreach(vol_parts, lparts, vol_part_t, part) { 379 430 if (part->svc_id == sid) { 431 /* Add reference */ 432 atomic_inc(&part->refcnt); 380 433 *rpart = part; 381 /* XXX Add reference */382 434 return EOK; 383 435 } … … 385 437 386 438 return ENOENT; 439 } 440 441 errno_t vol_part_find_by_id_ref(service_id_t sid, vol_part_t **rpart) 442 { 443 errno_t rc; 444 445 fibril_mutex_lock(&vol_parts_lock); 446 rc = vol_part_find_by_id_ref_locked(sid, rpart); 447 fibril_mutex_unlock(&vol_parts_lock); 448 449 return rc; 450 } 451 452 void vol_part_del_ref(vol_part_t *part) 453 { 454 if (atomic_predec(&part->refcnt) == 0) 455 vol_part_delete(part); 387 456 } 388 457
Note:
See TracChangeset
for help on using the changeset viewer.