Changeset 63c1dd5 in mainline for uspace/srv/volsrv/volume.c
- Timestamp:
- 2018-10-09T08:40:53Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 63a045c
- Parents:
- ee9c703
- git-author:
- Jiri Svoboda <jiri@…> (2018-10-08 18:38:16)
- git-committer:
- Jiri Svoboda <jiri@…> (2018-10-09 08:40:53)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/volsrv/volume.c
ree9c703 r63c1dd5 125 125 fibril_mutex_initialize(&volumes->lock); 126 126 list_initialize(&volumes->volumes); 127 volumes->next_id = 1; 127 128 128 129 /* Try opening existing repository */ … … 222 223 volume->volumes = volumes; 223 224 list_append(&volume->lvolumes, &volumes->volumes); 225 volume->id.id = volumes->next_id; 226 ++volumes->next_id; 224 227 } 225 228 … … 294 297 } 295 298 299 /** Find volume structure by ID with locked volumes lock. 300 * * 301 * @param volumes List of volumes 302 * @param vid Volume ID 303 * @param rvolume Place to store pointer to volume structure (existing or new) 304 * 305 * @return EOK on success, ENOENT if not found 306 */ 307 static errno_t vol_volume_find_by_id_ref_locked(vol_volumes_t *volumes, 308 volume_id_t vid, vol_volume_t **rvolume) 309 { 310 assert(fibril_mutex_is_locked(&volumes->lock)); 311 312 list_foreach(volumes->volumes, lvolumes, vol_volume_t, volume) { 313 log_msg(LOG_DEFAULT, LVL_DEBUG2, 314 "vol_volume_find_by_id_ref_locked(%zu==%zu)?", 315 volume->id.id, vid.id); 316 if (volume->id.id == vid.id) { 317 log_msg(LOG_DEFAULT, LVL_DEBUG2, 318 "vol_volume_find_by_id_ref_locked: found"); 319 /* Add reference */ 320 refcount_up(&volume->refcnt); 321 *rvolume = volume; 322 return EOK; 323 } 324 } 325 326 log_msg(LOG_DEFAULT, LVL_DEBUG2, 327 "vol_volume_find_by_id_ref_locked: not found"); 328 return ENOENT; 329 } 330 331 /** Find volume by ID. 332 * 333 * @param volumes Volumes 334 * @param vid Volume ID 335 * @param rvolume Place to store pointer to volume, with reference count 336 * increased. 337 * @return EOK on success or an error code 338 */ 339 errno_t vol_volume_find_by_id_ref(vol_volumes_t *volumes, volume_id_t vid, 340 vol_volume_t **rvolume) 341 { 342 errno_t rc; 343 344 fibril_mutex_lock(&volumes->lock); 345 rc = vol_volume_find_by_id_ref_locked(volumes, vid, rvolume); 346 fibril_mutex_unlock(&volumes->lock); 347 348 return rc; 349 } 350 296 351 /** Determine if volume has non-default settings that need to persist. 297 352 * … … 416 471 } 417 472 473 /** Get list of volume IDs. 474 * 475 * Get the list of IDs of all persistent volumes (volume configuration 476 * entries). 477 * 478 * @param volumes Volumes 479 * @param id_buf Buffer to hold the IDs 480 * @param buf_size Buffer size in bytes 481 * @param act_size Place to store actual number bytes needed 482 * @return EOK on success or an error code 483 */ 484 errno_t vol_get_ids(vol_volumes_t *volumes, volume_id_t *id_buf, 485 size_t buf_size, size_t *act_size) 486 { 487 size_t act_cnt; 488 size_t buf_cnt; 489 490 fibril_mutex_lock(&volumes->lock); 491 492 buf_cnt = buf_size / sizeof(volume_id_t); 493 494 act_cnt = 0; 495 list_foreach(volumes->volumes, lvolumes, vol_volume_t, volume) { 496 if (vol_volume_is_persist(volume)) 497 ++act_cnt; 498 } 499 *act_size = act_cnt * sizeof(volume_id_t); 500 501 if (buf_size % sizeof(volume_id_t) != 0) { 502 fibril_mutex_unlock(&volumes->lock); 503 return EINVAL; 504 } 505 506 size_t pos = 0; 507 list_foreach(volumes->volumes, lvolumes, vol_volume_t, volume) { 508 if (vol_volume_is_persist(volume)) { 509 if (pos < buf_cnt) 510 id_buf[pos].id = volume->id.id; 511 pos++; 512 } 513 } 514 515 fibril_mutex_unlock(&volumes->lock); 516 return EOK; 517 } 518 418 519 /** Load volumes from SIF repository. 419 520 * … … 474 575 } 475 576 577 /** Get volume information. 578 * 579 * @param volume Volume 580 * @param vinfo Volume information structure to safe info to 581 * @return EOK on success or an error code 582 */ 583 errno_t vol_volume_get_info(vol_volume_t *volume, vol_info_t *vinfo) 584 { 585 vinfo->id = volume->id; 586 str_cpy(vinfo->label, sizeof(vinfo->label), volume->label); 587 str_cpy(vinfo->path, sizeof(vinfo->path), volume->mountp); 588 return EOK; 589 } 590 476 591 /** @} 477 592 */
Note:
See TracChangeset
for help on using the changeset viewer.