Changeset 63c1dd5 in mainline for uspace/srv
- Timestamp:
- 2018-10-09T08:40:53Z (7 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)
- Location:
- uspace/srv/volsrv
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/volsrv/types/volume.h
ree9c703 r63c1dd5 49 49 /** Link to vol_volumes */ 50 50 link_t lvolumes; 51 /** ID used by clients to refer to the volume */ 52 volume_id_t id; 51 53 /** Reference count */ 52 54 atomic_refcount_t refcnt; … … 69 71 /** Volumes SIF node */ 70 72 sif_node_t *nvolumes; 73 /** Next ID */ 74 sysarg_t next_id; 71 75 } vol_volumes_t; 72 76 -
uspace/srv/volsrv/volsrv.c
ree9c703 r63c1dd5 419 419 } 420 420 421 static void vol_get_volumes_srv(vol_parts_t *parts, ipc_call_t *icall) 422 { 423 ipc_call_t call; 424 size_t size; 425 size_t act_size; 426 errno_t rc; 427 428 log_msg(LOG_DEFAULT, LVL_NOTE, "vol_get_volumes_srv()"); 429 430 if (!async_data_read_receive(&call, &size)) { 431 async_answer_0(&call, EREFUSED); 432 async_answer_0(icall, EREFUSED); 433 return; 434 } 435 436 volume_id_t *id_buf = (volume_id_t *) malloc(size); 437 if (id_buf == NULL) { 438 async_answer_0(&call, ENOMEM); 439 async_answer_0(icall, ENOMEM); 440 return; 441 } 442 443 rc = vol_get_ids(parts->volumes, id_buf, size, &act_size); 444 if (rc != EOK) { 445 async_answer_0(&call, rc); 446 async_answer_0(icall, rc); 447 return; 448 } 449 450 errno_t retval = async_data_read_finalize(&call, id_buf, size); 451 free(id_buf); 452 453 async_answer_1(icall, retval, act_size); 454 } 455 456 static void vol_info_srv(vol_parts_t *parts, ipc_call_t *icall) 457 { 458 volume_id_t vid; 459 vol_volume_t *volume; 460 vol_info_t vinfo; 461 errno_t rc; 462 463 vid.id = IPC_GET_ARG1(*icall); 464 log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_info_srv(%zu)", vid.id); 465 466 rc = vol_volume_find_by_id_ref(parts->volumes, vid, &volume); 467 if (rc != EOK) { 468 log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_info_srv: volume %zu not found", 469 vid.id); 470 async_answer_0(icall, ENOENT); 471 return; 472 } 473 474 log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_info_srv: vol_volume_get_info"); 475 rc = vol_volume_get_info(volume, &vinfo); 476 if (rc != EOK) { 477 async_answer_0(icall, EIO); 478 goto error; 479 } 480 481 ipc_call_t call; 482 size_t size; 483 if (!async_data_read_receive(&call, &size)) { 484 async_answer_0(&call, EREFUSED); 485 async_answer_0(icall, EREFUSED); 486 goto error; 487 } 488 489 if (size != sizeof(vol_info_t)) { 490 async_answer_0(&call, EINVAL); 491 async_answer_0(icall, EINVAL); 492 goto error; 493 } 494 495 rc = async_data_read_finalize(&call, &vinfo, 496 min(size, sizeof(vinfo))); 497 if (rc != EOK) { 498 async_answer_0(&call, rc); 499 async_answer_0(icall, rc); 500 goto error; 501 } 502 503 async_answer_0(icall, EOK); 504 error: 505 vol_volume_del_ref(volume); 506 } 507 421 508 static void vol_client_conn(ipc_call_t *icall, void *arg) 422 509 { … … 467 554 vol_part_set_mountp_srv(parts, &call); 468 555 break; 556 case VOL_GET_VOLUMES: 557 vol_get_volumes_srv(parts, &call); 558 break; 559 case VOL_INFO: 560 vol_info_srv(parts, &call); 561 break; 469 562 default: 470 563 async_answer_0(&call, EINVAL); -
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 */ -
uspace/srv/volsrv/volume.h
ree9c703 r63c1dd5 38 38 #define VOLUME_H_ 39 39 40 #include "types/vol.h" 40 41 #include "types/volume.h" 41 42 … … 44 45 extern errno_t vol_volume_lookup_ref(vol_volumes_t *, const char *, 45 46 vol_volume_t **); 47 extern errno_t vol_volume_find_by_id_ref(vol_volumes_t *, volume_id_t, 48 vol_volume_t **); 46 49 extern void vol_volume_del_ref(vol_volume_t *); 47 50 extern errno_t vol_volume_set_mountp(vol_volume_t *, const char *); 51 extern errno_t vol_get_ids(vol_volumes_t *, volume_id_t *, size_t, 52 size_t *); 53 extern errno_t vol_volume_get_info(vol_volume_t *, vol_info_t *); 48 54 49 55 #endif
Note:
See TracChangeset
for help on using the changeset viewer.