Changeset 1a9174e in mainline
- 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)
- Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/vol/vol.c
r72c72d4 r1a9174e 190 190 } 191 191 192 table_printf(table, "%s\t" "%s\t" "%s\t" "% d\t" "%s\n",193 vinfo.label, svc_name, sfstype, vinfo.cur_mp_auto,194 vinfo.cur_mp );192 table_printf(table, "%s\t" "%s\t" "%s\t" "%s\t" "%s\n", 193 vinfo.label, svc_name, sfstype, 194 vinfo.cur_mp_auto ? "Yes" : "", vinfo.cur_mp); 195 195 196 196 free(svc_name); -
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 -
uspace/srv/volsrv/part.h
r72c72d4 r1a9174e 47 47 extern errno_t vol_part_add(service_id_t); 48 48 extern errno_t vol_part_get_ids(service_id_t *, size_t, size_t *); 49 extern errno_t vol_part_find_by_id(service_id_t, vol_part_t **); 49 extern errno_t vol_part_find_by_id_ref(service_id_t, vol_part_t **); 50 extern void vol_part_del_ref(vol_part_t *); 50 51 extern errno_t vol_part_eject_part(vol_part_t *); 51 52 extern errno_t vol_part_empty_part(vol_part_t *); -
uspace/srv/volsrv/types/part.h
r72c72d4 r1a9174e 39 39 40 40 #include <adt/list.h> 41 #include <atomic.h> 41 42 #include <stdbool.h> 42 43 #include <types/label.h> … … 46 47 /** Link to vol_parts */ 47 48 link_t lparts; 49 /** Reference count */ 50 atomic_t refcnt; 48 51 /** Service ID */ 49 52 service_id_t svc_id; -
uspace/srv/volsrv/volsrv.c
r72c72d4 r1a9174e 144 144 log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_info_srv(%zu)", 145 145 sid); 146 rc = vol_part_find_by_id (sid, &part);146 rc = vol_part_find_by_id_ref(sid, &part); 147 147 if (rc != EOK) { 148 148 async_answer_0(icall_handle, ENOENT); … … 153 153 if (rc != EOK) { 154 154 async_answer_0(icall_handle, EIO); 155 return;155 goto error; 156 156 } 157 157 … … 161 161 async_answer_0(chandle, EREFUSED); 162 162 async_answer_0(icall_handle, EREFUSED); 163 return;163 goto error; 164 164 } 165 165 … … 167 167 async_answer_0(chandle, EINVAL); 168 168 async_answer_0(icall_handle, EINVAL); 169 return;169 goto error; 170 170 } 171 171 … … 175 175 async_answer_0(chandle, rc); 176 176 async_answer_0(icall_handle, rc); 177 return; 178 } 179 180 async_answer_0(icall_handle, EOK); 177 goto error; 178 } 179 180 async_answer_0(icall_handle, EOK); 181 error: 182 vol_part_del_ref(part); 181 183 } 182 184 … … 190 192 log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_eject_srv(%zu)", sid); 191 193 192 rc = vol_part_find_by_id (sid, &part);194 rc = vol_part_find_by_id_ref(sid, &part); 193 195 if (rc != EOK) { 194 196 async_answer_0(icall_handle, ENOENT); 195 return;197 goto error; 196 198 } 197 199 … … 199 201 if (rc != EOK) { 200 202 async_answer_0(icall_handle, EIO); 201 return; 202 } 203 204 async_answer_0(icall_handle, EOK); 203 goto error; 204 } 205 206 async_answer_0(icall_handle, EOK); 207 error: 208 vol_part_del_ref(part); 205 209 } 206 210 … … 214 218 log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_empty_srv(%zu)", sid); 215 219 216 rc = vol_part_find_by_id (sid, &part);220 rc = vol_part_find_by_id_ref(sid, &part); 217 221 if (rc != EOK) { 218 222 async_answer_0(icall_handle, ENOENT); … … 223 227 if (rc != EOK) { 224 228 async_answer_0(icall_handle, EIO); 225 return; 226 } 227 228 async_answer_0(icall_handle, EOK); 229 goto error; 230 } 231 232 async_answer_0(icall_handle, EOK); 233 error: 234 vol_part_del_ref(part); 229 235 } 230 236 … … 292 298 } 293 299 294 rc = vol_part_find_by_id (sid, &part);300 rc = vol_part_find_by_id_ref(sid, &part); 295 301 if (rc != EOK) { 296 302 free(label); … … 303 309 free(label); 304 310 async_answer_0(icall_handle, rc); 311 vol_part_del_ref(part); 305 312 return; 306 313 }
Note:
See TracChangeset
for help on using the changeset viewer.